/* thatchy.cc — public page. Premium dark studio: near-black, generous space, one accent used sparingly. */
:root {
  --bg: #090b0e;
  --surface: #15181e;
  --surface-2: #1b1f26;
  --text: #f5f5f7;
  --text-2: #b6bbc4;
  --text-3: #8e949e; /* ≥ 4.5:1 on --bg (checked in e2e/a11y) */
  --line: rgb(255 255 255 / 0.12);
  --line-strong: rgb(255 255 255 / 0.28);
  --accent: #9dc4ff;
  --font: "Plex Thai", "Noto Sans Thai", "Sukhumvit Set", "Leelawadee UI", "Thonburi", system-ui, sans-serif;
  --gutter: max(16px, env(safe-area-inset-left), env(safe-area-inset-right));
  --page-max: 1200px;
  --ease: cubic-bezier(0.2, 0.7, 0.2, 1);
  --t-fast: 180ms;
  --t-fade: 260ms;
  --stage-h: clamp(300px, 58svh, 520px);
  color-scheme: dark;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100svh;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 1rem;
  line-height: 1.65;
  font-synthesis: none;
  -webkit-font-smoothing: antialiased;
  display: flex;
  flex-direction: column;
}

[hidden] {
  display: none !important;
}

img,
video {
  display: block;
  max-width: 100%;
}

a {
  color: inherit;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
  border-radius: 6px;
}

.visually-hidden {
  position: absolute !important;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.skip-link {
  position: absolute;
  left: var(--gutter);
  top: 12px;
  z-index: 20;
  padding: 10px 16px;
  background: var(--text);
  color: var(--bg);
  border-radius: 8px;
  font-weight: 500;
  text-decoration: none;
  transform: translateY(-160%);
}
.skip-link:focus {
  transform: none;
}

/* ---------- header ---------- */
.site-header {
  width: 100%;
  max-width: calc(var(--page-max) + 2 * var(--gutter));
  margin: 0 auto;
  padding: max(20px, env(safe-area-inset-top)) var(--gutter) 0;
}
.wordmark {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  font-size: 0.875rem;
  font-weight: 600;
  letter-spacing: 0.28em;
  text-decoration: none;
}

/* ---------- intro ---------- */
.page {
  flex: 1;
  width: 100%;
  max-width: calc(var(--page-max) + 2 * var(--gutter));
  margin: 0 auto;
  padding: 0 var(--gutter);
  overflow-x: clip; /* the studio-light glow may extend past narrow screens; never cause sideways scroll */
}
.intro {
  text-align: center;
  margin: clamp(8px, 2.5svh, 28px) auto clamp(12px, 3svh, 32px);
  max-width: 40rem;
}
.eyebrow {
  margin: 0 0 6px;
  font-size: 0.8125rem;
  font-weight: 500;
  letter-spacing: 0.24em;
  color: var(--text-3);
}
.intro-heading {
  margin: 0;
  font-size: clamp(1.875rem, 1.2rem + 2.6vw, 3.5rem);
  font-weight: 600;
  line-height: 1.3;
  text-wrap: balance;
}
.intro-lede {
  margin: 10px 0 0;
  font-size: clamp(1rem, 0.95rem + 0.3vw, 1.125rem);
  color: var(--text-2);
  text-wrap: balance;
}

/* ---------- stage area (mobile first: stacked) ---------- */
.stage-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
}
.stage {
  order: 1;
  position: relative;
  margin: 0;
  isolation: isolate;
}
.entries {
  order: 2;
  width: 100%;
  max-width: 34rem;
}
.caption {
  order: 3;
  width: 100%;
  max-width: 34rem;
}

/* Studio light behind the figure — soft, no neon. */
.stage::before {
  content: "";
  position: absolute;
  inset: -12% -38%;
  z-index: -1;
  background: radial-gradient(closest-side, rgb(182 187 196 / 0.09), rgb(182 187 196 / 0.03) 55%, transparent 100%);
  pointer-events: none;
}

