:root {
  color-scheme: dark;
  --bg: #121a21;
  --panel: #141d25;
  --well: #101820;
  --edge: #2b3945;
  --edge-hover: #34506a;
  --ink: #e7eef3;
  --muted: #a2b1bd;
  --blue: #8fd8ff;
  --amber: #f4a63a;
  --amber-light: #ffc76b;
  --rose: #e86a85;
  --sans: 'IBM Plex Sans', Helvetica, Arial, sans-serif;
  --mono: 'IBM Plex Mono', ui-monospace, Consolas, monospace;
}

* { box-sizing: border-box; }
html { scrollbar-gutter: stable; }
body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font: 400 1rem/1.5 var(--sans);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--blue); text-decoration: none; }
a:hover { color: var(--amber-light); }
button, input, select { font: inherit; }
button, input, select, a { -webkit-tap-highlight-color: transparent; }
button { cursor: pointer; }
button:focus-visible, input:focus-visible, select:focus-visible, a:focus-visible {
  outline: 2px solid var(--blue);
  outline-offset: 3px;
}
[hidden] { display: none !important; }

.page-shell { max-width: 1228px; margin: 0 auto; padding: 24px 24px 32px; }
.board-header .lang { gap: 4px; }
.board-header .lang button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 40px;
  min-height: 44px;
  padding: 6px;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: var(--blue);
  font: 400 .875rem var(--mono);
}
.board-header .lang button[aria-pressed='true'] { color: var(--ink); }
.board-header .lang button:hover { color: var(--amber-light); background: #8fd8ff0a; }
.board-title { padding-top: 8px; }
.board-intro { margin: 10px 0 0; color: var(--muted); max-width: 760px; }
.board-title .board-intro { flex-basis: 100%; }

.app-grid {
  display: grid;
  grid-template-columns: minmax(280px, 326px) minmax(0, 1fr);
  align-items: start;
  gap: 16px;
  margin-top: 24px;
}
.panel { min-width: 0; background: var(--panel); border: 1px solid var(--edge); border-radius: 10px; padding: 20px; }
.panel-head { min-width: 0; }
.panel-kicker { margin: 0 0 6px; color: var(--blue); font: 400 .75rem/1.5 var(--mono); letter-spacing: .15em; text-transform: uppercase; }
h2, h3 { margin: 0; font-weight: 500; letter-spacing: -.02em; line-height: 1.3; }
h2 { font-size: 1.25rem; }
h3 { font-size: 1rem; }

.settings-form { display: grid; gap: 18px; margin-top: 22px; }
.range-block { display: grid; gap: 10px; padding-bottom: 17px; border-bottom: 1px solid var(--edge); }
.range-block-head p { margin: 0; font-size: .9375rem; font-weight: 500; }
.range-block-head span { display: block; color: var(--muted); font-size: .875rem; line-height: 1.5; margin-top: 4px; }
.range-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.field { display: grid; min-width: 0; gap: 7px; }
.field > span { color: var(--muted); font-size: .875rem; }
.field input, .field select, #answer-input {
  min-width: 0;
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  border: 1px solid var(--edge);
  border-radius: 6px;
  background: var(--well);
  color: var(--ink);
  font-family: var(--mono);
}
.field input:hover, .field select:hover { border-color: var(--edge-hover); }
.field select {
  appearance: none;
  padding-right: 36px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='m1 1 5 5 5-5' fill='none' stroke='%238fd8ff' stroke-width='1.5'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 13px center;
}
.range-note { margin: 0; color: var(--muted); font-size: .875rem; line-height: 1.6; }
.field-hint { grid-column: 1 / -1; margin: 0; color: var(--muted); font-size: .875rem; line-height: 1.5; }
.preset-row { display: flex; flex-wrap: wrap; gap: 7px; }
.preset, .secondary-button, .primary-button {
  min-height: 44px;
  padding: 9px 14px;
  border: 1px solid var(--edge);
  border-radius: 999px;
  background: transparent;
  color: var(--blue);
  font: 400 .875rem/1.4 var(--sans);
  transition: background .15s, border-color .15s;
}
.preset { flex: 1 1 auto; padding: 8px 12px; }
.preset:hover, .secondary-button:hover { background: #8fd8ff0a; border-color: var(--edge-hover); }
.primary-button { color: var(--amber-light); border-color: var(--amber); background: #f4a63a0c; font-weight: 500; }
.primary-button:hover { background: #f4a63a1f; border-color: var(--amber-light); }
button:disabled { opacity: .45; cursor: default; }
.primary-button:disabled:hover { background: #f4a63a0c; border-color: var(--amber); }
.settings-form > .primary-button { width: 100%; }

.trainer-top { display: flex; justify-content: space-between; align-items: flex-start; flex-wrap: wrap; gap: 14px; }
.trainer-top .secondary-button { flex-shrink: 0; }
body[data-state='idle'] #restart-button { border-color: var(--amber); color: var(--amber-light); background: #f4a63a0c; }
.stats-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 9px; margin-top: 22px; }
.stat-card { min-width: 0; border: 1px solid var(--edge); border-radius: 8px; background: var(--well); padding: 11px 12px; }
.stat-label { display: block; color: var(--muted); font-size: .875rem; }
.stat-card strong { display: block; margin-top: 5px; color: var(--blue); font: 500 clamp(1.375rem, 2.8vw, 1.75rem)/1.2 var(--mono); }
.stat-card:last-child strong { color: var(--amber-light); }
.progress-meta { display: flex; justify-content: space-between; flex-wrap: wrap; gap: 6px 16px; margin: 20px 0 9px; color: var(--muted); font-size: .875rem; }
.progress-track { height: 4px; background: var(--edge); border-radius: 2px; overflow: hidden; }
.progress-fill { height: 100%; width: 0; border-radius: inherit; background: var(--blue); transition: width .2s ease; }

.question-card { display: flex; flex-direction: column; gap: 18px; margin-top: 18px; padding: 22px; background: var(--well); border: 1px solid var(--edge); border-radius: 10px; }
.question-label { margin: 0; color: var(--muted); font-size: .875rem; }
.question-value { display: flex; align-items: center; min-height: 90px; color: var(--ink); font: 400 clamp(2.5rem, 5.5vw, 4rem)/1.2 var(--mono); letter-spacing: -.05em; overflow-wrap: anywhere; }
body[data-state='idle'] .question-value, body[data-state='done'] .question-value, .question-value.is-message { font: 400 clamp(1.5rem, 3vw, 2rem)/1.3 var(--sans); letter-spacing: -.03em; }
.answer-form { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 12px; }
.answer-entry { display: grid; grid-template-columns: minmax(0, 1fr) 44px; gap: 8px; min-width: 0; }
.sign-button { border: 1px solid var(--edge); border-radius: 6px; color: var(--blue); background: transparent; font: 400 1.375rem var(--mono); }
.sign-button:hover { border-color: var(--edge-hover); background: #8fd8ff0a; }
#answer-input { min-height: 52px; color: var(--amber-light); font-size: 1.375rem; }
#answer-input::placeholder { color: var(--muted); font: 400 .9375rem var(--sans); letter-spacing: 0; opacity: 1; }
#answer-input:disabled { opacity: .55; }
.answer-form .primary-button { padding: 11px 20px; }
.feedback-text { margin: 0; min-height: 48px; color: var(--muted); line-height: 1.5; }
.feedback-text.correct { color: var(--blue); }
.feedback-text.incorrect { color: var(--rose); }
.feedback-text.info { color: var(--muted); }

.summary-grid { display: grid; grid-template-columns: 1fr; gap: 20px; margin-top: 24px; }
.summary-card { min-width: 0; border-top: 1px solid var(--edge); padding-top: 18px; }
.summary-card h3 { color: var(--ink); }
.summary-card p { margin: 9px 0 0; color: var(--muted); line-height: 1.65; }
.mistakes-list { margin: 9px 0 0; padding-left: 19px; color: var(--muted); font-size: .9375rem; line-height: 1.7; }
.mistakes-list li + li { margin-top: 9px; }
.review-badge { margin-right: 8px; color: var(--rose); font-weight: 500; }
.review-item.slow .review-badge { color: var(--amber-light); }
.board-footer { display: flex; justify-content: space-between; flex-wrap: wrap; gap: 8px 20px; margin-top: 28px; padding-top: 18px; border-top: 1px solid var(--edge); color: var(--muted); font-size: .8125rem; }
.board-footer > :first-child { font-family: var(--mono); }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }

@media (max-width: 920px) {
  .app-grid { grid-template-columns: minmax(250px, 290px) minmax(0, 1fr); gap: 12px; }
  .panel { padding: 16px; }
  .stats-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .answer-form { grid-template-columns: 1fr; }
  .question-card { padding: 17px; }
}
@media (max-width: 700px) {
  .page-shell { padding: 16px 16px 28px; }
  .app-grid { grid-template-columns: 1fr; margin-top: 20px; gap: 16px; }
  .settings-form { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px 14px; }
  .range-block, .range-note, .preset-row, .settings-form > .primary-button { grid-column: 1 / -1; }
  .range-block-head span { max-width: 42ch; }
  .stats-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .stat-card { padding: 10px 8px; }
  .stat-label { font-size: .8125rem; }
  .question-value { min-height: 76px; font-size: clamp(2rem, 9vw, 3rem); }
  .answer-form { grid-template-columns: 1fr; }
  .answer-form .primary-button { padding: 10px 14px; }
}
@media (max-width: 380px) {
  .page-shell { padding-inline: 12px; }
  .panel { padding: 14px; }
  .stats-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .answer-form { grid-template-columns: 1fr; }
  .settings-form { grid-template-columns: 1fr; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
}
