:root {
  --bg: #efe6d4;
  --bg-deep: #e4d8c0;
  --paper: #fbf6ec;
  --ink: #1f1a14;
  --ink-soft: #5c5348;
  --line: #d8ccb6;
  --pine: #1e5c4a;
  --pine-deep: #143f34;
  --pine-soft: #e6f0eb;
  --seal: #b5402e;
  --gold: #b8902a;
  --ok: #2a7a5a;
  --shadow: 0 10px 30px rgba(70, 50, 20, 0.08);
  --radius: 18px;
  --sans: "PingFang SC", "Hiragino Sans GB", "Noto Sans SC", "Source Han Sans SC",
    "Microsoft YaHei", "Segoe UI", system-ui, sans-serif;
  --serif: "Songti SC", "STSong", "Noto Serif SC", "Source Han Serif SC",
    "PMingLiU", "Times New Roman", serif;
  --mono: "SF Mono", "Cascadia Mono", "JetBrains Mono", ui-monospace, Menlo, Consolas, monospace;
}

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

html, body { margin: 0; padding: 0; }

html { scroll-behavior: smooth; }

body {
  min-height: 100vh;
  font-family: var(--sans);
  color: var(--ink);
  background:
    radial-gradient(ellipse at 12% -10%, rgba(184, 144, 42, 0.14), transparent 42%),
    radial-gradient(ellipse at 100% 0%, rgba(30, 92, 74, 0.1), transparent 36%),
    linear-gradient(180deg, var(--bg) 0%, var(--bg-deep) 100%);
  line-height: 1.65;
}

.skip {
  position: absolute;
  left: 12px;
  top: -40px;
  background: var(--ink);
  color: var(--paper);
  padding: 6px 10px;
  border-radius: 8px;
  z-index: 20;
}
.skip:focus { top: 12px; }

a { color: var(--pine); text-decoration-thickness: 1px; text-underline-offset: 3px; }
a:hover { color: var(--pine-deep); }

.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  max-width: 980px;
  margin: 0 auto;
  padding: 20px 20px 8px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  color: inherit;
  text-decoration: none;
}

.brand-seal {
  width: 44px;
  height: 44px;
  border: 2px solid var(--seal);
  color: var(--seal);
  border-radius: 6px;
  display: grid;
  place-items: center;
  font-family: var(--serif);
  font-size: 22px;
  font-weight: 700;
  transform: rotate(-8deg);
  box-shadow: inset 0 0 0 1px rgba(181, 64, 46, 0.25);
}

.brand-text { display: flex; flex-direction: column; line-height: 1.2; }
.brand-text strong { font-family: var(--serif); font-size: 20px; letter-spacing: 0.04em; }
.brand-text small { color: var(--ink-soft); font-size: 12px; }

.site-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.site-nav a {
  color: var(--ink-soft);
  text-decoration: none;
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 14px;
}

.site-nav a:hover,
.site-nav a:focus-visible { background: rgba(255,255,255,0.55); color: var(--ink); }

.site-nav a[aria-current="page"] {
  background: var(--pine);
  color: #f7f3ea;
}

main {
  max-width: 980px;
  margin: 0 auto;
  padding: 12px 20px 48px;
}

.hero { padding: 18px 0 8px; max-width: 720px; }
.eyebrow {
  margin: 0 0 8px;
  color: var(--pine);
  letter-spacing: 0.16em;
  font-size: 12px;
  text-transform: none;
}
.hero h1, .view-head h1 {
  font-family: var(--serif);
  font-weight: 600;
  letter-spacing: 0.03em;
  line-height: 1.3;
  margin: 0 0 12px;
  font-size: clamp(28px, 5vw, 40px);
}
.lede, .view-head p { margin: 0; color: var(--ink-soft); font-size: 16px; }

.game-cards {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  margin-top: 28px;
}

