:root {
  color-scheme: dark;
  --white: #f7fbfc;
  --muted: #a9b6ba;
  --cyan: #08d6ef;
  --cyan-soft: rgba(8, 214, 239, .18);
  --danger: #ff3b4f;
  --black: #050708;
  --wood: #a86f43;
  --line: rgba(255, 255, 255, .22);
  /* Aliases kept for the independent ranking screen. */
  --ink: var(--white);
  --panel: rgba(7, 11, 12, .88);
  --lime: var(--cyan);
  --violet: var(--wood);
}

* { box-sizing: border-box; }

html,
body {
  width: 100%;
  height: 100%;
  min-width: 320px;
  margin: 0;
  overflow: hidden;
  background: var(--black);
}

body {
  color: var(--white);
  font-family: Arial, Helvetica, ui-sans-serif, system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}

button,
input { font: inherit; }

button { color: inherit; }

.game-stage,
.arena {
  width: 100%;
  height: 100vh;
  height: 100dvh;
}

.arena {
  position: relative;
  overflow: hidden;
  isolation: isolate;
  background: #101416;
}

.arena::before,
.arena::after {
  content: "";
  position: absolute;
  z-index: 0;
  inset: 0;
  pointer-events: none;
}

.arena::before {
  background:
    linear-gradient(180deg, rgba(0, 0, 0, .08), rgba(0, 0, 0, .16)),
    url("./assets/backgrounds/gamingcity-counter.webp") center / cover no-repeat;
  filter: brightness(1) contrast(1);
  transform: scale(1.01);
  transition: filter 1.15s ease;
}

.arena::after {
  background:
    linear-gradient(180deg, rgba(2, 5, 6, .58) 0, transparent 17%, transparent 73%, rgba(2, 4, 5, .68) 100%),
    linear-gradient(90deg, rgba(0, 0, 0, .18), transparent 17%, transparent 83%, rgba(0, 0, 0, .18));
  transition: background 1.15s ease, opacity .35s ease;
}

.arena.night-mode::before { filter: brightness(.29) saturate(.65) contrast(1.32); }
.arena.night-mode::after {
  background:
    radial-gradient(ellipse at 88% 46%, rgba(0, 220, 255, .29), transparent 30%),
    radial-gradient(ellipse at 12% 45%, rgba(0, 188, 235, .2), transparent 28%),
    linear-gradient(180deg, rgba(0, 0, 0, .72), rgba(0, 5, 8, .28) 38%, rgba(0, 0, 0, .66));
}

.arena.fire-mode::before { filter: brightness(.42) saturate(.82) contrast(1.38); }
.arena.fire-mode::after {
  background:
    radial-gradient(ellipse at 88% 46%, rgba(0, 224, 255, .2), transparent 29%),
    radial-gradient(ellipse at 12% 45%, rgba(255, 91, 22, .13), transparent 27%),
    linear-gradient(180deg, rgba(0, 0, 0, .72), rgba(5, 7, 8, .3) 42%, rgba(0, 0, 0, .68));
  animation: shelfLights 3.2s ease-in-out infinite;
}

.arena.stage-night::before { animation: lightsOut 1.75s ease both; }
.arena.stage-fire::before { animation: powerSurge 1.8s ease both; }
.arena.stage-fire::after { animation: showroomFlash 1.8s ease both; }

@keyframes lightsOut {
  0% { filter: brightness(1); }
  18% { filter: brightness(.05); }
  31% { filter: brightness(.72); }
  46% { filter: brightness(.02); }
  63% { filter: brightness(.38); }
  100% { filter: brightness(.29) saturate(.65) contrast(1.32); }
}

@keyframes powerSurge {
  0%, 20%, 46% { filter: brightness(.18) saturate(.7); }
  10%, 34%, 62% { filter: brightness(.95) saturate(1.1); }
  100% { filter: brightness(.42) saturate(.82) contrast(1.38); }
}

