:root {
  --bg: #07080c;
  --bg-2: #0c0e14;
  --surface: #12151d;
  --surface-2: #181c27;
  --line: rgba(212, 184, 116, 0.16);
  --line-strong: rgba(212, 184, 116, 0.38);
  --gold: #d4b874;
  --gold-2: #f0e0b0;
  --cyan: #7ed0dc;
  --cyan-2: #b7eef4;
  --ink: #efe8d8;
  --muted: #9a9386;
  --dim: #6c675d;
  --danger: #d07058;
  --ok: #8fbf88;
  --accent: var(--gold);
  --accent-2: var(--gold-2);
  --shadow: 0 24px 80px rgba(0, 0, 0, 0.45);
  --radius: 18px;
  --header-h: 72px;
  --font-display: "Cormorant Garamond", "Noto Serif SC", serif;
  --font-sans: "Outfit", "Noto Sans SC", sans-serif;
  --font-serif: "Noto Serif SC", "Cormorant Garamond", serif;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
}

body[data-realm="physics"] {
  --accent: var(--cyan);
  --accent-2: var(--cyan-2);
  --line: rgba(126, 208, 220, 0.16);
  --line-strong: rgba(126, 208, 220, 0.38);
}

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

html, body { margin: 0; padding: 0; }
html { scroll-behavior: smooth; }

body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-sans);
  font-weight: 400;
  line-height: 1.65;
  min-height: 100vh;
  overflow-x: hidden;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background:
    radial-gradient(1200px 600px at 10% -10%, rgba(212, 184, 116, 0.07), transparent 55%),
    radial-gradient(900px 500px at 110% 10%, rgba(126, 208, 220, 0.06), transparent 50%),
    linear-gradient(180deg, transparent, rgba(0,0,0,0.25));
  z-index: 0;
}

img { max-width: 100%; display: block; }
a { color: inherit; text-decoration: none; }
button { font-family: inherit; cursor: pointer; }
code, .mono { font-family: "JetBrains Mono", ui-monospace, monospace; }

.skip {
  position: absolute;
  left: -999px;
  top: 8px;
  background: var(--gold);
  color: #111;
  padding: 8px 12px;
  z-index: 1000;
}
.skip:focus { left: 8px; }

.site-header {
  position: sticky;
  top: 0;
  z-index: 50;
  height: var(--header-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 28px;
  background: rgba(7, 8, 12, 0.78);
  backdrop-filter: blur(18px);
  border-bottom: 1px solid var(--line);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 180px;
}
.brand-mark {
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
}
.brand-mark svg { width: 36px; height: 36px; }
.brand-text { display: flex; flex-direction: column; line-height: 1.05; }
.brand-text strong {
  font-family: var(--font-display);
  font-size: 22px;
  font-weight: 600;
  letter-spacing: 0.18em;
}
.brand-text span {
  font-size: 11px;
  color: var(--muted);
  letter-spacing: 0.22em;
  text-transform: uppercase;
}

.nav {
  display: flex;
  align-items: stretch;
  gap: 2px;
  height: 100%;
}
.nav-item { position: relative; height: 100%; display: flex; align-items: center; }
.nav-item > a,
.nav-item > button.nav-link {
  background: none;
  border: 0;
  color: var(--ink);
  font-size: 13.5px;
  letter-spacing: 0.06em;
  padding: 8px 12px;
  opacity: 0.82;
  display: flex;
  align-items: center;
  gap: 6px;
  height: 100%;
  white-space: nowrap;
}
.nav-item > a:hover,
.nav-item > button.nav-link:hover,
.nav-item:focus-within > a,
.nav-item:focus-within > button.nav-link,
.nav-item.is-active > a {
  opacity: 1;
  color: var(--accent-2);
}
.nav-caret { font-size: 9px; opacity: 0.6; }

.mega {
  display: none;
  position: absolute;
  top: calc(100% - 1px);
  left: 50%;
  transform: translateX(-50%);
  min-width: 320px;
  background: rgba(14, 16, 22, 0.96);
  border: 1px solid var(--line-strong);
  border-radius: 14px;
  padding: 14px;
  box-shadow: var(--shadow);
}
.nav-item:hover .mega,
.nav-item:focus-within .mega { display: grid; gap: 4px; }
.nav > .nav-item:last-child .mega { left: auto; right: 0; transform: none; }
.mega a {
  display: block;
  padding: 9px 12px;
  border-radius: 8px;
  color: var(--ink);
  font-size: 13px;
}
.mega a:hover { background: var(--surface-2); color: var(--accent-2); }
.mega small { display: block; color: var(--dim); font-size: 11px; margin-top: 2px; }

.header-tools {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 180px;
  justify-content: flex-end;
}
.icon-btn {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--ink);
  display: grid;
  place-items: center;
}
.icon-btn:hover { border-color: var(--accent); color: var(--accent-2); }
.lang-toggle {
  display: flex;
  border: 1px solid var(--line);
  border-radius: 999px;
  overflow: hidden;
}
.lang-toggle button {
  background: transparent;
  border: 0;
  color: var(--muted);
  padding: 6px 10px;
  font-size: 11px;
  letter-spacing: 0.08em;
}
.lang-toggle button.is-on {
  background: var(--accent);
  color: #111;
}

