:root {
  --bg: #f3f5f4;
  --surface: #ffffff;
  --surface-2: #e9eeec;
  --ink: #17201d;
  --muted: #64716c;
  --line: #d8dfdc;
  --primary: #126b59;
  --primary-hover: #0d594a;
  --primary-soft: #dcece7;
  --blue: #356fa5;
  --blue-soft: #dce8f2;
  --orange: #c76c34;
  --orange-soft: #f4e3d6;
  --danger: #b9423a;
  --danger-soft: #f6e1df;
  --shadow: 0 8px 28px rgba(26, 39, 34, 0.08);
  --sidebar: 224px;
  --radius: 8px;
  font-family: Inter, "PingFang SC", "Microsoft YaHei", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--bg);
  font-synthesis: none;
}

/* The shared arcade return button is fixed in the top-left corner. Keep the
   first page heading clear of it on narrow screens and desktop. */
.arcade-home-button--page + #app {
  padding-top: 42px;
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  min-height: 100%;
  background: var(--bg);
}

body {
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  background: var(--bg);
  line-height: 1.5;
  letter-spacing: 0;
  -webkit-font-smoothing: antialiased;
}

button,
input {
  font: inherit;
  letter-spacing: 0;
}

button {
  color: inherit;
}

button:focus-visible,
input:focus-visible {
  outline: 3px solid rgba(18, 107, 89, 0.28);
  outline-offset: 2px;
}

button,
[role="button"] {
  -webkit-tap-highlight-color: transparent;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1,
h2,
h3,
strong,
b {
  font-weight: 700;
}

.app-shell {
  min-height: 100vh;
  padding-left: var(--sidebar);
}

.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 20;
  display: flex;
  width: var(--sidebar);
  flex-direction: column;
  padding: 28px 18px 22px;
  border-right: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.92);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 8px 24px;
  border: 0;
  background: transparent;
  text-align: left;
  cursor: pointer;
}

.brand strong,
.brand small {
  display: block;
}

.brand strong {
  font-size: 17px;
}

.brand small {
  margin-top: 1px;
  color: var(--muted);
  font-size: 12px;
}

.brand-grid {
  display: grid;
  flex: 0 0 auto;
  width: 34px;
  height: 34px;
  grid-template-columns: repeat(2, 1fr);
  gap: 3px;
  padding: 5px;
  border-radius: 7px;
  background: var(--ink);
}

.brand-grid i {
  border-radius: 1px;
  background: var(--surface);
}

.brand-grid i:first-child,
.brand-grid i:last-child {
  background: #72c1a7;
}

.brand-grid.large {
  width: 48px;
  height: 48px;
  padding: 7px;
}

.desktop-nav {
  display: grid;
  gap: 6px;
}

.nav-item {
  display: flex;
  min-height: 46px;
  align-items: center;
  gap: 12px;
  padding: 0 14px;
  border: 0;
  border-radius: 6px;
  color: var(--muted);
  background: transparent;
  cursor: pointer;
  text-align: left;
}

.nav-item > span:first-child {
  display: grid;
  width: 22px;
  place-items: center;
  font-size: 20px;
  line-height: 1;
}

.nav-item:hover {
  color: var(--ink);
  background: var(--surface-2);
}

.nav-item.is-active {
  color: var(--primary);
  background: var(--primary-soft);
  font-weight: 700;
}

.sidebar-foot {
  margin-top: auto;
  padding: 12px 10px 0;
  color: var(--muted);
  font-size: 12px;
}

.status-dot {
  display: inline-block;
  width: 7px;
  height: 7px;
  margin-right: 5px;
  border-radius: 50%;
  background: #2d9477;
  box-shadow: 0 0 0 3px rgba(45, 148, 119, 0.12);
}

.mobile-nav {
  display: none;
}

.main-content {
  min-width: 0;
}

.page {
  width: min(1160px, calc(100% - 64px));
  min-height: 100vh;
  margin: 0 auto;
  padding: 48px 0 64px;
}

.page-header {
  display: flex;
  min-height: 132px;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 32px;
}

.page-header h1 {
  max-width: 100%;
  margin-bottom: 8px;
  font-size: 40px;
  line-height: 1.12;
}

.page-header p:not(.eyebrow) {
  max-width: 620px;
  margin-bottom: 0;
  color: var(--muted);
  font-size: 16px;
}

