:root {
  color-scheme: dark;
  --bg: #05070b;
  --panel: rgba(8, 13, 24, 0.8);
  --panel-strong: rgba(7, 10, 20, 0.94);
  --line: rgba(113, 224, 255, 0.3);
  --line-hot: #68e7ff;
  --gold: #ffd84a;
  --green: #67f08b;
  --pink: #ff5f9f;
  --violet: #9d7cff;
  --red: #ff4c5f;
  --ink: #f7fbff;
  --muted: #93a6bd;
  --shadow: 0 24px 70px rgba(0, 0, 0, 0.5);
  --display-font: "Fredoka", "Assistant", "Noto Sans Hebrew", Arial, sans-serif;
  --body-font: "Assistant", "Noto Sans Hebrew", Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  overflow: hidden;
  background:
    linear-gradient(180deg, rgba(0, 0, 0, 0.08), rgba(0, 0, 0, 0.7)),
    repeating-linear-gradient(90deg, rgba(255, 255, 255, 0.025) 0 1px, transparent 1px 80px),
    repeating-linear-gradient(0deg, rgba(255, 255, 255, 0.018) 0 1px, transparent 1px 80px),
    #05070b;
  color: var(--ink);
  font-family: var(--body-font);
  direction: rtl;
  -webkit-font-smoothing: antialiased;
}

button,
input {
  font: inherit;
}

button {
  color: inherit;
}

.game-shell {
  --shell-padding: clamp(8px, 1.4vw, 18px);
  --stage-width: min(
    calc(100vw - var(--shell-padding) - var(--shell-padding)),
    1180px,
    calc((100dvh - 132px - var(--shell-padding) - var(--shell-padding)) * 1.3333)
  );
  --joystick-size: 112px;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  display: grid;
  grid-template-rows: auto auto;
  align-content: center;
  justify-items: center;
  gap: clamp(6px, 1.1dvh, 10px);
  padding: var(--shell-padding);
}

.stage {
  position: relative;
  width: var(--stage-width);
  aspect-ratio: 4 / 3;
  overflow: hidden;
  touch-action: none;
  border: 1px solid rgba(104, 231, 255, 0.24);
  background: #02040a;
  box-shadow:
    var(--shadow),
    inset 0 0 0 1px rgba(255, 255, 255, 0.05),
    inset 0 0 70px rgba(10, 55, 96, 0.35);
}

.stage-hit {
  animation: stageHit 460ms ease;
}

#game-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  background: #02040a;
}

.hud {
  position: relative;
  width: var(--stage-width);
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(150px, 25%) auto;
  align-items: start;
  gap: 12px;
  z-index: 5;
  pointer-events: none;
}

.hud-group {
  display: flex;
  align-items: stretch;
  gap: 8px;
  min-width: 0;
}

.hud-group-main {
  flex-wrap: wrap;
}

.metric {
  min-width: 82px;
  padding: 8px 10px 9px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(2, 6, 14, 0.68);
  box-shadow: inset 0 0 18px rgba(104, 231, 255, 0.08);
  backdrop-filter: blur(8px);
}

.metric-label {
  display: block;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.1;
  margin-bottom: 4px;
}

.metric strong {
  display: block;
  color: var(--ink);
  font-size: clamp(16px, 2.2vw, 22px);
  line-height: 1;
  white-space: nowrap;
}

.metric-muted {
  color: var(--muted);
  font-size: 0.78em;
  padding-inline-start: 2px;
}

.metric-lives strong {
  color: var(--red);
  letter-spacing: 0;
}

.metric-world {
  min-width: 96px;
}

