/* Тема осознанно своя, а не из клиента Telegram: тёмный терминал с сеткой
   графика и биржевой палитрой. Фон задан явно, поэтому вид не зависит от того,
   светлая тема у пользователя или тёмная. */
:root {
  --bg: #0a0f15;
  --grid-line: rgba(125, 165, 205, .055);
  --panel: #141d27;
  --panel-2: #1b2733;
  --panel-line: rgba(140, 180, 220, .1);

  --text: #e9f0f7;
  --sub: #9fb0c1;
  --hint: #78899a;

  --up: #16c784;      /* рост */
  --down: #ea3943;    /* падение */

  --c1: #2f80ed;      /* рынки */
  --c2: #16c784;      /* брокер */
  --c3: #f0b90b;      /* график */
  --c4: #ea3943;      /* риск */
  --c5: #8b5cf6;      /* психология */
  --c6: #0fbfbf;      /* режим */

  --app-h: 100dvh;
}

/* Обязательно !important: классы ниже задают display и иначе перебивают [hidden]. */
[hidden] { display: none !important; }

* { box-sizing: border-box; }

/* overscroll-behavior гасит «резинку» и передачу прокрутки наружу:
   без неё докрутка до края внутреннего блока утягивает вниз всё окно. */
html, body { height: 100%; margin: 0; overflow: hidden; overscroll-behavior: none; }

/* Без этого WebView считает два быстрых нажатия по клавиатуре
   двойным тапом и увеличивает масштаб страницы. Жесты прокрутки
   и щипок при этом сохраняются. */
html { touch-action: manipulation; }

body {
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;

  /* Свечение сверху, сетка как на графике, тёмная основа */
  background-color: var(--bg);
  background-image:
    radial-gradient(130% 62% at 50% -12%, rgba(22, 199, 132, .16), transparent 62%),
    linear-gradient(var(--grid-line) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid-line) 1px, transparent 1px);
  background-size: 100% 100%, 30px 30px, 30px 30px;
  background-attachment: fixed;
}

.app { height: var(--app-h); max-width: 480px; margin: 0 auto; }

.screen {
  height: 100%;
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding-inline: 16px;
  padding-block: calc(14px + env(safe-area-inset-top, 0px)) calc(14px + env(safe-area-inset-bottom, 0px));
}

h1, h2 { margin: 0; text-wrap: balance; }
p { margin: 0; }

