/* ============================================================
   TESSERA — "It starts with a single tile."
   Scroll-scrubbed camera flight through a mosaic world.
   ============================================================ */

@font-face {
  font-family: 'Fraunces';
  src: url('../assets/fonts/Fraunces-var.woff2') format('woff2');
  font-weight: 300 650;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'Space Grotesk';
  src: url('../assets/fonts/SpaceGrotesk-var.woff2') format('woff2');
  font-weight: 300 700;
  font-style: normal;
  font-display: swap;
}

:root {
  --cream: #F4F0E6;
  --cream-hi: #FBF8F1;
  --ink: #22304A;
  --ink-soft: #5C6878;
  --coral: #F07F5F;
  --coral-deep: #E06A4A;
  --sage: #A9C0B4;
  --gold: #E3BE7B;
  --hairline: rgba(34, 48, 74, 0.14);
  /* Latin runs in the brand faces; CJK falls through to the system stack
     (Fraunces / Space Grotesk carry no Han glyphs) */
  --font-display: 'Fraunces', Georgia, 'Noto Serif TC', 'Songti TC', 'PingFang TC',
                  'Microsoft JhengHei', serif;
  --font-body: 'Space Grotesk', 'Helvetica Neue', 'PingFang TC', 'Noto Sans TC',
               'Microsoft JhengHei', sans-serif;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html { scroll-behavior: auto; }

body {
  background: var(--cream);
  color: var(--ink);
  font-family: var(--font-body);
  font-weight: 400;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

::selection { background: var(--coral); color: var(--cream-hi); }

a { color: inherit; text-decoration: none; }

/* ---------------- canvas + atmosphere ---------------- */

#scene {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  z-index: 1;
}

.vignette {
  position: fixed; inset: 0; z-index: 2; pointer-events: none;
  background: radial-gradient(120% 115% at 50% 38%,
              transparent 52%, rgba(34, 48, 74, 0.11) 100%);
}

.grain {
  position: fixed; inset: -50%; z-index: 3; pointer-events: none;
  width: 200%; height: 200%;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='160' height='160'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='2' stitchTiles='stitch'/><feColorMatrix type='saturate' values='0'/></filter><rect width='160' height='160' filter='url(%23n)'/></svg>");
  opacity: 0.045;
  animation: grain-shift 1.4s steps(3) infinite;
}
@keyframes grain-shift {
  0% { transform: translate(0, 0); }
  33% { transform: translate(-2%, 1%); }
  66% { transform: translate(1%, -2%); }
  100% { transform: translate(0, 0); }
}

/* ---------------- scroll length ---------------- */

.scroll-space { height: 900vh; position: relative; z-index: 0; }

/* ---------------- top bar ---------------- */

.topbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 22px clamp(20px, 4vw, 48px);
}

.brand {
  display: inline-flex;
  align-items: center;
}
/* official Tessera lockup (mark + wordmark) */
.brand__logo {
  display: block;
  height: 24px;
  width: auto;
  transition: opacity 0.35s ease;
}
.brand:hover .brand__logo { opacity: 0.62; }
/* the mark alone — footers, small slots */
.brand__symbol {
  display: block;
  height: 22px;
  width: auto;
}

.topnav { display: flex; align-items: center; gap: clamp(16px, 2.6vw, 34px); }
.topnav__link {
  position: relative;
  font-size: 13px;
  font-weight: 500;
  letter-spacing: 0.08em;
  color: var(--ink-soft);
  transition: color 0.25s ease;
}
.topnav__link::after {
  content: '';
  position: absolute;
  left: 0; bottom: -5px;
  width: 100%; height: 1.5px;
  background: var(--coral);
  transform: scaleX(0);
  transform-origin: right;
  transition: transform 0.35s cubic-bezier(0.22, 1, 0.36, 1);
}
.topnav__link:hover { color: var(--ink); }
.topnav__link:hover::after { transform: scaleX(1); transform-origin: left; }

/* language switcher */
.topnav__lang {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.1em;
  color: var(--ink-soft);
  border: 1px solid var(--hairline);
  border-radius: 100px;
  padding: 6px 13px;
  transition: color 0.25s ease, border-color 0.25s ease;
  white-space: nowrap;
}
.topnav__lang:hover { color: var(--coral-deep); border-color: var(--coral); }

