:root {
  --bg: #f6f7fb; --surface: #ffffff; --text: #1d2433; --muted: #6b7385; --border: #e3e6ee;
  --primary: #2f5bea; --primary-ink: #fff;
  --red: #d64545; --orange: #e08a1e; --green: #2e9d5b; --blue: #2f7fd6;
  --radius: 14px; --shadow: 0 1px 2px rgba(20,30,60,.06), 0 4px 16px rgba(20,30,60,.06);
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #11141b; --surface: #1a1f2a; --text: #e8ebf2; --muted: #98a0b3; --border: #2a3140;
          --primary: #5b82ff; --shadow: none; }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.6rem; margin: 0 0 .5rem; } h2 { font-size: 1.15rem; margin: 0 0 .75rem; }
code, kbd { font-size: .85em; background: var(--bg); border: 1px solid var(--border); border-radius: 5px; padding: 0 .35em; }

.topbar { display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap;
  padding: .75rem 1rem; background: var(--surface); border-bottom: 1px solid var(--border); }
.brand { font-weight: 700; color: var(--text); }
.topbar nav { display: flex; gap: 1rem; align-items: center; }
.topbar nav a { color: var(--text); }
.wrap { max-width: 960px; margin: 0 auto; padding: 1.25rem 1rem 3rem; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 1.25rem; margin-bottom: 1rem; }
.narrow { max-width: 440px; margin: 2rem auto; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 1rem; }
.grid > .card { margin: 0; }
.row { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }
.between { justify-content: space-between; }
.muted { color: var(--muted); } .small { font-size: .85rem; } .center { text-align: center; }
.hidden { display: none !important; }
.inline { display: inline; margin: 0; }

/* forms */
label { display: block; font-size: .9rem; font-weight: 600; margin-bottom: .75rem; }
label.check { display: flex; gap: .5rem; align-items: center; font-weight: 400; }
input, textarea, select { width: 100%; font: inherit; color: var(--text); background: var(--bg);
  border: 1px solid var(--border); border-radius: 10px; padding: .6rem .75rem; margin-top: .25rem; }
input[type=checkbox] { width: auto; margin: 0; }
input:focus, textarea:focus, select:focus { outline: 2px solid var(--primary); outline-offset: -1px; }
.card-form { display: grid; gap: 0 1rem; grid-template-columns: 1fr 1fr; }
.card-form > .btn, .card-form > label.check, .card-form textarea { grid-column: 1 / -1; }
.card-form > label:has(textarea) { grid-column: 1 / -1; }
.narrow .card-form { grid-template-columns: 1fr; }
@media (max-width: 640px) { .card-form { grid-template-columns: 1fr; } }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: .5rem; font: inherit; font-weight: 600;
  padding: .6rem 1rem; border-radius: 10px; border: 1px solid var(--border); background: var(--surface);
  color: var(--text); cursor: pointer; text-decoration: none !important; }
.btn:hover { filter: brightness(.97); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
.btn.danger { color: var(--red); border-color: var(--red); }
.btn.big { padding: .9rem 1.4rem; font-size: 1.05rem; }
button.link { background: none; border: 0; color: var(--text); font: inherit; cursor: pointer; padding: 0; }
.pill { background: rgba(255,255,255,.2); border-radius: 99px; padding: .1rem .6rem; font-size: .85rem; font-weight: 500; }

.flash { padding: .75rem 1rem; border-radius: 10px; margin-bottom: 1rem; background: #e7f6ec; color: #1b6b3a; }
.flash.err { background: #fdeaea; color: #9b2c2c; }
@media (prefers-color-scheme: dark) { .flash { background: #173524; color: #9fe0b5; } .flash.err { background: #3a1a1a; color: #f3a6a6; } }

/* dashboard */
.hero { display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap; margin-bottom: 1.25rem; }
.deck-title { font-weight: 700; font-size: 1.1rem; color: var(--text); }
.counts { display: flex; gap: .75rem; font-size: .9rem; }
.counts .due { color: var(--green); font-weight: 600; } .counts .new { color: var(--blue); font-weight: 600; }
.new-deck input { margin-bottom: .5rem; }
.deck-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; flex-wrap: wrap; margin-bottom: 1rem; }
.danger-zone { margin-top: 1rem; padding-top: 1rem; border-top: 1px solid var(--border); }
details summary { cursor: pointer; font-weight: 600; }
details[open] summary { margin-bottom: 1rem; }

.tag { display: inline-block; font-size: .75rem; font-weight: 600; padding: .1rem .5rem; border-radius: 99px;
  background: var(--bg); border: 1px solid var(--border); color: var(--muted); }
.tag.new { color: var(--blue); border-color: currentColor; }
.tag.due { color: var(--green); border-color: currentColor; }

.cards-table { width: 100%; border-collapse: collapse; font-size: .95rem; }
.cards-table th, .cards-table td { text-align: left; padding: .6rem .5rem; border-bottom: 1px solid var(--border); vertical-align: top; }
.cards-table th { font-size: .8rem; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }
@media (max-width: 640px) { .cards-table th:nth-child(3), .cards-table td:nth-child(3) { display: none; } }

/* study */
.study { max-width: 640px; margin: 0 auto; }
.study-top { display: flex; justify-content: space-between; align-items: center; gap: .5rem; margin-bottom: .75rem; font-size: .9rem; }
.study-top label { margin: 0; }
.flashcard { background: var(--surface); border: 1px solid var(--border); border-radius: 18px; box-shadow: var(--shadow);
  min-height: 300px; padding: 2rem 1.5rem; display: flex; flex-direction: column; justify-content: center;
  text-align: center; cursor: pointer; outline: none; }
.flashcard .face .tag { margin-bottom: 1rem; }
.term { font-size: clamp(1.6rem, 5vw, 2.3rem); font-weight: 700; line-height: 1.25; }
.answer { border-top: 1px dashed var(--border); margin-top: 1.5rem; padding-top: 1.5rem; }
.answer .term { font-size: clamp(1.3rem, 4vw, 1.7rem); font-weight: 600; }
.example { font-style: italic; color: var(--muted); font-size: 1.05rem; }
.notes { font-size: .95rem; color: var(--muted); }
.answer .edit { display: inline-block; margin-top: .5rem; }
.speak { background: none; border: 0; cursor: pointer; font-size: .7em; vertical-align: middle; padding: .2rem; opacity: .75; }
.speak:hover { opacity: 1; }

.actions { margin: 1rem 0 .5rem; }
.actions > .btn { width: 100%; }
.ratings { display: grid; grid-template-columns: repeat(4, 1fr); gap: .5rem; }
.ratings .btn { flex-direction: column; gap: 0; padding: .7rem .25rem; color: #fff; border: 0; }
.ratings small { font-weight: 400; opacity: .85; font-size: .78rem; }
.r1 { background: var(--red); } .r2 { background: var(--orange); } .r3 { background: var(--green); } .r4 { background: var(--blue); }
.done { text-align: center; padding: 3rem 1rem; }

/* stats */
.stats-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 1rem; margin-bottom: 1rem; }
.stats-row .card { margin: 0; }
.stat b { display: block; font-size: 1.8rem; } .stat span { color: var(--muted); font-size: .85rem; }
.bars { display: flex; align-items: flex-end; gap: 3px; height: 140px; }
.bar { flex: 1; height: 100%; display: flex; align-items: flex-end; }
.bar span { display: block; width: 100%; min-height: 2px; background: var(--primary); border-radius: 3px 3px 0 0; }