.metric-world strong {
  max-width: 118px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.metric-mission {
  position: absolute;
  inline-size: 1px;
  block-size: 1px;
  min-width: 0;
  flex: 0 0 auto;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  clip-path: inset(50%);
  border: 0;
  white-space: nowrap;
}

.metric-mission strong {
  overflow: hidden;
  color: var(--gold);
  font-size: clamp(13px, 1.7vw, 17px);
  line-height: 1.18;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.mission-progress {
  display: block;
  margin-top: 5px;
  color: var(--line-hot);
  font-size: 12px;
  line-height: 1;
}

.metric-pulse {
  animation: metricPulse 440ms ease;
}

.life-hit {
  animation: lifeHit 520ms ease;
}

.progress-wrap {
  height: 12px;
  margin-top: 8px;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.16);
  background: rgba(0, 0, 0, 0.45);
  box-shadow: 0 0 26px rgba(104, 231, 255, 0.18);
}

.progress-pulse {
  animation: progressPulse 520ms ease;
}

#progress-fill {
  width: 0%;
  height: 100%;
  background: linear-gradient(90deg, var(--green), var(--gold), var(--pink));
  box-shadow: 0 0 20px rgba(255, 216, 74, 0.55);
  transition: width 240ms ease;
}

.hud-actions {
  justify-content: flex-end;
  pointer-events: auto;
}

.icon-button {
  width: 42px;
  height: 42px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  background: rgba(2, 6, 14, 0.72);
  cursor: pointer;
  box-shadow: inset 0 0 18px rgba(104, 231, 255, 0.08);
}

.icon-button:hover,
.icon-button:focus-visible {
  outline: none;
  border-color: rgba(104, 231, 255, 0.7);
  box-shadow:
    0 0 0 3px rgba(104, 231, 255, 0.18),
    inset 0 0 18px rgba(104, 231, 255, 0.12);
}

.screen {
  position: fixed;
  inset: 0;
  z-index: 14;
  display: grid;
  place-items: center;
  overflow-y: auto;
  padding: clamp(10px, 2vmin, 24px);
  background:
    linear-gradient(180deg, rgba(0, 0, 0, 0.34), rgba(0, 0, 0, 0.76)),
    rgba(2, 5, 12, 0.62);
  backdrop-filter: blur(6px);
}

.dialog {
  position: absolute;
  left: 50%;
  top: 50%;
  z-index: 12;
  width: min(300px, calc(100% - 48px));
  display: block;
  transform: translate(-50%, -50%);
  pointer-events: auto;
}

.dialog[hidden],
.screen[hidden] {
  display: none;
}

.dialog-inner,
.screen-panel {
  position: relative;
  isolation: isolate;
  border: 1px solid rgba(104, 231, 255, 0.42);
  background:
    linear-gradient(180deg, rgba(10, 16, 32, 0.96), rgba(5, 7, 17, 0.98)),
    var(--panel-strong);
  box-shadow:
    0 24px 90px rgba(0, 0, 0, 0.66),
    0 0 0 4px rgba(104, 231, 255, 0.04),
    inset 0 0 44px rgba(104, 231, 255, 0.08);
  text-align: center;
}

.dialog-inner::before,
.screen-panel::before {
  content: "";
  position: absolute;
  inset: 7px;
  z-index: -1;
  border: 1px solid rgba(255, 216, 74, 0.18);
  pointer-events: none;
}

.screen-panel::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -2;
  background:
    linear-gradient(90deg, transparent 0 9px, rgba(104, 231, 255, 0.08) 9px 10px, transparent 10px 100%),
    linear-gradient(0deg, transparent 0 9px, rgba(255, 216, 74, 0.07) 9px 10px, transparent 10px 100%);
  background-size: 40px 40px;
  opacity: 0.34;
  pointer-events: none;
}

.dialog-inner {
  width: 100%;
  padding: clamp(12px, 2vw, 18px);
}

.screen-panel {
  width: min(520px, 92%);
  max-height: 100%;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: clamp(18px, 3vmin, 30px);
  scrollbar-gutter: stable;
}

.dialog-kicker,
.eyebrow {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 26px;
  padding: 4px 10px;
  border: 1px solid rgba(104, 231, 255, 0.42);
  color: var(--line-hot);
  background: rgba(104, 231, 255, 0.1);
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0;
  line-height: 1.2;
  box-shadow: inset 0 0 16px rgba(104, 231, 255, 0.08);
}

