/* Цвета берём из темы Телеграма, чтобы приложение выглядело родным
   и в светлой, и в тёмной. Значения после запятой — на случай открытия
   в обычном браузере, где переменных Телеграма нет. */
:root {
  --bg: var(--tg-theme-bg-color, #ffffff);
  --surface: var(--tg-theme-secondary-bg-color, #f2f2f7);
  --text: var(--tg-theme-text-color, #000000);
  --hint: var(--tg-theme-hint-color, #8e8e93);
  --link: var(--tg-theme-link-color, #2481cc);
  --accent: var(--tg-theme-button-color, #2481cc);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);

  --ok: #2eb872;
  --warn: #e8a33d;
  --radius: 14px;
  --gap: 12px;
}

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

body {
  margin: 0;
  padding: 16px 16px calc(24px + env(safe-area-inset-bottom));
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}

h1, h2, h3 { margin: 0; font-weight: 650; }
h1 { font-size: 22px; }
h2 { font-size: 17px; }
p { margin: 0; }

.hint { color: var(--hint); font-size: 14px; }
.stack { display: flex; flex-direction: column; gap: var(--gap); }
.center { text-align: center; }

/* --- шапка с кольцом прогресса --- */

.hero { display: flex; flex-direction: column; align-items: center; gap: 10px; padding: 8px 0 4px; }

.ring {
  width: 132px; height: 132px; border-radius: 50%;
  display: grid; place-items: center;
  background: conic-gradient(var(--accent) var(--pct, 0%), var(--surface) 0);
  transition: background 400ms ease;
}
.ring__inner {
  width: 108px; height: 108px; border-radius: 50%;
  background: var(--bg);
  display: grid; place-items: center; align-content: center; gap: 2px;
}
.ring__value { font-size: 26px; font-weight: 700; line-height: 1; }
.ring__label { font-size: 12px; color: var(--hint); }

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

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

.button {
  display: block; width: 100%; padding: 15px 18px;
  border: 0; border-radius: var(--radius);
  background: var(--accent); color: var(--accent-text);
  font-size: 16px; font-weight: 600; font-family: inherit;
  cursor: pointer;
}
.button:active { opacity: .82; }
.button--quiet { background: var(--surface); color: var(--text); }

/* --- плитки быстрых режимов --- */

.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: var(--gap); }

.tile {
  padding: 14px; border: 0; border-radius: var(--radius);
  background: var(--surface); color: var(--text);
  font-family: inherit; font-size: 15px; text-align: left; cursor: pointer;
}
.tile:active { opacity: .82; }
.tile__title { font-weight: 600; }
.tile__value { font-size: 13px; color: var(--hint); margin-top: 2px; }
.tile__value--accent { color: var(--warn); font-weight: 600; }

/* --- карточки курсов и тем --- */

.card { background: var(--surface); border-radius: var(--radius); padding: 14px; }
.card + .card { margin-top: var(--gap); }
.card__head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }

.bar { height: 6px; border-radius: 3px; background: rgba(127,127,127,.25); overflow: hidden; margin-top: 8px; }
.bar__fill { height: 100%; border-radius: 3px; background: var(--accent); transition: width 400ms ease; }

.topic {
  display: flex; justify-content: space-between; align-items: center; gap: 10px;
  padding: 10px 0; border-top: 1px solid rgba(127,127,127,.18);
  font-size: 15px;
}
.topic:first-of-type { border-top: 0; }
.topic__count { color: var(--hint); font-size: 13px; white-space: nowrap; }
.topic--off { opacity: .45; }

.topic__main {
  flex: 1; display: grid; grid-template-columns: 1fr auto; gap: 2px 10px;
  padding: 0; border: 0; background: none; color: inherit;
  font-family: inherit; font-size: 15px; text-align: left; cursor: pointer;
}
.topic__main:active { opacity: .6; }
.topic__title { grid-column: 1; }
.topic__meta { grid-column: 2; color: var(--hint); font-size: 13px; white-space: nowrap; }
.bar--thin { grid-column: 1 / -1; height: 4px; margin-top: 4px; display: block; }

/* переключатель «учить тему» */
.switch { flex: none; position: relative; width: 44px; height: 26px; }
.switch input { position: absolute; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.switch__track {
  display: block; width: 100%; height: 100%; border-radius: 13px;
  background: rgba(127,127,127,.35); transition: background 150ms ease;
  pointer-events: none;
}
.switch__track::after {
  content: ''; position: absolute; top: 3px; left: 3px;
  width: 20px; height: 20px; border-radius: 50%; background: #fff;
  transition: transform 150ms ease;
}
.switch input:checked + .switch__track { background: var(--ok); }
.switch input:checked + .switch__track::after { transform: translateX(18px); }

/* распределение карточек по состояниям */
.stackbar { display: flex; height: 10px; border-radius: 5px; overflow: hidden; gap: 2px; margin-top: 10px; }
.stackbar__part { display: block; }
.state--new { background: rgba(127,127,127,.45); }
.state--learning { background: var(--warn); }
.state--review { background: var(--accent); }
.state--mastered { background: var(--ok); }

.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; margin-top: 10px; font-size: 13px; color: var(--hint); }
.legend__item { display: inline-flex; align-items: center; gap: 6px; }
.legend__dot { width: 9px; height: 9px; border-radius: 50%; }

/* активность за месяц */
.heatmap {
  display: grid; grid-template-columns: repeat(15, 1fr);
  gap: 4px; margin-top: 10px;
}
.heatmap__cell {
  aspect-ratio: 1; border-radius: 3px; background: var(--accent);
}

/* --- экран тренировки --- */

.session {
  display: flex; flex-direction: column;
  min-height: calc(100vh - 40px); gap: var(--gap);
}
.session__top { display: flex; align-items: center; gap: 10px; }
.session__bottom { margin-top: auto; padding-top: var(--gap); }

.iconbutton {
  width: 32px; height: 32px; flex: none;
  border: 0; border-radius: 50%;
  background: var(--surface); color: var(--text);
  font-size: 15px; line-height: 1; cursor: pointer;
}

.flashcard {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 8px;
  padding: 28px 18px; border-radius: 18px;
  background: var(--surface); text-align: center;
  touch-action: pan-y; user-select: none;
}
.flashcard__direction {
  font-size: 12px; color: var(--hint); text-transform: uppercase;
  letter-spacing: .04em; margin-bottom: 4px;
}
.flashcard__question { font-size: 30px; font-weight: 650; line-height: 1.2; }
.flashcard__answer { font-size: 23px; font-weight: 600; color: var(--accent); }
.flashcard__note { font-size: 15px; color: var(--hint); }
.flashcard__divider {
  width: 40px; height: 2px; border-radius: 1px;
  background: rgba(127,127,127,.3); margin: 10px 0;
}

.flashcard--ok { box-shadow: inset 0 0 0 2px var(--ok); }
.flashcard--almost { box-shadow: inset 0 0 0 2px var(--warn); }
.flashcard--bad { box-shadow: inset 0 0 0 2px #e5484d; }

.verdict { font-size: 15px; font-weight: 700; margin-bottom: 2px; }
.verdict--ok { color: var(--ok); }
.verdict--almost { color: var(--warn); }
.verdict--bad { color: #e5484d; }

.input {
  width: 100%; padding: 14px 16px;
  border: 2px solid transparent; border-radius: var(--radius);
  background: var(--surface); color: var(--text);
  font-family: inherit; font-size: 17px;
}
.input:focus { outline: none; border-color: var(--accent); }
.input::placeholder { color: var(--hint); }

.options { display: grid; gap: 8px; }
.option {
  width: 100%; padding: 14px 16px;
  border: 2px solid transparent; border-radius: var(--radius);
  background: var(--surface); color: var(--text);
  font-family: inherit; font-size: 16px; text-align: left; cursor: pointer;
  transition: border-color 150ms ease, opacity 150ms ease;
}
.option:active { opacity: .8; }
.option[disabled] { cursor: default; }
.option--right { border-color: var(--ok); color: var(--ok); font-weight: 600; }
.option--wrong { border-color: #e5484d; color: #e5484d; }
.option--dim { opacity: .45; }

.grades { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.grade {
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  padding: 13px 6px; border: 0; border-radius: var(--radius);
  background: var(--surface); color: var(--text);
  font-family: inherit; font-size: 13px; font-weight: 600; cursor: pointer;
}
.grade:active { opacity: .8; }
.grade__icon { font-size: 17px; line-height: 1; }
.grade--again { color: #e5484d; }
.grade--hard { color: var(--warn); }
.grade--good { color: var(--ok); }

.summary__mark { font-size: 48px; line-height: 1; }

/* --- настройки и онбординг --- */

.choices { display: flex; flex-wrap: wrap; gap: 8px; }
.choice {
  flex: 1 1 auto; min-width: 80px;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 12px 10px; border: 2px solid transparent; border-radius: var(--radius);
  background: var(--surface); color: var(--text);
  font-family: inherit; cursor: pointer;
}
.choice:active { opacity: .8; }
.choice--on { border-color: var(--accent); color: var(--accent); }
.choice__label { font-size: 16px; font-weight: 650; }
.choice__note { font-size: 12px; color: var(--hint); }
.choice--on .choice__note { color: var(--accent); opacity: .8; }

.dots { display: flex; justify-content: center; gap: 6px; margin-top: 4px; }
.dot { width: 7px; height: 7px; border-radius: 50%; background: rgba(127,127,127,.35); }
.dot--on { background: var(--accent); }

/* --- бейджи --- */

.badges { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.badge {
  flex: 1 1 96px; display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 12px 8px; border-radius: var(--radius);
  background: rgba(127,127,127,.12); text-align: center;
}
.badge--earned { background: rgba(46,184,114,.14); }
.badge__mark { font-size: 15px; font-weight: 700; color: var(--hint); }
.badge--earned .badge__mark { color: var(--ok); }
.badge__title { font-size: 13px; font-weight: 600; }
.badge__note { font-size: 11px; color: var(--hint); }

/* --- служебные экраны --- */

.notice { padding: 32px 16px; text-align: center; color: var(--hint); }
.notice code {
  display: block; margin-top: 12px; padding: 10px;
  background: var(--surface); border-radius: 10px;
  font-size: 13px; color: var(--text); word-break: break-all;
}

.skeleton {
  height: 72px; border-radius: var(--radius); background: var(--surface);
  animation: pulse 1.2s ease-in-out infinite;
}
@keyframes pulse { 50% { opacity: .5; } }
