/* Themes. Every colour the app uses is one of these tokens; a theme is a
   different set of values and nothing else. */
:root, [data-theme="paper"] {
  color-scheme: light;
  --bg: #f6f1e7; --surface: #fffdf8; --surface-2: #efe8da; --text: #23201b; --muted: #6f675a;
  --border: #e2d9c8; --accent: #2a6f5a; --accent-text: #ffffff; --accent-soft: #dcebe4;
  --good: #2f8f5b; --warn: #c98a12; --bad: #c2453a; --shadow: 0 1px 2px rgba(40, 30, 10, .08), 0 8px 24px -16px rgba(40, 30, 10, .25);
  --font: "Iowan Old Style", "Palatino Linotype", "Book Antiqua", Georgia, serif;
  --font-ui: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
[data-theme="slate"] {
  color-scheme: light;
  --bg: #eef1f5; --surface: #ffffff; --surface-2: #e3e8ef; --text: #1c2430; --muted: #5c6878;
  --border: #d5dce6; --accent: #2b5fd9; --accent-text: #ffffff; --accent-soft: #dde6fb;
  --good: #1f9d63; --warn: #d19a10; --bad: #d64545; --shadow: 0 1px 2px rgba(20, 30, 50, .06), 0 8px 24px -16px rgba(20, 30, 50, .25);
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; --font-ui: var(--font);
}
[data-theme="sakura"] {
  color-scheme: light;
  --bg: #fbf0f3; --surface: #fffafb; --surface-2: #f6e1e7; --text: #3a2530; --muted: #8a6a76;
  --border: #ecd3db; --accent: #c2466f; --accent-text: #ffffff; --accent-soft: #f7dbe5;
  --good: #3b9a6a; --warn: #d39b1c; --bad: #c9403f; --shadow: 0 1px 2px rgba(80, 30, 50, .06), 0 8px 24px -16px rgba(80, 30, 50, .25);
  --font: "Avenir Next", "Nunito", ui-rounded, ui-sans-serif, system-ui, sans-serif; --font-ui: var(--font);
}
[data-theme="ink"] {
  color-scheme: dark;
  --bg: #121212; --surface: #1c1c1c; --surface-2: #262626; --text: #ececec; --muted: #9a9a9a;
  --border: #303030; --accent: #e8e8e8; --accent-text: #121212; --accent-soft: #2f2f2f;
  --good: #5cc48a; --warn: #e0b04a; --bad: #e46b62; --shadow: 0 1px 2px rgba(0, 0, 0, .5), 0 8px 24px -16px rgba(0, 0, 0, .8);
  --font: ui-monospace, "SF Mono", Menlo, Consolas, monospace; --font-ui: ui-sans-serif, system-ui, sans-serif;
}
[data-theme="midnight"] {
  color-scheme: dark;
  --bg: #0f1526; --surface: #171f36; --surface-2: #212b48; --text: #e6eaf5; --muted: #98a3c4;
  --border: #2a3556; --accent: #7aa2ff; --accent-text: #0b1020; --accent-soft: #263562;
  --good: #5ad19a; --warn: #f0c060; --bad: #ff7b72; --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 8px 24px -16px rgba(0, 0, 0, .8);
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; --font-ui: var(--font);
}
[data-theme="forest"] {
  color-scheme: dark;
  --bg: #101a15; --surface: #182620; --surface-2: #22342b; --text: #e4efe7; --muted: #93aa9c;
  --border: #2b4034; --accent: #8ed39a; --accent-text: #0e1a12; --accent-soft: #2a4a36;
  --good: #7bd68f; --warn: #e6c25a; --bad: #f08a7a; --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 8px 24px -16px rgba(0, 0, 0, .8);
  --font: "Iowan Old Style", "Palatino Linotype", Georgia, serif; --font-ui: ui-sans-serif, system-ui, sans-serif;
}
[data-theme="ember"] {
  color-scheme: dark;
  --bg: #1a1210; --surface: #251a17; --surface-2: #33241f; --text: #f3e9e3; --muted: #b39a8f;
  --border: #45302a; --accent: #f28c4b; --accent-text: #1a0e08; --accent-soft: #4a2e21;
  --good: #7fd4a0; --warn: #f0c060; --bad: #ff8a80; --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 8px 24px -16px rgba(0, 0, 0, .8);
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; --font-ui: var(--font);
}

* { box-sizing: border-box; }
html { font-size: 16px; }
body {
  margin: 0; background: var(--bg); color: var(--text); font-family: var(--font-ui);
  line-height: 1.5; -webkit-font-smoothing: antialiased;
  padding-top: env(safe-area-inset-top, 0px); padding-bottom: env(safe-area-inset-bottom, 0px);
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { font-family: var(--font); font-weight: 600; line-height: 1.2; margin: 0 0 .5rem; letter-spacing: -.01em; }
h1 { font-size: 1.9rem; } h2 { font-size: 1.35rem; } h3 { font-size: 1.05rem; }
p { margin: 0 0 .75rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.mono { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; }
.hidden { display: none !important; }
[hidden] { display: none !important; }

.app { min-height: 100vh; display: flex; flex-direction: column; }
.nav {
  position: sticky; top: env(safe-area-inset-top, 0px); z-index: 5; background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px); border-bottom: 1px solid var(--border);
}
.nav-inner { max-width: 960px; margin: 0 auto; padding: .5rem 1rem; display: flex; align-items: center; gap: .25rem; flex-wrap: wrap; }
.brand { font-family: var(--font); font-weight: 700; font-size: 1.15rem; margin-right: .75rem; color: var(--text); }
.nav a.link { padding: .35rem .6rem; border-radius: 8px; color: var(--muted); font-size: .92rem; }
.nav a.link:hover { background: var(--surface-2); text-decoration: none; color: var(--text); }
.nav a.link.active { background: var(--accent-soft); color: var(--text); }
.nav .spacer { flex: 1; }

.pomo { display: flex; align-items: center; gap: .35rem; font-size: .85rem; }
.pomo .time { font-variant-numeric: tabular-nums; font-weight: 600; min-width: 3.2em; text-align: right; }
.pomo .phase { color: var(--muted); }
.pomo.on-break .phase { color: var(--good); }
.pomo button { padding: .2rem .5rem; font-size: .8rem; }

.main { max-width: 960px; width: 100%; margin: 0 auto; padding: 1.5rem 1rem 4rem; flex: 1; }
.grid { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }
.grid.two { grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); }
.stack > * + * { margin-top: 1rem; }
.row { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.right { text-align: right; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 1.1rem 1.25rem; box-shadow: var(--shadow); }
.card.soft { background: var(--surface-2); box-shadow: none; }
.card h2, .card h3 { margin-top: 0; }
.stat { font-family: var(--font); font-size: 2rem; font-weight: 700; line-height: 1; }
.stat-label { color: var(--muted); font-size: .8rem; text-transform: uppercase; letter-spacing: .06em; }

button, .btn {
  font: inherit; font-size: .95rem; padding: .55rem .95rem; border-radius: 10px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); cursor: pointer; transition: background .12s, transform .05s;
  display: inline-flex; align-items: center; gap: .4rem; text-decoration: none;
}
button:hover, .btn:hover { background: var(--surface-2); text-decoration: none; }
button:active { transform: translateY(1px); }
button.primary, .btn.primary { background: var(--accent); color: var(--accent-text); border-color: transparent; font-weight: 600; }
button.primary:hover { filter: brightness(1.05); background: var(--accent); }
button.big { font-size: 1.1rem; padding: .8rem 1.4rem; }
button.ghost { background: transparent; border-color: transparent; color: var(--muted); }
button.ghost:hover { background: var(--surface-2); color: var(--text); }
button.danger { color: var(--bad); }
button.danger:hover { background: color-mix(in srgb, var(--bad) 12%, transparent); }
button:disabled { opacity: .5; cursor: not-allowed; }
button.good { border-color: var(--good); } button.warn { border-color: var(--warn); } button.bad { border-color: var(--bad); }
.key { display: inline-block; font-family: var(--font-ui); font-size: .72rem; min-width: 1.4em; padding: 0 .3em; border-radius: 5px; border: 1px solid var(--border); background: var(--surface-2); color: var(--muted); text-align: center; line-height: 1.5; }
button.primary .key { background: color-mix(in srgb, var(--accent-text) 18%, transparent); color: var(--accent-text); border-color: transparent; }

input, textarea, select {
  font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  padding: .55rem .7rem; width: 100%; max-width: 100%;
}
input[type="checkbox"], input[type="radio"] { width: auto; }
input[type="number"] { max-width: 8em; }
textarea { min-height: 6rem; resize: vertical; font-family: var(--font-ui); line-height: 1.45; }
label { display: block; font-size: .85rem; color: var(--muted); margin-bottom: .25rem; }
.field { margin-bottom: .8rem; }
.field-row { display: grid; gap: .75rem; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); }
.check { display: flex; align-items: center; gap: .5rem; font-size: .95rem; color: var(--text); margin-bottom: .3rem; }

