/* ==========================================================================
   МатоМолния — дизайн-система в тёплой палитре Claude
   ========================================================================== */

:root {
  --bg: #f5f1eb;
  --surface: #fdfcfa;
  --panel: #efe9e1;
  --panel-strong: #e6dfd5;
  --text: #2b2723;
  --text-soft: #6e6459;
  --text-faint: #9b9086;
  --border: #e0d8cd;
  --accent: #d97757;
  --accent-hover: #c5613f;
  --accent-soft: rgba(217, 119, 87, 0.12);
  --accent-ring: rgba(217, 119, 87, 0.3);
  --ok: #3d8f6b;
  --ok-soft: rgba(61, 143, 107, 0.14);
  --bad: #c7503f;
  --bad-soft: rgba(199, 80, 63, 0.14);
  --shadow: 0 1px 2px rgba(43, 39, 35, 0.06);
  --shadow-lift: 0 6px 20px rgba(43, 39, 35, 0.08);
  --radius: 12px;
  --radius-lg: 20px;
  --ease: cubic-bezier(0.25, 1, 0.5, 1);
  --serif: ui-serif, Georgia, "Times New Roman", serif;
  --sans: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto,
    "Helvetica Neue", sans-serif;
}

[data-theme='dark'] {
  --bg: #1f1d1b;
  --surface: #2a2724;
  --panel: #332f2b;
  --panel-strong: #3d3833;
  --text: #f2eee8;
  --text-soft: #a8a099;
  --text-faint: #7d746c;
  --border: #3d3833;
  --accent: #e08b6b;
  --accent-hover: #eb9c7d;
  --accent-soft: rgba(224, 139, 107, 0.16);
  --accent-ring: rgba(224, 139, 107, 0.35);
  --ok: #59a883;
  --ok-soft: rgba(89, 168, 131, 0.16);
  --bad: #dd6b58;
  --bad-soft: rgba(221, 107, 88, 0.16);
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-lift: 0 8px 24px rgba(0, 0, 0, 0.35);
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  height: 100%;
  margin: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.5;
  overscroll-behavior: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-font-smoothing: antialiased;
}

button {
  font: inherit;
  color: inherit;
  border: none;
  background: none;
  cursor: pointer;
}

/* ---------------------------------------------------------------- Каркас */

.app {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  max-width: 560px;
  margin: 0 auto;
  padding: calc(env(safe-area-inset-top) + 10px) calc(env(safe-area-inset-left) + 16px)
    calc(env(safe-area-inset-bottom) + 14px) calc(env(safe-area-inset-right) + 16px);
}

.topbar {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  margin-bottom: 14px;
}

.topbar__title {
  flex: 1;
  font-family: var(--serif);
  font-size: 19px;
  font-weight: 600;
  letter-spacing: -0.01em;
  margin: 0;
}

.icon-btn {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: 999px;
  background: var(--panel);
  color: var(--text-soft);
  font-size: 17px;
  transition: background 140ms var(--ease), color 140ms var(--ease);
}

.icon-btn:active {
  background: var(--panel-strong);
  color: var(--text);
}

.icon-btn[hidden] {
  display: none;
}

.screen {
  display: none;
  flex: 1;
  flex-direction: column;
  animation: fade-up 260ms var(--ease);
}

.screen.is-active {
  display: flex;
}