/* ---- Traditional Chinese typography ---- */
:lang(zh-Hant) .beat__title,
:lang(zh-Hant) .ph__title,
:lang(zh-Hant) .cta-band h2,
:lang(zh-Hant) .card__title,
:lang(zh-Hant) .chapter__name,
:lang(zh-Hant) .prose h2 {
  letter-spacing: 0.01em;   /* Han needs no Latin tightening */
  line-height: 1.28;
  /* squeeze the built-in side-bearing of full-width punctuation at display
     sizes (progressive enhancement — ignored where unsupported) */
  text-spacing-trim: trim-both;
  font-feature-settings: 'halt' 1;
}
:lang(zh-Hant) .beat__body,
:lang(zh-Hant) .ph__body,
:lang(zh-Hant) .card__body,
:lang(zh-Hant) .chapter__desc,
:lang(zh-Hant) .cs-section__body p,
:lang(zh-Hant) .prose p,
:lang(zh-Hant) .prose li {
  line-height: 1.9;
  letter-spacing: 0.02em;
}
:lang(zh-Hant) .manifesto { line-height: 1.75; }
:lang(zh-Hant) .beat__eyebrow,
:lang(zh-Hant) .ph__eyebrow,
:lang(zh-Hant) .sect__label,
:lang(zh-Hant) .cs-section__label,
:lang(zh-Hant) .tag { letter-spacing: 0.14em; }

.btn-contact {
  font-size: 13px;
  font-weight: 500;
  letter-spacing: 0.06em;
  color: var(--cream-hi);
  background: var(--ink);
  padding: 11px 22px;
  border-radius: 100px;
  transition: background 0.3s ease, transform 0.3s ease;
}
.btn-contact:hover { background: var(--coral-deep); transform: translateY(-1px); }

/* ---------------- progress bar ---------------- */

.progress {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: 2px;
  z-index: 41;
  background: transparent;
}
.progress span {
  display: block;
  height: 100%;
  width: 100%;
  background: var(--coral);
  transform: scaleX(0);
  transform-origin: left;
}

/* ---------------- route rail ---------------- */

.rail {
  position: fixed;
  right: clamp(16px, 2.6vw, 36px);
  top: 50%;
  transform: translateY(-50%);
  z-index: 40;
  display: flex;
  flex-direction: column;
  gap: 18px;
}
.rail__item {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
  cursor: pointer;
  background: none; border: none;
  padding: 2px;
  font-family: var(--font-body);
}
.rail__label {
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--ink-soft);
  opacity: 0;
  transform: translateX(6px);
  transition: opacity 0.3s ease, transform 0.3s ease, color 0.3s ease;
  white-space: nowrap;
}
.rail__dot {
  width: 8px; height: 8px;
  flex: 0 0 8px;
  border-radius: 50%;
  border: 1.5px solid rgba(34, 48, 74, 0.35);
  background: transparent;
  transition: all 0.35s cubic-bezier(0.22, 1, 0.36, 1);
}
.rail__item:hover .rail__label { opacity: 1; transform: translateX(0); }
.rail__item:hover .rail__dot { border-color: var(--ink); }
.rail__item.is-active .rail__dot {
  background: var(--coral);
  border-color: var(--coral);
  transform: scale(1.45);
}
.rail__item.is-active .rail__label {
  opacity: 1;
  transform: translateX(0);
  color: var(--coral-deep);
}

/* ---------------- copy beats ---------------- */

.beat {
  position: fixed;
  z-index: 20;
  left: clamp(24px, 7vw, 100px);
  top: 50%;
  transform: translateY(calc(-46% + var(--oy, 0px)));
  max-width: 33rem;
  opacity: 0;
  pointer-events: none;
  visibility: hidden;
}
.beat.is-on { pointer-events: auto; visibility: visible; }

/* soft cream scrim so copy floats over the 3D world legibly */
.beat::before {
  content: '';
  position: absolute;
  inset: -3.4rem -4.5rem;
  z-index: -1;
  background: radial-gradient(closest-side, rgba(244, 240, 230, 0.86), rgba(244, 240, 230, 0.55) 55%, transparent 100%);
  filter: blur(4px);
}

.beat__eyebrow {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: 0.26em;
  text-transform: uppercase;
  color: var(--coral-deep);
  margin-bottom: 1.15rem;
}
.beat__eyebrow::before {
  content: '';
  width: 26px; height: 1.5px;
  background: var(--coral);
}

