:root {
  --bg: #0f1013;
  --panel: #18191e;
  --panel-2: #202228;
  --line: #2a2c33;
  --text: #ececee;
  --muted: #9a9ca5;
  --faint: #6c6f78;
  --accent: #7aa7f0;
  --again: #e0685e;
  --hard: #d9a441;
  --good: #5cb871;
  --easy: #6aa0e8;
  --due: #f0a37a;
  --new: #7ab3f0;
  --radius: 16px;
  color-scheme: dark;
}
* { box-sizing: border-box; transition: none !important; animation: none !important; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); }
body {
  font: 18px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  display: flex; flex-direction: column;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  -webkit-tap-highlight-color: transparent;
  -webkit-font-smoothing: antialiased;
}
button { font: inherit; color: inherit; border: 0; cursor: pointer; touch-action: manipulation; background: none; }
button:focus-visible, #card:focus-visible, input:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
[hidden] { display: none !important; }
svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }
kbd { display: none; font: 11px ui-monospace, Menlo, monospace; color: inherit; opacity: .55; border: 1px solid currentColor; border-radius: 4px; padding: 0 4px; margin-top: 4px; }
@media (hover: hover) and (pointer: fine) { kbd { display: inline-block; } }

/* ------------------------------------------------------------ top bar */
#bar { padding: 10px 14px 8px; background: var(--bg); }
#bar .row { display: flex; align-items: center; justify-content: space-between; gap: 8px; max-width: 760px; margin: 0 auto; }
.counts { display: flex; gap: 6px; flex-wrap: wrap; }
.pill { display: inline-flex; align-items: baseline; gap: 5px; font-size: 14px; color: var(--muted); background: var(--panel); border: 1px solid var(--line); border-radius: 999px; padding: 5px 11px; white-space: nowrap; }
.pill b { font-size: 17px; font-weight: 650; color: var(--text); font-variant-numeric: tabular-nums; }
.pill.due b { color: var(--due); }
.pill.new b { color: var(--new); }
.tools { display: flex; gap: 6px; }
.tool { display: inline-flex; align-items: center; gap: 6px; background: var(--panel); border: 1px solid var(--line); padding: 0 12px; border-radius: 12px; min-height: 44px; min-width: 44px; justify-content: center; font-size: 15px; color: var(--text); }
.tool:disabled { opacity: .35; cursor: default; }
.tool:not(:disabled):active { background: var(--panel-2); }
.tool.busy svg { opacity: .4; }
@media (max-width: 420px) { .tool span { display: none; } .pill { padding: 5px 9px; } }
.subrow { display: flex; align-items: center; gap: 10px; max-width: 760px; margin: 9px auto 0; }
.progress { flex: 1; height: 4px; background: var(--panel-2); border-radius: 2px; overflow: hidden; }
#progress-fill { height: 100%; width: 0; background: var(--good); border-radius: 2px; }
.pending { font-size: 12px; color: var(--faint); white-space: nowrap; font-variant-numeric: tabular-nums; }
.pending.waiting { color: var(--hard); font-weight: 600; }