@keyframes fade-up {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

/* ------------------------------------------------------------ Главная */

.hero {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 22px;
}

.hero__mark {
  width: 54px;
  height: 54px;
  border-radius: 16px;
  background: var(--accent-soft);
  object-fit: contain;
  padding: 8px;
}

.hero__title {
  font-family: var(--serif);
  font-size: 27px;
  font-weight: 600;
  line-height: 1.15;
  letter-spacing: -0.02em;
  margin: 0;
}

.hero__sub {
  color: var(--text-soft);
  font-size: 14px;
  margin: 2px 0 0;
}

.streak-strip {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  border-radius: var(--radius);
  background: var(--accent-soft);
  color: var(--accent-hover);
  font-size: 14px;
  font-weight: 500;
  margin-bottom: 18px;
}

.section-label {
  color: var(--text-faint);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  margin: 0 0 10px;
}

.trainer-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.trainer {
  display: flex;
  align-items: center;
  gap: 14px;
  width: 100%;
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: var(--shadow);
  text-align: left;
  transition: transform 140ms var(--ease), border-color 140ms var(--ease);
}

.trainer:active {
  transform: scale(0.985);
  border-color: var(--accent);
}

.trainer--primary {
  background: linear-gradient(180deg, var(--surface), var(--accent-soft));
}

.trainer__glyph {
  display: grid;
  place-items: center;
  flex: none;
  width: 46px;
  height: 46px;
  border-radius: 14px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 22px;
  font-weight: 600;
}

.trainer__name {
  font-size: 17px;
  font-weight: 600;
}

.trainer__desc {
  color: var(--text-soft);
  font-size: 13px;
  line-height: 1.35;
  margin-top: 2px;
}

.trainer__chev {
  margin-left: auto;
  color: var(--text-faint);
  font-size: 18px;
}

.home-footer {
  display: flex;
  gap: 10px;
  margin-top: 18px;
}

/* ------------------------------------------------------------ Настройки */

.setup {
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding-bottom: 96px;
}

.card {
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.card__title {
  font-size: 15px;
  font-weight: 600;
  margin: 0;
}

.card__note {
  color: var(--text-soft);
  font-size: 13px;
  line-height: 1.4;
  margin: 4px 0 0;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

.chip {
  min-height: 44px;
  padding: 10px 16px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--panel);
  color: var(--text-soft);
  font-size: 15px;
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  letter-spacing: 0.06em;
  transition: background 140ms var(--ease), color 140ms var(--ease),
    border-color 140ms var(--ease);
}

.chip[aria-pressed='true'] {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.chip__hint {
  display: block;
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0;
  opacity: 0.75;
}

.mode-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 12px;
}

.mode {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 56px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--panel);
  text-align: left;
  transition: background 140ms var(--ease), border-color 140ms var(--ease);
}

.mode[aria-pressed='true'] {
  background: var(--accent-soft);
  border-color: var(--accent);
}

.mode__name {
  font-size: 15px;
  font-weight: 600;
}

.mode__hint {
  color: var(--text-soft);
  font-size: 12.5px;
}

.mode__dot {
  flex: none;
  width: 18px;
  height: 18px;
  margin-left: auto;
  border: 2px solid var(--border);
  border-radius: 999px;
}

.mode[aria-pressed='true'] .mode__dot {
  border-color: var(--accent);
  background: radial-gradient(circle, var(--accent) 0 42%, transparent 45%);
}

.toggle-row {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 52px;
  padding: 8px 0;
  border-top: 1px solid var(--border);
  text-align: left;
}

.toggle-row:first-of-type {
  border-top: none;
}

.toggle-row__label {
  font-size: 15px;
  font-weight: 500;
}

.toggle-row__hint {
  color: var(--text-soft);
  font-size: 12.5px;
}

.switch {
  flex: none;
  width: 46px;
  height: 28px;
  margin-left: auto;
  border-radius: 999px;
  background: var(--panel-strong);
  transition: background 160ms var(--ease);
  position: relative;
}

.switch::after {
  content: '';
  position: absolute;
  top: 3px;
  left: 3px;
  width: 22px;
  height: 22px;
  border-radius: 999px;
  background: var(--surface);
  box-shadow: var(--shadow);
  transition: transform 160ms var(--ease);
}

.toggle-row[aria-pressed='true'] .switch {
  background: var(--accent);
}

.toggle-row[aria-pressed='true'] .switch::after {
  transform: translateX(18px);
}

.preview {
  margin-top: 12px;
  padding: 14px;
  border-radius: var(--radius);
  background: var(--panel);
  color: var(--text);
  font-size: 19px;
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  text-align: center;
  min-height: 56px;
  display: grid;
  place-items: center;
}

.sticky-cta {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 12px calc(env(safe-area-inset-left) + 16px)
    calc(env(safe-area-inset-bottom) + 14px) calc(env(safe-area-inset-right) + 16px);
  background: linear-gradient(180deg, transparent, var(--bg) 40%);
}

.sticky-cta__inner {
  max-width: 560px;
  margin: 0 auto;
}

/* -------------------------------------------------------------- Кнопки */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  min-height: 56px;
  padding: 14px 20px;
  border-radius: var(--radius);
  background: var(--accent);
  color: #fff;
  font-size: 17px;
  font-weight: 600;
  transition: background 140ms var(--ease), transform 120ms var(--ease);
}