.stage-frame {
  position: relative;
  /* Feather the rectangular video edges into the page. The figure's head and feet stay inside the opaque area. */
  -webkit-mask-image: linear-gradient(to right, transparent 0, #000 12%, #000 88%, transparent 100%),
    linear-gradient(to bottom, transparent 0, #000 7%, #000 95%, transparent 100%);
  -webkit-mask-composite: source-in;
  mask-image: linear-gradient(to right, transparent 0, #000 12%, #000 88%, transparent 100%),
    linear-gradient(to bottom, transparent 0, #000 7%, #000 95%, transparent 100%);
  mask-composite: intersect;
}
.stage-poster {
  /* In-flow element that defines the stage size from the media's real aspect ratio (width/height attributes). */
  width: auto;
  height: auto;
  max-height: var(--stage-h);
  max-width: 100%;
}
.stage-poster--missing {
  display: block;
  width: calc(var(--stage-h) * 0.733);
  max-width: 100%;
  aspect-ratio: 528 / 720;
  background: radial-gradient(closest-side, var(--surface-2), var(--bg));
}
.stage-video,
.role-layer {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.stage[data-video="error"] .stage-video,
.stage[data-video="none"] .stage-video {
  display: none;
}
.role-layer {
  opacity: 0;
  transition: opacity var(--t-fade) var(--ease);
}
.role-layer.is-visible {
  opacity: 1;
}

.video-toggle {
  position: absolute;
  left: 12px;
  bottom: 12px;
  z-index: 2;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  min-width: 44px;
  padding: 0 16px 0 14px;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  background: rgb(9 11 14 / 0.72);
  color: var(--text);
  font: inherit;
  font-size: 0.875rem;
  cursor: pointer;
  transition: border-color var(--t-fast) var(--ease), background var(--t-fast) var(--ease);
}
.video-toggle:hover {
  border-color: var(--accent);
}
.video-toggle-icon {
  width: 12px;
  height: 12px;
  background: currentColor;
  /* play triangle by default */
  clip-path: polygon(15% 5%, 95% 50%, 15% 95%);
}
.stage[data-video="playing"] .video-toggle-icon {
  clip-path: polygon(10% 5%, 38% 5%, 38% 95%, 10% 95%, 10% 5%, 62% 5%, 90% 5%, 90% 95%, 62% 95%, 62% 5%);
}

/* ---------- entries ---------- */
.entry-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 220px), 1fr));
  gap: 10px;
}
.page[data-count="1"] .entry-list {
  grid-template-columns: minmax(0, 20rem);
  justify-content: center;
}
.entry {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 56px;
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  text-align: start;
  text-decoration: none;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: transform var(--t-fast) var(--ease), border-color var(--t-fast) var(--ease), background var(--t-fast) var(--ease),
    opacity var(--t-fast) var(--ease);
}
.entry-icon {
  flex: none;
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: 10px;
  border: 1px solid var(--line);
  color: var(--text-2);
  transition: color var(--t-fast) var(--ease), border-color var(--t-fast) var(--ease);
}
.entry-icon .icon {
  width: 20px;
  height: 20px;
}
.entry-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
  line-height: 1.4;
}
.entry-label {
  font-weight: 500;
  overflow-wrap: anywhere;
}
.entry-role {
  font-size: 0.875rem;
  color: var(--text-2);
}
.entry.is-active,
.entry[aria-pressed="true"] {
  border-color: var(--accent);
  background: var(--surface-2);
}
.entry.is-active .entry-icon,
.entry[aria-pressed="true"] .entry-icon {
  color: var(--accent);
  border-color: rgb(157 196 255 / 0.45);
}
@media (hover: hover) and (pointer: fine) {
  .entry:hover {
    border-color: var(--line-strong);
  }
}

/* ---------- caption ---------- */
.caption {
  text-align: center;
}
.caption-body {
  min-height: 11rem; /* reserved so selecting a role never shifts the page (kicker + title + 1 line + CTA) */
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  transition: opacity var(--t-fast) var(--ease);
}
.caption-body.is-swapping {
  opacity: 0;
}
.caption-kicker {
  margin: 0;
  min-height: 1.6em;
  font-size: 0.875rem;
  color: var(--text-3);
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
}
.caption-label {
  color: var(--text-2);
}
.caption-host:empty,
.caption-label:empty {
  display: none;
}
.caption-title {
  margin: 0;
  font-size: clamp(1.375rem, 1.1rem + 1vw, 1.875rem);
  font-weight: 600;
  line-height: 1.35;
}
.caption-title:empty {
  display: none;
}
.caption-desc {
  margin: 4px 0 0;
  color: var(--text-2);
  max-width: 30rem;
}
[data-caption="default"] .caption-desc {
  color: var(--text-3);
}
.hint--fine {
  display: none;
}
@media (hover: hover) and (pointer: fine) {
  .hint--fine {
    display: inline;
  }
  .hint--touch {
    display: none;
  }
}
.cta {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 48px;
  margin-top: 14px;
  padding: 0 22px;
  border-radius: 999px;
  background: var(--text);
  color: var(--bg);
  font-weight: 500;
  text-decoration: none;
  transition: background var(--t-fast) var(--ease), transform var(--t-fast) var(--ease);
}
.cta:hover {
  background: #fff;
}
.cta[hidden] {
  display: none;
}

/* ---------- all works (> 6 entries) ---------- */
.all-works {
  max-width: 46rem;
  margin: 40px auto 0;
  padding-top: 28px;
  border-top: 1px solid var(--line);
}
.all-works-title {
  margin: 0 0 12px;
  font-size: 1.125rem;
  font-weight: 600;
}
.all-works-list {
  list-style: none;
  margin: 0;
  padding: 0;
}
.work-link {
  display: flex;
  align-items: center;
  gap: 14px;
  min-height: 60px;
  padding: 10px 4px;
  border-bottom: 1px solid var(--line);
  text-decoration: none;
}
.work-text {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-width: 0;
  line-height: 1.4;
}
.work-label {
  font-weight: 500;
}
.work-role,
.work-host {
  font-size: 0.875rem;
  color: var(--text-2);
}
.work-host {
  overflow-wrap: anywhere;
  text-align: end;
}
.work-link:hover .work-label {
  text-decoration: underline;
  text-underline-offset: 4px;
}

