:root {
  color-scheme: light;
  --bg: #f6f5f2;
  --surface: #ffffff;
  --surface-2: #f0eee9;
  --border: #e3e0d8;
  --text: #1b1a18;
  --text-2: #52514e;
  --muted: #8a887f;
  --accent: #4a3aa7;
  --accent-soft: #ece9fb;
  --accent-ink: #ffffff;
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --series-3: #1baf7a;
  --good: #1f8a4c;
  --good-soft: #e3f4ea;
  --warn: #b26b00;
  --warn-soft: #fbefd9;
  --bad: #c43d3c;
  --bad-soft: #fbe6e5;
  --grid: #ebe9e3;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(0,0,0,.04), 0 4px 16px rgba(0,0,0,.04);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #121211;
    --surface: #1a1a19;
    --surface-2: #232321;
    --border: #2f2e2b;
    --text: #f4f3ef;
    --text-2: #c3c2b7;
    --muted: #8f8e86;
    --accent: #9085e9;
    --accent-soft: #2a2645;
    --accent-ink: #121211;
    --series-1: #3987e5;
    --series-2: #d95926;
    --series-3: #199e70;
    --good: #4cc07c;
    --good-soft: #17301f;
    --warn: #e0a640;
    --warn-soft: #33270f;
    --bad: #e66767;
    --bad-soft: #3a1b1b;
    --grid: #2a2a27;
    --shadow: none;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #121211; --surface: #1a1a19; --surface-2: #232321; --border: #2f2e2b;
  --text: #f4f3ef; --text-2: #c3c2b7; --muted: #8f8e86; --accent: #9085e9; --accent-soft: #2a2645; --accent-ink: #121211;
  --series-1: #3987e5; --series-2: #d95926; --series-3: #199e70;
  --good: #4cc07c; --good-soft: #17301f; --warn: #e0a640; --warn-soft: #33270f; --bad: #e66767; --bad-soft: #3a1b1b;
  --grid: #2a2a27; --shadow: none;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
button, input, textarea, select { font: inherit; color: inherit; }

.wrap { max-width: 980px; margin: 0 auto; padding: 16px 16px 64px; }
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 16px; max-width: 980px; margin: 0 auto;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; letter-spacing: -.01em; }
.brand .logo {
  width: 32px; height: 32px; border-radius: 9px; background: var(--accent); color: var(--accent-ink);
  display: grid; place-items: center; font-weight: 800;
}
.brand small { display: block; font-weight: 500; color: var(--muted); font-size: 12px; margin-top: -2px; }
.nav { display: flex; gap: 4px; flex-wrap: wrap; }
.nav button {
  border: 0; background: transparent; padding: 8px 12px; border-radius: 999px; cursor: pointer; color: var(--text-2);
}
.nav button.on { background: var(--accent-soft); color: var(--accent); font-weight: 600; }