.btn:active {
  background: var(--accent-hover);
  transform: scale(0.99);
}

.btn--ghost {
  background: var(--panel);
  color: var(--text);
}

.btn--ghost:active {
  background: var(--panel-strong);
}

.btn--sm {
  min-height: 46px;
  font-size: 15px;
}

/* ---------------------------------------------------------------- Игра */

.game {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 14px;
}

.game-head {
  display: flex;
  align-items: center;
  gap: 10px;
}

.metric {
  flex: 1;
  padding: 10px 12px;
  border-radius: var(--radius);
  background: var(--panel);
  text-align: center;
}

.metric__value {
  display: block;
  font-size: 22px;
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  line-height: 1.1;
}

.metric__label {
  color: var(--text-soft);
  font-size: 11.5px;
  letter-spacing: 0.03em;
}

.metric--alarm .metric__value {
  color: var(--bad);
}

.lives {
  display: flex;
  gap: 4px;
  justify-content: center;
  font-size: 15px;
}

.progress {
  height: 5px;
  border-radius: 999px;
  background: var(--panel-strong);
  overflow: hidden;
}

.progress__fill {
  height: 100%;
  width: 0;
  border-radius: 999px;
  background: var(--accent);
  transition: width 200ms var(--ease);
}

.question {
  display: flex;
  flex: 1;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 20px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: var(--shadow);
  min-height: 180px;
  text-align: center;
}

.question__hint {
  color: var(--text-faint);
  font-size: 12.5px;
  letter-spacing: 0.03em;
  min-height: 16px;
}

.question__prompt {
  font-size: clamp(26px, 8vw, 40px);
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  letter-spacing: -0.01em;
  line-height: 1.2;
  word-break: break-word;
}

.question__prompt.is-memorize {
  font-size: clamp(32px, 11vw, 52px);
  letter-spacing: 0.12em;
  color: var(--accent);
}

.answer {
  min-width: 140px;
  min-height: 54px;
  padding: 8px 18px;
  border-bottom: 2px solid var(--border);
  color: var(--text);
  font-size: 32px;
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  display: grid;
  place-items: center;
  transition: border-color 140ms var(--ease), color 140ms var(--ease);
}

.answer.is-empty {
  color: var(--text-faint);
}

.question.is-ok {
  border-color: var(--ok);
  background: var(--ok-soft);
  animation: pulse-ok 260ms var(--ease);
}

.question.is-bad {
  border-color: var(--bad);
  background: var(--bad-soft);
  animation: shake 260ms var(--ease);
}

@keyframes pulse-ok {
  from {
    transform: scale(0.985);
  }
  to {
    transform: none;
  }
}

@keyframes shake {
  0%,
  100% {
    transform: translateX(0);
  }
  25% {
    transform: translateX(-6px);
  }
  75% {
    transform: translateX(6px);
  }
}

.feedback {
  min-height: 22px;
  font-size: 14.5px;
  font-weight: 600;
}

.feedback.is-ok {
  color: var(--ok);
}

.feedback.is-bad {
  color: var(--bad);
}

/* -------------------------------------------------------------- Numpad */

.pad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.pad__key {
  min-height: 58px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  font-size: 24px;
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  box-shadow: var(--shadow);
  transition: background 100ms var(--ease), transform 100ms var(--ease);
}

.pad__key:active {
  background: var(--panel-strong);
  transform: scale(0.96);
}

.pad__key--util {
  background: var(--panel);
  font-size: 20px;
  box-shadow: none;
}

.pad__key--submit {
  grid-column: span 3;
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-size: 18px;
}

.pad__key--submit:active {
  background: var(--accent-hover);
}

.pad--choice {
  grid-template-columns: repeat(3, 1fr);
}

.pad--choice .pad__key {
  min-height: 76px;
  font-size: 30px;
}

.pad__key:disabled {
  opacity: 0.45;
}

/* ---------------------------------------------------------- Результаты */

