/* Craft tab — single-image slide viewer.
 * Companion to main.css (reuses every design token from :root).
 *
 * Core promises:
 *   - Images are never cropped. `object-fit: contain` wherever an image is shown.
 *   - One image at a time, with a caption panel sitting next to it.
 *   - Works with keyboard arrows, touch swipe, and explicit prev/next buttons.
 */

/* -------------------------------------------------------------------------
 * View toggle — identical pattern to .about-inline
 * ------------------------------------------------------------------------- */

.craft-inline {
  display: none;
  width: 100%;
}

.portfolio-site.view-craft .craft-inline {
  display: block;
}

.portfolio-site.view-craft .hero-msg-section,
.portfolio-site.view-craft .project-list-section,
.portfolio-site.view-craft .chronological-bleed,
.portfolio-site.view-craft .about-inline {
  display: none;
}

.portfolio-site.view-craft .hero-inner {
  justify-content: flex-start;
  padding-bottom: 0;
  min-height: auto;
}

/* -------------------------------------------------------------------------
 * Header — chapter index across the top
 * ------------------------------------------------------------------------- */

.craft-header {
  width: 100%;
  max-width: var(--layout-content-width);
  margin: clamp(12px, 3vw, 28px) auto clamp(20px, 3vw, 36px);
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--space-6);
  flex-wrap: wrap;
}

.craft-eyebrow {
  font-family: "PT Serif Caption", serif;
  font-style: italic;
  font-size: 15px;
  color: var(--text-secondary);
  margin: 0;
}

.craft-eyebrow em {
  color: var(--text-primary-muted);
  font-style: italic;
}

.craft-chapters {
  display: flex;
  gap: var(--space-5);
  flex-wrap: wrap;
}

.craft-chapter-btn {
  appearance: none;
  background: none;
  border: 0;
  padding: 4px 0;
  font-family: "Roboto Condensed", sans-serif;
  font-size: 14px;
  letter-spacing: 0.08em;
  color: var(--text-secondary);
  cursor: pointer;
  border-bottom: 1px solid transparent;
  transition: color 0.18s ease, border-color 0.18s ease;
  display: inline-flex;
  align-items: baseline;
  gap: 6px;
}

.craft-chapter-btn span {
  font-family: "Roboto Flex", sans-serif;
  font-size: 12px;
  color: var(--text-tertiary);
  letter-spacing: 0;
}

.craft-chapter-btn:hover {
  color: var(--text-primary);
}

.craft-chapter-btn.is-current {
  color: var(--text-primary);
  border-bottom-color: var(--border-brand-subtle);
}

.craft-chapter-btn:focus-visible {
  outline: 2px solid var(--focus-ring-default);
  outline-offset: 4px;
}

/* -------------------------------------------------------------------------
 * Viewer layout — stage on the left, caption panel on the right
 * ------------------------------------------------------------------------- */

.craft-viewer {
  width: 100%;
  max-width: var(--layout-content-width);
  margin: 0 auto;
  display: grid;
  grid-template-columns: minmax(0, 1fr) clamp(280px, 28%, 380px);
  grid-template-areas:
    "stage caption"
    "dots  hint";
  column-gap: clamp(24px, 4vw, 64px);
  align-items: stretch;
  /* Stage carries its own aspect-ratio (see .craft-stage), so the viewer
     no longer needs to lock height to viewport. */
}

.craft-stage {
  grid-area: stage;
}

.craft-caption {
  grid-area: caption;
}

.craft-viewer > .craft-dots {
  grid-area: dots;
  margin-top: var(--space-5);
  align-self: center;
}

.craft-viewer > .craft-hint {
  grid-area: hint;
  margin-top: var(--space-5);
  align-self: center;
  justify-self: end; /* push to right edge of the caption column */
  text-align: right;
}

/* ---- Stage ---- */

.craft-stage {
  position: relative;
  overflow: hidden;
  background: var(--surface-page-default);
  touch-action: pan-y;
  user-select: none;
  /* Fixed 4:3 aspect ratio: the stage div has constant dimensions across
     all slides, so the page layout never jumps when navigating between
     images of different aspect ratios. Image inside uses object-fit:
     contain so it's never cropped — it fits naturally within the box,
     with letterbox / pillarbox filling the rest of the stage. */
  aspect-ratio: 4 / 3;
}

.craft-stage__img {
  display: block;
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  /* Contain — preserve the image's natural aspect, never crop. Landscape
     images > 4:3 fit by width (consistent width across landscape slides);
     near-square or portrait images fit by height. The page layout is
     stable because the surrounding stage box never changes size. */
  object-fit: contain;
  /* Shown via .is-current; animate opacity + a tiny scale as it arrives */
  opacity: 0;
  transform: scale(0.995);
  transition:
    opacity 0.45s cubic-bezier(0.22, 1, 0.36, 1),
    transform 0.6s cubic-bezier(0.22, 1, 0.36, 1);
  will-change: opacity, transform;
  pointer-events: none;
}

.craft-stage__img.is-current {
  opacity: 1;
  transform: scale(1);
  pointer-events: auto;
}