.dialog h1,
.screen h1 {
  margin: 16px 0 18px;
  color: var(--gold);
  font-family: var(--display-font);
  font-weight: 700;
  font-size: clamp(36px, 7vw, 66px);
  line-height: 1;
  text-shadow: 0 0 24px rgba(255, 216, 74, 0.42);
}

.dialog h1 {
  direction: ltr;
  unicode-bidi: bidi-override;
  font-size: clamp(30px, 4.8vw, 42px);
}

.question-timer {
  display: inline-grid;
  grid-template-columns: auto auto;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-width: 74px;
  margin-top: 10px;
  padding: 6px 10px;
  border: 1px solid rgba(255, 216, 74, 0.36);
  background: rgba(255, 216, 74, 0.08);
  color: var(--gold);
  font-size: 14px;
  line-height: 1;
}

.question-timer[hidden] {
  display: none;
}

.question-timer strong {
  min-width: 2ch;
  font-size: 20px;
  line-height: 1;
  text-align: center;
}

.question-timer-low {
  border-color: rgba(255, 76, 95, 0.65);
  background: rgba(255, 76, 95, 0.14);
  color: var(--red);
}

.screen h1 {
  margin-top: 10px;
  font-size: clamp(34px, 6vw, 56px);
  letter-spacing: 0;
}

.start-graphic {
  position: relative;
  display: grid;
  grid-template-columns: 58px repeat(3, 12px) 42px 42px;
  align-items: center;
  justify-content: center;
  gap: 12px;
  height: 74px;
  margin: 10px auto 4px;
  overflow: hidden;
  border-block: 1px solid rgba(104, 231, 255, 0.16);
}

.start-graphic::before {
  content: "×";
  position: absolute;
  inset-inline-start: 38px;
  top: 50%;
  color: rgba(255, 216, 74, 0.44);
  font-family: var(--display-font);
  font-size: 34px;
  transform: translateY(-52%);
}

.start-graphic::after {
  content: "12";
  position: absolute;
  inset-inline-end: 32px;
  top: 50%;
  color: rgba(103, 240, 139, 0.44);
  font-family: var(--display-font);
  font-size: 24px;
  transform: translateY(-48%);
}

.start-graphic-pacman {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: conic-gradient(from 35deg, transparent 0 74deg, var(--gold) 75deg 360deg);
  box-shadow: 0 0 28px rgba(255, 216, 74, 0.46);
}

.start-graphic-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #f7fbff;
  box-shadow: 0 0 12px rgba(247, 251, 255, 0.66);
}

.start-graphic-ghost {
  position: relative;
  width: 38px;
  height: 42px;
  border-radius: 18px 18px 9px 9px;
  background: var(--pink);
  box-shadow: 0 0 22px rgba(255, 95, 159, 0.38);
}

.start-graphic-ghost::before,
.start-graphic-ghost::after {
  content: "";
  position: absolute;
  top: 13px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #f7fbff;
}

.start-graphic-ghost::before {
  left: 9px;
}

.start-graphic-ghost::after {
  right: 9px;
}

.start-graphic-ghost-b {
  background: var(--line-hot);
  box-shadow: 0 0 22px rgba(104, 231, 255, 0.36);
}

#answer-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  direction: ltr;
}

#answer-input {
  min-width: 0;
  height: 48px;
  border: 1px solid rgba(104, 231, 255, 0.44);
  background: rgba(0, 0, 0, 0.42);
  color: var(--ink);
  text-align: center;
  font-size: 24px;
  outline: none;
}

#answer-input:focus {
  border-color: var(--gold);
  box-shadow: 0 0 0 3px rgba(255, 216, 74, 0.18);
}

