/* =====================================================================
   GT Dynamics — base.css
   Reset, typography, links, containers, grids, sections, dot-grid page,
   scrollbars, selection, skip-link, utilities, reveal, reduced motion,
   Lite performance tier (html[data-perf="lite"], GTD.perf).
   Owner: web-design-system. Values ONLY from tokens.css (var(--…)).
   Spec: docs/DESIGN.md §2–§5
   ===================================================================== */

/* ---------- 1. Reset ---------- */
*, *::before, *::after { box-sizing: border-box; }

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  -moz-tab-size: 4;
  tab-size: 4;
  scroll-padding-top: calc(var(--header-h) + var(--sp-4));
  scrollbar-color: var(--bg-6) var(--bg-0);
  scrollbar-width: thin;
  interpolate-size: allow-keywords;          /* smooth <details> open (progressive) */
  background-color: var(--bg-0);
}

@media (prefers-reduced-motion: no-preference) {
  html { scroll-behavior: smooth; }
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  font-family: var(--font-body);
  font-size: var(--fs-base);
  font-weight: 400;
  line-height: var(--lh-body);
  color: var(--text-2);
  background-color: var(--bg-0);
  background-image: var(--dot-grid);
  background-size: var(--grid-size) var(--grid-size);
  background-position: calc(var(--grid-size) / -2) calc(var(--grid-size) / -2);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  font-feature-settings: "cv11", "calt";
  overflow-x: clip;
}

/* layout.js mounts: the wrappers must not create boxes, otherwise the
   sticky header would only stick inside its own wrapper. */
#gtd-header, #gtd-footer { display: contents; }

main { flex: 1 0 auto; display: block; }
main:focus { outline: none; }

:where(h1, h2, h3, h4, h5, h6, p, figure, blockquote, dl, dd, pre) { margin: 0; }
:where(ul, ol) { margin: 0; padding-left: 1.25em; }
:where(ul, ol)[role="list"], .list-reset { list-style: none; padding: 0; margin: 0; }
:where(img, picture, video, canvas) { display: block; max-width: 100%; height: auto; }
:where(svg) { flex-shrink: 0; }
:where(input, button, textarea, select) { font: inherit; color: inherit; letter-spacing: inherit; }
:where(button) { background: none; border: 0; padding: 0; margin: 0; cursor: pointer; text-align: inherit; }
:where(button:disabled, [aria-disabled="true"]) { cursor: not-allowed; }
:where(table) { border-collapse: collapse; border-spacing: 0; }
:where(fieldset) { margin: 0; padding: 0; border: 0; min-width: 0; }
:where(legend) { padding: 0; }
:where(summary) { cursor: pointer; }
/* One cursor standard for the whole site (Bizhan 2026-12-05): the normal arrow everywhere — no text I-beam over
   headings or copy — and the hand on everything you can click. Only fields you type into keep the I-beam.
   :where() keeps these at zero specificity, so a component's own cursor (zoom-in, grab, not-allowed) still wins. */
:where(html) { cursor: default; caret-color: transparent; }   /* no blinking text caret when you click on copy (caret browsing, Bizhan 2026-12-05) */
:where(a[href], [role="button"], [role="link"], [role="tab"], [role="menuitem"], [role="option"], [role="switch"],
  [role="checkbox"], [role="radio"], label[for], select, input[type="checkbox"], input[type="radio"],
  input[type="range"], input[type="color"], input[type="file"], input[type="submit"], input[type="button"],
  input[type="reset"]) { cursor: pointer; }
:where(input:not([type]), input[type="text"], input[type="email"], input[type="search"], input[type="password"],
  input[type="tel"], input[type="url"], input[type="number"], textarea, [contenteditable="true"]) { cursor: text; caret-color: auto; }
:where(dialog) { color: inherit; }
:where(address) { font-style: normal; }
[hidden] { display: none !important; }

/* ---------- 2. Typography ---------- */
:where(h1, h2, h3, h4, h5, h6) {
  font-family: var(--font-display);
  color: var(--text-1);
  font-weight: 600;
  line-height: var(--lh-snug);
  letter-spacing: var(--tracking-display);
  text-wrap: balance;
}
:where(h1) { font-size: var(--fs-3xl); font-weight: 700; line-height: 1.08; }
:where(h2) { font-size: var(--fs-2xl); }
:where(h3) { font-size: var(--fs-lg); }
:where(h4) { font-size: var(--fs-md); }
:where(h5, h6) { font-size: var(--fs-base); }
:where(p, li, dd, blockquote) { text-wrap: pretty; }
:where(strong, b) { font-weight: 600; color: var(--text-1); }
:where(small) { font-size: var(--fs-sm); }

