:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --text: #1c1f24;
  --muted: #5f6672;
  --border: #d5d9e0;
  --accent: #2f6fde;
  --accent-text: #ffffff;
  --selected-bg: #e3edff;
  --ok: #1f9d55;
  --ok-bg: #dcf5e6;
  --bad: #d64545;
  --bad-bg: #fde3e3;
  --radius: 12px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14161a;
    --surface: #1f2228;
    --text: #e8eaee;
    --muted: #9aa1ad;
    --border: #353a43;
    --accent: #5b8ff0;
    --accent-text: #0d1117;
    --selected-bg: #22324f;
    --ok: #4cc983;
    --ok-bg: #173826;
    --bad: #f07171;
    --bad-bg: #3d1d1d;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

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

a { color: var(--accent); }

h1 { font-size: 1.6rem; margin: 0.5rem 0 1rem; }
h2 { font-size: 1.1rem; margin: 1.5rem 0 0.5rem; }

/* --- layout ------------------------------------------------------------ */

.nav {
  display: flex;
  gap: 4px;
  padding: 8px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.nav a {
  padding: 10px 14px;
  border-radius: 8px;
  color: var(--muted);
  text-decoration: none;
  font-weight: 600;
}

.nav a[aria-current="page"] { color: var(--text); background: var(--bg); }

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

.screen[hidden] { display: none; }

.stack {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 1.5rem;
}

/* --- buttons ----------------------------------------------------------- */

.btn {
  min-height: 56px;
  padding: 0 20px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  touch-action: manipulation;
}

.btn:disabled { opacity: 0.6; }

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-text);
}

.btn-small { min-height: 44px; padding: 0 16px; }

.btn-danger {
  background: var(--bad);
  border-color: var(--bad);
  color: #ffffff;
}

.btn-danger-quiet { color: var(--bad); border-color: var(--bad); }

/* An <a> used as a button needs the text centred like a real one. */
a.btn { display: inline-flex; align-items: center; justify-content: center; text-decoration: none; }

/* --- home / messages --------------------------------------------------- */

.home { text-align: center; padding-top: 2rem; }

.overview { color: var(--muted); font-size: 1.1rem; margin: 0; }

.msg {
  padding: 12px 14px;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--border);
}

.msg[hidden] { display: none; }
.msg-ok { background: var(--ok-bg); border-color: var(--ok); }
.msg-error { background: var(--bad-bg); border-color: var(--bad); }

/* --- forms ------------------------------------------------------------- */

.form { display: flex; flex-direction: column; gap: 14px; }

.field { display: flex; flex-direction: column; gap: 6px; border: 0; padding: 0; margin: 0; min-width: 0; }
.field[hidden] { display: none; }
.field > span, .field legend { font-weight: 600; padding: 0; }
.field small, .check small { color: var(--muted); font-weight: 400; }

input[type="text"], select, textarea {
  width: 100%;
  min-height: 48px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
}

textarea { resize: vertical; }

input:focus, select:focus, textarea:focus, .btn:focus-visible, .card:focus-visible, .chip:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.suffix-input { display: flex; align-items: center; gap: 6px; }
.suffix { color: var(--muted); }

.radios { display: flex; gap: 8px; }

.radio, .check {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 48px;
  padding: 0 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
}

.radio { flex: 1; justify-content: center; }
.radio input, .check input { width: 20px; height: 20px; margin: 0; accent-color: var(--accent); }

.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: -6px; }

.chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 0 14px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 0.95rem;
  touch-action: manipulation;
}

/* A chip that is a checkbox label (the practice filter) rather than a button. */
label.chip { cursor: pointer; }
label.chip input { width: 18px; height: 18px; margin: 0; accent-color: var(--accent); }
label.chip:has(input:checked) { border-color: var(--accent); font-weight: 600; }

.practise { margin-top: 1.5rem; text-align: left; }
.practise summary {
  min-height: 44px;
  display: flex;
  align-items: center;
  color: var(--muted);
  font-weight: 600;
  cursor: pointer;
}
.practise .field { margin-top: 12px; }
.practise .check { margin-top: 12px; }
.practise #filter-count { margin-top: 10px; }
.practise .chips:empty::after { content: "None yet."; color: var(--muted); font-size: 0.9rem; }

.nav-course {
  margin-left: auto;
  padding: 2px 8px;
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.03em;
  white-space: nowrap;
}

/* --- deck list --------------------------------------------------------- */

.deck-list li { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 10px; }
.deck-list a { font-weight: 600; }

/* --- word overview ----------------------------------------------------- */

/* Only the table scrolls sideways on a phone; the page itself never does. */
.table-scroll { overflow-x: auto; margin-top: 12px; }

.word-table { border-collapse: collapse; width: 100%; font-size: 0.95rem; }
.word-table th, .word-table td { padding: 10px 12px; text-align: left; white-space: nowrap; }
.word-table th { color: var(--muted); font-size: 0.85rem; border-bottom: 1px solid var(--border); }
.word-table tbody tr { border-bottom: 1px solid var(--border); }
.word-table tbody tr[hidden] { display: none; }
.word-table a { font-weight: 600; }
.word-table .muted-link { color: var(--muted); font-weight: 400; }
.word-table td small { margin-left: 6px; }

