:root {
  --bg: #fbf6ea;
  --surface: #ffffff;
  --surface-2: #f4efe2;
  --ink: #1c2a21;
  --muted: #5f6d64;
  --line: #e5ddca;
  --green: #1d5c3a;
  --green-ink: #ffffff;
  --gold: #e3ad18;
  --red: #c8392d;
  --st-mastered: #2f8f57;
  --st-learning: #e3ad18;
  --st-missed: #d24a3e;
  --st-new: #ddd5c3;
  --right-bg: #e3f3e8;
  --wrong-bg: #fbe6e3;
  --hint-bg: #fdf3d6;
  --shadow: 0 1px 2px rgba(30, 40, 30, .06), 0 8px 24px rgba(30, 40, 30, .08);
  --radius: 18px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1612;
    --surface: #16231b;
    --surface-2: #1d2d23;
    --ink: #edf2ec;
    --muted: #9fb2a5;
    --line: #2a3c31;
    --green: #3f9a66;
    --green-ink: #06140c;
    --gold: #f0c04a;
    --red: #e86a5e;
    --st-mastered: #45b072;
    --st-learning: #e9b93a;
    --st-missed: #e2665a;
    --st-new: #34463b;
    --right-bg: #173826;
    --wrong-bg: #3d1d1a;
    --hint-bg: #3a3016;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .3);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  min-height: 100dvh;
}
button { font: inherit; color: inherit; cursor: pointer; }
[hidden] { display: none !important; }

