:root {
  --navy-1: #241c4d;
  --navy-2: #453494;
  --accent: #6558f5;
  --accent-soft: #a99ffb;
  --card: #f0edfe;
  --card-2: #e4defd;
  --white: #ffffff;
  --bg: #f7f5fd;
  --text: #241c4d;
  --muted: #7d76a0;
  --locked: #b3aecb;
  --locked-bg: #eae7f4;
  --correct: #2fa84f;
  --correct-bg: rgba(47, 168, 79, 0.13);
  --incorrect: #dd3d43;
  --incorrect-bg: rgba(221, 61, 67, 0.13);
  --warn: #d9822b;
  --warn-bg: rgba(217, 130, 43, 0.14);
  --shadow: 0 2px 6px rgba(60, 40, 140, 0.06), 0 12px 32px rgba(60, 40, 140, 0.13);
  --shadow-sm: 0 1px 3px rgba(60, 40, 140, 0.1);
  --r-card: 26px;
  --r-btn: 999px;
  --ease-bounce: cubic-bezier(0.34, 1.56, 0.64, 1);
  --ease-smooth: cubic-bezier(0.16, 1, 0.3, 1);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
}

#app {
  max-width: 480px;
  margin: 0 auto;
  padding: 18px 18px 104px;
}

.screen,
.tab-screen {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

[hidden] {
  display: none !important;
}

.screen.screen-animate,
.tab-screen.screen-animate {
  animation: screenEnter 0.32s var(--ease-smooth);
}

@keyframes screenEnter {
  from {
    opacity: 0;
    transform: translateY(10px) scale(0.99);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.tab-title {
  font-size: 23px;
  font-weight: 800;
  margin: 4px 0;
  letter-spacing: -0.3px;
}

/* ---------- Тёмные шапки ---------- */

.course-header,
.screen-header {
  background: linear-gradient(165deg, var(--navy-1), var(--navy-2));
  color: var(--white);
  margin: -18px -18px 0;
  padding: 18px 20px 24px;
  border-radius: 0 0 34px 34px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.course-header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.streak-pill {
  display: flex;
  align-items: center;
  gap: 5px;
  background: rgba(255, 255, 255, 0.14);
  color: #ffce6a;
  padding: 5px 11px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 800;
  flex-shrink: 0;
}

.streak-pill.streak-zero {
  color: rgba(255, 255, 255, 0.5);
}

.course-eyebrow {
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.9px;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.62);
  margin: 0;
}

.course-title {
  font-size: 23px;
  font-weight: 800;
  margin: 0;
  line-height: 1.2;
  letter-spacing: -0.3px;
}

.course-progress-caption {
  font-size: 12.5px;
  color: rgba(255, 255, 255, 0.72);
  margin: 0;
}

.course-header .progress-bar,
.screen-header .progress-bar {
  background: rgba(255, 255, 255, 0.18);
}

.course-header .progress-bar-fill,
.screen-header .progress-bar-fill {
  background: var(--accent-soft);
}

.screen-header {
  gap: 12px;
}

.screen-header .progress {
  color: rgba(255, 255, 255, 0.72);
}

/* карточка урока заходит на шапку */
.lesson-card {
  position: relative;
  margin-top: -40px;
  background: var(--card);
  border-radius: var(--r-card);
  padding: 18px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.lesson-card-tabs {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.pill {
  font-size: 10.5px;
  font-weight: 800;
  letter-spacing: 0.6px;
  text-transform: uppercase;
  padding: 6px 11px;
  border-radius: 999px;
  background: var(--card-2);
  color: #5a48c9;
}

.pill-muted {
  background: rgba(60, 40, 140, 0.07);
  color: var(--muted);
  text-transform: none;
  letter-spacing: 0;
  font-weight: 600;
}

.lesson-card-head {
  display: flex;
  align-items: center;
  gap: 12px;
}

.lesson-icon {
  width: 46px;
  height: 46px;
  border-radius: 16px;
  background: var(--white);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--accent);
  box-shadow: var(--shadow-sm);
  flex-shrink: 0;
}

.lesson-card-title {
  font-size: 19px;
  font-weight: 800;
  line-height: 1.22;
  letter-spacing: -0.2px;
}

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

.btn-primary,
.btn-secondary {
  width: 100%;
  border: none;
  border-radius: var(--r-btn);
  padding: 15px;
  font-size: 15.5px;
  font-weight: 800;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  transition: transform 0.18s var(--ease-bounce), opacity 0.15s ease;
}

.btn-primary {
  background: var(--accent);
  color: var(--white);
  box-shadow: 0 10px 24px rgba(101, 88, 245, 0.38);
}

.btn-secondary {
  background: var(--white);
  color: #5a48c9;
  box-shadow: var(--shadow-sm);
}

.btn-primary:active,
.btn-secondary:active {
  transform: scale(0.96);
  opacity: 0.92;
}

.back-btn {
  background: none;
  border: none;
  color: #c3b9ff;
  padding: 0;
  font-size: 14.5px;
  font-weight: 700;
  align-self: flex-start;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: opacity 0.15s ease;
}

.back-btn:active {
  opacity: 0.55;
}

/* ---------- Прогресс ---------- */

.progress {
  color: var(--muted);
  font-size: 13px;
  margin: 0;
  font-weight: 600;
}

.progress-bar {
  height: 7px;
  border-radius: 4px;
  background: var(--card-2);
  overflow: hidden;
}

.progress-bar-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 4px;
  transition: width 0.35s var(--ease-smooth);
  width: 0%;
}

/* ---------- Дорожка модулей ---------- */

.roadmap {
  display: flex;
  flex-direction: column;
}

.roadmap-item {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  position: relative;
  padding-bottom: 22px;
  cursor: pointer;
  background: none;
  border: none;
  text-align: left;
  width: 100%;
  font: inherit;
  color: inherit;
  transition: opacity 0.15s ease;
}

.roadmap-item:active {
  opacity: 0.65;
}

.roadmap-item:last-child {
  padding-bottom: 0;
}

.roadmap-item:not(:last-child)::before {
  content: "";
  position: absolute;
  left: 18px;
  top: 40px;
  bottom: 0;
  border-left: 2px dashed #d0c9ea;
}

.roadmap-circle {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  z-index: 1;
}

.roadmap-item.done .roadmap-circle {
  background: var(--accent);
  color: var(--white);
}

.roadmap-item.current .roadmap-circle {
  background: var(--white);
  border: 3px solid var(--accent);
  box-shadow: var(--shadow);
}

.roadmap-item.current .roadmap-circle .dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #f7a93b;
}

.roadmap-item.future .roadmap-circle {
  background: var(--locked-bg);
  color: var(--locked);
}

.roadmap-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding-top: 3px;
}

.roadmap-label-eyebrow {
  font-size: 10.5px;
  font-weight: 800;
  letter-spacing: 0.7px;
  text-transform: uppercase;
  color: var(--accent);
  margin: 0;
}

.roadmap-label-title {
  font-size: 14.5px;
  font-weight: 650;
  margin: 0;
}

.roadmap-item.future .roadmap-label-eyebrow,
.roadmap-item.future .roadmap-label-title {
  color: var(--locked);
}

/* ---------- Песочница ---------- */

.sandbox-toggle {
  display: flex;
  gap: 6px;
  background: var(--card-2);
  padding: 5px;
  border-radius: 999px;
}

.toggle-btn {
  flex: 1;
  padding: 11px;
  font-size: 14px;
  font-weight: 700;
  border: none;
  border-radius: 999px;
  background: none;
  color: #5a48c9;
  cursor: pointer;
  transition: background 0.2s ease, box-shadow 0.2s ease;
}

.toggle-btn.active {
  background: var(--white);
  box-shadow: var(--shadow-sm);
}

/* ---------- Вопрос и варианты ---------- */

.question {
  font-size: 18px;
  font-weight: 700;
  margin: 0;
  line-height: 1.35;
}

.task-image {
  display: block;
  width: 100%;
  max-width: 340px;
  margin: 0 auto;
  background: var(--white);
  border-radius: 18px;
  padding: 8px;
  box-shadow: var(--shadow-sm);
}

.answer-pad {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.answer-box {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--white);
  border: 2px solid var(--card-2);
  border-radius: 20px;
  padding: 14px 16px;
  box-shadow: var(--shadow-sm);
  transition: border-color 0.2s ease, background 0.2s ease;
}

.answer-label {
  font-size: 12.5px;
  font-weight: 700;
  color: var(--muted);
}

.answer-value {
  flex: 1;
  text-align: right;
  font-size: 27px;
  font-weight: 800;
  letter-spacing: 0.5px;
  font-variant-numeric: tabular-nums;
}

.answer-value.empty {
  color: #cbc4e4;
}

.answer-backspace {
  background: none;
  border: none;
  padding: 4px;
  color: var(--muted);
  cursor: pointer;
  display: flex;
  transition: transform 0.14s var(--ease-bounce), opacity 0.15s ease;
}

.answer-backspace:active {
  transform: scale(0.88);
  opacity: 0.6;
}

.answer-box.correct {
  border-color: var(--correct);
  background: var(--correct-bg);
}

.answer-box.incorrect {
  border-color: var(--incorrect);
  background: var(--incorrect-bg);
}

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

.key {
  background: var(--white);
  border: none;
  border-radius: 20px;
  padding: 16px 0;
  font-size: 22px;
  font-weight: 700;
  color: var(--text);
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: transform 0.14s var(--ease-bounce), background 0.15s ease;
}

.key:active:not(:disabled) {
  transform: scale(0.93);
  background: var(--card-2);
}

.key-util {
  background: var(--card-2);
  color: #5a48c9;
}

.key:disabled,
.check-btn:disabled {
  opacity: 0.55;
  cursor: default;
}

.feedback {
  font-size: 15px;
  font-weight: 800;
  min-height: 20px;
  margin: 0;
  opacity: 0;
  transform: translateY(4px);
  transition: opacity 0.25s ease, transform 0.25s ease;
}

.feedback.correct,
.feedback.incorrect {
  opacity: 1;
  transform: translateY(0);
}

.feedback.correct {
  color: var(--correct);
}

.feedback.incorrect {
  color: var(--incorrect);
}

/* ---------- Карточки и результаты ---------- */

.banner {
  background: var(--card);
  padding: 16px 18px;
  border-radius: var(--r-card);
  box-shadow: var(--shadow);
}

.result-card {
  background: var(--card);
  border-radius: var(--r-card);
  padding: 24px 18px;
  text-align: center;
  border-width: 2px;
  border-style: solid;
  border-color: transparent;
  box-shadow: var(--shadow);
  animation: screenEnter 0.35s var(--ease-smooth);
}

.result-card.decision-good {
  border-color: var(--correct);
  background: var(--correct-bg);
}

.result-card.decision-bad {
  border-color: var(--incorrect);
  background: var(--incorrect-bg);
}

.result-card.decision-neutral {
  border-color: var(--warn);
  background: var(--warn-bg);
}

.big {
  font-size: 21px;
  font-weight: 800;
  text-align: center;
  margin: 4px 0;
}

.hint {
  color: var(--muted);
  text-align: center;
  font-size: 14px;
}

.error {
  color: var(--incorrect);
}

/* ---------- Уровень ---------- */

.level-ring {
  width: 152px;
  height: 152px;
  border-radius: 50%;
  margin: 14px auto 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: conic-gradient(var(--accent) calc(var(--pct, 0) * 1%), var(--card-2) 0);
  transition: background 0.4s var(--ease-smooth);
}

.level-ring-inner {
  width: 120px;
  height: 120px;
  border-radius: 50%;
  background: var(--white);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  box-shadow: var(--shadow);
}

.level-ring-number {
  font-size: 32px;
  font-weight: 800;
}

.level-ring-label {
  font-size: 12px;
  color: var(--muted);
}

/* ---------- Списки ---------- */

.mistake-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 0;
  margin: 0;
  list-style: none;
}

