:root {
  --bg: #0b0f14;
  --surface: #121821;
  --surface-2: #19212c;
  --border: #243040;
  --text: #e6edf3;
  --muted: #8b98a9;
  --accent: #10b981;
  --accent-ink: #04140e;
  --accent-soft: rgba(16, 185, 129, 0.14);
  --miss: #f87171;
  --miss-soft: rgba(248, 113, 113, 0.12);
  --warn: #fbbf24;
  --easy: #34d399;
  --medium: #fbbf24;
  --hard: #f87171;
  --radius: 12px;
  --mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
  color-scheme: dark;
}
@media (prefers-color-scheme: light) {
  :root {
    --bg: #f6f7f9;
    --surface: #ffffff;
    --surface-2: #f1f3f6;
    --border: #e1e5ea;
    --text: #111827;
    --muted: #5b6676;
    --accent: #059669;
    --accent-ink: #ffffff;
    --accent-soft: rgba(5, 150, 105, 0.1);
    --miss: #dc2626;
    --miss-soft: rgba(220, 38, 38, 0.08);
    --warn: #b45309;
    --easy: #059669;
    --medium: #b45309;
    --hard: #dc2626;
    color-scheme: light;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.55 Inter, system-ui, -apple-system, sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; }
code, kbd, pre, textarea { font-family: var(--mono); }
code { background: var(--surface-2); border: 1px solid var(--border); border-radius: 5px; padding: 0 5px; font-size: 0.88em; }
kbd { border: 1px solid var(--border); border-bottom-width: 2px; border-radius: 4px; padding: 0 4px; font-size: 0.8em; }
h1 { font-size: clamp(1.6rem, 3.4vw, 2.2rem); line-height: 1.15; letter-spacing: -0.02em; margin: 0 0 8px; }
h2 { font-size: 1.15rem; margin: 0 0 12px; letter-spacing: -0.01em; }
h3 { margin: 0; font-size: 1rem; }
p { margin: 0 0 10px; }
.muted { color: var(--muted); }
.small { font-size: 0.84rem; }
.lede { color: var(--muted); font-size: 1.02rem; max-width: 60ch; margin-bottom: 20px; }
.eyebrow { text-transform: uppercase; letter-spacing: 0.08em; font-size: 0.72rem; font-weight: 600; color: var(--accent); margin-bottom: 6px; }

/* top bar */
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 24px;
  padding: 12px max(16px, calc((100vw - 1180px) / 2));
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; text-decoration: none; letter-spacing: -0.01em; }
.logo { width: 24px; height: 24px; border-radius: 7px; background: var(--accent); position: relative; }
.logo::after { content: ''; position: absolute; inset: 7px 6px; border-top: 2px solid var(--accent-ink); border-bottom: 2px solid var(--accent-ink); }
.tabs { display: flex; gap: 4px; }
.tabs a { text-decoration: none; color: var(--muted); padding: 6px 12px; border-radius: 8px; font-weight: 500; }
.tabs a:hover { color: var(--text); background: var(--surface-2); }
.tabs a.active { color: var(--text); background: var(--surface-2); }
.streak { margin-left: auto; font-weight: 600; font-size: 0.9rem; white-space: nowrap; }
.flame { color: var(--warn); }

main { max-width: 1180px; margin: 0 auto; padding: 32px 16px 80px; outline: none; }

/* cards and buttons */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; }
.card.flush { padding: 0; overflow: hidden; }
.btn {
  display: inline-flex; align-items: center; gap: 8px;
  border: 1px solid transparent; border-radius: 9px; padding: 10px 18px;
  font: 600 0.95rem Inter, sans-serif; cursor: pointer; text-decoration: none;
  transition: transform 0.08s ease, background 0.15s ease;
}
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { background: var(--surface-2); color: var(--text); border-color: var(--border); }
.btn.ghost:hover { border-color: var(--muted); }
.link { background: none; border: 0; padding: 0; color: var(--accent); font: inherit; font-weight: 500; cursor: pointer; text-decoration: none; }
.link:hover { text-decoration: underline; }
.back { display: inline-block; margin-bottom: 16px; }
button:focus-visible, a:focus-visible, textarea:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.bar { height: 6px; background: var(--surface-2); border-radius: 99px; overflow: hidden; margin: 10px 0 6px; }
.bar span { display: block; height: 100%; background: var(--accent); border-radius: 99px; transition: width 0.4s ease; }

