:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --text: #16181d;
  --muted: #667085;
  --border: #e4e7ec;
  --brand: #ff0033;
  --brand-soft: #fff0f2;
  --good: #12b76a;
  --hard: #f79009;
  --again: #f04438;
  --code-bg: #f2f4f7;
  --radius: 14px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115;
    --surface: #181b21;
    --text: #eceef2;
    --muted: #98a2b3;
    --border: #2a2f38;
    --brand-soft: #2a1418;
    --code-bg: #232831;
  }
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font: 16px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}
.topbar {
  display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 12px;
  padding: 14px 24px; background: var(--surface); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 5;
}
.brand { display: flex; align-items: center; gap: 12px; }
.logo {
  width: 38px; height: 38px; border-radius: 10px; background: var(--brand); color: #fff;
  display: grid; place-items: center; font-weight: 800; font-size: 20px;
}
h1 { font-size: 18px; margin: 0; }
h2 { font-size: 17px; margin: 0 0 12px; }
.subtitle { margin: 0; font-size: 13px; color: var(--muted); }
.tabs { display: flex; gap: 4px; background: var(--bg); padding: 4px; border-radius: 10px; }
.tab { border: 0; background: transparent; padding: 7px 14px; border-radius: 8px; color: var(--muted); }
.tab.active { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.08); }

main { max-width: 860px; margin: 0 auto; padding: 24px 16px 80px; }
.view { display: none; }
.view.active { display: block; }
.hidden { display: none !important; }
.panel {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px; margin-bottom: 16px;
}
.panel-head { display: flex; justify-content: space-between; align-items: center; }
.panel-head h2 { margin: 0; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.center { justify-content: center; margin-top: 12px; }
.options { margin-top: 16px; justify-content: flex-end; }
.options label { color: var(--muted); font-size: 14px; display: flex; gap: 6px; align-items: center; }
.center-text { text-align: center; }
.muted { color: var(--muted); font-size: 14px; }

button, .button {
  font: inherit; font-size: 14px; cursor: pointer; border-radius: 10px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text); padding: 8px 14px;
}
button:hover, .button:hover { border-color: var(--muted); }
button.primary { background: var(--brand); border-color: var(--brand); color: #fff; font-weight: 600; }
button.ghost { background: transparent; }
button.small { padding: 4px 10px; font-size: 13px; }
button.danger { color: var(--again); }
kbd {
  font-family: ui-monospace, monospace; font-size: 11px; padding: 1px 5px;
  border: 1px solid var(--border); border-radius: 4px; opacity: .75;
}

.chips { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 10px; margin-top: 14px; }
.chip {
  text-align: left; display: flex; flex-direction: column; gap: 4px; padding: 12px;
  opacity: .6; transition: all .15s;
}
.chip.on { opacity: 1; border-color: var(--brand); background: var(--brand-soft); }
.chip-title { font-weight: 600; }
.chip-meta { font-size: 12px; color: var(--muted); }
.meter { height: 4px; background: var(--border); border-radius: 4px; overflow: hidden; }
.meter span { display: block; height: 100%; background: var(--good); }

.progress { height: 4px; background: var(--border); border-radius: 4px; overflow: hidden; margin: 8px 0 12px; }
#progress-bar { height: 100%; background: var(--brand); transition: width .25s; width: 0; }
.session-meta { display: flex; justify-content: space-between; align-items: center; color: var(--muted); font-size: 14px; margin-bottom: 10px; }
.pill {
  display: inline-block; font-size: 12px; padding: 2px 9px; border-radius: 999px;
  background: var(--brand-soft); color: var(--brand); font-weight: 600;
}
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 26px; min-height: 240px; cursor: pointer; outline: none;
  box-shadow: 0 6px 24px rgba(0,0,0,.05);
}
.card:focus-visible { border-color: var(--brand); }
.card-face .label { font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin-bottom: 8px; }
.front .content { font-size: 20px; font-weight: 600; }
.back { border-top: 1px dashed var(--border); margin-top: 20px; padding-top: 18px; cursor: auto; }
.hint { margin-top: 28px; color: var(--muted); font-size: 13px; }
.content p { margin: 0 0 10px; }
.content ul { margin: 0 0 10px; padding-left: 22px; }
.content li { margin-bottom: 4px; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .88em; background: var(--code-bg); padding: 1px 5px; border-radius: 5px; }
pre { background: var(--code-bg); padding: 12px 14px; border-radius: 10px; overflow-x: auto; font-size: 14px; }
pre code { background: none; padding: 0; }

.grade { justify-content: center; margin-top: 16px; }
.grade button { min-width: 110px; font-weight: 600; color: #fff; border: 0; padding: 10px 16px; }
.grade .again { background: var(--again); }
.grade .hard { background: var(--hard); }
.grade .good { background: var(--good); }
.grade kbd { border-color: rgba(255,255,255,.5); }

.browse-item {
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  padding: 12px 16px; margin-bottom: 8px;
}
.browse-item summary { cursor: pointer; font-weight: 500; }
.browse-item .content { margin-top: 12px; }
.level { font-size: 11px; font-weight: 700; padding: 1px 6px; border-radius: 5px; background: var(--code-bg); color: var(--muted); }
.level.l2, .level.l3 { color: var(--hard); }
.level.l4 { color: var(--good); }
#browse-deck, #browse-search { flex: 1; min-width: 200px; }

.form { display: flex; flex-direction: column; gap: 10px; }
input, textarea, select {
  font: inherit; font-size: 15px; padding: 9px 12px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--bg); color: var(--text);
}
textarea { resize: vertical; }
.form button { align-self: flex-start; }

.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 10px 18px; border-radius: 10px; font-size: 14px;
}