.result {
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding-bottom: 96px;
}

.result-head {
  padding: 20px 16px;
  border-radius: var(--radius-lg);
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  text-align: center;
}

.result-head__title {
  font-family: var(--serif);
  font-size: 24px;
  font-weight: 600;
  margin: 0;
}

.result-head__sub {
  color: var(--text-soft);
  font-size: 13.5px;
  margin: 4px 0 0;
}

.record-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 10px;
  padding: 6px 12px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent-hover);
  font-size: 13px;
  font-weight: 600;
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}

.stat-cell {
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}

.stat-cell__value {
  display: block;
  font-size: 24px;
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  line-height: 1.1;
}

.stat-cell__label {
  color: var(--text-soft);
  font-size: 12.5px;
}

.mistakes {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.mistake {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  font-variant-numeric: tabular-nums;
}

.mistake__prompt {
  font-size: 15px;
  font-weight: 600;
  flex: 1;
  word-break: break-word;
}

.mistake__given {
  color: var(--bad);
  font-size: 14px;
  text-decoration: line-through;
}

.mistake__expected {
  color: var(--ok);
  font-size: 15px;
  font-weight: 600;
}

.empty-note {
  padding: 16px;
  border-radius: var(--radius);
  background: var(--panel);
  color: var(--text-soft);
  font-size: 14px;
  text-align: center;
}

/* ---------------------------------------------------------- Статистика */

.stats {
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding-bottom: 40px;
}

.chart {
  width: 100%;
  height: 140px;
  display: block;
}

.chart-line {
  fill: none;
  stroke: var(--accent);
  stroke-width: 2.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.chart-area {
  fill: var(--accent-soft);
  stroke: none;
}

.chart-grid {
  stroke: var(--border);
  stroke-width: 1;
}

.chart-dot {
  fill: var(--accent);
}

.record-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 0;
  border-top: 1px solid var(--border);
}

.record-row:first-of-type {
  border-top: none;
}

.record-row__main {
  flex: 1;
}

.record-row__name {
  font-size: 14.5px;
  font-weight: 600;
}

.record-row__meta {
  color: var(--text-soft);
  font-size: 12.5px;
}

.record-row__score {
  color: var(--accent);
  font-size: 17px;
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  text-align: right;
}

.history-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 0;
  border-top: 1px solid var(--border);
  font-size: 13.5px;
}

.history-row:first-of-type {
  border-top: none;
}

.history-row__meta {
  color: var(--text-soft);
  flex: 1;
}

.history-row__score {
  font-variant-numeric: tabular-nums;
  font-weight: 600;
}

/* ------------------------------------------------------------- Модалка */

.sheet {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: none;
  align-items: flex-end;
  justify-content: center;
  background: rgba(43, 39, 35, 0.4);
  padding: 16px;
}

.sheet.is-open {
  display: flex;
  animation: fade-in 180ms var(--ease);
}

@keyframes fade-in {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

.sheet__panel {
  width: 100%;
  max-width: 520px;
  padding: 20px;
  padding-bottom: calc(20px + env(safe-area-inset-bottom));
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: var(--shadow-lift);
  animation: slide-up 240ms var(--ease);
}

@keyframes slide-up {
  from {
    transform: translateY(24px);
  }
  to {
    transform: none;
  }
}

.sheet__title {
  font-family: var(--serif);
  font-size: 20px;
  font-weight: 600;
  margin: 0 0 8px;
}

.sheet__text {
  color: var(--text-soft);
  font-size: 14px;
  line-height: 1.5;
  margin: 0 0 8px;
}

.sheet__steps {
  color: var(--text-soft);
  font-size: 14px;
  line-height: 1.6;
  margin: 0 0 16px;
  padding-left: 20px;
}

.sheet__actions {
  display: flex;
  gap: 10px;
}

@media (pointer: fine) {
  .trainer:hover,
  .mode:hover {
    border-color: var(--accent);
  }
  .pad__key:hover {
    background: var(--panel);
  }
  .pad__key--submit:hover {
    background: var(--accent-hover);
  }
}

@media (max-height: 700px) {
  .question {
    min-height: 140px;
  }
  .pad__key {
    min-height: 52px;
  }
}