.burger { display: none; }

#app { position: relative; z-index: 1; min-height: calc(100vh - 180px); }

.wrap {
  width: min(1180px, calc(100% - 40px));
  margin: 0 auto;
}
.wrap-wide {
  width: min(1360px, calc(100% - 32px));
  margin: 0 auto;
}

.hero {
  position: relative;
  min-height: calc(100vh - var(--header-h));
  display: grid;
  place-items: center;
  overflow: hidden;
}
.hero-bg {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(ellipse at center, rgba(7,8,12,0.15), rgba(7,8,12,0.88) 70%),
    url("../assets/hero.jpg") center/cover no-repeat;
  filter: saturate(0.9);
}
.hero-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0.55;
}
.hero-inner {
  position: relative;
  z-index: 2;
  text-align: center;
  padding: 80px 20px 100px;
}
.kicker {
  font-size: 12px;
  letter-spacing: 0.38em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 18px;
}
.hero h1 {
  font-family: var(--font-display);
  font-weight: 500;
  font-size: clamp(48px, 8vw, 104px);
  line-height: 0.92;
  margin: 0 0 18px;
  letter-spacing: 0.04em;
}
.hero h1 em {
  font-style: italic;
  color: var(--accent-2);
}
.lede {
  max-width: 680px;
  margin: 0 auto 32px;
  color: var(--muted);
  font-size: 18px;
  font-family: var(--font-serif);
}
.cta-row { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; }
.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border-radius: 999px;
  padding: 12px 20px;
  border: 1px solid var(--line-strong);
  color: var(--ink);
  background: transparent;
  font-size: 14px;
  letter-spacing: 0.04em;
  transition: 0.25s var(--ease);
}
.btn:hover { transform: translateY(-1px); border-color: var(--accent); color: var(--accent-2); }
.btn.primary {
  background: var(--accent);
  color: #16130c;
  border-color: var(--accent);
  font-weight: 600;
}
.btn.primary:hover { color: #111; filter: brightness(1.05); }

.section {
  padding: 84px 0;
}
.section-head {
  display: flex;
  justify-content: space-between;
  gap: 24px;
  align-items: end;
  margin-bottom: 36px;
}
.section-head h2 {
  font-family: var(--font-display);
  font-size: clamp(32px, 4vw, 48px);
  margin: 0;
  font-weight: 500;
  letter-spacing: 0.03em;
}
.section-head p { color: var(--muted); max-width: 520px; margin: 0; }
.idx {
  font-family: var(--font-display);
  color: var(--accent);
  font-size: 13px;
  letter-spacing: 0.28em;
  margin-bottom: 8px;
}

.grid-4, .grid-3, .grid-2, .grid-symbols { display: grid; gap: 16px; }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-4 > *, .grid-3 > *, .grid-2 > * { min-width: 0; }
.card h3 { overflow-wrap: anywhere; line-height: 1.2; }

.card {
  background: linear-gradient(180deg, rgba(255,255,255,0.025), rgba(255,255,255,0.01));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 22px;
  transition: 0.28s var(--ease);
  min-height: 100%;
}
.card:hover {
  border-color: var(--line-strong);
  transform: translateY(-3px);
  box-shadow: 0 16px 40px rgba(0,0,0,0.28);
}
.card h3 {
  font-family: var(--font-display);
  font-size: 26px;
  margin: 8px 0 10px;
  font-weight: 600;
}
.card p { color: var(--muted); margin: 0; }
.card .num {
  font-family: var(--font-display);
  color: var(--accent);
  letter-spacing: 0.16em;
  font-size: 13px;
}

.page-hero {
  padding: 56px 0 20px;
}
.page-hero h1 {
  font-family: var(--font-display);
  font-size: clamp(36px, 5vw, 64px);
  margin: 8px 0 14px;
  font-weight: 500;
  line-height: 1.05;
}
.page-hero .lede { margin: 0; text-align: left; max-width: 760px; font-size: 17px; overflow-wrap: break-word; }
.crumbs {
  color: var(--dim);
  font-size: 12px;
  letter-spacing: 0.08em;
}
.crumbs a:hover { color: var(--accent); }

.why {
  border-left: 2px solid var(--accent);
  padding: 8px 0 8px 18px;
  margin: 28px 0 12px;
  color: var(--muted);
  font-family: var(--font-serif);
}
.why strong { color: var(--accent-2); font-weight: 600; }

.subnav {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin: 18px 0 8px;
}
.chip {
  border: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
  border-radius: 999px;
  padding: 7px 13px;
  font-size: 12px;
  letter-spacing: 0.04em;
}
.chip.is-on, .chip:hover { color: var(--accent-2); border-color: var(--accent); }

.formula-card {
  display: grid;
  grid-template-columns: 72px minmax(0, 1fr);
  gap: 8px 20px;
  padding: 28px;
  margin: 16px 0;
  border: 1px solid var(--line);
  border-radius: 22px;
  background: var(--surface);
}
.formula-card > * { min-width: 0; }
.formula-card .rank {
  font-family: var(--font-display);
  font-size: 42px;
  color: var(--accent);
  line-height: 1;
}
.formula-card h3 {
  margin: 0 0 10px;
  font-family: var(--font-display);
  font-size: clamp(20px, 3vw, 28px);
  font-weight: 600;
  line-height: 1.2;
  overflow-wrap: anywhere;
}
.formula-stage {
  grid-column: 1 / -1;
  background: #0a0c12;
  border-radius: 14px;
  padding: 22px 16px;
  overflow-x: auto;
  overflow-y: hidden;
  text-align: center;
  border: 1px solid var(--line);
  max-width: 100%;
}
.formula-stage .katex { font-size: clamp(0.95em, 2.6vw, 1.28em); color: var(--gold-2); }
.formula-stage .katex-display { margin: 0; overflow-x: auto; overflow-y: hidden; }
body[data-realm="physics"] .formula-stage .katex { color: var(--cyan-2); }
.formula-meta { grid-column: 1 / -1; display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.formula-meta > * { min-width: 0; }
.formula-meta h4 {
  margin: 0 0 6px;
  font-size: 12px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--accent);
}
.formula-meta p { margin: 0; color: var(--muted); overflow-wrap: break-word; }
.tags { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 10px; }
.tag {
  font-size: 11px;
  letter-spacing: 0.08em;
  color: var(--dim);
  border: 1px solid var(--line);
  padding: 3px 8px;
  border-radius: 999px;
}

.symbol-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
  gap: 12px;
}
.symbol-card {
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 16px;
  background: var(--surface);
  cursor: pointer;
  text-align: left;
  color: inherit;
  width: 100%;
}
.symbol-card:hover { border-color: var(--accent); }
.glyph {
  font-size: 34px;
  line-height: 1.1;
  font-family: "Cormorant Garamond", "Times New Roman", serif;
  color: var(--accent-2);
}
.symbol-card .name { margin-top: 8px; font-size: 14px; }
.symbol-card .read { color: var(--dim); font-size: 12px; }