.beat__title {
  font-family: var(--font-display);
  font-weight: 560;
  font-variation-settings: 'opsz' 90;
  font-size: clamp(2.35rem, 4.6vw, 4.15rem);
  line-height: 1.04;
  letter-spacing: -0.015em;
  color: var(--ink);
  margin-bottom: 1.3rem;
  text-wrap: balance;
}
.beat__title em {
  font-style: italic;
  color: var(--coral-deep);
}

.beat__body {
  font-size: clamp(0.98rem, 1.25vw, 1.09rem);
  font-weight: 400;
  line-height: 1.65;
  color: var(--ink-soft);
  max-width: 27rem;
  margin-bottom: 1.5rem;
}

.beat__tags { display: flex; flex-wrap: wrap; gap: 8px; }
.beat__tags span {
  font-size: 11.5px;
  font-weight: 500;
  letter-spacing: 0.09em;
  color: var(--ink);
  border: 1px solid var(--hairline);
  background: rgba(251, 248, 241, 0.55);
  padding: 7px 14px;
  border-radius: 100px;
  backdrop-filter: blur(3px);
}

/* hero beat — centered */
.beat--hero {
  left: 50%;
  top: 50%;
  transform: translate(-50%, calc(-46% + var(--oy, 0px)));
  max-width: 46rem;
  text-align: center;
}
.beat--hero::before { inset: -4rem -6rem; }
.beat--hero .beat__eyebrow { justify-content: center; }
.beat--hero .beat__eyebrow::before { display: none; }
.beat--hero .beat__title { font-size: clamp(2.8rem, 6.2vw, 5.4rem); }
.beat--hero .beat__body { margin-left: auto; margin-right: auto; max-width: 30rem; }

.beat__def {
  font-family: var(--font-display);
  font-style: italic;
  font-weight: 400;
  font-size: clamp(0.95rem, 1.2vw, 1.05rem);
  color: var(--ink-soft);
  opacity: 0.85;
  margin-bottom: 2.2rem;
}
.beat__def b { color: var(--coral-deep); font-weight: 560; }

.hint {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  margin-top: 2.4rem;
}
.hint__ring {
  width: 42px; height: 42px;
  border: 1.5px solid rgba(34, 48, 74, 0.3);
  border-radius: 50%;
  display: grid;
  place-items: center;
  animation: hint-bob 2.4s ease-in-out infinite;
}
.hint__ring svg { display: block; }
.hint__text {
  font-size: 10.5px;
  font-weight: 500;
  letter-spacing: 0.24em;
  text-transform: uppercase;
  color: var(--ink-soft);
}
@keyframes hint-bob {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(7px); }
}

/* finale beat */
.beat--finale .beat__title { font-size: clamp(2.6rem, 5.2vw, 4.6rem); }

.beat__cta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 14px;
  margin-top: 1.9rem;
}
.btn-primary {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-size: 14.5px;
  font-weight: 500;
  letter-spacing: 0.04em;
  color: var(--cream-hi);
  background: var(--coral-deep);
  padding: 15px 30px;
  border-radius: 100px;
  transition: background 0.3s ease, transform 0.3s ease, box-shadow 0.3s ease;
  box-shadow: 0 10px 28px -10px rgba(224, 106, 74, 0.55);
}
.btn-primary:hover {
  background: var(--ink);
  transform: translateY(-2px);
  box-shadow: 0 14px 30px -10px rgba(34, 48, 74, 0.4);
}
.btn-ghost {
  display: inline-flex;
  align-items: center;
  font-size: 14.5px;
  font-weight: 500;
  letter-spacing: 0.04em;
  color: var(--ink);
  padding: 14px 26px;
  border-radius: 100px;
  border: 1.5px solid rgba(34, 48, 74, 0.28);
  transition: border-color 0.3s ease, color 0.3s ease, background 0.3s ease;
}
.btn-ghost:hover { border-color: var(--coral); color: var(--coral-deep); background: rgba(251, 248, 241, 0.6); }

.beat__social {
  display: flex;
  gap: 20px;
  margin-top: 2.1rem;
}
.beat__social a {
  font-size: 11.5px;
  font-weight: 500;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--ink-soft);
  transition: color 0.25s ease;
}
.beat__social a:hover { color: var(--coral-deep); }

/* ---------------- loader ---------------- */

