:root {
  --bg: #f2f4f7;
  --card: #ffffff;
  --ink: #101c2a;
  --muted: #5b6675;
  --line: rgba(16, 28, 42, 0.09);
  --field: #eef1f5;
  --accent: #1f4fd8;
  --accent-soft: #e6ecfb;
  --ok: #1e7a4f;
  --ok-soft: #e3f3ea;
  --danger: #b3261e;
  --shadow: 0 1px 2px rgba(16, 28, 42, 0.06), 0 6px 20px rgba(16, 28, 42, 0.06);
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 14px/1.5 "Segoe UI", system-ui, -apple-system, sans-serif;
}
h1 { font-size: 26px; line-height: 1.2; margin: 0 0 4px; font-weight: 650; }
h2 { font-size: 20px; margin: 0 0 12px; font-weight: 650; }
h3 { font-size: 16px; margin: 0 0 8px; font-weight: 650; }
p { margin: 0 0 10px; }
a { color: var(--accent); }
.muted { color: var(--muted); }
.small { font-size: 13px; }
[hidden] { display: none !important; }

.shell { display: grid; grid-template-columns: 208px minmax(0, 1fr); min-height: 100vh; }
.nav {
  position: sticky; top: 0; align-self: start; height: 100vh;
  padding: 24px 12px; display: flex; flex-direction: column; gap: 2px;
  background: var(--card); border-right: 1px solid var(--line);
}
.brand { font-weight: 700; font-size: 16px; padding: 0 12px 20px; }
.brand span { font-weight: 400; color: var(--muted); }
.nav a {
  padding: 10px 12px; border-radius: 12px; color: var(--ink);
  text-decoration: none; font-size: 14px;
}
.nav a:hover { background: var(--field); }
.nav a.active { background: var(--ink); color: #fff; }

main {
  padding-block: 32px; max-width: 1180px; width: 100%;
  padding-left: max(32px, env(safe-area-inset-left, 0px)); padding-right: max(32px, env(safe-area-inset-right, 0px));
}
.head { margin-bottom: 20px; }
.grid { display: grid; gap: 16px; }
.grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.card {
  background: var(--card); border-radius: 20px; padding: 20px;
  box-shadow: var(--shadow);
}
.card + .card, .grid + .card, .card + .grid, .grid + .grid { margin-top: 16px; }
.grid > .card { margin-top: 0; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.stack > * + * { margin-top: 10px; }

.big { font-size: 40px; font-weight: 650; line-height: 1.1; font-variant-numeric: tabular-nums; }
.stat { font-size: 26px; font-weight: 650; font-variant-numeric: tabular-nums; }

button, .btn {
  font: inherit; cursor: pointer; border: 0; border-radius: 12px;
  height: 40px; padding: 0 16px; background: var(--field); color: var(--ink);
  box-shadow: 0 1px 2px rgba(16, 28, 42, 0.08);
  transition: transform 150ms ease-out, opacity 150ms ease-out;
}
button:hover { opacity: 0.88; }
button:active { transform: scale(0.98); }
button.dark { background: var(--ink); color: #fff; }
button.text { background: none; box-shadow: none; color: var(--accent); padding: 0 6px; }
button.danger { background: none; box-shadow: none; color: var(--danger); padding: 0 6px; }
button.sm { height: 32px; padding: 0 12px; font-size: 13px; }
button:disabled { opacity: 0.45; cursor: default; }

input, select, textarea {
  font: inherit; color: var(--ink); background: var(--field);
  border: 0; border-radius: 12px; padding: 0 12px; height: 40px; width: 100%;
  outline: none;
}
textarea { padding: 12px; height: auto; resize: vertical; line-height: 1.6; }
input:focus, select:focus, textarea:focus { box-shadow: 0 0 0 2px var(--accent); }
label.field { display: block; }
label.field > span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }
.inline { width: auto; }

.list { list-style: none; margin: 0; padding: 0; }
.list li { padding: 12px 0; border-top: 1px solid var(--line); }
.list li:first-child { border-top: 0; padding-top: 0; }
.item-btn {
  display: block; width: 100%; height: auto; text-align: left; padding: 12px 14px;
  background: var(--field); box-shadow: none; line-height: 1.4;
}
.item-btn + .item-btn { margin-top: 8px; }
.item-btn b { display: block; font-weight: 600; }

.check { display: flex; gap: 10px; align-items: flex-start; padding: 6px 0; cursor: pointer; }
.check input { width: 18px; height: 18px; margin-top: 2px; flex: none; accent-color: var(--ink); }

.tag {
  display: inline-flex; align-items: center; height: 24px; padding: 0 8px;
  border-radius: 8px; background: var(--field); font-size: 12px; color: var(--muted);
}
.tag.ok { background: var(--ok-soft); color: var(--ok); }
.tag.blue { background: var(--accent-soft); color: var(--accent); }

/* Редактор письма — как на экзамене: задание слева, ответ справа */
.exam-bar {
  position: sticky; top: 0; z-index: 2; background: var(--ink); color: #fff;
  border-radius: 16px; padding: 10px 16px; margin-bottom: 16px;
  display: flex; gap: 16px; align-items: center; flex-wrap: wrap;
}
.exam-bar .clock { font-size: 20px; font-weight: 650; font-variant-numeric: tabular-nums; min-width: 72px; }
.exam-bar .clock.over { color: #ff9a92; }
.exam-bar .spacer { flex: 1; }
.exam-bar button { background: rgba(255, 255, 255, 0.14); color: #fff; box-shadow: none; }
.exam-bar button.light { background: #fff; color: var(--ink); }
.exam { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 16px; align-items: start; }
.exam textarea.answer { min-height: 520px; font-size: 16px; background: #fff; box-shadow: var(--shadow); border-radius: 20px; padding: 20px; }
.prompt { font-size: 16px; line-height: 1.6; white-space: pre-wrap; }
.essay { white-space: pre-wrap; font-size: 16px; line-height: 1.7; }

/* Графики */
.chart svg { width: 100%; height: auto; display: block; }
.chart .legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 13px; margin-top: 8px; }
.chart .legend i { display: inline-block; width: 18px; height: 4px; border-radius: 2px; vertical-align: middle; margin-right: 6px; }
table.data { border-collapse: collapse; width: 100%; font-size: 14px; }
table.data th, table.data td { padding: 8px 10px; border-bottom: 1px solid var(--line); text-align: right; }
table.data th:first-child, table.data td:first-child { text-align: left; }
table.data th { font-weight: 600; }
.flow { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.flow .step { background: var(--field); border-radius: 12px; padding: 10px 12px; max-width: 190px; font-size: 13px; }
.flow .arrow { color: var(--muted); }

/* Бланк ответов Listening и Reading */
.answers { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px 20px; }
.ans { display: flex; align-items: center; gap: 10px; }
.ans > span { width: 26px; text-align: right; color: var(--muted); font-variant-numeric: tabular-nums; flex: none; }
.ans input:disabled { opacity: 0.55; }
.mk { display: flex; align-items: center; gap: 12px; padding: 8px 0 !important; }
.mk .num { width: 26px; text-align: right; color: var(--muted); font-variant-numeric: tabular-nums; flex: none; }
.mk .mine { flex: 1; min-width: 0; font-size: 16px; overflow-wrap: anywhere; }
select.sm { height: 32px; font-size: 13px; }
button.on-ok { background: var(--ok); color: #fff; }
button.on-bad { background: var(--danger); color: #fff; }

/* Карточки */
.grid.four { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.flash { max-width: 640px; margin: 0 auto; text-align: center; padding: 36px 28px; }
.flash .front { font-size: 26px; font-weight: 650; line-height: 1.25; margin: 14px 0 22px; }
.flash .back { font-size: 26px; font-weight: 650; line-height: 1.25; color: var(--accent); margin: 6px 0 10px; }
.flash .example { font-size: 16px; color: var(--muted); margin-bottom: 18px; }
.flash input { text-align: center; font-size: 16px; height: 48px; }
.flash .row { justify-content: center; margin-top: 18px; }
.flash button { height: 48px; padding: 0 22px; }

/* Слушать и читать */
.btn-link {
  display: inline-flex; align-items: center; height: 40px; padding: 0 16px; border-radius: 12px;
  background: var(--ink); color: #fff; text-decoration: none; box-shadow: 0 1px 2px rgba(16, 28, 42, 0.08);
}
ol.steps { margin: 0; padding-left: 20px; }
ol.steps li { padding: 4px 0; }

/* Речь */
.cue { font-size: 16px; line-height: 1.6; }
.cue ul { margin: 8px 0 0; padding-left: 20px; }
.phase { text-align: center; padding: 28px 16px; }
.phase .big { margin: 8px 0 16px; }
audio { width: 100%; margin-top: 8px; }

/* Окно подтверждения — только для предупреждений */
.ask {
  position: fixed; inset: 0; z-index: 20; background: rgba(16, 28, 42, 0.45);
  display: flex; align-items: center; justify-content: center;
  padding: 16px max(16px, env(safe-area-inset-right, 0px)) 16px max(16px, env(safe-area-inset-left, 0px));
}
.ask-box { background: var(--card); border-radius: 20px; padding: 22px; max-width: 400px; width: 100%; box-shadow: 0 12px 40px rgba(16, 28, 42, 0.3); }
.ask-box p { font-size: 16px; margin-bottom: 18px; }
.ask-box .row { justify-content: flex-end; }

.toast {
  position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%);
  background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 12px;
  box-shadow: var(--shadow); z-index: 10;
}

@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
  .nav {
    position: sticky; height: auto; flex-direction: row; overflow-x: auto;
    padding-block: 8px; padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px));
    top: env(safe-area-inset-top, 0px); border-right: 0; border-bottom: 1px solid var(--line); z-index: 3;
  }
  body::before { content: ""; position: fixed; inset: 0 0 auto; height: env(safe-area-inset-top, 0px); z-index: 10; background: var(--card); }
  input, select, textarea { font-size: 16px; } /* меньше 16 — телефон приближает страницу при вводе */
  .brand { display: none; }
  .nav a { white-space: nowrap; }
  .nav { scrollbar-width: none; } /* полоса прокрутки под вкладками не нужна — они листаются пальцем */
  .nav::-webkit-scrollbar { display: none; }
  main { padding-block: 16px; padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px)); }
  .grid.two, .grid.three, .exam { grid-template-columns: 1fr; }
  .grid.four { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .exam-bar { top: calc(env(safe-area-inset-top, 0px) + 60px); }
  .exam textarea.answer { min-height: 360px; }
}
