:root {
  --bg: #f6f5f1;
  --surface: #ffffff;
  --surface-2: #efede6;
  --text: #1f2328;
  --muted: #5f6670;
  --line: #dcd8cd;
  --accent: #1f5f8b;
  --accent-soft: #e3eef6;
  --ok: #1d7a46;
  --ok-soft: #e2f3e8;
  --bad: #b3261e;
  --bad-soft: #f9e3e1;
  --warn: #8a5a00;
  --warn-soft: #fbf0d9;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(0, 0, 0, .06), 0 2px 8px rgba(0, 0, 0, .04);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --serif: Georgia, "Times New Roman", serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15181c;
    --surface: #1d2126;
    --surface-2: #262b31;
    --text: #e6e8eb;
    --muted: #9aa3ad;
    --line: #353b43;
    --accent: #6fb3e0;
    --accent-soft: #1f3445;
    --ok: #5fcf8d;
    --ok-soft: #1c3427;
    --bad: #f08a80;
    --bad-soft: #3d2120;
    --warn: #e6b450;
    --warn-soft: #3a2f17;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.55 var(--font);
}
a { color: var(--accent); }
h1, h2, h3, h4 { line-height: 1.25; margin: 0 0 .5em; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.3rem; }
h3 { font-size: 1.08rem; }
p { margin: 0 0 .8em; }
button, input, select, textarea { font: inherit; color: inherit; }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 12px;
  padding: 8px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; text-decoration: none; color: var(--text); white-space: nowrap; }
.brand span { color: var(--accent); font-weight: 600; }
.topbar-mid { flex: 1; min-width: 0; display: flex; align-items: center; gap: 10px; overflow: hidden; }
.topbar-mid .crumb { color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-right { display: flex; align-items: center; gap: 8px; }
.icon-btn {
  border: 1px solid var(--line); background: var(--surface); border-radius: 8px;
  width: 36px; height: 36px; font-size: 18px; cursor: pointer;
}
.timer {
  font-variant-numeric: tabular-nums; font-weight: 600;
  padding: 4px 10px; border-radius: 999px; background: var(--accent-soft); color: var(--accent);
}
.timer.low { background: var(--bad-soft); color: var(--bad); }

/* ---------- layout ---------- */
.app { max-width: 1240px; margin: 0 auto; padding: 20px 16px 80px; }
.loading { color: var(--muted); }

.test-layout { display: grid; grid-template-columns: 230px minmax(0, 1fr); gap: 24px; align-items: start; }
.sidenav { position: sticky; top: 68px; max-height: calc(100vh - 80px); overflow: auto; }
.sidenav .group { margin-bottom: 10px; }
.sidenav .group-title { font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 0 0 4px 8px; display: flex; justify-content: space-between; }
.sidenav a {
  display: flex; justify-content: space-between; gap: 6px;
  padding: 4px 10px; border-radius: 8px; text-decoration: none; color: var(--text); font-size: .93rem;
}
.sidenav a:hover { background: var(--surface-2); }
.sidenav a.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.sidenav .badge { font-size: .78rem; color: var(--muted); font-weight: 500; }
.sidenav .badge.done { color: var(--ok); }
.mobile-nav { display: none; margin-bottom: 14px; }
.mobile-nav select { width: 100%; padding: 8px; border-radius: 8px; border: 1px solid var(--line); background: var(--surface); }

@media (max-width: 860px) {
  .test-layout { grid-template-columns: 1fr; }
  .sidenav { display: none; }
  .mobile-nav { display: block; }
  .topbar-mid .crumb { display: none; }
}

/* ---------- home ---------- */
.hero { margin-bottom: 22px; }
.hero p { color: var(--muted); max-width: 70ch; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(270px, 1fr)); gap: 14px; }
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 8px;
  text-decoration: none; color: var(--text);
}
.card:hover { border-color: var(--accent); }
.card .num { font-size: .8rem; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.card h3 { margin: 0; }
.card .sector { color: var(--accent); font-weight: 600; font-size: .95rem; }
.card .summary { color: var(--muted); font-size: .92rem; flex: 1; }
.progress { height: 6px; border-radius: 99px; background: var(--surface-2); overflow: hidden; }
.progress > span { display: block; height: 100%; background: var(--accent); }
.card .meta { font-size: .85rem; color: var(--muted); display: flex; justify-content: space-between; }

.info-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 12px; margin: 26px 0 8px; }
.info-grid .box { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; font-size: .92rem; }
.info-grid .box h4 { margin-bottom: 4px; }
.info-grid .box p { margin: 0; color: var(--muted); }