/* Heading scale as classes (when the semantic level differs from the look) */
.h-hero { font-family: var(--font-display); font-size: var(--fs-hero); font-weight: 700; line-height: var(--lh-tight); letter-spacing: var(--tracking-display); color: var(--text-1); text-wrap: balance; }
.h1 { font-family: var(--font-display); font-size: var(--fs-3xl); font-weight: 700; line-height: 1.08; color: var(--text-1); }
.h2 { font-family: var(--font-display); font-size: var(--fs-2xl); font-weight: 600; line-height: var(--lh-snug); color: var(--text-1); }
.h3 { font-family: var(--font-display); font-size: var(--fs-lg); font-weight: 600; line-height: var(--lh-snug); color: var(--text-1); }
.h4 { font-family: var(--font-display); font-size: var(--fs-md); font-weight: 600; line-height: var(--lh-snug); color: var(--text-1); }

.lead { font-size: var(--fs-md); line-height: var(--lh-body); color: var(--text-2); max-width: 60ch; }
.text-sm { font-size: var(--fs-sm); }
.text-xs { font-size: var(--fs-xs); }

/* Mono label (spec / meta / small caps marking) */
.meta {
  font-family: var(--font-mono);
  font-size: var(--fs-xs);
  font-weight: 500;
  letter-spacing: var(--tracking-caps);
  text-transform: uppercase;
  color: var(--text-3);
}

:where(code, kbd, samp, pre) { font-family: var(--font-mono); font-size: 0.875em; }
:where(code):not([class]) {
  padding: 0.12em 0.4em;
  border-radius: var(--r-xs);
  background: var(--bg-2);
  border: 1px solid var(--line-1);
  color: var(--text-1);
  overflow-wrap: anywhere;
}
:where(pre) {
  padding: var(--sp-4);
  border-radius: var(--r-md);
  background: var(--bg-2);
  border: 1px solid var(--line-1);
  color: var(--text-1);
  overflow-x: auto;
  line-height: 1.6;
}
:where(hr) { height: 1px; margin: var(--sp-8) 0; border: 0; background: var(--line-2); }

/* Japanese: no wide tracking / uppercase on headings, phrase-aware breaking */
html[lang="ja"] body { line-break: strict; }
html[lang="ja"] :where(h1, h2, h3, h4, h5, h6, .h-hero, .h1, .h2, .h3, .h4, .lead) {
  letter-spacing: 0;
  word-break: auto-phrase;
}
html[lang="ja"] :where(h1, .h1) { line-height: var(--lh-snug); }
html[lang="ja"] .h-hero { line-height: 1.2; }

/* ---------- 3. Links ---------- */
:where(a) {
  color: var(--text-1);
  text-decoration-line: underline;
  text-decoration-color: var(--line-3);
  text-decoration-thickness: 1px;
  text-underline-offset: 0.22em;
  transition: color var(--dur-1) var(--ease), text-decoration-color var(--dur-1) var(--ease);
}
:where(a:hover) { text-decoration-color: var(--brand); }
:where(a:not([href])) { text-decoration: none; }

/* ---------- 4. Focus ---------- */
:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
}
:focus:not(:focus-visible) { outline: none; }

/* ---------- 5. Selection & scrollbars ---------- */
::selection { background: var(--brand-soft-2); color: var(--text-1); }

::-webkit-scrollbar { width: 12px; height: 12px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background-color: var(--bg-6);
  border-radius: var(--r-pill);
  border: 3px solid transparent;
  background-clip: padding-box;
}
::-webkit-scrollbar-thumb:hover { background-color: var(--text-4); }
::-webkit-scrollbar-corner { background: transparent; }

.scroll-thin { scrollbar-width: thin; scrollbar-color: var(--bg-6) transparent; }
.scroll-none { scrollbar-width: none; }
.scroll-none::-webkit-scrollbar { display: none; }

/* Scroll lock (drawer / modal) — set by GTD.lockScroll() */
html.gtd-locked { overflow: hidden; }
html.gtd-locked body { padding-right: var(--gtd-sbw, 0px); }

/* ---------- 6. Skip link ---------- */
.skip-link {
  position: fixed;
  top: var(--sp-3);
  left: var(--sp-3);
  z-index: calc(var(--z-toast) + 10);
  display: inline-flex;
  align-items: center;
  height: var(--sp-10);
  padding-inline: var(--sp-4);
  border-radius: var(--r-md);
  background: var(--brand);
  color: var(--brand-ink);
  font-size: var(--fs-sm);
  font-weight: 600;
  text-decoration: none;
  transform: translateY(calc(-100% - var(--sp-6)));
  transition: transform var(--dur-2) var(--ease-out);
}
.skip-link:focus, .skip-link:focus-visible {
  transform: none;
  outline: none;
  box-shadow: var(--ring);
}

