/* ---------- tokens ---------- */
:root {
  --bg: #F4F6F8;
  --surface: #FFFFFF;
  --surface-2: #EAEEF4;
  --ink: #101828;
  --ink-2: #4B5565;
  --ink-3: #8A94A6;
  --line: #DDE3EC;
  --cobalt: #1E4DD8;
  --cobalt-deep: #163BB0;
  --cobalt-soft: #E4EAFB;
  --new: #1E4DD8;
  --learn: #E8701A;
  --review: #1A9C5B;
  --again: #D93025;
  --hard: #C47A00;
  --good: #1A9C5B;
  --easy: #1E4DD8;
  --shadow: 0 1px 2px rgba(16,24,40,.06), 0 8px 24px -12px rgba(16,24,40,.18);
  --r-s: 8px; --r-m: 14px; --r-l: 22px;
  --ease: cubic-bezier(.2,.8,.2,1);
  --safe-b: env(safe-area-inset-bottom, 0px);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0E1420; --surface: #161E2E; --surface-2: #1F2940; --ink: #EDF1F7; --ink-2: #AEB8C9; --ink-3: #6F7B91;
    --line: #27324A; --cobalt: #5B86F5; --cobalt-deep: #3F6BE0; --cobalt-soft: #1B2A4D; --new: #5B86F5; --easy: #5B86F5;
    --learn: #F08A3C; --review: #2FB874; --good: #2FB874; --again: #F0584D; --hard: #E0A030;
    --shadow: 0 1px 2px rgba(0,0,0,.4), 0 10px 30px -12px rgba(0,0,0,.6);
  }
}

/* ---------- base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 16px/1.5 Manrope, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-feature-settings: "tnum";
  min-height: 100dvh; padding-bottom: calc(24px + var(--safe-b));
}
a { color: var(--cobalt); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.9rem; line-height: 1.15; letter-spacing: -.02em; margin: 0 0 .4em; font-weight: 800; }
h2 { font-size: 1.05rem; margin: 0 0 .6em; font-weight: 700; letter-spacing: -.01em; }
p { margin: 0 0 .8em; }
code { font: .9em ui-monospace, SFMono-Regular, Menlo, monospace; background: var(--surface-2); padding: 2px 6px; border-radius: 6px; word-break: break-all; }
kbd { font: 600 .72em/1 ui-monospace, SFMono-Regular, Menlo, monospace; border: 1px solid currentColor; border-radius: 5px; padding: 3px 6px; opacity: .6; margin-left: 8px; vertical-align: 1px; }
.muted { color: var(--ink-2); } .error { color: var(--again); } .ok { color: var(--good); font-weight: 600; }
.hidden { display: none !important; }
:focus-visible { outline: 3px solid color-mix(in srgb, var(--cobalt) 50%, transparent); outline-offset: 2px; border-radius: 6px; }

main { max-width: 680px; margin: 0 auto; padding: 20px 16px 0; }
.narrow { max-width: 420px; margin: 56px auto; }
.page-head { margin-bottom: 18px; }
.page-head h1 { margin-bottom: 0; }
.page-head .muted { margin-top: 2px; }
.crumb { display: inline-block; font-size: .9rem; margin-bottom: 8px; color: var(--ink-2); }

/* header */
header.top { display: flex; align-items: center; justify-content: space-between; max-width: 680px; margin: 0 auto; padding: 14px 16px 0; }
.brand { display: inline-flex; align-items: center; gap: 10px; color: var(--ink); font-weight: 800; letter-spacing: -.01em; }
.brand:hover { text-decoration: none; }
header .user { color: var(--ink-2); font-weight: 600; padding: 6px 12px; border-radius: 999px; background: var(--surface); border: 1px solid var(--line); }