.stripe {
  height: 6px;
  background: repeating-linear-gradient(-45deg, var(--red) 0 10px, #fff 10px 20px);
  position: sticky; top: 0; z-index: 5;
}
@media (prefers-color-scheme: dark) { .stripe { background: repeating-linear-gradient(-45deg, var(--red) 0 10px, #f3efe6 10px 20px); } }

.view {
  max-width: 680px;
  margin: 0 auto;
  padding: 16px max(16px, env(safe-area-inset-right)) calc(24px + env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
}

h1, h2 { margin: 0; }
h2 { font-size: 1.05rem; font-weight: 650; }
.mt { margin-top: 18px; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.error { color: var(--red); }

.logo {
  font-family: "Mountains of Christmas", Georgia, serif;
  font-weight: 700;
  color: var(--green);
  font-size: 2.6rem;
  line-height: 1.1;
  letter-spacing: .5px;
}
.logo-sm { font-size: 1.7rem; }
.brand { text-align: center; padding: 28px 0 18px; }
.tagline { margin: 6px 0 0; color: var(--muted); }

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
  margin-bottom: 14px;
}
.panel-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 10px; }

/* ---------- buttons ---------- */
.btn {
  border: 1px solid transparent;
  border-radius: 14px;
  padding: 12px 16px;
  font-weight: 600;
  min-height: 48px;
  display: inline-flex; align-items: center; justify-content: center; gap: 10px;
  transition: transform .06s ease, filter .15s ease, background .15s ease;
  -webkit-tap-highlight-color: transparent;
}
.btn:active:not(:disabled) { transform: scale(.98); }
.btn:disabled { opacity: .45; cursor: default; }
.btn-lg { min-height: 56px; font-size: 1.05rem; }
.btn-primary { background: var(--green); color: var(--green-ink); }
.btn-primary:hover:not(:disabled) { filter: brightness(1.08); }
.btn-secondary { background: var(--surface); border-color: var(--line); color: var(--ink); }
.btn-ghost { background: transparent; border-color: var(--line); color: var(--ink); }
.btn-right { background: var(--st-mastered); color: #fff; }
.btn-wrong { background: var(--st-missed); color: #fff; }
@media (prefers-color-scheme: dark) { .btn-right, .btn-wrong { color: #0b130e; } }
.grow { flex: 1 1 0; }
.link { background: none; border: 0; padding: 4px; color: var(--green); font-weight: 600; }
.link-danger { color: var(--red); font-weight: 500; }
.icon-btn {
  width: 44px; height: 44px; border-radius: 50%;
  border: 1px solid var(--line); background: var(--surface); font-size: 1.1rem; flex: none;
}
kbd {
  font: 600 .7rem/1 ui-monospace, SFMono-Regular, Menlo, monospace;
  padding: 3px 5px; border-radius: 5px;
  border: 1px solid currentColor; opacity: .55;
}
@media (hover: none), (max-width: 600px) { .act-row kbd { display: none; } }

.chip {
  border: 1px solid var(--line); background: var(--surface);
  border-radius: 999px; padding: 8px 14px; min-height: 40px;
  text-transform: capitalize; font-weight: 550;
}
.chip.on { background: var(--green); border-color: var(--green); color: var(--green-ink); }
.chips { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.chip-player { text-transform: none; }

/* ---------- players ---------- */
.player-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; margin: 14px 0; }
.player-list p { grid-column: 1 / -1; margin: 0; }
.btn-player { background: var(--surface-2); border-color: var(--line); min-height: 64px; font-size: 1.1rem; }
.btn-player:hover { border-color: var(--green); }
.add-player { display: flex; gap: 8px; }
.add-player input {
  flex: 1; min-width: 0; min-height: 48px; padding: 0 14px;
  border-radius: 14px; border: 1px solid var(--line);
  background: var(--surface-2); color: var(--ink); font-size: 16px;
}

/* ---------- home ---------- */
.topbar { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin: 4px 0 14px; }
.overall-head { display: flex; justify-content: space-between; align-items: flex-end; margin-bottom: 12px; }
.big-number { font-size: 2.4rem; font-weight: 750; line-height: 1; font-variant-numeric: tabular-nums; }
.big-number .of { font-size: 1.2rem; color: var(--muted); font-weight: 600; }
.sync { font-size: .8rem; color: var(--muted); text-align: right; }
.sync-wait { color: var(--gold); }

.bar {
  display: flex; height: 10px; border-radius: 99px; overflow: hidden;
  background: var(--st-new); gap: 2px;
}
.bar-lg { height: 16px; }
.seg { display: block; min-width: 3px; }
.seg-mastered { background: var(--st-mastered); }
.seg-learning { background: var(--st-learning); }
.seg-missed { background: var(--st-missed); }
.seg-new { background: var(--st-new); }

.legend { list-style: none; padding: 0; margin: 12px 0 0; display: flex; flex-wrap: wrap; gap: 6px 16px; font-size: .85rem; color: var(--muted); }
.legend b { color: var(--ink); font-variant-numeric: tabular-nums; margin-left: 4px; }
.sw { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }
.sw-mastered { background: var(--st-mastered); } .sw-learning { background: var(--st-learning); }
.sw-missed { background: var(--st-missed); } .sw-new { background: var(--st-new); }

.category-list { display: grid; gap: 8px; }
.cat-row {
  text-align: left; width: 100%;
  background: var(--surface-2); border: 1px solid var(--line); border-radius: 14px;
  padding: 10px 12px 12px; opacity: .55;
}
.cat-row.on { opacity: 1; border-color: color-mix(in srgb, var(--green) 45%, var(--line)); }
.cat-head { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.check {
  width: 22px; height: 22px; border-radius: 7px; flex: none;
  border: 1.5px solid var(--line); display: grid; place-items: center;
  font-size: .8rem; font-weight: 800;
}
.cat-row.on .check { background: var(--green); border-color: var(--green); color: var(--green-ink); }
.cat-name { flex: 1; font-weight: 600; }
.cat-count { font-variant-numeric: tabular-nums; font-size: .9rem; }

.actions-home { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 4px 0 14px; }
@media (max-width: 420px) { .actions-home { grid-template-columns: 1fr; } }
.howto { font-size: .9rem; margin: 6px 4px 18px; }
.footer { text-align: center; padding-bottom: 8px; }

/* ---------- study ---------- */
.view-study {
  display: flex; flex-direction: column; min-height: calc(100dvh - 6px);
  padding-bottom: 0;
}
.study-top { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.study-progress { flex: 1; }
.study-progress .bar { margin-bottom: 6px; background: var(--line); }
.study-progress .seg { transition: width .3s ease; }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 22px;
  box-shadow: var(--shadow);
  padding: 20px 20px 22px;
  flex: 1 0 auto;
  display: flex; flex-direction: column;
  border-top: 5px solid var(--green);
}
.card.enter { animation: enter .22s ease-out; }
@keyframes enter { from { opacity: 0; transform: translateY(8px) scale(.99); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) { .card.enter { animation: none; } }

.card-meta { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.tag {
  font-size: .75rem; font-weight: 650; letter-spacing: .02em;
  padding: 4px 9px; border-radius: 99px; background: var(--surface-2); color: var(--muted);
}
.tag-diff { text-transform: capitalize; }
.tag-diff[data-diff="easy"] { color: var(--st-mastered); }
.tag-diff[data-diff="medium"] { color: var(--gold); }
.tag-diff[data-diff="hard"] { color: var(--st-missed); }
.streak { margin-left: auto; display: inline-flex; align-items: center; gap: 5px; }
.dot { width: 10px; height: 10px; border-radius: 50%; border: 2px solid var(--st-mastered); display: inline-block; }
.dot.on { background: var(--st-mastered); }
.missed-badge { font-size: .72rem; color: var(--st-missed); font-weight: 650; margin-left: 4px; }
.topic { margin: 12px 0 2px; }
.question {
  font-size: clamp(1.3rem, 1rem + 1.6vw, 1.85rem);
  line-height: 1.3; font-weight: 650; margin: 2px 0 10px;
  text-wrap: pretty;
}

.answer {
  margin-top: 10px;
  border-top: 2px dashed var(--line);
  padding-top: 14px;
  animation: enter .2s ease-out;
}
.answer-text { font-size: clamp(1.25rem, 1rem + 1.2vw, 1.6rem); font-weight: 700; color: var(--green); }
.note { margin: 10px 0 0; padding: 10px 12px; border-radius: 12px; background: var(--surface-2); color: var(--muted); font-size: .92rem; }

.choices { display: grid; gap: 8px; margin: 8px 0 14px; }
@media (min-width: 600px) { .choices { grid-template-columns: 1fr 1fr; } }
.choice {
  display: flex; align-items: center; gap: 10px; text-align: left;
  background: var(--surface-2); border: 1.5px solid var(--line); border-radius: 14px;
  padding: 12px 14px; min-height: 52px; font-weight: 550;
}
.choice:hover:not(:disabled) { border-color: var(--green); }
.choice kbd { flex: none; }
.choice.correct { background: var(--right-bg); border-color: var(--st-mastered); }
.choice.wrong { background: var(--wrong-bg); border-color: var(--st-missed); }
.choice:disabled { cursor: default; }
.choice:disabled:not(.correct):not(.wrong) { opacity: .55; }

.feedback { margin: 10px 0 0; padding: 10px 14px; border-radius: 12px; font-weight: 600; font-size: .95rem; }
.fb-right { background: var(--right-bg); }
.fb-hint { background: var(--hint-bg); }
.fb-wrong { background: var(--wrong-bg); }

.study-actions {
  position: sticky; bottom: 0;
  padding: 12px 0 calc(12px + env(safe-area-inset-bottom));
  background: linear-gradient(to bottom, transparent, var(--bg) 14px);
  margin-top: 8px;
}
.act-row { display: flex; gap: 10px; }
#act-front .btn-ghost { flex: 0 0 auto; }
@media (max-width: 420px) {
  #act-front { flex-direction: column-reverse; }
  #act-front .btn-ghost { min-height: 44px; }
}

.btn-drop {
  flex: none; background: none; border: 1px solid var(--line); border-radius: 99px;
  padding: 8px 12px; min-height: 40px; font-size: .85rem; font-weight: 600; color: var(--muted);
}
.btn-drop:hover { color: var(--red); border-color: var(--red); }

.dropped summary { cursor: pointer; font-weight: 650; }
.dropped > p { margin: 10px 0 4px; }
.dropped-list { list-style: none; padding: 0; margin: 0; }
.dropped-item { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-top: 1px solid var(--line); }
.dropped-item:first-child { border-top: 0; }
.dropped-text { flex: 1; min-width: 0; }
.btn-restore { min-height: 40px; padding: 8px 14px; flex: none; }

.confirm-detail {
  margin: 0 0 16px; padding: 10px 14px; border-left: 4px solid var(--line);
  background: var(--surface-2); border-radius: 0 10px 10px 0; font-weight: 600;
}

/* ---------- done ---------- */
.done { text-align: center; padding: 36px 20px; margin-top: 40px; }
.done-star { font-size: 3.5rem; color: var(--gold); line-height: 1; margin-bottom: 10px; }
.done h2 { font-size: 1.6rem; margin-bottom: 8px; }
.done .actions-home { grid-template-columns: 1fr; max-width: 320px; margin: 22px auto 0; }

/* ---------- dialog + toast ---------- */
.dialog {
  border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--surface); color: var(--ink);
  padding: 20px; width: min(420px, calc(100vw - 32px));
  box-shadow: var(--shadow);
}
.dialog::backdrop { background: rgba(0, 0, 0, .4); }
.dialog p { margin: 0 0 16px; }
.toast {
  position: fixed; left: 50%; top: 22px; transform: translateX(-50%);
  background: var(--ink); color: var(--bg);
  padding: 10px 18px; border-radius: 99px; font-weight: 650; z-index: 20;
  box-shadow: var(--shadow); animation: enter .18s ease-out;
}

@media (min-width: 760px) {
  .view { padding-top: 28px; }
  .card { padding: 28px 32px 30px; min-height: 360px; flex: 0 0 auto; }
  .view-study { min-height: auto; }
  .study-actions { position: static; background: none; }
}

/* ---------- quick quiz ---------- */
.actions-home .btn-wide { grid-column: 1 / -1; }
.done-review { list-style: none; padding: 0; margin: 20px 0 0; text-align: left; display: grid; gap: 8px; }
.review-item { padding: 10px 14px; border-radius: 12px; border-left: 4px solid var(--st-missed); background: var(--wrong-bg); }
.review-item.rv-hint { border-left-color: var(--st-learning); background: var(--hint-bg); }
.rv-q { font-size: .95rem; }
.rv-a { font-weight: 700; margin-top: 4px; }
.rv-a::before { content: "Answer: "; font-weight: 500; color: var(--muted); }