/* home */
.hero { display: grid; grid-template-columns: 1fr 320px; gap: 32px; align-items: start; margin-bottom: 28px; }
.plan { display: grid; gap: 6px; margin: 4px 0 22px; max-width: 520px; }
.plan-row { display: grid; grid-template-columns: 14px 130px 1fr; align-items: center; gap: 10px; padding: 9px 12px; background: var(--surface); border: 1px solid var(--border); border-radius: 9px; }
.plan-row .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--border); }
.plan-row.next { border-color: var(--accent); }
.plan-row.next .dot { background: var(--accent); }
.plan-row.ok .dot { background: var(--accent); }
.plan-row.miss .dot { background: var(--miss); }
.plan-row .kind { font-weight: 600; font-size: 0.88rem; }
.plan-row .topic { color: var(--muted); font-size: 0.88rem; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.stat { display: flex; flex-direction: column; }
.stat .num { font-size: 1.7rem; font-weight: 700; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.stat .label { color: var(--muted); font-size: 0.78rem; }
.level { grid-column: 1 / -1; border-top: 1px solid var(--border); padding-top: 14px; margin-top: 6px; }
.level-row { display: flex; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.stage-name { font-size: 1.2rem; font-weight: 600; margin-bottom: 4px; }
.heatmap { display: grid; grid-template-rows: repeat(7, 12px); grid-auto-flow: column; grid-auto-columns: 12px; gap: 3px; margin-bottom: 10px; overflow-x: auto; }
.cell { border-radius: 3px; background: var(--surface-2); }
.cell.l1 { background: color-mix(in srgb, var(--accent) 22%, var(--surface-2)); }
.cell.l2 { background: color-mix(in srgb, var(--accent) 45%, var(--surface-2)); }
.cell.l3 { background: color-mix(in srgb, var(--accent) 70%, var(--surface-2)); }
.cell.l4 { background: var(--accent); }

/* roadmap */
.roadmap { list-style: none; padding: 0; margin: 0 0 24px; display: grid; gap: 10px; }
.road { display: grid; grid-template-columns: 36px 1fr; gap: 14px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; }
.road .step { width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; background: var(--surface-2); border: 1px solid var(--border); }
.road.current { border-color: var(--accent); }
.road.current .step, .road.complete .step { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.road-head { display: flex; justify-content: space-between; gap: 10px; flex-wrap: wrap; margin-bottom: 4px; }
.road p { margin: 0; }

/* problem list */
table { border-collapse: collapse; width: 100%; }
.list th, .list td { text-align: left; padding: 12px 16px; border-bottom: 1px solid var(--border); }
.list th { font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); font-weight: 600; }
.list tr:last-child td { border-bottom: 0; }
.list tbody tr:hover { background: var(--surface-2); }
.list a { text-decoration: none; font-weight: 500; }
.list a:hover { color: var(--accent); }
.diff { font-weight: 600; font-size: 0.85rem; }
.diff.easy { color: var(--easy); }
.diff.medium { color: var(--medium); }
.diff.hard { color: var(--hard); }
.pill { font-size: 0.76rem; padding: 2px 8px; border-radius: 99px; background: var(--surface-2); color: var(--muted); border: 1px solid var(--border); white-space: nowrap; }
.pill.ok { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.pill.miss { background: var(--miss-soft); color: var(--miss); border-color: transparent; }

/* session */
.session-head { display: flex; align-items: center; gap: 16px; margin-bottom: 20px; }
.progress { display: flex; gap: 6px; flex: 1; }
.seg { flex: 1; height: 6px; border-radius: 99px; background: var(--surface-2); }
.seg.cur { background: color-mix(in srgb, var(--accent) 40%, var(--surface-2)); }
.seg.ok { background: var(--accent); }
.seg.miss { background: var(--miss); }
.timer { font: 600 1rem var(--mono); font-variant-numeric: tabular-nums; min-width: 56px; text-align: right; }
.timer.over { color: var(--warn); }

.question { max-width: 760px; margin: 0 auto; }
.question .q { font-size: 1.2rem; font-weight: 600; line-height: 1.45; }
.question .q p { margin: 0; }
.options { display: grid; gap: 8px; margin: 18px 0; }
.option {
  display: grid; grid-template-columns: 28px 1fr; gap: 12px; align-items: center; text-align: left;
  background: var(--surface-2); border: 1px solid var(--border); color: var(--text);
  border-radius: 10px; padding: 12px 14px; font: inherit; cursor: pointer;
  transition: border-color 0.12s ease, background 0.12s ease;
}
.option p { margin: 0; }
.option:hover:not(:disabled) { border-color: var(--accent); }
.option:disabled { cursor: default; }
.option .key { width: 26px; height: 26px; border-radius: 7px; display: grid; place-items: center; font: 600 0.8rem var(--mono); border: 1px solid var(--border); background: var(--surface); }
.option.correct { border-color: var(--accent); background: var(--accent-soft); }
.option.correct .key { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.option.wrong { border-color: var(--miss); background: var(--miss-soft); }
.option.wrong .key { background: var(--miss); color: #fff; border-color: var(--miss); }
.feedback { border-radius: 10px; padding: 14px 16px; margin-bottom: 14px; border: 1px solid; }
.feedback strong { display: block; margin-bottom: 4px; }
.feedback p:last-child { margin-bottom: 0; }
.feedback.ok { background: var(--accent-soft); border-color: color-mix(in srgb, var(--accent) 40%, transparent); }
.feedback.ok strong { color: var(--accent); }
.feedback.miss { background: var(--miss-soft); border-color: color-mix(in srgb, var(--miss) 40%, transparent); }
.feedback.miss strong { color: var(--miss); }

/* sql */
.sql-layout { display: grid; grid-template-columns: minmax(0, 5fr) minmax(0, 7fr); gap: 16px; align-items: start; }
.problem { position: sticky; top: 76px; max-height: calc(100vh - 96px); overflow: auto; }
.title-row { display: flex; justify-content: space-between; gap: 10px; align-items: baseline; }
.prompt ul { padding-left: 20px; margin: 0 0 10px; }
.note { color: var(--warn); }
.small-h { font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); margin: 18px 0 8px; }
.schema { display: grid; gap: 6px; }
.tbl { background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; padding: 8px 12px; }
.tbl summary { cursor: pointer; display: flex; justify-content: space-between; gap: 8px; list-style: none; }
.tbl summary::-webkit-details-marker { display: none; }
.tbl summary code { background: none; border: 0; padding: 0; font-weight: 500; }
.cols { display: flex; flex-wrap: wrap; gap: 4px 14px; margin: 8px 0; font: 0.82rem var(--mono); }
.cols em { color: var(--muted); font-style: normal; }
.hint-row { display: flex; gap: 18px; margin-top: 16px; }
.hint { margin-top: 12px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; padding: 12px 14px; }
.code { margin: 6px 0 10px; white-space: pre-wrap; font-size: 0.82rem; line-height: 1.5; }
.editor-card { padding: 0; overflow: hidden; }
.editor-head { padding: 10px 16px; border-bottom: 1px solid var(--border); }
#editor {
  display: block; width: 100%; min-height: 260px; resize: vertical;
  background: var(--surface-2); color: var(--text); border: 0; padding: 16px;
  font-size: 0.9rem; line-height: 1.6; tab-size: 2;
}
#editor:focus-visible { outline: none; box-shadow: inset 0 0 0 2px var(--accent); }
.editor-actions { display: flex; align-items: center; gap: 10px; padding: 12px 16px; border-top: 1px solid var(--border); }
.editor-actions .link { margin-left: auto; color: var(--muted); }
#verdict, #output { padding: 0 16px; }
#verdict:not(:empty) { padding-top: 4px; }
#verdict .btn { margin-bottom: 14px; }
#output { padding-bottom: 16px; }
.table-wrap { overflow: auto; max-height: 360px; border: 1px solid var(--border); border-radius: 8px; margin: 8px 0; }
.table-wrap table { font: 0.82rem var(--mono); }
.table-wrap th, .table-wrap td { padding: 6px 12px; border-bottom: 1px solid var(--border); text-align: left; white-space: nowrap; }
.table-wrap th { position: sticky; top: 0; background: var(--surface-2); font-weight: 600; }
.null { color: var(--muted); font-style: italic; }
.error { color: var(--miss); white-space: pre-wrap; font-size: 0.85rem; background: var(--miss-soft); padding: 10px 12px; border-radius: 8px; }

/* summary */
.summary { max-width: 680px; margin: 0 auto; }
.recap { list-style: none; padding: 0; margin: 0 0 20px; display: grid; gap: 6px; }
.recap li { display: grid; grid-template-columns: 22px 1fr auto; gap: 10px; align-items: center; padding: 10px 12px; background: var(--surface-2); border-radius: 8px; }
.recap .mark { font-weight: 700; }
.recap .ok .mark { color: var(--accent); }
.recap .miss .mark { color: var(--miss); }
.actions { display: flex; gap: 10px; flex-wrap: wrap; }

@media (max-width: 900px) {
  .hero, .grid2, .sql-layout { grid-template-columns: 1fr; }
  .problem { position: static; max-height: none; }
}
@media (max-width: 560px) {
  .topbar { gap: 10px; }
  .brand span:last-child { display: none; }
  .tabs a { padding: 6px 8px; }
  .hide-sm { display: none; }
  .list th, .list td { padding: 10px; }
  .plan-row { grid-template-columns: 14px 1fr; }
  .plan-row .topic { grid-column: 2; }
  .recap li { grid-template-columns: 22px 1fr; }
  .recap li .small { grid-column: 2; }
}
