:root {
  --maroon: #7a3841;
  --red: #bf1e2e;
  --sand: #eae5db;
  --rust: #b0433f;
  --ice: #f3f3f4;
  --ink: #000;
  --paper: #fff;
  --page-w: min(1200px, calc(100% - 32px));
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #fff;
    /* the case study is designed on a light canvas; keep it light */
  }
}

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

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: 'Noto Sans Thai', system-ui, sans-serif;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

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

/* ---------- Nav (Figma "Nav", node 313:2): name only ---------- */
.nav {
  padding: 10px 16px;
  background: var(--paper);
}

.nav-inner {
  width: min(1200px, 100%);
  margin-inline: auto;
  padding: 10px;
  font-family: 'Google Sans Flex', 'Google Sans', 'Noto Sans Thai', system-ui, sans-serif;
  font-size: 18px;
  font-weight: 300;
  line-height: normal;
  color: #000;
}

.nav-name {
  color: inherit;
  text-decoration: none;
}

.nav-name:hover {
  text-decoration: underline;
  text-underline-offset: 4px;
}

/* Smooth scrolling: native for anchor links, Lenis (script.js) for wheel/trackpad. */
html {
  scroll-behavior: smooth;
}

html.lenis,
html.lenis body {
  height: auto;
}

.lenis.lenis-smooth {
  scroll-behavior: auto !important;
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }
}

/* Pratu Lanna variable font (covers the full weight range). */
@font-face {
  font-family: 'Pratu Lanna';
  src: url('assets/Fonts/Pratu%20Lanna-VF.otf') format('opentype');
  font-weight: 100 400;
  /* the file's wght axis is 100–400 (400 is its heaviest) */
  font-display: swap;
}

.display {
  font-family: 'Pratu Lanna', 'Noto Serif Thai', serif;
  font-weight: 900;
  /* Pratu Lanna tops out at 400; stop the browser faking a bold by smearing the outlines. */
  font-synthesis-weight: none;
  color: var(--maroon);
  line-height: 1.1;
  margin: 0;
}

/* ---------- Hero ---------- */
.hero {
  position: relative;
  min-height: min(760px, 100vh);
  display: grid;
  place-items: center;
  overflow: hidden;
  padding: 64px 16px;
}

.hero-inner {
  position: relative;
  text-align: center;
}

.hero-title {
  font-size: clamp(64px, 20.8vw, 300px);
  color: var(--red);
}

.hero-sub {
  font-size: clamp(48px, 13.9vw, 200px);
  color: var(--red);
}

/* Typing animation (script.js). The untyped rest stays in the layout but hidden,
   so the text never shifts while it is being typed. */
.type-rest {
  visibility: hidden;
}

.type-caret {
  display: inline-block;
  width: 0.06em;
  height: 0.9em;
  margin: 0 0.02em;
  vertical-align: -0.05em;
  background: currentColor;
  visibility: hidden;
}

.type-caret.is-active {
  visibility: visible;
  animation: caret-blink 1s steps(1) infinite;
}

@keyframes caret-blink {
  50% {
    opacity: 0;
  }
}

/* ---------- Overview ---------- */
/* Full-width white band behind the Overview text (covers the page background). */
.overview-band,
.anatomy-band,
.cards-band {
  background: #fff;
}

.overview {
  width: min(1200px, 100%);
  margin: 0 auto;
  padding: clamp(40px, 8vw, 64px) clamp(16px, 4vw, 48px) clamp(32px, 6vw, 64px);
}

.overview-title {
  font-size: clamp(44px, 5.3vw, 64px);
  font-weight: 900;
  color: var(--red);
}

.overview-year {
  font-size: clamp(36px, 4vw, 48px);
  margin-top: 8px;
  color: var(--red);
}

.overview-text {
  max-width: 1200px;
  margin: 24px 0 0;
  font-size: clamp(17px, 1.4vw, 20px);
  line-height: 1.2;
}

/* ---------- Sections ---------- */
.section {
  width: min(1200px, 100%);
  margin: 0 auto;
  padding: clamp(32px, 5vw, 64px) clamp(16px, 4vw, 48px);
}

.heading {
  color: var(--red);
  font-size: clamp(40px, 6vw, 72px);
  text-align: center;
  margin-bottom: clamp(16px, 3vw, 40px);
}

/* ---------- Stages: Figma coordinates turned into percentages ---------- */
.stage {
  position: relative;
  width: 100%;
  container-type: inline-size;
}

.stage .abs {
  position: absolute;
}

