:root {
  --bg: #0f1419;
  --surface: #182029;
  --surface-2: #212c38;
  --text: #e8edf2;
  --muted: #9aa8b6;
  --border: #2d3a48;
  --accent: #4aa3ff;
  --correct: #2f9e5b;
  --partial: #c79a1b;
  --absent: #3a4552;
  --radius: 10px;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f5f7fa;
    --surface: #ffffff;
    --surface-2: #eef2f6;
    --text: #17202a;
    --muted: #5b6876;
    --border: #d5dde6;
    --accent: #0b6bcb;
    --correct: #2a8a50;
    --partial: #b8860b;
    --absent: #8b97a5;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

.sr-only {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}

.top {
  display: flex; align-items: center; justify-content: space-between;
  max-width: 960px; margin: 0 auto; padding: 16px;
  border-bottom: 1px solid var(--border);
}
h1 { margin: 0; font-size: 1.7rem; letter-spacing: 0.04em; }
.tagline { margin: 0; color: var(--muted); font-size: 0.9rem; }
.top-actions { display: flex; gap: 8px; }

main { max-width: 960px; margin: 0 auto; padding: 16px; }

button, input {
  font: inherit; color: inherit;
}
button {
  cursor: pointer; border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--accent); color: #fff; padding: 8px 16px; font-weight: 600;
}
button:hover:not(:disabled) { filter: brightness(1.1); }
button:disabled { opacity: 0.5; cursor: not-allowed; }
button:focus-visible, input:focus-visible, summary:focus-visible {
  outline: 3px solid var(--accent); outline-offset: 2px;
}
button.secondary, .icon-btn, .chip {
  background: var(--surface); color: var(--text);
}
.icon-btn { width: 40px; height: 40px; padding: 0; font-size: 1.1rem; }
.chip[aria-pressed="true"] { background: var(--accent); color: #fff; border-color: var(--accent); }
.mode-bar { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }

#guess-form { display: flex; gap: 8px; }
#guess-input {
  flex: 1; min-width: 0; padding: 10px 12px; border-radius: var(--radius);
  border: 1px solid var(--border); background: var(--surface);
}

#message { min-height: 1.5em; margin: 8px 0 0; color: var(--muted); }
.counter { margin: 0 0 8px; font-size: 0.9rem; color: var(--muted); }