/* ------------------------------------------------------------ review */
#main { flex: 1; display: flex; flex-direction: column; min-height: 0; padding: 6px 14px 14px; width: 100%; max-width: 760px; margin: 0 auto; }
#review { flex: 1; display: flex; flex-direction: column; min-height: 0; gap: 10px; }
#card {
  flex: 1; overflow-y: auto; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px 18px 22px; outline: none; user-select: text; display: flex; flex-direction: column; cursor: pointer;
}
#card.revealed { cursor: auto; }
#meta { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; font-size: 12.5px; color: var(--muted); }
.chip { background: var(--panel-2); border-radius: 6px; padding: 2px 8px; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.state { border-radius: 6px; padding: 2px 8px; font-weight: 600; letter-spacing: .02em; }
.state.s-new { color: var(--new); background: rgba(122, 179, 240, .12); }
.state.s-learning, .state.s-relearning { color: var(--hard); background: rgba(217, 164, 65, .12); }
.state.s-review { color: var(--good); background: rgba(92, 184, 113, .12); }
.face { flex: 1; display: flex; flex-direction: column; justify-content: center; padding: 18px 0 6px; }
.side { font-size: 23px; line-height: 1.45; overflow-wrap: anywhere; }
#front { font-weight: 550; }
#answer-block { margin-top: 22px; padding-top: 18px; border-top: 1px dashed var(--line); }
.answer-label { font-size: 11.5px; letter-spacing: .08em; text-transform: uppercase; color: var(--faint); margin-bottom: 6px; }
#back { color: #f4f4f5; }
@media (min-width: 600px) { .side { font-size: 26px; } #card { padding: 22px 28px 28px; } }

#source { display: flex; gap: 8px; flex-wrap: nowrap; align-items: center; min-height: 24px; font-size: 13.5px; color: var(--muted); padding: 0 2px; }
#source .where { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#source a { color: var(--accent); text-decoration: none; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 4px 10px; white-space: nowrap; }

#controls { min-height: 78px; }
.primary { width: 100%; min-height: 56px; border-radius: 14px; background: var(--text); color: #111; font-weight: 650; font-size: 18px; display: flex; align-items: center; justify-content: center; gap: 10px; }
.primary:active { background: #cfcfd3; }
.primary kbd { margin: 0; opacity: .5; }
.show { min-height: 78px; }
#answers { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.rate {
  min-height: 78px; border-radius: 14px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px;
  background: var(--panel); border: 1px solid var(--line); border-bottom-width: 3px;
}
.rate span { font-size: 15px; font-weight: 600; color: var(--muted); }
.rate small { font-size: 19px; font-weight: 700; font-variant-numeric: tabular-nums; }
.rate:active { background: var(--panel-2); }
.again { border-bottom-color: var(--again); } .again small { color: var(--again); }
.hard { border-bottom-color: var(--hard); } .hard small { color: var(--hard); }
.good { border-bottom-color: var(--good); } .good small { color: var(--good); }
.easy { border-bottom-color: var(--easy); } .easy small { color: var(--easy); }

.code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .86em; background: #0b0d12; border: 1px solid var(--line); padding: 1px 6px; border-radius: 6px; }
code.hljs { display: inline; padding: 1px 6px; }
.katex { font-size: 1.05em; }
.katex-display { overflow-x: auto; overflow-y: hidden; padding: 4px 0; }

/* ------------------------------------------------------------ login */
#login { flex: 1; display: flex; align-items: flex-start; justify-content: center; }
#login form { width: 100%; max-width: 360px; margin-top: 10vh; display: flex; flex-direction: column; gap: 12px; text-align: center; }
.logo { align-self: center; border-radius: 16px; }
#login h1 { margin: 4px 0 0; font-weight: 650; font-size: 28px; }
.sub { margin: 0 0 12px; color: var(--muted); font-size: 15px; }
#login input { font: inherit; padding: 15px 16px; border-radius: 14px; border: 1px solid var(--line); background: var(--panel); color: var(--text); }
.msg { color: var(--again); font-size: 15px; white-space: pre-line; min-height: 1.5em; margin: 0; }

/* ------------------------------------------------------------ done */
#empty { text-align: center; padding-top: 9vh; display: flex; flex-direction: column; align-items: center; gap: 6px; }
.done-mark { width: 72px; height: 72px; border-radius: 50%; background: rgba(92, 184, 113, .14); display: grid; place-items: center; color: var(--good); }
.done-mark svg { width: 36px; height: 36px; stroke-width: 2.5; }
#empty h2 { margin: 12px 0 8px; font-weight: 650; font-size: 26px; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; width: 100%; max-width: 420px; margin-top: 8px; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 12px 6px; display: flex; flex-direction: column; }
.stat b { font-size: 26px; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat span { font-size: 13px; color: var(--muted); }
.breakdown { display: flex; width: 100%; max-width: 420px; height: 10px; border-radius: 5px; overflow: hidden; margin-top: 12px; background: var(--panel-2); }
.breakdown i { display: block; height: 100%; }
.legend { display: flex; gap: 14px; justify-content: center; flex-wrap: wrap; font-size: 13px; color: var(--muted); margin-top: 8px; }
.legend b { font-weight: 650; }
#empty-msg { color: var(--muted); font-size: 15px; white-space: pre-line; max-width: 420px; margin: 12px 0 0; }
.tomorrow { margin: 10px 0 0; font-size: 15px; color: var(--text); background: var(--panel); border: 1px solid var(--line); border-radius: 999px; padding: 8px 16px; }

/* ------------------------------------------------------------ status toast */
.toast {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(108px + env(safe-area-inset-bottom));
  width: calc(100% - 28px); max-width: 560px; max-height: 40vh; overflow-y: auto;
  background: #2a2c34; color: var(--text); border: 1px solid #3a3d46; border-radius: 12px; padding: 11px 14px;
  font-size: 14.5px; white-space: pre-line; box-shadow: 0 6px 24px rgba(0, 0, 0, .45); z-index: 10; cursor: pointer;
}
.toast.warn { border-color: rgba(217, 164, 65, .6); }
