/* ============================================================
   МОРЗЯНКА — стили
   Тёмное «ночное небо» + неоновые леденцовые акценты.
   Всё крупное: минимальная зона касания 56px (детские пальцы).
   ============================================================ */

:root {
  --cyan:    #22e0ff;
  --pink:    #ff4fd8;
  --yellow:  #ffd93d;
  --green:   #57ff8f;
  --violet:  #8b6bff;
  --orange:  #ff8a3d;
  --red:     #ff5a6e;

  --bg0: #060820;
  --bg1: #0d1038;
  --bg2: #161a4d;

  /* тёмная подложка: карточки уверенно читаются поверх «звёздного» фона */
  --card: linear-gradient(160deg, rgba(22, 27, 74, .78), rgba(10, 13, 44, .68));
  --card-flat: rgba(14, 18, 56, .72);
  --card-brd: rgba(255, 255, 255, .16);
  --ink: #f2f6ff;
  --ink-dim: rgba(242, 246, 255, .72);
  --ink-faint: rgba(242, 246, 255, .46);

  --accent: var(--cyan);
  --r-lg: 28px;
  --r-md: 20px;
  --r-sm: 14px;
  --shadow: 0 18px 50px rgba(0, 0, 0, .45);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}

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

html, body {
  height: 100%;
  overscroll-behavior: none;
}

body {
  font-family: 'Nunito', 'Segoe UI Variable Display', 'Segoe UI', system-ui, -apple-system, 'Trebuchet MS', sans-serif;
  font-weight: 700;
  color: var(--ink);
  background: var(--bg0);
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}

/* ---------- Фон ---------- */
#bg-gradient {
  position: fixed; inset: 0; z-index: 0;
  background:
    radial-gradient(120% 80% at 15% 10%, rgba(139, 107, 255, .30), transparent 60%),
    radial-gradient(110% 75% at 85% 15%, rgba(34, 224, 255, .22), transparent 62%),
    radial-gradient(120% 90% at 50% 110%, rgba(255, 79, 216, .22), transparent 60%),
    linear-gradient(170deg, var(--bg1), var(--bg0) 60%, #04061a);
  transition: background .8s ease;
}
#fx-canvas { position: fixed; inset: 0; z-index: 1; pointer-events: none; }

/* ---------- Каркас экранов ---------- */
#app { position: relative; z-index: 2; height: 100%; display: flex; flex-direction: column; }

.screen {
  position: absolute; inset: 0;
  display: none; flex-direction: column;
  padding: calc(12px + var(--safe-t)) 16px calc(14px + var(--safe-b));
  overflow: hidden;
}
.screen.active { display: flex; animation: screenIn .38s cubic-bezier(.2, .9, .25, 1); }
@keyframes screenIn { from { opacity: 0; transform: translateY(26px) scale(.985); } to { opacity: 1; transform: none; } }

.scroll { flex: 1; overflow-y: auto; overflow-x: hidden; -webkit-overflow-scrolling: touch; padding-bottom: 12px; }
.scroll::-webkit-scrollbar { width: 6px; }
.scroll::-webkit-scrollbar-thumb { background: rgba(255,255,255,.16); border-radius: 3px; }

/* ---------- Общие элементы ---------- */
.card {
  background: var(--card);
  border: 1.5px solid var(--card-brd);
  border-radius: var(--r-md);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  padding: 16px;
}