/* buttons & forms */
.btn, button.btn {
  font: inherit; font-weight: 700; display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 10px 18px; border-radius: var(--r-m); border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  cursor: pointer; transition: transform .12s var(--ease), background .15s, box-shadow .15s; text-decoration: none; white-space: nowrap;
}
.btn:hover { text-decoration: none; background: var(--surface-2); }
.btn:active { transform: scale(.97); }
.btn.primary { background: var(--cobalt); border-color: var(--cobalt); color: #fff; box-shadow: 0 6px 16px -8px var(--cobalt); }
.btn.primary:hover { background: var(--cobalt-deep); }
.btn.primary kbd { opacity: .75; }
.btn.ghost { background: transparent; border-color: transparent; color: var(--ink-2); }
.btn.ghost:hover { background: var(--surface-2); }
.btn.big { font-size: 1.05rem; padding: 14px 26px; border-radius: 16px; }
.btn.small { padding: 6px 12px; font-size: .9rem; border-radius: 10px; }
input:not([type=checkbox]) { font: inherit; padding: 10px 12px; border: 1px solid var(--line); border-radius: var(--r-s); background: var(--surface); color: var(--ink); width: 100%; }
input:focus { border-color: var(--cobalt); outline: none; box-shadow: 0 0 0 3px var(--cobalt-soft); }
label { display: flex; flex-direction: column; gap: 6px; font-size: .9rem; color: var(--ink-2); font-weight: 600; }
label.check { flex-direction: row; align-items: center; gap: 8px; }
form.row { display: flex; gap: 14px; align-items: flex-end; flex-wrap: wrap; }
form.row label { flex: 1 1 180px; }
form.stack { display: flex; flex-direction: column; gap: 14px; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-l); padding: 20px; margin-bottom: 14px; }
.panel p { color: var(--ink-2); font-size: .95rem; }
.linkbox { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.linkbox code { flex: 1; padding: 8px 10px; }
ul.plain { list-style: none; padding: 0; margin: 0; } ul.plain li { padding: 8px 0; border-bottom: 1px solid var(--line); } ul.plain li:last-child { border: 0; }
.tag { font-size: .72rem; font-weight: 700; padding: 2px 8px; border-radius: 999px; background: var(--cobalt-soft); color: var(--cobalt); vertical-align: middle; }
.tag.leech { background: color-mix(in srgb, var(--again) 15%, transparent); color: var(--again); }

/* ---------- landing ---------- */
.hero { text-align: center; max-width: 440px; margin: 48px auto; }
.hero h1 { font-size: 2.1rem; }
.hero-card { position: relative; width: 180px; height: 120px; margin: 0 auto 28px; }
.hc { position: absolute; inset: 0; border-radius: 16px; background: var(--surface); border: 1px solid var(--line); box-shadow: var(--shadow); display: flex; flex-direction: column; align-items: center; justify-content: center; }
.hc.back { transform: rotate(-6deg) translate(-8px, 4px); background: var(--cobalt-soft); border-color: transparent; }
.hc.front { animation: tilt 6s var(--ease) infinite alternate; }
.hc b { font-size: 1.6rem; color: var(--cobalt); } .hc i { color: var(--ink-2); font-style: normal; }
@keyframes tilt { from { transform: rotate(2deg); } to { transform: rotate(-1deg) translateY(-3px); } }

/* ---------- dashboard ---------- */
.today { display: grid; grid-template-columns: 168px 1fr; gap: 22px; align-items: center; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-l); padding: 22px; box-shadow: var(--shadow); }
.ring { position: relative; width: 168px; height: 168px; }
.ring svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring circle { fill: none; stroke-width: 10; stroke-linecap: round; }
.ring .track { stroke: var(--surface-2); }
.ring .prog { stroke: var(--cobalt); stroke-dasharray: 339.292; animation: ring 1.1s var(--ease) both; }
@keyframes ring { from { stroke-dashoffset: 339.292; } }
.ring-center { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; }
.ring-center b { font-size: 2.6rem; font-weight: 800; letter-spacing: -.04em; line-height: 1; }
.ring-center b.check { color: var(--review); }
.ring-center span { font-size: .8rem; color: var(--ink-2); font-weight: 600; margin-top: 4px; }
.today-text .date { color: var(--ink-2); font-weight: 600; font-size: .9rem; margin-bottom: 4px; }
.today-text h1 { margin-bottom: 10px; }
.legend { list-style: none; padding: 0; margin: 0 0 16px; display: flex; gap: 14px; flex-wrap: wrap; font-size: .92rem; font-weight: 600; color: var(--ink-2); }
.legend li { display: inline-flex; align-items: center; gap: 6px; }
.dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }
.dot.new { background: var(--new); } .dot.learn { background: var(--learn); } .dot.review { background: var(--review); } .dot.young { background: color-mix(in srgb, var(--review) 55%, white); } .dot.bad { background: var(--again); }