.eyebrow {
  margin-bottom: 8px;
  color: var(--primary);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

.home-header {
  align-items: center;
}

.hero-mark {
  display: grid;
  width: 128px;
  aspect-ratio: 1;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  transform: rotate(3deg);
}

.hero-mark i {
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 4px;
  color: var(--muted);
  background: var(--surface);
  box-shadow: 2px 3px 0 var(--line);
  font-size: 14px;
  font-style: normal;
}

.hero-mark i:nth-child(4),
.hero-mark i:nth-child(8) {
  color: white;
  border-color: var(--primary);
  background: var(--primary);
}

.unfinished-banner {
  display: grid;
  width: 100%;
  min-height: 74px;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 14px;
  margin: -10px 0 22px;
  padding: 12px 18px;
  border: 1px solid #e9c9a8;
  border-radius: var(--radius);
  background: #fff7ed;
  cursor: pointer;
  text-align: left;
}

.unfinished-banner small,
.unfinished-banner strong {
  display: block;
}

.unfinished-banner small {
  margin-top: 2px;
  color: var(--muted);
}

.unfinished-banner > span:last-child {
  font-size: 24px;
}

.unfinished-symbol {
  display: grid;
  width: 34px;
  height: 34px;
  place-items: center;
  border-radius: 50%;
  color: #8c4e18;
  background: #f7d9b8;
  font-weight: 800;
}

.home-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(320px, 0.9fr);
  gap: 22px;
}

.today-panel,
.trend-panel,
.chart-section,
.best-section,
.records-section,
.form-section,
.settings-section,
.data-section,
.legal-section {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.today-panel {
  min-height: 500px;
  padding: 34px;
  box-shadow: var(--shadow);
}

.panel-heading,
.section-title,
.game-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
}

.panel-heading h2,
.section-title h2,
.game-heading h1 {
  margin-bottom: 0;
}

.panel-heading h2 {
  font-size: 28px;
}

.done-seal,
.time-badge {
  display: grid;
  width: 62px;
  height: 62px;
  flex: 0 0 auto;
  place-items: center;
  border-radius: 50%;
  color: var(--primary);
  background: var(--primary-soft);
}

.done-seal {
  font-size: 28px;
}

.time-badge strong,
.time-badge small {
  display: block;
  line-height: 1;
  text-align: center;
}

.time-badge strong {
  font-size: 24px;
}

.time-badge small {
  margin-top: -16px;
  font-size: 10px;
}

.panel-copy {
  max-width: 480px;
  margin: 34px 0 30px;
  color: var(--muted);
}

.score-hero {
  display: flex;
  align-items: baseline;
  gap: 14px;
  margin: 24px 0 20px;
}

