/* ── Reset ─────────────────────────────────────────────────────────────── */

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

/* ── Colour tokens ─────────────────────────────────────────────────────── */

:root {
  --bg: #f9f9f7;
  --surface: #ffffff;
  --border: #e5e5e0;
  --text: #1a1a1a;
  --text-muted: #888;
  --accent: #1a1a1a;
  --correct: #2d6a4f;
  --wrong: #c0392b;
  --easy: #1d5fa6;
  --btn-bg: #1a1a1a;
  --btn-text: #fff;
  --radius: 12px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f0f0f;
    --surface: #1a1a1a;
    --border: #2a2a2a;
    --text: #f0f0ee;
    --text-muted: #666;
    --accent: #f0f0ee;
    --btn-bg: #f0f0ee;
    --btn-text: #0f0f0f;
  }
}

/* ── Base ──────────────────────────────────────────────────────────────── */

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}

body {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  padding-bottom: var(--safe-bottom);
}

/* ── Navigation ────────────────────────────────────────────────────────── */

nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

nav a {
  color: var(--text-muted);
  text-decoration: none;
  font-size: 14px;
  letter-spacing: 0.02em;
}

nav a.active, nav a:hover { color: var(--text); }

.nav-brand {
  display: flex;
  align-items: center;
}

.nav-brand a {
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.02em;
  color: var(--text);
  text-decoration: none;
}

.nav-brand .separator {
  color: var(--border);
  margin: 0 8px;
}

.nav-brand .deck-link {
  font-size: 13px;
  color: var(--text-muted);
  text-decoration: none;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 120px;
}

nav .links {
  display: flex;
  gap: 20px;
  align-items: center;
}

/* ── Layout ────────────────────────────────────────────────────────────── */

main {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 24px 20px;
  max-width: 480px;
  width: 100%;
  margin: 0 auto;
}

@media (orientation: landscape) {
  main.wide { max-width: 1000px; }
}

h1 {
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -0.01em;
  margin-bottom: 24px;
}

/* ── Offline banner ────────────────────────────────────────────────────── */

.offline-banner {
  display: none;
  background: #fff3cd;
  color: #856404;
  text-align: center;
  padding: 8px;
  font-size: 13px;
}

@media (prefers-color-scheme: dark) {
  .offline-banner { background: #2a2000; color: #ccaa00; }
}

body.is-offline .offline-banner { display: block; }

/* ── Buttons ───────────────────────────────────────────────────────────── */

.btn {
  display: block;
  width: 100%;
  padding: 16px 20px;
  background: var(--btn-bg);
  color: var(--btn-text);
  border: none;
  border-radius: var(--radius);
  font-size: 16px;
  font-weight: 500;
  cursor: pointer;
  text-align: center;
  text-decoration: none;
  -webkit-tap-highlight-color: transparent;
  transition: opacity 0.15s;
}

.btn:active { opacity: 0.75; }

.btn-outline {
  background: transparent;
  border: 1.5px solid var(--border);
  color: var(--text);
}

.btn-correct { background: var(--correct); color: #fff; }
.btn-wrong   { background: var(--wrong);   color: #fff; }
.btn-easy    { background: var(--easy);    color: #fff; }

.btn-sm {
  width: auto;
  padding: 8px 14px;
  font-size: 14px;
  display: inline-block;
}

.btn-delete {
  color: var(--wrong);
  border-color: var(--wrong);
}

/* ── Form elements ─────────────────────────────────────────────────────── */

input[type="text"],
input[type="password"],
input[type="number"],
textarea {
  width: 100%;
  padding: 14px 16px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font-size: 16px;
  outline: none;
  transition: border-color 0.15s;
}

textarea {
  resize: vertical;
  font-family: inherit;
}

input[type="text"]:focus,
input[type="password"]:focus,
input[type="number"]:focus,
textarea:focus {
  border-color: var(--accent);
}

input[type="range"] {
  width: 100%;
  margin: 8px 0 4px;
}

.field { margin-bottom: 12px; }

.field label {
  display: block;
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.field label .note {
  font-weight: 400;
  text-transform: none;
  letter-spacing: 0;
}

.field .hint {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 6px;
}

.field .range-labels {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: var(--text-muted);
}

.checkbox-label {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 8px;
  text-transform: none;
  letter-spacing: normal;
  font-size: 14px;
  font-weight: 400;
  color: var(--text);
}

.form-footer { margin-top: 16px; }

/* ── Utilities ─────────────────────────────────────────────────────────── */

.stack   { display: flex; flex-direction: column; gap: 10px; }
.divider { height: 1px; background: var(--border); margin: 20px 0; }

.error {
  background: #fff0f0;
  border: 1px solid #ffcccc;
  color: var(--wrong);
  padding: 12px 16px;
  border-radius: var(--radius);
  font-size: 14px;
  margin-bottom: 16px;
}

@media (prefers-color-scheme: dark) {
  .error { background: #2a1010; border-color: #5a2020; }
}

.empty-message {
  color: var(--text-muted);
  font-size: 14px;
  padding: 20px 0;
}

.empty-message a { color: var(--text); }

/* ── Sort controls ─────────────────────────────────────────────────────── */

.sort-controls {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.sort-controls a {
  color: var(--text-muted);
  text-decoration: none;
}

.sort-controls a:hover,
.sort-controls a.active {
  color: var(--text);
}

.sort-controls a.active {
  font-weight: 500;
}

/* ── List rows (decks, cards) ──────────────────────────────────────────── */

.deck-list { margin-bottom: 24px; }


.list-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 0;
  border-bottom: 1px solid var(--border);
}

.list-row .name { font-size: 15px; }
.list-row .name.active { font-weight: 600; }

.list-row .meta {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 3px;
}

.list-row .actions {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
  margin-left: 12px;
}

.active-badge {
  margin-left: 8px;
  font-size: 11px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-muted);
}

/* ── Card pair (manage page) ───────────────────────────────────────────── */

.card-pair {
  flex: 1;
  min-width: 0;
}

.card-pair .separator {
  color: var(--text-muted);
  margin: 0 8px;
}

.card-pair .description {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 3px;
}

/* ── Login page ────────────────────────────────────────────────────────── */

main.login {
  padding: 40px 24px;
  max-width: 400px;
}

main.login .intro {
  display: flex;
  flex-direction: column;
  justify-content: center;
  flex: 1;
  padding-top: 40px;
}

main.login h1 {
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -0.03em;
  margin-bottom: 8px;
}

main.login .tagline {
  color: var(--text-muted);
  font-size: 14px;
  margin-bottom: 32px;
}

/* ── Game page ─────────────────────────────────────────────────────────── */

#game-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

#state-loading {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}

#state-loading p {
  color: var(--text-muted);
  font-size: 15px;
}

#state-empty,
#state-done {
  display: none;
  flex: 1;
  align-items: center;
  justify-content: center;
  text-align: center;
}

#state-empty p {
  color: var(--text-muted);
  font-size: 15px;
  margin-bottom: 20px;
}

#state-done .heading {
  font-size: 22px;
  font-weight: 600;
  letter-spacing: -0.02em;
  margin-bottom: 8px;
}

#done-next {
  color: var(--text-muted);
  font-size: 14px;
  margin-bottom: 4px;
}

