/* Design system: GUIDELINES.md applied to light mode.
   Monochrome + single teal accent. DM Sans body, IBM Plex Mono labels. Tight density. */

:root {
  --base:    #ffffff;
  --surface: #fafafa;
  --border:  rgba(0,0,0,0.10);
  --muted:   #888888;
  --text:    #1a1a1a;
  --primary: #0d0d0d;
  --accent:  #1d9e75;
  --hover:   rgba(0,0,0,0.04);

  --r-pill: 3px;
  --r-input: 6px;
  --r-panel: 8px;

  --t: 150ms ease;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--base);
  color: var(--text);
  font-family: "DM Sans", system-ui, sans-serif;
  font-size: 13px;
  font-weight: 400;
  line-height: 1.5;
}

body {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ---------- Top bar ---------- */
.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: max(8px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right))
           8px max(16px, env(safe-area-inset-left));
  border-bottom: 0.5px solid var(--border);
}

.brand {
  font-weight: 600;
  font-size: 13px;
  letter-spacing: 0.02em;
}

.modes {
  display: flex;
  gap: 2px;
}
.mode-btn {
  font-family: "IBM Plex Mono", monospace;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--muted);
  background: transparent;
  border: none;
  border-bottom: 1px solid transparent;
  padding: 4px 6px;
  cursor: pointer;
  transition: color var(--t), border-color var(--t);
}
.mode-btn:hover { color: var(--text); }
.mode-btn.active {
  color: var(--text);
  border-bottom-color: var(--accent);
}

.decks {
  display: flex;
  gap: 4px;
  margin-left: 8px;
}

.deck-btn {
  font-family: "IBM Plex Mono", monospace;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--muted);
  background: transparent;
  border: 0.5px solid transparent;
  border-radius: var(--r-pill);
  padding: 4px 8px;
  cursor: pointer;
  transition: background var(--t), color var(--t), border-color var(--t);
}
.deck-btn:hover { background: var(--hover); color: var(--text); }
.deck-btn.active {
  color: var(--accent);
  border-color: var(--accent);
}

.concept-select {
  font-family: "IBM Plex Mono", monospace;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  background: transparent;
  border: 0.5px solid var(--border);
  border-radius: var(--r-pill);
  padding: 4px 8px;
  cursor: pointer;
  max-width: 280px;
  transition: background var(--t), color var(--t), border-color var(--t);
}
.concept-select:hover { background: var(--hover); color: var(--text); }
.concept-select:focus { outline: none; border-color: var(--accent); color: var(--text); }

.stats {
  margin-left: auto;
  font-family: "IBM Plex Mono", monospace;
  font-size: 10px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
}
.stats .stat-accent { color: var(--accent); }

/* ---------- Stage ---------- */
.stage {
  flex: 1;
  max-width: 760px;
  width: 100%;
  margin: 0 auto;
  padding: 24px 16px;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 16px;
}

/* ---------- Card ---------- */
.card {
  appearance: none;
  background: var(--base);
  border: 0.5px solid var(--border);
  border-radius: var(--r-panel);
  padding: 24px;
  min-height: 280px;
  text-align: left;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 12px;
  color: inherit;
  font: inherit;
  transition: background var(--t), border-color var(--t);
}
.card:hover { background: var(--surface); }
.card:focus { outline: none; border-color: var(--accent); }

.card-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}

.card-tag,
.card-added {
  font-family: "IBM Plex Mono", monospace;
  font-size: 10px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
}

.card-added {
  flex-shrink: 0;
  text-align: right;
}

.card-added .badge-new {
  display: inline-block;
  margin-left: 6px;
  padding: 1px 5px;
  border: 0.5px solid var(--accent);
  border-radius: var(--r-pill);
  color: var(--accent);
}

.card-q {
  font-size: 15px;
  font-weight: 600;
  color: var(--primary);
  line-height: 1.35;
}

.card-a {
  font-size: 13px;
  color: var(--text);
  border-top: 0.5px solid var(--border);
  padding-top: 12px;
}

.card-hint {
  margin-top: auto;
  font-family: "IBM Plex Mono", monospace;
  font-size: 10px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
}
.card-hint kbd {
  font-family: inherit;
  font-size: 10px;
  background: var(--surface);
  border: 0.5px solid var(--border);
  border-radius: var(--r-pill);
  padding: 1px 4px;
  margin: 0 2px;
}
.card.revealed .card-hint { display: none; }