.game-card {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 22px 20px 18px;
  text-decoration: none;
  color: inherit;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  min-height: 230px;
  transition: transform 160ms ease, box-shadow 160ms ease;
}
.game-card:hover { transform: translateY(-3px); box-shadow: 0 16px 36px rgba(70, 50, 20, 0.12); }

.card-index {
  font-family: var(--mono);
  color: var(--gold);
  font-size: 12px;
  letter-spacing: 0.08em;
}
.game-card h2 {
  font-family: var(--serif);
  margin: 12px 0 8px;
  font-size: 24px;
}
.game-card p { margin: 0; color: var(--ink-soft); font-size: 14px; }
.card-best {
  margin-top: auto !important;
  padding-top: 16px;
  color: var(--pine) !important;
  font-weight: 600;
}

.view-head { margin: 8px 0 20px; max-width: 680px; }

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: end;
  margin-bottom: 16px;
}

.toolbar label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 12px;
  color: var(--ink-soft);
}

select, .btn {
  font: inherit;
  color: var(--ink);
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 14px;
  min-height: 44px;
}

select { min-width: 150px; }

.btn {
  cursor: pointer;
  touch-action: manipulation;
  transition: background 120ms ease, transform 120ms ease;
}
.btn:hover { background: #fff; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; transform: none; }

.btn.primary {
  background: var(--pine);
  border-color: var(--pine);
  color: #f6f3ea;
  font-weight: 600;
  padding-inline: 20px;
}
.btn.primary:hover { background: var(--pine-deep); border-color: var(--pine-deep); }

.btn.ghost {
  background: transparent;
  border-color: transparent;
  min-height: 36px;
  padding: 6px 10px;
  color: var(--ink-soft);
}
.btn.danger-text { color: var(--seal); }
.btn.danger { background: var(--seal); border-color: var(--seal); color: #fff; }

.status-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  margin-bottom: 16px;
}

.stat {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 10px 12px;
}
.stat-label { display: block; font-size: 12px; color: var(--ink-soft); }
.stat-value { display: block; font-size: 22px; font-weight: 650; line-height: 1.3; }
.mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }

.schulte-board {
  display: grid;
  gap: 8px;
  width: min(100%, 560px);
  margin: 0 auto 16px;
  aspect-ratio: 1;
}

.schulte-cell {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--paper);
  border-radius: 12px;
  font: inherit;
  font-weight: 650;
  color: var(--ink);
  cursor: pointer;
  touch-action: manipulation;
  box-shadow: 0 1px 0 rgba(255,255,255,0.8) inset;
}
.schulte-cell.word { font-size: clamp(11px, 2.4vw, 16px); font-weight: 600; }
.schulte-cell:not(.word) { font-size: clamp(18px, 5vw, 28px); font-family: var(--mono); }
.schulte-cell:enabled:hover { background: #fff; }
.schulte-cell:enabled:focus-visible { outline: 3px solid var(--pine); outline-offset: 1px; }
.schulte-cell.done {
  background: var(--pine-soft);
  color: var(--pine-deep);
  border-color: #c9ddd4;
  cursor: default;
}
.schulte-cell.wrong {
  background: #f8e6e2;
  border-color: var(--seal);
  color: var(--seal);
  animation: shake 280ms ease;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-3px); }
  75% { transform: translateX(3px); }
}

.feedback {
  min-height: 1.6em;
  text-align: center;
  font-weight: 600;
  margin: 0 0 24px;
}
.feedback.ok { color: var(--ok); }
.feedback.bad { color: var(--seal); }

.stroop-stage, .nback-stage {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 22px;
  padding: 24px 16px 20px;
  box-shadow: var(--shadow);
  margin-bottom: 16px;
  text-align: center;
}

.stroop-hint, .hint-keys, .stroop-keys {
  margin: 0;
  color: var(--ink-soft);
  font-size: 13px;
}

