/* Nambyte brand stylesheet — the single source of truth for the brand.
   Palette, type, spacing, and radii come from the Nambyte brand book (rev 11)
   and USAGE.md. Do not hard-code a colour or a font anywhere else.
   No gradients, no drop shadows, no pure black, no red. */

/* ---------- Type ----------
   Manrope ExtraBold    wordmark and interface
   JetBrains Mono       data and labels
   Noto Sans Thai       Thai, SemiBold, at 92% of the Latin size
   All three are OFL and self-hosted from assets/fonts (variable woff2). */
@font-face {
  font-family: "Manrope";
  font-style: normal;
  font-weight: 400 800;
  font-display: swap;
  src: url("fonts/manrope-latin.woff2") format("woff2");
}
@font-face {
  font-family: "JetBrains Mono";
  font-style: normal;
  font-weight: 400 700;
  font-display: swap;
  src: url("fonts/jetbrains-mono-latin.woff2") format("woff2");
}
@font-face {
  font-family: "Noto Sans Thai";
  font-style: normal;
  font-weight: 100 900;
  font-display: swap;
  src: url("fonts/noto-sans-thai-thai.woff2") format("woff2");
}

/* ---------- Tokens ---------- */
:root {
  /* Brand palette. */
  --deep-current: #0b3b3c; /* mark body, headings, dark surfaces */
  --aqua-current: #1fb6a6; /* accent: data, links, focus, charts */
  --cream-water: #e9f5f1;  /* water current on dark, tints and panels */
  --temple-gold: #c9a227;  /* committed: byte and gold rule */
  --ink-deep: #10201f;     /* dark-mode surface */
  --paper: #fbfaf7;        /* page ground */
  --muted-ink: #5c6270;    /* descriptor and secondary text */

  /* Semantic roles — light ground (default). */
  --bg: var(--paper);
  --panel: color-mix(in srgb, var(--cream-water) 55%, var(--paper));
  --fg: var(--deep-current);
  --muted: var(--muted-ink);
  --line: color-mix(in srgb, var(--deep-current) 16%, var(--paper));
  --link: var(--deep-current);
  --link-rule: var(--aqua-current);                /* Aqua underline keeps the accent */
  --focus: var(--deep-current);                    /* 11:1 on Paper */

  /* Spacing scale (4 px base) and radii. */
  --s1: 0.25rem;
  --s2: 0.5rem;
  --s3: 0.75rem;
  --s4: 1rem;
  --s5: 1.5rem;
  --s6: 2rem;
  --s7: 3rem;
  --r1: 0.25rem;
  --r2: 0.5rem;
  --r3: 0.75rem;
  --r4: 1rem;

  --measure: 40rem;
  --page: 68rem;
}

/* Noto Sans Thai runs at 92% of the Latin size. */
:root { --thai-scale: 0.92; }

/* Dark ground: Ink Deep surface, Cream Water text. Never the deep disc here. */
@media (prefers-color-scheme: dark) {
  :root {
    --bg: var(--ink-deep);
    --panel: color-mix(in srgb, var(--aqua-current) 9%, var(--ink-deep));
    --fg: var(--cream-water);
    --muted: color-mix(in srgb, var(--cream-water) 62%, var(--ink-deep));
    --line: color-mix(in srgb, var(--cream-water) 18%, var(--ink-deep));
    --link: var(--aqua-current);
    --link-rule: var(--aqua-current);
    --focus: var(--aqua-current);                  /* 6.6:1 on Ink Deep */
  }
}

/* ---------- Reset ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100svh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--fg);
  font-family: "Manrope", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 1rem;
  font-weight: 500;
  line-height: 1.6;
  text-rendering: optimizeLegibility;
}
img, svg { display: block; max-width: 100%; }
a { color: var(--link); text-decoration-color: var(--link-rule); text-decoration-thickness: 0.14em; text-underline-offset: 0.18em; }
a:hover { text-decoration-thickness: 0.22em; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 3px; border-radius: var(--r1); }

/* ---------- Language ----------
   Thai is set in Noto Sans Thai at 92% of the Latin size, and it comes first
   in the DOM. Both languages are in the HTML, so the page reads with
   JavaScript off. A tiny script selects one when JavaScript is on. */
[lang="th"]:not(html) {
  font-family: "Noto Sans Thai", "Manrope", system-ui, sans-serif;
  font-weight: 600;
  font-size: calc(1em * var(--thai-scale));
}
h1 [lang="th"], h2 [lang="th"] { font-weight: 600; }

.js[data-lang="th"] .i18n-en { display: none; }
.js[data-lang="en"] .i18n-th { display: none; }
.no-js .i18n-th + .i18n-en { margin-top: var(--s2); }