.stage .abs>img,
.stage .abs>.fill {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.stage .abs.svg>img {
  object-fit: fill;
}

/* Pop-in: pieces scale up with a little overshoot, one after another (order = --pop). */
.stage .abs.pop {
  opacity: 0;
  transform: scale(0.4);
  transition:
    opacity 0.3s ease,
    transform 0.6s cubic-bezier(0.34, 1.56, 0.64, 1);
  transition-delay: calc(var(--pop, 0) * 180ms);
}

.stage.is-drawn .abs.pop {
  opacity: 1;
  transform: none;
}

/* Hover (after the pop-in has finished): products lift and tilt, badges wiggle. */
.stage.is-done .abs.pop {
  transition: transform 0.35s cubic-bezier(0.34, 1.56, 0.64, 1), filter 0.35s ease;
  transition-delay: 0s;
}

.stage.is-done .abs.pop:hover {
  z-index: 2;
  transform: translateY(-3%) scale(1.05) rotate(-2deg);
  filter: drop-shadow(0 12px 16px rgb(0 0 0 / 0.18));
}

.stage.is-done .abs.badge:hover {
  transform: scale(1.12);
  filter: none;
  animation: badge-wiggle 0.6s ease-in-out;
}

@keyframes badge-wiggle {

  0%,
  100% {
    rotate: 0deg;
  }

  20% {
    rotate: -12deg;
  }

  40% {
    rotate: 10deg;
  }

  60% {
    rotate: -6deg;
  }

  80% {
    rotate: 3deg;
  }
}

@media (prefers-reduced-motion: reduce) {
  .stage .abs.pop {
    opacity: 1;
    transform: none;
    transition: none;
  }

  .stage.is-done .abs.pop:hover {
    transform: none;
    animation: none;
  }
}

/* Evolution diagram connector lines that draw themselves (script.js → drawSvg). */
.stage .abs.draw svg {
  display: block;
  width: 100%;
  height: 100%;
  overflow: visible;
}

.stage .abs.draw path {
  fill: none;
  stroke: var(--stroke, #000);
  stroke-width: 4;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-dasharray: 1;
  stroke-dashoffset: 1;
  opacity: 0;
  /* hides the round-cap dot before the line starts */
}

.stage.is-drawn .abs.draw path {
  stroke-dashoffset: 0;
  opacity: 1;
  transition:
    stroke-dashoffset var(--dur) cubic-bezier(0.65, 0, 0.35, 1) var(--delay),
    opacity 0s linear var(--delay);
}

@media (prefers-reduced-motion: reduce) {
  .stage .abs.draw path {
    stroke-dashoffset: 0;
    opacity: 1;
    transition: none;
  }
}

/* SVG vectors fill their box exactly */
.stage .label {
  white-space: nowrap;
  font-weight: 700;
  line-height: 1;
  display: flex;
  align-items: center;
  color: #000;
}

.stage--evolution .abs.pic>img {
  transition: transform 0.25s ease, filter 0.25s ease;
  cursor: zoom-in;
}

.stage--evolution .abs.pic:hover>img,
.stage--evolution .abs.pic:focus-visible>img {
  transform: translateY(-6px);
  filter: drop-shadow(0 8px 12px rgba(122, 56, 65, 0.25));
}

/* Card / panel stages keep their own background */
.card {}

.card--sand {
  background: var(--sand);
}

.card--rust {
  background: var(--rust);
}

/* ---------- Full-width imagery ---------- */
.figure {
  margin: 4rem auto;
  width: min(1200px, 100%);
  padding: clamp(24px, 4vw, 48px) clamp(16px, 4vw, 48px);
}

.figure img {
  width: 100%;
  height: auto;
  object-fit: cover;
}

.band {
  background: var(--maroon);
  padding: clamp(48px, 9.8vw, 141px) 0 clamp(48px, 9.8vw, 142px);
}

/* ---------- Character set grids (real type, see script.js) ---------- */
.glyphs {
  --cols: 12;
  display: grid;
  grid-template-columns: repeat(var(--cols), minmax(0, 1fr));
  row-gap: clamp(4px, 1vw, 16px);
  margin: 0;
  container-type: inline-size;
  /* glyph size follows the grid's width */
  font-family: 'Pratu Lanna', 'Noto Sans Thai', sans-serif;
  font-weight: 400;
  line-height: 1.5;
  color: var(--red);
}

.glyphs>span {
  /* Pratu Lanna draws small inside its em box, so size is set per grid in cqw. */
  font-size: var(--size);
  text-align: left;
  white-space: nowrap;
  /* Reveal: each letter rises and fades in, staggered by its index (--i, set in script.js). */
  opacity: 0;
  transform: translateY(0.35em);
  filter: blur(4px);
  transition:
    opacity 0.6s ease,
    transform 0.6s cubic-bezier(0.22, 1, 0.36, 1),
    filter 0.6s ease;
  transition-delay: calc(var(--i, 0) * 25ms);
}

.glyphs.is-in>span {
  opacity: 1;
  transform: none;
  filter: none;
}

/* After the reveal, letters lift slightly on hover. */
.glyphs.is-done>span {
  transition-delay: 0s;
  transition-duration: 0.25s;
}

.glyphs.is-done>span:hover {
  transform: translateY(-0.08em) scale(1.08);
}

@media (prefers-reduced-motion: reduce) {
  .glyphs>span {
    opacity: 1;
    transform: none;
    filter: none;
    transition: none;
  }
}

.glyphs--thai {
  --cols: 12;
  --size: 7.5cqw;
}

.glyphs--nums {
  --cols: 9;
  --size: 7.5cqw;
}

.glyphs--latin {
  --cols: 7;
  --size: 7cqw;
  width: var(--page-w);
  margin: 0 auto;
  color: #fff;
}

@media (max-width: 720px) {
  .glyphs--thai {
    --cols: 6;
    --size: 14cqw;
  }

  .glyphs--nums {
    --cols: 6;
    --size: 13cqw;
  }

  .glyphs--latin {
    --cols: 4;
    --size: 12cqw;
  }
}

.band img {
  width: var(--page-w);
  margin: 0 auto;
  height: auto;
  object-fit: cover;
}

/* Full-width maroon band behind the two posters. */
.pair-band {
  background: var(--maroon);
  padding: clamp(24px, 4vw, 64px) 0;
}

.pair {
  width: min(1200px, 100%);
  margin: 0 auto;
  padding: clamp(24px, 4vw, 48px) clamp(16px, 4vw, 48px);
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: clamp(16px, 4.7vw, 68px);
}

.pair img {
  width: 100%;
  height: auto;
  object-fit: cover;
}

.collage {
  width: min(1200px, 100%);
  margin: 4rem auto;
  aspect-ratio: 1200 / 668;
  display: grid;
  grid-template-columns: 470fr 361fr 361fr;
  grid-template-rows: 361fr 307fr;
  gap: 6px;
}

.collage img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  min-height: 0;
}

.collage .c-tall {
  grid-column: 1;
  grid-row: 1 / span 2;
}

.collage .c-sq-top {
  grid-column: 2;
  grid-row: 1;
}

.collage .c-sq-top-r {
  grid-column: 3;
  grid-row: 1;
}

.collage .c-mid {
  grid-column: 2;
  grid-row: 2;
  background: var(--ice);
  display: grid;
  place-items: center;
}

.collage .c-mid img {
  width: 86.6%;
  height: auto;
  aspect-ratio: 311 / 154;
}

.collage .c-mid-r {
  grid-column: 3;
  grid-row: 2;
}

/* Full-width white band behind the product mock-ups (covers the page background). */
.scatter-band {
  background: #fff;
}

.scatter-wrap {
  width: min(1200px, 100%);
  margin: 0 auto;
  padding: clamp(32px, 5vw, 64px) clamp(16px, 4vw, 48px);
}

.cards {
  width: min(1200px, 100%);
  margin: 0 auto;
  padding: clamp(32px, 5vw, 64px) clamp(16px, 4vw, 48px) clamp(48px, 8vw, 96px);
  display: grid;
  grid-template-columns: 1fr 1fr;
}

.cards .card {
  width: 100%;
}

/* ---------- Lightbox ---------- */
.lightbox {
  border: 0;
  padding: 0;
  background: transparent;
  max-width: 96vw;
  max-height: 96vh;
}

.lightbox::backdrop {
  background: rgba(0, 0, 0, 0.8);
}

.lightbox img {
  max-width: 96vw;
  max-height: 92vh;
  display: block;
}

.lightbox-close {
  position: absolute;
  top: 8px;
  right: 12px;
  font-size: 32px;
  line-height: 1;
  background: none;
  border: 0;
  color: #fff;
  cursor: pointer;
}

/* ---------- Phones ---------- */
@media (max-width: 720px) {
  .pair {
    grid-template-columns: 1fr;
  }

  .collage {
    aspect-ratio: auto;
    grid-template-columns: 1fr 1fr;
    grid-template-rows: auto;
  }

  .collage .c-tall,
  .collage .c-sq-top,
  .collage .c-sq-top-r,
  .collage .c-mid,
  .collage .c-mid-r {
    grid-column: auto;
    grid-row: auto;
  }

  .collage .c-tall {
    grid-column: 1 / span 2;
  }

  .collage .c-mid {
    min-height: 160px;
  }

  .cards {
    grid-template-columns: 1fr;
  }
}