/* ---------- 7. Containers ---------- */
.container {
  width: 100%;
  max-width: var(--container);
  margin-inline: auto;
  padding-inline: var(--gutter);
}
.container--wide { max-width: var(--container-wide); }
.container--narrow { max-width: calc(var(--container) * 0.68); }
.container--flush { padding-inline: 0; }

/* ---------- 8. Sections ---------- */
.section { position: relative; padding-block: var(--section-y); }
.section--alt {
  background-color: var(--bg-1);
  border-block: 1px solid var(--line-1);
}
.section--grid {
  background-color: var(--bg-1);
  background-image: var(--dot-grid);
  background-size: var(--grid-size) var(--grid-size);
  border-block: 1px solid var(--line-1);
}
.section--tight { padding-block: calc(var(--section-y) * 0.6); }
.section--flush-top { padding-top: 0; }
.section--flush-bottom { padding-bottom: 0; }

/* ---------- 9. Grids ----------
   .grid + .grid--2/3/4: auto-fill with a column cap (never more than N
   columns, never narrower than --grid-min). ≤720 px → one column.
   .grid--fit: items stretch to fill the row (auto-fit). */
.grid {
  --grid-cols: 3;
  --grid-min: 260px;
  --grid-gap: var(--sp-6);
  display: grid;
  gap: var(--grid-gap);
  grid-template-columns: repeat(
    auto-fill,
    minmax(max(var(--grid-min), (100% - (var(--grid-cols) - 1) * var(--grid-gap)) / var(--grid-cols)), 1fr)
  );
}
.grid--2 { --grid-cols: 2; --grid-min: 320px; }
.grid--3 { --grid-cols: 3; --grid-min: 260px; }
.grid--4 { --grid-cols: 4; --grid-min: 220px; }
.grid--fit {
  grid-template-columns: repeat(
    auto-fit,
    minmax(max(var(--grid-min), (100% - (var(--grid-cols) - 1) * var(--grid-gap)) / var(--grid-cols)), 1fr)
  );
}
.grid--tight { --grid-gap: var(--sp-4); }
.grid--loose { --grid-gap: var(--sp-8); }
@media (max-width: 720px) {
  .grid, .grid--fit { grid-template-columns: minmax(0, 1fr); }
}

/* Two-column split (text + visual) → stacks at ≤960 */
.split {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: var(--sp-12);
  align-items: center;
}
.split--start { align-items: start; }
.split--wide-left { grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr); }
.split--wide-right { grid-template-columns: minmax(0, 1fr) minmax(0, 1.25fr); }
@media (max-width: 960px) {
  .split, .split--wide-left, .split--wide-right { grid-template-columns: minmax(0, 1fr); gap: var(--sp-10); }
}

/* Flow helpers */
.stack { display: flex; flex-direction: column; gap: var(--stack-gap, var(--sp-4)); }
.stack--sm { --stack-gap: var(--sp-2); }
.stack--lg { --stack-gap: var(--sp-8); }
.cluster { display: flex; flex-wrap: wrap; align-items: center; gap: var(--cluster-gap, var(--sp-3)); }
.cluster--sm { --cluster-gap: var(--sp-2); }
.cluster--lg { --cluster-gap: var(--sp-6); }
.cluster--end { justify-content: flex-end; }
.cluster--between { justify-content: space-between; }
.flow { --flow-space: 1em; }
.flow > * + * { margin-top: var(--flow-space); }

/* Long-form text */
.prose { max-width: 68ch; color: var(--text-2); }
.prose > * + * { margin-top: 1em; }
.prose :where(h2, h3, h4) { margin-top: 1.6em; }
.prose :where(h2, h3, h4) + * { margin-top: 0.6em; }
.prose :where(ul, ol) { padding-left: 1.25em; }
.prose :where(li + li) { margin-top: 0.4em; }
.prose :where(li)::marker { color: var(--text-4); }

/* ---------- 10. Engineering backgrounds ---------- */
.dot-grid {
  background-image: var(--dot-grid);
  background-size: var(--grid-size) var(--grid-size);
}
/* Soft yellow radial glow (hero). Decorative, alpha ≤ 0.12 */
.glow {
  position: absolute;
  width: min(720px, 120vw);
  aspect-ratio: 1;
  border-radius: 50%;
  background: radial-gradient(closest-side, color-mix(in srgb, var(--brand) 12%, transparent), transparent);
  pointer-events: none;
  z-index: 0;
}

/* ---------- 11. Utilities ---------- */
.visually-hidden, .sr-only {
  position: absolute !important;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}