/* ---------- part view ---------- */
.part-head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 8px 16px; margin-bottom: 6px; }
.part-head .tag { font-size: .85rem; color: var(--muted); }
.instruction {
  background: var(--accent-soft); border-left: 4px solid var(--accent);
  padding: 10px 14px; border-radius: 0 var(--radius) var(--radius) 0; margin: 8px 0 18px;
}
.instruction p:last-child { margin: 0; }

.split { display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr); gap: 20px; align-items: start; }
.split > .sticky { position: sticky; top: 68px; max-height: calc(100vh - 84px); overflow: auto; }
@media (max-width: 1000px) {
  .split { grid-template-columns: 1fr; }
  .split > .sticky { position: static; max-height: none; }
}

.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow); margin-bottom: 16px; }
.panel h3 { margin-bottom: .4em; }
.panel.muted { background: var(--surface-2); box-shadow: none; }

.doc { font-family: var(--serif); font-size: 1.02rem; }
.doc h3 { font-family: var(--font); }
.doc .doc-meta { font-family: var(--font); font-size: .9rem; display: grid; grid-template-columns: max-content 1fr; gap: 2px 12px; margin: 0 0 12px; color: var(--muted); }
.doc .doc-meta dt { font-weight: 600; }
.doc .doc-meta dd { margin: 0; }
.doc .sec { margin-bottom: 12px; }
.doc .sec h4 { font-family: var(--font); font-size: .98rem; margin-bottom: 4px; }

.textlist { display: grid; gap: 10px; }
.textlist .item { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 14px; }
.textlist .item .key { display: inline-grid; place-items: center; width: 26px; height: 26px; border-radius: 50%; background: var(--surface-2); font-weight: 700; margin-right: 8px; font-size: .9rem; }
.textlist .item h4 { display: inline; font-size: 1rem; }
.textlist .item p { margin: 6px 0 0; }
.post .author { font-weight: 600; color: var(--accent); }

.email { font-family: var(--font); }
.email .hdr { display: grid; grid-template-columns: max-content 1fr; gap: 2px 10px; font-size: .9rem; padding-bottom: 8px; margin-bottom: 10px; border-bottom: 1px solid var(--line); }
.email .hdr dt { color: var(--muted); }
.email .hdr dd { margin: 0; }
.email .body { white-space: pre-wrap; }

/* ---------- tasks ---------- */
.task { padding: 12px 0; border-top: 1px solid var(--line); }
.task:first-child { border-top: 0; padding-top: 0; }
.task .q { display: flex; gap: 10px; margin-bottom: 6px; }
.task .nr {
  flex: none; display: inline-grid; place-items: center; min-width: 30px; height: 30px; padding: 0 6px;
  border-radius: 8px; background: var(--surface-2); font-weight: 700; font-size: .9rem;
}
.task.correct .nr { background: var(--ok-soft); color: var(--ok); }
.task.wrong .nr { background: var(--bad-soft); color: var(--bad); }
.options { display: grid; gap: 4px; margin-left: 40px; }
.opt {
  display: flex; gap: 8px; align-items: flex-start; padding: 6px 10px; border-radius: 8px;
  border: 1px solid transparent; cursor: pointer;
}
.opt:hover { background: var(--surface-2); }
.opt input { margin-top: 5px; }
.opt .letter { font-weight: 700; min-width: 1.2em; }
.opt.is-right { background: var(--ok-soft); border-color: var(--ok); }
.opt.is-wrong { background: var(--bad-soft); border-color: var(--bad); }
.rf { display: flex; gap: 8px; margin-left: 40px; flex-wrap: wrap; }
.rf .opt { border: 1px solid var(--line); }
.match-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.match-row select, .gap-select, .field input, .field select, .field textarea, textarea.write, input.line {
  padding: 7px 10px; border-radius: 8px; border: 1px solid var(--line); background: var(--surface);
}
.match-row select { min-width: 90px; }
.explain { margin: 8px 0 0 40px; padding: 8px 12px; border-radius: 8px; background: var(--surface-2); font-size: .93rem; }
.explain .sol { font-weight: 700; }
.correct .explain { border-left: 3px solid var(--ok); }
.wrong .explain { border-left: 3px solid var(--bad); }