/* ---------- Layout ---------- */
.skip-link {
  position: absolute;
  left: -100vw;
  top: 0;
  z-index: 10;
  padding: var(--s3) var(--s4);
  background: var(--deep-current);
  color: var(--cream-water);
  border-radius: 0 0 var(--r3) 0;
}
.skip-link:focus { left: 0; }

.wrap { width: 100%; max-width: var(--page); margin: 0 auto; padding-inline: clamp(1.25rem, 5vw, 2.5rem); }

.site-header { padding-block: var(--s5); }
.site-header .wrap { display: flex; align-items: center; justify-content: space-between; gap: var(--s4); }
.brand { display: inline-flex; align-items: center; }
.brand img { height: 40px; width: auto; }
.brand .for-dark { display: none; }
@media (prefers-color-scheme: dark) {
  .brand .for-light { display: none; }
  .brand .for-dark { display: block; }
}

.langs { display: flex; gap: var(--s1); }
.langs button {
  font: inherit;
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--muted);
  background: none;
  border: 0;
  border-radius: var(--r2);
  padding: var(--s2) var(--s3);
  cursor: pointer;
}
.langs button:hover { color: var(--fg); background: var(--panel); }
.langs button[aria-pressed="true"] { color: var(--fg); background: var(--panel); }
.no-js .langs { display: none; }

main { flex: 1; }

/* ---------- Hero ---------- */
.hero { padding-block: clamp(1.5rem, 6vw, 4rem) var(--s7); }
.hero .measure { max-width: var(--measure); }
.mark { width: 104px; height: 104px; margin-bottom: var(--s5); }
.eyebrow {
  margin: 0 0 var(--s4);
  font-family: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.72rem;
  font-weight: 500;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--muted);
}
h1 {
  margin: 0 0 var(--s4);
  font-size: clamp(2.1rem, 8vw, 3.1rem);
  font-weight: 800;
  line-height: 1.1;
  letter-spacing: -0.02em;
}
h1 [lang="th"] { display: block; }
.lead {
  margin: 0 0 var(--s6);
  font-size: clamp(1rem, 3.4vw, 1.12rem);
  color: var(--muted);
  max-width: 34rem;
}
.lead [lang="th"] { display: block; }

.actions { display: flex; flex-wrap: wrap; gap: var(--s3); align-items: center; }
.btn {
  display: inline-block;
  padding: 0.7rem 1.15rem;
  border-radius: var(--r2);
  font-weight: 800;
  font-size: 0.95rem;
  letter-spacing: -0.01em;
  text-decoration: none;
  background: var(--deep-current);   /* never Gold in a button */
  color: var(--cream-water);
  border: 1px solid var(--deep-current);
}
.btn:hover { background: color-mix(in srgb, var(--deep-current) 82%, var(--ink-deep)); }
@media (prefers-color-scheme: dark) {
  .btn { background: var(--cream-water); color: var(--ink-deep); border-color: var(--cream-water); }
  .btn:hover { background: var(--aqua-current); border-color: var(--aqua-current); color: var(--ink-deep); }
}

/* ---------- Content blocks (scaffold pages) ---------- */
.section { padding-block: var(--s6); }
.section + .section { border-top: 1px solid var(--line); }
h2 { margin: 0 0 var(--s3); font-size: clamp(1.3rem, 4vw, 1.7rem); font-weight: 800; letter-spacing: -0.02em; }
h2 [lang="th"], h3 [lang="th"] { display: block; }
h3 { margin: 0 0 var(--s2); font-size: 1.05rem; font-weight: 800; }
p { margin: 0 0 var(--s4); }
p:last-child { margin-bottom: 0; }
.label {
  font-family: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.72rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
}

.cards { display: grid; gap: var(--s4); grid-template-columns: 1fr; margin-top: var(--s5); }
@media (min-width: 44rem) { .cards { grid-template-columns: repeat(3, 1fr); } }
.card {
  border: 1px solid var(--line);
  border-radius: var(--r4);
  padding: var(--s5);
  background: var(--bg);
}
.card .label { display: block; margin-bottom: var(--s3); }
.card p { color: var(--muted); margin: 0; }

/* ---------- Footer ---------- */
.site-footer { border-top: 1px solid var(--line); padding-block: var(--s5); margin-top: var(--s6); }
.site-footer .wrap { display: flex; flex-wrap: wrap; gap: var(--s3) var(--s5); justify-content: space-between; align-items: baseline; }
.site-footer nav { display: flex; flex-wrap: wrap; gap: var(--s4); }
.site-footer nav a { font-size: 0.85rem; font-weight: 600; text-decoration: none; }
.site-footer nav a:hover { text-decoration: underline; text-decoration-color: var(--link-rule); }
.colophon { margin: 0; font-size: 0.8rem; color: var(--muted); }