#done-session {
  color: var(--text-muted);
  font-size: 13px;
}

#state-card {
  display: none;
  flex: 1;
  flex-direction: column;
  justify-content: space-between;
}

#state-card .content {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 20px 0;
}

#state-card .prompt {
  font-size: 36px;
  font-weight: 600;
  letter-spacing: -0.02em;
  line-height: 1.2;
  word-break: break-word;
}

#state-card .answer-area {
  margin-top: 32px;
  width: 100%;
}

#answer-shown { display: none; }

#state-card .answer {
  font-size: 24px;
  color: var(--text-muted);
  margin-bottom: 12px;
  word-break: break-word;
}

#state-card .description {
  font-size: 14px;
  color: var(--text-muted);
  margin-bottom: 28px;
  font-style: italic;
  display: none;
  word-break: break-word;
}

#state-card .answer-row {
  display: flex;
  gap: 8px;
}

#state-card .answer-row .btn {
  flex: 1;
  padding-left: 0;
  padding-right: 0;
}

#state-card .footer {
  padding-top: 16px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

#card-counter {
  font-size: 13px;
  color: var(--text-muted);
}

#sync-status {
  font-size: 12px;
  color: var(--text-muted);
}

/* ── Scores page ───────────────────────────────────────────────────────── */

.stat-grid {
  display: flex;
  gap: 24px;
  margin-bottom: 24px;
}

.stat-item .label {
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.stat-item .value {
  font-size: 24px;
  font-weight: 600;
}

.stat-item .value[data-wrong="true"] { color: var(--wrong); }

.scores-table {
  width: 100%;
  border-collapse: collapse;
}

.scores-table thead tr { border-bottom: 1px solid var(--border); }

.scores-table th {
  text-align: left;
  font-size: 11px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-muted);
  padding-bottom: 8px;
  font-weight: 500;
}

.scores-table th + th { padding-left: 8px; }
.scores-table th[title] { cursor: help; }

.scores-table td { padding: 10px 0; font-size: 14px; }
.scores-table td + td { padding-left: 8px; }
.scores-table td:first-child { font-size: 15px; }
.scores-table td:nth-child(2) { color: var(--text-muted); }
.scores-table td:nth-child(3),
.scores-table td:nth-child(4) { font-weight: 500; white-space: nowrap; }
.scores-table td:nth-child(5) { white-space: nowrap; font-size: 13px; }

/* Due column */
.scores-table [data-due="overdue"]            { color: var(--wrong); }
.scores-table [data-due="soon"]               { color: var(--correct); }
.scores-table [data-due="later"],
.scores-table [data-due="new"]                { color: var(--text-muted); }

/* Stability column */
.scores-table [data-stability="weak"]         { color: var(--wrong); }
.scores-table [data-stability="moderate"]     { color: inherit; }
.scores-table [data-stability="strong"]       { color: var(--correct); }
.scores-table [data-stability="none"],
.scores-table [data-stability="muted"]        { color: var(--text-muted); }

/* Stage column */
.scores-table [data-stage="learning"]         { color: var(--easy); }
.scores-table [data-stage="relearning"]       { color: var(--wrong); }
.scores-table [data-stage="review"]           { color: var(--correct); }
.scores-table [data-stage="new"]              { color: var(--text-muted); }