/* ---- Caption panel ---- */

.craft-caption {
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  gap: var(--space-4);
  padding: var(--space-5) 0;
  min-width: 0;
}

/* Top nav row inside the caption panel: Previous · counter · Next.
 * Editorial, text-first — no button chrome, no borders, just type and an
 * even-stroke SVG arrow. Integrates with the caption the way a page number
 * integrates with a book. */
.craft-caption__nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding-bottom: var(--space-4);
  border-bottom: 1px solid var(--border-neutral-subtle);
}

.craft-nav-btn {
  appearance: none;
  background: none;
  border: 0;
  padding: 2px 0;
  cursor: pointer;
  font-family: "PT Serif", serif;
  font-size: 14px;
  line-height: 1.2;
  color: var(--text-secondary);
  display: inline-flex;
  align-items: center;
  gap: 8px;
  transition: color 0.18s ease, opacity 0.18s ease;
}

/* Arrow is an inline SVG using stroke="currentColor" so hover color changes
 * automatically follow the button's text color. */
.craft-nav-btn__arrow {
  display: inline-block;
  width: 16px;
  height: 16px;
  color: inherit;
  flex-shrink: 0;
  transition: transform 0.22s cubic-bezier(0.22, 1, 0.36, 1);
}

.craft-nav-btn:hover:not(:disabled),
.craft-nav-btn:focus-visible:not(:disabled) {
  color: var(--text-primary);
}

.craft-nav-btn--prev:hover:not(:disabled) .craft-nav-btn__arrow,
.craft-nav-btn--prev:focus-visible:not(:disabled) .craft-nav-btn__arrow {
  transform: translateX(-3px);
}

.craft-nav-btn--next:hover:not(:disabled) .craft-nav-btn__arrow,
.craft-nav-btn--next:focus-visible:not(:disabled) .craft-nav-btn__arrow {
  transform: translateX(3px);
}

.craft-nav-btn:disabled {
  opacity: 0.25;
  cursor: default;
}

.craft-nav-btn:focus-visible {
  outline: 2px solid var(--focus-ring-default);
  outline-offset: 4px;
}

.craft-caption__counter {
  font-family: "Roboto Flex", sans-serif;
  font-size: 12px;
  letter-spacing: 0.08em;
  color: var(--text-tertiary);
  font-variant-numeric: tabular-nums;
}

.craft-caption__chapter {
  margin: 0 0 var(--space-3);
  font-family: "Roboto Condensed", sans-serif;
  font-size: 12px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--text-tertiary);
}

.craft-caption__title {
  font-family: "Public Sans", sans-serif;
  font-size: clamp(24px, 1.9vw, 30px);
  font-weight: 300;
  letter-spacing: -0.03em;
  line-height: 1.2;
  color: var(--text-primary);
  margin: 0;
}

.craft-caption__subtitle {
  font-family: "PT Serif Caption", serif;
  font-style: italic;
  font-size: 15px;
  color: var(--text-primary-muted);
  margin: 0;
}

.craft-caption__body {
  font-family: "PT Serif", serif;
  font-size: 15px;
  line-height: 1.65;
  color: var(--text-secondary);
  margin: 0;
}

.craft-caption__meta {
  margin-top: auto;
  padding-top: var(--space-4);
  border-top: 1px solid var(--border-neutral-subtle);
  font-family: "Roboto Flex", sans-serif;
  font-size: 12px;
  letter-spacing: 0.04em;
  color: var(--text-tertiary);
}

/* Caption content fades when slides change, so the panel reads like the
 * picture plate: image updates, text updates, nothing jumps layout. */
.craft-caption__content {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  transition: opacity 0.28s cubic-bezier(0.22, 1, 0.36, 1);
}

.craft-caption.is-transitioning .craft-caption__content {
  opacity: 0;
}

/* -------------------------------------------------------------------------
 * Footer strip — dots + keyboard hint
 * ------------------------------------------------------------------------- */

.craft-footer {
  width: 100%;
  max-width: var(--layout-content-width);
  margin: var(--space-4) auto 0;
  padding-bottom: clamp(24px, 4vw, 48px);
  display: flex;
  align-items: center;
  justify-content: flex-end; /* dots moved into viewer; only the hint lives here now */
  gap: var(--space-4);
  flex-wrap: wrap;
}

.craft-dots {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  list-style: none;
  padding: 0;
  margin: 0;
}

/* Dots palette — pulled into a neutral-grey family so both ends feel subtle.
 * Inactive: a light grey (L≈70%, barely-saturated) — present but unassertive.
 * Current: a dark muted charcoal (L≈21%, barely-saturated) — clear but quiet.
 * 49 points of lightness gap between the two carries the "position" signal
 * without needing brand color. */
.craft-dot {
  width: 22px;
  height: 1.5px;
  border-radius: 999px; /* fully-rounded ends rather than square */
  background: var(--border-neutral-subtle);
  border: 0;
  padding: 0;
  cursor: pointer;
  transition: background 0.2s ease, width 0.25s cubic-bezier(0.22, 1, 0.36, 1);
}

