:root {
  --bg: #0d0f14;
  --surface: #161922;
  --surface-2: #1e222d;
  --line: rgba(255, 255, 255, 0.07);
  --text: #eef0f5;
  --muted: #8b91a1;
  --faint: #5b6172;
  --accent: #8ab4ff;
  --danger: #ff6b6b;
  --radius: 18px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: dark;
}
@media (prefers-color-scheme: light) {
  :root {
    --bg: #f4f5f8;
    --surface: #ffffff;
    --surface-2: #eceef3;
    --line: rgba(0, 0, 0, 0.07);
    --text: #14161c;
    --muted: #646a7a;
    --faint: #9aa0ae;
    --accent: #2f6fe0;
    color-scheme: light;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
input, select, textarea { font: inherit; color: inherit; }

#view {
  max-width: 560px;
  margin: 0 auto;
  padding: calc(var(--safe-top) + 20px) 16px calc(var(--safe-bottom) + 96px);
  min-height: 100%;
}

/* ---------- headers ---------- */
.eyebrow { color: var(--muted); font-size: 13px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; }
h1 { font-size: 32px; line-height: 1.1; letter-spacing: -.02em; margin: 4px 0 18px; }
h2 { font-size: 13px; color: var(--muted); font-weight: 600; letter-spacing: .06em; text-transform: uppercase; margin: 26px 4px 10px; }

/* ---------- cards & lists ---------- */
.panel { background: var(--surface); border-radius: var(--radius); border: 1px solid var(--line); }
.list { overflow: hidden; }
.row { display: flex; gap: 12px; align-items: flex-start; padding: 14px 16px; border-top: 1px solid var(--line); }
.row:first-child { border-top: 0; }
.row .main { flex: 1; min-width: 0; }
.row .title { font-weight: 600; }
.row .sub { color: var(--muted); font-size: 14px; margin-top: 2px; }
.row.done .title { color: var(--faint); text-decoration: line-through; }
.row.done .sub { color: var(--faint); }

.dot { width: 9px; height: 9px; border-radius: 50%; flex: none; display: inline-block; }
.bar { width: 4px; align-self: stretch; border-radius: 4px; flex: none; }

.check {
  width: 24px; height: 24px; border-radius: 50%; flex: none; margin-top: 1px;
  border: 2px solid var(--faint); display: grid; place-items: center; transition: .15s;
}
.check svg { width: 14px; height: 14px; stroke: var(--bg); stroke-width: 3; fill: none; opacity: 0; }
.checked .check { background: var(--c, var(--accent)); border-color: var(--c, var(--accent)); }
.checked .check svg { opacity: 1; }

.pill {
  display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px;
  font-size: 13px; font-weight: 600; background: var(--surface-2); color: var(--muted); white-space: nowrap;
}
.pill.hot { background: color-mix(in srgb, var(--danger) 18%, transparent); color: var(--danger); }
.pill.warm { background: color-mix(in srgb, #f2c94c 18%, transparent); color: #e0b43a; }

.chips { display: flex; gap: 8px; overflow-x: auto; padding: 2px 0 6px; scrollbar-width: none; margin: 0 -16px; padding-inline: 16px; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  padding: 8px 14px; border-radius: 999px; background: var(--surface); border: 1px solid var(--line);
  font-size: 14px; font-weight: 600; white-space: nowrap; color: var(--muted); display: inline-flex; gap: 8px; align-items: center;
}
.chip.on { background: var(--text); color: var(--bg); border-color: var(--text); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 13px 20px; border-radius: 14px; font-weight: 650; background: var(--surface-2);
}
a.btn { color: var(--text); }
.btn.primary { background: var(--text); color: var(--bg); }
.btn.block { width: 100%; }
.btn:active, .chip:active, .row:active { transform: scale(.98); }

.empty { color: var(--muted); text-align: center; padding: 28px 16px; }
.note { color: var(--muted); font-size: 14px; margin: 10px 4px 0; }

/* ---------- today ---------- */
.focus-card { padding: 18px; position: relative; overflow: hidden; }
.focus-card .big { font-size: 20px; font-weight: 700; letter-spacing: -.01em; margin: 6px 0 12px; }
.focus-card .glow { position: absolute; inset: -40% -20% auto auto; width: 220px; height: 220px; border-radius: 50%; filter: blur(60px); opacity: .35; pointer-events: none; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-top: 12px; }
.stat { padding: 14px; text-align: left; }
.stat b { display: block; font-size: 22px; letter-spacing: -.02em; }
.stat span { font-size: 12px; color: var(--muted); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; line-height: 1.3; }
.add-row { display: flex; gap: 8px; padding: 10px 12px; border-top: 1px solid var(--line); }
.add-row input { flex: 1; min-width: 0; background: transparent; border: 0; outline: 0; padding: 6px 4px; }
.add-row select { background: var(--surface-2); border: 0; border-radius: 10px; padding: 6px 8px; font-size: 14px; }

/* ---------- focus timer ---------- */
.timer-wrap { display: grid; place-items: center; margin: 8px 0 18px; }
.ring { width: min(78vw, 320px); aspect-ratio: 1; position: relative; }
.ring svg { width: 100%; height: 100%; transform: rotate(-90deg); overflow: visible; }
.ring .track { stroke: var(--surface-2); }
.ring .prog { transition: stroke-dashoffset .9s linear, stroke .4s; filter: drop-shadow(0 0 10px var(--rc)); }
.ring .center { position: absolute; inset: 0; display: grid; place-content: center; text-align: center; }
.ring .time { font-size: clamp(54px, 17vw, 76px); font-weight: 250; letter-spacing: -.03em; font-variant-numeric: tabular-nums; line-height: 1; }
.ring .label { color: var(--muted); font-size: 14px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; margin-top: 8px; }
.seg { display: flex; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 4px; }
.seg button { flex: 1; padding: 9px 4px; border-radius: 10px; font-size: 14px; font-weight: 600; color: var(--muted); }
.seg button.on { background: var(--surface-2); color: var(--text); }
.controls { display: flex; justify-content: center; align-items: center; gap: 22px; margin: 22px 0 6px; }
.play { width: 76px; height: 76px; border-radius: 50%; background: var(--text); color: var(--bg); display: grid; place-items: center; }
.play svg { width: 30px; height: 30px; fill: currentColor; }
.ghost { width: 52px; height: 52px; border-radius: 50%; background: var(--surface); border: 1px solid var(--line); display: grid; place-items: center; }
.ghost svg { width: 22px; height: 22px; stroke: currentColor; stroke-width: 2; fill: none; stroke-linecap: round; stroke-linejoin: round; }
.pips { display: flex; justify-content: center; gap: 8px; margin-top: 14px; }
.pips i { width: 8px; height: 8px; border-radius: 50%; background: var(--surface-2); }
.pips i.on { background: var(--rc); box-shadow: 0 0 8px var(--rc); }
.settings { display: grid; grid-template-columns: 1fr auto; gap: 12px 10px; padding: 14px 16px; align-items: center; }
.stepper { display: flex; align-items: center; gap: 12px; }
.stepper button { width: 32px; height: 32px; border-radius: 10px; background: var(--surface-2); font-weight: 700; }
.stepper b { min-width: 46px; text-align: center; font-variant-numeric: tabular-nums; }
.toggle { width: 50px; height: 30px; border-radius: 99px; background: var(--surface-2); position: relative; transition: .2s; }
.toggle::after { content: ""; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%; background: #fff; transition: .2s; box-shadow: 0 1px 3px rgba(0,0,0,.3); }
.toggle.on { background: #4cc38a; }
.toggle.on::after { left: 23px; }

/* ---------- flashcards ---------- */
.deck-grid { display: grid; gap: 10px; }
.deck { display: flex; align-items: center; gap: 14px; padding: 16px; text-align: left; width: 100%; }
.deck .main { flex: 1; }
.deck .name { font-weight: 650; }
.deck .meta { color: var(--muted); font-size: 14px; }
.due-badge { font-weight: 700; font-variant-numeric: tabular-nums; }

.study-top { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.progress { height: 4px; background: var(--surface-2); border-radius: 4px; overflow: hidden; margin-bottom: 18px; }
.progress div { height: 100%; transition: width .3s; }
.flip { perspective: 1400px; }
.flip-inner { position: relative; min-height: 360px; transition: transform .5s cubic-bezier(.2,.8,.2,1); transform-style: preserve-3d; }
.flipped .flip-inner { transform: rotateY(180deg); }
.study .rate, .study.flipped .show { display: none; }
.study.flipped .rate { display: grid; }
.face {
  position: absolute; inset: 0; backface-visibility: hidden; -webkit-backface-visibility: hidden;
  padding: 26px 22px; display: flex; flex-direction: column; border-radius: 24px;
  background: var(--surface); border: 1px solid var(--line);
}
.face.back { transform: rotateY(180deg); }
.face .tag { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); font-weight: 600; }
.face .content { flex: 1; display: grid; place-items: center; text-align: center; padding: 14px 0; }
.face.front .content { font-size: 24px; font-weight: 650; letter-spacing: -.01em; }
.face.front.q .content { font-size: 19px; font-weight: 600; }
.face.back .content { font-size: 18px; text-align: left; place-items: center start; white-space: pre-line; }
.face .hint { text-align: center; color: var(--faint); font-size: 13px; }
.rate { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-top: 16px; }
.rate .btn { flex-direction: column; gap: 0; padding: 11px 6px; }
.rate small { font-weight: 500; color: var(--muted); font-size: 12px; }

/* ---------- quiz & write ---------- */
.mode-seg button { font-size: 13px; }
.deck[disabled] { opacity: .45; }
.qcard { padding: 20px 20px 22px; border-radius: 24px; }
.qcard .tag { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); font-weight: 600; }
.qlabel { margin-top: 16px; font-size: 13px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--faint); }
.qtext { margin-top: 8px; font-size: 18px; line-height: 1.45; white-space: pre-line; }
.qtext.big { font-size: 26px; font-weight: 650; letter-spacing: -.01em; }
.opts { display: grid; gap: 10px; margin-top: 14px; }
.opt {
  display: flex; gap: 12px; align-items: flex-start; text-align: left; width: 100%;
  padding: 14px 14px; border-radius: 16px; background: var(--surface); border: 1.5px solid var(--line);
  font-size: 15px; line-height: 1.4; transition: background .15s, border-color .15s, opacity .15s;
}
.opt .key {
  flex: none; width: 26px; height: 26px; border-radius: 8px; display: grid; place-items: center;
  background: var(--surface-2); font-size: 13px; font-weight: 700; color: var(--muted);
}
.opt:not([disabled]):active { transform: scale(.98); }
.opt.right { border-color: #4cc38a; background: color-mix(in srgb, #4cc38a 14%, var(--surface)); }
.opt.right .key { background: #4cc38a; color: #08130d; }
.opt.wrong { border-color: var(--danger); background: color-mix(in srgb, var(--danger) 14%, var(--surface)); animation: shake .35s; }
.opt.wrong .key { background: var(--danger); color: #1a0606; }
.opt.dim { opacity: .45; }
.opt[disabled] { cursor: default; color: inherit; }
@keyframes shake { 25% { transform: translateX(-5px); } 75% { transform: translateX(5px); } }
.write-box {
  width: 100%; margin-top: 14px; padding: 14px 16px; border-radius: 16px; resize: vertical;
  background: var(--surface); border: 1.5px solid var(--line); outline: 0; font-size: 16px; line-height: 1.45;
}
.write-box:focus { border-color: var(--accent); }
.verdict { margin: 16px 4px 10px; font-weight: 700; font-size: 17px; }
.verdict.right { color: #4cc38a; }
.verdict.partial { color: #e0b43a; }
.verdict.wrong { color: var(--danger); }
.verdict.miss { color: var(--muted); }
.compare { padding: 14px 16px; display: grid; gap: 4px; }
.compare .lbl { font-size: 12px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--faint); margin-top: 6px; }
.compare .lbl:first-child { margin-top: 0; }
.compare .def { white-space: pre-line; }
mark { border-radius: 4px; padding: 0 2px; color: inherit; }
mark.hit { background: color-mix(in srgb, #4cc38a 30%, transparent); }
mark.miss { background: color-mix(in srgb, var(--danger) 28%, transparent); }
.score-ring { position: relative; width: 110px; height: 110px; margin: 0 auto; }
.score-ring svg { width: 110px; height: 110px; }
.score-ring b { position: absolute; inset: 0; display: grid; place-items: center; font-size: 26px; letter-spacing: -.02em; }

/* ---------- progress ---------- */
.ring-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; }
.ring-card { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 10px 2px; font-size: 12px; font-weight: 600; color: var(--muted); }
.ring-card.on { border-color: var(--c); color: var(--text); }
.ring-card .mini { position: relative; width: 52px; height: 52px; }
.ring-card .mini svg { width: 52px; height: 52px; }
.ring-card .mini b { position: absolute; inset: 0; display: grid; place-items: center; font-size: 12px; color: var(--text); }
.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; margin: 12px 4px 0; font-size: 12px; color: var(--muted); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.topic-head { display: flex; justify-content: space-between; gap: 10px; align-items: baseline; }
.topic-pct { font-variant-numeric: tabular-nums; }
.stack { display: flex; gap: 2px; height: 8px; border-radius: 6px; overflow: hidden; background: var(--surface-2); margin: 8px 0; }
.stack i { display: block; min-width: 3px; }
.topic-foot { display: flex; justify-content: space-between; align-items: center; margin-bottom: 4px; }
.conf { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); }
.conf span { margin-right: 4px; }
.conf button { width: 20px; height: 20px; border-radius: 50%; border: 2px solid var(--faint); }
.conf button.on { background: var(--c); border-color: var(--c); }
.hbar { display: grid; grid-template-columns: 74px 1fr 44px; align-items: center; gap: 10px; padding: 5px 0; font-size: 14px; }
.hbar div { height: 10px; background: var(--surface-2); border-radius: 6px; overflow: hidden; }
.hbar i { display: block; height: 100%; border-radius: 6px; }
.hbar b { text-align: right; font-variant-numeric: tabular-nums; }

/* ---------- tab bar ---------- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: flex; justify-content: space-around;
  padding: 8px 8px calc(var(--safe-bottom) + 6px);
  background: color-mix(in srgb, var(--bg) 78%, transparent);
  backdrop-filter: saturate(180%) blur(20px); -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-top: 1px solid var(--line);
}
.tabbar button { flex: 1; max-width: 96px; min-width: 0; display: flex; flex-direction: column; align-items: center; gap: 3px; color: var(--faint); font-size: 11px; font-weight: 600; padding: 4px 0; }
.tabbar svg { width: 25px; height: 25px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.tabbar button.on { color: var(--text); }

.toast {
  position: fixed; left: 50%; top: calc(var(--safe-top) + 12px); transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 10px 18px; border-radius: 999px; font-weight: 600; font-size: 14px;
  z-index: 20; animation: drop .3s ease; width: max-content; max-width: calc(100% - 32px); text-align: center;
}
@keyframes drop { from { opacity: 0; transform: translate(-50%, -10px); } }

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