.score-hero strong {
  font-size: 64px;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.score-hero span {
  color: var(--muted);
}

.training-steps {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0;
  margin: 0 0 30px;
  padding: 0;
  list-style: none;
}

.training-steps li {
  display: grid;
  gap: 7px;
  min-width: 0;
  padding: 15px 12px;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  font-size: 14px;
}

.training-steps li + li {
  border-left: 1px solid var(--line);
}

.training-steps span {
  color: var(--primary);
  font-size: 11px;
  font-weight: 800;
}

.button {
  display: inline-flex;
  min-height: 46px;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 0 22px;
  border: 1px solid transparent;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 700;
  transition: transform 160ms ease, background 160ms ease, border-color 160ms ease;
}

.button:hover:not(.is-disabled) {
  transform: translateY(-1px);
}

.button.primary {
  color: #fff;
  background: var(--primary);
}

.button.primary:hover:not(.is-disabled) {
  background: var(--primary-hover);
}

.button.secondary {
  border-color: var(--line);
  background: var(--surface);
}

.button.secondary:hover {
  border-color: #adb8b4;
  background: var(--surface-2);
}

.button.danger {
  color: #fff;
  background: var(--danger);
}

.button.wide {
  width: 100%;
  justify-content: space-between;
}

.button.is-disabled,
.keypad .is-disabled {
  cursor: not-allowed;
  opacity: 0.4;
}

.privacy-line {
  margin: 16px 0 0;
  color: var(--muted);
  font-size: 12px;
  text-align: center;
}

.home-side {
  display: grid;
  align-content: start;
  gap: 22px;
}

.metrics-strip,
.history-metrics,
.result-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.metrics-strip > div,
.history-metrics > div,
.result-stats > div {
  min-width: 0;
  padding: 20px 12px;
  text-align: center;
}

.metrics-strip > div + div,
.history-metrics > div + div,
.result-stats > div + div {
  border-left: 1px solid var(--line);
}

.metrics-strip strong,
.metrics-strip span,
.history-metrics strong,
.history-metrics span,
.result-stats strong,
.result-stats span {
  display: block;
}

.metrics-strip strong,
.history-metrics strong {
  font-size: 22px;
  font-variant-numeric: tabular-nums;
}

.metrics-strip span,
.history-metrics span,
.result-stats span {
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
}

.trend-panel {
  min-height: 310px;
  padding: 26px;
}

.section-title h2,
.form-section h2,
.settings-section h2,
.best-section h2 {
  font-size: 18px;
}

.section-title p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.text-button,
.danger-link {
  padding: 4px;
  border: 0;
  color: var(--primary);
  background: transparent;
  cursor: pointer;
  font-size: 13px;
}

.trend-row {
  display: grid;
  grid-template-columns: 92px minmax(50px, 1fr) 34px;
  align-items: center;
  gap: 12px;
  min-height: 64px;
  border-top: 1px solid var(--line);
}

.trend-row:first-of-type {
  margin-top: 14px;
}

.trend-row strong,
.trend-row small {
  display: block;
}

.trend-row strong {
  font-size: 13px;
}

.trend-row small {
  margin-top: 2px;
  overflow: hidden;
  color: var(--muted);
  font-size: 10px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.trend-row b {
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.trend-meter {
  height: 6px;
  overflow: hidden;
  border-radius: 3px;
  background: var(--surface-2);
}

.trend-meter i {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--primary);
}

.baseline-chip,
.best-chip,
.neutral-chip,
.local-badge {
  display: inline-flex;
  align-items: center;
  width: max-content;
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 700;
}

.baseline-chip,
.neutral-chip {
  color: var(--muted);
  background: var(--surface-2);
}

.best-chip,
.local-badge {
  color: var(--primary);
  background: var(--primary-soft);
}

.empty-inline,
.empty-state,
.chart-empty {
  display: grid;
  place-items: center;
  color: var(--muted);
  text-align: center;
}

.empty-inline {
  min-height: 190px;
}

.empty-grid {
  display: grid;
  width: 38px;
  height: 38px;
  grid-template-columns: repeat(2, 1fr);
  gap: 4px;
}

.empty-grid i {
  border-radius: 2px;
  background: var(--line);
}

.empty-grid i:first-child {
  background: var(--primary);
}

/* Practice */
.practice-page,
.history-page,
.about-page {
  max-width: 980px;
}

.form-section,
.settings-section,
.data-section,
.legal-section {
  margin-bottom: 18px;
  padding: 26px;
}

.form-section > h2,
.settings-section > h2 {
  margin-bottom: 18px;
}

.game-picker {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}

.game-option {
  display: grid;
  min-height: 160px;
  align-content: start;
  gap: 6px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  cursor: pointer;
  text-align: left;
}

.game-option:hover {
  border-color: #9baba5;
}

.game-option.is-selected {
  border-color: var(--primary);
  box-shadow: inset 0 0 0 1px var(--primary);
}

.game-option small {
  color: var(--muted);
}

.game-glyph,
.best-icon,
.result-game {
  display: grid;
  width: 42px;
  height: 42px;
  margin-bottom: 8px;
  place-items: center;
  border-radius: 5px;
  font-size: 13px;
  font-weight: 800;
}

.game-glyph--search,
.best-icon--search,
.result-game--search {
  color: var(--primary);
  background: var(--primary-soft);
}

.game-glyph--digit,
.best-icon--digit,
.result-game--digit {
  color: var(--blue);
  background: var(--blue-soft);
}

.game-glyph--spatial,
.best-icon--spatial,
.result-game--spatial {
  color: var(--orange);
  background: var(--orange-soft);
}

.segmented-control {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--line);
}

.segmented-control button {
  display: grid;
  min-height: 66px;
  place-content: center;
  border: 0;
  background: var(--surface);
  cursor: pointer;
}

.segmented-control button.is-selected {
  color: var(--primary);
  background: var(--primary-soft);
}

.segmented-control small {
  margin-top: 2px;
  color: var(--muted);
  font-size: 10px;
}

.difficulty-section output {
  padding: 6px 10px;
  border-radius: 4px;
  color: var(--primary);
  background: var(--primary-soft);
  font-weight: 700;
}

.range {
  width: 100%;
  height: 24px;
  margin-top: 26px;
  accent-color: var(--primary);
  cursor: pointer;
}

.sticky-action {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 16px;
  padding-top: 8px;
}

.sticky-action small {
  color: var(--muted);
}

/* History */
.history-metrics {
  margin-bottom: 18px;
}

.chart-section,
.best-section,
.records-section {
  margin-bottom: 18px;
  padding: 26px;
}

.compact-tabs {
  display: flex;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 5px;
}

.compact-tabs button {
  min-height: 34px;
  padding: 0 12px;
  border: 0;
  background: var(--surface);
  cursor: pointer;
  font-size: 12px;
}

.compact-tabs button.is-active {
  color: var(--primary);
  background: var(--primary-soft);
  font-weight: 700;
}

.bar-chart {
  display: grid;
  height: 230px;
  grid-template-columns: repeat(14, minmax(8px, 1fr));
  align-items: end;
  gap: 8px;
  margin-top: 26px;
  padding: 18px 4px 0;
  border-bottom: 1px solid var(--line);
}

.chart-column {
  display: grid;
  height: 100%;
  grid-template-rows: 1fr 22px;
  align-items: end;
  gap: 5px;
}

.chart-column i {
  display: block;
  width: 100%;
  min-height: 4px;
  border-radius: 3px 3px 0 0;
  background: var(--primary);
}

.chart-column i.is-empty {
  background: var(--line);
}

.chart-column span {
  overflow: visible;
  color: var(--muted);
  font-size: 9px;
  text-align: center;
  white-space: nowrap;
}

.chart-empty {
  min-height: 210px;
}

.best-list {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}

.best-list > div {
  display: flex;
  min-width: 0;
  align-items: center;
  gap: 12px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 6px;
}

.best-icon {
  margin: 0;
}

.best-list p,
.best-list strong,
.best-list small {
  display: block;
  min-width: 0;
  margin: 0;
}

.best-list small {
  overflow: hidden;
  margin-top: 2px;
  color: var(--muted);
  font-size: 11px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.record-list {
  margin-top: 18px;
  border-top: 1px solid var(--line);
}

.record-row {
  display: grid;
  grid-template-columns: minmax(150px, 1fr) minmax(170px, auto) 72px;
  align-items: center;
  gap: 20px;
  min-height: 76px;
  border-bottom: 1px solid var(--line);
}

.record-date strong,
.record-date small,
.record-score strong,
.record-score small {
  display: block;
}

.record-date small,
.record-score small {
  color: var(--muted);
  font-size: 11px;
}

.record-games {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.record-games span {
  padding: 3px 6px;
  border-radius: 3px;
  color: var(--muted);
  background: var(--surface-2);
  font-size: 10px;
  font-variant-numeric: tabular-nums;
}

.record-score {
  text-align: right;
}

.record-score strong {
  font-size: 22px;
  font-variant-numeric: tabular-nums;
}

.records-section .empty-state {
  min-height: 260px;
  gap: 14px;
}

.empty-state h3 {
  margin: 0;
}

/* Settings */
.setting-list {
  border-top: 1px solid var(--line);
}

.setting-list label {
  display: flex;
  min-height: 82px;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  border-bottom: 1px solid var(--line);
  cursor: pointer;
}

.setting-list label > span strong,
.setting-list label > span small {
  display: block;
}

.setting-list label > span small {
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
}

.setting-list input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
}

.setting-list label > i {
  position: relative;
  width: 44px;
  height: 24px;
  flex: 0 0 auto;
  border-radius: 12px;
  background: #b9c2bf;
  transition: background 160ms ease;
}

.setting-list label > i::after {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.22);
  content: "";
  transition: transform 160ms ease;
}

.setting-list input:checked + i {
  background: var(--primary);
}

.setting-list input:checked + i::after {
  transform: translateX(20px);
}

.setting-list input:focus-visible + i {
  outline: 3px solid rgba(18, 107, 89, 0.28);
  outline-offset: 3px;
}

.backup-actions {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-top: 24px;
}

.tool-button {
  display: flex;
  min-height: 82px;
  align-items: center;
  gap: 12px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  cursor: pointer;
  text-align: left;
}

.tool-button:hover {
  border-color: #9baba5;
  background: var(--surface-2);
}

.tool-button > span:first-child {
  display: grid;
  width: 34px;
  height: 34px;
  flex: 0 0 auto;
  place-items: center;
  border-radius: 5px;
  color: var(--primary);
  background: var(--primary-soft);
  font-size: 20px;
}

.tool-button strong,
.tool-button small {
  display: block;
}

.tool-button small {
  color: var(--muted);
  font-size: 10px;
}

.danger-link {
  margin-top: 20px;
  color: var(--danger);
}

.legal-section {
  display: flex;
  align-items: flex-start;
  gap: 18px;
}

.legal-section h2 {
  margin-bottom: 6px;
  font-size: 18px;
}

.legal-section p {
  max-width: 700px;
  margin-bottom: 12px;
  color: var(--muted);
  font-size: 13px;
}

.legal-section small {
  color: var(--muted);
}

/* Training */
.training-page {
  min-height: 100vh;
  background: var(--bg);
}

.training-topbar {
  position: relative;
  z-index: 10;
  display: grid;
  width: min(920px, calc(100% - 48px));
  height: 72px;
  grid-template-columns: 48px 1fr 72px;
  align-items: center;
  margin: 0 auto;
}

.icon-button {
  display: grid;
  width: 40px;
  height: 40px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--surface);
  cursor: pointer;
  font-size: 28px;
  line-height: 1;
}