#submit-answer,
.primary-button {
  min-height: 48px;
  border: 1px solid rgba(247, 251, 255, 0.16);
  background: linear-gradient(135deg, #13c985, #86f76f);
  color: #031009;
  cursor: pointer;
  font-family: var(--display-font);
  font-weight: 700;
  padding: 0 16px;
  box-shadow:
    0 12px 34px rgba(19, 201, 133, 0.24),
    inset 0 1px 0 rgba(255, 255, 255, 0.34);
}

#submit-answer:hover,
#submit-answer:focus-visible,
.primary-button:hover,
.primary-button:focus-visible {
  outline: none;
  filter: brightness(1.08);
  box-shadow:
    0 0 0 3px rgba(103, 240, 139, 0.2),
    0 16px 42px rgba(19, 201, 133, 0.3);
}

#question-feedback {
  min-height: 22px;
  margin: 12px 0 0;
  color: var(--muted);
}

.screen-visible {
  display: grid;
}

.screen-panel {
  border-color: rgba(104, 231, 255, 0.34);
}

.screen-panel p {
  margin: 0;
}

.screen-stats {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 10px;
  margin: 18px 0 22px;
}

.screen-stats span {
  min-width: 104px;
  padding: 9px 12px;
  border: 1px solid rgba(104, 231, 255, 0.2);
  background: rgba(104, 231, 255, 0.055);
  color: var(--muted);
  box-shadow: inset 0 0 18px rgba(104, 231, 255, 0.05);
}

.screen-stats strong {
  color: var(--ink);
}

.name-form {
  display: grid;
  gap: 10px;
  margin-top: 4px;
}

.name-form label {
  color: var(--muted);
  font-size: 14px;
  font-weight: 700;
}

#player-name-input {
  width: 100%;
  height: 54px;
  border: 1px solid rgba(104, 231, 255, 0.5);
  background: rgba(0, 0, 0, 0.5);
  color: var(--ink);
  text-align: center;
  font-family: var(--display-font);
  font-size: 24px;
  outline: none;
  box-shadow:
    inset 0 0 18px rgba(104, 231, 255, 0.08),
    0 10px 26px rgba(0, 0, 0, 0.22);
}

#player-name-input:focus {
  border-color: var(--gold);
  box-shadow: 0 0 0 3px rgba(255, 216, 74, 0.18);
}

.form-note {
  min-height: 20px;
  color: var(--red);
  font-size: 13px;
}

.difficulty-field {
  display: grid;
  gap: 8px;
  margin: 0;
  padding: 0;
  border: 0;
}

.difficulty-field legend {
  display: block;
  width: 100%;
  padding: 0;
  color: var(--ink);
  font-size: 15px;
  font-weight: 900;
  line-height: 1.2;
  text-align: center;
  text-shadow: 0 0 10px rgba(104, 231, 255, 0.28);
}

.difficulty-options {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 6px;
}

.difficulty-options label {
  min-width: 0;
}

.difficulty-options input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.difficulty-options span {
  display: grid;
  min-height: 42px;
  place-items: center;
  padding: 0 7px;
  border: 1px solid rgba(104, 231, 255, 0.32);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.075), rgba(255, 255, 255, 0.025));
  color: var(--ink);
  cursor: pointer;
  font-weight: 800;
  line-height: 1.15;
  overflow-wrap: anywhere;
  text-align: center;
  box-shadow: inset 0 0 16px rgba(104, 231, 255, 0.04);
}

.difficulty-options input:checked + span {
  border-color: rgba(255, 216, 74, 0.82);
  background:
    linear-gradient(180deg, rgba(255, 216, 74, 0.22), rgba(255, 216, 74, 0.08));
  color: var(--gold);
  box-shadow:
    0 0 0 2px rgba(255, 216, 74, 0.08),
    inset 0 0 20px rgba(255, 216, 74, 0.12);
}

.difficulty-options input:focus-visible + span {
  outline: 2px solid rgba(104, 231, 255, 0.72);
  outline-offset: 2px;
}

.time-limit-setting {
  display: grid;
  justify-items: center;
  gap: 7px;
  margin: 2px 0 4px;
}

.time-limit-title {
  color: var(--muted);
  font-size: 14px;
  font-weight: 700;
  line-height: 1.2;
}