@keyframes showroomFlash {
  0%, 20%, 46% { opacity: .36; }
  10%, 34%, 62% { opacity: 1; }
  100% { opacity: .88; }
}

@keyframes shelfLights {
  0%, 100% { opacity: .72; }
  50% { opacity: 1; }
}

#gameCanvas {
  position: absolute;
  z-index: 1;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  cursor: crosshair;
  user-select: none;
  -webkit-user-select: none;
}

.game-header {
  position: absolute;
  z-index: 11;
  top: 0;
  left: 0;
  right: 0;
  min-height: 86px;
  display: grid;
  grid-template-columns: minmax(210px, 1fr) auto minmax(210px, 1fr);
  align-items: start;
  gap: 22px;
  padding: max(17px, env(safe-area-inset-top)) max(20px, env(safe-area-inset-right)) 0 max(20px, env(safe-area-inset-left));
  pointer-events: none;
}

.brand,
.header-actions,
.overlay { pointer-events: auto; }

.brand {
  justify-self: start;
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--white);
  text-decoration: none;
  filter: drop-shadow(0 2px 12px rgba(0, 0, 0, .75));
}

.brand-logo { width: 46px; height: 46px; object-fit: contain; }
.brand small { color: rgba(255, 255, 255, .72); font-size: 8px; font-weight: 900; letter-spacing: .24em; }
.scoreboard-page .brand-logo { width: 52px; height: 52px; }
.hud {
  justify-self: center;
  display: flex;
  align-items: flex-start;
  padding-top: 2px;
  filter: drop-shadow(0 2px 10px rgba(0, 0, 0, .8));
}

.hud-cell {
  min-width: 112px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
  padding: 0 20px;
  border-right: 1px solid rgba(255, 255, 255, .35);
}

.hud-cell:last-child { border: 0; }
.hud-cell span,
.live-metrics span,
.result-grid span,
.result-caption {
  color: rgba(255, 255, 255, .7);
  font-size: 8px;
  font-weight: 900;
  letter-spacing: .19em;
}

.hud-cell strong {
  color: var(--white);
  font-size: clamp(19px, 2.1vw, 27px);
  font-variant-numeric: tabular-nums;
  letter-spacing: .02em;
  line-height: 1.1;
  text-shadow: 0 2px 10px #000;
}