.progress-dots {
  display: flex;
  justify-content: center;
  gap: 8px;
}

.progress-dots i {
  width: 28px;
  height: 5px;
  border-radius: 3px;
  background: var(--line);
}

.progress-dots i.is-current {
  background: var(--primary);
}

.progress-dots i.is-done {
  background: #76aa9a;
}

.practice-mode-label {
  justify-self: center;
  color: var(--primary);
  font-size: 13px;
  font-weight: 700;
}

.training-timer {
  justify-self: end;
  font-variant-numeric: tabular-nums;
  font-weight: 700;
}

.training-content {
  display: grid;
  min-height: calc(100vh - 72px);
  place-items: center;
  padding: 24px 24px 54px;
}

.intro-view,
.summary-view,
.paused-view,
.countdown-view {
  display: grid;
  width: min(500px, 100%);
  justify-items: center;
  text-align: center;
}

.intro-meta {
  display: flex;
  width: 100%;
  justify-content: space-between;
  margin-bottom: 34px;
  color: var(--muted);
  font-size: 12px;
}

.intro-view h1 {
  margin-bottom: 10px;
  font-size: 36px;
}

.intro-view > p {
  max-width: 420px;
  min-height: 48px;
  margin-bottom: 30px;
  color: var(--muted);
}

.intro-view > .button {
  margin-top: 34px;
}

