/*
 * Экран упражнения НОТОГРАМ, компоновка «Стан главный».
 * Отдельный файл: пока идёт переход на v3, старые стили не трогаем.
 * Оформление одно — светлая классика.
 */

.lv3 {
  --lv3-bg: #f7f7fb;
  --lv3-surface: #fff;
  --lv3-text: #1f2430;
  --lv3-text-2: #4a5060;
  --lv3-text-3: #747c8b;
  --lv3-violet: #7357ef;
  --lv3-violet-soft: #ece8ff;
  --lv3-mint: #16754e;
  --lv3-mint-soft: #e2f6ec;
  --lv3-rose: #c02b3a;
  --lv3-border: rgba(31, 36, 48, 0.09);
  --lv3-ink: #777382;
  --lv3-gap: 7px;

  position: relative;
  display: grid;
  width: 100%;
  height: 100%;
  /* Все четыре выреза: в альбомной ориентации панель навигации Samsung стоит
     вертикально у правого края и перекрывала колонку с диаграммой. */
  padding:
    calc(7px + env(safe-area-inset-top, 0px))
    calc(9px + env(safe-area-inset-right, 0px))
    calc(7px + env(safe-area-inset-bottom, 0px))
    calc(9px + env(safe-area-inset-left, 0px));
  gap: var(--lv3-gap);
  grid-template-columns: minmax(0, 1fr) 216px;
  grid-template-rows: auto minmax(0, 1fr) minmax(92px, 28%) auto;
  grid-template-areas:
    "hud hud"
    "staff side"
    "answer answer"
    "map map";
  background: var(--lv3-bg);
  color: var(--lv3-text);
  font-family: Onest, system-ui, sans-serif;
  overflow: hidden;
}

.lv3[data-layout="compact"] {
  --lv3-gap: 5px;
  grid-template-columns: minmax(0, 1fr) 178px;
}

/*
 * Низкий вьюпорт (у телефона видны панели браузера): пол клавиш ответа ниже,
 * иначе всё сжатие достаётся стану и он превращается в полоску, а карта
 * 88 клавиш уезжает за нижнюю границу.
 */
@media (orientation: landscape) and (max-height: 420px) {
  .lv3 { grid-template-rows: auto minmax(84px, 1fr) minmax(64px, 26%) auto; }
}

@media (orientation: landscape) and (max-height: 340px) {
  .lv3 {
    --lv3-gap: 4px;
    grid-template-rows: auto minmax(70px, 1fr) minmax(54px, 24%) auto;
  }

  /* Карта клавиш ужимается вместе со всем остальным, а не режется по краю. */
  .keymap-octaves { height: 9px; margin-bottom: 2px; }
  .keymap-keys { height: 24px; }
}

/* ---------- HUD ---------- */

.lv3-hud {
  grid-area: hud;
  /* Над затемнением: выйти и поставить на паузу можно в любой момент,
     даже когда открыта карточка знакомства или награды. */
  position: relative;
  z-index: 6;
  display: flex;
  min-height: 28px;
  gap: 8px;
  align-items: center;
}

.lv3-close,
.lv3-pause {
  display: grid;
  width: 30px;
  height: 30px;
  flex: 0 0 auto;
  place-items: center;
  border: 1px solid var(--lv3-border);
  border-radius: 10px;
  background: var(--lv3-surface);
  color: var(--lv3-text-2);
  font: inherit;
  font-size: 0.8rem;
  cursor: pointer;
}

.lv3-close:focus-visible,
.lv3-pause:focus-visible,
.lv3-card-action:focus-visible,
.ak-white:focus-visible {
  outline: 2px solid var(--lv3-violet);
  outline-offset: 2px;
}