.mono { font-family: var(--font-mono); }
.tabular { font-variant-numeric: tabular-nums; }
.upper { text-transform: uppercase; letter-spacing: var(--tracking-caps); }
.text-1 { color: var(--text-1); }
.text-2 { color: var(--text-2); }
.text-3 { color: var(--text-3); }
.text-4 { color: var(--text-4); }
.text-brand { color: var(--brand); }
.text-ok { color: var(--ok); }
.text-info { color: var(--info); }
.text-warn { color: var(--warn); }
.text-danger { color: var(--danger); }
.text-center { text-align: center; }
.text-balance { text-wrap: balance; }
.nowrap { white-space: nowrap; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.w-full { width: 100%; }
.mt-auto { margin-top: auto; }
.mx-auto { margin-inline: auto; }
.mt-0 { margin-top: 0; }
.mt-2 { margin-top: var(--sp-2); }
.mt-4 { margin-top: var(--sp-4); }
.mt-6 { margin-top: var(--sp-6); }
.mt-8 { margin-top: var(--sp-8); }
.mt-12 { margin-top: var(--sp-12); }
.mb-0 { margin-bottom: 0; }
.mb-4 { margin-bottom: var(--sp-4); }
.mb-8 { margin-bottom: var(--sp-8); }
.relative { position: relative; }
@media (max-width: 720px) { .hide-sm { display: none !important; } }
@media (min-width: 721px) { .show-sm { display: none !important; } }
@media (max-width: 960px) { .hide-md { display: none !important; } }
@media (min-width: 961px) { .show-md { display: none !important; } }

/* ---------- 12. Reveal on scroll (GTD.reveal) ----------
   Hidden state applies only when JS is running (html.gtd-js). */
/* lead: reveal is a one-shot animation (fill-mode backwards), not a persistent
   transition/transform — so once revealed, a card's own :hover lift and
   hover transitions work again (a transform: none here used to override them). */
html.gtd-js [data-reveal] { --reveal-from: translateY(14px); }
html.gtd-js [data-reveal="fade"] { --reveal-from: none; }
html.gtd-js [data-reveal="scale"] { --reveal-from: scale(0.97); }
html.gtd-js [data-reveal="left"] { --reveal-from: translateX(-14px); }
html.gtd-js [data-reveal="right"] { --reveal-from: translateX(14px); }
html.gtd-js [data-reveal]:not(.is-revealed) { opacity: 0; }
html.gtd-js [data-reveal].is-revealed {
  animation: gtd-reveal var(--dur-4) var(--ease-out) var(--reveal-delay, 0ms) backwards;
}
@keyframes gtd-reveal { from { opacity: 0; transform: var(--reveal-from); } }

/* ---------- 13. Keyframes (shared) ---------- */
@keyframes gtd-fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes gtd-fade-out { from { opacity: 1; } to { opacity: 0; } }
@keyframes gtd-rise-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@keyframes gtd-pop-in { from { opacity: 0; transform: translateY(6px) scale(0.98); } to { opacity: 1; transform: none; } }
@keyframes gtd-pop-out { from { opacity: 1; transform: none; } to { opacity: 0; transform: translateY(4px) scale(0.98); } }
@keyframes gtd-spin { to { transform: rotate(360deg); } }
@keyframes gtd-pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.35; } }

/* ---------- 14. Reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
  html.gtd-js [data-reveal]:not(.is-revealed) { opacity: 1; }
  html.gtd-js [data-reveal].is-revealed { animation: none; }
}

/* ---------- 15. Lite performance tier (GTD.perf → html[data-perf="lite"]) ----------
   Same look, cheaper paint (DESIGN.md §13). core.js sets the attribute before
   the first paint; "high" = no overrides. Here: lighter elevation tokens, no
   backdrop blur anywhere, instant reveal. Components and pages add their own
   lite rules (solid sticky bars, no infinite decorative animations). */
html[data-perf="lite"] {
  /* small blur radii instead of 24–56 px soft shadows and the yellow halo */
  --shadow-2: var(--shadow-1);
  --shadow-3: var(--shadow-1), 0 8px 16px -8px var(--bg-0);
  --brand-glow: 0 0 0 1px var(--brand-line);
}
/* safety net for every stylesheet (translucent bars get solid tokens in their own lite rules) */
html[data-perf="lite"] *,
html[data-perf="lite"] *::before,
html[data-perf="lite"] *::after {
  -webkit-backdrop-filter: none !important;
  backdrop-filter: none !important;
}
html[data-perf="lite"].gtd-js [data-reveal]:not(.is-revealed) { opacity: 1; }
html[data-perf="lite"].gtd-js [data-reveal].is-revealed { animation: none; }

/* ---------- 16. Print ---------- */
@media print {
  body { background: none; color: var(--bg-0); }
  .site-header, .site-footer, .drawer, .toast-stack, .announce, .skip-link { display: none !important; }
}
