:root {
  color-scheme: light;
  --bg: #f4f3ef;
  --surface: #fcfcfb;
  --surface-2: #efeee9;
  --line: #e0dfd8;
  --text: #0b0b0b;
  --text-2: #52514e;
  --text-3: #6f6e69;
  --accent: #5b4bd5;
  --accent-ink: #ffffff;
  --danger: #b3261e;
  --correct: #2a78d6;
  --wrong: #eb6834;
  --m0: #e7e6e0;
  --m1: #d95926;
  --m2: #f6c9ae;
  --m3: #b7d3f6;
  --m4: #256abf;
  --m1-ink: #ffffff;
  --m2-ink: #0b0b0b;
  --m3-ink: #0b0b0b;
  --m4-ink: #ffffff;
  --m0-ink: #6f6e69;
  --shadow: 0 1px 2px rgb(0 0 0 / 6%);
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #121211;
    --surface: #1a1a19;
    --surface-2: #262624;
    --line: #363632;
    --text: #f0efec;
    --text-2: #c3c2b7;
    --text-3: #a5a49a;
    --accent: #9085e9;
    --accent-ink: #121211;
    --danger: #ff8a80;
    --correct: #3987e5;
    --wrong: #d95926;
    --m0: #2c2c2a;
    --m1: #d95926;
    --m2: #7a4326;
    --m3: #245087;
    --m4: #6da7ec;
    --m1-ink: #ffffff;
    --m2-ink: #ffffff;
    --m3-ink: #ffffff;
    --m4-ink: #0b0b0b;
    --m0-ink: #a5a49a;
    --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;
}

h1, h2, h3 { margin: 0; line-height: 1.25; }
h1 { font-size: 26px; font-weight: 700; }
h2 { font-size: 18px; font-weight: 650; }
h3 { font-size: 16px; font-weight: 650; }
p { margin: 0; }
a { color: var(--accent); }

.page { max-width: 1040px; margin: 0 auto; padding: 24px 16px 64px; }
.stack { display: flex; flex-direction: column; gap: 16px; }
.row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.spread { justify-content: space-between; }
.muted { color: var(--text-2); }
.small { font-size: 14px; }
.tiny { font-size: 13px; color: var(--text-3); }
.nowrap { white-space: nowrap; }

.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 16px; background: var(--surface); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; color: inherit; text-decoration: none; }
.brand img { width: 28px; height: 28px; }
.who { color: var(--text-2); font-size: 14px; }

.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: 14px;
  padding: 18px; box-shadow: var(--shadow);
}
.card > h2 + .tiny { margin-top: 2px; }

.btn {
  font: inherit; font-weight: 600; font-size: 15px; cursor: pointer;
  padding: 9px 16px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--surface); color: var(--text); text-decoration: none; display: inline-block;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--danger); }
.btn.link { border: 0; background: none; padding: 4px 0; color: var(--accent); }
.btn.link.danger { color: var(--danger); }
.btn:disabled { opacity: 0.6; cursor: default; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

label.field { display: flex; flex-direction: column; gap: 4px; font-size: 14px; font-weight: 600; }
input[type=text], input[type=password] {
  font: inherit; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--surface); color: var(--text); width: 100%;
}
.error { color: var(--danger); font-size: 14px; }
.error:empty { display: none; }

.auth { max-width: 420px; margin: 48px auto; }
.auth .logo { width: 56px; height: 56px; }
.choice { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.choice label {
  display: block; padding: 10px; text-align: center; border: 1px solid var(--line);
  border-radius: 10px; cursor: pointer; font-weight: 600;
}
.choice input { position: absolute; opacity: 0; }
.choice input:checked + span { color: var(--accent); }
.choice label:has(input:checked) { border-color: var(--accent); }
.choice label:has(input:focus-visible) { outline: 2px solid var(--accent); outline-offset: 2px; }

.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }
.tile { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 14px 16px; }
.tile .label { font-size: 13px; color: var(--text-2); }
.tile .value { font-size: 26px; font-weight: 650; line-height: 1.2; margin-top: 2px; }
.tile .note { font-size: 13px; color: var(--text-3); }

.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 12px; }
.metrics { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 16px; margin: 12px 0; }
.metric .label { font-size: 13px; color: var(--text-2); }
.metric .value { font-weight: 650; }

.badge {
  display: inline-block; font-size: 13px; font-weight: 600; padding: 2px 10px;
  border-radius: 999px; background: var(--surface-2); color: var(--text-2);
}
.code { font: 700 22px/1.3 ui-monospace, Consolas, monospace; letter-spacing: 0.08em; }
.steps { margin: 0; padding-left: 20px; }
.steps li { margin: 4px 0; }

