:root {
  color-scheme: dark;
  --bg: #070a15;
  --panel: #0f152a;
  --line: #25304b;
  --ink: #eaf3ff;
  --muted: #7d91b1;
  --cyan: #4ee0ef;
  --pink: #ff64ad;
  --gold: #ffc477;
}
* {
  box-sizing: border-box;
}
html {
  background: var(--bg);
}
body {
  margin: 0;
  min-height: 100svh;
  background:
    radial-gradient(ellipse 60% 45% at 48% 13%, #14254b 0%, transparent 75%),
    radial-gradient(ellipse 43% 30% at 8% 88%, #261331 0%, transparent 100%), var(--bg);
  font-family:
    system-ui,
    -apple-system,
    Segoe UI,
    Roboto,
    'Helvetica Neue',
    Arial,
    sans-serif;
  color: var(--ink);
  -webkit-tap-highlight-color: transparent;
}
button {
  font: inherit;
  cursor: pointer;
}
button:focus-visible {
  outline: 2px solid #9beaf7;
  outline-offset: 3px;
}
.shell {
  width: min(100% - 24px, 526px);
  margin: 0 auto;
  padding: 18px 0 25px;
}
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 17px;
}
.brand {
  display: flex;
  align-items: center;
  gap: 11px;
}
.brand-mark {
  display: grid;
  place-items: center;
  width: 45px;
  height: 45px;
  background: linear-gradient(145deg, #204466, #13233f);
  border: 1px solid #416381;
  border-radius: 13px;
  color: var(--cyan);
  font-size: 28px;
  box-shadow:
    inset 0 0 17px #2651744d,
    0 0 26px #19bfd621;
}
.eyebrow {
  display: block;
  color: var(--muted);
  font-size: 9px;
  font-weight: 750;
  letter-spacing: 2px;
}
.brand h1 {
  margin: 1px 0 0;
  font-weight: 900;
  font-size: 25px;
  line-height: 1;
  letter-spacing: 2px;
}
.brand-dot {
  color: var(--cyan);
}
.top-actions {
  display: flex;
  gap: 7px;
}
.icon-btn {
  height: 39px;
  min-width: 39px;
  border: 1px solid #304364;
  border-radius: 9px;
  background: #17223c;
  color: #d9eaff;
  font-size: 17px;
  font-weight: 750;
}
.sound-state {
  font-size: 9px;
  letter-spacing: 0.4px;
}
.hud {
  background: #0d162b;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 14px;
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  margin-bottom: 10px;
  gap: 8px;
}
.hud-cell:not(:last-child) {
  border-right: 1px solid #263351;
}
.hud-label {
  color: var(--muted);
  font-size: 9px;
  font-weight: 800;
  letter-spacing: 1.4px;
  display: block;
}
.hud-sector {
  display: none;
}
.hud-value {
  display: block;
  margin-top: 4px;
  font-size: 20px;
  font-weight: 900;
  letter-spacing: 1.6px;
  font-variant-numeric: tabular-nums;
}
.hud-value.lives {
  color: #fa7eaa;
  letter-spacing: 2px;
  white-space: nowrap;
  font-size: 16px;
  margin-top: 6px;
}
.game-frame {
  border: 1px solid #3c5577;
  border-radius: 12px;
  padding: 5px;
  background: linear-gradient(145deg, #1d3655, #171b37 52%, #4d2548);
  box-shadow:
    0 15px 50px #03060f99,
    0 0 0 1px #7796b322;
}
.game-stage {
  position: relative;
  aspect-ratio: 2/3;
  max-height: calc(100svh - 305px);
  min-height: 280px;
  width: min(100%, calc((100svh - 305px) * 2 / 3));
  margin: auto;
  background: #070f22;
  overflow: hidden;
  border-radius: 7px;
}
canvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  user-select: none;
  cursor: crosshair;
}
.stage-status {
  position: absolute;
  top: 11px;
  left: 15px;
  font-size: 9px;
  font-weight: 850;
  letter-spacing: 1.8px;
  color: #92a9cd;
  pointer-events: none;
  display: flex;
  align-items: center;
  gap: 7px;
}
.led {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #5cf3c1;
  box-shadow: 0 0 9px #5cf3c1;
}
.stage-corner {
  position: absolute;
  width: 19px;
  height: 19px;
  pointer-events: none;
  border-color: #62d4f59c;
}
.stage-corner--tl {
  top: 5px;
  left: 5px;
  border-top: 1px solid;
  border-left: 1px solid;
}
.stage-corner--tr {
  top: 5px;
  right: 5px;
  border-top: 1px solid;
  border-right: 1px solid;
}
.stage-corner--bl {
  bottom: 5px;
  left: 5px;
  border-bottom: 1px solid;
  border-left: 1px solid;
}
.stage-corner--br {
  bottom: 5px;
  right: 5px;
  border-bottom: 1px solid;
  border-right: 1px solid;
}
.overlay {
  position: absolute;
  inset: 0;
  z-index: 2;
  background: linear-gradient(180deg, #08132895 0%, #0a112ce6 56%, #0c1027e8 100%);
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  text-align: center;
  padding: 30px 30px 55px;
  backdrop-filter: blur(3px);
}
.overlay[hidden] {
  display: none;
}
.overlay-icon {
  width: 74px;
  height: 74px;
  border-radius: 21px;
  display: grid;
  place-items: center;
  background: linear-gradient(140deg, #1c7c93, #13335f);
  color: #d3fcff;
  font-size: 45px;
  box-shadow: 0 0 45px #3ad5ed52;
  border: 1px solid #60d9e55e;
  transform: rotate(-8deg);
  margin-bottom: 22px;
}
.overlay-kicker {
  margin: 0 0 8px;
  color: var(--cyan);
  font-size: 10px;
  font-weight: 850;
  letter-spacing: 2.8px;
}
.overlay h2 {
  font-size: clamp(24px, 7vw, 37px);
  margin: 0 0 12px;
  letter-spacing: 2.1px;
  line-height: 1.12;
}
.overlay p {
  line-height: 1.65;
  color: #b4c5e1;
  font-size: 13px;
  max-width: 292px;
  margin: 0 0 20px;
}
.overlay-action {
  background: linear-gradient(100deg, #4dd5e9, #789cff);
  color: #07152b;
  border: none;
  border-radius: 11px;
  padding: 13px 25px;
  font-size: 14px;
  font-weight: 900;
  letter-spacing: 1px;
  box-shadow: 0 7px 28px #3bb6f446;
}
.overlay-small {
  font-size: 11px;
  color: #7f95bb;
  line-height: 1.6;
  margin-top: 15px;
  max-width: 265px;
}
.charge {
  margin: 13px 3px 0;
}
.charge-heading {
  display: flex;
  justify-content: space-between;
  color: #9aabca;
  font-size: 10px;
  font-weight: 900;
  letter-spacing: 1.2px;
  margin-bottom: 8px;
}
.charge-track {
  height: 9px;
  background: #1b2540;
  border-radius: 20px;
  overflow: hidden;
  border: 1px solid #314365;
}
.charge-fill {
  height: 100%;
  width: 0%;
  border-radius: inherit;
  background: linear-gradient(90deg, #4ad6e4, #7986ff 56%, #fa70bb);
  transition: width 0.18s ease;
}
.hint {
  font-size: 11px;
  color: #8195b7;
  margin: 8px 0 0;
  min-height: 14px;
}
.controls {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 13px;
}
.control-btn {
  height: 52px;
  background: #1b2a48;
  border: 1px solid #3b5777;
  border-radius: 11px;
  color: #eaf6ff;
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 1.25px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
}
.control-btn:hover:not(:disabled) {
  background: #263b5f;
}
.control-btn--pulse {
  background: #2b2040;
  border-color: #634679;
}
.control-btn--pulse:hover:not(:disabled) {
  background: #3e2c55;
}
.control-btn:disabled {
  opacity: 0.46;
  cursor: default;
}
.control-icon {
  font-size: 20px;
  line-height: 1;
}
.footer {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
  color: #607594;
  margin-top: 18px;
  font-size: 9px;
  font-weight: 850;
  letter-spacing: 0.6px;
}
@media (max-width: 390px) {
  .shell {
    width: calc(100% - 16px);
    padding-top: 10px;
  }
  .brand h1 {
    font-size: 21px;
  }
  .brand-mark {
    width: 39px;
    height: 39px;
  }
  .topbar {
    margin-bottom: 10px;
  }
  .hud {
    padding: 8px;
  }
  .hud-value {
    font-size: 17px;
  }
  .hud-value.lives {
    font-size: 13px;
  }
  .game-stage {
    max-height: calc(100svh - 228px);
    width: min(100%, calc((100svh - 228px) * 2 / 3));
  }
  .overlay {
    padding: 20px 19px 45px;
  }
  .overlay-icon {
    width: 55px;
    height: 55px;
    font-size: 35px;
    margin-bottom: 13px;
  }
  .overlay h2 {
    font-size: 25px;
  }
  .overlay p {
    font-size: 12px;
    margin-bottom: 14px;
  }
  .footer {
    margin-top: 10px;
  }
}
@media (max-height: 690px) {
  .shell {
    padding-top: 7px;
  }
  .topbar {
    margin-bottom: 8px;
  }
  .hud {
    padding: 7px 12px;
    margin-bottom: 6px;
  }
  .game-stage {
    max-height: calc(100svh - 275px);
    width: min(100%, calc((100svh - 275px) * 2 / 3));
  }
  .charge {
    margin-top: 8px;
  }
  .controls {
    margin-top: 8px;
  }
  .control-btn {
    height: 43px;
  }
  .footer {
    margin-top: 8px;
  }
  .hint {
    margin-top: 4px;
  }
}
/* На коротких экранах размещаем вступление и кнопки без обрезания. */
@media (max-height: 600px) {
  .overlay {
    padding: 10px 9px 16px;
  }
  .overlay-icon {
    width: 39px;
    height: 39px;
    margin-bottom: 6px;
    font-size: 25px;
  }
  .overlay-kicker {
    font-size: 8px;
    letter-spacing: 1.7px;
    margin-bottom: 4px;
  }
  .overlay h2 {
    font-size: 20px;
    margin-bottom: 6px;
  }
  .overlay p {
    font-size: 10px;
    line-height: 1.35;
    margin-bottom: 8px;
  }
  .overlay-action {
    padding: 9px 12px;
    font-size: 11px;
  }
  .overlay-small {
    display: none;
  }
}
/* В альбомной ориентации допускаем прокрутку, не сжимая игровую арену. */
@media (max-height: 500px) and (orientation: landscape) {
  .game-stage {
    min-height: 360px;
    max-height: none;
    width: min(100%, 240px);
  }
}
/*
 * Портретный мобильный экран: HUD размещается над свободной верхней областью.
 * Соотношение Canvas 480×720 неизменно, иначе нарушится физическая геометрия.
 */
@media (max-width: 540px) and (orientation: portrait) {
  .shell {
    width: 100%;
    max-width: 540px;
    margin: 0 auto;
    padding: 4px 6px max(4px, env(safe-area-inset-bottom));
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas: 'top' 'arena' 'energy' 'actions';
    row-gap: 4px;
  }
  .topbar {
    grid-area: top;
    min-height: 34px;
    margin: 0;
    gap: 6px;
  }
  .brand {
    gap: 6px;
    min-width: 0;
  }
  .brand-mark {
    width: 30px;
    height: 30px;
    border-radius: 9px;
    font-size: 20px;
    box-shadow: none;
    flex-shrink: 0;
  }
  .brand h1 {
    font-size: clamp(17px, 5.3vw, 22px);
    line-height: 1;
    letter-spacing: 1px;
    white-space: nowrap;
  }
  .eyebrow {
    font-size: 7px;
    letter-spacing: 1.1px;
  }
  .top-actions {
    gap: 4px;
  }
  .icon-btn {
    width: 34px;
    min-width: 34px;
    height: 34px;
    padding: 0;
    border-radius: 8px;
    font-size: 17px;
  }
  .sound-state {
    display: none;
  }
  .game-frame {
    grid-area: arena;
    min-width: 0;
    width: 100%;
    padding: 2px;
    border-radius: 9px;
    box-shadow: none;
    align-self: start;
  }
  .game-stage {
    width: min(100%, calc((100dvh - 140px) * 2 / 3));
    min-height: 0;
    max-height: none;
    aspect-ratio: 2 / 3;
    height: auto;
    border-radius: 6px;
  }
  .hud {
    grid-area: arena;
    z-index: 4;
    align-self: start;
    justify-self: stretch;
    margin: 5px 9px 0;
    padding: 5px 7px;
    gap: 3px;
    border-radius: 8px;
    background: #08132ddf;
    border-color: #385377a0;
    backdrop-filter: blur(6px);
    pointer-events: none;
  }
  .hud-cell {
    min-width: 0;
  }
  .hud-cell:not(:last-child) {
    border-right-color: #3c4d69;
  }
  .hud-label {
    font-size: 7px;
    letter-spacing: 0.5px;
    line-height: 1.1;
  }
  .hud-sector {
    display: inline;
    color: var(--cyan);
    font-size: 7px;
    white-space: nowrap;
    letter-spacing: 0;
    margin-left: 3px;
  }
  .hud-value {
    margin-top: 2px;
    font-size: clamp(12px, 3.8vw, 16px);
    letter-spacing: 0.3px;
    line-height: 1.1;
  }
  .hud-value.lives {
    margin-top: 3px;
    font-size: clamp(11px, 3.3vw, 15px);
    letter-spacing: 0;
  }
  .stage-status {
    display: none;
  }
  .stage-corner {
    opacity: 0.45;
  }
  .overlay {
    padding: 10px;
    background: linear-gradient(180deg, #07122684 0%, #09122ad9 45%, #091127d9 100%);
    backdrop-filter: blur(2px);
  }
  .overlay-icon {
    width: 40px;
    height: 40px;
    border-radius: 12px;
    font-size: 27px;
    margin-bottom: 7px;
    box-shadow: 0 0 22px #3ad5ed40;
  }
  .overlay-kicker {
    margin-bottom: 4px;
    font-size: 8px;
    letter-spacing: 1.4px;
  }
  .overlay h2 {
    font-size: clamp(19px, 5.8vw, 26px);
    letter-spacing: 1px;
    margin-bottom: 8px;
  }
  .overlay p {
    font-size: 11px;
    line-height: 1.35;
    max-width: 240px;
    margin-bottom: 10px;
  }
  .overlay-action {
    min-height: 40px;
    padding: 8px 15px;
    border-radius: 9px;
    font-size: 12px;
  }
  .overlay-small {
    display: none;
  }
  .charge {
    grid-area: energy;
    margin: 0 2px;
    min-width: 0;
  }
  .charge-heading {
    font-size: 9px;
    letter-spacing: 0.4px;
    margin-bottom: 3px;
  }
  .charge-track {
    height: 6px;
  }
  .hint {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
  }
  .controls {
    grid-area: actions;
    margin: 0;
    gap: 6px;
    min-width: 0;
  }
  .control-btn {
    height: 39px;
    padding: 0 4px;
    gap: 6px;
    border-radius: 8px;
    font-size: clamp(10px, 3vw, 12px);
    letter-spacing: 0.25px;
  }
  .control-icon {
    font-size: 16px;
  }
  .footer {
    display: none;
  }
}
/* На маленьких портретных экранах оставляем место под панели браузера. */
@media (max-width: 540px) and (orientation: portrait) and (max-height: 600px) {
  .game-stage {
    width: min(100%, calc((100dvh - 148px) * 2 / 3));
  }
  .overlay-icon {
    width: 32px;
    height: 32px;
    font-size: 22px;
    margin-bottom: 4px;
  }
  .overlay p {
    font-size: 10px;
    line-height: 1.25;
    margin-bottom: 7px;
  }
  .overlay h2 {
    font-size: 19px;
    margin-bottom: 5px;
  }
  .overlay-action {
    min-height: 36px;
    padding: 6px 12px;
  }
}
/* 0.9.0: компактная вторая кнопка при наличии контрольной точки. */
.overlay-new-game {
  margin-top: 9px;
  background: #162541;
  border: 1px solid #6880ac;
  color: #c9ddfb;
  box-shadow: none;
  font-size: 11px;
  padding: 9px 17px;
  letter-spacing: 0.8px;
}
.overlay-new-game:focus-visible {
  outline: 2px solid #6ce4ec;
  outline-offset: 2px;
}
@media (max-height: 600px) {
  .overlay-new-game {
    min-height: 30px;
    padding: 5px 10px;
    margin-top: 5px;
    font-size: 10px;
  }
}
/* 1.0 RC: настройки должны быть поверх затемнения паузы на всех экранах. */
.settings-panel {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: grid;
  place-items: center;
  background: #080e23eb;
  padding: 12px;
  overflow-y: auto;
  overscroll-behavior: contain;
}
.settings-panel[hidden] {
  display: none;
}
.settings-dialog {
  width: min(100%, 310px);
  max-height: 100%;
  overflow-y: auto;
  padding: 15px 17px;
  border: 1px solid #577a9d;
  border-radius: 15px;
  background: #111c34;
  box-shadow: 0 15px 35px #0008;
  display: grid;
  gap: 7px;
}
.settings-heading {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 3px;
}
.settings-heading h2 {
  font-size: 17px;
  letter-spacing: 1.5px;
  margin: 0;
  color: #ebfaff;
}
.settings-close {
  width: 30px;
  height: 30px;
  border-radius: 7px;
  border: 1px solid #597294;
  background: #23314b;
  color: #edf8ff;
  font-size: 16px;
}
.settings-dialog label {
  color: #c8e6f3;
  font-size: 10px;
  letter-spacing: 0.75px;
  font-weight: 800;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.settings-dialog output {
  font-variant-numeric: tabular-nums;
  color: #75dcf0;
}
.settings-dialog input[type='range'] {
  width: 100%;
  margin: 0 0 8px;
  accent-color: #65dceb;
  height: 23px;
  touch-action: pan-x;
}
.settings-dialog select {
  width: 100%;
  padding: 7px 6px;
  border-radius: 7px;
  border: 1px solid #526d91;
  background: #1b2d4c;
  color: #ecf8ff;
  font-size: 12px;
  margin-bottom: 7px;
}
.settings-dialog p {
  margin: 0;
  color: #9eb4cf;
  font-size: 10px;
  line-height: 1.35;
}
.settings-done {
  margin-top: 5px;
  padding: 9px 12px;
  border: 0;
  border-radius: 8px;
  background: linear-gradient(100deg, #52d5e5, #819fff);
  color: #10213c;
  font-weight: 850;
  font-size: 12px;
}
.settings-panel button:focus-visible,
.settings-panel input:focus-visible,
.settings-panel select:focus-visible {
  outline: 2px solid #86f8ff;
  outline-offset: 2px;
}
@media (max-height: 600px) {
  .settings-dialog {
    gap: 3px;
    padding: 9px 12px;
  }
  .settings-heading h2 {
    font-size: 14px;
  }
  .settings-dialog input[type='range'] {
    margin-bottom: 4px;
    height: 18px;
  }
  .settings-dialog select {
    margin-bottom: 4px;
  }
  .settings-dialog p {
    font-size: 9px;
  }
  .settings-done {
    padding: 6px 10px;
  }
}

/* Итоги забега: три главных числа остаются читаемыми на узком экране. */
.run-stats {
  width: 100%;
  max-width: 300px;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
  margin: -5px 0 10px;
}
.run-stats > div {
  min-width: 0;
  padding: 7px 3px;
  border: 1px solid #334864;
  border-radius: 7px;
  background: #0b1835b5;
}
.run-stats span {
  display: block;
  color: #a5c2e1;
  font-size: 9px;
  font-weight: 800;
  letter-spacing: 0.2px;
}
.run-stats strong {
  display: block;
  margin-top: 3px;
  color: #f2faff;
  font-size: 17px;
  font-variant-numeric: tabular-nums;
}
.run-stats-more {
  max-width: 305px;
  margin: -3px 0 12px;
  color: #a3c8df;
  font-size: 10px;
  line-height: 1.4;
}
@media (max-width: 540px) and (orientation: portrait) {
  .run-stats {
    gap: 4px;
    margin: -2px 0 7px;
  }
  .run-stats > div {
    padding: 4px 2px;
  }
  .run-stats span {
    font-size: 8px;
    letter-spacing: 0;
  }
  .run-stats strong {
    font-size: 14px;
    margin-top: 1px;
  }
  .run-stats-more {
    font-size: 9px;
    margin: -2px 0 8px;
  }
}
@media (max-height: 500px) {
  .run-stats {
    margin: 0 0 5px;
    gap: 3px;
  }
  .run-stats > div {
    padding: 3px 2px;
  }
  .run-stats strong {
    font-size: 13px;
  }
  .run-stats-more {
    font-size: 9px;
    margin-bottom: 6px;
  }
}