.stroop-word {
  margin: 18px 0;
  font-family: var(--serif);
  font-size: clamp(48px, 14vw, 88px);
  font-weight: 700;
  letter-spacing: 0.12em;
  min-height: 1.2em;
  line-height: 1.1;
  user-select: none;
}

.color-buttons {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
  max-width: 640px;
  margin: 0 auto;
}

.color-btn {
  border: 0;
  border-radius: 14px;
  min-height: 56px;
  color: #fff;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  touch-action: manipulation;
  box-shadow: 0 3px 0 rgba(0,0,0,0.12);
}
.color-btn:disabled { opacity: 0.5; cursor: not-allowed; }
.color-btn[data-color="red"] { background: #c23a2b; }
.color-btn[data-color="green"] { background: #1e7a4a; }
.color-btn[data-color="blue"] { background: #2a5ea8; }
.color-btn[data-color="yellow"] { background: #c9a227; color: #2a220c; }
.color-btn[data-color="purple"] { background: #6b3fa0; }

.nback-letter {
  font-family: var(--mono);
  font-size: 42px;
  font-weight: 700;
  letter-spacing: 0.08em;
  margin: 0 0 12px;
  min-height: 52px;
  color: var(--ink);
}

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

.nback-cell {
  border-radius: 14px;
  background: #efe6d4;
  border: 1px solid var(--line);
}
.nback-cell.active {
  background: var(--pine);
  border-color: var(--pine-deep);
  box-shadow: 0 0 0 4px rgba(30, 92, 74, 0.18);
}

.nback-actions {
  display: flex;
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap;
}

.btn.match {
  min-width: 140px;
  min-height: 52px;
  background: var(--ink);
  color: var(--paper);
  border-color: var(--ink);
  font-size: 18px;
  font-weight: 700;
}
.btn.match:hover { background: #000; }
.btn.match.pressed { background: var(--pine); border-color: var(--pine); }

.history {
  background: rgba(251, 246, 236, 0.7);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px 18px 10px;
}

.history-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}
.history h2 {
  margin: 0;
  font-family: var(--serif);
  font-size: 20px;
}
.best-line { margin: 8px 0 12px; color: var(--pine-deep); font-weight: 600; }

.chart-wrap {
  width: 100%;
  height: 140px;
  margin-bottom: 8px;
}
.chart-wrap svg { width: 100%; height: 100%; display: block; }
.chart-empty {
  height: 100%;
  display: grid;
  place-items: center;
  color: var(--ink-soft);
  font-size: 14px;
}

.history-list {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: 280px;
  overflow: auto;
}
.history-list li {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 9px 0;
  border-top: 1px solid var(--line);
  font-size: 14px;
}
.history-list .when { color: var(--ink-soft); white-space: nowrap; }

.site-footer {
  max-width: 980px;
  margin: 0 auto;
  padding: 0 20px 40px;
  color: var(--ink-soft);
  font-size: 13px;
}

.dialog {
  position: fixed;
  inset: 0;
  background: rgba(31, 26, 20, 0.35);
  display: grid;
  place-items: center;
  z-index: 30;
  padding: 20px;
}
.dialog[hidden] { display: none !important; }
.dialog-card {
  background: var(--paper);
  border-radius: 18px;
  padding: 22px;
  max-width: 400px;
  width: 100%;
  box-shadow: var(--shadow);
}
.dialog-card h2 { font-family: var(--serif); margin: 0 0 8px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }

@media (max-width: 800px) {
  .game-cards { grid-template-columns: 1fr; }
  .site-header { flex-direction: column; align-items: flex-start; }
  .status-row { grid-template-columns: 1fr 1fr; }
  .color-buttons { grid-template-columns: 1fr 1fr; }
  .color-buttons .color-btn:last-child { grid-column: 1 / -1; }
  .schulte-board { gap: 5px; }
  .schulte-cell { border-radius: 8px; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  .game-card, .btn, .schulte-cell.wrong { transition: none; animation: none; }
}