.week { margin-top: 18px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-l); padding: 18px 20px; }
.week-head { display: flex; justify-content: space-between; align-items: baseline; }
.streak { font-size: .88rem; font-weight: 700; color: var(--learn); }
.bars { display: flex; gap: 8px; align-items: flex-end; height: 92px; margin-top: 8px; }
.bar { flex: 1; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; height: 100%; gap: 6px; }
.bar .fill { width: 100%; max-width: 34px; height: max(var(--h), 4%); border-radius: 6px 6px 3px 3px; background: var(--cobalt-soft); transition: height .7s var(--ease); animation: grow .7s var(--ease) both; transform-origin: bottom; }
.bar .fill.review { background: var(--review); }
.bar.now .fill { background: var(--cobalt); }
.bar span { font-size: .75rem; color: var(--ink-3); font-weight: 600; } .bar.now span { color: var(--cobalt); }
.bar b { font-size: .8rem; }
@keyframes grow { from { transform: scaleY(0); } }

.decks { margin-top: 24px; }
.deck-list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 10px; }
.deck-list li { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-m); overflow: hidden; }
.deck { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 16px; color: var(--ink); transition: background .15s; }
.deck:hover { background: var(--surface-2); text-decoration: none; }
.deck-name { font-weight: 700; }
.counts { display: inline-flex; gap: 4px; }
.counts span { min-width: 34px; text-align: center; font-weight: 700; font-size: .85rem; padding: 3px 8px; border-radius: 999px; }
.counts .new { background: color-mix(in srgb, var(--new) 12%, transparent); color: var(--new); }
.counts .learn { background: color-mix(in srgb, var(--learn) 14%, transparent); color: var(--learn); }
.counts .review { background: color-mix(in srgb, var(--review) 14%, transparent); color: var(--review); }
.deck-links { display: flex; gap: 16px; padding: 8px 16px 10px; font-size: .85rem; border-top: 1px solid var(--line); }
.empty { color: var(--ink-2); }

/* ---------- study ---------- */
.page-study main { max-width: 720px; }
.study-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.back { display: inline-flex; align-items: center; gap: 4px; color: var(--ink-2); font-weight: 600; min-width: 0; }
.deck-title { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 48vw; }
.study-head .counts span.current { box-shadow: 0 0 0 2px currentColor inset; }
.progress { height: 4px; border-radius: 2px; background: var(--surface-2); margin: 12px 0 16px; overflow: hidden; }
#progress-fill { height: 100%; width: 0; background: var(--cobalt); border-radius: 2px; transition: width .5s var(--ease); }