.loader {
  position: fixed; inset: 0;
  z-index: 100;
  background: var(--cream);
  display: grid;
  place-items: center;
  transition: opacity 0.7s ease 0.15s, visibility 0.7s ease 0.15s;
}
body.is-ready .loader { opacity: 0; visibility: hidden; }

.loader__inner { display: flex; flex-direction: column; align-items: center; gap: 26px; }
/* the official mark, assembling piece by piece */
.loader__mark { display: block; height: 54px; width: auto; }
.loader__mark path {
  transform-box: fill-box;
  transform-origin: center;
  animation: tile-in 1.6s cubic-bezier(0.22, 1, 0.36, 1) infinite;
}
.loader__mark path:nth-child(1) { animation-delay: 0.36s; }   /* coral, last */
.loader__mark path:nth-child(2) { animation-delay: 0s; }
.loader__mark path:nth-child(3) { animation-delay: 0.12s; }
.loader__mark path:nth-child(4) { animation-delay: 0.24s; }
@keyframes tile-in {
  0% { transform: scale(0.35); opacity: 0; }
  35%, 70% { transform: scale(1); opacity: 1; }
  100% { transform: scale(0.35); opacity: 0; }
}
.loader__word {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.5em;
  text-indent: 0.5em;
  color: var(--ink-soft);
}

/* ---------------- custom cursor ---------------- */

.cursor {
  position: fixed;
  z-index: 200;
  top: 0; left: 0;
  width: 34px; height: 34px;
  margin: -17px 0 0 -17px;
  border: 1.5px solid var(--coral);
  border-radius: 50%;
  pointer-events: none;
  transition: transform 0.2s ease, opacity 0.3s ease;
  opacity: 0;
}
.cursor::after {
  content: '';
  position: absolute;
  top: 50%; left: 50%;
  width: 4px; height: 4px;
  margin: -2px 0 0 -2px;
  border-radius: 50%;
  background: var(--coral);
}
body.has-cursor .cursor { opacity: 1; }
body.cursor-hover .cursor { transform: scale(1.6); background: rgba(240, 127, 95, 0.12); }
@media (hover: none) { .cursor { display: none; } }

/* ---------------- reduced motion / no-webgl fallback ---------------- */

.rm #scene, .rm .rail, .rm .scroll-space, .rm .grain, .rm .cursor, .rm .hint { display: none; }
.rm body, body.rm { overflow-x: hidden; }
.rm .beat {
  position: relative;
  top: auto; left: auto;
  transform: none !important;
  opacity: 1 !important;
  visibility: visible;
  pointer-events: auto;
  max-width: 44rem;
  margin: 0 auto;
  padding: 18vh clamp(24px, 7vw, 60px);
  border-bottom: 1px solid var(--hairline);
}
.rm .beat::before { display: none; }
.rm .beat--hero { text-align: center; padding-top: 26vh; }
.rm main { position: relative; z-index: 5; padding-top: 60px; }

/* ---------------- responsive ---------------- */

@media (max-width: 860px) {
  .topnav__link { display: none; }
  .rail { display: none; }

  .beat {
    left: 6vw;
    right: 6vw;
    top: auto;
    bottom: calc(env(safe-area-inset-bottom, 0px) + 7.5vh);
    transform: translateY(var(--oy, 0px));
    max-width: none;
  }
  .beat::before { inset: -2rem -2.5rem; }
  .beat--hero {
    left: 6vw; right: 6vw;
    top: 50%; bottom: auto;
    transform: translateY(calc(-50% + var(--oy, 0px)));
    text-align: center;
  }
  .beat__title { font-size: clamp(1.9rem, 8.4vw, 2.6rem); }
  .beat--hero .beat__title { font-size: clamp(2.2rem, 10vw, 3rem); }
  .beat__body { font-size: 0.95rem; margin-bottom: 1rem; }
  .beat__tags span { padding: 6px 12px; font-size: 10.5px; }
  .hint { margin-top: 1.6rem; }
  .beat__cta { gap: 10px; }
  .btn-primary { padding: 13px 24px; font-size: 13.5px; }
  .btn-ghost { padding: 12px 20px; font-size: 13.5px; }
  .beat__social { gap: 14px; margin-top: 1.5rem; flex-wrap: wrap; }
}

@media (max-width: 400px) {
  .brand__logo { height: 20px; }
  .btn-contact { padding: 9px 16px; font-size: 12px; }
}