.bar { height: 8px; border-radius: 99px; background: var(--surface-2); overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--accent); border-radius: 99px; transition: width .3s; }
.bar.good > i { background: var(--good); } .bar.warn > i { background: var(--warn); } .bar.bad > i { background: var(--bad); }

.badge { display: inline-block; font-size: .72rem; padding: .1rem .5rem; border-radius: 99px; background: var(--surface-2); color: var(--muted); border: 1px solid var(--border); }
.badge.accent { background: var(--accent-soft); color: var(--text); }
.badge.bad { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 40%, transparent); }
.badge.warn { color: var(--warn); border-color: color-mix(in srgb, var(--warn) 40%, transparent); }
.badge.good { color: var(--good); border-color: color-mix(in srgb, var(--good) 40%, transparent); }

table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th, td { text-align: left; padding: .45rem .5rem; border-bottom: 1px solid var(--border); vertical-align: top; }
th { color: var(--muted); font-weight: 500; font-size: .78rem; text-transform: uppercase; letter-spacing: .05em; }
.table-wrap { overflow-x: auto; }
tr.relearn td:first-child { border-left: 3px solid var(--warn); }

/* Study card */
.study { max-width: 720px; margin: 0 auto; }
.study-top { display: flex; justify-content: space-between; align-items: center; gap: 1rem; margin-bottom: 1rem; font-size: .85rem; color: var(--muted); }
.study-card { background: var(--surface); border: 1px solid var(--border); border-radius: 18px; padding: 2rem 1.75rem; box-shadow: var(--shadow); min-height: 240px; }
.prompt { font-family: var(--font); font-size: 1.55rem; line-height: 1.35; margin: 0 0 1rem; white-space: pre-wrap; }
.prompt .blank { display: inline-block; min-width: 3em; border-bottom: 2px solid var(--accent); color: transparent; }
.prompt .blank.shown { color: var(--accent); border-bottom-color: transparent; font-weight: 600; }
.answer { border-top: 1px dashed var(--border); padding-top: 1rem; margin-top: 1rem; font-size: 1.2rem; white-space: pre-wrap; }
.answer.hint { font-size: 1rem; color: var(--muted); border-top: none; padding-top: 0; }
.choices { display: flex; gap: .5rem; flex-wrap: wrap; margin-top: 1.25rem; }
.choices button { flex: 1 1 auto; justify-content: center; }
.choices.column { flex-direction: column; } .choices.column button { justify-content: flex-start; }
.question { font-size: .85rem; color: var(--muted); margin-top: 1.25rem; margin-bottom: .35rem; }
.notes { background: var(--surface-2); border-radius: 10px; padding: .75rem 1rem; margin-top: 1rem; white-space: pre-wrap; font-size: .95rem; }
.points { list-style: none; padding: 0; margin: 1rem 0 0; }
.points li { display: flex; gap: .6rem; align-items: flex-start; padding: .45rem 0; border-bottom: 1px solid var(--border); cursor: pointer; }
.points li .mark { width: 1.4em; height: 1.4em; border-radius: 6px; flex: none; display: grid; place-items: center; font-size: .8rem; font-weight: 700; border: 1px solid var(--border); }
.points li.hit .mark { background: color-mix(in srgb, var(--good) 20%, transparent); color: var(--good); border-color: var(--good); }
.points li.miss .mark { background: color-mix(in srgb, var(--bad) 15%, transparent); color: var(--bad); border-color: var(--bad); }
.points li .missing { color: var(--muted); font-size: .8rem; display: block; }
.pick-list { max-height: 240px; overflow: auto; border: 1px solid var(--border); border-radius: 10px; margin-top: .5rem; }
.pick-list button { display: block; width: 100%; text-align: left; border: 0; border-radius: 0; border-bottom: 1px solid var(--border); background: transparent; }
.stop { text-align: center; padding: 2.5rem 1.5rem; }
.stop h2 { font-size: 1.8rem; }
.mock-timer { font-variant-numeric: tabular-nums; font-weight: 600; }
.mock-timer.low { color: var(--bad); }