.lv3-unit {
  overflow: hidden;
  color: var(--lv3-text-3);
  font-size: 0.58rem;
  font-weight: 800;
  letter-spacing: 0.11em;
  text-transform: uppercase;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.lv3-spacer { flex: 1; }

.lv3-chip {
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 0.62rem;
  font-weight: 800;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.lv3-chip--streak { background: var(--lv3-violet-soft); color: var(--lv3-violet); }
.lv3-chip--speed { background: var(--lv3-mint-soft); color: var(--lv3-mint); }
.lv3-chip--score { background: #fff3c8; color: #765400; }

/* ---------- стан ---------- */

.lv3-staff {
  grid-area: staff;
  display: grid;
  min-height: 0;
  place-items: center;
  overflow: hidden;
  border-radius: 13px;
  background: var(--lv3-surface);
}

.grand-staff { display: block; width: 100%; height: 100%; }
.staff-line,
.staff-ledger,
.staff-bar { fill: none; stroke: var(--lv3-ink); stroke-width: 1.1; }
/* Акколада — заливка: у настоящей скобки переменная толщина, обводкой её не задать. */
.staff-brace { fill: var(--lv3-ink); stroke: none; }
.staff-clef { fill: var(--lv3-text); stroke: none; font-family: "Segoe UI Symbol", "Noto Music", serif; }
/*
 * Поток нот. Будущие серые, текущая фиолетовая, сыгранные — зелёная или
 * красная. Цвет ноты и есть подсказка «нажми сейчас именно эту».
 */
.staff-note ellipse { fill: var(--lv3-text-3); stroke: none; }
.staff-note line { stroke: var(--lv3-text-3); stroke-width: 2; }

.staff-note[data-state="upcoming"] { opacity: 0.42; }

.staff-note[data-state="current"] ellipse { fill: var(--lv3-violet); }
.staff-note[data-state="current"] line { stroke: var(--lv3-violet); stroke-width: 2.4; }

.staff-note[data-state="done-correct"] ellipse { fill: var(--lv3-mint); }
.staff-note[data-state="done-correct"] line { stroke: var(--lv3-mint); }

.staff-note[data-state="done-wrong"] ellipse { fill: var(--lv3-rose); }
.staff-note[data-state="done-wrong"] line { stroke: var(--lv3-rose); }

.lv3-staff { position: relative; }

/* Лопок рисуется поверх стана отдельным слоем. Он не является ещё одной нотой
   и не участвует в конвейере, поэтому после ответа ничего лишнего не выезжает. */
.lv3-note-burst {
  --burst-color: var(--lv3-mint);
  position: absolute;
  z-index: 3;
  width: 1px;
  height: 1px;
  pointer-events: none;
}
.lv3-note-burst.is-wrong { --burst-color: var(--lv3-rose); }
.lv3-note-burst::before {
  position: absolute;
  width: 17px;
  height: 13px;
  border-radius: 50%;
  background: var(--burst-color);
  content: "";
  transform: translate(-50%, -50%);
  animation: lv3-burst-core 300ms ease-out forwards;
}
.lv3-note-burst i {
  position: absolute;
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: var(--burst-color);
  transform: translate(-50%, -50%) rotate(var(--burst-angle)) translateX(4px);
  animation: lv3-burst-particle 430ms ease-out forwards;
}
@keyframes lv3-burst-core {
  0% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
  55% { opacity: 1; transform: translate(-50%, -50%) scale(1.35); }
  100% { opacity: 0; transform: translate(-50%, -50%) scale(.15); }
}
@keyframes lv3-burst-particle {
  from { opacity: 1; transform: translate(-50%, -50%) rotate(var(--burst-angle)) translateX(4px); }
  to { opacity: 0; transform: translate(-50%, -50%) rotate(var(--burst-angle)) translateX(24px); }
}

/*
 * Группа нот едет справа налево. Плавность даёт переход: интерфейс правит
 * transform каждый кадр, а ответ подтягивает поток на часть слота — без
 * перехода этот рывок был бы заметен.
 */
.staff-notes { transition: transform 140ms linear; }

.staff-cursor { stroke: rgba(115, 87, 239, 0.28); stroke-width: 2; stroke-linecap: round; }

/* ---------- правая зона ---------- */

.lv3-side {
  grid-area: side;
  overflow: hidden;
  display: grid;
  min-height: 0;
  gap: 5px;
  grid-template-rows: minmax(0, 1fr) auto;
  padding: 6px;
  border-radius: 13px;
  background: var(--lv3-surface);
}

/* overflow: hidden — страховка: промах замера обрежется по блоку, а не наедет. */
.lv3-ring { display: grid; width: 100%; min-width: 0; max-width: 100%; min-height: 0; overflow: hidden; place-items: center; }
.lv3-ring svg { display: block; width: auto; max-width: 100%; max-height: 100%; }
.lv3-ring-track { fill: none; stroke: rgba(115, 87, 239, 0.14); }
.lv3-ring-value { fill: none; stroke: var(--lv3-violet); stroke-linecap: round; transition: stroke-dashoffset 0.35s ease; }
.lv3-ring-number { fill: var(--lv3-violet); stroke: none; font-family: Comfortaa, sans-serif; font-weight: 700; }
.lv3-ring-sign { fill: var(--lv3-violet); stroke: none; }

.lv3-stats { display: grid; min-width: 0; margin: 0; gap: 3px; }
.lv3-stats div { display: flex; gap: 8px; align-items: baseline; justify-content: space-between; }
.lv3-stats dt { color: var(--lv3-text-3); font-size: 0.62rem; }
.lv3-stats dd { margin: 0; font-size: 0.72rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.lv3-opened { display: flex; min-width: 0; max-width: 100%; gap: 3px; align-items: center; overflow: hidden; }
.lv3-opened i { display: block; width: 9px; height: 5px; border-radius: 999px; background: rgba(115, 87, 239, 0.18); }
.lv3-opened i.on { background: var(--lv3-violet); }

/* ---------- панель ответа ---------- */

.lv3-answer { grid-area: answer; min-height: 0; }

.answer-keyboard { position: relative; display: flex; width: 100%; height: 100%; }

.ak-white {
  position: relative;
  display: grid;
  flex: 1 1 0;
  min-width: 0;
  align-content: end;
  justify-items: center;
  padding: 0 2px 7px;
  border: 1px solid rgba(31, 36, 48, 0.14);
  border-bottom-width: 4px;
  border-radius: 0 0 5px 5px;
  background: linear-gradient(180deg, #fff 68%, #f3f2f9);
  color: var(--lv3-text);
  font: inherit;
  cursor: pointer;
}

.ak-white + .ak-white { border-left: none; }
.ak-white:first-child { border-top-left-radius: 4px; }
.ak-white:last-child { border-top-right-radius: 4px; }
.ak-white strong { font-family: Comfortaa, sans-serif; font-size: 0.9rem; font-weight: 700; line-height: 1.1; }
.ak-white small { color: var(--lv3-text-3); font-size: 0.55rem; }
.ak-white:active:not(.is-locked) { background: var(--lv3-violet-soft); }

.ak-octave {
  position: absolute;
  top: 5px;
  left: 5px;
  color: var(--lv3-text-3);
  font-size: 0.5rem;
  font-weight: 800;
}

.ak-white.is-locked {
  border-color: rgba(31, 36, 48, 0.07);
  background: #f4f3f8;
  color: rgba(31, 36, 48, 0.26);
  cursor: default;
}

.ak-white.is-locked small { color: rgba(31, 36, 48, 0.2); }
.ak-white.is-new { border-color: rgba(115, 87, 239, 0.55); background: linear-gradient(180deg, #fff 58%, var(--lv3-violet-soft)); }
.ak-white.is-target { box-shadow: inset 0 0 0 2px var(--lv3-mint); }
.ak-white.is-played { box-shadow: inset 0 0 0 2px var(--lv3-rose); }

.ak-black {
  position: absolute;
  top: 0;
  height: 56%;
  border-radius: 0 0 4px 4px;
  background: #2a2733;
  pointer-events: none;
}

.ak-split { position: absolute; top: 0; bottom: 0; width: 2px; background: rgba(115, 87, 239, 0.35); pointer-events: none; }

/* ---------- карта 88 клавиш ---------- */

.lv3-map { grid-area: map; min-height: 0; }

.keymap-88 { padding: 4px 6px 5px; border-radius: 12px; background: var(--lv3-surface); }
.keymap-octaves { position: relative; height: 11px; margin-bottom: 3px; }

.km-octave {
  position: absolute;
  top: 0;
  overflow: hidden;
  padding-left: 4px;
  border-left: 1px solid rgba(31, 36, 48, 0.16);
  color: var(--lv3-text-3);
  font-size: 0.5rem;
  font-weight: 800;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.km-octave.is-current { border-left-color: var(--lv3-violet); color: var(--lv3-violet); }

.keymap-keys { position: relative; display: flex; height: 31px; }
.km-white { position: relative; flex: 1 1 0; border: 1px solid rgba(31, 36, 48, 0.12); border-radius: 0 0 3px 3px; background: #fff; }
.km-white.is-outside { border-color: rgba(31, 36, 48, 0.07); background: #edecf3; }
.km-white.is-range { background: #fbfaff; }
.km-white.is-current { box-shadow: inset 0 -7px 0 rgba(115, 87, 239, 0.22); }
.km-black { position: absolute; top: 0; height: 60%; border-radius: 0 0 2px 2px; background: #2a2733; }
.km-black.is-outside { background: #9a97a6; }
.km-white.is-target, .km-black.is-target { box-shadow: inset 0 0 0 2px var(--lv3-mint); }
.km-white.is-played, .km-black.is-played { box-shadow: inset 0 0 0 2px var(--lv3-rose); }

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

.lv3-overlay {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: grid;
  padding: 16px;
  place-items: center;
  background: rgba(31, 36, 48, 0.42);
}

.lv3-overlay[hidden] { display: none; }

/*
 * Экран не повёрнут: содержимое занятия скрыто целиком, чтобы за просьбой
 * повернуть не мельтешил сплющенный стан. Шапка остаётся — из неё выходят.
 */
.lv3[data-blocked] .lv3-staff,
.lv3[data-blocked] .lv3-side,
.lv3[data-blocked] .lv3-answer,
.lv3[data-blocked] .lv3-map,
.lv3[data-blocked] .lv3-chip,
.lv3[data-blocked] .lv3-pause { visibility: hidden; }

.lv3[data-blocked] .lv3-overlay { background: var(--lv3-bg); }

.lv3-card {
  display: grid;
  width: min(420px, 100%);
  max-height: 100%;
  gap: 8px;
  overflow-y: auto;
  padding: 18px 20px;
  border-radius: 18px;
  background: var(--lv3-surface);
  text-align: center;
}

.lv3-card-kicker {
  color: var(--lv3-text-3);
  font-size: 0.58rem;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.lv3-card h2 { margin: 0; font-family: Comfortaa, sans-serif; font-size: 1.15rem; }
.lv3-card p { margin: 0; color: var(--lv3-text-2); font-size: 0.82rem; line-height: 1.45; }
.lv3-score-result { padding: 8px 12px; border-radius: 12px; background: #fff7d7; color: #604600 !important; }

/* Иконка поворота: телефон со стрелкой, тем же фиолетовым, что и акценты. */
.lv3-rotate-icon { width: 74px; height: 74px; margin: 2px auto 0; color: var(--lv3-violet); }
.lv3-rotate-hint { color: var(--lv3-text-3); font-size: 0.72rem; }
.lv3-card-staff { width: 100%; }
.lv3-card-staff .grand-staff { width: 100%; height: auto; max-height: 190px; }

.lv3-card-action {
  margin-top: 4px;
  padding: 12px 22px;
  border: none;
  border-radius: 999px;
  background: var(--lv3-violet);
  color: #fff;
  font: inherit;
  font-weight: 800;
  cursor: pointer;
}

.lv3-card--promoted h2 { color: var(--lv3-violet); }
.lv3-card--demoted h2 { color: var(--lv3-rose); }

/* Празднование скромное и отключается системной настройкой. */
.lv3-card--promoted.is-celebrating { animation: lv3-pop 0.42s ease-out; }

@keyframes lv3-pop {
  0% { transform: scale(0.92); }
  60% { transform: scale(1.03); }
  100% { transform: scale(1); }
}

@media (prefers-reduced-motion: reduce) {
  .lv3-card--promoted.is-celebrating { animation: none; }
  .lv3-ring-value,
  .staff-notes { transition: none; }
  .lv3-note-burst::before,
  .lv3-note-burst i { animation-duration: 0.01ms; }
}

/* ---------- включение в приложение ---------- */

/*
 * Экран v3 живёт поверх приложения: пока идёт переход, старый интерфейс
 * остаётся на месте и продолжает работать.
 */
.lv3-root {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: var(--lv3-bg, #f7f7fb);
}

.lv3-root[hidden] { display: none; }

body.lv3-open { overflow: hidden; }

/* ---------- выбор режима игры ---------- */

.lv3-mode-root {
  position: fixed;
  inset: 0;
  z-index: 58;
  overflow: auto;
  background:
    radial-gradient(circle at 15% 10%, rgba(115, 87, 239, 0.13), transparent 28rem),
    radial-gradient(circle at 90% 85%, rgba(22, 117, 78, 0.1), transparent 30rem),
    #f7f7fb;
  color: #1f2430;
  font-family: Onest, system-ui, sans-serif;
}

.lv3-mode-root[hidden] { display: none; }
body.lv3-mode-open { overflow: hidden; }

.play-mode-screen {
  width: min(100%, 1080px);
  min-height: 100dvh;
  margin: 0 auto;
  padding: calc(18px + env(safe-area-inset-top, 0px))
    calc(18px + env(safe-area-inset-right, 0px))
    calc(24px + env(safe-area-inset-bottom, 0px))
    calc(18px + env(safe-area-inset-left, 0px));
}

.play-mode-head {
  display: grid;
  margin-bottom: 20px;
  gap: 12px;
  grid-template-columns: 46px minmax(0, 1fr) 46px;
  align-items: center;
}

.play-mode-head > div { min-width: 0; }
.play-mode-head span,
.program-speed > div > span,
.program-modules__head span {
  color: #747c8b;
  font-size: 0.65rem;
  font-weight: 800;
  letter-spacing: 0.12em;
}
.play-mode-head h1 { margin: 2px 0 0; font-family: Unbounded, sans-serif; font-size: clamp(1.45rem, 4vw, 2.4rem); }

.play-mode-back,
.play-mode-close {
  display: grid;
  width: 46px;
  height: 46px;
  place-items: center;
  border: 1px solid rgba(31, 36, 48, 0.09);
  border-radius: 15px;
  background: #fff;
  color: #4a5060;
  font: inherit;
  font-size: 1.15rem;
  cursor: pointer;
}
.play-mode-head > .play-mode-close:last-child { grid-column: 3; }

.play-kind-grid { display: grid; gap: 14px; }
.play-kind-card {
  display: grid;
  min-height: 190px;
  padding: 22px;
  gap: 14px;
  grid-template-columns: 58px minmax(0, 1fr);
  grid-template-rows: 1fr auto;
  border: 1px solid rgba(31, 36, 48, 0.08);
  border-radius: 24px;
  color: #fff;
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.play-kind-card--route { background: linear-gradient(145deg, #7357ef, #5132c5); }
.play-kind-card--personal { background: linear-gradient(145deg, #16754e, #0d5136); }
.play-kind-card__icon { display: grid; width: 58px; height: 58px; place-items: center; border-radius: 18px; background: rgba(255,255,255,.16); font-size: 1.7rem; }
.play-kind-card__icon svg { width: 29px; height: 29px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.play-kind-card__copy { display: grid; min-width: 0; align-content: start; gap: 7px; }
.play-kind-card__copy strong { font-family: Unbounded, sans-serif; font-size: 1.2rem; }
.play-kind-card__copy small { max-width: 38rem; font-size: 0.84rem; line-height: 1.45; opacity: .88; }
.play-kind-card__meta { grid-column: 1 / -1; justify-self: start; padding: 6px 10px; border-radius: 999px; background: rgba(255,255,255,.15); font-size: .72rem; font-weight: 800; }

.route-score-formula {
  display: grid;
  margin: 14px 0 0;
  padding: 11px 14px;
  gap: 8px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  border: 1px solid rgba(31, 36, 48, 0.07);
  border-radius: 17px;
  background: rgba(255,255,255,.82);
}
.route-score-formula div { display: flex; min-width: 0; gap: 8px; justify-content: space-between; }
.route-score-formula dt { overflow: hidden; color: #747c8b; font-size: .68rem; white-space: nowrap; text-overflow: ellipsis; }
.route-score-formula dd { margin: 0; color: #5b3ed1; font-size: .7rem; font-weight: 800; white-space: nowrap; }

.play-arcade-link {
  display: grid;
  width: 100%;
  min-height: 68px;
  margin-top: 14px;
  padding: 12px 16px;
  gap: 12px;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  border: 1px solid rgba(31, 36, 48, 0.08);
  border-radius: 19px;
  background: #fff;
  color: #1f2430;
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.play-arcade-link > span:first-child { display: grid; width: 42px; height: 42px; place-items: center; border-radius: 13px; background: #ece8ff; color: #7357ef; }
.play-arcade-link > span:first-child svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.play-arcade-link > span:nth-child(2) { display: grid; }
.play-arcade-link small { color: #747c8b; }
.play-arcade-link b { color: #7357ef; font-size: .78rem; }

.personal-program { display: grid; gap: 18px; }
.program-speed,
.program-modules { padding: 17px; border: 1px solid rgba(31, 36, 48, 0.07); border-radius: 22px; background: #fff; }
.program-speed h2,
.program-modules h2 { margin: 3px 0 0; font-family: Comfortaa, sans-serif; font-size: 1.15rem; }
.speed-choice-row { display: grid; margin-top: 14px; gap: 8px; grid-template-columns: repeat(2, minmax(0, 1fr)); }
.speed-choice {
  min-height: 72px;
  padding: 12px 8px;
  border: 1px solid #e4e1ef;
  border-radius: 15px;
  background: #f7f7fb;
  color: #4a5060;
  font: inherit;
  cursor: pointer;
}
.speed-choice strong,
.speed-choice small { display: block; }
.speed-choice strong { font-size: .83rem; }
.speed-choice small { margin-top: 2px; color: #747c8b; }
.speed-choice.is-active { border-color: #7357ef; background: #ece8ff; color: #5b3ed1; box-shadow: inset 0 0 0 1px #7357ef; }

.program-modules__head { display: flex; gap: 14px; align-items: end; justify-content: space-between; }
.program-modules__head > small { max-width: 260px; color: #747c8b; font-size: .72rem; text-align: right; }
.program-module-grid { display: grid; margin-top: 14px; gap: 9px; grid-template-columns: repeat(2, minmax(0, 1fr)); }
.program-module {
  position: relative;
  display: grid;
  min-height: 116px;
  padding: 13px;
  gap: 8px;
  grid-template-columns: 42px minmax(0, 1fr);
  grid-template-rows: auto 1fr auto;
  align-items: start;
  border: 1px solid #e6e3ef;
  border-radius: 17px;
  background: #fafafe;
  color: #1f2430;
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.program-module--random { grid-column: 1 / -1; background: linear-gradient(120deg, #f0ecff, #e5f8ef); }
.program-module__icon { display: grid; width: 42px; height: 42px; place-items: center; border-radius: 13px; background: #ece8ff; color: #6548dc; font-family: Unbounded, sans-serif; font-weight: 800; }
.program-module__check,
.program-module__random-arrow {
  display: grid;
  width: 29px;
  height: 29px;
  justify-self: end;
  place-items: center;
  border: 1px solid #d9d5e7;
  border-radius: 50%;
  background: #fff;
  color: transparent;
}
.program-module__check svg { width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-width: 2.5; stroke-linecap: round; stroke-linejoin: round; }
.program-module__random-arrow { color: #6548dc; font-weight: 900; }
.program-module.is-selected { border-color: #7357ef; background: #f0ecff; box-shadow: inset 0 0 0 1px #7357ef; }
.program-module.is-selected .program-module__check { border-color: #7357ef; background: #7357ef; color: #fff; }
.program-module__copy { display: grid; min-width: 0; grid-column: 1 / -1; gap: 3px; }
.program-module__copy strong { line-height: 1.15; }
.program-module__copy small { color: #747c8b; font-size: .68rem; line-height: 1.25; }
.program-module__percent { grid-column: 1 / -1; justify-self: end; color: #7357ef; font-size: .76rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.program-module__track { grid-column: 1 / -1; height: 6px; overflow: hidden; border-radius: 999px; background: #e9e7ef; }
.program-module__track i { display: block; height: 100%; border-radius: inherit; background: #7357ef; }

.program-start {
  position: sticky;
  bottom: calc(8px + env(safe-area-inset-bottom, 0px));
  width: 100%;
  min-height: 56px;
  margin-top: 14px;
  border: none;
  border-radius: 17px;
  background: #7357ef;
  color: #fff;
  font: inherit;
  font-family: Unbounded, sans-serif;
  font-size: .86rem;
  font-weight: 700;
  box-shadow: 0 12px 24px rgba(115, 87, 239, .25);
  cursor: pointer;
}
.program-start:disabled { background: #d7d3e3; color: #7b7588; box-shadow: none; cursor: default; }

.play-kind-card:focus-visible,
.play-arcade-link:focus-visible,
.play-mode-back:focus-visible,
.play-mode-close:focus-visible,
.speed-choice:focus-visible,
.program-module:focus-visible,
.program-start:focus-visible { outline: 3px solid #2f66d0; outline-offset: 3px; }

@media (min-width: 700px) {
  .play-kind-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .speed-choice-row { grid-template-columns: repeat(6, minmax(0, 1fr)); }
  .program-module-grid { grid-template-columns: repeat(5, minmax(0, 1fr)); }
  .program-module--random { grid-column: auto; }
  .route-score-formula { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}

/* ---------- главная: два действия и короткая справка ---------- */

/*
 * Всё, что противоречит новой методике, скрывается, а не удаляется:
 * откат делается флагом ?v3=0 без деплоя.
 */
body.lv3-default #homeView .daily-hero,
body.lv3-default #homeView .content-section,
body.lv3-default .guide-button { display: none !important; }

/*
 * Главная — ровно один экран, но только пока содержимое в него влезает.
 * Ниже порога (min-height ниже) экран возвращается к обычной прокрутке:
 * втискивание в 100dvh на низком вьюпорте давало наползание справки на кнопки.
 *
 * Боковые отступы учитывают вырезы: в альбомной ориентации у Samsung панель
 * навигации стоит вертикально у правого края и перекрывала бы контент.
 */
body.lv3-default #homeView {
  padding-right: calc(18px + env(safe-area-inset-right, 0px));
  padding-left: calc(18px + env(safe-area-inset-left, 0px));
}

/*
 * Раскладку главной задаём безусловно, а не только внутри гейта: на широком
 * экране styles.css переводит #homeView в сетку из двух колонок, и ниже порога
 * главная разваливалась на половину экрана. Селектор с .app-view--active
 * обязателен — иначе правило перебивает display:none у неактивных экранов
 * и выбранная вкладка рисуется под главной.
 *
 * gap обнуляем по той же причине: 18px из правила для широких экранов
 * протекали в колонку и отбирали 36px у строки кнопок.
 */
body.lv3-default #homeView.app-view--active {
  display: block;
  gap: 0;
  grid-template-columns: none;
}

body.lv3-default #homeView .page-header--home { margin-bottom: 0; }
body.lv3-default #homeView .home-title { margin: 12px 0 18px; }

@media (min-height: 620px), (orientation: landscape) and (min-height: 289px) {
  body.lv3-default:has(#homeView.app-view--active) { overflow: hidden; }

  body.lv3-default:has(#homeView.app-view--active) .app-content {
    height: 100dvh;
    min-height: 0;
    padding-bottom: 0;
  }

  body.lv3-default #homeView.app-view--active {
    display: flex;
    height: 100%;
    min-height: 0;
    flex-direction: column;
    padding-bottom: calc(86px + var(--safe-bottom));
    overflow: hidden;
  }

  body.lv3-default #homeView .page-header--home { flex: 0 0 auto; }
  body.lv3-default #homeView .home-title { flex: 0 0 auto; margin-bottom: 0; }
}

.lv3-home {
  display: grid;
  min-height: 0;
  margin: 0;
  gap: 12px;
  grid-template-rows: auto auto;
  flex: 1 1 auto;
}

@media (min-height: 620px), (orientation: landscape) and (min-height: 289px) {
  .lv3-home { grid-template-rows: minmax(0, 1fr) auto; }
}

.lv3-home__actions {
  display: grid;
  min-height: 0;
  align-self: center;
  gap: 10px;
  grid-template-columns: 1fr 1fr;
}

/* Растягиваем действия по свободному месту только там, где место есть. */
@media (min-height: 620px), (orientation: landscape) and (min-height: 289px) {
  .lv3-home__actions { height: 100%; grid-auto-rows: minmax(0, 1fr); }
}

.lv3-btn {
  display: grid;
  min-height: 82px;
  align-content: center;
  gap: 4px;
  padding: 16px 14px;
  border: none;
  border-radius: 20px;
  color: #fff;
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.lv3-btn strong { font-family: Unbounded, Comfortaa, sans-serif; font-size: 1.15rem; font-weight: 700; }
.lv3-btn small { font-size: 0.72rem; opacity: 0.86; }
.lv3-btn:active { box-shadow: inset 0 3px 8px rgba(0, 0, 0, 0.18); }
.lv3-btn:focus-visible { outline: 2px solid #1f2430; outline-offset: 3px; }

/*
 * В одноэкранном режиме высоту кнопок задаёт сетка, а не пол в 82px: с полом
 * кнопка вылезала из своей дорожки и накрывала соседнюю кнопку и карточку
 * справки. Правило обязано стоять ПОСЛЕ базового .lv3-btn — специфичность
 * одинаковая, и выше по файлу оно было мёртвым.
 */
@media (min-height: 620px), (orientation: landscape) and (min-height: 289px) {
  .lv3-btn { min-height: 0; }
}

.lv3-btn--learn { background: linear-gradient(150deg, #7357ef, #5637cc); box-shadow: 0 14px 28px rgba(115, 87, 239, 0.28); }
.lv3-btn--play { background: linear-gradient(150deg, #16754e, #0f5c3d); box-shadow: 0 14px 28px rgba(22, 117, 78, 0.24); }

/*
 * Справка строками: подпись слева, значение справа. Тремя колонками длинное
 * значение («Спокойно 1/3») распирало свою ячейку и подписи наезжали друг на друга.
 */
.lv3-home__info {
  display: grid;
  margin: 0;
  gap: 7px;
  grid-template-columns: minmax(0, 1fr);
  padding: 12px 16px;
  border-radius: 16px;
  background: #fff;
}

.lv3-home__info div {
  display: grid;
  gap: 12px;
  align-items: baseline;
  grid-template-columns: minmax(0, 1fr) auto;
  min-width: 0;
}

/*
 * Многоточие вместо переполнения: «Уверенность» — одно слово без точки переноса,
 * и в узкой дорожке оно вылезало на соседнюю, а «Спокойно 1/3» срезалось по краю
 * карточки на полуслове. Перенос у подписи запрещён, чтобы высота карточки
 * не гуляла на 12px и не отбирала место у кнопок.
 */
.lv3-home__info dt {
  overflow: hidden;
  color: #747c8b;
  font-size: 0.62rem;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.lv3-home__info dd {
  overflow: hidden;
  margin: 0;
  font-size: 0.86rem;
  font-weight: 800;
  white-space: nowrap;
  text-overflow: ellipsis;
  font-variant-numeric: tabular-nums;
}

@media (max-width: 420px) and (orientation: portrait) {
  .lv3-home__actions { grid-template-columns: minmax(0, 1fr); height: min(330px, 100%); }
}

/* Альбомный экран: высоты мало — заголовок мельче, справка тремя колонками. */
@media (orientation: landscape) and (max-height: 600px) {
  /* Специфичность равна правилу одноэкранного режима: иначе снизу остаётся
     запас под таб-бар, которого в альбомной ориентации нет — он стоит слева. */
  body.lv3-default #homeView.app-view--active { padding-bottom: calc(14px + var(--safe-bottom)); }
  body.lv3-default #homeView .home-title { margin-top: 6px; }
  body.lv3-default #homeView .home-title p { font-size: 1rem; }
  body.lv3-default #homeView .home-title h1 { font-size: 1.85rem; }

  .lv3-home { gap: 10px; }
  /* Три колонки требуют места: ниже 560px они наползают друг на друга,
     поэтому там справка остаётся строками. */
  .lv3-home__info { gap: 10px; padding: 10px 14px; }
  .lv3-home__info div { gap: 1px; }
}

/* Справка тремя колонками — только там, где на дорожку хватает ширины. */
@media (orientation: landscape) and (max-height: 600px) and (min-width: 560px) {
  .lv3-home__info { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .lv3-home__info div { grid-template-columns: minmax(0, 1fr); }
}
