:root {
  /* Semantic core. Existing aliases below preserve the approved palette. */
  --surface-page: #f3f1ec;
  --surface-primary: #fcfbf8;
  --surface-secondary: #e9e5de;
  --text-primary: #282725;
  --text-secondary: #6f6c67;
  --separator: #d8d4cd;
  --accent: #d4323a;
  --accent-strong: #a92029;
  --accent-soft: #f7e6e6;
  --success: #4e7561;
  --success-soft: #e3ece7;
  --error: #b54b52;
  --error-soft: #f4d9dc;
  --focus-ring: #2563eb;
  --font-ui: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif;
  --type-xs: .75rem;
  --type-sm: .875rem;
  --type-body: 1rem;
  --type-leading: 1.5;
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --radius-compact: 8px;
  --radius-control: 14px;
  --radius-panel: 20px;
  --control-height-sm: 36px;
  --control-height-md: 44px;
  --control-height-lg: 48px;
  --layer-header: 30;
  --layer-mobile-nav: 40;
  --layer-modal: 60;
  --layer-tooltip: 2000;
  --motion-fast: 100ms;
  --motion-ui: 180ms;
  --motion-slow: 280ms;
  --motion-ease: cubic-bezier(.23, 1, .32, 1);
  --shadow-panel: 0 18px 48px rgba(40, 39, 37, 0.16);

  --paper: var(--surface-page);
  --surface: var(--surface-primary);
  --surface-2: var(--surface-secondary);
  --ink: var(--text-primary);
  --muted: var(--text-secondary);
  --line: var(--separator);
  --red: var(--accent);
  --red-dark: var(--accent-strong);
  --red-soft: var(--accent-soft);
  --green: var(--success);
  --green-soft: var(--success-soft);
  --sand: #e9dfd0;
  --focus: var(--focus-ring);
  --radius-s: var(--radius-compact);
  --radius-m: 14px;
  --radius-l: var(--radius-panel);
  --control-ease: var(--motion-ease);
  --max: 1320px;
  --shadow: var(--shadow-panel);
}

* { box-sizing: border-box; }

html { overflow-x: hidden; }

@media (pointer: fine) {
  html { overscroll-behavior: none; }
}

html { scroll-behavior: smooth; }

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  color: var(--ink);
  background: var(--paper);
  font-family: var(--font-ui);
  font-size: var(--type-body);
  line-height: var(--type-leading);
  font-optical-sizing: auto;
  text-rendering: optimizeLegibility;
  overflow-x: hidden;
  -webkit-tap-highlight-color: rgba(212, 50, 58, .16);
}

body.modal-open { overflow: hidden; }

button,
input { font: inherit; }

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

button,
[role="button"] { cursor: pointer; }

button { touch-action: manipulation; }

button:focus-visible,
input:focus-visible,
[tabindex]:focus-visible,
a:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 3px;
}

button[disabled] { cursor: not-allowed; opacity: .48; }

.skip-link {
  position: fixed;
  z-index: 100;
  top: 10px;
  left: 10px;
  padding: 10px 14px;
  color: #fff;
  background: var(--ink);
  border-radius: var(--radius-s);
  transform: translateY(-150%);
}
.skip-link:focus { transform: translateY(0); }

.site-header {
  position: sticky;
  z-index: var(--layer-header);
  top: 0;
  background: rgba(243, 241, 236, .95);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(10px);
}

.header-inner {
  width: min(calc(100% - 48px), var(--max));
  height: 76px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: 28px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 11px;
  border: 0;
  padding: 0;
  color: inherit;
  background: transparent;
  text-align: left;
}

.brand-mark {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  color: #fff;
  background: var(--red);
  border-radius: 12px;
}
.brand-mark svg { width: 22px; height: 22px; }
.brand-copy { display: grid; line-height: 1.1; }
.brand-copy strong { font-size: 16px; letter-spacing: -.01em; }
.brand-copy span { margin-top: 3px; color: var(--muted); font-size: 11px; }

.main-nav { display: flex; align-items: stretch; align-self: stretch; gap: 6px; }
.nav-link {
  position: relative;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  padding: 0 14px;
  border: 0;
  color: var(--muted);
  background: transparent;
  font-weight: 600;
}
.nav-link:hover { color: var(--ink); }
.nav-link.active { color: var(--ink); }
.nav-link.active::after {
  content: "";
  position: absolute;
  right: 14px;
  bottom: -1px;
  left: 14px;
  height: 3px;
  background: var(--red);
}