.segmented { display: inline-flex; background: var(--surface-2); border-radius: 10px; padding: 3px; }
.segmented button {
  font: inherit; font-weight: 600; font-size: 14px; border: 0; background: none; color: var(--text-2);
  padding: 6px 16px; border-radius: 8px; cursor: pointer;
}
.segmented button[aria-pressed=true] { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

/* Карта знаний */
.map { display: grid; grid-template-columns: repeat(11, minmax(0, 1fr)); gap: 2px; max-width: 520px; }
.map .head { display: flex; align-items: center; justify-content: center; font-size: 12px; color: var(--text-3); font-weight: 600; aspect-ratio: 1; }
.map .cell {
  display: flex; align-items: center; justify-content: center; aspect-ratio: 1; font-size: 12px;
  border-radius: 4px; cursor: default; font-variant-numeric: tabular-nums;
}
.map .cell:hover { outline: 2px solid var(--text); outline-offset: -1px; }
.m0 { background: var(--m0); color: var(--m0-ink); }
.m1 { background: var(--m1); color: var(--m1-ink); }
.m2 { background: var(--m2); color: var(--m2-ink); }
.m3 { background: var(--m3); color: var(--m3-ink); }
.m4 { background: var(--m4); color: var(--m4-ink); }
.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 13px; color: var(--text-2); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.swatch { width: 12px; height: 12px; border-radius: 3px; display: inline-block; }
.swatch.correct { background: var(--correct); }
.swatch.wrong { background: var(--wrong); }
.swatch.goal-line { height: 0; width: 16px; border-radius: 0; border-top: 1px dashed var(--text-3); }

.two { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 16px; align-items: start; }

/* Полосы освоения */
.bar-row { display: grid; grid-template-columns: 44px 1fr 44px; gap: 10px; align-items: center; font-size: 14px; padding: 3px 0; }
.bar-row .pct { text-align: right; font-variant-numeric: tabular-nums; color: var(--text-2); }
.track { height: 8px; background: var(--surface-2); border-radius: 4px; overflow: hidden; }
.fill { height: 100%; background: var(--correct); border-radius: 0 4px 4px 0; }
.rus-row { display: grid; grid-template-columns: 150px 1fr 64px; gap: 10px; align-items: center; font-size: 14px; padding: 3px 0; }
.rus-row .pct { text-align: right; font-variant-numeric: tabular-nums; color: var(--text-2); }
.bar-cell { display: flex; align-items: center; gap: 8px; min-width: 110px; }
.bar-cell .track { flex: 1; }

/* График активности */
.chart { position: relative; height: 180px; margin: 14px 0 4px 30px; border-bottom: 1px solid var(--line); }
.chart .cols { position: absolute; inset: 0; display: flex; gap: 2px; align-items: stretch; }
.chart .col { flex: 1; display: flex; flex-direction: column; justify-content: flex-end; gap: 2px; min-width: 0; cursor: default; }
.chart .col:hover { background: var(--surface-2); }
.chart .seg.wrong { background: var(--wrong); border-radius: 3px 3px 0 0; }
.chart .seg.correct { background: var(--correct); }
.chart .seg.correct:first-child { border-radius: 3px 3px 0 0; }
.chart .tick { position: absolute; left: -30px; width: 24px; text-align: right; font-size: 12px; color: var(--text-3); transform: translateY(-50%); }
.chart .grid { position: absolute; left: 0; right: 0; border-top: 1px solid var(--line); }
.chart .goal { position: absolute; left: 0; right: 0; border-top: 1px dashed var(--text-3); pointer-events: none; }
.xlabels { display: flex; gap: 2px; margin-left: 30px; font-size: 12px; color: var(--text-3); }
.xlabels span { flex: 1; min-width: 0; white-space: nowrap; overflow: visible; }

details summary { cursor: pointer; font-size: 14px; color: var(--accent); }

.table-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: 14px; }
th, td { padding: 8px 10px; text-align: left; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { font-size: 13px; color: var(--text-2); font-weight: 600; }
th button { font: inherit; font-weight: 600; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
th[aria-sort=ascending] button::after { content: " ↑"; }
th[aria-sort=descending] button::after { content: " ↓"; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tr:last-child td { border-bottom: 0; }

.fact-row { display: flex; justify-content: space-between; gap: 12px; padding: 6px 0; border-bottom: 1px solid var(--line); }
.fact-row:last-child { border-bottom: 0; }
.fact-row .expr { font-weight: 650; font-variant-numeric: tabular-nums; }

.tooltip {
  position: fixed; z-index: 20; pointer-events: none; max-width: 240px;
  background: var(--text); color: var(--bg); font-size: 13px; line-height: 1.35;
  padding: 7px 10px; border-radius: 8px; white-space: pre-line;
}

dialog {
  border: 1px solid var(--line); border-radius: 14px; padding: 20px; width: min(440px, calc(100vw - 32px));
  background: var(--surface); color: var(--text);
}
dialog::backdrop { background: rgb(0 0 0 / 45%); }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; }

@media (max-width: 560px) {
  h1 { font-size: 22px; }
  .who { display: none; }
  .map .cell, .map .head { font-size: 10px; }
  .cards { grid-template-columns: 1fr; }
  .two { grid-template-columns: minmax(0, 1fr); }
}