.mistake-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  background: var(--card);
  border-radius: 18px;
  padding: 14px 16px;
  box-shadow: var(--shadow-sm);
}

.mistake-topic {
  font-size: 15px;
}

.mistake-streak {
  font-size: 13px;
  color: var(--muted);
  white-space: nowrap;
}

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

.stat-tile {
  background: var(--card);
  border-radius: 20px;
  padding: 16px 8px;
  text-align: center;
  box-shadow: var(--shadow-sm);
}

.stat-value {
  font-size: 22px;
  font-weight: 800;
}

.stat-label {
  font-size: 12px;
  color: var(--muted);
  margin-top: 2px;
}

/* ---------- Нижняя навигация ---------- */

.bottom-nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  background: var(--white);
  padding: 10px 8px calc(12px + env(safe-area-inset-bottom));
  box-shadow: 0 -2px 16px rgba(60, 40, 140, 0.1);
  border-radius: 30px 30px 0 0;
  max-width: 480px;
  margin: 0 auto;
  z-index: 10;
}

.nav-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  background: none;
  border: none;
  padding: 5px 4px;
  cursor: pointer;
  color: var(--locked);
  transition: transform 0.15s var(--ease-bounce), color 0.15s ease;
}

.nav-btn:active {
  transform: scale(0.9);
}

.nav-btn.active {
  color: var(--accent);
}

.nav-label {
  font-size: 10.5px;
  font-weight: 700;
}

/* ---------- Сообщение об ошибке связи ---------- */

.toast {
  position: fixed;
  left: 16px;
  right: 16px;
  bottom: calc(86px + env(safe-area-inset-bottom));
  max-width: 448px;
  margin: 0 auto;
  background: var(--navy-1);
  color: var(--white);
  padding: 13px 16px;
  border-radius: 16px;
  font-size: 14px;
  font-weight: 600;
  text-align: center;
  box-shadow: 0 8px 24px rgba(26, 20, 60, 0.35);
  opacity: 0;
  transform: translateY(12px);
  pointer-events: none;
  transition: opacity 0.25s ease, transform 0.25s var(--ease-smooth);
  z-index: 20;
}

.toast.visible {
  opacity: 1;
  transform: translateY(0);
}