.header-actions { margin-left: auto; display: flex; gap: 8px; }
.profile-button {
  width: 44px;
  height: 44px;
  border: 1px solid var(--line);
  color: var(--ink);
  background: var(--surface);
  border-radius: var(--radius-control);
  font-weight: 700;
  transition: color var(--motion-ui) var(--motion-ease), background-color var(--motion-ui) var(--motion-ease), border-color var(--motion-ui) var(--motion-ease), transform var(--motion-ui) var(--motion-ease);
}
.profile-button:hover { color: var(--red-dark); border-color: #aaa59d; background: #fff; }
.profile-button:active { transform: scale(.97); transition-duration: var(--motion-fast); }

.page-shell {
  width: min(calc(100% - 48px), var(--max));
  margin: 0 auto;
  padding: 48px 0 88px;
}

h1, h2, h3, p { margin-top: 0; }
h1, h2, h3 { text-wrap: balance; scroll-margin-top: 96px; }
p { text-wrap: pretty; }
h1 { max-width: 820px; margin-bottom: 16px; font-size: clamp(2.15rem, 4vw, 3.4rem); line-height: 1.05; letter-spacing: -.045em; font-weight: 680; }
h2 { margin-bottom: 20px; font-size: clamp(1.65rem, 2.4vw, 2.15rem); line-height: 1.15; letter-spacing: -.03em; font-weight: 680; }
h3 { margin-bottom: 8px; font-size: 1.15rem; line-height: 1.25; letter-spacing: -.015em; }
.lead { max-width: 720px; color: var(--muted); font-size: 1.15rem; line-height: 1.55; }
.eyebrow { margin: 0 0 12px; color: var(--red-dark); font-size: 14px; font-weight: 700; }
.muted { color: var(--muted); }
.small { font-size: 14px; }
.section { margin-top: 64px; }
.section-head { display: flex; align-items: end; justify-content: space-between; gap: 20px; margin-bottom: 24px; }
.section-head h2, .section-head p { margin-bottom: 0; }

.button {
  min-height: var(--control-height-md);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  padding: 0 20px;
  border: 1px solid transparent;
  border-radius: var(--radius-control);
  font-size: 14px;
  font-weight: 650;
  line-height: 1;
  white-space: nowrap;
  box-shadow: none;
  transform: translateZ(0);
  transition: background-color var(--motion-ui) var(--motion-ease), border-color var(--motion-ui) var(--motion-ease), color var(--motion-ui) var(--motion-ease), opacity var(--motion-ui) var(--motion-ease), transform var(--motion-ui) var(--motion-ease);
}
.button:active { transform: scale(.97); transition-duration: var(--motion-fast); }
.button svg { width: 17px; height: 17px; flex: 0 0 auto; transition: transform .16s var(--control-ease); }
.button:hover svg:last-child { transform: translateX(2px); }
.button:active svg:last-child { transform: translateX(1px); }
.button.primary { color: #fff; background: var(--red); border-color: #bd2830; }
.button.primary:hover { background: var(--red-dark); border-color: #8f1820; }
.button.secondary { color: var(--ink); background: var(--surface); border-color: var(--line); }
.button.secondary:hover { border-color: #aaa59d; background: #fff; }
.button.text { min-height: 44px; padding: 0 6px; color: var(--red-dark); background: transparent; }
.button.text:hover { text-decoration: none; }
.button.compact { min-height: var(--control-height-sm); padding: 0 14px; font-size: 13px; }

.icon-button {
  width: 44px;
  height: 44px;
  display: inline-grid;
  place-items: center;
  padding: 0;
  border: 1px solid var(--line);
  color: var(--ink);
  background: var(--surface);
  border-radius: var(--radius-control);
  box-shadow: none;
  transition: color var(--motion-ui) var(--motion-ease), background-color var(--motion-ui) var(--motion-ease), border-color var(--motion-ui) var(--motion-ease), transform var(--motion-ui) var(--motion-ease);
}
.icon-button:hover { border-color: #aaa59d; background: #fff; }
.icon-button:active { transform: scale(.97); transition-duration: var(--motion-fast); }
.icon-button svg { width: 20px; height: 20px; }

.back-button {
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 28px;
  padding: 0;
  border: 0;
  color: var(--ink);
  background: transparent;
  font-weight: 650;
  transition: color .18s var(--control-ease), transform .18s var(--control-ease);
}
.back-button:hover { color: var(--red-dark); }
.back-button:active { transform: translateX(-2px); }
.back-button svg { width: 18px; height: 18px; }

.tag-row { display: flex; flex-wrap: wrap; gap: 7px; }
.tag {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 3px 9px;
  color: #57534e;
  background: #efede8;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 650;
}

.status-pill { display: inline-flex; align-items: center; gap: 7px; color: var(--green); font-size: 13px; font-weight: 700; }
.status-pill::before { content: ""; width: 7px; height: 7px; background: currentColor; border-radius: 50%; }

@media (prefers-reduced-motion: reduce) {
  .button,
  .button svg,
  .icon-button,
  .profile-button,
  .back-button { transition: none; transform: none !important; }
}

.notice {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 16px 18px;
  color: #5e5045;
  background: #f3ece4;
  border-left: 3px solid #a67a55;
  border-radius: 0 var(--radius-s) var(--radius-s) 0;
}
.notice svg { width: 20px; height: 20px; flex: 0 0 auto; margin-top: 2px; }

.cover-art {
  min-height: 100%;
  overflow: hidden;
  background: var(--sand);
  border-radius: var(--radius-m);
}
.cover-art svg { width: 100%; height: 100%; display: block; }

.metric { font-variant-numeric: tabular-nums; }

.modal-backdrop,
.drawer-backdrop {
  position: fixed;
  z-index: var(--layer-modal);
  inset: 0;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(40, 39, 37, .46);
}
.modal {
  width: min(100%, 540px);
  max-height: min(760px, calc(100vh - 40px));
  overflow: auto;
  padding: 28px;
  background: var(--surface);
  border-radius: var(--radius-l);
  box-shadow: var(--shadow);
  overscroll-behavior: contain;
}
.modal-head { display: flex; justify-content: space-between; gap: 20px; margin-bottom: 24px; }
.modal-head h2 { margin: 0; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 28px; }

.toast {
  position: fixed;
  z-index: 90;
  right: 24px;
  bottom: 24px;
  max-width: min(380px, calc(100vw - 32px));
  padding: 14px 18px;
  color: #fff;
  background: var(--ink);
  border-radius: var(--radius-s);
  box-shadow: var(--shadow);
}

.demo-stage {
  min-height: 560px;
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: 24px;
  padding: 24px;
  background: #dedbd4;
  border-radius: var(--radius-l);
}
.demo-hud { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.demo-hud strong { font-variant-numeric: tabular-nums; }
.session-status { padding: 18px 20px; background: rgba(252, 251, 248, .9); border: 1px solid #c9c5bd; border-radius: var(--radius-m); }
.hud-stats { display: flex; align-items: center; gap: 28px; }
.hud-stats span { display: grid; }
.hud-stats small { color: var(--muted); font-size: 11px; }
.hud-stars { color: var(--red); letter-spacing: 2px; }
.hud-stars i { color: #c7c2ba; font-style: normal; }
.round-progress { display: grid; grid-template-columns: repeat(20, 1fr); gap: 5px; margin: 14px 0 16px; }
.round-progress span { height: 5px; background: #d6d2cb; border-radius: 99px; }
.round-progress span.correct { background: var(--green); }
.round-progress span.wrong { background: var(--red); }
.round-progress span.current { background: var(--ink); box-shadow: 0 0 0 3px #fff, 0 0 0 4px var(--ink); }
.difficulty-head { display: flex; justify-content: space-between; gap: 12px; color: var(--muted); font-size: 11px; }
.difficulty-head strong { color: var(--ink); }
.difficulty-track-proto { position: relative; display: grid; grid-template-columns: repeat(32, 1fr); gap: 3px; height: 16px; align-items: end; margin-top: 7px; }
.difficulty-track-proto span { height: 7px; background: #cecac3; border-radius: 1px; }
.difficulty-track-proto span.passed { background: #817c75; }
.difficulty-track-proto i { position: absolute; top: -4px; width: 3px; height: 20px; background: var(--red); border-radius: 2px; transform: translateX(-50%); }
.demo-board {
  display: grid;
  place-items: center;
  min-height: 360px;
  background: var(--surface);
  border: 1px solid #c9c5bd;
  border-radius: var(--radius-m);
}
.demo-orbit { position: relative; width: min(300px, 76vw); aspect-ratio: 1; border: 1px dashed #aaa49b; border-radius: 50%; }
.demo-dot { position: absolute; width: 52px; height: 52px; display: grid; place-items: center; padding: 0; border: 0; color: #fff; background: var(--ink); border-radius: 50%; font-weight: 800; transition: transform .18s ease, background-color .18s ease; }
.demo-dot:hover, .demo-dot:focus-visible { transform: scale(1.08); background: var(--red-dark); }
.demo-dot:nth-child(1) { top: -8px; left: calc(50% - 26px); background: var(--red); }
.demo-dot:nth-child(2) { top: 23%; right: -10px; }
.demo-dot:nth-child(3) { right: 8%; bottom: 8%; }
.demo-dot:nth-child(4) { bottom: -8px; left: calc(50% - 26px); background: var(--red); }
.demo-dot:nth-child(5) { bottom: 8%; left: 8%; }
.demo-dot:nth-child(6) { top: 23%; left: -10px; }
.demo-controls { display: flex; justify-content: center; gap: 12px; }
.session-hint { align-self: center; color: var(--muted); font-size: 13px; }

.result-panel {
  max-width: 800px;
  margin: 24px auto 0;
  padding: clamp(24px, 5vw, 52px);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-l);
}
.result-number { margin: 12px 0 28px; font-size: clamp(3rem, 8vw, 5.5rem); line-height: 1; letter-spacing: -.06em; font-weight: 700; font-variant-numeric: tabular-nums; }
.result-grid { display: grid; grid-template-columns: repeat(3, 1fr); margin: 28px 0; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.result-grid div { padding: 20px; border-right: 1px solid var(--line); }
.result-grid div:last-child { border-right: 0; }
.result-grid span { display: block; color: var(--muted); font-size: 13px; }
.result-grid strong { display: block; margin-top: 6px; font-size: 20px; font-variant-numeric: tabular-nums; }
.result-actions { display: flex; flex-wrap: wrap; gap: 10px; }

.mobile-nav { display: none; }

@media (max-width: 820px) {
  .header-inner { width: min(calc(100% - 32px), var(--max)); height: 68px; }
  .main-nav { display: none; }
  .page-shell { width: min(calc(100% - 32px), var(--max)); padding-top: 32px; padding-bottom: 100px; }
  .section { margin-top: 48px; }
  .section-head { align-items: flex-start; }
  .demo-stage { min-height: 500px; padding: 16px; }
  .demo-hud { align-items: flex-start; }
  .hud-stats { gap: 12px; }
  .result-grid { grid-template-columns: 1fr; }
  .result-grid div { border-right: 0; border-bottom: 1px solid var(--line); }
  .result-grid div:last-child { border-bottom: 0; }
  .mobile-nav {
    position: fixed;
    z-index: var(--layer-mobile-nav);
    right: 12px;
    bottom: max(12px, env(safe-area-inset-bottom));
    left: 12px;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    padding: 6px;
    padding-bottom: max(6px, env(safe-area-inset-bottom));
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 14px;
    box-shadow: 0 10px 30px rgba(40, 39, 37, .14);
  }
  .mobile-nav a { min-height: 52px; display: grid; place-items: center; border: 0; color: var(--muted); background: transparent; border-radius: 9px; font-size: 12px; font-weight: 700; }
  .mobile-nav a.active { color: var(--red-dark); background: var(--red-soft); }
}

@media (max-width: 520px) {
  .brand-copy span { display: none; }
  .section-head { display: block; }
  .section-head .button { margin-top: 16px; }
  .button:not(.compact):not(.text) { width: 100%; }
  .modal-actions, .result-actions, .demo-controls { flex-direction: column-reverse; }
  .modal { padding: 22px; border-radius: var(--radius-m); }
  .demo-hud { display: block; }
  .hud-stats { margin-top: 12px; justify-content: space-between; }
  .difficulty-head span { display: none; }
  .difficulty-head { justify-content: center; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: .01ms !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; }
}

@media (prefers-reduced-transparency: reduce) {
  .site-header, .mobile-nav { background: var(--surface-page); backdrop-filter: none; }
  .modal-backdrop, .drawer-backdrop { background: #514e49; }
}

@media (prefers-contrast: more) {
  .site-header, .mobile-nav, .button.secondary, .icon-button, .profile-button { border-color: var(--text-primary); }
  .muted, .lead { color: var(--text-primary); }
}