.board-scroll { overflow-x: auto; padding-bottom: 8px; }
.board { min-width: 760px; display: grid; gap: 6px; }
.row {
  display: grid; gap: 6px;
  grid-template-columns: minmax(150px, 1.5fr) repeat(6, minmax(90px, 1fr));
}
.row.head .cell {
  background: none; border: none; color: var(--muted);
  font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.05em; padding: 0 4px;
}
.cell {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 8px; padding: 8px; font-size: 0.85rem;
  display: flex; flex-direction: column; justify-content: center; min-height: 56px;
}
.cell.name { font-weight: 700; }
.cell.correct { background: var(--correct); border-color: var(--correct); color: #fff; }
.cell.partial { background: var(--partial); border-color: var(--partial); color: #fff; }
.cell.absent { background: var(--absent); border-color: var(--absent); color: #fff; }
.cell .sym { font-size: 0.7rem; opacity: 0.9; font-weight: 700; }

.actions { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; }
.clue {
  margin: 12px 0 0; padding: 12px 14px; border-left: 4px solid var(--accent);
  background: var(--surface); border-radius: 0 var(--radius) var(--radius) 0;
}

.result {
  margin-top: 16px; padding: 16px; border: 1px solid var(--border);
  border-radius: var(--radius); background: var(--surface);
}
.result h2 { margin: 0 0 4px; }
.result .meta { color: var(--muted); font-size: 0.9rem; margin: 0 0 8px; }
.result .tip { margin: 8px 0; }
.result a { color: var(--accent); }
.result pre {
  background: var(--surface-2); padding: 10px; border-radius: 8px;
  overflow-x: auto; font-size: 0.95rem;
}
.result .row-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

.sheet { margin-top: 24px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
.sheet summary { cursor: pointer; padding: 12px 16px; font-weight: 600; }
.sheet-wrap { overflow-x: auto; padding: 0 16px 16px; }
table { border-collapse: collapse; width: 100%; font-size: 0.85rem; }
th, td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { color: var(--muted); font-weight: 600; white-space: nowrap; }
tr.group td { background: var(--surface-2); font-weight: 700; }

dialog {
  max-width: 520px; width: calc(100% - 32px);
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface); color: var(--text); padding: 20px;
}
dialog::backdrop { background: rgba(0, 0, 0, 0.55); }
dialog h2 { margin-top: 0; }
.legend { list-style: none; padding: 0; display: grid; gap: 8px; }
.legend li { display: flex; gap: 10px; align-items: center; }
.tile {
  display: inline-flex; align-items: center; justify-content: center;
  width: 28px; height: 28px; border-radius: 6px; color: #fff; font-weight: 700; flex: none;
}
.tile.correct { background: var(--correct); }
.tile.partial { background: var(--partial); }
.tile.absent { background: var(--absent); }

.stat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; text-align: center; margin-bottom: 12px; }
.stat-grid strong { display: block; font-size: 1.6rem; }
.stat-grid span { font-size: 0.75rem; color: var(--muted); }

footer { max-width: 960px; margin: 0 auto; padding: 16px; color: var(--muted); font-size: 0.8rem; }

@media (max-width: 520px) {
  main, .top, footer { padding-left: 12px; padding-right: 12px; }
}

/* ---------- tabs and shared layout ---------- */
.tabs {
  max-width: 960px; margin: 0 auto; padding: 12px 16px 0;
  display: flex; gap: 6px; flex-wrap: wrap;
}
.tabs button {
  background: var(--surface); color: var(--text); border-radius: 999px; padding: 8px 16px;
}
.tabs button[aria-selected="true"] { background: var(--accent); border-color: var(--accent); color: #fff; }
.intro { margin: 0 0 14px; color: var(--muted); }
.toolbar { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; flex-wrap: wrap; }
.toolbar .mode-bar { margin-bottom: 12px; }
.big { font-size: 1.8rem; font-weight: 700; margin: 4px 0; }
.meta { color: var(--muted); font-size: 0.9rem; }
.message-line { min-height: 1.5em; margin: 6px 0; color: var(--muted); }
h2 { margin: 8px 0; }
h3 { margin: 18px 0 8px; }

/* ---------- scenarios ---------- */
.tag {
  display: inline-block; font-size: 0.8rem; padding: 3px 10px; border-radius: 999px;
  background: var(--surface-2); border: 1px solid var(--border); color: var(--muted); margin-bottom: 8px;
}
.prompt { font-size: 1.1rem; margin: 6px 0 12px; }
.options { display: grid; gap: 8px; margin: 12px 0; }
.opt {
  display: flex; flex-direction: column; align-items: flex-start; gap: 4px; text-align: left;
  width: 100%; background: var(--surface); color: var(--text); font-weight: 600;
}
.opt:disabled { opacity: 1; cursor: default; }
.opt-score { font-size: 0.8rem; font-weight: 700; }
.opt-why { font-size: 0.9rem; font-weight: 400; }
.opt.s3 { border-color: var(--correct); box-shadow: inset 4px 0 0 var(--correct); }
.opt.s2 { border-color: var(--partial); box-shadow: inset 4px 0 0 var(--partial); }
.opt.s1 { border-color: var(--absent); box-shadow: inset 4px 0 0 var(--absent); }
.opt.s0 { border-color: var(--border); box-shadow: inset 4px 0 0 var(--border); }
.opt.picked { outline: 3px solid var(--accent); outline-offset: 2px; }
.feedback { font-weight: 600; margin: 10px 0; }

/* ---------- memory pairs ---------- */
.mem-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 12px 0; }
@media (min-width: 700px) { .mem-grid { grid-template-columns: repeat(4, 1fr); } }
.mem-card {
  min-height: 92px; padding: 10px; font-size: 0.9rem; line-height: 1.3;
  background: var(--surface-2); color: var(--muted); font-weight: 600;
  display: flex; align-items: center; justify-content: center; text-align: center;
}
.mem-card.up { background: var(--surface); color: var(--text); border-color: var(--accent); }
.mem-card.up.is-name, .mem-card.done.is-name { font-weight: 700; }
.mem-card.done { background: var(--correct); border-color: var(--correct); color: #fff; opacity: 1; }
.mem-card:disabled { cursor: default; }

/* ---------- progress ---------- */
.lv { font-size: 0.75rem; font-weight: 700; padding: 2px 8px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--border); }
.lv2 { border-color: var(--absent); }
.lv3 { border-color: var(--partial); }
.lv4 { background: var(--correct); border-color: var(--correct); color: #fff; }
.pips { letter-spacing: 3px; }
.tools { margin-top: 24px; }
.import-box {
  width: 100%; padding: 10px; border-radius: var(--radius); border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font: inherit; margin-bottom: 8px;
}
button.danger { background: transparent; color: #d64545; border-color: #d64545; }
#prog-root .sheet-wrap { padding: 0; }