.intro-view > small {
  margin-top: 14px;
  color: var(--muted);
}

.intro-grid {
  display: grid;
  width: 220px;
  aspect-ratio: 1;
  grid-template-columns: repeat(4, 1fr);
  gap: 5px;
}

.intro-grid i {
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--surface);
  font-size: 13px;
  font-style: normal;
}

.spatial-preview {
  width: 210px;
  grid-template-columns: repeat(3, 1fr);
}

.spatial-preview i.is-lit {
  border-color: var(--orange);
  background: var(--orange-soft);
}

.intro-digits {
  min-height: 120px;
  align-content: center;
  font-size: 38px;
  font-variant-numeric: tabular-nums;
  font-weight: 700;
}

.countdown-view p,
.countdown-view span {
  color: var(--muted);
}

.countdown-view strong {
  margin: 18px 0;
  font-size: 120px;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.game-view {
  width: min(680px, 100%);
}

.game-heading {
  min-height: 76px;
  align-items: center;
  margin-bottom: 22px;
}

.game-heading h1 {
  font-size: 26px;
}

.target-display {
  display: grid;
  min-width: 82px;
  grid-template-columns: auto auto;
  align-items: center;
  gap: 0 8px;
  text-align: right;
}

.target-display span,
.target-display small {
  color: var(--muted);
  font-size: 10px;
}

.target-display strong {
  grid-row: span 2;
  color: var(--blue);
  font-size: 40px;
  line-height: 1;
}

.target-display strong.group-b {
  color: var(--orange);
}

.number-grid,
.spatial-grid {
  --grid-n: 4;
  display: grid;
  width: min(560px, 78vh, 100%);
  aspect-ratio: 1;
  grid-template-columns: repeat(var(--grid-n), minmax(0, 1fr));
  gap: 8px;
  margin: 0 auto;
}

.grid-cell,
.spatial-cell {
  min-width: 0;
  min-height: 0;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  cursor: pointer;
  font-size: 24px;
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  transition: transform 100ms ease, background 140ms ease, color 140ms ease;
}

.grid-cell:hover:not(:disabled),
.spatial-cell:hover {
  border-color: var(--primary);
  transform: translateY(-1px);
}

.grid-cell.group-a {
  color: var(--blue);
  background: var(--blue-soft);
}

.grid-cell.group-b {
  color: var(--orange);
  background: var(--orange-soft);
}

.grid-cell.is-done {
  color: transparent;
  border-color: transparent;
  background: var(--surface-2);
  cursor: default;
  opacity: 0.45;
}

.grid-cell.is-wrong,
.spatial-cell.is-wrong {
  color: var(--danger);
  border-color: var(--danger);
  background: var(--danger-soft);
  animation: shake 180ms linear 2;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  50% { transform: translateX(4px); }
}

.game-foot,
.spatial-controls {
  display: flex;
  width: min(560px, 100%);
  min-height: 52px;
  align-items: center;
  justify-content: space-between;
  margin: 12px auto 0;
  color: var(--muted);
  font-size: 13px;
}

.game-foot strong {
  color: var(--ink);
}

.round-count,
.level-badge {
  padding: 6px 9px;
  border-radius: 4px;
  color: var(--primary);
  background: var(--primary-soft);
  font-size: 12px;
  font-weight: 700;
}

.digit-stage {
  display: grid;
  min-height: 220px;
  place-items: center;
  align-content: center;
  gap: 20px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.digit-stage p,
.digit-stage small {
  margin: 0;
  color: var(--muted);
}

.digit-sequence,
.digit-feedback {
  max-width: 100%;
  padding: 0 16px;
  overflow-wrap: anywhere;
  font-size: 42px;
  font-variant-numeric: tabular-nums;
  line-height: 1.35;
}

.digit-slots {
  display: flex;
  width: min(560px, calc(100% - 30px));
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px;
}

.digit-slots i {
  display: grid;
  width: 34px;
  height: 46px;
  place-items: center;
  border-bottom: 2px solid var(--line);
  font-size: 24px;
  font-style: normal;
  font-weight: 700;
}

.digit-slots i.is-filled {
  border-color: var(--primary);
}

.keypad {
  display: grid;
  width: min(420px, 100%);
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin: 18px auto 0;
}

.keypad button {
  min-height: 54px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  cursor: pointer;
  font-size: 19px;
  font-weight: 700;
}

.keypad button:hover:not(.is-disabled) {
  border-color: var(--primary);
  background: var(--primary-soft);
}

.keypad .muted {
  color: var(--muted);
  background: var(--surface-2);
}

.keypad .confirm {
  color: white;
  border-color: var(--primary);
  background: var(--primary);
  font-size: 14px;
}

.spatial-cell {
  color: var(--ink);
  font-size: 16px;
}

.spatial-cell.is-lit {
  border-color: #d79a6f;
  background: var(--orange-soft);
}

.spatial-cell.is-selected {
  color: white;
  border-color: var(--primary);
  background: var(--primary);
}

.spatial-cell.is-picked {
  color: var(--primary);
  border-color: var(--primary);
  background: var(--primary-soft);
}

.summary-view,
.paused-view {
  gap: 12px;
}

.summary-icon,
.pause-symbol,
.completion-check {
  display: grid;
  width: 58px;
  height: 58px;
  margin-bottom: 12px;
  place-items: center;
  border-radius: 50%;
  color: var(--primary);
  background: var(--primary-soft);
  font-size: 26px;
}

.pause-symbol {
  color: var(--orange);
  background: var(--orange-soft);
  font-size: 18px;
  font-weight: 800;
}

.summary-view h1,
.paused-view h1 {
  margin-bottom: 0;
  font-size: 30px;
}

.summary-view > strong {
  font-size: 54px;
  line-height: 1.1;
}

.summary-view > p:not(.eyebrow),
.paused-view p {
  color: var(--muted);
}

.summary-view > .button,
.paused-view > .button {
  min-width: 180px;
  margin-top: 24px;
}

.summary-actions {
  display: flex;
  gap: 10px;
  margin-top: 24px;
}

.summary-actions .button {
  min-width: 150px;
}

/* Result */
.result-page {
  min-height: 100vh;
  padding: 34px 20px 54px;
  background: var(--bg);
}

.result-wrap {
  width: min(620px, 100%);
  margin: 0 auto;
}

.result-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 32px;
  font-size: 14px;
  font-weight: 700;
}

.result-brand .brand-grid {
  width: 30px;
  height: 30px;
}

.result-hero {
  display: grid;
  justify-items: center;
  min-height: 270px;
  align-content: center;
  text-align: center;
}

.result-number,
.baseline-number {
  margin: 4px 0;
  font-size: 80px;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.baseline-number {
  font-size: 58px;
}

.result-hero > span:not(.completion-check) {
  color: var(--muted);
}

.comparison {
  margin: 12px 0 0;
  font-size: 13px;
  font-weight: 700;
}

.comparison.up {
  color: var(--primary);
}

.comparison.down,
.comparison.neutral {
  color: var(--muted);
}

.result-details {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.result-row {
  display: grid;
  min-height: 82px;
  grid-template-columns: 42px 1fr auto 42px;
  align-items: center;
  gap: 14px;
  padding: 12px 18px;
}

.result-row + .result-row {
  border-top: 1px solid var(--line);
}

.result-game {
  margin: 0;
}

.result-row strong,
.result-row small {
  display: block;
}

.result-row small {
  color: var(--muted);
  font-size: 11px;
}

.result-row > b {
  font-size: 22px;
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.result-stats {
  grid-template-columns: repeat(2, 1fr);
  margin-top: 14px;
}

.result-note {
  margin: 20px auto;
  color: var(--muted);
  font-size: 11px;
  text-align: center;
}

.result-actions {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}

/* Modal and toast */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(9, 15, 13, 0.48);
}

.modal {
  width: min(390px, 100%);
  padding: 26px;
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.22);
}

.modal h2 {
  margin-bottom: 10px;
  font-size: 21px;
}

.modal p {
  color: var(--muted);
  font-size: 14px;
}

.modal-actions {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin-top: 24px;
}

.toast {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 120;
  max-width: calc(100% - 48px);
  padding: 11px 16px;
  border-radius: 5px;
  color: #fff;
  background: #25302c;
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transform: translateY(8px);
  transition: opacity 160ms ease, transform 160ms ease;
}

.toast.is-visible {
  opacity: 1;
  transform: translateY(0);
}

@media (max-width: 900px) {
  :root {
    --sidebar: 188px;
  }

  .page {
    width: min(100% - 40px, 900px);
  }

  .home-grid {
    grid-template-columns: 1fr;
  }

  .home-side {
    grid-template-columns: minmax(0, 0.7fr) minmax(0, 1.3fr);
  }

  .metrics-strip {
    grid-template-columns: 1fr;
  }

  .metrics-strip > div + div {
    border-top: 1px solid var(--line);
    border-left: 0;
  }

  .backup-actions,
  .best-list {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 700px) {
  .app-shell {
    padding: 0 0 calc(70px + env(safe-area-inset-bottom));
  }

  .sidebar {
    display: none;
  }

  .mobile-nav {
    position: fixed;
    right: 0;
    bottom: 0;
    left: 0;
    z-index: 30;
    display: grid;
    height: calc(64px + env(safe-area-inset-bottom));
    grid-template-columns: repeat(4, 1fr);
    padding: 4px 8px env(safe-area-inset-bottom);
    border-top: 1px solid var(--line);
    background: rgba(255, 255, 255, 0.96);
  }

  .mobile-nav .nav-item {
    display: grid;
    min-height: 54px;
    place-items: center;
    align-content: center;
    gap: 3px;
    padding: 0;
    font-size: 10px;
    text-align: center;
  }

  .mobile-nav .nav-item > span:first-child {
    font-size: 18px;
  }

  .page {
    width: calc(100% - 28px);
    padding: 28px 0 34px;
  }

  .page-header {
    min-height: 0;
    margin-bottom: 24px;
  }

  .page-header h1 {
    font-size: 30px;
  }

  .page-header p:not(.eyebrow) {
    font-size: 14px;
  }

  .hero-mark {
    width: 86px;
    gap: 4px;
  }

  .hero-mark i {
    font-size: 10px;
  }

  .home-header > div:first-child {
    min-width: 0;
  }

  .home-grid,
  .home-side {
    display: grid;
    grid-template-columns: 1fr;
  }

  .today-panel,
  .trend-panel,
  .form-section,
  .chart-section,
  .best-section,
  .records-section,
  .settings-section,
  .data-section,
  .legal-section {
    padding: 20px;
  }

  .today-panel {
    min-height: 0;
  }

  .panel-heading h2 {
    font-size: 23px;
  }

  .done-seal,
  .time-badge {
    width: 54px;
    height: 54px;
  }

  .training-steps li {
    padding: 13px 7px;
    font-size: 12px;
  }

  .score-hero strong {
    font-size: 52px;
  }

  .metrics-strip {
    grid-template-columns: repeat(3, 1fr);
  }

  .metrics-strip > div + div {
    border-top: 0;
    border-left: 1px solid var(--line);
  }

  .game-picker {
    grid-template-columns: 1fr;
  }

  .game-option {
    min-height: 90px;
    grid-template-columns: 46px 1fr;
    align-items: center;
    align-content: center;
  }

  .game-option .game-glyph {
    grid-row: span 2;
    margin: 0;
  }

  .segmented-control {
    grid-template-columns: 1fr;
  }

  .segmented-control button {
    min-height: 54px;
  }

  .sticky-action {
    display: grid;
    position: sticky;
    bottom: calc(68px + env(safe-area-inset-bottom));
    z-index: 5;
    padding: 10px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: rgba(255, 255, 255, 0.96);
    text-align: center;
  }

  .history-metrics strong {
    font-size: 16px;
  }

  .compact-tabs {
    width: 100%;
    margin-top: 14px;
  }

  .chart-section > .section-title {
    display: block;
  }

  .compact-tabs button {
    flex: 1;
    padding: 0 6px;
  }

  .bar-chart {
    height: 190px;
    gap: 4px;
  }

  .record-row {
    grid-template-columns: 1fr 52px;
    gap: 8px;
    padding: 13px 0;
  }

  .record-games {
    grid-column: 1 / -1;
    grid-row: 2;
  }

  .record-score {
    grid-column: 2;
    grid-row: 1;
  }

  .backup-actions {
    grid-template-columns: 1fr;
  }

  .local-badge {
    display: none;
  }

  .legal-section {
    display: grid;
  }

  .training-topbar {
    width: calc(100% - 24px);
    height: 60px;
    grid-template-columns: 44px 1fr 58px;
  }

  .training-content {
    min-height: calc(100vh - 60px);
    padding: 18px 14px calc(26px + env(safe-area-inset-bottom));
  }

  .intro-view h1 {
    font-size: 30px;
  }

  .intro-grid {
    width: 190px;
  }

  .game-heading h1 {
    font-size: 21px;
  }

  .number-grid,
  .spatial-grid {
    width: min(calc(100vw - 28px), 60vh, 500px);
    gap: 6px;
  }

  .grid-cell {
    font-size: 19px;
  }

  .number-grid.grid-n6 .grid-cell,
  .spatial-grid.grid-n6 .spatial-cell {
    font-size: 14px;
  }

  .digit-stage {
    min-height: 180px;
  }

  .digit-sequence,
  .digit-feedback {
    font-size: 32px;
  }

  .keypad button {
    min-height: 50px;
  }

  .summary-actions,
  .result-actions {
    display: grid;
    width: 100%;
    grid-template-columns: 1fr;
  }

  .summary-actions .button {
    width: 100%;
  }

  .result-page {
    padding-top: 24px;
  }

  .result-hero {
    min-height: 240px;
  }

  .result-number {
    font-size: 68px;
  }

  .result-row {
    grid-template-columns: 38px minmax(0, 1fr) auto;
    gap: 10px;
    padding: 12px;
  }

  .result-row .best-chip {
    display: none;
  }

  .result-game {
    width: 38px;
    height: 38px;
  }

  .toast {
    right: 14px;
    bottom: calc(78px + env(safe-area-inset-bottom));
    max-width: calc(100% - 28px);
  }
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #151a18;
    --surface: #1d2421;
    --surface-2: #28302d;
    --ink: #edf3f0;
    --muted: #a1ada8;
    --line: #34403b;
    --primary: #68c2a5;
    --primary-hover: #79ceb2;
    --primary-soft: #203d34;
    --blue: #81b7e5;
    --blue-soft: #23394a;
    --orange: #e6a06f;
    --orange-soft: #493326;
    --danger: #e77b73;
    --danger-soft: #4b2928;
    --shadow: 0 8px 28px rgba(0, 0, 0, 0.24);
  }

  .sidebar,
  .mobile-nav {
    background: rgba(29, 36, 33, 0.96);
  }

  .unfinished-banner {
    color: var(--ink);
    border-color: #674c33;
    background: #372b21;
  }

  .unfinished-symbol {
    color: #f0b77b;
    background: #543a26;
  }

  .sticky-action {
    background: rgba(29, 36, 33, 0.96);
  }

  .modal-backdrop {
    background: rgba(0, 0, 0, 0.65);
  }
}

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

.reduced-motion *,
.reduced-motion *::before,
.reduced-motion *::after {
  scroll-behavior: auto !important;
  animation-duration: 0.01ms !important;
  animation-iteration-count: 1 !important;
  transition-duration: 0.01ms !important;
}