.drawer {
  position: fixed;
  right: 0; top: 0; bottom: 0;
  width: min(460px, 100%);
  background: #0e1016;
  border-left: 1px solid var(--line-strong);
  z-index: 80;
  padding: 64px 28px 28px;
  overflow: auto;
  box-shadow: var(--shadow);
  transform: translateX(100%);
  transition: transform 0.35s var(--ease);
}
.drawer .icon-btn { position: absolute; top: 16px; right: 16px; }
.drawer.open { transform: none; }
.drawer-backdrop {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.45);
  z-index: 70;
}
.ex {
  background: #0a0c12;
  border-radius: 12px;
  padding: 14px;
  border: 1px solid var(--line);
  margin: 12px 0;
}

.person-card {
  display: grid;
  grid-template-columns: 72px minmax(0, 1fr);
  gap: 16px;
  align-items: start;
  min-width: 0;
}
.mono-portrait {
  width: 88px; height: 88px;
  border-radius: 50%;
  border: 1px solid var(--line-strong);
  display: grid; place-items: center;
  font-family: var(--font-display);
  font-size: 28px;
  color: var(--accent-2);
  background:
    radial-gradient(circle at 30% 20%, rgba(212,184,116,0.18), transparent 55%),
    #10131a;
}
.person-card h3 { margin: 0 0 4px; font-family: var(--font-display); font-size: 26px; }
.life { color: var(--dim); font-size: 12px; letter-spacing: 0.08em; }