/* ---------- Rating controls ---------- */
.controls {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}
.rate {
  appearance: none;
  background: var(--base);
  color: var(--text);
  font-family: "DM Sans", sans-serif;
  font-size: 12px;
  font-weight: 500;
  height: 32px;
  padding: 0 12px;
  border: 0.5px solid var(--border);
  border-radius: var(--r-input);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: background var(--t), border-color var(--t), color var(--t);
}
.rate:hover { background: var(--hover); }
.rate span {
  font-family: "IBM Plex Mono", monospace;
  font-size: 10px;
  color: var(--muted);
}
.rate[data-rate="again"] { background: #c0392b;     border-color: #c0392b;     color: #fff; }
.rate[data-rate="hard"]  { background: #d68a3c;     border-color: #d68a3c;     color: #fff; }
.rate[data-rate="good"]  { background: var(--accent); border-color: var(--accent); color: #fff; }
.rate[data-rate="easy"]  { background: #6cc9a0;     border-color: #6cc9a0;     color: #fff; }
.rate[data-rate] span { color: rgba(255,255,255,0.7); }
.rate[data-rate]:hover { filter: brightness(0.95); }

/* ---------- Browse mode ---------- */
.notes {
  display: flex;
  flex-direction: column;
  gap: 32px;
  padding-bottom: 32px;
}
.note { display: flex; flex-direction: column; gap: 8px; }
.note-tag {
  font-family: "IBM Plex Mono", monospace;
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 0;
  padding-bottom: 4px;
  border-bottom: 0.5px solid var(--border);
}
.note-section { font-size: 15px; font-weight: 600; color: var(--primary); margin: 12px 0 0 0; padding: 6px 10px; background: var(--surface); border-radius: 4px; line-height: 1.35; }
.notes-actions { display: flex; justify-content: flex-end; }
.notes-action { background: var(--base); border: 0.5px solid var(--border); padding: 6px 12px; font-size: 12px; border-radius: 4px; cursor: pointer; font-family: "DM Sans", sans-serif; color: var(--text); }
.notes-action:hover { background: var(--hover); }
.source-link { margin-left: 8px; color: var(--muted); text-decoration: none; }
.source-link:hover { color: var(--accent); }
.note-body {
  font-size: 13px;
  color: var(--text);
  line-height: 1.55;
}
.note-body p,
.card-a p { margin: 0 0 8px 0; }
.note-body p:last-child,
.card-a p:last-child { margin-bottom: 0; }
.note-body ul,
.card-a ul { margin: 0 0 8px 0; padding-left: 20px; }
.note-body li,
.card-a li { margin: 0 0 2px 0; }
.note-body h4,
.card-a h4 {
  font-size: 13px;
  font-weight: 600;
  margin: 12px 0 4px 0;
}
.note-body code,
.card-a code {
  font-family: "IBM Plex Mono", monospace;
  font-size: 12px;
  background: var(--surface);
  padding: 1px 4px;
  border-radius: var(--r-pill);
}
.note-body a,
.card-a a { color: var(--accent); text-decoration: none; }
.note-body a:hover,
.card-a a:hover { text-decoration: underline; }
.notes-empty {
  font-family: "IBM Plex Mono", monospace;
  font-size: 11px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
  text-align: center;
  padding: 48px 0;
}

/* ---------- Done state ---------- */
.done {
  border: 0.5px solid var(--border);
  border-radius: var(--r-panel);
  padding: 24px;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
}
.done-title {
  font-size: 15px;
  font-weight: 600;
}
.done-sub {
  color: var(--muted);
  font-family: "IBM Plex Mono", monospace;
  font-size: 11px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}
.restart {
  margin-top: 8px;
  appearance: none;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--r-input);
  height: 32px;
  padding: 0 16px;
  font: inherit;
  font-weight: 500;
  cursor: pointer;
}
.restart:hover { filter: brightness(0.95); }

/* ---------- Bottom bar ---------- */
.bottombar {
  border-top: 0.5px solid var(--border);
  padding: 8px max(16px, env(safe-area-inset-right))
           max(8px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  display: flex;
  align-items: center;
  gap: 12px;
}
.hint,
.build-stamp {
  font-family: "IBM Plex Mono", monospace;
  font-size: 10px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
}
.build-stamp { margin-left: auto; }

@media (max-width: 640px) {
  .topbar { flex-wrap: wrap; gap: 8px; }
  .decks { margin-left: 0; flex-wrap: wrap; }
  .stats { margin-left: 0; width: 100%; order: 99; }
  .concept-select { flex: 1 1 100%; max-width: 100%; }
  .stage { padding: 16px 12px; }
  .card { padding: 16px; min-height: 220px; }
  .controls { grid-template-columns: repeat(2, 1fr); }
  .build-stamp { display: none; }
}

[hidden] { display: none !important; }