.hud-level strong { color: var(--cyan); }
.hud-lives strong { color: var(--danger); font-size: 15px; letter-spacing: .15em; line-height: 1.65; white-space: nowrap; }
.hud-lives strong i { font-style: normal; }
.hud-lives .gold-life { color: #ffd65a; text-shadow: 0 0 12px rgba(255, 214, 90, .9); }
.hud-lives .half-life {
  color: transparent;
  background: linear-gradient(90deg, var(--danger) 50%, rgba(255, 255, 255, .28) 50%);
  background-clip: text;
  -webkit-background-clip: text;
}
.hud-lives .gold-life.half-life {
  background: linear-gradient(90deg, #ffd65a 50%, rgba(255, 255, 255, .28) 50%);
  background-clip: text;
  -webkit-background-clip: text;
}

.header-actions {
  justify-self: end;
  display: flex;
  gap: 8px;
}

.icon-button {
  min-height: 34px;
  padding: 0 11px;
  border: 1px solid rgba(255, 255, 255, .45);
  border-radius: 0;
  background: rgba(4, 8, 9, .42);
  box-shadow: 0 2px 12px rgba(0, 0, 0, .28);
  font-size: 8px;
  font-weight: 900;
  letter-spacing: .12em;
  cursor: pointer;
  backdrop-filter: blur(5px);
}

.icon-button:hover,
.icon-button:focus-visible {
  border-color: var(--cyan);
  color: var(--cyan);
  outline: none;
}

.level-progress {
  position: absolute;
  z-index: 6;
  top: 0;
  left: 0;
  width: 100%;
  height: 3px;
  pointer-events: none;
  background: rgba(255, 255, 255, .12);
}

.level-progress i {
  display: block;
  width: 0;
  height: 100%;
  background: var(--cyan);
  box-shadow: 0 0 13px rgba(8, 214, 239, .85);
  transition: width .12s linear;
}

.combo-badge {
  position: absolute;
  z-index: 7;
  top: 94px;
  right: max(22px, env(safe-area-inset-right));
  color: var(--white);
  font-size: 9px;
  font-weight: 900;
  letter-spacing: .14em;
  text-align: right;
  text-shadow: 0 2px 14px #000;
  opacity: 0;
  transform: translateX(12px) skew(-8deg);
  transition: .16s ease;
  pointer-events: none;
}

.combo-badge::before {
  content: "";
  position: absolute;
  left: -12px;
  top: 50%;
  width: 3px;
  height: 36px;
  background: var(--cyan);
  transform: translateY(-50%);
  box-shadow: 0 0 12px var(--cyan);
}

.combo-badge.show { opacity: 1; transform: skew(-8deg); }
.combo-badge b { display: block; color: var(--cyan); font-size: 24px; line-height: .9; }

.notice {
  position: absolute;
  z-index: 7;
  top: 43%;
  left: 50%;
  width: min(92%, 660px);
  color: var(--white);
  font-size: clamp(29px, 5.5vw, 70px);
  font-weight: 950;
  font-style: italic;
  line-height: .86;
  letter-spacing: -.05em;
  text-align: center;
  text-transform: uppercase;
  text-shadow: 0 5px 28px #000, 3px 3px 0 rgba(8, 214, 239, .5);
  opacity: 0;
  transform: translate(-50%, -50%) scale(.78) rotate(-2deg);
  transition: .16s ease;
  pointer-events: none;
}

.notice.show { opacity: 1; transform: translate(-50%, -50%) scale(1) rotate(-2deg); }
.notice small { display: block; margin-top: 13px; color: var(--cyan); font-size: 10px; font-style: normal; letter-spacing: .27em; text-shadow: 0 2px 12px #000; }

.energy-warning {
  position: absolute;
  z-index: 7;
  left: 50%;
  bottom: max(62px, calc(env(safe-area-inset-bottom) + 52px));
  padding: 8px 12px;
  border-left: 2px solid #ff8b32;
  color: #ffcf7a;
  background: rgba(3, 7, 8, .58);
  font-size: 8px;
  font-weight: 900;
  letter-spacing: .12em;
  text-transform: uppercase;
  text-shadow: 0 2px 8px #000;
  opacity: 0;
  transform: translate(-50%, 8px);
  transition: .18s ease;
  pointer-events: none;
}

.energy-warning b { margin-left: 8px; color: #fff; }
.energy-warning.show { opacity: 1; transform: translate(-50%, 0); }

.live-metrics {
  position: absolute;
  z-index: 6;
  left: max(20px, env(safe-area-inset-left));
  bottom: max(17px, env(safe-area-inset-bottom));
  display: flex;
  align-items: center;
  filter: drop-shadow(0 2px 9px #000);
  pointer-events: none;
}

.live-metrics div {
  min-width: 96px;
  padding: 0 15px;
  border-left: 2px solid rgba(255, 255, 255, .42);
}

.live-metrics div:first-child { padding-left: 0; border-left: 0; }
.live-metrics span { display: block; font-size: 7px; }
.live-metrics b { display: block; margin-top: 2px; font-size: 14px; font-variant-numeric: tabular-nums; }

.overlay {
  position: absolute;
  z-index: 10;
  inset: 0;
  display: flex;
  align-items: center;
  padding: clamp(88px, 11vh, 130px) max(6vw, 42px) clamp(68px, 9vh, 100px);
}

.overlay[hidden] { display: none; }
.intro-overlay { justify-content: flex-start; background: linear-gradient(90deg, rgba(2, 5, 6, .94) 0, rgba(2, 5, 6, .82) 28%, rgba(2, 5, 6, .18) 66%, transparent 86%); }
.result-overlay { justify-content: center; background: radial-gradient(ellipse at center, rgba(2, 5, 6, .92) 0, rgba(2, 5, 6, .68) 37%, rgba(2, 5, 6, .12) 70%, transparent 85%); }
.performance-toggle {
  position: absolute;
  right: max(18px, env(safe-area-inset-right));
  bottom: max(20px, env(safe-area-inset-bottom));
  padding: 7px 9px;
  border: 0;
  border-left: 1px solid rgba(8, 214, 239, .55);
  color: rgba(255, 255, 255, .72);
  background: rgba(2, 6, 7, .45);
  font-size: 7px;
  font-weight: 900;
  letter-spacing: .13em;
  cursor: pointer;
  opacity: .55;
}
.performance-toggle b { color: var(--cyan); }
.performance-toggle:hover, .performance-toggle:focus-visible { opacity: 1; outline: 1px solid rgba(8, 214, 239, .45); }
.performance-mode .icon-button { backdrop-filter: none; }
.panel { position: relative; width: min(650px, 100%); }
.eyebrow { color: var(--cyan); font-size: 9px; font-weight: 900; letter-spacing: .24em; text-shadow: 0 2px 9px #000; }

.intro-panel h1 {
  margin: 17px 0 18px;
  font-size: clamp(52px, 8.2vw, 112px);
  font-weight: 950;
  font-style: italic;
  line-height: .76;
  letter-spacing: -.065em;
  text-shadow: 0 5px 30px rgba(0, 0, 0, .72);
}

.intro-panel h1 i {
  color: var(--cyan);
  font-style: inherit;
  text-shadow: 4px 4px 0 rgba(255, 255, 255, .17), 0 0 30px rgba(8, 214, 239, .2);
}

.intro-panel p {
  max-width: 470px;
  margin: 0 0 24px;
  color: #d4dee0;
  font-size: clamp(12px, 1.25vw, 15px);
  line-height: 1.55;
  text-shadow: 0 2px 9px #000;
}

#startForm { width: min(500px, 100%); }
#startForm label { display: block; margin-bottom: 7px; color: rgba(255, 255, 255, .7); font-size: 8px; font-weight: 900; letter-spacing: .2em; }
.name-row { display: grid; grid-template-columns: 1fr auto; gap: 9px; }
.name-row input {
  min-width: 0;
  height: 50px;
  padding: 0 16px;
  border: 1px solid rgba(255, 255, 255, .56);
  border-radius: 0;
  outline: none;
  color: var(--white);
  background: rgba(0, 0, 0, .34);
  font-size: 14px;
  font-weight: 800;
  letter-spacing: .08em;
  text-transform: uppercase;
  backdrop-filter: blur(4px);
}

.name-row input::placeholder { color: rgba(255, 255, 255, .42); }
.name-row input:focus { border-color: var(--cyan); box-shadow: inset 4px 0 0 var(--cyan); }

.touch-keyboard { display: grid; gap: 5px; margin-top: 11px; touch-action: manipulation; }
.keyboard-row { display: flex; justify-content: center; gap: 5px; }
.touch-key {
  flex: 1 1 0;
  max-width: 44px;
  min-height: 42px;
  padding: 0;
  border: 1px solid rgba(255, 255, 255, .32);
  color: #fff;
  background: rgba(4, 11, 13, .76);
  box-shadow: inset 0 -2px 0 rgba(8, 214, 239, .22);
  font-size: 12px;
  font-weight: 900;
  cursor: pointer;
}
.touch-key:hover,
.touch-key:focus-visible { border-color: var(--cyan); outline: none; }
.touch-key:active { color: #031012; background: var(--cyan); transform: translateY(2px); }
.touch-key-delete { flex-grow: 2; max-width: 84px; color: #ffcf7a; font-size: 18px; }

.primary-button {
  min-height: 50px;
  padding: 0 22px;
  border: 0;
  border-radius: 0;
  color: #041012;
  background: var(--cyan);
  box-shadow: 5px 5px 0 rgba(255, 255, 255, .2), 0 0 24px rgba(8, 214, 239, .14);
  font-size: 10px;
  font-weight: 950;
  letter-spacing: .13em;
  cursor: pointer;
  transition: transform .13s ease, box-shadow .13s ease;
}

.primary-button span { margin-left: 8px; font-size: 17px; }
.primary-button:hover,
.primary-button:focus-visible { transform: translate(-2px, -2px); box-shadow: 8px 8px 0 rgba(255, 255, 255, .22); outline: none; }
.primary-button:active { transform: translate(2px, 2px); box-shadow: 2px 2px 0 rgba(255, 255, 255, .22); }
.primary-button:disabled { opacity: .38; transform: none; box-shadow: none; cursor: default; }
.primary-button.wide { width: 100%; margin-top: 22px; }

.how-to { display: flex; gap: clamp(14px, 2.4vw, 28px); margin-top: 23px; color: rgba(255, 255, 255, .68); font-size: 8px; font-weight: 800; letter-spacing: .08em; text-shadow: 0 2px 8px #000; }
.how-to span { white-space: nowrap; }
.how-to b { margin-right: 5px; color: var(--cyan); }

.result-panel { max-width: 460px; text-align: center; filter: drop-shadow(0 3px 22px #000); }
.result-panel h2 { margin: 13px 0 24px; font-size: clamp(38px, 5vw, 67px); font-style: italic; line-height: .84; letter-spacing: -.055em; }
.result-caption { display: block; }
.result-score { display: block; margin: 5px 0 19px; color: var(--cyan); font-size: clamp(58px, 9vw, 104px); font-variant-numeric: tabular-nums; line-height: .95; }
.result-grid { display: grid; grid-template-columns: repeat(4, 1fr); border-block: 1px solid rgba(255, 255, 255, .36); }
.result-grid div { padding: 14px 8px; border-right: 1px solid rgba(255, 255, 255, .25); }
.result-grid div:last-child { border: 0; }
.result-grid span { display: block; min-height: 19px; font-size: 7px; }
.result-grid b { display: block; font-size: 18px; }
.result-ranking { display: inline-block; margin-top: 20px; color: var(--white); font-size: 8px; font-weight: 900; letter-spacing: .15em; text-underline-offset: 5px; }
.leaderboard-data {
  position: absolute;
  z-index: 6;
  top: 50%;
  left: max(18px, env(safe-area-inset-left));
  width: 205px;
  padding: 9px 10px;
  color: rgba(255, 255, 255, .9);
  background: rgba(1, 5, 7, .28);
  font-size: 9px;
  font-weight: 850;
  letter-spacing: .08em;
  text-shadow: 0 2px 7px #000;
  transform: translateY(-50%);
  transition: opacity .18s ease;
  pointer-events: none;
}

.leaderboard-head,
.rank-row {
  display: grid;
  grid-template-columns: 30px 1fr auto;
  align-items: center;
  gap: 8px;
}

.leaderboard-head { padding-bottom: 5px; color: rgba(255, 255, 255, .52); font-size: 7px; }
.leaderboard-head span:last-child { text-align: right; }
#leaderboardList { margin: 0; padding: 0; list-style: none; }
.rank-row { min-height: 25px; border-top: 1px solid rgba(255, 255, 255, .12); }
.rank-position { color: var(--cyan); font-variant-numeric: tabular-nums; }
.rank-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rank-score { text-align: right; font-variant-numeric: tabular-nums; }
#leaderboardEmpty { margin: 6px 0 0; color: rgba(255, 255, 255, .55); font-size: 7px; }
#introPanel:not([hidden]) ~ .leaderboard-data,
#resultPanel:not([hidden]) ~ .leaderboard-data { opacity: 0; }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@media (max-width: 920px) {
  .game-header { grid-template-columns: 1fr auto; }
  .hud { position: absolute; top: 64px; left: 50%; transform: translateX(-50%); }
  .hud-cell { min-width: 92px; padding-inline: 15px; }
  .intro-overlay { background: linear-gradient(90deg, rgba(2, 5, 6, .92), rgba(2, 5, 6, .7) 58%, rgba(2, 5, 6, .2)); }
}

@media (max-width: 680px) {
  .game-header { min-height: 62px; padding: max(11px, env(safe-area-inset-top)) max(11px, env(safe-area-inset-right)) 0 max(11px, env(safe-area-inset-left)); }
  .brand { gap: 7px; }
  .brand-logo { width: 34px; height: 34px; }
  .brand small { font-size: 5px; letter-spacing: .18em; }
  #soundButton { display: none; }
  .icon-button { min-height: 30px; padding-inline: 8px; font-size: 7px; }
  .hud { top: 51px; width: 100%; justify-content: center; }
  .hud-cell { min-width: 0; width: 30%; max-width: 112px; padding-inline: 8px; }
  .hud-cell span { font-size: 6px; }
  .hud-cell strong { font-size: 16px; }
  .hud-lives strong { font-size: 11px; line-height: 1.6; }
  .combo-badge { top: 98px; right: 13px; }
  .overlay { align-items: center; padding: 106px 18px 67px; }
  .intro-overlay { background: linear-gradient(90deg, rgba(2, 5, 6, .88), rgba(2, 5, 6, .64)); }
  .intro-panel h1 { margin-block: 13px; font-size: clamp(47px, 16vw, 77px); }
  .intro-panel p { margin-bottom: 16px; font-size: 11px; }
  .performance-toggle { right: 10px; bottom: max(10px, env(safe-area-inset-bottom)); }
  .name-row { grid-template-columns: 1fr; gap: 7px; }
  .name-row input, .primary-button { height: 45px; min-height: 45px; }
  .how-to { display: none; }
  .live-metrics { left: 11px; right: 11px; bottom: max(9px, env(safe-area-inset-bottom)); justify-content: space-between; }
  .live-metrics div { min-width: 0; padding: 0 8px; }
  .live-metrics span { font-size: 5px; letter-spacing: .11em; }
  .live-metrics b { font-size: 11px; }
  .leaderboard-data { top: 138px; left: 8px; width: 158px; padding: 7px; font-size: 8px; transform: none; }
  .leaderboard-head, .rank-row { grid-template-columns: 25px 1fr auto; gap: 5px; }
  .leaderboard-head { font-size: 6px; }
  .rank-row { min-height: 22px; }
  .result-panel h2 { font-size: 39px; }
  .result-score { font-size: 63px; }
}

@media (max-height: 560px) and (orientation: landscape) {
  .game-header { padding-top: 9px; }
  .brand-logo { width: 32px; height: 32px; }
  .hud { position: static; transform: none; padding-top: 0; }
  .hud-cell { min-width: 82px; padding-inline: 10px; }
  .hud-cell strong { font-size: 16px; }
  .hud-cell span { font-size: 6px; }
  .overlay { align-items: flex-start; padding: 62px 34px 43px; }
  .intro-panel { max-width: 640px; }
  .intro-panel h1 { margin: 8px 0 9px; font-size: clamp(45px, 11.8vh, 70px); }
  .intro-panel p { max-width: 540px; margin-bottom: 10px; font-size: 10px; }
  .name-row input, .primary-button { height: 39px; min-height: 39px; }
  .touch-keyboard { gap: 3px; margin-top: 6px; }
  .keyboard-row { gap: 3px; }
  .touch-key { min-height: 34px; }
  .performance-toggle { right: 8px; bottom: 7px; padding: 5px 7px; font-size: 6px; }
  .how-to { margin-top: 10px; }
  .result-panel h2 { margin: 7px 0 10px; font-size: 35px; }
  .result-score { margin-block: 2px 8px; font-size: 49px; }
  .result-grid div { padding-block: 7px; }
  .primary-button.wide { margin-top: 10px; }
  .result-ranking { margin-top: 11px; }
  .live-metrics { bottom: 8px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
