/* Flashcards. Signal yellow marks the thing to study (the question card and the Study buttons);
   everything else stays quiet: cool grey page, ink text, thin rules. */

:root {
  --page: #e9edf0;
  --surface: #ffffff;
  --ink: #16202b;
  --muted: #566574;
  --line: #c7d0d8;
  --signal: #f5c400;
  --on-signal: #16202b;
  --right: #17794f;
  --wrong: #c1392a;
  --focus: #16202b;
  --edge: #16202b;
  --font: system-ui, -apple-system, "Segoe UI Variable", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --page: #12171e;
    --surface: #1c2430;
    --ink: #e8edf2;
    --muted: #9aa8b6;
    --line: #2f3b49;
    --right: #3dbb85;
    --wrong: #f2705c;
    --focus: #f5c400;
    --edge: #e8edf2;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--page);
  color: var(--ink);
  font: 1rem/1.5 var(--font);
  min-height: 100vh;
}
[hidden] { display: none !important; }
h1, h2, h3 { line-height: 1.15; letter-spacing: -0.02em; margin: 0; }
h1 { font-size: clamp(1.7rem, 4vw, 2.3rem); font-weight: 800; }
h2 { font-size: 1.25rem; font-weight: 750; }
p { margin: 0; }
a { color: inherit; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.muted { color: var(--muted); }
.noscript { padding: 2rem; }

/* ---------- frame ---------- */
.top {
  display: flex; align-items: center; gap: 1.5rem;
  max-width: 62rem; margin: 0 auto; padding: 1rem 1rem 0;
}
.brand { font-weight: 850; letter-spacing: -0.03em; font-size: 1.15rem; text-decoration: none; display: flex; align-items: center; gap: .55rem; }
.brand::before { content: ""; width: 1.5rem; height: 1.05rem; background: var(--signal); border: 2px solid var(--edge); border-radius: 4px; }
.tabs { display: flex; gap: .25rem; margin-right: auto; }
.tabs a {
  text-decoration: none; padding: .45rem .8rem; border-radius: 6px; font-weight: 600; color: var(--muted);
}
.tabs a:hover { color: var(--ink); }
.tabs a[aria-current="page"] { color: var(--ink); box-shadow: inset 0 -3px 0 var(--signal); border-radius: 0; }
main { max-width: 62rem; margin: 0 auto; padding: 2rem 1rem 6rem; }
main > header { margin-bottom: 1.5rem; }
main > header p { margin-top: .4rem; color: var(--muted); max-width: 60ch; }

@media (max-width: 640px) {
  .top { padding-top: .75rem; }
  .tabs {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 10; margin: 0; gap: 0;
    background: var(--surface); border-top: 1px solid var(--line);
    padding-bottom: env(safe-area-inset-bottom);
  }
  .tabs a { flex: 1; text-align: center; padding: .9rem .25rem; border-radius: 0; }
  .tabs a[aria-current="page"] { box-shadow: inset 0 3px 0 var(--signal); }
  .top .brand { margin-right: auto; }
}

/* ---------- buttons and fields ---------- */
.btn {
  font: inherit; font-weight: 700; cursor: pointer; text-decoration: none; text-align: center;
  display: inline-flex; align-items: center; justify-content: center; gap: .5rem;
  padding: .7rem 1.1rem; border-radius: 8px; border: 2px solid var(--edge);
  background: var(--surface); color: var(--ink); min-height: 2.9rem;
}
.btn:hover { background: var(--page); }
.btn.go { background: var(--signal); color: var(--on-signal); border-color: var(--on-signal); }
.btn.go:hover { filter: brightness(.95); }
.btn.solid { background: var(--ink); color: var(--page); }
.btn.right { background: var(--right); border-color: var(--right); color: #fff; }
.btn.wrong { background: transparent; border-color: var(--wrong); color: var(--wrong); }
.btn.quiet { border-color: transparent; background: transparent; color: var(--muted); }
.btn.quiet:hover { color: var(--ink); background: transparent; }
.btn.small { min-height: 2.2rem; padding: .3rem .75rem; font-size: .9rem; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
kbd { font: inherit; font-size: .75em; opacity: .65; border: 1px solid currentColor; border-radius: 4px; padding: 0 .35em; }
@media (hover: none) { kbd { display: none; } }

label { display: block; font-weight: 650; margin-bottom: .3rem; }
input[type=text], input[type=password], input[type=search], select, textarea {
  font: inherit; color: var(--ink); background: var(--surface); width: 100%;
  border: 2px solid var(--line); border-radius: 6px; padding: .6rem .7rem; min-height: 2.9rem;
}
input:focus, select:focus, textarea:focus { border-color: var(--edge); outline: none; box-shadow: 0 0 0 3px var(--signal); }
.field { margin-bottom: 1.25rem; }
.hint { color: var(--muted); font-size: .9rem; margin-top: .3rem; }
.error { color: var(--wrong); font-weight: 650; }

/* ---------- login ---------- */
.login { max-width: 24rem; margin: 18vh auto 0; padding: 0 1rem; }
.login h1 { margin-bottom: 1.5rem; }
.login .btn { width: 100%; }

/* ---------- study: choices and category list ---------- */
.options { display: flex; flex-wrap: wrap; gap: 1rem 2rem; align-items: end; margin-bottom: 1.75rem; }
.options .field { margin: 0; }
.segmented { display: inline-flex; border: 2px solid var(--edge); border-radius: 8px; overflow: hidden; background: var(--surface); }
.segmented button {
  font: inherit; font-weight: 650; border: 0; background: transparent; color: var(--ink);
  padding: .55rem .95rem; cursor: pointer; min-height: 2.6rem;
}
.segmented button + button { border-left: 1px solid var(--line); }
.segmented button[aria-pressed="true"] { background: var(--ink); color: var(--page); }
.check { display: flex; align-items: center; gap: .5rem; font-weight: 600; margin: 0; min-height: 2.6rem; cursor: pointer; }
.check input { width: 1.2rem; height: 1.2rem; accent-color: var(--ink); }
.options select { min-width: 12rem; }

.list { list-style: none; margin: 0; padding: 0; border-top: 2px solid var(--edge); }
.row {
  display: grid; grid-template-columns: 1fr auto; gap: .25rem 1rem; align-items: center;
  padding: .85rem .25rem; border-bottom: 1px solid var(--line); text-decoration: none; color: inherit;
}
a.row:hover { background: color-mix(in srgb, var(--signal) 14%, transparent); }
.row .name { font-weight: 700; font-size: 1.1rem; letter-spacing: -0.01em; }
.row .detail { color: var(--muted); font-size: .9rem; grid-column: 1; }
.row .go-label { grid-column: 2; grid-row: 1 / span 2; }
.row .progress { grid-column: 1 / -1; }
.row.child .name { font-weight: 600; font-size: 1rem; }
.progress { display: flex; height: .4rem; background: var(--line); border-radius: 2px; overflow: hidden; margin-top: .35rem; }
.progress i { display: block; height: 100%; }
.progress .known { background: var(--right); }
.progress .seen { background: var(--muted); }

/* ---------- quiz ---------- */
.quiz { max-width: 46rem; margin: 0 auto; }
.quiz-head { display: flex; align-items: center; gap: 1rem; margin-bottom: .75rem; }
.quiz-head h1 { flex: 1; min-width: 0; }
.quiz-head .count { font-weight: 650; color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.steps { display: flex; gap: 3px; margin-bottom: 1.25rem; }
.steps i { flex: 1; height: .45rem; border-radius: 2px; background: var(--line); }
.steps i.right { background: var(--right); }
.steps i.wrong { background: var(--wrong); }
.steps i.now { background: var(--ink); }
.steps.bar { gap: 0; }
.steps.bar i { flex: none; border-radius: 0; }

.card {
  background: var(--signal); color: var(--on-signal); border: 2px solid var(--on-signal); border-radius: 12px;
  min-height: min(26rem, 55vh); padding: 1.75rem 1.5rem; display: flex; flex-direction: column;
  transition: background-color .18s ease;
  box-shadow: 6px 6px 0 var(--on-signal);
}
.card.answer { background: var(--surface); color: var(--ink); border-color: var(--edge); box-shadow: 6px 6px 0 var(--edge); }
.card-source { font-size: .85rem; opacity: .7; margin-bottom: 1rem; }
.card-body { font-size: 1.15rem; line-height: 1.55; overflow-wrap: anywhere; margin-block: auto; }
.card-body.short { text-align: center; font-size: clamp(1.6rem, 5vw, 2.4rem); font-weight: 750; line-height: 1.2; letter-spacing: -0.015em; }
.card-body.short .card-part + .card-part { margin-top: 1.25rem; }
.card-body hr { border: 0; border-top: 2px solid currentColor; opacity: .25; margin: 1.25rem 0; }
.card-part.asked { color: color-mix(in srgb, currentColor 60%, transparent); text-align: center; }
.card-part.asked img { display: inline-block; max-height: 20vh; margin: .3rem; }
.card-body img { display: block; max-width: 100%; max-height: 42vh; height: auto; margin: .6rem auto; background: #fff; border-radius: 4px; }
.card-body img.latex { display: inline-block; margin: .2rem .3rem; padding: .25rem .5rem; vertical-align: middle; }
.card-body audio { width: 100%; margin: .5rem 0; }
.card-body .value { font-size: 1.6em; font-weight: 750; line-height: 1.2; letter-spacing: -0.01em; text-align: center; }
.card-body .value--top { font-size: 2em; }
.card-body .info { font-size: .95rem; text-align: center; opacity: .75; margin-top: .25rem; }
.card-body .type { font-size: .9rem; text-align: center; opacity: .65; margin-top: .75rem; }
.card-body .value--image { font-size: 1rem; }
.card-body .cloze { font-weight: 800; border-bottom: 3px solid currentColor; }
.card-body details.hint { margin-top: .75rem; font-size: 1rem; }
.card-body table { border-collapse: collapse; margin: .5rem 0; }
.card-body td, .card-body th { border: 1px solid var(--line); padding: .25rem .6rem; }

.quiz-actions { display: flex; gap: .75rem; margin-top: 1.75rem; }
.quiz-actions .btn { flex: 1; min-height: 3.4rem; font-size: 1.05rem; }

.done h1 { margin-bottom: .5rem; }
.done .score { font-size: 1.15rem; margin-bottom: 1.5rem; }
.done .buttons { display: flex; flex-wrap: wrap; gap: .75rem; margin: 1.5rem 0 2.5rem; }

/* ---------- cards list and editor ---------- */
.toolbar { display: flex; flex-wrap: wrap; gap: .75rem; margin-bottom: 1.25rem; }
.toolbar .grow { flex: 1 1 14rem; }
.toolbar select { flex: 0 1 13rem; width: auto; }
.card-row { display: grid; grid-template-columns: 1fr auto; gap: .2rem 1rem; padding: .8rem .25rem; border-bottom: 1px solid var(--line); align-items: start; }
.card-row .front { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; grid-column: 1; }
.card-row .back { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; grid-column: 1; }
.card-row .meta { grid-column: 1; font-size: .85rem; color: var(--muted); }
.card-row .btn { grid-column: 2; grid-row: 1 / span 3; align-self: center; }
.more { margin-top: 1.25rem; }

.editor-wrap { border: 2px solid var(--line); border-radius: 8px; background: var(--surface); }
.editor-wrap:focus-within { border-color: var(--edge); box-shadow: 0 0 0 3px var(--signal); }
.editor-bar { display: flex; flex-wrap: wrap; gap: .25rem; padding: .35rem; border-bottom: 1px solid var(--line); }
.editor-bar .btn { min-height: 2.2rem; padding: .2rem .65rem; border-width: 1px; border-color: var(--line); }
.editor { min-height: 7rem; padding: .75rem; outline: none; overflow-wrap: anywhere; }
.editor img { max-width: 100%; max-height: 16rem; background: #fff; }
.editor:empty::before { content: attr(data-placeholder); color: var(--muted); }
.form-actions { display: flex; flex-wrap: wrap; gap: .75rem; margin-top: 1.5rem; }
.form-actions .push { margin-left: auto; }

/* ---------- stats ---------- */
.facts { font-size: 1.15rem; max-width: 46rem; display: grid; gap: .5rem; margin-bottom: 2.25rem; }
.chart { width: 100%; max-width: 46rem; height: auto; display: block; }
.chart text { fill: var(--muted); font: 12px var(--font); }
.legend { display: flex; gap: 1.25rem; font-size: .9rem; color: var(--muted); margin: .5rem 0 2.25rem; }
.legend span::before { content: ""; display: inline-block; width: .8rem; height: .8rem; border-radius: 2px; margin-right: .4rem; vertical-align: -1px; background: var(--c); }
table.table { width: 100%; border-collapse: collapse; margin-bottom: 2.25rem; }
.table th { text-align: left; font-weight: 650; color: var(--muted); border-bottom: 2px solid var(--edge); padding: .4rem .5rem .4rem 0; }
.table td { padding: .6rem .5rem .6rem 0; border-bottom: 1px solid var(--line); vertical-align: top; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; padding-right: .75rem; }
.table td .progress { min-width: 6rem; }
section + section { margin-top: 2.5rem; }
section > h2, .done h2 { margin-bottom: .75rem; }
@media (max-width: 640px) { .table .hide-small { display: none; } }

/* ---------- import ---------- */
.steps-list { padding-left: 1.2rem; max-width: 60ch; display: grid; gap: .4rem; margin: 0 0 1.5rem; }
.bigbar { height: .9rem; background: var(--line); border-radius: 5px; overflow: hidden; margin: .5rem 0; }
.bigbar i { display: block; height: 100%; background: var(--signal); width: 0; transition: width .2s; }
.panel { border: 2px solid var(--edge); border-radius: 10px; padding: 1.25rem; background: var(--surface); max-width: 40rem; }

/* ---------- messages ---------- */
#toast {
  position: fixed; left: 50%; bottom: 5.5rem; transform: translateX(-50%); z-index: 50; pointer-events: none;
  background: var(--ink); color: var(--page); padding: .7rem 1.1rem; border-radius: 8px; font-weight: 650;
  opacity: 0; transition: opacity .2s; max-width: 90vw;
}
#toast.show { opacity: 1; }
#toast.bad { background: var(--wrong); color: #fff; }
.empty { padding: 2rem 0; max-width: 40rem; }
.empty p + p, .empty p + .btn { margin-top: .75rem; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
}

/* In the category list the Study buttons stay quiet until you point at a row */
.row .btn.go { background: transparent; color: var(--ink); border-color: var(--line); }
a.row:hover .btn.go, a.row:focus-visible .btn.go { background: var(--signal); color: var(--on-signal); border-color: var(--on-signal); }