/* ---------- шапка ---------- */
.top { flex: 0 0 auto; }
.top-row { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.top-text { min-width: 0; }
.admin-btn {
  flex: 0 0 auto; width: 40px; height: 40px; border-radius: 12px;
  background: var(--panel); border: 1px solid var(--panel-line);
  color: var(--up); cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.admin-btn svg { width: 20px; height: 20px; display: block; }
.admin-btn:focus-visible { outline: 2px solid var(--up); outline-offset: 2px; }
.top h1 { font-size: 26px; line-height: 1.1; font-weight: 800; letter-spacing: -.015em; }
.greet { font-size: 13.5px; color: var(--sub); margin-top: 3px; }

/* ---------- карточка прогресса ---------- */
.stat {
  flex: 0 0 auto;
  background: linear-gradient(180deg, rgba(22, 199, 132, .07), rgba(255, 255, 255, .02));
  border: 1px solid var(--panel-line);
  border-radius: 18px;
  padding: 14px 16px 16px;
  display: flex;
  flex-direction: column;
  gap: 13px;
}

.stat-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.stat-text { min-width: 0; }
.stat-label {
  font-size: 10.5px; letter-spacing: .14em; text-transform: uppercase;
  font-weight: 700; color: var(--hint);
}
.stat-value { font-size: 14px; color: var(--sub); font-variant-numeric: tabular-nums; }
.stat-value b {
  font-size: 30px; font-weight: 800; color: var(--up); line-height: 1.05;
  letter-spacing: -.02em;
}

.stat-info {
  flex: 0 0 auto; width: 40px; height: 40px; border-radius: 50%;
  background: rgba(255, 255, 255, .06); border: 1px solid var(--panel-line);
  cursor: pointer; display: flex; align-items: center; justify-content: center;
}
.stat-info svg { width: 20px; height: 20px; display: block; stroke: var(--sub); }
.stat-info:focus-visible { outline: 2px solid var(--up); outline-offset: 2px; }

.pill {
  align-self: center; max-width: 100%;
  display: flex; align-items: center; justify-content: center; gap: 10px;
  background: linear-gradient(135deg, #16c784, #0fa5a0);
  color: #04120d; border: none; border-radius: 999px;
  padding: 13px 22px 13px 13px;
  font: inherit; font-size: 15.5px; font-weight: 800;
  cursor: pointer; white-space: nowrap;
  box-shadow: 0 10px 26px -10px rgba(22, 199, 132, .75);
}
.pill-icon {
  flex: 0 0 auto; width: 30px; height: 30px; border-radius: 50%;
  background: rgba(4, 18, 13, .18);
  display: flex; align-items: center; justify-content: center;
}
.pill-icon svg { width: 17px; height: 17px; display: block; stroke: #04120d; }
.pill:active { transform: scale(.98); }
.pill:focus-visible { outline: 2px solid var(--text); outline-offset: 3px; }

.stat-foot { display: flex; flex-direction: column; gap: 8px; }
.stat-next {
  font-size: 12px; color: var(--hint);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.bar { height: 6px; border-radius: 3px; background: rgba(255, 255, 255, .07); overflow: hidden; }
.bar-fill {
  height: 100%; width: 0; border-radius: 3px;
  background: linear-gradient(90deg, #16c784, #0fbfbf);
  transition: width .4s ease;
}

.warn { flex: 0 0 auto; font-size: 11.5px; color: var(--down); }

/* Салют при прохождении курса — поверх всего, кликам не мешает. */
#fx {
  position: fixed; inset: 0; width: 100%; height: 100%;
  pointer-events: none; z-index: 60;
}

/* Курс пройден: экран прокручивается целиком, сетка не зажата в остаток. */
#screen-home.is-complete { overflow-y: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; }
#screen-home.is-complete .grid { flex: 0 0 auto; overflow: visible; }

/* ---------- финальный экран (оффер) ---------- */
.final {
  flex: 0 0 auto;
  background: linear-gradient(160deg, rgba(22, 199, 132, .16), rgba(15, 191, 191, .06));
  border: 1px solid var(--up);
  border-radius: 18px;
  padding: 18px 16px;
  display: flex; flex-direction: column; gap: 10px;
  box-shadow: 0 12px 30px -16px rgba(22, 199, 132, .7);
}
.final-title { font-size: 17px; font-weight: 800; color: var(--text); line-height: 1.25; }
.final-text { font-size: 14px; color: var(--sub); line-height: 1.5; }
.final-btn {
  margin-top: 2px; width: 100%; border: none; cursor: pointer;
  background: linear-gradient(135deg, #16c784, #0fa5a0);
  color: #04120d; border-radius: 14px; padding: 15px 16px;
  font: inherit; font-size: 15.5px; font-weight: 800;
  box-shadow: 0 10px 24px -10px rgba(22, 199, 132, .8);
}
.final-btn:active { transform: scale(.98); }
.final-btn:focus-visible { outline: 2px solid var(--text); outline-offset: 3px; }

/* ---------- сетка уроков ---------- */
.grid {
  flex: 1 1 auto; min-height: 0; overflow-y: auto; overscroll-behavior: contain;
  list-style: none; margin: 0; padding: 0;
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  grid-auto-rows: minmax(104px, 1fr);
  gap: 12px;
}
.grid > li { min-height: 0; }

.tile {
  position: relative;
  width: 100%; height: 100%; cursor: pointer;
  font: inherit; color: inherit;
  background: var(--panel);
  border: 1px solid var(--panel-line);
  border-radius: 18px;
  padding: 12px 10px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px;
}
.tile:active { transform: scale(.98); }
.tile:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.tile.is-next {
  border-color: var(--accent);
  background: var(--panel);
  background: linear-gradient(180deg, color-mix(in srgb, var(--accent) 14%, var(--panel)), var(--panel));
}

.tile-icon {
  flex: 0 0 auto; width: 50px; height: 50px; border-radius: 15px;
  background: var(--accent);
  background: linear-gradient(145deg, var(--accent), color-mix(in srgb, var(--accent) 62%, #000));
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 8px 20px -8px var(--accent), inset 0 1px 0 rgba(255, 255, 255, .25);
}
.tile-icon svg { width: 26px; height: 26px; display: block; }

/* flex: 0 0 auto обязателен — иначе подпись сжимается и обрезается по высоте */
.tile-title {
  flex: 0 0 auto;
  font-size: 13.5px; font-weight: 700; line-height: 1.2; text-align: center;
  color: var(--text);
}
.tile.is-done .tile-title { color: var(--sub); }

.tile.is-locked { opacity: .55; }
.tile.is-locked .tile-icon { background: var(--panel-2); box-shadow: none; }
.tile.is-locked .tile-icon svg { stroke: var(--hint); }

.tile-lock {
  position: absolute; top: 8px; right: 9px;
  font-size: 13px; color: var(--hint); line-height: 1;
}

.tile-check {
  position: absolute; top: 8px; right: 8px;
  width: 20px; height: 20px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 800; color: #04120d; background: var(--up);
}

/* ---------- экран урока ---------- */
.lesson-top { display: flex; align-items: center; gap: 10px; }
.back {
  flex: 0 0 auto; width: 36px; height: 36px; border-radius: 50%;
  background: var(--panel); border: 1px solid var(--panel-line);
  font-size: 17px; line-height: 1; color: var(--accent); cursor: pointer;
}
.back:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.l-index {
  font-size: 10.5px; letter-spacing: .14em; text-transform: uppercase;
  font-weight: 800; color: var(--accent);
}

.scroll {
  flex: 1 1 auto; min-height: 0; overflow-y: auto; overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  display: flex; flex-direction: column; gap: 12px;
  padding-bottom: 4px;
}

/* Обложка урока — она же кнопка запуска видео.
   Нет картинки — показывается цветная заглушка, кнопка остаётся. */
.cover {
  flex: 0 0 auto; position: relative; display: block;
  /* Обложки уроков квадратные (1:1) — показываем целиком, без обрезки. */
  aspect-ratio: 1 / 1; max-width: 100%;
  width: min(100%, 62vh);
  margin-inline: auto;
  border-radius: 16px; overflow: hidden; text-decoration: none;
  border: 1px solid var(--panel-line);
  background: var(--accent);
  background: linear-gradient(145deg, var(--accent), color-mix(in srgb, var(--accent) 45%, #000));
}
.cover-img { width: 100%; height: 100%; object-fit: cover; display: block; }
.cover-stub {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center; padding: 16px;
  font-size: 13px; font-weight: 700; letter-spacing: .14em; text-transform: uppercase;
  color: rgba(255, 255, 255, .85); text-align: center;
}

/* Затемнение снизу, чтобы подпись читалась на любой картинке */
.cover-scrim {
  position: absolute; inset: 0;
  background: linear-gradient(to top, rgba(4, 8, 12, .85) 0%, rgba(4, 8, 12, .3) 38%, rgba(4, 8, 12, 0) 68%);
}

.cover-play {
  position: absolute; left: 12px; right: 12px; bottom: 12px;
  display: flex; align-items: center; gap: 11px;
  background: rgba(10, 15, 21, .55);
  border: 1px solid rgba(255, 255, 255, .18);
  border-radius: 999px; padding: 8px 16px 8px 8px;
  backdrop-filter: blur(8px);
}
.play-dot {
  flex: 0 0 auto; width: 36px; height: 36px; border-radius: 50%;
  background: var(--up); color: #04120d;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 6px 16px -6px var(--up);
}
.play-dot svg { width: 18px; height: 18px; display: block; margin-left: 2px; }
.play-text {
  font-size: 14.5px; font-weight: 700; color: #fff;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.cover:active { transform: scale(.99); }
.cover:focus-visible { outline: 2px solid var(--up); outline-offset: 3px; }

ul.links { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
ul.links a, ul.links span {
  display: block; text-decoration: none;
  background: var(--panel); border: 1px solid var(--panel-line);
  border-radius: 12px; padding: 12px 14px;
  font-size: 14px; font-weight: 600; color: var(--accent);
}
ul.links span { color: var(--hint); font-weight: 500; }

#l-title { font-size: 20px; line-height: 1.2; font-weight: 800; }
.l-lead { font-size: 13.5px; color: var(--sub); }

.video {
  display: block; text-align: center; text-decoration: none;
  background: var(--accent); color: #fff;
  border-radius: 999px; padding: 14px 16px; font-size: 15px; font-weight: 700;
  box-shadow: 0 10px 24px -10px var(--accent);
}

.prose {
  background: var(--panel); border: 1px solid var(--panel-line);
  border-radius: 16px; padding: 14px; font-size: 14.5px; color: var(--text);
}
.prose p + p { margin-top: 10px; }

ul.terms { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 6px; }
ul.terms li {
  font-size: 12.5px; background: var(--panel-2); color: var(--sub);
  border: 1px solid var(--panel-line); border-radius: 999px; padding: 5px 11px;
}

.qa { background: var(--panel); border: 1px solid var(--panel-line); border-radius: 16px; padding: 14px; }
.q { font-size: 14.5px; }
.reveal {
  margin-top: 11px; background: var(--panel-2); border: 1px solid var(--panel-line);
  border-radius: 999px; padding: 9px 16px; font: inherit; font-size: 13.5px;
  font-weight: 700; color: var(--accent); cursor: pointer;
}
.reveal:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.a {
  margin-top: 11px; padding-top: 11px; border-top: 1px solid var(--panel-line);
  font-size: 14px; color: var(--sub);
}

/* ---- ввод кода: панель поверх затемнения ---- */
.bottom { flex: 0 0 auto; }

.gate-open { display: flex; align-items: center; justify-content: center; gap: 9px; }
.lock-ico { display: flex; }
.lock-ico svg { width: 18px; height: 18px; display: block; }

.scrim {
  position: fixed; inset: 0; z-index: 20;
  background: rgba(3, 7, 11, .68);
  opacity: 0; transition: opacity .24s ease;
}
.scrim.open { opacity: 1; }

.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 21;
  margin-inline: auto; width: 100%; max-width: 480px;
  background: var(--panel-2);
  border: 1px solid var(--panel-line); border-bottom: none;
  border-top: 2px solid var(--accent);
  border-radius: 22px 22px 0 0;
  padding: 10px 16px calc(16px + env(safe-area-inset-bottom, 0px));
  display: flex; flex-direction: column; gap: 10px;
  box-shadow: 0 -22px 50px -24px rgba(0, 0, 0, .9);
  transform: translateY(100%);
  transition: transform .26s cubic-bezier(.22, .8, .3, 1);
}
.sheet.open { transform: translateY(0); }

.sheet-grip {
  width: 38px; height: 4px; border-radius: 2px;
  background: var(--panel-line); align-self: center; margin-bottom: 2px;
}
.sheet-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.sheet-title { font-size: 15px; font-weight: 700; color: var(--text); }
.sheet-close {
  flex: 0 0 auto; width: 32px; height: 32px; border-radius: 50%;
  background: var(--panel); border: 1px solid var(--panel-line);
  color: var(--hint); font-size: 14px; line-height: 1; cursor: pointer;
}
.sheet-close:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.gate-hint { font-size: 12.5px; line-height: 1.4; color: var(--hint); text-align: center; }
.gate-hint.err { color: var(--down); }
.gate-hint.ok { color: var(--up); }

.cells { display: flex; justify-content: center; gap: 9px; }
.cell {
  width: 46px; height: 54px; border-radius: 13px;
  background: var(--panel); border: 1.5px solid var(--panel-line);
  display: flex; align-items: center; justify-content: center;
  font-size: 24px; font-weight: 800; color: var(--text);
  font-variant-numeric: tabular-nums;
}
.cell.filled { border-color: var(--accent); }
.cell.caret { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent); }
.cells.err .cell { border-color: var(--down); color: var(--down); animation: nudge .3s ease; }
.cells.ok .cell { border-color: var(--up); color: var(--up); }

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

.pad {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px;
  /* длинное нажатие по клавише не должно выделять текст и звать меню */
  user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
}
.key {
  height: 48px; border-radius: 13px; cursor: pointer;
  background: var(--panel); border: 1px solid var(--panel-line);
  font: inherit; font-size: 21px; font-weight: 700; color: var(--text);
  font-variant-numeric: tabular-nums;
  display: flex; align-items: center; justify-content: center;
}
.key:active { background: var(--panel-2); transform: scale(.97); }
.key:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.key.wide { grid-column: span 1; }
.key.act { color: var(--up); font-size: 15px; font-weight: 800; }
.key.del { color: var(--hint); font-size: 18px; }
.key[disabled] { opacity: .4; cursor: default; }

@media (max-height: 700px) {
  .cell { width: 42px; height: 46px; font-size: 21px; }
  .key { height: 42px; font-size: 19px; }
}
.primary {
  width: 100%; background: var(--accent); color: #fff; border: none;
  border-radius: 999px; padding: 15px 16px;
  font: inherit; font-size: 15px; font-weight: 800; cursor: pointer;
  box-shadow: 0 10px 24px -10px var(--accent);
}
.primary.is-done {
  background: var(--panel); color: var(--sub);
  border: 1px solid var(--panel-line); box-shadow: none;
}
.primary:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.primary:active, .video:active { transform: scale(.98); }

/* ---------- экран аналитики ---------- */
.kpis { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.kpi {
  background: var(--panel); border: 1px solid var(--panel-line);
  border-radius: 14px; padding: 12px 13px;
  display: flex; flex-direction: column; gap: 2px;
}
.kpi-num { font-size: 24px; font-weight: 800; line-height: 1.1; font-variant-numeric: tabular-nums; }
.kpi-label { font-size: 11.5px; color: var(--hint); }
.kpi.good .kpi-num { color: var(--up); }
.kpi.bad .kpi-num { color: var(--down); }

.panel {
  background: var(--panel); border: 1px solid var(--panel-line);
  border-radius: 16px; padding: 14px;
}
.panel-label {
  font-size: 10.5px; letter-spacing: .14em; text-transform: uppercase;
  font-weight: 800; color: var(--hint); margin-bottom: 6px;
}
.panel-hint { font-size: 11.5px; color: var(--hint); line-height: 1.45; }

.funnel { display: flex; flex-direction: column; gap: 12px; margin-top: 12px; }
.f-row { display: flex; flex-direction: column; gap: 6px; }
.f-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
.f-name { font-size: 13px; font-weight: 600; }
.f-name span { color: var(--hint); font-weight: 500; }
.f-nums { font-size: 12px; color: var(--sub); font-variant-numeric: tabular-nums; white-space: nowrap; }
.f-track {
  position: relative; height: 22px; border-radius: 6px;
  background: rgba(255, 255, 255, .05); overflow: hidden;
}
.f-open { position: absolute; inset: 0 auto 0 0; background: rgba(255, 255, 255, .14); }
.f-done { position: absolute; inset: 0 auto 0 0; background: linear-gradient(90deg, #16c784, #0fbfbf); }
.f-foot { display: flex; gap: 8px; flex-wrap: wrap; }
.chip {
  font-size: 11px; font-weight: 700; border-radius: 999px; padding: 3px 9px;
  background: rgba(255, 255, 255, .06); color: var(--sub);
}
.chip.warn-chip { background: rgba(234, 57, 67, .16); color: #ff8d8d; }

.people { list-style: none; margin: 8px 0 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.people li {
  display: flex; align-items: baseline; justify-content: space-between; gap: 10px;
  font-size: 13px; border-bottom: 1px solid var(--panel-line); padding-bottom: 8px;
}
.people li:last-child { border-bottom: none; padding-bottom: 0; }
.p-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.p-meta { font-size: 11.5px; color: var(--hint); white-space: nowrap; }

.empty { font-size: 13px; color: var(--hint); }

/* источники / крео */
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 6px; }
.panel-head .panel-label { margin-bottom: 0; }
.csv-btn {
  flex: 0 0 auto; font-size: 11.5px; font-weight: 700; color: var(--bg);
  background: linear-gradient(90deg, #16c784, #0fbfbf);
  border: none; border-radius: 999px; padding: 6px 12px; cursor: pointer;
}
.csv-btn:disabled { opacity: .6; }
.src-cap { font-size: 11.5px; color: var(--hint); margin: 10px 0 4px; font-variant-numeric: tabular-nums; }
.sources { display: flex; flex-direction: column; gap: 12px; margin-top: 6px; }
.src-row { display: flex; flex-direction: column; gap: 6px; }
.src-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
.src-name { font-size: 13px; font-weight: 600; word-break: break-word; }
.src-users { font-size: 12px; color: var(--sub); white-space: nowrap; font-variant-numeric: tabular-nums; }
.src-track { position: relative; height: 8px; border-radius: 6px; background: rgba(255, 255, 255, .05); overflow: hidden; }
.src-fill { position: absolute; inset: 0 auto 0 0; background: linear-gradient(90deg, #f0b90b, #f8d33a); }
.src-foot { display: flex; gap: 8px; flex-wrap: wrap; }

@media (prefers-reduced-motion: reduce) {
  .bar-fill { transition: none; }
  .tile:active, .primary:active, .pill:active, .cover:active, .key:active, .final-btn:active { transform: none; }
  .cells.err .cell { animation: none; }
  .sheet { transition: none; }
  .scrim { transition: none; }
}

@media (max-height: 620px) {
  .tile-icon { width: 42px; height: 42px; border-radius: 13px; }
  .tile-icon svg { width: 22px; height: 22px; }
  .grid { grid-auto-rows: minmax(92px, 1fr); }
}