.gaptext { white-space: pre-wrap; font-family: var(--serif); font-size: 1.03rem; line-height: 2.1; }
.gap { display: inline-flex; align-items: center; gap: 4px; vertical-align: baseline; }
.gap .gnr { font-family: var(--font); font-size: .75rem; font-weight: 700; color: var(--muted); }
.gap-select { font-family: var(--font); font-size: .9rem; padding: 2px 6px; max-width: 260px; }
.gap.correct .gap-select { border-color: var(--ok); background: var(--ok-soft); }
.gap.wrong .gap-select { border-color: var(--bad); background: var(--bad-soft); }
.wordbox { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 6px; }
.wordbox span { padding: 6px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); font-size: .92rem; }
.wordbox b { margin-right: 6px; }

.actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: 16px 0; }
.btn {
  border: 1px solid var(--line); background: var(--surface); border-radius: 8px; padding: 8px 14px; cursor: pointer;
  font-weight: 500;
}
.btn:hover { border-color: var(--accent); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
@media (prefers-color-scheme: dark) { .btn-primary { color: #0e1a24; } }
.btn-danger { color: var(--bad); }
.btn-small { padding: 4px 10px; font-size: .9rem; }
.scoreline { font-weight: 600; }
.scoreline.good { color: var(--ok); }
.scoreline.bad { color: var(--bad); }
.note { font-size: .9rem; color: var(--muted); }
.warnbox { background: var(--warn-soft); color: var(--warn); border-radius: 8px; padding: 8px 12px; font-size: .92rem; }

/* ---------- audio player ---------- */
.player { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; padding: 10px 14px; border-radius: var(--radius); background: var(--surface-2); margin-bottom: 12px; }
.player .status { font-size: .9rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.player .bar { flex: 1 1 120px; height: 6px; border-radius: 99px; background: var(--line); overflow: hidden; min-width: 80px; }
.player .bar > span { display: block; height: 100%; width: 0; background: var(--accent); transition: width .2s; }
.transcript { margin-top: 8px; }
.transcript .line { margin: 0 0 6px; }
.transcript .line.current { background: var(--accent-soft); border-radius: 6px; }
.transcript .sp { font-weight: 600; }
.slides { display: flex; flex-wrap: wrap; gap: 6px; margin: 6px 0 12px; }
.slides span { padding: 6px 10px; border-radius: 8px; border: 1px dashed var(--line); font-size: .9rem; }

/* ---------- writing ---------- */
textarea.write { width: 100%; min-height: 280px; line-height: 1.5; resize: vertical; }
.wordcount { font-size: .85rem; color: var(--muted); }
.checklist { margin: 0; padding-left: 1.2em; }
.checklist li { margin-bottom: 3px; }
details { margin: 10px 0; }
details > summary { cursor: pointer; font-weight: 600; color: var(--accent); }
.model { white-space: pre-wrap; background: var(--surface-2); padding: 12px 14px; border-radius: 8px; margin-top: 8px; font-family: var(--serif); }

.feedback { border: 1px solid var(--accent); border-radius: var(--radius); padding: 14px 16px; margin-top: 14px; background: var(--surface); }
.feedback .crit { display: grid; grid-template-columns: 1fr auto; gap: 2px 10px; padding: 6px 0; border-bottom: 1px solid var(--line); }
.feedback .crit:last-of-type { border-bottom: 0; }
.feedback .crit .pts { font-weight: 700; font-variant-numeric: tabular-nums; }
.feedback .crit .cmt { grid-column: 1 / -1; color: var(--muted); font-size: .93rem; }
.feedback table { width: 100%; border-collapse: collapse; font-size: .93rem; margin-top: 6px; }
.feedback td, .feedback th { text-align: left; vertical-align: top; padding: 6px; border-bottom: 1px solid var(--line); }
.feedback .orig { color: var(--bad); text-decoration: line-through; text-decoration-thickness: 1px; }
.feedback .corr { color: var(--ok); font-weight: 600; }
.feedback .total { font-size: 1.2rem; font-weight: 700; }
.spinner { display: inline-block; width: 16px; height: 16px; border: 2px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin 1s linear infinite; vertical-align: -3px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- phone note ---------- */
.phonenote { display: grid; gap: 10px; }
.phonenote .row { display: grid; grid-template-columns: 150px 1fr; gap: 10px; align-items: center; }
.phonenote .row > label { font-weight: 600; font-size: .93rem; }
.phonenote .infos { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.phonenote input.line { width: 100%; }
.phonenote .inline { display: flex; gap: 8px; }
.phonenote .inline select { flex: none; }
.phonenote .res { font-size: .85rem; margin-top: 2px; }
@media (max-width: 600px) {
  .phonenote .row { grid-template-columns: 1fr; }
  .phonenote .infos { grid-template-columns: 1fr; }
}

/* ---------- speaking ---------- */
.topic-list { display: grid; gap: 8px; }
.topic-list label { display: flex; gap: 10px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); cursor: pointer; }
.topic-list label.sel { border-color: var(--accent); background: var(--accent-soft); }
.phrases { columns: 2 260px; padding-left: 1.1em; margin: 0; }
.phrases li { break-inside: avoid; margin-bottom: 3px; }
.rec { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.rec .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--bad); animation: blink 1s infinite; }
@keyframes blink { 50% { opacity: .2; } }
audio { max-width: 100%; }

/* ---------- results ---------- */
table.results { width: 100%; border-collapse: collapse; background: var(--surface); border-radius: var(--radius); overflow: hidden; }
table.results th, table.results td { padding: 10px 12px; border-bottom: 1px solid var(--line); text-align: left; }
table.results td.num { text-align: right; font-variant-numeric: tabular-nums; }
table.results tr.total td { font-weight: 700; }

/* ---------- dialog ---------- */
.dialog { border: 1px solid var(--line); border-radius: 14px; padding: 0; width: min(560px, calc(100vw - 32px)); background: var(--surface); color: var(--text); }
.dialog::backdrop { background: rgba(0, 0, 0, .4); }
.dialog-body { padding: 20px 22px; max-height: 85vh; overflow: auto; }
.dialog section { margin: 16px 0; padding-top: 12px; border-top: 1px solid var(--line); }
.hint { font-size: .88rem; color: var(--muted); }
.field { display: grid; gap: 4px; margin: 10px 0; font-weight: 500; font-size: .95rem; }
.field input[type=password], .field input[type=text], .field select { width: 100%; }
.dialog-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 18px; }

.mode-switch { display: inline-flex; border: 1px solid var(--line); border-radius: 999px; overflow: hidden; flex: none; }
.mode-switch button { border: 0; background: transparent; padding: 4px 12px; cursor: pointer; font-size: .88rem; }
.mode-switch button.on { background: var(--accent); color: #fff; }
@media (prefers-color-scheme: dark) { .mode-switch button.on { color: #0e1a24; } }