.problem-card .status {
  display: inline-block;
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--danger);
  border: 1px solid rgba(208,112,88,0.35);
  padding: 3px 8px;
  border-radius: 999px;
}

.lab-shell {
  display: grid;
  grid-template-columns: minmax(0, 240px) minmax(0, 1fr);
  gap: 18px;
  align-items: start;
}
.lab-main { min-width: 0; display: flex; flex-direction: column; gap: 12px; }
.lab-side {
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 16px;
  background: var(--surface);
  height: fit-content;
  position: sticky;
  top: 88px;
  max-height: calc(100vh - 120px);
  overflow: auto;
}
.lab-side a {
  display: block;
  padding: 8px 10px;
  border-radius: 8px;
  color: var(--muted);
  font-size: 13px;
  overflow-wrap: anywhere;
  line-height: 1.4;
}
.lab-side a.is-on, .lab-side a:hover { background: var(--surface-2); color: var(--accent-2); }
.lab-stage {
  border: 1px solid var(--line);
  border-radius: 18px;
  overflow: hidden;
  background: #05060a;
  height: min(58vh, 560px);
  min-height: 380px;
  position: relative;
}
.lab-stage canvas { width: 100%; height: 100%; display: block; }
.lab-ui {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px 14px;
  pointer-events: auto;
}
.lab-ui label { font-size: 12px; color: var(--muted); display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.lab-ui input[type="range"] { width: 120px; accent-color: var(--accent); }
.lab-caption {
  position: static;
  pointer-events: auto;
}
.lab-caption h3 {
  margin: 0;
  font-family: var(--font-display);
  font-size: clamp(22px, 3vw, 30px);
  line-height: 1.2;
  overflow-wrap: anywhere;
}
.lab-caption p { margin: 6px 0 0; color: var(--muted); max-width: 72ch; font-size: 14px; }
.lab-hint { color: var(--dim) !important; font-size: 13px !important; }
.lab-hint a { color: var(--accent); text-decoration: underline; text-underline-offset: 3px; }

.timeline { position: relative; padding-left: 22px; }
.timeline::before {
  content: "";
  position: absolute;
  left: 4px; top: 0; bottom: 0;
  width: 1px;
  background: var(--line-strong);
}
.tl-item { position: relative; padding: 0 0 28px 16px; }
.tl-item::before {
  content: "";
  position: absolute;
  left: -22px; top: 8px;
  width: 9px; height: 9px;
  border-radius: 50%;
  background: var(--accent);
}
.tl-item h3 { margin: 0; font-family: var(--font-display); font-size: 22px; }
.tl-item .year { color: var(--accent); font-size: 12px; letter-spacing: 0.16em; }

.table-scroll { overflow-x: auto; max-width: 100%; }
.const-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 520px;
}
.const-table th, .const-table td {
  text-align: left;
  padding: 12px 10px;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}
.const-table th { color: var(--accent); font-size: 12px; letter-spacing: 0.14em; font-weight: 500; }
.katex { color: var(--ink); }