.craft-dot:hover {
  background: var(--text-primary-muted);
}

.craft-dot.is-current {
  background: var(--text-primary-muted);
  width: 40px;
}

.craft-dot:focus-visible {
  outline: 2px solid var(--focus-ring-default);
  outline-offset: 3px;
}

.craft-hint {
  font-family: "PT Serif Caption", serif;
  font-style: italic;
  font-size: 13px;
  color: var(--text-tertiary);
}

.craft-hint kbd {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  /* Square buttons with slight rounded corners (4px). */
  width: 18px;
  height: 18px;
  font-family: "Roboto Flex", sans-serif;
  font-style: normal;
  font-size: 12px;
  line-height: 1;
  /* Brand mint blended ~45/55 with white — quiet pale hint of green,
     not a saturated mint. */
  background: color-mix(in srgb, var(--surface-brand-badge) 45%, var(--surface-page-default));
  color: var(--text-primary-muted);
  border-radius: 4px;
  border: 1px solid color-mix(in srgb, var(--border-brand-subtle) 45%, var(--surface-page-default));
  margin: 0 2px;
  vertical-align: middle;
}

/* -------------------------------------------------------------------------
 * Mobile — ≤768px
 *   Stage on top, caption panel underneath. Image still `contain`, so
 *   portraits and landscapes both show whole.
 * ------------------------------------------------------------------------- */

@media (max-width: 768px) {
  .craft-header {
    flex-direction: column;
    align-items: flex-start;
    gap: var(--space-3);
    /* Push the two header lines down (away from the top nav's Contact link)
       while pulling them closer to the image. */
    margin-top: 64px;
    margin-bottom: 24px;
  }

  /* Eyebrow size left at the desktop default (15px) — original look */

  .craft-chapters {
    gap: var(--space-4);
  }

  .craft-chapter-btn {
    font-size: 13px;
  }
  /* span size left at the desktop default (12px) — original mobile look */

  .craft-viewer {
    grid-template-columns: 1fr;
    grid-template-areas:
      "stage"
      "caption"
      "dots";
    grid-template-rows: auto auto auto;
    row-gap: 0; /* control gaps per element below */
    min-height: auto;
  }

  .craft-viewer > .craft-dots {
    margin-top: var(--space-5); /* gap from caption above */
    margin-bottom: 24px; /* breathing room at the bottom of the page */
  }

  .craft-stage {
    /* Mobile uses 4/5 (slightly portrait) since the screen is portrait
       — works better for the deck which has a mix of landscape and
       portrait images. Same fixed-size + object-fit: contain principle
       as desktop: stage size is constant, image fits naturally inside. */
    aspect-ratio: 4 / 5;
    width: 100%;
  }

  .craft-caption {
    padding: 24px 0 0 0; /* 24px breathing room above the Previous/Next nav (i.e. between image and pagination) */
    gap: var(--space-3);
  }

  /* Caption keeps its default DOM order on mobile: nav (Previous · counter
     · Next) at the top, then content, then meta. */
  .craft-caption__nav {
    padding-bottom: var(--space-3);
  }

  .craft-caption__meta {
    margin-top: var(--space-3);
  }

  .craft-nav-btn {
    font-size: 13px;
  }

  .craft-caption__counter {
    font-size: 11px;
  }

  .craft-caption__title {
    font-size: 22px;
  }

  .craft-caption__body {
    font-size: 14.5px;
  }

  .craft-footer {
    /* On mobile, the footer is empty (hint hidden, dots moved into viewer) */
    display: none;
  }

  /* Mobile dots: fit edge-to-edge in a single row; each dash gets an equal
     share of width and a generous vertical tap target (the thin line is
     drawn via ::after so the visible mark stays minimal). */
  .craft-dots {
    flex-wrap: nowrap;
    width: 100%;
    gap: 4px;
  }

  .craft-dots > li {
    flex: 1 1 0;
    min-width: 0;
  }

  .craft-dot {
    width: 100%;
    height: 32px; /* tap target — comfortable for thumb */
    background: transparent;
    position: relative;
    transition: none;
  }

  .craft-dot::after {
    content: "";
    position: absolute;
    left: 0;
    right: 0;
    top: 50%;
    height: 1.5px;
    margin-top: -0.75px;
    background: var(--border-neutral-subtle);
    border-radius: 1px;
    transition: background 0.2s ease, height 0.2s ease, margin-top 0.2s ease;
  }

  .craft-dot:hover {
    background: transparent;
  }

  .craft-dot:hover::after {
    background: var(--text-primary-muted);
  }

  .craft-dot.is-current {
    width: 100%; /* override desktop's 40px override; flex handles width */
    background: transparent;
  }

  .craft-dot.is-current::after {
    background: var(--text-primary-muted);
    height: 2.5px;
    margin-top: -1.25px;
  }

  .craft-hint {
    display: none; /* Touch users don't need a keyboard hint */
  }
}

@media (prefers-reduced-motion: reduce) {
  .craft-stage__img,
  .craft-caption__content,
  .craft-dot,
  .craft-nav-btn,
  .craft-nav-btn__arrow {
    transition: none;
  }
}