.time-limit-toggle {
  position: relative;
  display: grid;
  width: 56px;
  height: 56px;
  place-items: center;
  border: 1px solid rgba(104, 231, 255, 0.34);
  border-radius: 50%;
  background:
    radial-gradient(circle at 50% 50%, rgba(104, 231, 255, 0.16), rgba(2, 6, 14, 0.76) 68%),
    rgba(255, 255, 255, 0.04);
  cursor: pointer;
  box-shadow:
    inset 0 0 18px rgba(104, 231, 255, 0.1),
    0 12px 28px rgba(0, 0, 0, 0.34);
}

.time-limit-toggle:hover,
.time-limit-toggle:focus-visible {
  outline: none;
  border-color: rgba(255, 216, 74, 0.78);
  box-shadow:
    0 0 0 3px rgba(255, 216, 74, 0.14),
    inset 0 0 18px rgba(255, 216, 74, 0.12),
    0 14px 32px rgba(0, 0, 0, 0.4);
}

.time-limit-toggle[aria-pressed="true"] {
  border-color: rgba(255, 216, 74, 0.86);
  background:
    radial-gradient(circle at 50% 50%, rgba(255, 216, 74, 0.24), rgba(2, 6, 14, 0.78) 68%),
    rgba(255, 216, 74, 0.08);
}

.clock-icon {
  position: relative;
  width: 28px;
  height: 28px;
  border: 3px solid currentColor;
  border-radius: 50%;
  color: var(--line-hot);
}

.time-limit-toggle[aria-pressed="true"] .clock-icon {
  color: var(--gold);
}

.clock-icon::before,
.clock-icon::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: 50%;
  width: 3px;
  background: currentColor;
  border-radius: 999px;
  transform-origin: bottom center;
}

.clock-icon::before {
  height: 9px;
  transform: translateX(-50%) rotate(0deg);
}

.clock-icon::after {
  height: 7px;
  transform: translateX(-50%) rotate(115deg);
}

.time-limit-state {
  min-height: 17px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.2;
}

.time-limit-toggle[aria-pressed="true"] + .time-limit-state {
  color: var(--gold);
}

.winner-trophy {
  font-size: clamp(56px, 10vw, 94px);
  line-height: 1;
  margin-bottom: 8px;
  filter: drop-shadow(0 0 22px rgba(255, 216, 74, 0.55));
}

.primary-button {
  min-width: min(240px, 100%);
  font-size: 18px;
}

.mobile-joystick {
  display: none;
}

.touch-pad {
  display: none !important;
}

@media (max-height: 820px) {
  .screen {
    padding: 12px;
  }

  .screen-panel {
    padding: 16px;
  }

  .dialog h1,
  .screen h1 {
    margin: 10px 0 12px;
  }

  .screen h1 {
    font-size: clamp(30px, 5.2vw, 48px);
  }

  .start-graphic {
    grid-template-columns: 46px repeat(3, 9px) 34px 34px;
    gap: 9px;
    height: 52px;
    margin: 6px auto 2px;
  }

  .start-graphic::before {
    inset-inline-start: 30px;
    font-size: 25px;
  }

  .start-graphic::after {
    inset-inline-end: 24px;
    font-size: 19px;
  }

  .start-graphic-pacman {
    width: 38px;
    height: 38px;
  }

  .start-graphic-dot {
    width: 7px;
    height: 7px;
  }

  .start-graphic-ghost {
    width: 30px;
    height: 33px;
  }

  .start-graphic-ghost::before,
  .start-graphic-ghost::after {
    top: 10px;
    width: 6px;
    height: 6px;
  }

  .start-graphic-ghost::before {
    left: 8px;
  }

  .start-graphic-ghost::after {
    right: 8px;
  }

  .screen-stats {
    gap: 6px;
    margin: 10px 0 12px;
  }

  .screen-stats span {
    padding: 7px 9px;
  }

  .name-form,
  .difficulty-field {
    gap: 8px;
  }

  #player-name-input {
    height: 46px;
    font-size: 20px;
  }

  .difficulty-options span {
    min-height: 38px;
  }

  .time-limit-setting {
    gap: 5px;
    margin: 0;
  }

  .time-limit-toggle {
    width: 48px;
    height: 48px;
  }

  .clock-icon {
    width: 24px;
    height: 24px;
  }

  .primary-button {
    min-height: 44px;
  }
}