.search-modal {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.55);
  z-index: 90;
  display: none;
  place-items: start center;
  padding-top: 12vh;
}
.search-modal.open { display: grid; }
.search-box {
  width: min(720px, calc(100% - 32px));
  background: #10131a;
  border: 1px solid var(--line-strong);
  border-radius: 16px;
  overflow: hidden;
  box-shadow: var(--shadow);
}
.search-box input {
  width: 100%;
  background: transparent;
  border: 0;
  color: var(--ink);
  font-size: 18px;
  padding: 18px 20px;
  outline: none;
}
.search-results { max-height: 50vh; overflow: auto; border-top: 1px solid var(--line); }
.search-results a {
  display: block;
  padding: 12px 20px;
  color: var(--muted);
  border-bottom: 1px solid var(--line);
}
.search-results a:hover { background: var(--surface-2); color: var(--ink); }

.essay { font-family: var(--font-serif); font-size: 17.5px; color: #ddd4c3; }
.essay p { margin: 0 0 16px; }
.essay h3 { font-family: var(--font-display); font-size: 28px; margin: 28px 0 10px; color: var(--ink); }

.site-footer {
  border-top: 1px solid var(--line);
  padding: 36px 0 48px;
  color: var(--dim);
  font-size: 13px;
  position: relative;
  z-index: 1;
}
.foot-grid {
  display: flex;
  justify-content: space-between;
  gap: 24px;
  flex-wrap: wrap;
}
.foot-grid a:hover { color: var(--accent); }

.mobile-panel {
  display: none;
  position: fixed;
  inset: var(--header-h) 0 0 0;
  background: rgba(8,9,13,0.98);
  z-index: 40;
  padding: 18px 22px 40px;
  overflow: auto;
}
.mobile-panel.open { display: block; }
.mobile-panel a, .mobile-panel button {
  display: block;
  width: 100%;
  text-align: left;
  background: none;
  border: 0;
  color: var(--ink);
  padding: 12px 0;
  font-size: 16px;
  border-bottom: 1px solid var(--line);
}

.dim-ladder {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin: 12px 0;
}
.dim-btn {
  width: 42px; height: 42px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
  font-family: var(--font-display);
  font-size: 16px;
}
.dim-btn.is-on { background: var(--accent); color: #111; border-color: var(--accent); }

.note {
  font-size: 13px;
  color: var(--dim);
  margin-top: 8px;
}

@media (max-width: 1180px) {
  .nav { display: none; }
  .burger { display: grid; }
  .site-header { padding: 0 14px; }
  .brand-text span { display: none; }
  .header-tools { min-width: unset; }
}

@media (max-width: 1100px) {
  .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .section-head { flex-direction: column; align-items: flex-start; }
}

@media (max-width: 980px) {
  .grid-4, .grid-3, .lab-shell, .formula-meta, .grid-2 { grid-template-columns: 1fr; }
  .formula-card { grid-template-columns: 1fr; }
  .lab-side { position: static; max-height: none; }
  .lab-stage { height: 420px; min-height: 360px; }
  .page-hero { padding-top: 28px; }
  .hero h1 { font-size: clamp(36px, 11vw, 64px); }
  .brand { min-width: unset; }
}

.game-hud {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 18px;
  align-items: center;
  color: var(--muted);
  font-size: 14px;
}
.game-hud strong { color: var(--accent-2); font-family: var(--font-display); font-size: 22px; font-weight: 600; }
.game-board {
  position: absolute;
  inset: 0;
  overflow: auto;
  padding: 20px 22px;
  background: #05060a;
  color: var(--ink);
}
.token-tray, .token-slots {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin: 10px 0;
}
.token, .slot {
  min-width: 48px;
  min-height: 48px;
  padding: 8px 12px;
  border-radius: 12px;
  border: 1px dashed var(--line-strong);
  display: grid;
  place-items: center;
  font-family: var(--font-display);
  font-size: 22px;
  background: #0a0c12;
}
.token {
  border-style: solid;
  cursor: pointer;
  color: var(--accent-2);
}
.token:hover, .token.is-on { border-color: var(--accent); background: var(--surface-2); }
.choice-row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.choice-row .btn { font-size: 14px; }
.quiz-q {
  font-family: var(--font-serif);
  font-size: 18px;
  color: var(--ink);
  margin: 8px 0 4px;
}
.feedback { min-height: 1.4em; font-size: 14px; color: var(--ok); }
.feedback.bad { color: var(--danger); }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
  html { scroll-behavior: auto; }
}