.cardwrap { position: relative; background: #fff; color: #000; border: 1px solid var(--line); border-radius: var(--r-l); padding: 34px 22px 28px; min-height: 260px; box-shadow: var(--shadow); overflow: hidden; }
@media (prefers-color-scheme: dark) { .cardwrap { border-color: transparent; } }
.card-state { position: absolute; top: 12px; left: 16px; font: 700 .7rem/1 Manrope, sans-serif; letter-spacing: .02em; color: #fff; padding: 5px 9px; border-radius: 999px; background: var(--ink-3); opacity: 0; transition: opacity .3s; }
.card-state.show { opacity: 1; }
.card-state.k-new { background: var(--new); } .card-state.k-learn { background: var(--learn); } .card-state.k-review { background: var(--review); }
#card { animation: cardIn .32s var(--ease) both; }
#card.leaving { animation: cardOut .18s ease-in both; }
@keyframes cardIn { from { opacity: 0; transform: translateY(14px) scale(.985); } }
@keyframes cardOut { to { opacity: 0; transform: translateX(-28px); } }
#card img { max-width: 100%; }
#card hr#answer { margin: 20px 0; border: 0; border-top: 1px solid #e3e6ea; }
#card.is-back hr#answer ~ * { animation: fadeUp .35s var(--ease) both; }
#card.is-back hr#answer ~ * + * { animation-delay: .06s; }
#card.is-back hr#answer ~ * + * + * { animation-delay: .12s; }
@keyframes fadeUp { from { opacity: 0; transform: translateY(8px); } }
.replay-button { background: none; border: 0; padding: 0; vertical-align: middle; cursor: pointer; color: #0384ca; transition: transform .15s var(--ease); }
.replay-button:active { transform: scale(.85); }
.replay-button svg { width: 30px; height: 30px; }

.controls { display: flex; flex-direction: column; align-items: center; margin-top: 18px; gap: 10px; }
.controls > .btn.big { width: 100%; max-width: 420px; }
.answers { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; width: 100%; max-width: 640px; animation: fadeUp .25s var(--ease) both; }
.answers button {
  position: relative; font: inherit; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 12px 6px 10px;
  border-radius: var(--r-m); border: 1.5px solid var(--line); background: var(--surface); color: var(--ink); cursor: pointer;
  transition: transform .12s var(--ease), background .15s, border-color .15s;
}
.answers button b { font-size: .95rem; font-weight: 700; }
.answers button span { font-size: .78rem; color: var(--ink-2); font-weight: 600; }
.answers button kbd { position: absolute; top: 6px; right: 6px; margin: 0; padding: 2px 5px; font-size: .62rem; opacity: .45; }
.answers button:hover { background: var(--surface-2); }
.answers button:active, .answers button.pressed { transform: scale(.95); }
.answers .e1 { border-color: color-mix(in srgb, var(--again) 55%, transparent); } .answers .e1 b { color: var(--again); }
.answers .e2 { border-color: color-mix(in srgb, var(--hard) 55%, transparent); } .answers .e2 b { color: var(--hard); }
.answers .e3 { border-color: color-mix(in srgb, var(--good) 55%, transparent); } .answers .e3 b { color: var(--good); }
.answers .e4 { border-color: color-mix(in srgb, var(--easy) 55%, transparent); } .answers .e4 b { color: var(--easy); }
.answers .e1.pressed { background: color-mix(in srgb, var(--again) 14%, transparent); }
.answers .e2.pressed { background: color-mix(in srgb, var(--hard) 14%, transparent); }
.answers .e3.pressed { background: color-mix(in srgb, var(--good) 14%, transparent); }
.answers .e4.pressed { background: color-mix(in srgb, var(--easy) 14%, transparent); }

.done { text-align: center; padding: 36px 0 20px; animation: fadeUp .4s var(--ease) both; }
.done p { color: var(--ink-2); }
.tick { width: 84px; height: 84px; margin-bottom: 8px; }
.tick circle { fill: none; stroke: var(--review); stroke-width: 3; stroke-dasharray: 183; stroke-dashoffset: 183; animation: draw .6s var(--ease) forwards; }
.tick path { fill: none; stroke: var(--review); stroke-width: 4; stroke-linecap: round; stroke-linejoin: round; stroke-dasharray: 40; stroke-dashoffset: 40; animation: draw .4s var(--ease) .45s forwards; }
@keyframes draw { to { stroke-dashoffset: 0; } }

.toast { position: fixed; left: 50%; bottom: calc(24px + var(--safe-b)); transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-weight: 600; font-size: .92rem; box-shadow: var(--shadow); animation: fadeUp .25s var(--ease) both; z-index: 20; max-width: calc(100vw - 32px); }

/* ---------- browse ---------- */
.search { display: flex; gap: 8px; align-items: center; margin-bottom: 14px; }
.card-list { list-style: none; padding: 0; margin: 0; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-l); overflow: hidden; }
.card-list li { display: flex; gap: 12px; padding: 12px 16px; border-bottom: 1px solid var(--line); border-left: 3px solid transparent; }
.card-list li:last-child { border-bottom: 0; }
.card-list li.q1, .card-list li.q3 { border-left-color: var(--learn); } .card-list li.q2 { border-left-color: var(--review); }
.pos { color: var(--ink-3); font-size: .8rem; font-weight: 700; min-width: 34px; padding-top: 3px; }
.body { min-width: 0; flex: 1; }
.summary { font-weight: 600; overflow-wrap: anywhere; }
.meta { display: flex; flex-wrap: wrap; gap: 4px 12px; font-size: .8rem; color: var(--ink-2); margin-top: 3px; }
.state { font-weight: 700; } .state.s0 { color: var(--new); } .state.s1, .state.s3 { color: var(--learn); } .state.s2 { color: var(--review); }
.meta .bad { color: var(--again); }
.pager { display: flex; gap: 12px; justify-content: center; align-items: center; padding: 16px; color: var(--ink-2); font-weight: 600; }

/* ---------- stats ---------- */
.composition, .tiles { margin-bottom: 14px; }
.composition { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-l); padding: 18px 20px; }
.stack-bar { display: flex; height: 14px; border-radius: 7px; overflow: hidden; background: var(--surface-2); gap: 2px; margin-bottom: 12px; }
.stack-bar i { display: block; min-width: 0; }
.stack-bar .s-new { background: var(--new); } .stack-bar .s-learn { background: var(--learn); } .stack-bar .s-young { background: color-mix(in srgb, var(--review) 55%, white); } .stack-bar .s-mature { background: var(--review); }
.legend.wide { margin: 0; }
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 10px; }
.tile { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-m); padding: 14px; }
.tile b { display: block; font-size: 1.6rem; font-weight: 800; letter-spacing: -.03em; line-height: 1.1; }
.tile span { color: var(--ink-2); font-size: .82rem; font-weight: 600; }
.actions { margin-top: 18px; display: flex; gap: 10px; }