.btn {
  border: none; border-radius: var(--r-md);
  font-family: inherit; font-weight: 800; font-size: 1.02rem;
  color: #08122a; cursor: pointer;
  padding: 15px 22px; min-height: 56px;
  background: linear-gradient(145deg, var(--cyan), var(--violet));
  box-shadow: 0 8px 0 rgba(0, 0, 0, .28), 0 14px 30px rgba(34, 224, 255, .22);
  transition: transform .12s, box-shadow .12s, filter .2s;
  display: inline-flex; align-items: center; justify-content: center; gap: 9px;
}
.btn:active { transform: translateY(6px); box-shadow: 0 2px 0 rgba(0,0,0,.28), 0 6px 14px rgba(0,0,0,.3); }
.btn.ghost {
  background: var(--card); color: var(--ink);
  border: 1.5px solid var(--card-brd); box-shadow: none;
}
.btn.ghost:active { transform: scale(.96); }
.btn.pink   { background: linear-gradient(145deg, var(--pink), #ff8a3d); box-shadow: 0 8px 0 rgba(0,0,0,.28), 0 14px 30px rgba(255,79,216,.22); }
.btn.green  { background: linear-gradient(145deg, var(--green), var(--cyan)); box-shadow: 0 8px 0 rgba(0,0,0,.28), 0 14px 30px rgba(87,255,143,.2); }
.btn.yellow { background: linear-gradient(145deg, var(--yellow), var(--orange)); box-shadow: 0 8px 0 rgba(0,0,0,.28), 0 14px 30px rgba(255,217,61,.2); }
.btn:disabled { filter: grayscale(.7) brightness(.7); pointer-events: none; }
.btn.sm { min-height: 44px; padding: 10px 16px; font-size: .9rem; border-radius: var(--r-sm); }

.row { display: flex; gap: 10px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.spacer { flex: 1; }
.center { text-align: center; }
.dim { color: var(--ink-dim); font-weight: 700; }
.faint { color: var(--ink-faint); }
.tiny { font-size: .78rem; }
.mono { font-family: 'JetBrains Mono', 'Consolas', 'Courier New', monospace; }

/* ---------- Код Морзе как графические блоки ---------- */
.mcode { display: inline-flex; align-items: center; gap: .28em; vertical-align: middle; line-height: 1; }
.mcode i {
  display: inline-block; width: .40em; height: .40em; border-radius: .22em;
  background: currentColor; box-shadow: 0 0 .5em currentColor;
}
.mcode i[data-l] { width: 1.15em; }
.mcode b { font-weight: 900; opacity: .8; margin: 0 .15em; }
.mcode i.pop { animation: symPop .28s cubic-bezier(.2,1.6,.4,1); }
@keyframes symPop { from { transform: scale(0) translateY(-10px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ---------- Шапка экрана ---------- */
.topbar { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; flex-shrink: 0; }
.icon-btn {
  width: 46px; height: 46px; flex-shrink: 0;
  border-radius: 16px; border: 1.5px solid var(--card-brd);
  background: var(--card); color: var(--ink);
  font-size: 1.25rem; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: transform .12s, background .2s;
}
.icon-btn:active { transform: scale(.9); background: rgba(255,255,255,.14); }
.topbar h2 { font-size: 1.12rem; font-weight: 900; letter-spacing: .2px; }

/* ---------- ГЛАВНОЕ МЕНЮ ---------- */
.logo-wrap { text-align: center; padding: 8px 0 4px; flex-shrink: 0; }
.logo {
  font-size: clamp(2.3rem, 11vw, 3.4rem); font-weight: 900; letter-spacing: 2px;
  background: linear-gradient(100deg, var(--cyan), var(--pink) 40%, var(--yellow) 75%, var(--green));
  background-size: 250% 100%;
  -webkit-background-clip: text; background-clip: text;
  -webkit-text-fill-color: transparent; color: transparent;
  animation: hue 7s linear infinite;
  filter: drop-shadow(0 4px 22px rgba(34,224,255,.35));
}
@keyframes hue { to { background-position: 250% 0; } }
.logo-sub { color: var(--ink-dim); font-size: .88rem; margin-top: 2px; font-weight: 700; }

.logo-morse {
  display: flex; gap: 7px; justify-content: center; align-items: center;
  margin: 10px 0 4px; height: 18px;
}
.logo-morse i {
  display: block; height: 9px; border-radius: 6px; background: var(--cyan);
  box-shadow: 0 0 14px var(--cyan);
  animation: blip 1.9s infinite;
}
.logo-morse i.d { width: 9px; }
.logo-morse i.l { width: 28px; background: var(--pink); box-shadow: 0 0 14px var(--pink); }
@keyframes blip { 0%,100% { opacity: .25; transform: scaleY(.7); } 45% { opacity: 1; transform: scaleY(1); } }

/* Пип — маскот */
.pip {
  font-size: 3.6rem; text-align: center; line-height: 1;
  filter: drop-shadow(0 0 18px rgba(255,217,61,.7));
  animation: pipFloat 3.4s ease-in-out infinite;
}
@keyframes pipFloat { 0%,100% { transform: translateY(0) rotate(-4deg); } 50% { transform: translateY(-12px) rotate(4deg); } }
.pip.talk { animation: pipTalk .5s ease; }
@keyframes pipTalk { 0%,100% { transform: scale(1); } 50% { transform: scale(1.2) rotate(8deg); } }

.speech {
  background: rgba(255,255,255,.1); border: 1.5px solid var(--card-brd);
  border-radius: 18px; padding: 12px 16px; margin: 10px auto; max-width: 420px;
  font-size: .92rem; text-align: center; position: relative; backdrop-filter: blur(10px);
}
.speech::before {
  content: ''; position: absolute; top: -9px; left: 50%; transform: translateX(-50%) rotate(45deg);
  width: 16px; height: 16px; background: rgba(255,255,255,.1);
  border-left: 1.5px solid var(--card-brd); border-top: 1.5px solid var(--card-brd);
}

.menu-grid {
  display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px;
  max-width: 520px; width: 100%; margin: 0 auto;
}
.menu-btn {
  border: 1.5px solid var(--card-brd); border-radius: var(--r-lg);
  background: var(--card); backdrop-filter: blur(14px);
  color: var(--ink); padding: 18px 12px; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 7px;
  font-family: inherit; font-weight: 800; font-size: .93rem;
  position: relative; overflow: hidden;
  transition: transform .16s cubic-bezier(.2,.9,.25,1), border-color .2s, box-shadow .2s;
}
.menu-btn .ic { font-size: 2.1rem; line-height: 1; filter: drop-shadow(0 3px 10px rgba(0,0,0,.4)); }
.menu-btn .sub { font-size: .7rem; color: var(--ink-faint); font-weight: 700; }
.menu-btn::after {
  content: ''; position: absolute; inset: 0;
  background: linear-gradient(115deg, transparent 35%, rgba(255,255,255,.16) 50%, transparent 65%);
  transform: translateX(-120%); transition: transform .6s;
}
.menu-btn:active { transform: scale(.95); }
.menu-btn:hover::after { transform: translateX(120%); }
.menu-btn.c1 { border-color: rgba(87,255,143,.42);  box-shadow: 0 10px 34px rgba(87,255,143,.12); }
.menu-btn.c2 { border-color: rgba(34,224,255,.42);  box-shadow: 0 10px 34px rgba(34,224,255,.12); }
.menu-btn.c3 { border-color: rgba(255,217,61,.42);  box-shadow: 0 10px 34px rgba(255,217,61,.12); }
.menu-btn.c4 { border-color: rgba(255,79,216,.42);  box-shadow: 0 10px 34px rgba(255,79,216,.12); }
.menu-btn.c5 { border-color: rgba(139,107,255,.42); box-shadow: 0 10px 34px rgba(139,107,255,.12); }
.menu-btn.c6 { border-color: rgba(255,138,61,.42);  box-shadow: 0 10px 34px rgba(255,138,61,.12); }

/* Полоска профиля */
.profile-strip {
  display: flex; align-items: center; gap: 11px;
  background: var(--card); border: 1.5px solid var(--card-brd);
  border-radius: var(--r-md); padding: 10px 13px; margin-bottom: 12px;
  backdrop-filter: blur(14px); flex-shrink: 0;
}
.avatar {
  width: 46px; height: 46px; border-radius: 15px; flex-shrink: 0;
  background: linear-gradient(145deg, var(--violet), var(--pink));
  display: flex; align-items: center; justify-content: center; font-size: 1.6rem;
  box-shadow: 0 6px 18px rgba(139,107,255,.4); cursor: pointer;
}
.xp-track { height: 9px; border-radius: 6px; background: rgba(0,0,0,.35); overflow: hidden; margin-top: 5px; }
.xp-fill {
  height: 100%; border-radius: 6px;
  background: linear-gradient(90deg, var(--green), var(--cyan), var(--violet));
  box-shadow: 0 0 12px rgba(34,224,255,.6); transition: width .7s cubic-bezier(.2,.9,.25,1);
}
.pill {
  background: rgba(0,0,0,.3); border: 1px solid var(--card-brd);
  border-radius: 999px; padding: 5px 11px; font-size: .8rem; font-weight: 800;
  display: inline-flex; align-items: center; gap: 5px; white-space: nowrap;
}

/* ---------- КАРТА УРОВНЕЙ ---------- */
.world-band {
  border-radius: var(--r-lg); padding: 15px 84px 15px 17px; margin: 12px 0 10px;
  position: relative; overflow: hidden;
  border: 1.5px solid var(--card-brd);
}
.world-band .wname { font-size: 1.08rem; font-weight: 900; }
.world-band .wintro { font-size: .8rem; color: rgba(255,255,255,.88); margin-top: 3px; line-height: 1.35; }
.world-band .wemoji {
  position: absolute; right: 10px; top: 50%; transform: translateY(-50%);
  font-size: 3.4rem; opacity: .3;
}

.lvl-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 10px; }
.lvl {
  aspect-ratio: 1 / 1.06; border-radius: 22px; cursor: pointer;
  border: 2px solid var(--card-brd); background: var(--card);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  position: relative; transition: transform .16s, box-shadow .2s;
  font-family: inherit; color: var(--ink); overflow: hidden;
}
.lvl:active { transform: scale(.93); }
.lvl .num { font-size: 1.5rem; font-weight: 900; }
.lvl .chars { font-size: .68rem; color: var(--ink-faint); letter-spacing: 1px; font-weight: 800; }
.lvl .stars { font-size: .72rem; letter-spacing: 1px; height: 14px; }
.lvl.locked { opacity: .62; filter: saturate(.4); }
.lvl.locked .num { font-size: 1.4rem; }
.lvl.done { border-color: var(--green); box-shadow: 0 0 22px rgba(87,255,143,.2) inset; }
.lvl.next {
  border-color: var(--yellow);
  box-shadow: 0 0 0 0 rgba(255,217,61,.6);
  animation: pulseRing 2s infinite;
}
@keyframes pulseRing {
  0%   { box-shadow: 0 0 0 0 rgba(255,217,61,.55); }
  70%  { box-shadow: 0 0 0 16px rgba(255,217,61,0); }
  100% { box-shadow: 0 0 0 0 rgba(255,217,61,0); }
}

/* ---------- ИГРОВОЙ ЭКРАН ---------- */
.hud { display: flex; align-items: center; gap: 8px; flex-shrink: 0; margin-bottom: 8px; }
.hearts { font-size: 1.05rem; letter-spacing: 1px; }
.heart-lost { opacity: .22; filter: grayscale(1); }
.progress-track { flex: 1; height: 11px; border-radius: 7px; background: rgba(0,0,0,.4); overflow: hidden; }
.progress-fill {
  height: 100%; border-radius: 7px;
  background: linear-gradient(90deg, var(--yellow), var(--green));
  box-shadow: 0 0 14px rgba(87,255,143,.55); transition: width .45s cubic-bezier(.2,.9,.25,1);
}

.combo-badge {
  position: absolute; top: calc(60px + var(--safe-t)); right: 16px;
  font-size: .92rem; font-weight: 900; padding: 6px 13px; border-radius: 999px;
  background: linear-gradient(145deg, var(--orange), var(--pink));
  box-shadow: 0 6px 22px rgba(255,79,216,.4); color: #fff;
  opacity: 0; transform: scale(.5); transition: .25s; pointer-events: none; z-index: 5;
}
.combo-badge.show { opacity: 1; transform: scale(1); }

.stage {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 12px;
  min-height: 0; position: relative;
}

/* Табло приёма */
.panel {
  width: 100%; max-width: 460px;
  border-radius: var(--r-lg); border: 2px solid rgba(34,224,255,.32);
  background: linear-gradient(160deg, rgba(255,255,255,.09), rgba(255,255,255,.03));
  backdrop-filter: blur(16px); padding: 18px 16px; text-align: center;
  position: relative; overflow: hidden; transition: border-color .25s, box-shadow .25s;
}
.panel.ok  { border-color: var(--green); box-shadow: 0 0 46px rgba(87,255,143,.3); }
.panel.bad { border-color: var(--red);   box-shadow: 0 0 46px rgba(255,90,110,.3); }

.prompt-label { font-size: .76rem; color: var(--ink-faint); letter-spacing: 2px; text-transform: uppercase; }
.prompt-big {
  font-size: clamp(2.6rem, 15vw, 4.4rem); font-weight: 900; line-height: 1.05;
  background: linear-gradient(135deg, var(--cyan), var(--pink));
  -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent;
  filter: drop-shadow(0 0 24px rgba(34,224,255,.35));
  margin: 2px 0;
  word-break: break-word;
}
.prompt-big.word { font-size: clamp(1.5rem, 8vw, 2.4rem); letter-spacing: 3px; }
.prompt-big.pulse { animation: soundPulse 1.6s ease-in-out infinite; }
@keyframes soundPulse { 0%,100% { transform: scale(1); opacity: .85; } 50% { transform: scale(1.12); opacity: 1; } }
.prompt-chant { font-size: .92rem; color: var(--yellow); margin-top: 4px; font-weight: 800; }
.prompt-code { font-size: 1.5rem; color: var(--yellow); min-height: 30px; }

/* Лампа-сигнал */
.lamp {
  width: 74px; height: 74px; border-radius: 50%; margin: 0 auto 6px;
  background: radial-gradient(circle at 34% 30%, #2a3060, #10133a);
  border: 3px solid rgba(255,255,255,.14);
  transition: background .06s, box-shadow .06s, transform .06s;
  display: flex; align-items: center; justify-content: center; font-size: 1.9rem;
}
.lamp.on {
  background: radial-gradient(circle at 34% 30%, #fffde0, var(--yellow) 55%, var(--orange));
  box-shadow: 0 0 46px 12px rgba(255,217,61,.65), 0 0 90px 30px rgba(255,138,61,.3);
  transform: scale(1.08);
}

/* Осциллограф */
#scope { width: 100%; max-width: 460px; height: 54px; display: block; opacity: .9; }

/* Строка набора */
.io {
  width: 100%; max-width: 460px; border-radius: var(--r-md);
  background: rgba(0,0,0,.36); border: 1.5px solid var(--card-brd);
  padding: 11px 14px; text-align: center; min-height: 74px;
  display: flex; flex-direction: column; justify-content: center; gap: 3px;
}
.io-code {
  font-size: 1.85rem; color: var(--cyan);
  min-height: 34px; line-height: 1.15; word-break: break-all;
}
.io-text { font-size: 1.15rem; color: var(--green); letter-spacing: 3px; min-height: 22px; }
.io-text .cursor { animation: blink 1s steps(2) infinite; color: var(--yellow); }
@keyframes blink { 50% { opacity: 0; } }

/* Варианты ответа */
.choices { display: grid; grid-template-columns: repeat(4, 1fr); gap: 9px; width: 100%; max-width: 460px; }
.choices.n3 { grid-template-columns: repeat(3, 1fr); }
.choices.n2 { grid-template-columns: repeat(2, 1fr); }
.choices.n2 .choice { min-height: 78px; font-size: 2rem; }
.choice {
  min-height: 62px; border-radius: 18px; font-family: inherit;
  font-size: 1.6rem; font-weight: 900; color: var(--ink); cursor: pointer;
  background: var(--card); border: 2px solid var(--card-brd);
  transition: transform .13s, background .2s, border-color .2s;
  display: flex; align-items: center; justify-content: center;
}
.choice:active { transform: scale(.92); }
.choice.right { background: rgba(87,255,143,.24); border-color: var(--green); animation: popIn .35s; }
.choice.wrong { background: rgba(255,90,110,.24); border-color: var(--red); animation: nope .4s; }
@keyframes popIn { 0% { transform: scale(1); } 45% { transform: scale(1.16); } 100% { transform: scale(1); } }
@keyframes nope { 0%,100% { transform: translateX(0); } 22% { transform: translateX(-9px); } 62% { transform: translateX(9px); } }

/* ---------- КЛЮЧ ---------- */
.keypad { flex-shrink: 0; padding-top: 6px; }
.key-row { display: flex; gap: 14px; justify-content: center; align-items: center; }

.key {
  border: none; font-family: inherit; cursor: pointer; color: #071026;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  position: relative; transition: transform .07s, box-shadow .07s, filter .1s;
  user-select: none; -webkit-user-select: none; touch-action: none;
}
.key .glyph { font-size: 2.1rem; font-weight: 900; line-height: 1; }
.key .cap { font-size: .68rem; font-weight: 800; opacity: .72; margin-top: 3px; }

.key.dot {
  width: 112px; height: 112px; border-radius: 50%;
  background: radial-gradient(circle at 34% 28%, #8ff4ff, var(--cyan) 55%, #0aa8cc);
  box-shadow: 0 10px 0 #0a7a96, 0 18px 36px rgba(34,224,255,.35);
}
.key.dash {
  width: 112px; height: 112px; border-radius: 50%;
  background: radial-gradient(circle at 34% 28%, #ffb0ee, var(--pink) 55%, #c01d9d);
  box-shadow: 0 10px 0 #94157a, 0 18px 36px rgba(255,79,216,.35);
}
.key.big {
  width: 100%; max-width: 400px; height: 132px; border-radius: 34px;
  background: linear-gradient(150deg, #ffe27a, var(--yellow) 45%, var(--orange));
  box-shadow: 0 12px 0 #b45c14, 0 22px 44px rgba(255,138,61,.35);
}
.key.pressed { transform: translateY(9px); box-shadow: 0 2px 0 rgba(0,0,0,.35), 0 6px 16px rgba(0,0,0,.4); filter: brightness(1.18); }
.key.aux {
  width: 62px; height: 62px; border-radius: 20px; font-size: 1.35rem;
  background: var(--card); color: var(--ink); border: 1.5px solid var(--card-brd);
  box-shadow: none; backdrop-filter: blur(10px);
}
.key.aux:active { transform: scale(.9); }

.key-hint { text-align: center; font-size: .74rem; color: var(--ink-faint); margin-top: 9px; }

/* ---------- ОБУЧЕНИЕ ---------- */
.learn-card { max-width: 460px; margin: 0 auto; width: 100%; text-align: center; }
.learn-letter {
  font-size: clamp(4rem, 24vw, 7rem); font-weight: 900; line-height: 1;
  background: linear-gradient(135deg, var(--yellow), var(--pink));
  -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent;
  filter: drop-shadow(0 0 30px rgba(255,217,61,.4));
}
.code-blocks { display: flex; gap: 11px; justify-content: center; margin: 14px 0; min-height: 34px; align-items: center; }
.cb { border-radius: 9px; height: 26px; box-shadow: 0 0 16px currentColor; transition: transform .12s, filter .12s; }
.cb.dot  { width: 26px;  background: var(--cyan);  color: var(--cyan); }
.cb.dash { width: 78px;  background: var(--pink);  color: var(--pink); }
.cb.lit  { transform: scale(1.25); filter: brightness(1.5); }

.chant {
  font-size: 1.22rem; font-weight: 900; letter-spacing: .5px;
  margin: 8px 0 4px; line-height: 1.5;
}
.chant .hi { color: var(--pink); }
.chant .lo { color: var(--cyan); font-weight: 700; }

/* ---------- СПРАВОЧНИК ---------- */
.ref-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(112px, 1fr)); gap: 9px; }
.ref-item {
  border-radius: var(--r-sm); padding: 11px 8px; cursor: pointer;
  background: var(--card); border: 1.5px solid var(--card-brd);
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  font-family: inherit; color: var(--ink); transition: transform .14s, border-color .2s;
}
.ref-item:active { transform: scale(.92); border-color: var(--cyan); }
.ref-item .rl { font-size: 1.45rem; font-weight: 900; }
.ref-item .rc { font-size: 1.05rem; color: var(--yellow); min-height: 18px; }
.ref-item .rch { font-size: .64rem; color: rgba(242,246,255,.6); font-weight: 700; text-align: center; line-height: 1.2; }
.ref-item.known { border-color: rgba(87,255,143,.4); }

/* ---------- НАСТРОЙКИ ---------- */
.set-row {
  display: flex; align-items: center; gap: 12px; padding: 13px 0;
  border-bottom: 1px solid rgba(255,255,255,.07);
}
.set-row:last-child { border-bottom: none; }
.set-row .lbl { flex: 1; font-size: .93rem; }
.set-row .lbl small { display: block; color: var(--ink-faint); font-weight: 700; font-size: .74rem; margin-top: 2px; }

.switch { width: 56px; height: 32px; border-radius: 999px; background: rgba(0,0,0,.42); position: relative; cursor: pointer; flex-shrink: 0; border: 1.5px solid var(--card-brd); transition: background .2s; }
.switch::after { content: ''; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%; background: var(--ink-dim); transition: .22s cubic-bezier(.2,.9,.25,1); }
.switch.on { background: linear-gradient(90deg, var(--green), var(--cyan)); }
.switch.on::after { left: 27px; background: #fff; }

.seg { display: flex; gap: 5px; background: rgba(0,0,0,.34); padding: 4px; border-radius: 14px; border: 1.5px solid var(--card-brd); }
.seg button {
  border: none; background: transparent; color: var(--ink-dim); font-family: inherit;
  font-weight: 800; font-size: .84rem; padding: 9px 13px; border-radius: 10px; cursor: pointer; transition: .2s;
}
.seg button.on { background: linear-gradient(145deg, var(--cyan), var(--violet)); color: #071026; }

input[type=range] {
  -webkit-appearance: none; appearance: none; width: 100%; height: 8px;
  border-radius: 5px; background: rgba(0,0,0,.42); outline: none;
}
input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none; width: 26px; height: 26px; border-radius: 50%;
  background: linear-gradient(145deg, var(--cyan), var(--violet));
  box-shadow: 0 3px 10px rgba(0,0,0,.45); cursor: pointer;
}
input[type=range]::-moz-range-thumb {
  width: 26px; height: 26px; border-radius: 50%; border: none;
  background: linear-gradient(145deg, var(--cyan), var(--violet)); cursor: pointer;
}
input[type=text] {
  background: rgba(0,0,0,.34); border: 1.5px solid var(--card-brd); color: var(--ink);
  border-radius: 12px; padding: 12px 14px; font-family: inherit; font-weight: 800;
  font-size: 1rem; width: 100%; outline: none;
}
input[type=text]:focus { border-color: var(--cyan); }

/* ---------- ИТОГИ УРОВНЯ ---------- */
.overlay {
  position: fixed; inset: 0; z-index: 40;
  background: rgba(4, 6, 26, .82); backdrop-filter: blur(9px);
  display: none; align-items: center; justify-content: center; padding: 20px;
}
.overlay.show { display: flex; animation: fadeIn .3s; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.result {
  width: 100%; max-width: 400px; text-align: center;
  border-radius: 32px; padding: 26px 22px;
  background: linear-gradient(165deg, rgba(255,255,255,.13), rgba(255,255,255,.04));
  border: 2px solid var(--card-brd); backdrop-filter: blur(20px);
  box-shadow: var(--shadow); animation: resultIn .5s cubic-bezier(.2,1.3,.4,1);
  max-height: 92vh; overflow-y: auto;
}
@keyframes resultIn { from { transform: scale(.75) translateY(30px); opacity: 0; } to { transform: none; opacity: 1; } }

.star-row { display: flex; justify-content: center; gap: 10px; margin: 14px 0 6px; }
.star-row span {
  font-size: 3rem; opacity: .18; transform: scale(.5); filter: grayscale(1);
  transition: .45s cubic-bezier(.2,1.6,.4,1);
}
.star-row span.lit { opacity: 1; transform: scale(1); filter: none; text-shadow: 0 0 26px rgba(255,217,61,.9); }

.stat-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 9px; margin: 16px 0; }
.stat-box { background: rgba(0,0,0,.3); border-radius: 16px; padding: 11px 6px; border: 1px solid var(--card-brd); }
.stat-box .v { font-size: 1.28rem; font-weight: 900; color: var(--cyan); }
.stat-box .k { font-size: .66rem; color: var(--ink-faint); text-transform: uppercase; letter-spacing: .8px; }

.badge-pop {
  display: flex; align-items: center; gap: 11px; text-align: left;
  background: linear-gradient(120deg, rgba(255,217,61,.18), rgba(255,138,61,.09));
  border: 1.5px solid rgba(255,217,61,.45); border-radius: 18px; padding: 11px 13px; margin: 9px 0;
  animation: popIn .5s;
}
.badge-pop .be { font-size: 2rem; }
.badge-pop .bn { font-weight: 900; font-size: .95rem; }
.badge-pop .bd { font-size: .74rem; color: var(--ink-dim); }

/* ---------- СЕТЕВАЯ ДУЭЛЬ ---------- */
.duel-bars { display: flex; flex-direction: column; gap: 12px; width: 100%; max-width: 460px; }
.duel-side { display: flex; align-items: center; gap: 10px; }
.duel-side .who { width: 74px; font-size: .82rem; font-weight: 900; }
.duel-track { flex: 1; height: 24px; border-radius: 12px; background: rgba(0,0,0,.4); overflow: hidden; position: relative; border: 1.5px solid var(--card-brd); }
.duel-fill { height: 100%; border-radius: 12px; transition: width .4s cubic-bezier(.2,.9,.25,1); }
.duel-fill.me { background: linear-gradient(90deg, var(--cyan), var(--green)); box-shadow: 0 0 16px rgba(34,224,255,.5); }
.duel-fill.op { background: linear-gradient(90deg, var(--pink), var(--orange)); box-shadow: 0 0 16px rgba(255,79,216,.5); }
.room-code {
  font-size: 2.3rem; font-weight: 900; letter-spacing: 8px; text-align: center;
  color: var(--yellow); text-shadow: 0 0 24px rgba(255,217,61,.5); margin: 10px 0;
}

/* ---------- Тосты ---------- */
#toast-host { position: fixed; left: 0; right: 0; top: calc(14px + var(--safe-t)); z-index: 60; display: flex; flex-direction: column; align-items: center; gap: 7px; pointer-events: none; }
.toast {
  background: rgba(10,14,44,.94); border: 1.5px solid var(--card-brd);
  border-radius: 999px; padding: 10px 18px; font-size: .87rem; font-weight: 800;
  box-shadow: var(--shadow); animation: toastIn .34s cubic-bezier(.2,1.4,.4,1);
  max-width: 90vw; text-align: center;
}
@keyframes toastIn { from { transform: translateY(-24px) scale(.85); opacity: 0; } to { transform: none; opacity: 1; } }
.toast.out { animation: toastOut .3s forwards; }
@keyframes toastOut { to { transform: translateY(-18px) scale(.9); opacity: 0; } }

/* ---------- Утилиты ---------- */
.fx-shake { animation: shakeAnim .4s cubic-bezier(.36,.07,.19,.97); }
@keyframes shakeAnim {
  10%, 90% { transform: translateX(calc(var(--shake) * -.25)); }
  20%, 80% { transform: translateX(calc(var(--shake) * .45)); }
  30%, 50%, 70% { transform: translateX(calc(var(--shake) * -.8)); }
  40%, 60% { transform: translateX(var(--shake)); }
}
.hidden { display: none !important; }

/* ---------- Ландшафт / широкий экран ---------- */
@media (min-height: 760px) {
  .key.dot, .key.dash { width: 128px; height: 128px; }
  .key.big { height: 150px; }
}
@media (max-height: 620px) {
  .key.dot, .key.dash { width: 92px; height: 92px; }
  .key.big { height: 104px; }
  .lamp { width: 56px; height: 56px; font-size: 1.4rem; }
  #scope { height: 40px; }
  .prompt-big { font-size: clamp(2rem, 11vw, 3rem); }
}
@media (min-width: 760px) {
  .screen { padding-left: max(16px, calc((100vw - 720px) / 2)); padding-right: max(16px, calc((100vw - 720px) / 2)); }
  .menu-grid { grid-template-columns: repeat(3, 1fr); }
}
@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

/* ============================================================
   ЛАНДШАФТ ТЕЛЕФОНА (высота ≤ 500px)
   Колонка не помещается: табло сплющивалось до полоски.
   Переходим на две колонки — экран слева, ключ справа под большой палец.
   ============================================================ */
@media (orientation: landscape) and (max-height: 500px) {

  #scr-play.active, #scr-free.active, #scr-duel.active, #scr-learn.active {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(220px, 40%);
    grid-template-rows: auto minmax(0, 1fr);
    column-gap: 14px;
    padding-top: calc(6px + var(--safe-t));
    padding-bottom: calc(6px + var(--safe-b));
  }

  #scr-play .hud,
  #scr-free .topbar, #scr-duel .topbar, #scr-learn .topbar {
    grid-column: 1 / -1; grid-row: 1; margin-bottom: 4px;
  }
  #scr-play .stage, #scr-free .stage, #scr-duel .stage, #scr-learn .stage {
    grid-column: 1; grid-row: 2;
    justify-content: flex-start; gap: 8px;
    overflow-y: auto; overflow-x: hidden;
  }
  #scr-play .keypad, #scr-free .keypad, #scr-duel .keypad, #scr-learn .keypad {
    grid-column: 2; grid-row: 2;
    display: flex; flex-direction: column; justify-content: center; gap: 8px;
    padding-top: 0; min-height: 0;
  }

  /* лобби дуэли — на всю ширину, ключа там ещё нет */
  #scr-duel #duel-lobby { grid-column: 1 / -1; grid-row: 2; overflow-y: auto; }

  /* табло больше не имеет права схлопываться */
  .panel, .io, #scope, #scope-free { flex-shrink: 0; }

  /* экономим каждый пиксель высоты */
  .lamp { width: 42px; height: 42px; font-size: 1.1rem; margin-bottom: 2px; }
  #scope, #scope-free { height: 28px; }
  .panel { padding: 10px 14px; }
  .prompt-label { font-size: .66rem; letter-spacing: 1.4px; }
  .prompt-big { font-size: clamp(1.7rem, 11vh, 2.6rem); }
  .prompt-big.word { font-size: clamp(1.1rem, 7vh, 1.7rem); letter-spacing: 2px; }
  .prompt-chant { font-size: .8rem; }
  .prompt-code { font-size: 1.15rem; min-height: 22px; }
  .io { min-height: 54px; padding: 8px 12px; }
  .io-code { font-size: 1.35rem; min-height: 26px; }
  .io-text { font-size: .95rem; }

  .key.dot, .key.dash { width: 82px; height: 82px; }
  .key .glyph { font-size: 1.5rem; }
  .key .cap { font-size: .58rem; }
  .key.aux { width: 46px; height: 46px; font-size: 1rem; border-radius: 15px; }
  .key.big { height: 88px; max-width: 100%; }
  .key-row { gap: 9px; }
  .key-hint { margin-top: 4px; font-size: .66rem; }

  .choice { min-height: 48px; font-size: 1.25rem; border-radius: 14px; }
  .choices { gap: 7px; }

  /* обучение: буква и напев компактнее */
  .learn-letter { font-size: clamp(2.4rem, 16vh, 3.6rem); }
  .code-blocks { margin: 8px 0; min-height: 24px; }
  .cb { height: 20px; } .cb.dot { width: 20px; } .cb.dash { width: 60px; }
  .chant { font-size: 1rem; margin: 4px 0 2px; }
  .speech { padding: 8px 12px; font-size: .78rem; margin: 6px auto; }

  /* аркада остаётся в одну колонку, но ужимается */
  #scr-arcade .stage { gap: 8px; justify-content: center; }

  /* меню и списки: логотип не должен съедать пол-экрана */
  .logo { font-size: clamp(1.6rem, 7vh, 2.2rem); }
  .logo-morse { height: 12px; margin: 5px 0 2px; }
  .logo-morse i { height: 7px; } .logo-morse i.d { width: 7px; } .logo-morse i.l { width: 22px; }
  .logo-sub { font-size: .72rem; }
  .pip { font-size: 2.2rem; }
  /* в коротком ландшафте маскот съедает строку меню — прячем, реплика остаётся */
  #scr-home .pip { display: none; }
  #scr-home .speech { margin: 4px auto 8px; }
  .menu-grid { grid-template-columns: repeat(3, 1fr); }
  .menu-btn { padding: 12px 8px; }
  .menu-btn .ic { font-size: 1.6rem; }
  .result { max-height: 94vh; padding: 16px 18px; }
  .star-row span { font-size: 2.1rem; }
  .stat-grid { margin: 10px 0; }
}