h1 { font-size: 28px; letter-spacing: -.02em; margin: 8px 0 4px; line-height: 1.2; }
h2 { font-size: 18px; margin: 0 0 12px; letter-spacing: -.01em; }
h3 { font-size: 15px; margin: 0 0 8px; }
.sub { color: var(--text-2); margin: 0 0 20px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 20px; box-shadow: var(--shadow);
}
.grid { display: grid; gap: 16px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
@media (max-width: 760px) { .g2, .g3 { grid-template-columns: minmax(0, 1fr); } .g4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.stack > * + * { margin-top: 16px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 1px solid var(--border); background: var(--surface); padding: 10px 18px; border-radius: 999px;
  cursor: pointer; font-weight: 600; transition: transform .05s ease, background .15s;
}
.btn:hover { background: var(--surface-2); }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.big { padding: 14px 26px; font-size: 17px; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn:disabled { opacity: .5; cursor: default; }
.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.spread { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }

.input, textarea.input, select.input {
  width: 100%; padding: 11px 14px; border-radius: 10px; border: 1px solid var(--border); background: var(--surface);
  outline: none;
}
.input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
textarea.input { min-height: 180px; resize: vertical; line-height: 1.6; }
label.lbl { display: block; font-size: 13px; color: var(--text-2); margin-bottom: 4px; font-weight: 600; }

/* Login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login .card { width: 100%; max-width: 420px; }
.who { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 16px 0; }
.who button {
  border: 1px solid var(--border); background: var(--surface); padding: 16px; border-radius: 12px; cursor: pointer; text-align: left;
}
.who button.on { border-color: var(--accent); background: var(--accent-soft); }
.who b { display: block; }
.err { color: var(--bad); font-size: 14px; margin-top: 8px; }

/* Tiles */
.tile { padding: 16px; }
.tile .k { font-size: 12px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.tile .v { font-size: 30px; font-weight: 750; letter-spacing: -.02em; line-height: 1.1; margin-top: 4px; font-variant-numeric: tabular-nums; }
.tile .d { font-size: 13px; color: var(--text-2); margin-top: 4px; }
.pill { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 600; padding: 3px 10px; border-radius: 999px; }
.pill.good { background: var(--good-soft); color: var(--good); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.bad { background: var(--bad-soft); color: var(--bad); }
.pill.neutral { background: var(--surface-2); color: var(--text-2); }

.hero {
  background: linear-gradient(135deg, var(--accent) 0%, #6a55d8 100%); color: #fff; border: 0;
}
:root[data-theme="dark"] .hero { color: #121211; }
.hero .muted { color: rgba(255,255,255,.8); }
.hero h1 { margin-top: 0; }

.progress { height: 10px; background: var(--surface-2); border-radius: 999px; overflow: hidden; }
.progress > div { height: 100%; background: var(--accent); border-radius: 999px; transition: width .4s ease; }
.hero .progress { background: rgba(255,255,255,.25); }
.hero .progress > div { background: #fff; }

/* Activities */
.acts { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 12px; }
.act {
  text-align: left; border: 1px solid var(--border); background: var(--surface); border-radius: var(--radius); padding: 16px;
  cursor: pointer; transition: border-color .15s, transform .1s;
}
.act:hover { border-color: var(--accent); transform: translateY(-1px); }
.act .ic { font-size: 22px; }
.act b { display: block; margin-top: 6px; }
.act span { font-size: 13px; color: var(--text-2); }
.act .tag { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; font-weight: 700; margin-top: 8px; display: block; }

/* Exercise screens */
.exhead { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 12px; }
.timer { font-variant-numeric: tabular-nums; font-weight: 700; color: var(--text-2); }
.timer.low { color: var(--bad); }
.steps { display: flex; gap: 6px; margin-bottom: 16px; }
.steps i { flex: 1; height: 4px; border-radius: 4px; background: var(--surface-2); }
.steps i.done { background: var(--accent); }
.steps i.cur { background: var(--accent); opacity: .45; }

.bigword {
  font-size: 44px; font-weight: 750; text-align: center; letter-spacing: .01em; padding: 36px 8px; word-break: break-word;
}
.choice2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.choice2 .btn { padding: 18px; font-size: 18px; border-radius: 14px; }

.ctest { font-size: 18px; line-height: 2.3; }
.gap { white-space: nowrap; }
.gap input {
  border: 0; border-bottom: 2px solid var(--accent); background: var(--accent-soft); border-radius: 4px 4px 0 0;
  padding: 0 2px; font-size: 18px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; outline: none; margin-left: 1px;
}
.gap input.ok { border-color: var(--good); background: var(--good-soft); }
.gap input.ko { border-color: var(--bad); background: var(--bad-soft); }
.fix { font-size: 12px; color: var(--good); font-weight: 700; margin-left: 2px; vertical-align: super; }

.passage { font-size: 17px; line-height: 1.75; background: var(--surface-2); padding: 16px 18px; border-radius: 12px; }
.opts { display: grid; gap: 8px; margin-top: 8px; }
.opt {
  text-align: left; border: 1px solid var(--border); background: var(--surface); padding: 12px 14px; border-radius: 10px; cursor: pointer;
}
.opt.sel { border-color: var(--accent); background: var(--accent-soft); }
.opt.ok { border-color: var(--good); background: var(--good-soft); }
.opt.ko { border-color: var(--bad); background: var(--bad-soft); }

.flash { text-align: center; padding: 28px 12px; }
.flash .w { font-size: 36px; font-weight: 750; }
.flash .fr { font-size: 20px; margin-top: 12px; }
.flash .ex { font-style: italic; color: var(--text-2); margin-top: 8px; }
.grade4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
@media (max-width: 520px) { .grade4 { grid-template-columns: 1fr 1fr; } .bigword { font-size: 34px; } }

.diff span { padding: 1px 3px; border-radius: 4px; margin-right: 2px; }
.diff .ok { background: var(--good-soft); color: var(--good); }
.diff .ko { background: var(--bad-soft); color: var(--bad); text-decoration: underline; }

.result-score { font-size: 54px; font-weight: 800; letter-spacing: -.03em; line-height: 1; }

/* Charts */
.chart { width: 100%; height: auto; display: block; overflow: visible; }
.chart text { fill: var(--muted); font-size: 11px; }
.chart .gridl { stroke: var(--grid); stroke-width: 1; }
.chart .target { stroke: var(--text-2); stroke-width: 1.5; stroke-dasharray: 5 4; }
.chart .target-sub { stroke: var(--muted); stroke-width: 1; stroke-dasharray: 2 4; }
.legend { display: flex; gap: 16px; flex-wrap: wrap; font-size: 13px; color: var(--text-2); margin-bottom: 8px; }
.legend i { display: inline-block; width: 12px; height: 3px; border-radius: 2px; vertical-align: middle; margin-right: 6px; }
.legend i.dot { width: 9px; height: 9px; border-radius: 50%; }
.legend i.dash { background: repeating-linear-gradient(90deg, var(--text-2) 0 5px, transparent 5px 9px); }
.tip {
  position: absolute; pointer-events: none; background: var(--text); color: var(--bg); font-size: 12px; padding: 6px 9px;
  border-radius: 8px; white-space: nowrap; transform: translate(-50%, -110%); box-shadow: 0 4px 12px rgba(0,0,0,.15);
}
.rel { position: relative; }

.gauge { display: grid; gap: 6px; }
.gauge .track { position: relative; height: 12px; background: var(--surface-2); border-radius: 999px; }
.gauge .fill { position: absolute; left: 0; top: 0; bottom: 0; border-radius: 999px; }
.gauge .mark { position: absolute; top: -4px; bottom: -4px; width: 2px; background: var(--text); border-radius: 2px; }

table.t { width: 100%; border-collapse: collapse; font-size: 14px; }
table.t th { text-align: left; font-size: 12px; color: var(--muted); font-weight: 600; padding: 6px 8px; border-bottom: 1px solid var(--border); }
table.t td { padding: 8px; border-bottom: 1px solid var(--border); font-variant-numeric: tabular-nums; }
.scroll-x { overflow-x: auto; }

.writing-item { border-top: 1px solid var(--border); padding: 14px 0; }
.writing-item:first-child { border-top: 0; }
.writing-text { white-space: pre-wrap; background: var(--surface-2); padding: 12px; border-radius: 10px; font-size: 15px; }
.badge-new { font-size: 11px; background: var(--accent); color: var(--accent-ink); padding: 1px 7px; border-radius: 999px; font-weight: 700; margin-left: 6px; vertical-align: middle; }
.center { text-align: center; }
.mt { margin-top: 16px; }
.mt-s { margin-top: 8px; }
.note { font-size: 13px; color: var(--text-2); background: var(--surface-2); padding: 10px 12px; border-radius: 10px; }
@media (max-width: 600px) {
  .chart text { font-size: 22px; }
  .topbar { flex-direction: column; align-items: flex-start; gap: 6px; }
  .nav button { padding: 6px 10px; font-size: 14px; }
  h1 { font-size: 24px; }
  .card { padding: 16px; }
}