.form.bare { border: 0; padding: 0; margin: 0; }
.form.bare:disabled { opacity: 0.75; }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

/* --- tags -------------------------------------------------------------- */

.tag-list { margin-top: 1rem; }
.tag-row { display: block; padding: 12px 0; border-bottom: 1px solid var(--border); }
.tag-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.tag-name { font-weight: 600; }
.tag-head .btn { margin-left: auto; }
.tag-rename { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.tag-rename input[type="text"] { flex: 1 1 10rem; min-width: 0; }

/* --- game -------------------------------------------------------------- */

.game-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.clock, .progress-text { font-variant-numeric: tabular-nums; font-weight: 600; }
.round-text { font-size: 0.9rem; color: var(--muted); }
.clock { font-size: 1.3rem; }
.progress-text { color: var(--muted); }

.bar {
  height: 6px;
  margin: 10px 0 16px;
  border-radius: 3px;
  background: var(--border);
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  width: 0;
  background: var(--accent);
  transition: width 0.25s linear;
}

.board {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.card {
  min-height: 64px;
  min-width: 0;
  padding: 8px 10px;
  border: 2px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-weight: 600;
  overflow-wrap: anywhere;
  hyphens: auto;
  touch-action: manipulation;
  cursor: pointer;
  transition: background-color 0.12s, border-color 0.12s, opacity 0.3s;
}

.card.empty { visibility: hidden; }
.card.selected { border-color: var(--accent); background: var(--selected-bg); }
.card.matched { border-color: var(--ok); background: var(--ok-bg); opacity: 0.4; pointer-events: none; }
.card.wrong { border-color: var(--bad); background: var(--bad-bg); animation: shake 0.35s; }
.card.appear { animation: appear 0.3s ease-out; }

@keyframes shake {
  20%, 60% { transform: translateX(-5px); }
  40%, 80% { transform: translateX(5px); }
}

@keyframes appear {
  from { opacity: 0; transform: scale(0.96); }
}

@media (prefers-reduced-motion: reduce) {
  .card.wrong, .card.appear { animation: none; }
}

/* --- end screen -------------------------------------------------------- */

.stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin: 0;
}

.stats > div {
  padding: 12px;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--border);
  text-align: center;
}

.stats dt { color: var(--muted); font-size: 0.9rem; }
.stats dd { margin: 4px 0 0; font-size: 1.3rem; font-weight: 700; font-variant-numeric: tabular-nums; }

.failed-list { margin: 0; padding: 0; list-style: none; }

.failed-list li {
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}

/* --- accounts ---------------------------------------------------------- */

.nav { align-items: center; flex-wrap: wrap; }
.nav-logout { margin-left: auto; }

.nav-logout button {
  min-height: 40px;
  padding: 0 12px;
  border: 0;
  border-radius: 8px;
  background: none;
  color: var(--muted);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

.login { max-width: 380px; margin: 2rem auto 0; }
.login h1 { text-align: center; }

.section { margin-top: 1.5rem; padding-top: 1.5rem; border-top: 1px solid var(--border); }
.section h2 { margin-top: 0; }
.muted { color: var(--muted); }
.hint { color: var(--muted); font-size: 0.9rem; line-height: 1.4; margin: 0; }

.user-list { margin: 0; padding: 0; list-style: none; }
.user-list li { padding: 10px 0; border-bottom: 1px solid var(--border); overflow-wrap: anywhere; }

.tag {
  display: inline-block;
  margin-left: 6px;
  padding: 1px 8px;
  border-radius: 999px;
  background: var(--selected-bg);
  font-size: 0.8rem;
}

.tag-off { background: var(--bad-bg); }

/* --- courses ----------------------------------------------------------- */

.course-picker { text-align: left; margin-top: 1rem; }
.course-picker h2 { margin-top: 0; }

.course-switch, .course-new {
  margin-top: 1.5rem;
  text-align: left;
}

.course-switch summary, .course-new summary {
  min-height: 44px;
  display: flex;
  align-items: center;
  color: var(--muted);
  font-weight: 600;
  cursor: pointer;
}

.course-new .form { margin-top: 8px; }
.stack form { display: contents; }

.board-head {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 600;
  text-align: center;
}

/* --- profile ----------------------------------------------------------- */

.stats-wide { grid-template-columns: repeat(auto-fit, minmax(96px, 1fr)); }

.boxes { margin: 0; padding: 0; list-style: none; display: grid; gap: 8px; }

.boxes li {
  display: grid;
  grid-template-columns: 4rem 1fr 3rem;
  align-items: center;
  gap: 10px;
}

.box-label { color: var(--muted); font-weight: 600; }
.box-count { text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }

.box-bar {
  height: 14px;
  border-radius: 7px;
  background: var(--border);
  overflow: hidden;
}

.box-bar span { display: block; height: 100%; background: var(--accent); border-radius: 7px; }

.plain-list { margin: 0; padding: 0; list-style: none; }

.plain-list li {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 4px 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  overflow-wrap: anywhere;
}