@media (max-height: 620px) {
  .hud {
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 6px;
  }

  .hud-group-main {
    gap: 4px;
  }

  .metric {
    min-width: 58px;
    padding: 4px 6px;
  }

  .metric-world {
    min-width: 68px;
  }

  .metric-label {
    margin-bottom: 3px;
    font-size: 9px;
  }

  .metric strong {
    font-size: 14px;
  }

  .progress-wrap {
    grid-column: 1 / -1;
    grid-row: 2;
    margin-top: 0;
  }

  .icon-button {
    width: 30px;
    height: 30px;
  }
}

.joystick-base {
  position: relative;
  width: var(--joystick-size);
  height: var(--joystick-size);
  border: 1px solid rgba(104, 231, 255, 0.34);
  border-radius: 50%;
  background:
    radial-gradient(circle at 50% 50%, rgba(255, 216, 74, 0.13), transparent 29%),
    radial-gradient(circle at 50% 50%, rgba(104, 231, 255, 0.18), rgba(2, 6, 14, 0.78) 68%);
  box-shadow:
    inset 0 0 28px rgba(104, 231, 255, 0.15),
    0 18px 38px rgba(0, 0, 0, 0.42);
  cursor: grab;
  touch-action: none;
  user-select: none;
}

.joystick-base::before,
.joystick-base::after {
  content: "";
  position: absolute;
  inset: 50% auto auto 50%;
  width: 70%;
  height: 1px;
  background: rgba(247, 251, 255, 0.12);
  transform: translate(-50%, -50%);
  pointer-events: none;
}

.joystick-base::after {
  width: 1px;
  height: 70%;
}

.joystick-base.is-active {
  border-color: rgba(255, 216, 74, 0.72);
  cursor: grabbing;
  box-shadow:
    inset 0 0 30px rgba(255, 216, 74, 0.13),
    0 0 0 6px rgba(255, 216, 74, 0.08),
    0 18px 38px rgba(0, 0, 0, 0.42);
}

