/* HARMONIA · overlays — стартовый экран и модальное окно паузы */

.scrim {
  position: absolute; inset: 0; z-index: 10;
  background: rgba(14, 16, 23, 0.9); backdrop-filter: blur(8px);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center; padding: 30px; overflow: auto; cursor: pointer;
}
.scrim h1 {
  margin: 0 0 12px; font-size: 29px;
  background: linear-gradient(90deg, #6bdfff, #a455e3, #ff1541);
  -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent;
}
.scrim p { max-width: 640px; line-height: 1.6; color: #c2cae0; margin: 0 0 22px; font-size: 14.5px; }
/* ===== Стартовый экран: проба пальцев =====
   Игрок знакомится с кнопками руками, а не чтением, поэтому текста на экране
   ровно две строки: название и «нажмите десять подсвеченных клавиш» со
   счётчиком. Всё остальное место занимает интерактивная схема клавиатуры.
   Экран фиксирован к окну, а не лежит внутри #game-container: сцена
   масштабируется transform'ом (fitStage), и внутри неё и текст, и клавиши на
   телефоне сжимались бы до нечитаемых. */
#startOverlay {
  position: fixed; inset: 0; z-index: 30;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: clamp(6px, 1.4vh, 14px);
  padding: clamp(10px, 2.4vh, 26px) clamp(10px, 3vw, 32px);
  background: radial-gradient(circle at 50% 36%, #1c2132 0%, #0b0d15 72%);
  overflow: auto; cursor: default;
  transition: opacity 0.5s ease, transform 0.5s ease;
}
/* Затухание после пробела: сессия начинается сразу, поэтому фон сначала
   гаснет, а уже потом прячется совсем (display: none ставит beginFromOverlay). */
#startOverlay.fade { opacity: 0; transform: scale(1.02); pointer-events: none; }
.intro-title {
  margin: 0; font-size: clamp(11px, 1.4vw, 16px); font-weight: 800;
  letter-spacing: clamp(1px, 0.26vw, 3px); text-transform: uppercase;
  background: linear-gradient(90deg, #6bdfff, #a455e3, #ff1541);
  -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent;
}
/* Единственная инструкция: что нажать и сколько осталось. */
.intro-lead {
  display: flex; align-items: baseline; justify-content: center; flex-wrap: wrap;
  gap: 4px 10px; margin: 0; text-align: center;
  font-size: clamp(11px, 1.35vw, 15px); line-height: 1.35; color: #c2cae0;
}
.intro-lead b { color: #ffffff; }
.ip-count {
  font-weight: 800; letter-spacing: 0.4px; color: #ffd166;
  font-variant-numeric: tabular-nums;
}
/* Второй шаг пробы: десять клавиш собраны, но пробел ещё не активен — окно
   просит Enter, и он включает барабаны. Текст живёт в разметке (.ip-drums),
   JS переключает только класс drums; счётчик 10 / 10 уже зелёный. */
.intro-lead .ip-drums { display: none; }
#startOverlay.drums .ip-before,
#startOverlay.drums .ip-after { display: none; }
#startOverlay.drums .ip-drums { display: inline; }
#startOverlay.drums .ip-count { color: #74cc3d; }
/* После пробы инструкция меняется целиком: одна короткая строка про пробел.
   Счётчик остаётся 10 / 10 и зеленеет, чтобы «готово» читалось без текста. */
.intro-lead .ip-after { display: none; }
#startOverlay.ready .ip-before { display: none; }
#startOverlay.ready .ip-after { display: inline; }
#startOverlay.ready .ip-count { color: #74cc3d; }
/* Клавиатура забирает всё свободное место: схема — главный элемент экрана. */
.intro-keyboard {
  flex: 1 1 auto; min-height: 0; width: 100%; max-width: 1360px;
  display: flex; flex-direction: column; justify-content: center;
  gap: clamp(4px, 1vh, 10px);
}
.kb-hands { display: flex; justify-content: space-between; gap: 12px; padding: 0 clamp(4px, 1vw, 14px); }
.kb-hand {
  display: flex; align-items: center; gap: 6px;
  font-size: clamp(8px, 1vw, 12px); font-weight: 800; letter-spacing: 0.45px;
  text-transform: uppercase; color: #9aa4c2; white-space: nowrap;
}
.kb-hand i {
  width: 7px; height: 7px; border-radius: 50%; flex: none;
  background: #6bdfff; box-shadow: 0 0 8px rgba(107, 223, 255, 0.6);
}
.kb-hand.rh i { background: #74cc3d; box-shadow: 0 0 8px rgba(116, 204, 61, 0.6); }
.kb-board {
  flex: 1 1 auto; min-height: 0; width: 100%;
  /* Высота доски ограничена и шириной, и высотой окна: на телефоне клавиши
     остаются компактными, на большом мониторе — крупными, но не вытянутыми. */
  max-height: min(520px, 60vh, 82vw);
  padding: clamp(6px, 1.2vh, 14px);
  display: flex; flex-direction: column; gap: clamp(4px, 0.9vh, 10px);
  border: 1px solid rgba(255, 255, 255, 0.12); border-radius: 14px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.05), rgba(255, 255, 255, 0.02));
  box-shadow: 0 16px 44px rgba(0, 0, 0, 0.34), inset 0 1px 0 rgba(255, 255, 255, 0.06);
}
.kb-row { flex: 1 1 0; min-height: 0; display: flex; gap: clamp(3px, 0.55vw, 8px); }
/* Небольшой сдвиг рядов даёт настоящую «лесенку», но не выводит клавиши
   за скруглённую рамку: иначе на узком экране появляется горизонтальный скролл. */
.kb-home { transform: translateX(6px); }
.kb-bottom { transform: translateX(5px); }
.kb-space-row { transform: translateX(3px); }
.kb-key {
  position: relative; flex: 1 1 0; min-width: 0;
  display: inline-flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; padding: 0 2px; line-height: 1;
  font-size: clamp(9px, 1.1vw, 15px); font-weight: 800;
  color: #b9c2da; background: rgba(255, 255, 255, 0.055);
  border: 1px solid rgba(255, 255, 255, 0.16); border-radius: 8px;
  box-shadow: inset 0 -3px 0 rgba(0, 0, 0, 0.22);
  transition: background 0.15s, border-color 0.15s, transform 0.15s;
}
.kb-key b { font-size: clamp(10px, 1.3vw, 17px); line-height: 1; color: #e8eeff; }
.kb-key span { font-size: clamp(7px, 0.72vw, 10px); line-height: 1; color: #8b95b3; white-space: nowrap; }
.kb-key.dim { color: #69738f; opacity: 0.42; font-weight: 700; }
.kb-key.on {
  animation: introKeyPulse 4.2s ease-in-out infinite;
  animation-delay: calc(var(--i) * 0.18s);
}
.kb-key.lh { --lit: #6bdfff; color: #c9f4ff; border-color: rgba(107, 223, 255, 0.38); }
.kb-key.rh { --lit: #74cc3d; color: #d6f5c9; border-color: rgba(116, 204, 61, 0.38); }
.kb-key.cmd { --lit: #ffd166; color: #ffe7a8; border-color: rgba(255, 209, 102, 0.32); }
.kb-key.home::after {
  content: ''; position: absolute; bottom: 3px; width: 8px; height: 2px;
  border-radius: 2px; background: currentColor; opacity: 0.55;
}
/* Клавиши пробы: пунктир — ещё не нажата, «hit» — засчитана и больше не мигает.
   Клик по схеме равен нажатию: на планшете и без клавиатуры вход тот же. */
.kb-key[data-key] { cursor: pointer; }
.kb-key.need { border-style: dashed; border-color: rgba(255, 255, 255, 0.3); }
.kb-key.hit {
  animation: none; transform: translateY(1px);
  background: rgba(255, 255, 255, 0.2);
  border-style: solid; border-color: var(--lit);
  box-shadow: 0 0 14px var(--lit), inset 0 -2px 0 rgba(0, 0, 0, 0.22);
}
.kb-key.hit b { color: #ffffff; }
.kb-key.hit::before {
  content: '✓'; position: absolute; top: 1px; right: 3px;
  font-size: 7px; line-height: 1; color: var(--lit);
}
/* Широкие клавиши растягиваются непропорционально — как на настоящей доске. */
.kb-tab { flex-grow: 1.7; }
.kb-caps { flex-grow: 1.6; }
.kb-enter { flex-grow: 2; }
.kb-shift { flex-grow: 1.9; }
.kb-mod { flex-grow: 1.4; }
.kb-space {
  flex-grow: 6; flex-direction: row; gap: 6px;
  background: rgba(255, 209, 102, 0.09);
}
.kb-space b { font-size: clamp(9px, 1vw, 13px); }
/* Пробел — единственная клавиша, которую просят нажать после пробы: в игре она
   открывает новое комбо, поэтому на старте закрепляется та же реакция. До
   10 / 10 клавиша нейтральна, после — пульсирует и подписана «начать»; клик по
   ней равен нажатию, поэтому старт доступен и без физической клавиатуры. */
.kb-space-start { display: none; }
#startOverlay.ready .kb-space {
  border-style: solid; border-color: #ffd166; cursor: pointer;
  background: rgba(255, 209, 102, 0.18);
  box-shadow: 0 0 16px rgba(255, 209, 102, 0.5), inset 0 -2px 0 rgba(0, 0, 0, 0.22);
  animation: introSpaceReady 1.7s ease-in-out infinite;
}
#startOverlay.ready .kb-space-role { display: none; }
#startOverlay.ready .kb-space-start { display: inline; }
/* Enter на шаге барабанов — та же подсветка, что у пробела после пробы:
   клавиша становится единственным путём дальше, и её видно без чтения строки. */
#startOverlay.drums .kb-enter {
  border-style: solid; border-color: #ffd166; cursor: pointer;
  background: rgba(255, 209, 102, 0.18);
  box-shadow: 0 0 16px rgba(255, 209, 102, 0.5), inset 0 -2px 0 rgba(0, 0, 0, 0.22);
  animation: introSpaceReady 1.7s ease-in-out infinite;
}
#startOverlay.drums .kb-enter b { color: #fff6dc; }
#startOverlay.ready .kb-space b,
#startOverlay.ready .kb-space-start { color: #fff6dc; }
/* Пробел нажат: свечение снимается сразу, а текст «начать» остаётся до конца
   затухания — окно не мигает обратно на инструкцию пробы. */
#startOverlay.ready.fade .kb-space {
  animation: none; transform: translateY(1px);
  background: rgba(255, 255, 255, 0.22); border-color: #ffffff;
}
/* Стрелки — сетка 3×2 внутри общего ряда: кластер растягивается вместе с доской. */
.kb-arrows {
  flex: 1.6 1 0; min-width: 0;
  display: grid; grid-template-columns: repeat(3, 1fr); grid-template-rows: repeat(2, 1fr);
  gap: clamp(2px, 0.4vw, 5px);
}
.kb-arrow { flex: none; border-radius: 6px; font-size: clamp(10px, 1.2vw, 16px); }
.kb-arrow.up { grid-column: 2; grid-row: 1; }
.kb-arrow.left { grid-column: 1; grid-row: 2; }
.kb-arrow.down { grid-column: 2; grid-row: 2; }
.kb-arrow.right { grid-column: 3; grid-row: 2; }
.kb-arrow-label {
  align-self: flex-end; margin-left: 1px;
  font-size: clamp(7px, 0.7vw, 9px); line-height: 1.1;
  color: #7e88a6; text-transform: uppercase; letter-spacing: 0.3px; white-space: nowrap;
}
/* ===== MIDI-знакомство =====
   Тот же #startOverlay, но вместо схемы компьютерных клавиш — расшифровка
   обозначений и три целевых аккорда. Экран остаётся вне #game-container:
   fitStage() не должен масштабировать текст и мини-клавиатуры. */
#startOverlay.midi .intro-lead,
#startOverlay.midi .intro-keyboard,
#startOverlay.midi .kb-tip { display: none; }
.midi-coach {
  flex: 1 1 auto; width: 100%; max-width: 1080px; min-height: 0;
  display: flex; flex-direction: column; justify-content: center;
  gap: clamp(8px, 1.3vh, 14px); margin: 0 auto;
}
.midi-coach[hidden] { display: none; }
.mi-head {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 14px; text-align: left;
}
.mi-head-copy { min-width: 0; }
.mi-kicker {
  display: flex; align-items: center; gap: 6px;
  font-size: clamp(8px, 0.95vw, 11px); font-weight: 800; letter-spacing: 1px;
  text-transform: uppercase; color: #8b95b3;
}
.mi-dot {
  width: 7px; height: 7px; flex: none; border-radius: 50%;
  background: #74cc3d; box-shadow: 0 0 8px rgba(116, 204, 61, 0.7);
}
.mi-device {
  max-width: 34vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  color: #d0d7ee; letter-spacing: 0.2px; text-transform: none;
}
.mi-head h2 {
  margin: 3px 0 2px; font-size: clamp(18px, 2.3vw, 29px);
  color: #ffd166; letter-spacing: 0.2px;
}
#miLead {
  max-width: 660px; margin: 0; font-size: clamp(11px, 1.25vw, 14px);
  line-height: 1.42; color: #c2cae0;
}
.mi-progress {
  flex: none; min-width: 76px; padding: 8px 11px; border-radius: 10px;
  font-size: clamp(15px, 1.8vw, 21px); font-weight: 900; line-height: 1;
  color: #6bdfff; text-align: center; font-variant-numeric: tabular-nums;
  background: rgba(107, 223, 255, 0.08);
  border: 1px solid rgba(107, 223, 255, 0.26);
}
.mi-progress.ready {
  color: #10131d; background: #74cc3d; border-color: #a8f47a;
  box-shadow: 0 0 14px rgba(116, 204, 61, 0.4);
}
.mi-grid {
  display: grid; grid-template-columns: minmax(0, 1.05fr) minmax(0, 0.95fr);
  gap: clamp(8px, 1.4vw, 16px); text-align: left;
}
.mi-panel {
  min-width: 0; padding: clamp(9px, 1.2vw, 14px);
  border-radius: 12px; border: 1px solid rgba(255, 255, 255, 0.12);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.055), rgba(255, 255, 255, 0.025));
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.05);
}
.mi-panel h3 {
  margin: 0 0 8px; font-size: clamp(10px, 1.1vw, 12px); font-weight: 800;
  letter-spacing: 1px; text-transform: uppercase; color: #9aa4c2;
}
.mi-legend-row { display: flex; flex-wrap: wrap; gap: 6px 8px; }
.mi-legend-item {
  display: inline-flex; align-items: center; gap: 5px; padding: 3px 6px;
  border-radius: 6px; background: rgba(255, 255, 255, 0.045);
  font-size: clamp(8px, 0.85vw, 10px); font-weight: 700; color: #b9c2da;
  white-space: nowrap;
}
.mi-legend-item .cc-note { font-size: clamp(12px, 1.35vw, 15px); font-weight: 900; }
.mi-legend-copy {
  margin: 8px 0; font-size: clamp(9px, 0.95vw, 11px); line-height: 1.45;
  color: #9aa4c2;
}
.mi-symbols {
  display: flex; flex-wrap: wrap; gap: 5px 12px;
  font-size: clamp(9px, 0.95vw, 11px); line-height: 1.35; color: #c2cae0;
}
.mi-symbols span { display: inline-flex; align-items: center; gap: 4px; }
.mi-pill {
  padding: 1px 5px; border-radius: 3px; font-size: 8px; font-weight: 900;
  color: #10131d; background: #6bdfff; white-space: nowrap;
}
.mi-next-mark { color: #74cc3d; font-size: 15px; line-height: 1; }
.mi-home-mark { color: #ffd166; font-size: 14px; line-height: 1; }
.mi-targets { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 7px; }
.mi-target {
  position: relative; min-width: 0; padding: 7px 6px 6px;
  border-radius: 9px; border: 1px solid rgba(255, 255, 255, 0.14);
  background: rgba(9, 12, 20, 0.58);
  transition: border-color 0.15s, background 0.15s, box-shadow 0.15s;
}
.mi-target.next {
  border-color: rgba(107, 223, 255, 0.68);
  box-shadow: inset 0 2px 0 #6bdfff;
}
.mi-target.heard {
  border-color: rgba(255, 209, 102, 0.8);
  box-shadow: 0 0 13px rgba(255, 209, 102, 0.24), inset 0 2px 0 #ffd166;
}
.mi-target.done {
  border-color: rgba(116, 204, 61, 0.64);
  background: rgba(23, 43, 19, 0.7);
}
.mi-target-head { display: flex; align-items: center; gap: 4px; min-height: 17px; }
.mi-target-deg { font-size: clamp(14px, 1.55vw, 18px); font-weight: 900; color: #ffd166; line-height: 1; }
.mi-target-hint {
  min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  font-size: 8px; font-weight: 800; letter-spacing: 0.35px; text-transform: uppercase;
  color: #8b95b3;
}
.mi-target-check { margin-left: auto; font-size: 13px; font-weight: 900; color: #74cc3d; opacity: 0; }
.mi-target.done .mi-target-check { opacity: 1; }
.mi-target-name {
  margin: 5px 0 4px; overflow: hidden; text-overflow: ellipsis;
  font-size: clamp(9px, 0.95vw, 11px); font-weight: 800; white-space: nowrap;
}
.mi-target-kb { display: flex; justify-content: center; overflow: hidden; }
.mi-target-kb .km-board { width: 100%; max-width: 104px; }
.mi-hint { margin: 7px 0 0; font-size: 9px; line-height: 1.35; color: #7e88a6; }
.mi-live {
  min-height: 30px; display: flex; align-items: center; justify-content: center;
  padding: 5px 10px; border-radius: 8px; text-align: center;
  font-size: clamp(10px, 1.05vw, 12px); font-weight: 700; color: #9aa4c2;
  background: rgba(107, 223, 255, 0.055); border: 1px solid rgba(107, 223, 255, 0.16);
}
.mi-live.live {
  color: #e8eeff; border-color: rgba(107, 223, 255, 0.42);
  background: rgba(107, 223, 255, 0.1);
}
.mi-live b { color: #6bdfff; }
.mi-actions { display: flex; align-items: center; justify-content: flex-end; gap: 8px; flex-wrap: wrap; }
.mi-skip, .mi-start {
  padding: 8px 16px; font-family: inherit; font-size: 12px; font-weight: 800;
  border-radius: 8px; cursor: pointer; transition: transform 0.15s, background 0.15s;
}
.mi-skip {
  color: #b9c2da; background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.18);
}
.mi-skip:hover { background: rgba(255, 255, 255, 0.12); }
.mi-skip[hidden] { display: none; }
.mi-start {
  color: #10131d; background: linear-gradient(90deg, #ffe08a, #ffd166);
  border: 1px solid #ffe3a1; box-shadow: 0 6px 20px rgba(255, 209, 102, 0.28);
}
.mi-start:hover:not(:disabled) { transform: translateY(-1px); }
.mi-start:disabled {
  opacity: 0.4; cursor: default; box-shadow: none; transform: none;
}
@media (max-width: 760px) {
  #startOverlay.midi { justify-content: flex-start; }
  .mi-grid { grid-template-columns: 1fr; }
  .mi-targets { grid-template-columns: 1fr; }
  .mi-target-kb .km-board { max-width: 124px; }
  .mi-head { gap: 8px; }
  .mi-device { max-width: 44vw; }
  .mi-actions { justify-content: stretch; }
  .mi-skip, .mi-start { flex: 1 1 auto; }
}
@media (prefers-reduced-motion: reduce) {
  .mi-target, .mi-start, .mi-skip { transition: none; }
}

/* Подсказка клавиши (#kbTip): один пузырёк на всё окно, позицию считает
   showKeyTip() по прямоугольнику клавиши. Висит над клавишей, мышь не
   перехватывает и на телефоне не мешает нажимать. */
.kb-tip {
  position: absolute; z-index: 3; max-width: min(280px, 46vw);
  padding: 7px 11px;
  font-size: clamp(10px, 1.15vw, 13px); line-height: 1.35; font-weight: 600;
  text-align: center; color: #f2f6ff; background: rgba(16, 20, 31, 0.96);
  border: 1px solid rgba(255, 209, 102, 0.5); border-radius: 9px;
  box-shadow: 0 10px 26px rgba(0, 0, 0, 0.45);
  transform: translate(-50%, -100%); pointer-events: none;
  opacity: 0; transition: opacity 0.12s ease;
}
.kb-tip.show { opacity: 1; }
@keyframes introKeyPulse {
  0%, 72%, 100% { transform: translateY(0); background: rgba(255, 255, 255, 0.055); box-shadow: inset 0 -2px 0 rgba(0, 0, 0, 0.22); }
  5% { transform: translateY(-2px); background: rgba(255, 255, 255, 0.16); border-color: var(--lit); box-shadow: 0 0 12px var(--lit), inset 0 -2px 0 rgba(0, 0, 0, 0.22); }
  5.01%, 12% { transform: translateY(-1px); background: rgba(255, 255, 255, 0.10); border-color: var(--lit); }
}
@keyframes introSpaceReady {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-2px); }
}
@media (prefers-reduced-motion: reduce) {
  .kb-key.on { animation: none; }
  #startOverlay.ready .kb-space { animation: none; }
  #startOverlay.drums .kb-enter { animation: none; }
  #startOverlay { transition: none; }
  .kb-tip { transition: none; }
}
.btnrow { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }
.big-btn {
  padding: 12px 26px; font-size: 15px; font-weight: 700; font-family: inherit;
  color: #12141d; background: linear-gradient(90deg, #6bdfff, #4ec3ff);
  border: none; border-radius: 10px; cursor: pointer; transition: transform 0.15s;
  box-shadow: 0 6px 24px rgba(78, 195, 255, 0.35);
}
.big-btn:hover { transform: scale(1.05); }
.big-btn.alt { background: rgba(255, 255, 255, 0.1); color: #d0d7ee; box-shadow: none; border: 1px solid rgba(255, 255, 255, 0.25); }
#modal { display: none; cursor: default; }
#modalStats { font-size: 15px; color: #ffd166; font-weight: 800; margin-bottom: 18px; }
/* ===== Рендер видео =====
   Оверлей лежит внутри сцены и закрывает её от случайного ввода. В кадр он не
   попадает: video.js снимает только канвасы через captureStream(). */
.video-export {
  position: absolute; inset: 0; z-index: 24;
  display: flex; align-items: center; justify-content: center;
  padding: 24px; text-align: center; cursor: default;
  background: rgba(8, 10, 16, 0.84); backdrop-filter: blur(7px);
}
.video-export[hidden] { display: none; }
.ve-card {
  width: min(360px, 86%);
  display: flex; flex-direction: column; align-items: center; gap: 12px;
  padding: 22px 24px;
  border-radius: 14px;
  background: rgba(18, 22, 34, 0.92);
  border: 1px solid rgba(107, 223, 255, 0.28);
  box-shadow: 0 18px 44px rgba(0, 0, 0, 0.48);
}
.ve-title {
  font-size: 13px; font-weight: 800; letter-spacing: 1px;
  text-transform: uppercase; color: #6bdfff;
}
.ve-text {
  font-size: 13px; line-height: 1.45; color: #c2cae0;
  font-variant-numeric: tabular-nums;
}
.ve-note {
  font-size: 11px; line-height: 1.4; color: #8b95b3;
}
.ve-card .big-btn { padding: 9px 20px; font-size: 13px; }