/* Themes picker */
.themes { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: .6rem; }
.theme-swatch { border-radius: 12px; border: 2px solid var(--border); padding: .6rem; cursor: pointer; text-align: left; display: block; }
.theme-swatch.active { border-color: var(--accent); }
.theme-swatch .dots { display: flex; gap: .25rem; margin-bottom: .35rem; }
.theme-swatch .dots i { width: 14px; height: 14px; border-radius: 50%; display: block; border: 1px solid rgba(0,0,0,.12); }

/* Heatmap & map */
.heat { display: grid; grid-auto-flow: column; grid-template-rows: repeat(7, 12px); gap: 3px; }
.heat i { width: 12px; height: 12px; border-radius: 3px; background: var(--surface-2); display: block; }
.heat i.l1 { background: color-mix(in srgb, var(--accent) 30%, var(--surface-2)); }
.heat i.l2 { background: color-mix(in srgb, var(--accent) 55%, var(--surface-2)); }
.heat i.l3 { background: color-mix(in srgb, var(--accent) 80%, var(--surface-2)); }
.heat i.l4 { background: var(--accent); }
.map-wrap { overflow: auto; border: 1px solid var(--border); border-radius: 12px; background: var(--surface); }
.map-wrap svg { display: block; min-width: 100%; }
.map-node { cursor: pointer; }
.map-node text { font-size: 12px; fill: var(--text); pointer-events: none; }
.map-node .sub { font-size: 10px; fill: var(--muted); }
.map-edge { stroke: var(--border); stroke-width: 2; fill: none; }
.legend { display: flex; gap: 1rem; flex-wrap: wrap; font-size: .8rem; color: var(--muted); margin-top: .5rem; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: .3rem; }

.toast { position: fixed; left: 50%; bottom: 1.5rem; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: .6rem 1rem; border-radius: 10px; font-size: .9rem; z-index: 10; max-width: min(90vw, 480px); box-shadow: var(--shadow); }
.deck-color { width: 10px; height: 10px; border-radius: 50%; display: inline-block; margin-right: .4rem; }
.empty { text-align: center; padding: 3rem 1rem; color: var(--muted); }
.empty h2 { color: var(--text); }
details summary { cursor: pointer; color: var(--muted); font-size: .9rem; }
.kbd-help { display: flex; gap: .75rem; flex-wrap: wrap; font-size: .8rem; color: var(--muted); margin-top: .75rem; }
@media (max-width: 600px) {
  .prompt { font-size: 1.3rem; }
  .study-card { padding: 1.4rem 1.1rem; }
  .nav a.link { padding: .3rem .45rem; font-size: .85rem; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
