:root {
  --bg: #f4f6fb;
  --card: #ffffff;
  --ink: #172033;
  --muted: #6b7280;
  --line: #e6e9f2;
  --primary: #4f46e5;
  --primary-dark: #4338ca;
  --primary-soft: #eef2ff;
  --good: #059669;
  --good-soft: #ecfdf5;
  --bad: #dc2626;
  --bad-soft: #fef2f2;
  --shadow: 0 18px 45px rgba(30, 41, 80, 0.10);
  --radius: 18px;
}

* { box-sizing: border-box; }

html, body { min-height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.background-glow {
  position: fixed;
  inset: 0;
  z-index: -1;
  background:
    radial-gradient(50rem 30rem at 12% -5%, rgba(79, 70, 229, 0.16), transparent 70%),
    radial-gradient(42rem 28rem at 105% 10%, rgba(16, 185, 129, 0.12), transparent 70%);
  pointer-events: none;
}

.is-hidden { display: none !important; }
.muted { color: var(--muted); }

/* ---------- общие элементы ---------- */

.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 13px;
  background: linear-gradient(145deg, var(--primary), #7c3aed);
  color: #fff;
  font-size: 28px;
  font-weight: 600;
  line-height: 1;
  box-shadow: 0 8px 20px rgba(79, 70, 229, 0.28);
}
.brand-name { display: block; font-weight: 750; font-size: 19px; letter-spacing: -0.02em; }
.brand-sub { display: block; color: var(--muted); font-size: 12px; }
.brand--large .brand-mark { width: 52px; height: 52px; font-size: 34px; }
.brand--large { margin-bottom: 26px; }
.brand-mark--button {
  border: 0;
  padding: 0;
  font-family: inherit;
  cursor: pointer;
  transition: transform .12s ease, filter .15s ease;
}
.brand-mark--button:hover { filter: brightness(1.08); }
.brand-mark--button:active { transform: translateY(1px); }
.brand-mark--button:focus-visible { outline: 3px solid #c7d2fe; outline-offset: 2px; }

.btn {
  appearance: none;
  border: 1px solid transparent;
  border-radius: 12px;
  padding: 13px 20px;
  font: inherit;
  font-weight: 650;
  cursor: pointer;
  transition: transform .12s ease, background .15s ease, box-shadow .15s ease;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn--primary { background: var(--primary); color: #fff; box-shadow: 0 10px 24px rgba(79, 70, 229, .24); }
.btn--primary:hover:not(:disabled) { background: var(--primary-dark); }
.btn--ghost { background: transparent; border-color: var(--line); color: var(--muted); }
.btn--ghost:hover { background: #fff; color: var(--ink); }
.btn--danger { background: #fff; border-color: #fecaca; color: var(--bad); }
.btn--danger:hover { background: var(--bad-soft); }
.btn--small { padding: 9px 14px; font-size: 14px; }

kbd {
  background: #fff;
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 6px;
  padding: 1px 6px;
  font: 600 12px/1.5 ui-monospace, SFMono-Regular, Consolas, monospace;
}

/* ---------- авторизация ---------- */

.auth-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}
.auth-card {
  width: 100%;
  max-width: 420px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 24px;
  box-shadow: var(--shadow);
  padding: 34px;
}
.auth-tabs {
  display: flex;
  gap: 6px;
  padding: 5px;
  background: #f3f5fa;
  border-radius: 12px;
  margin-bottom: 22px;
}
.auth-tab {
  flex: 1;
  border: 0;
  background: transparent;
  border-radius: 9px;
  padding: 10px;
  font: inherit;
  font-weight: 650;
  color: var(--muted);
  cursor: pointer;
}
.auth-tab.is-active { background: #fff; color: var(--primary); box-shadow: 0 2px 8px rgba(30,41,80,.08); }

.auth-form { display: grid; gap: 16px; }
.auth-form label { display: grid; gap: 7px; font-size: 14px; font-weight: 600; }
.auth-form input, .answer-input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 13px 15px;
  font: inherit;
  background: #fbfcff;
  color: var(--ink);
  outline: none;
  transition: border .15s ease, box-shadow .15s ease;
}
.auth-form input:focus, .answer-input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 4px rgba(79, 70, 229, .12);
}
.form-error { min-height: 22px; margin: 14px 0 0; color: var(--bad); font-size: 14px; font-weight: 600; }
.auth-footnote { margin: 4px 0 0; color: var(--muted); font-size: 12px; text-align: center; }

/* ---------- каркас приложения ---------- */

.app-screen { max-width: 940px; margin: 0 auto; padding: 18px 20px 24px; }
.topbar { display: flex; justify-content: space-between; align-items: center; gap: 16px; }
.topbar-right { display: flex; align-items: center; gap: 12px; }
.user-chip {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 8px 15px;
  font-size: 14px;
  font-weight: 600;
}
.user-name { color: var(--primary); }

.tabs { display: flex; gap: 6px; margin: 16px 0 14px; border-bottom: 1px solid var(--line); }
.tab {
  border: 0;
  border-bottom: 3px solid transparent;
  background: transparent;
  padding: 8px 16px;
  font: inherit;
  font-weight: 650;
  color: var(--muted);
  cursor: pointer;
  margin-bottom: -1px;
}
.tab:hover { color: var(--ink); }
.tab.is-active { color: var(--primary); border-bottom-color: var(--primary); }

/* ---------- тренажёр ---------- */

/* ---------- настройка тренировочной сессии ---------- */

.setup-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 20px 0;
  box-shadow: 0 8px 22px rgba(30,41,80,.06);
  margin-bottom: 12px;
  overflow: hidden;
}
.setup-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.setup-head h2 { margin: 0; font-size: 17px; letter-spacing: -0.01em; }
.setup-progress { color: var(--muted); font-size: 13px; font-weight: 650; }
.setup-fields {
  display: flex;
  align-items: flex-end;
  gap: 12px;
  flex-wrap: wrap;
  margin: 10px 0 12px;
}
.setup-fields label { display: grid; gap: 5px; font-size: 12px; font-weight: 650; color: var(--muted); }
.setup-fields input {
  width: 110px;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 10px;
  font: inherit;
  font-weight: 650;
  background: #fbfcff;
  color: var(--ink);
  outline: none;
}
.setup-fields input:focus { border-color: var(--primary); box-shadow: 0 0 0 4px rgba(79,70,229,.12); }
.progress-track { height: 5px; background: #eef1f8; margin: 0 -20px; }
.progress-fill { height: 100%; width: 0; background: linear-gradient(90deg, var(--primary), #818cf8); transition: width .25s ease; }

.task-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px 24px 20px;
  text-align: center;
}
.task-topline { display: flex; justify-content: space-between; color: var(--muted); font-size: 13px; font-weight: 600; }
.timer { font-variant-numeric: tabular-nums; }

.expression {
  margin: 18px 0 16px;
  font-size: clamp(2.4rem, 7vw, 3.8rem);
  font-weight: 750;
  letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
  min-height: 1.3em;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: .22em;
}
.expression-loading { font-size: 20px; font-weight: 500; color: var(--muted); letter-spacing: 0; }
.expression .question { color: var(--primary); }
.expression.pop { animation: pop .25s ease; }
@keyframes pop { from { transform: scale(.94); opacity: .4; } to { transform: scale(1); opacity: 1; } }

.answer-form { max-width: 420px; margin: 0 auto; }
.answer-label { display: block; text-align: left; font-size: 13px; font-weight: 650; color: var(--muted); margin-bottom: 8px; }
.answer-row { display: flex; gap: 10px; }
.answer-input { text-align: center; font-size: 24px; font-weight: 700; padding: 11px 14px; }
.answer-row .btn { min-width: 150px; }

.keypad {
  display: grid;
  grid-template-columns: repeat(3, minmax(62px, 84px));
  justify-content: center;
  gap: 6px;
  margin: 12px auto 0;
}
.keypad button {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  color: var(--ink);
  font: 700 21px/1 inherit;
  padding: 9px 0;
  cursor: pointer;
  box-shadow: 0 3px 10px rgba(30,41,80,.06);
  transition: transform .1s ease, background .15s ease, border-color .15s ease;
  user-select: none;
}
.keypad button:hover { border-color: #c7d2fe; background: var(--primary-soft); }
.keypad button:active { transform: translateY(2px); }
.keypad .key-util { background: #f3f5fa; color: var(--muted); font-size: 18px; }

.feedback { margin: 20px auto 0; min-height: 58px; max-width: 560px; font-size: 15px; }
.feedback:empty { min-height: 0; margin-top: 0; }
.feedback-box {
  border-radius: 13px;
  padding: 13px 16px;
  text-align: left;
  animation: rise .2s ease;
}
@keyframes rise { from { transform: translateY(6px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
.feedback-box strong { display: block; font-size: 17px; margin-bottom: 3px; }
.feedback-box.is-correct { background: var(--good-soft); color: var(--good); border: 1px solid #a7f3d0; }
.feedback-box.is-wrong { background: var(--bad-soft); color: var(--bad); border: 1px solid #fecaca; }
.feedback-box span { color: var(--ink); font-size: 14px; }
.task-card.shake { animation: shake .3s ease; }
@keyframes shake { 25% { transform: translateX(-5px); } 75% { transform: translateX(5px); } }

.tip { text-align: center; color: var(--muted); font-size: 13px; margin-top: 10px; }

.session-summary {
  margin: 18px auto 0;
  max-width: 520px;
  border: 1px solid #c7d2fe;
  background: var(--primary-soft);
  border-radius: 14px;
  padding: 16px 18px;
  text-align: left;
  animation: rise .2s ease;
}
.session-summary h3 { margin: 0 0 8px; font-size: 18px; color: var(--primary-dark); }
.session-summary p { margin: 0; font-size: 14px; }

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

.stats-head { display: flex; justify-content: space-between; align-items: center; gap: 14px; flex-wrap: wrap; margin-bottom: 18px; }
.stats-head h1 { margin: 0; font-size: 22px; letter-spacing: -0.02em; }
.stats-content { display: grid; gap: 18px; }
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 14px; }
.tile {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 15px;
  padding: 18px 20px;
  box-shadow: 0 8px 22px rgba(30,41,80,.06);
}
.tile-label { color: var(--muted); font-size: 13px; font-weight: 600; }
.tile-value { font-size: 30px; font-weight: 750; letter-spacing: -0.03em; margin-top: 4px; font-variant-numeric: tabular-nums; }
.tile-value.is-good { color: var(--good); }

.panels { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 18px; }
.panel {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 22px;
  box-shadow: 0 8px 22px rgba(30,41,80,.06);
}
.panel h2 { margin: 0 0 16px; font-size: 17px; letter-spacing: -0.01em; }
.empty { color: var(--muted); font-size: 14px; }

.bar-row { display: grid; grid-template-columns: 90px 1fr 78px; align-items: center; gap: 10px; margin-bottom: 11px; font-size: 13px; }
.bar-label { color: var(--muted); font-weight: 600; }
.bar-track { height: 10px; border-radius: 999px; background: #eef1f8; overflow: hidden; }
.bar-fill { height: 100%; border-radius: 999px; background: linear-gradient(90deg, var(--primary), #818cf8); min-width: 3px; }
.bar-fill.is-bad { background: linear-gradient(90deg, #f97316, #ef4444); }
.bar-value { text-align: right; color: var(--ink); font-weight: 650; font-variant-numeric: tabular-nums; }

.daily { display: flex; align-items: flex-end; gap: 10px; height: 150px; padding-top: 8px; }
.daily-col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 7px; height: 100%; justify-content: flex-end; }
.daily-bar { width: 100%; max-width: 42px; border-radius: 7px 7px 2px 2px; background: linear-gradient(180deg, #818cf8, var(--primary)); min-height: 3px; }
.daily-count { font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; }
.daily-label { font-size: 11px; color: var(--muted); }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 11px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { color: var(--muted); font-size: 12px; font-weight: 650; text-transform: uppercase; letter-spacing: .03em; }
td.expression-cell { font-weight: 700; font-variant-numeric: tabular-nums; }
.pill { border-radius: 999px; padding: 3px 9px; font-size: 12px; font-weight: 650; }
.pill.ok { background: var(--good-soft); color: var(--good); }
.pill.bad { background: var(--bad-soft); color: var(--bad); }

.session-item { border: 1px solid var(--line); border-radius: 12px; margin-bottom: 10px; overflow: hidden; }
.session-item > summary {
  cursor: pointer;
  padding: 13px 15px;
  font-size: 14px;
  background: #fbfcff;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.session-item > summary::-webkit-details-marker { display: none; }
.session-item > summary::after { content: "▾"; margin-left: auto; color: var(--muted); transition: transform .15s ease; }
.session-item[open] > summary::after { transform: rotate(180deg); }
.session-item > summary:hover { background: var(--primary-soft); }
.session-badge { border-radius: 999px; padding: 2px 9px; font-size: 11px; font-weight: 700; }
.session-badge.ok { background: var(--good-soft); color: var(--good); }
.session-badge.progress { background: #fff7ed; color: #c2410c; }
.session-body { padding: 14px 15px 18px; border-top: 1px solid var(--line); }
.session-meta { color: var(--muted); font-size: 13px; margin-bottom: 10px; }

.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: #172033;
  color: #fff;
  border-radius: 12px;
  padding: 11px 18px;
  font-size: 14px;
  box-shadow: var(--shadow);
  z-index: 10;
}

@media (max-width: 600px) {
  .task-card { padding: 20px 16px 24px; }
  .answer-row { flex-direction: column; }
  .answer-row .btn { width: 100%; }
  .auth-card { padding: 24px; }
  .topbar { flex-wrap: wrap; }
  .setup-card { padding: 18px 16px 0; }
  .setup-fields label { flex: 1 1 100px; }
  .setup-fields input { width: 100%; }
  .setup-fields .btn { width: 100%; }
  .progress-track { margin: 0 -16px; }
}

/* ---------- низкие экраны: убираем лишнюю вертикаль ---------- */

@media (max-height: 820px) {
  .expression { margin: 12px 0 10px; font-size: clamp(2rem, 6vw, 3.2rem); }
  .keypad button { padding: 7px 0; }
  .feedback { margin-top: 12px; }
  .session-summary { margin-top: 12px; padding: 12px 16px; }
}