/* ---------- install banner ---------- */
.install { position: fixed; left: 12px; right: 12px; bottom: calc(12px + var(--safe-b)); max-width: 560px; margin: 0 auto; display: flex; gap: 10px; align-items: center;
  background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 12px 14px; box-shadow: var(--shadow); z-index: 30; animation: fadeUp .4s var(--ease) both; }
.install > div { flex: 1; display: flex; flex-direction: column; font-size: .88rem; color: var(--ink-2); } .install b { color: var(--ink); }

/* ---------- responsive & motion ---------- */
@media (max-width: 560px) {
  main { padding: 14px 12px 0; }
  h1 { font-size: 1.6rem; }
  .today { grid-template-columns: 1fr; justify-items: center; text-align: center; padding: 20px 16px; }
  .legend { justify-content: center; }
  .today-text .btn { width: 100%; }
  .answers { gap: 6px; } .answers button { padding: 10px 4px 8px; border-radius: 12px; } .answers button b { font-size: .88rem; }
  .cardwrap { padding: 32px 14px 22px; border-radius: 18px; }
  .deck { flex-direction: column; align-items: flex-start; }
  .tiles { grid-template-columns: repeat(2, 1fr); }
  .install { font-size: .85rem; } .install .btn.small { padding: 6px 10px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