/* ---------- Motion ----------
   Phase 1 of the Nambyte motion system: A1 The Currents Draw, B1 Nam Flow
   Loader, B4 The Current Band. Exact values and the reasoning live in
   docs/nambyte-motion-spec.md. Animate transform and opacity only; SVG
   stroke-dashoffset only on the small mark and the dividers. Temple Gold is
   the byte and nothing else. Motion is an enhancement: the page is complete
   with JavaScript off and with reduced motion on. */

/* Motion tokens (one source of truth). */
:root {
  --motion-micro: 120ms;
  --motion-ui: 240ms;
  --motion-section: 400ms;
  --motion-brand: 900ms;
  --ease-enter: cubic-bezier(0.2, 0, 0, 1);
  --ease-current: linear;
  --ease-loop: ease-in-out;
  --loop-min: 12s;
  --loop-max: 20s;
}

/* A1 · The Currents Draw. The disc is painted at frame one. The aqua current
   draws left to right and the cream current right to left; they arrive at the
   byte together. The byte lands last with one settle. */
.nam-mark--draw .nam-mark__current { stroke-dasharray: 100; }
.nam-mark--draw .nam-mark__current--aqua {
  stroke-dashoffset: 100;
  animation: nam-draw-forward var(--motion-brand) var(--ease-enter) both;
}
.nam-mark--draw .nam-mark__current--cream {
  stroke-dashoffset: -100;
  animation: nam-draw-backward var(--motion-brand) var(--ease-enter) both;
}
.nam-mark--draw .nam-mark__byte {
  transform-box: fill-box;
  transform-origin: 50% 50%;
  opacity: 0;
  animation: nam-byte-settle 280ms var(--ease-enter) 620ms both;
}
@keyframes nam-draw-forward { from { stroke-dashoffset: 100; } to { stroke-dashoffset: 0; } }
@keyframes nam-draw-backward { from { stroke-dashoffset: -100; } to { stroke-dashoffset: 0; } }
@keyframes nam-byte-settle { from { opacity: 0; transform: scale(1.06); } to { opacity: 1; transform: scale(1); } }
@keyframes nam-fade { from { opacity: 0; } to { opacity: 1; } }

/* B1 · Nam Flow Loader. One aqua current travels the ring; the byte rides the
   head and stays upright. Shown only while the next page loads, and only when
   JavaScript runs. */
.nam-loader {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: none;
  place-items: center;
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  pointer-events: none;
}
.js.is-navigating .nam-loader { display: grid; }
.nam-loader__track { stroke: var(--line); }
.nam-loader__orbit {
  transform-origin: 56px 56px;
  animation: nam-orbit 1.2s var(--ease-current) infinite;
}
.nam-loader__byte {
  transform-box: fill-box;
  transform-origin: 50% 50%;
  animation: nam-orbit-back 1.2s var(--ease-current) infinite;
}
@keyframes nam-orbit { from { transform: rotate(0deg); } to { transform: rotate(360deg); } }
@keyframes nam-orbit-back { from { transform: rotate(0deg); } to { transform: rotate(-360deg); } }

/* B4 · The Current Band. A thin deep band crosses the top edge once per page
   load. The leading edge is aqua; the head carries a 4 px gold byte. CSS only,
   so it also runs with JavaScript off. */
.nam-band {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  z-index: 30;
  background: var(--deep-current);
  pointer-events: none;
  transform: translateX(-101%);
  animation: nam-band-cross var(--motion-section) var(--ease-enter) both;
}
.nam-band::after {
  content: "";
  position: absolute;
  top: 0;
  right: 7px; /* 4 px byte + 3 px deep gap: gold and aqua never touch */
  width: 3rem;
  height: 100%;
  background: var(--aqua-current);
}
.nam-band__head {
  position: absolute;
  top: 50%;
  right: 0;
  width: 4px;
  height: 4px;
  margin-top: -2px;
  background: var(--temple-gold);
  outline: 1px solid var(--deep-current);
}
@keyframes nam-band-cross { from { transform: translateX(-101%); } to { transform: translateX(101%); } }

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
  /* Keep the mark's final state and one short fade. Remove the traveling
     current (B1) and the band (B4). */
  .nam-mark { animation: nam-fade var(--motion-ui) var(--ease-enter) both !important; }
  .nam-mark--draw .nam-mark__current { stroke-dashoffset: 0 !important; }
  .nam-mark--draw .nam-mark__byte { opacity: 1 !important; transform: none !important; }
  .nam-loader,
  .nam-band { display: none !important; }
}