.joystick-knob {
  --knob-x: 0px;
  --knob-y: 0px;
  position: absolute;
  left: 50%;
  top: 50%;
  width: 48%;
  height: 48%;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 50%;
  background: radial-gradient(circle at 32% 28%, #fff8a5, #ffd84a 42%, #f0a500);
  box-shadow:
    0 8px 18px rgba(0, 0, 0, 0.42),
    0 0 22px rgba(255, 216, 74, 0.45);
  transform: translate(calc(-50% + var(--knob-x)), calc(-50% + var(--knob-y)));
  transition: transform 120ms ease;
  pointer-events: none;
}

@media (hover: none), (pointer: coarse) {
  .mobile-joystick {
    display: grid;
    width: var(--stage-width);
    place-items: center;
    pointer-events: auto;
  }
}

@media (max-width: 760px) {
  html,
  body {
    height: 100dvh;
    overflow: hidden;
  }

  body {
    min-height: 100dvh;
  }

  .game-shell {
    --joystick-size: clamp(92px, 25vw, 116px);
    --stage-width: min(100%, calc((100dvh - 218px - env(safe-area-inset-bottom)) * 1.3333));
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    height: 100dvh;
    min-height: 100dvh;
    gap: 8px;
    overflow: hidden;
    padding: max(8px, env(safe-area-inset-top)) 8px max(10px, env(safe-area-inset-bottom));
  }

  .stage {
    width: var(--stage-width);
    flex: 0 0 auto;
    margin-top: 0;
  }

  .hud {
    width: var(--stage-width);
    grid-template-columns: 1fr auto;
    gap: 8px;
    flex: 0 0 auto;
  }

  .hud-group-main {
    gap: 5px;
  }

  .metric {
    min-width: 68px;
    padding: 6px 7px;
  }

  .metric-label {
    font-size: 10px;
  }

  .metric strong {
    font-size: 15px;
  }

  .metric-mission {
    flex-basis: 100%;
    order: 2;
  }

  .metric-mission strong {
    font-size: 13px;
  }

  .progress-wrap {
    grid-column: 1 / -1;
    grid-row: 2;
    margin-top: 0;
  }

  .icon-button {
    width: 34px;
    height: 34px;
  }

  .screen {
    position: fixed;
    inset: 0;
    overflow-y: auto;
    padding: max(14px, env(safe-area-inset-top)) 14px max(14px, env(safe-area-inset-bottom));
  }

  .dialog {
    position: fixed;
    top: 42%;
    width: min(280px, calc(100% - 24px));
  }

  .screen-panel {
    width: min(340px, calc(100vw - 28px));
    max-height: calc(100dvh - 28px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
    overflow-y: auto;
    padding: 14px;
  }

  .screen h1 {
    margin: 10px 0 12px;
    font-size: clamp(26px, 8vw, 38px);
    line-height: 1.05;
    white-space: normal;
    overflow-wrap: anywhere;
  }

  .screen-stats {
    gap: 6px;
    margin: 10px 0 12px;
  }

  .screen-stats span {
    min-width: 92px;
    padding: 7px 9px;
  }

  .name-form {
    gap: 8px;
  }

  #player-name-input {
    height: 46px;
    font-size: 20px;
  }

  .primary-button {
    min-height: 44px;
    font-size: 16px;
  }

  .difficulty-options span {
    min-height: 38px;
    font-size: 14px;
  }

  .difficulty-options {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  #answer-form {
    grid-template-columns: 1fr;
  }

  .mobile-joystick {
    display: grid;
    width: 100%;
    min-height: calc(var(--joystick-size) + 12px);
    margin-top: auto;
    padding-top: 6px;
    place-items: center;
    flex: 0 0 auto;
  }

  .joystick-knob {
    transition: transform 80ms ease;
  }
}

@media (max-width: 760px) and (max-height: 560px) {
  .game-shell {
    --joystick-size: 82px;
    --stage-width: min(100%, calc((100dvh - 170px - env(safe-area-inset-bottom)) * 1.3333));
    gap: 6px;
  }

  .metric {
    min-width: 60px;
    padding: 5px 6px;
  }

  .metric-label {
    font-size: 9px;
  }

  .metric strong {
    font-size: 14px;
  }

  .icon-button {
    width: 30px;
    height: 30px;
  }
}

@keyframes metricPulse {
  0% {
    border-color: rgba(255, 255, 255, 0.12);
    box-shadow: inset 0 0 18px rgba(104, 231, 255, 0.08);
  }
  45% {
    border-color: rgba(103, 240, 139, 0.9);
    box-shadow:
      0 0 0 3px rgba(103, 240, 139, 0.18),
      inset 0 0 22px rgba(103, 240, 139, 0.2);
  }
  100% {
    border-color: rgba(255, 255, 255, 0.12);
    box-shadow: inset 0 0 18px rgba(104, 231, 255, 0.08);
  }
}

@keyframes progressPulse {
  0% {
    box-shadow: 0 0 26px rgba(104, 231, 255, 0.18);
  }
  50% {
    box-shadow:
      0 0 0 3px rgba(255, 216, 74, 0.18),
      0 0 34px rgba(255, 216, 74, 0.42);
  }
  100% {
    box-shadow: 0 0 26px rgba(104, 231, 255, 0.18);
  }
}

@keyframes lifeHit {
  0%,
  100% {
    border-color: rgba(255, 255, 255, 0.12);
  }
  45% {
    border-color: rgba(255, 76, 95, 0.95);
    box-shadow:
      0 0 0 3px rgba(255, 76, 95, 0.2),
      inset 0 0 24px rgba(255, 76, 95, 0.18);
  }
}

@keyframes stageHit {
  0%,
  100% {
    filter: none;
  }
  45% {
    filter: drop-shadow(0 0 22px rgba(255, 76, 95, 0.48));
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
  }
}