/* ---------- footer ---------- */
.site-footer {
  width: 100%;
  max-width: calc(var(--page-max) + 2 * var(--gutter));
  margin: 48px auto 0;
  padding: 24px var(--gutter) max(28px, env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  display: flex;
  flex-wrap: wrap;
  gap: 4px 20px;
  align-items: baseline;
  font-size: 0.875rem;
  color: var(--text-3);
}
.site-footer p {
  margin: 0;
}
.footer-mark {
  font-weight: 600;
  letter-spacing: 0.24em;
  color: var(--text-2);
}
.footer-contacts {
  display: flex;
  gap: 16px;
  list-style: none;
  margin: 0 0 0 auto;
  padding: 0;
}

/* ---------- desktop: entries placed around the figure ---------- */
@media (min-width: 960px) {
  :root {
    --stage-h: clamp(360px, calc(100svh - 440px), 640px); /* caption + CTA stay on the first screen at 1440×900 */
  }
  .stage-area {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
    grid-template-rows: auto auto;
    column-gap: clamp(28px, 4vw, 64px);
    row-gap: 8px;
    align-items: stretch;
  }
  .stage {
    grid-column: 2;
    grid-row: 1;
    z-index: 1;
  }
  .entries {
    grid-column: 1 / -1;
    grid-row: 1;
    max-width: none;
    display: grid;
    grid-template-columns: subgrid;
    align-items: center;
  }
  .entry-list {
    grid-column: 1 / -1;
    grid-template-columns: subgrid;
    align-content: center;
    row-gap: 4px;
    gap: 4px 0;
  }
  .half-rows-2 { grid-template-rows: repeat(2, auto); }
  .half-rows-4 { grid-template-rows: repeat(4, auto); }
  .half-rows-6 { grid-template-rows: repeat(6, auto); }
  .entry-item { grid-row-end: span 2; padding: 12px 0; }
  .row-1 { grid-row-start: 1; }
  .row-2 { grid-row-start: 2; }
  .row-3 { grid-row-start: 3; }
  .row-4 { grid-row-start: 4; }
  .row-5 { grid-row-start: 5; }
  .side-left { grid-column: 1; justify-self: end; }
  .side-right { grid-column: 3; justify-self: start; }
  .page[data-count="1"] .entry-list { grid-template-columns: subgrid; justify-content: normal; }

  /* Gentle arc toward the figure — fixed steps, no motion. */
  .side-left.curve-1 { margin-right: -14px; }
  .side-left.curve-2 { margin-right: -28px; }
  .side-right.curve-1 { margin-left: -14px; }
  .side-right.curve-2 { margin-left: -28px; }

  .entry {
    width: auto;
    min-width: 0;
    max-width: 17.5rem;
    min-height: 64px;
    padding: 10px 12px;
    border-color: transparent;
    background: transparent;
    border-radius: 16px;
  }
  .side-left .entry {
    flex-direction: row-reverse;
    text-align: end;
  }
  .entry-icon {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    border-color: var(--line-strong);
    background: rgb(21 24 30 / 0.7);
  }
  .entry-label {
    font-size: 1.0625rem;
  }
  /* While one role is previewed, the others step back. */
  .stage-area[data-active] .entry:not(.is-active) {
    opacity: 0.55;
  }
  .entry.is-active {
    background: rgb(21 24 30 / 0.6);
    border-color: var(--line);
    transform: translateY(-2px);
  }

  .caption {
    grid-column: 1 / -1;
    grid-row: 2;
    justify-self: center;
    max-width: 36rem;
  }
  .caption-body {
    min-height: 10.5rem;
  }
}

@media (min-width: 960px) and (hover: hover) and (pointer: fine) {
  .entry:hover {
    border-color: var(--line);
  }
}

/* Short landscape screens: let the page scroll naturally, keep the figure readable. */
@media (max-height: 560px) and (orientation: landscape) {
  :root {
    --stage-h: clamp(260px, 78svh, 420px);
  }
}

/* ---------- reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
  .entry.is-active {
    transform: none;
  }
}

/* ---------- plain pages (404, admin shell later) ---------- */
.plain-page {
  max-width: 36rem;
  margin: 18svh auto 0;
  padding: 0 var(--gutter);
}
.plain-page h1 {
  margin: 0 0 12px;
  font-size: 2rem;
  line-height: 1.3;
}

/* Draft preview (admin only) */
.preview-banner {
  margin: 0;
  padding: 8px var(--gutter);
  background: #3a2f10;
  color: #ffe7a3;
  font-size: 0.875rem;
  text-align: center;
}
