@font-face {
  font-family: "Bangers";
  src: url("assets/fonts/bangers-400.ttf") format("truetype");
  font-style: normal;
  font-weight: 400;
  font-display: swap;
}

@font-face {
  font-family: "Nunito";
  src: url("assets/fonts/nunito-600.ttf") format("truetype");
  font-style: normal;
  font-weight: 600;
  font-display: swap;
}

@font-face {
  font-family: "Nunito";
  src: url("assets/fonts/nunito-700.ttf") format("truetype");
  font-style: normal;
  font-weight: 700;
  font-display: swap;
}

@font-face {
  font-family: "Nunito";
  src: url("assets/fonts/nunito-800.ttf") format("truetype");
  font-style: normal;
  font-weight: 800;
  font-display: swap;
}

:root {
  --bg-deep: #1a1644;
  --bg-mid: #2d2a68;
  --panel: rgba(20, 27, 56, 0.72);
  --panel-border: rgba(255, 255, 255, 0.18);
  --gold: #ffd56a;
  --orange: #ff8e42;
  --mint: #74f3d8;
  --danger: #ff6978;
  --text: #f9fbff;
  --shadow: 0 12px 32px rgba(8, 12, 30, 0.42);
  --projectile-image: url("assets/themes/castle/projectile-arcane.png");
  --debug-bg-offset-y: 0px;
  --debug-path-offset-y: 0px;
  --debug-tower-offset-y: 0px;
  --debug-castle-offset-y: 0px;
  --debug-tower-scale: 1;
  --debug-castle-scale: 1;
  --platform-upshift-y: 0px;
  --battle-upshift-y: 50px;
  --castle-extra-shift-y: -60px;
  --world-tower-bottom-px: 0px;
  --world-castle-bottom-px: 0px;
  --keypad-bottom-extra: 30px;
  --app-max-width: 560px;
}

* {
  box-sizing: border-box;
}

button {
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  margin: 0;
  min-height: 100%;
  font-family: "Nunito", "Trebuchet MS", sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at 20% 20%, #4e7bff 0%, rgba(78, 123, 255, 0) 35%),
    radial-gradient(circle at 80% 70%, #1cd4b7 0%, rgba(28, 212, 183, 0) 30%),
    linear-gradient(160deg, var(--bg-deep), #262058 45%, var(--bg-mid));
}

body {
  display: grid;
  place-items: center;
  padding: 10px;
}

.game-shell {
  width: min(100vw, var(--app-max-width));
  max-width: var(--app-max-width);
  display: flex;
  align-items: flex-start;
  gap: 10px;
}

.phone-frame {
  position: relative;
  width: min(100%, var(--app-max-width));
  max-width: var(--app-max-width);
  height: min(900px, calc(100dvh - 12px));
  min-height: 640px;
  border-radius: 30px;
  overflow: hidden;
  border: 2px solid rgba(255, 255, 255, 0.35);
  box-shadow: var(--shadow);
  background: linear-gradient(180deg, #6ea6ff 0%, #3f7ccf 56%, #28466a 100%);
  display: flex;
  flex-direction: column;
  --layer-sky-epic: url("assets/themes/basic/backgrounds/bg-sky-epic.svg");
  --layer-sky-alt: url("assets/themes/basic/backgrounds/bg-sky.svg");
  --layer-hills-epic: url("assets/themes/basic/backgrounds/bg-mountains-epic.svg");
  --layer-hills-alt: url("assets/themes/basic/backgrounds/bg-hills.svg");
  --layer-forest: url("assets/themes/basic/backgrounds/bg-forest-foreground.svg");
  --world-bg-forest: url("assets/themes/castle/bg-forest.png");
  --world-bg-snow: url("assets/themes/castle/bg-snow.png");
  --world-bg-mountains: url("assets/themes/castle/bg-mountains.png");
  --world-bg-desert: url("assets/themes/castle/bg-desert.png");
  --world-bg-desolation: url("assets/themes/castle/bg-desolation.png");
}

.phone-frame.visual-style-basic {
  --layer-sky-epic: url("assets/themes/basic/backgrounds/bg-sky-epic.svg");
  --layer-sky-alt: url("assets/themes/basic/backgrounds/bg-sky.svg");
  --layer-hills-epic: url("assets/themes/basic/backgrounds/bg-mountains-epic.svg");
  --layer-hills-alt: url("assets/themes/basic/backgrounds/bg-hills.svg");
  --layer-forest: url("assets/themes/basic/backgrounds/bg-forest-foreground.svg");
  --world-bg-forest: url("assets/themes/basic/backgrounds/bg-forest-foreground.svg");
  --world-bg-snow: url("assets/themes/basic/backgrounds/bg-hills.svg");
  --world-bg-mountains: url("assets/themes/basic/backgrounds/bg-mountains-epic.svg");
  --world-bg-desert: url("assets/themes/basic/backgrounds/bg-hills.svg");
  --world-bg-desolation: url("assets/themes/basic/backgrounds/bg-hills.svg");
}

.phone-frame.visual-style-castle {
  --layer-sky-epic: url("assets/themes/basic/backgrounds/bg-sky-epic.svg");
  --layer-sky-alt: url("assets/themes/basic/backgrounds/bg-sky.svg");
  --layer-hills-epic: url("assets/themes/basic/backgrounds/bg-mountains-epic.svg");
  --layer-hills-alt: url("assets/themes/basic/backgrounds/bg-hills.svg");
  --layer-forest: url("assets/themes/basic/backgrounds/bg-forest-foreground.svg");
  --world-bg-forest: url("assets/themes/castle/bg-forest.png");
  --world-bg-snow: url("assets/themes/castle/bg-snow.png");
  --world-bg-mountains: url("assets/themes/castle/bg-mountains.png");
  --world-bg-desert: url("assets/themes/castle/bg-desert.png");
  --world-bg-desolation: url("assets/themes/castle/bg-desolation.png");
}

.phone-frame.visual-style-fairy {
  --layer-sky-epic: url("assets/themes/basic/backgrounds/bg-sky-epic.svg");
  --layer-sky-alt: url("assets/themes/basic/backgrounds/bg-sky.svg");
  --layer-hills-epic: url("assets/themes/basic/backgrounds/bg-mountains-epic.svg");
  --layer-hills-alt: url("assets/themes/basic/backgrounds/bg-hills.svg");
  --layer-forest: url("assets/themes/basic/backgrounds/bg-forest-foreground.svg");
  --world-bg-forest: url("assets/themes/fairy/bg-forest.png");
  --world-bg-snow: url("assets/themes/fairy/bg-snow.png");
  --world-bg-mountains: url("assets/themes/fairy/bg-mountains.png");
  --world-bg-desert: url("assets/themes/fairy/bg-desert.png");
  --world-bg-desolation: url("assets/themes/fairy/bg-desolation.png");
}

.phone-frame.shake-small {
  animation: screen-shake-small 220ms linear;
}

.phone-frame.shake-heavy {
  animation: screen-shake-heavy 560ms linear;
}

.title-screen {
  position: absolute;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  padding: 18px;
  background:
    radial-gradient(circle at 80% 20%, rgba(255, 234, 153, 0.28), transparent 40%),
    linear-gradient(180deg, rgba(8, 18, 38, 0.52), rgba(8, 12, 30, 0.9));
}

.title-card {
  width: min(100%, 360px);
  border-radius: 20px;
  padding: 18px 16px;
  background: rgba(10, 16, 38, 0.84);
  border: 1px solid rgba(255, 255, 255, 0.25);
  box-shadow: 0 14px 34px rgba(5, 8, 22, 0.48);
  text-align: center;
}

.title-kicker {
  margin: 0;
  font-size: 0.8rem;
  letter-spacing: 0.06em;
  opacity: 0.86;
}

.title-card h1 {
  margin: 4px 0 10px;
  font-family: "Bangers", cursive;
  font-size: 2.4rem;
  letter-spacing: 0.07em;
  color: #ffe17e;
}

.title-card p {
  margin: 0;
}

.title-actions {
  display: grid;
  gap: 10px;
  margin-top: 16px;
}

.title-actions button {
  border: none;
  border-radius: 12px;
  min-height: 44px;
  color: #f7fbff;
  font-weight: 800;
  letter-spacing: 0.03em;
}

#start-btn {
  background: linear-gradient(180deg, #ffb15c, #e16b35);
  box-shadow: 0 4px 0 #9f381d;
}

#open-tables-btn {
  background: linear-gradient(180deg, #4f74d4, #2f4f9f);
  box-shadow: 0 4px 0 #1b2f65;
}

#open-shop-btn {
  background: linear-gradient(180deg, #ffdb78, #c58a2d);
  box-shadow: 0 4px 0 #80521a;
  color: #27222e;
}

#open-stats-btn {
  background: linear-gradient(180deg, #58b7a5, #2d7b6e);
  box-shadow: 0 4px 0 #165047;
}

.hud {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 20;
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 8px;
  padding: 10px;
  background: transparent;
  border-bottom: 0;
}

.hud-item {
  background: rgba(10, 18, 42, 0.58);
  border: 1px solid rgba(255, 255, 255, 0.3);
  border-radius: 12px;
  padding: 6px 4px;
  text-align: center;
}

.hud-label {
  display: block;
  font-size: 0.7rem;
  opacity: 0.85;
  letter-spacing: 0.03em;
}

.hud-item strong {
  font-size: 1rem;
}

.hud-item.combo-debug {
  cursor: pointer;
}

.hud-item-coins strong {
  color: #ffe8a7;
}

.battlefield {
  position: relative;
  flex: 1;
  min-height: clamp(240px, 42vh, 380px);
  overflow: hidden;
}

.battlefield::before {
  content: none;
}

.layer {
  position: absolute;
  inset: 0;
  background-size: cover;
  background-repeat: no-repeat;
  background-position: center calc(100% + var(--debug-bg-offset-y) - var(--platform-upshift-y));
  pointer-events: none;
  transition: filter 520ms ease, opacity 520ms ease, transform 520ms ease;
}

.layer-sky {
  background-image: var(--layer-sky-epic);
  background-position: center calc(0% + var(--debug-bg-offset-y) - var(--platform-upshift-y));
}

.layer-hills {
  background-image: var(--layer-hills-epic);
  background-position: center calc(72% + var(--debug-bg-offset-y) - var(--platform-upshift-y));
  transform: scale(1.06);
}

.layer-forest {
  background-image: var(--layer-forest);
  background-position: center calc(100% + var(--debug-bg-offset-y) - var(--platform-upshift-y));
  transform: scale(1.03);
  z-index: 2;
}

.path {
  position: absolute;
  left: 16%;
  right: -6%;
  top: auto;
  bottom: calc(
    20% + var(--battle-upshift-y) + var(--platform-upshift-y) - var(--debug-path-offset-y)
  );
  height: 16%;
  border-radius: 60px;
  background:
    repeating-linear-gradient(
      88deg,
      #d8af5a 0,
      #d8af5a 36px,
      #bf9247 36px,
      #bf9247 72px
    );
  border: 4px solid rgba(94, 62, 24, 0.58);
  box-shadow: inset 0 8px 16px rgba(70, 45, 16, 0.35);
  z-index: 3;
}

.visual-style-castle .layer,
.visual-style-fairy .layer {
  background-size: 100% auto;
  background-position: center calc(100% + var(--debug-bg-offset-y) - var(--platform-upshift-y));
}

.visual-style-castle .layer-sky,
.visual-style-fairy .layer-sky {
  background-position: center calc(0% + var(--debug-bg-offset-y) - var(--platform-upshift-y));
}

.visual-style-castle .layer-hills,
.visual-style-fairy .layer-hills {
  background-position: center calc(86% + var(--debug-bg-offset-y) - var(--platform-upshift-y));
}

.visual-style-castle .layer-forest,
.visual-style-fairy .layer-forest {
  background-position: center calc(100% + var(--debug-bg-offset-y) - var(--platform-upshift-y));
}

.visual-style-castle .path,
.visual-style-fairy .path {
  top: auto;
  bottom: calc(
    12% + var(--battle-upshift-y) + var(--platform-upshift-y) - var(--debug-path-offset-y)
  );
  height: 10%;
  background: transparent;
  border: 0;
  box-shadow: none;
  border-radius: 0;
  opacity: 0;
}

.visual-style-basic .path {
  bottom: calc(
    20% + var(--battle-upshift-y) + var(--platform-upshift-y) - var(--debug-path-offset-y) - 40px
  );
}

.visual-style-castle .battlefield.world-forest .layer-sky,
.visual-style-castle .battlefield.world-snow .layer-sky,
.visual-style-castle .battlefield.world-mountains .layer-sky,
.visual-style-castle .battlefield.world-desert .layer-sky,
.visual-style-castle .battlefield.world-desolation .layer-sky,
.visual-style-fairy .battlefield.world-forest .layer-sky,
.visual-style-fairy .battlefield.world-snow .layer-sky,
.visual-style-fairy .battlefield.world-mountains .layer-sky,
.visual-style-fairy .battlefield.world-desert .layer-sky,
.visual-style-fairy .battlefield.world-desolation .layer-sky {
  filter: none;
}

.visual-style-castle .battlefield.world-forest .layer-sky,
.visual-style-castle .battlefield.world-forest .layer-hills,
.visual-style-castle .battlefield.world-forest .layer-forest,
.visual-style-fairy .battlefield.world-forest .layer-sky,
.visual-style-fairy .battlefield.world-forest .layer-hills,
.visual-style-fairy .battlefield.world-forest .layer-forest {
  background-image: var(--world-bg-forest);
  opacity: 1;
  filter: none;
  transform: scale(1);
}

.visual-style-castle .battlefield.world-snow .layer-sky,
.visual-style-castle .battlefield.world-snow .layer-hills,
.visual-style-castle .battlefield.world-snow .layer-forest,
.visual-style-fairy .battlefield.world-snow .layer-sky,
.visual-style-fairy .battlefield.world-snow .layer-hills,
.visual-style-fairy .battlefield.world-snow .layer-forest {
  background-image: var(--world-bg-snow);
  opacity: 1;
  filter: none;
  transform: scale(1);
}

.visual-style-castle .battlefield.world-mountains .layer-sky,
.visual-style-castle .battlefield.world-mountains .layer-hills,
.visual-style-castle .battlefield.world-mountains .layer-forest,
.visual-style-fairy .battlefield.world-mountains .layer-sky,
.visual-style-fairy .battlefield.world-mountains .layer-hills,
.visual-style-fairy .battlefield.world-mountains .layer-forest {
  background-image: var(--world-bg-mountains);
  opacity: 1;
  filter: none;
  transform: scale(1);
}

.visual-style-castle .battlefield.world-desert .layer-sky,
.visual-style-castle .battlefield.world-desert .layer-hills,
.visual-style-castle .battlefield.world-desert .layer-forest,
.visual-style-fairy .battlefield.world-desert .layer-sky,
.visual-style-fairy .battlefield.world-desert .layer-hills,
.visual-style-fairy .battlefield.world-desert .layer-forest {
  background-image: var(--world-bg-desert);
  opacity: 1;
  filter: none;
  transform: scale(1);
}

.visual-style-castle .battlefield.world-desolation .layer-sky,
.visual-style-castle .battlefield.world-desolation .layer-hills,
.visual-style-castle .battlefield.world-desolation .layer-forest,
.visual-style-fairy .battlefield.world-desolation .layer-sky,
.visual-style-fairy .battlefield.world-desolation .layer-hills,
.visual-style-fairy .battlefield.world-desolation .layer-forest {
  background-image: var(--world-bg-desolation);
  opacity: 1;
  filter: none;
  transform: scale(1);
}

.visual-style-castle .battlefield.world-desolation::after,
.visual-style-castle .battlefield.world-snow::after,
.visual-style-fairy .battlefield.world-desolation::after,
.visual-style-fairy .battlefield.world-snow::after {
  content: none;
}

.visual-style-castle .battlefield.world-forest .layer-sky,
.visual-style-castle .battlefield.world-forest .layer-hills,
.visual-style-castle .battlefield.world-forest .layer-forest,
.visual-style-castle .battlefield.world-snow .layer-sky,
.visual-style-castle .battlefield.world-snow .layer-hills,
.visual-style-castle .battlefield.world-snow .layer-forest,
.visual-style-castle .battlefield.world-mountains .layer-sky,
.visual-style-castle .battlefield.world-mountains .layer-hills,
.visual-style-castle .battlefield.world-mountains .layer-forest,
.visual-style-castle .battlefield.world-desert .layer-sky,
.visual-style-castle .battlefield.world-desert .layer-hills,
.visual-style-castle .battlefield.world-desert .layer-forest,
.visual-style-castle .battlefield.world-desolation .layer-sky,
.visual-style-castle .battlefield.world-desolation .layer-hills,
.visual-style-castle .battlefield.world-desolation .layer-forest,
.visual-style-fairy .battlefield.world-forest .layer-sky,
.visual-style-fairy .battlefield.world-forest .layer-hills,
.visual-style-fairy .battlefield.world-forest .layer-forest,
.visual-style-fairy .battlefield.world-snow .layer-sky,
.visual-style-fairy .battlefield.world-snow .layer-hills,
.visual-style-fairy .battlefield.world-snow .layer-forest,
.visual-style-fairy .battlefield.world-mountains .layer-sky,
.visual-style-fairy .battlefield.world-mountains .layer-hills,
.visual-style-fairy .battlefield.world-mountains .layer-forest,
.visual-style-fairy .battlefield.world-desert .layer-sky,
.visual-style-fairy .battlefield.world-desert .layer-hills,
.visual-style-fairy .battlefield.world-desert .layer-forest,
.visual-style-fairy .battlefield.world-desolation .layer-sky,
.visual-style-fairy .battlefield.world-desolation .layer-hills,
.visual-style-fairy .battlefield.world-desolation .layer-forest {
  background-position: center calc(100% + var(--debug-bg-offset-y) - var(--platform-upshift-y));
}

.visual-style-basic .battlefield.world-forest .layer-sky {
  background-image: var(--layer-sky-epic);
}

.visual-style-basic .battlefield.world-forest .layer-hills {
  background-image: var(--layer-hills-epic);
}

.visual-style-basic .battlefield.world-forest .layer-forest {
  background-image: var(--layer-forest);
  opacity: 1;
}

.visual-style-basic .battlefield.world-snow .layer-sky,
.visual-style-basic .battlefield.world-mountains .layer-sky,
.visual-style-basic .battlefield.world-desert .layer-sky,
.visual-style-basic .battlefield.world-desolation .layer-sky {
  background-image: var(--layer-sky-alt);
}

.visual-style-basic .battlefield.world-snow .layer-hills,
.visual-style-basic .battlefield.world-mountains .layer-hills,
.visual-style-basic .battlefield.world-desert .layer-hills,
.visual-style-basic .battlefield.world-desolation .layer-hills {
  background-image: var(--layer-hills-alt);
}

.visual-style-basic .battlefield.world-snow .layer-forest,
.visual-style-basic .battlefield.world-mountains .layer-forest,
.visual-style-basic .battlefield.world-desert .layer-forest,
.visual-style-basic .battlefield.world-desolation .layer-forest {
  background-image: var(--layer-forest);
  opacity: 1;
}

.castle-door {
  position: absolute;
  right: -8%;
  bottom: calc(
    5%
    + var(--battle-upshift-y)
    + var(--platform-upshift-y)
    + var(--castle-extra-shift-y)
    + var(--debug-castle-offset-y)
  );
  width: clamp(132px, 30vw, 210px);
  z-index: 4;
  filter: none;
  transform: scale(var(--debug-castle-scale));
  transform-origin: bottom right;
}

.castle-fire {
  position: absolute;
  right: -14%;
  bottom: calc(
    5%
    + var(--battle-upshift-y)
    + var(--platform-upshift-y)
    + var(--castle-extra-shift-y)
    + var(--debug-castle-offset-y)
  );
  width: clamp(170px, 40vw, 280px);
  z-index: 10;
  pointer-events: none;
  opacity: 0;
  transform: scale(var(--debug-castle-scale));
  transform-origin: 60% 80%;
}

.castle-fire.burning {
  opacity: 1;
  animation: fire-flicker 360ms infinite alternate ease-in-out;
}

.tower {
  position: absolute;
  width: clamp(100px, 24vw, 160px);
  left: 3%;
  bottom: calc(
    13% + var(--battle-upshift-y) + var(--platform-upshift-y) + var(--debug-tower-offset-y)
  );
  filter: none;
  z-index: 6;
  transition: filter 220ms ease, transform 220ms ease;
  transform: scale(calc(var(--debug-tower-scale) * var(--tower-skin-scale, 1)));
  transform-origin: bottom left;
}

.visual-style-basic .tower {
  bottom: calc(
    13% + var(--battle-upshift-y) + var(--platform-upshift-y) + var(--debug-tower-offset-y) - 40px
  );
}

.visual-style-castle .castle-door,
.visual-style-fairy .castle-door {
  right: -5%;
  bottom: calc(
    var(--world-castle-bottom-px, calc(3% + var(--battle-upshift-y) + var(--platform-upshift-y)))
    + var(--castle-extra-shift-y)
    + var(--debug-castle-offset-y)
  );
  width: calc(clamp(92px, 21vw, 150px) * 1.1);
  transform: scale(calc(var(--debug-castle-scale) * var(--castle-skin-scale, 1)));
}

.visual-style-castle .castle-fire,
.visual-style-fairy .castle-fire {
  right: -11%;
  bottom: calc(
    var(--world-castle-bottom-px, calc(3% + var(--battle-upshift-y) + var(--platform-upshift-y)))
    + var(--castle-extra-shift-y)
    + var(--debug-castle-offset-y)
  );
  width: clamp(124px, 30vw, 198px);
}

.visual-style-castle .tower,
.visual-style-fairy .tower {
  left: 3%;
  bottom: calc(
    var(--world-tower-bottom-px, calc(9% + var(--battle-upshift-y) + var(--platform-upshift-y)))
    + var(--debug-tower-offset-y)
  );
  width: clamp(70px, 16vw, 112px);
}

.tower.cast {
  transform: scale(calc(var(--debug-tower-scale) * var(--tower-skin-scale, 1) * 1.04)) rotate(-2deg);
  filter: drop-shadow(0 0 14px rgba(132, 234, 255, 0.92));
}

.boss-dragon {
  position: absolute;
  left: 50%;
  bottom: calc(20% + 30px + var(--platform-upshift-y));
  width: clamp(130px, 30vw, 210px);
  z-index: 11;
  pointer-events: none;
  image-rendering: pixelated;
  animation: boss-hover 1.4s ease-in-out infinite;
}

.boss-panel {
  position: absolute;
  left: 50%;
  bottom: 6%;
  width: min(210px, 46%);
  padding: 8px 10px;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.24);
  background: rgba(12, 14, 32, 0.78);
  z-index: 13;
  transform: translateX(-50%);
}

.boss-progress-text {
  margin: 0 0 4px;
  font-size: 0.8rem;
  font-weight: 800;
}

.boss-fire-track {
  height: 12px;
  border-radius: 999px;
  overflow: hidden;
  border: 1px solid rgba(255, 210, 132, 0.5);
  background: rgba(15, 8, 4, 0.72);
}

.boss-fire-fill {
  width: 0%;
  height: 100%;
  background: linear-gradient(90deg, #ff8b2c, #ffd35c, #ff4e36);
  box-shadow: 0 0 14px rgba(255, 157, 64, 0.66);
  transition: width 60ms linear;
}

.boss-timer-text {
  margin: 4px 0 0;
  font-size: 0.75rem;
  font-weight: 800;
  text-align: right;
}

.boss-rain-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 14;
  overflow: hidden;
}

.victory-drop {
  position: absolute;
  top: -18%;
  width: clamp(40px, 10vw, 64px);
  image-rendering: pixelated;
  animation: victory-rain linear forwards;
}

.boss-victory-banner {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  text-align: center;
  padding: 20px;
  z-index: 15;
  pointer-events: none;
  font-family: "Bangers", cursive;
  letter-spacing: 0.04em;
  line-height: 1.15;
  font-size: clamp(1.6rem, 5.2vw, 2.6rem);
  color: #ffe67f;
  text-shadow: 0 4px 0 rgba(0, 0, 0, 0.45), 0 0 22px rgba(255, 194, 86, 0.42);
}

.boss-defeat-overlay {
  position: absolute;
  inset: 14% 8% 14%;
  z-index: 19;
  display: grid;
  place-items: center;
  text-align: center;
  gap: 14px;
  padding: 18px 16px;
  border-radius: 16px;
  border: 1px solid rgba(255, 255, 255, 0.24);
  background: rgba(8, 12, 30, 0.92);
  box-shadow: var(--shadow);
}

.boss-defeat-overlay p {
  margin: 0;
  font-family: "Bangers", cursive;
  letter-spacing: 0.04em;
  font-size: clamp(1rem, 3.2vw, 1.2rem);
  font-weight: 400;
  line-height: 1.35;
}

#boss-defeat-go-btn {
  border: none;
  border-radius: 12px;
  min-height: 44px;
  min-width: 132px;
  padding: 0 18px;
  font-weight: 800;
  color: #1d2549;
  background: linear-gradient(180deg, #ffe183, #ffbf4f);
}

.enemy-layer,
.projectile-layer,
.fx-layer {
  position: absolute;
  inset: 0;
}

.enemy-layer {
  z-index: 7;
}

.projectile-layer {
  z-index: 8;
}

.fx-layer {
  z-index: 9;
}

.enemy {
  --enemy-scale: 1;
  --spawn-shift-x: 0px;
  position: absolute;
  width: clamp(68px, 18vw, 100px);
  transform: translate(calc(-50% + var(--spawn-shift-x)), -40%) scale(var(--enemy-scale));
  z-index: 5;
  animation: none;
}

.visual-style-castle .enemy,
.visual-style-fairy .enemy {
  transform: translate(calc(-50% + var(--spawn-shift-x)), -28%) scale(var(--enemy-scale));
}

.enemy img {
  width: 100%;
  height: auto;
  display: block;
  filter: none;
  animation: enemy-walk-bob 360ms ease-in-out infinite;
}

.bonus-chest {
  position: absolute;
  width: clamp(68px, 18vw, 100px);
  border: 0;
  padding: 0;
  margin: 0;
  background: transparent;
  transform: translate(-50%, -50%);
  z-index: 11;
  cursor: pointer;
  touch-action: manipulation;
  opacity: 0;
  transition: opacity 260ms ease;
  filter: drop-shadow(0 10px 14px rgba(0, 0, 0, 0.38));
  animation: chest-pulse 1.2s ease-in-out infinite;
}

.bonus-chest.is-visible {
  opacity: 1;
}

.bonus-chest.is-fading-out {
  opacity: 0;
  pointer-events: none;
}

.bonus-chest img {
  width: 100%;
  height: auto;
  display: block;
  pointer-events: none;
  user-select: none;
  -webkit-user-drag: none;
}

.bonus-chest:active {
  transform: translate(-50%, -50%) scale(0.96);
}

.visual-style-castle .castle-door,
.visual-style-castle .castle-fire,
.visual-style-castle .tower,
.visual-style-castle .enemy img,
.visual-style-fairy .castle-door,
.visual-style-fairy .castle-fire,
.visual-style-fairy .tower,
.visual-style-fairy .enemy img {
  image-rendering: pixelated;
}


.enemy.enraged img {
  filter: saturate(1.4) brightness(1.08) drop-shadow(0 8px 10px rgba(130, 20, 15, 0.64));
}

.enemy.enraged {
  animation-duration: 0.55s;
}

.hp-bar {
  display: none;
  width: 78%;
  height: 7px;
  margin: 0 auto;
  border-radius: 999px;
  background: rgba(10, 14, 20, 0.58);
  border: 1px solid rgba(255, 255, 255, 0.35);
  overflow: hidden;
}

.hp-fill {
  height: 100%;
  background: linear-gradient(90deg, #7dff9e, #ffe56c);
  transition: width 0.18s ease;
}

.projectile {
  position: absolute;
  width: 88px;
  height: 48px;
  background-image: var(--projectile-image);
  background-size: 100% 100%;
  background-repeat: no-repeat;
  background-position: center;
  filter: drop-shadow(0 0 12px rgba(84, 232, 255, 0.95));
  z-index: 8;
  transform: translate(-50%, -50%);
}

.hit-fx {
  position: absolute;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 3px solid rgba(255, 226, 140, 0.95);
  box-shadow: 0 0 16px rgba(255, 212, 86, 0.9);
  transform: translate(-50%, -50%);
  animation: burst 0.35s ease forwards;
  z-index: 9;
}

.wave-banner {
  position: absolute;
  top: 10%;
  left: 50%;
  transform: translate(-50%, -14px);
  padding: 10px 18px;
  border-radius: 12px;
  background: rgba(8, 15, 36, 0.75);
  border: 1px solid rgba(255, 255, 255, 0.28);
  font-family: "Bangers", cursive;
  letter-spacing: 0.08em;
  font-size: 1.3rem;
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.35);
  opacity: 0;
  pointer-events: none;
  z-index: 12;
}

.wave-banner.show {
  animation: banner-pop 1.8s ease;
}

.game-over {
  position: absolute;
  inset: 10% 8% 6%;
  background: rgba(17, 22, 42, 0.9);
  border: 1px solid rgba(255, 255, 255, 0.25);
  border-radius: 18px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  text-align: center;
  padding: 14px;
  gap: 10px;
  overflow-y: auto;
  scroll-padding-bottom: 14px;
  z-index: 20;
}

.game-over h2 {
  margin: 0;
  font-family: "Bangers", cursive;
  font-size: 2rem;
  letter-spacing: 0.08em;
}

.game-over p {
  margin: 0;
}

.final-score-text {
  font-weight: 800;
  color: #ffe083;
}

.score-submit {
  width: 100%;
}

.score-submit label {
  display: block;
  font-size: 0.8rem;
  margin-bottom: 4px;
}

.score-submit-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 6px;
}

#player-name-input {
  width: 100%;
  border: 1px solid rgba(255, 255, 255, 0.28);
  border-radius: 10px;
  background: rgba(10, 15, 34, 0.8);
  color: #f7fbff;
  font-weight: 700;
  padding: 8px 10px;
}

#save-score-btn {
  border: none;
  border-radius: 10px;
  padding: 0 10px;
  min-height: 36px;
  color: #1d2549;
  font-weight: 800;
  background: linear-gradient(180deg, #ffe183, #ffbf4f);
}

.score-save-feedback {
  min-height: 18px;
  margin-top: 4px;
  font-size: 0.78rem;
  color: #7ff7d9;
}

.leaderboard {
  width: 100%;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 10px;
  padding: 6px 8px;
  background: rgba(8, 12, 28, 0.45);
}

.leaderboard h3 {
  margin: 0 0 4px;
  font-size: 0.86rem;
}

#leaderboard-list {
  margin: 0;
  padding-left: 20px;
  text-align: left;
  max-height: 110px;
  overflow: auto;
}

#leaderboard-list li,
#stats-leaderboard-list li {
  font-size: 0.78rem;
  margin: 1px 0;
}

.game-over button {
  padding: 10px 18px;
  border: none;
  border-radius: 12px;
  font-weight: 800;
  color: #1d2549;
  background: linear-gradient(180deg, #ffe183, #ffbf4f);
}

#restart-btn {
  width: 100%;
  min-height: 42px;
  margin-top: 4px;
}

.score-submit {
  margin-bottom: 4px;
}

.hidden {
  display: none;
}

.question-panel {
  padding: 12px 12px calc(18px + var(--keypad-bottom-extra) + env(safe-area-inset-bottom));
  background: linear-gradient(180deg, var(--panel), rgba(8, 12, 28, 0.88));
  border-top: 1px solid var(--panel-border);
}

.question-headline {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.mini-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.mini-action {
  border: 1px solid rgba(255, 255, 255, 0.28);
  border-radius: 10px;
  min-height: 30px;
  padding: 0 10px;
  color: #f7fbff;
  font-size: 0.78rem;
  font-weight: 800;
  background: linear-gradient(180deg, #4f74d4, #2f4f9f);
}

.mini-action:disabled {
  opacity: 0.5;
}

.mini-action-shop {
  background: linear-gradient(180deg, #ffe28a, #cb9035);
  color: #2e2635;
}

.mini-action-pause {
  background: linear-gradient(180deg, #8da1cf, #61749d);
}

.mode-select {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin: 2px 0 10px;
}

.mode-select button {
  border: 1px solid rgba(255, 255, 255, 0.25);
  border-radius: 10px;
  min-height: 36px;
  color: #f7fbff;
  font-weight: 800;
  font-size: 0.88rem;
  background: linear-gradient(180deg, #3d5dae, #2a4083);
}

.mode-select button.active {
  border-color: rgba(255, 245, 175, 0.75);
  background: linear-gradient(180deg, #ffb15c, #e16b35);
  box-shadow: 0 2px 12px rgba(255, 172, 90, 0.45);
}

.tables-modal {
  position: absolute;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(6, 10, 24, 0.72);
}

.tables-modal.hidden {
  display: none;
}

.stats-modal {
  position: absolute;
  inset: 0;
  z-index: 52;
  display: grid;
  place-items: center;
  padding: 14px;
  background: rgba(6, 10, 24, 0.76);
}

.stats-modal.hidden {
  display: none;
}

.shop-modal {
  position: absolute;
  inset: 0;
  z-index: 51;
  display: grid;
  place-items: center;
  padding: 14px;
  background: rgba(6, 10, 24, 0.74);
}

.shop-modal.hidden {
  display: none;
}

.shop-card {
  width: min(100%, 430px);
  max-height: calc(100dvh - 70px);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  border-radius: 18px;
  border: 1px solid rgba(255, 255, 255, 0.28);
  background: rgba(11, 18, 43, 0.97);
  box-shadow: 0 16px 30px rgba(4, 8, 20, 0.58);
  padding: 14px;
}

.shop-card h2 {
  margin: 0;
  font-family: "Bangers", cursive;
  letter-spacing: 0.05em;
  font-size: 1.7rem;
}

.shop-subtitle {
  margin: 6px 0 8px;
  font-size: 0.84rem;
  opacity: 0.92;
}

.shop-wallet {
  padding: 8px 10px;
  border-radius: 10px;
  border: 1px solid rgba(255, 216, 118, 0.42);
  background: rgba(255, 196, 86, 0.12);
  font-size: 0.9rem;
  font-weight: 700;
}

.shop-wallet strong {
  color: #ffe8a7;
}

.shop-style-note {
  margin: 8px 0 6px;
  font-size: 0.75rem;
  opacity: 0.88;
}

.shop-filters {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 10px;
}

.shop-filters button {
  border: 1px solid rgba(255, 255, 255, 0.24);
  border-radius: 10px;
  min-height: 34px;
  color: #f7fbff;
  font-weight: 800;
  background: linear-gradient(180deg, #3d5dae, #2a4083);
}

.shop-filters button.active {
  border-color: rgba(255, 245, 175, 0.75);
  background: linear-gradient(180deg, #ffb15c, #e16b35);
}

.shop-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  padding-right: 2px;
  align-content: start;
}

.shop-item {
  position: relative;
  display: grid;
  grid-template-columns: 74px 1fr;
  gap: 10px;
  padding: 8px;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  background: rgba(255, 255, 255, 0.06);
}

.shop-item.shop-cat-projectile .shop-preview-wrap {
  min-height: 72px;
}

.shop-item.shop-cat-projectile .shop-preview {
  width: 100%;
  max-width: 100%;
  max-height: 64px;
  object-fit: contain;
}

.shop-item.selected {
  border-color: rgba(255, 236, 152, 0.75);
  box-shadow: 0 0 0 1px rgba(255, 202, 108, 0.24);
}

.shop-item.locked {
  filter: grayscale(1);
  opacity: 0.78;
}

.shop-lock {
  position: absolute;
  right: 8px;
  top: 8px;
  font-size: 1rem;
}

.shop-preview-wrap {
  display: grid;
  place-items: center;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  background: rgba(8, 12, 26, 0.72);
  min-height: 62px;
}

.shop-preview {
  max-width: 60px;
  max-height: 52px;
  image-rendering: pixelated;
}

.shop-item-body {
  display: grid;
  gap: 2px;
}

.shop-item-name {
  margin: 0;
  font-size: 0.86rem;
  font-weight: 800;
}

.shop-item-meta {
  margin: 0;
  font-size: 0.76rem;
}

.shop-item-requirement {
  margin: 0;
  font-size: 0.72rem;
  opacity: 0.88;
}

.shop-item button {
  margin-top: 4px;
  border: none;
  border-radius: 10px;
  min-height: 32px;
  color: #f7fbff;
  font-weight: 800;
  background: linear-gradient(180deg, #4f74d4, #2f4f9f);
}

.shop-item button:disabled {
  opacity: 0.56;
}

.shop-actions {
  margin-top: 10px;
  padding-top: 8px;
  border-top: 1px solid rgba(255, 255, 255, 0.14);
  background: linear-gradient(180deg, rgba(11, 18, 43, 0), rgba(11, 18, 43, 0.98) 36%);
}

#close-shop-btn {
  border: none;
  border-radius: 12px;
  min-height: 40px;
  width: 100%;
  color: #f7fbff;
  font-weight: 800;
  background: linear-gradient(180deg, #ffb15c, #e16b35);
}

.stats-card {
  width: min(100%, 430px);
  max-height: calc(100dvh - 70px);
  overflow-y: auto;
  border-radius: 18px;
  border: 1px solid rgba(255, 255, 255, 0.28);
  background: rgba(11, 18, 43, 0.96);
  box-shadow: 0 16px 30px rgba(4, 8, 20, 0.58);
  padding: 14px;
}

.stats-card h2 {
  margin: 0;
  font-family: "Bangers", cursive;
  letter-spacing: 0.05em;
  font-size: 1.7rem;
}

.stats-board {
  margin-top: 8px;
}

#stats-leaderboard-list {
  margin: 0;
  padding-left: 20px;
  text-align: left;
  max-height: 120px;
  overflow: auto;
}

.matrix-title {
  margin: 10px 0 2px;
  font-size: 0.96rem;
}

.matrix-subtitle {
  margin: 0 0 8px;
  font-size: 0.78rem;
  opacity: 0.9;
}

.matrix-wrap {
  overflow: auto;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 10px;
  background: rgba(8, 12, 28, 0.42);
}

.result-matrix {
  width: 100%;
  border-collapse: collapse;
  min-width: 430px;
}

.result-matrix th,
.result-matrix td {
  border: 1px solid rgba(255, 255, 255, 0.08);
  text-align: center;
  padding: 4px 3px;
}

.result-matrix th {
  position: sticky;
  top: 0;
  background: rgba(18, 26, 55, 0.96);
  z-index: 2;
  font-size: 0.72rem;
}

.matrix-main {
  font-size: 0.76rem;
  font-weight: 800;
  line-height: 1.1;
}

.matrix-sub {
  font-size: 0.6rem;
  opacity: 0.92;
}

#close-stats-btn {
  border: none;
  border-radius: 12px;
  min-height: 40px;
  margin-top: 10px;
  width: 100%;
  color: #f7fbff;
  font-weight: 800;
  background: linear-gradient(180deg, #ffb15c, #e16b35);
}

.pause-modal {
  position: absolute;
  inset: 0;
  z-index: 53;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(5, 10, 24, 0.72);
}

.pause-modal.hidden {
  display: none;
}

.debug-hidden {
  display: none;
}

.debug-modal {
  display: none;
  width: min(360px, 42vw);
}

.game-shell.debug-open {
  width: min(100vw, 860px);
}

.game-shell.debug-open .debug-modal {
  display: block;
}

@media (max-width: 980px) {
  .game-shell {
    width: min(100vw, var(--app-max-width));
    max-width: var(--app-max-width);
  }

  .debug-modal {
    position: fixed;
    inset: 8px;
    z-index: 70;
    width: auto;
    background: rgba(5, 10, 24, 0.76);
    padding: 10px;
    overflow-y: auto;
  }

  .game-shell.debug-open .debug-modal {
    display: grid;
    place-items: center;
  }
}

.debug-card {
  width: 100%;
  max-height: calc(100dvh - 20px);
  overflow-y: auto;
  border-radius: 18px;
  border: 1px solid rgba(255, 255, 255, 0.28);
  background: rgba(11, 18, 43, 0.98);
  box-shadow: 0 16px 30px rgba(4, 8, 20, 0.58);
  padding: 14px;
}

.debug-card h2 {
  margin: 0;
  font-family: "Bangers", cursive;
  letter-spacing: 0.05em;
  font-size: 1.7rem;
}

.debug-subtitle {
  margin: 6px 0 10px;
  font-size: 0.84rem;
  opacity: 0.92;
}

.debug-control {
  display: grid;
  gap: 6px;
  margin: 10px 0;
  font-size: 0.82rem;
  font-weight: 700;
}

.debug-control input[type="range"],
.debug-control select {
  width: 100%;
}

.debug-control strong {
  font-size: 0.78rem;
  font-weight: 800;
  color: #ffe083;
}

.debug-export-wrap {
  margin-top: 10px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 10px;
  background: rgba(8, 12, 28, 0.42);
  padding: 8px;
}

.debug-export-wrap p {
  margin: 0 0 6px;
  font-size: 0.78rem;
  opacity: 0.9;
}

#debug-export {
  width: 100%;
  min-height: 114px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 8px;
  background: rgba(7, 10, 26, 0.9);
  color: #d8f0ff;
  font-size: 0.72rem;
  line-height: 1.35;
  padding: 8px;
  resize: vertical;
}

.debug-actions {
  margin-top: 10px;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.debug-actions button {
  border: none;
  border-radius: 12px;
  min-height: 38px;
  color: #f7fbff;
  font-weight: 800;
}

#debug-reset-btn {
  background: linear-gradient(180deg, #61728f, #445169);
}

#close-debug-btn {
  background: linear-gradient(180deg, #ffb15c, #e16b35);
}

.pause-card {
  width: min(100%, 330px);
  border-radius: 18px;
  border: 1px solid rgba(255, 255, 255, 0.28);
  background: rgba(11, 18, 43, 0.96);
  box-shadow: 0 16px 30px rgba(4, 8, 20, 0.58);
  text-align: center;
  padding: 16px 14px;
}

.pause-card h2 {
  margin: 0;
  font-family: "Bangers", cursive;
  letter-spacing: 0.05em;
  font-size: 1.8rem;
}

.pause-card p {
  margin: 8px 0 0;
  font-size: 0.92rem;
  opacity: 0.92;
}

.pause-actions {
  margin-top: 14px;
  display: grid;
  gap: 8px;
}

.pause-actions button {
  border: none;
  border-radius: 12px;
  min-height: 40px;
  color: #f7fbff;
  font-weight: 800;
}

#resume-btn {
  background: linear-gradient(180deg, #ffb15c, #e16b35);
}

#back-title-btn {
  background: linear-gradient(180deg, #61728f, #445169);
}

#mode-confirm-cancel-btn {
  background: linear-gradient(180deg, #61728f, #445169);
}

#mode-confirm-accept-btn {
  background: linear-gradient(180deg, #ffb15c, #e16b35);
}

.tables-card {
  width: min(100%, 390px);
  max-height: calc(100dvh - 76px);
  overflow-y: auto;
  border-radius: 18px;
  border: 1px solid rgba(255, 255, 255, 0.28);
  background: rgba(11, 18, 43, 0.95);
  box-shadow: 0 16px 30px rgba(4, 8, 20, 0.58);
  padding: 14px;
}

.tables-card h2 {
  margin: 0;
  font-family: "Bangers", cursive;
  letter-spacing: 0.05em;
  font-size: 1.7rem;
}

.tables-subtitle {
  margin: 6px 0 10px;
  font-size: 0.85rem;
  opacity: 0.92;
}

.tables-label {
  margin: 0 0 4px;
  font-size: 0.9rem;
  font-weight: 800;
  letter-spacing: 0.02em;
}

.tables-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.visual-style-select {
  margin: 0 0 10px;
  padding: 8px;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  background: rgba(255, 255, 255, 0.06);
}

.visual-style-label {
  margin: 0 0 6px;
  font-size: 0.76rem;
  opacity: 0.92;
}

.visual-style-buttons {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

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

.audio-toggle-buttons {
  grid-template-columns: 1fr;
}

.audio-volume-controls {
  margin-top: 8px;
}

.audio-volume-label {
  display: block;
  margin: 8px 0 4px;
  font-size: 0.75rem;
  font-weight: 700;
  opacity: 0.95;
}

.audio-volume-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  align-items: center;
}

.audio-volume-slider {
  width: 100%;
  accent-color: #ffb15c;
}

.audio-volume-value {
  min-width: 46px;
  text-align: right;
  font-size: 0.75rem;
  font-weight: 800;
  color: #ffe6b7;
}

.visual-style-buttons button {
  border: 1px solid rgba(255, 255, 255, 0.26);
  border-radius: 10px;
  min-height: 34px;
  color: #f7fbff;
  font-weight: 800;
  font-size: 0.82rem;
  background: linear-gradient(180deg, #3d5dae, #2a4083);
}

.visual-style-buttons button.active {
  border-color: rgba(255, 245, 175, 0.75);
  background: linear-gradient(180deg, #ffb15c, #e16b35);
}

.table-option {
  display: block;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.07);
  padding: 8px;
}

.table-option.selected {
  border-color: rgba(255, 232, 157, 0.72);
  box-shadow: 0 0 0 1px rgba(255, 202, 108, 0.22);
}

.table-main {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-weight: 800;
}

.table-main input {
  accent-color: #ffb15c;
}

.table-meta {
  margin-top: 4px;
  font-size: 0.72rem;
  opacity: 0.92;
}

.table-meta.weak {
  color: #ff98a3;
}

.table-meta.medium {
  color: #ffd986;
}

.table-meta.strong {
  color: #7ff7d9;
}

.tables-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-top: 12px;
}

.tables-actions button {
  border: none;
  border-radius: 12px;
  min-height: 40px;
  color: #f7fbff;
  font-weight: 800;
}

#pwa-update-btn {
  grid-column: 1 / -1;
  order: 3;
  background: linear-gradient(180deg, #3d5dae, #2a4083);
}

#reset-mastery-btn {
  background: linear-gradient(180deg, #61728f, #445169);
}

#close-tables-btn {
  background: linear-gradient(180deg, #ffb15c, #e16b35);
}

.question-title {
  margin: 0;
  font-size: 0.88rem;
  opacity: 0.9;
}

.question-text {
  margin: 4px 0 10px;
  font-family: "Nunito", "Trebuchet MS", sans-serif;
  font-weight: 900;
  font-size: 1.94rem;
  letter-spacing: 0.02em;
  color: var(--gold);
  text-shadow: 0 3px 0 rgba(0, 0, 0, 0.3);
}

.answer-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
}

#answer-input {
  width: 100%;
  border: 2px solid rgba(255, 255, 255, 0.25);
  border-radius: 12px;
  background: rgba(13, 19, 44, 0.76);
  color: #fff;
  font-weight: 800;
  font-family: "Nunito", "Trebuchet MS", sans-serif;
  font-size: 1.4rem;
  padding: 10px 12px;
  text-align: center;
}

.fire-btn {
  border: none;
  border-radius: 12px;
  color: #fff;
  font-weight: 800;
  letter-spacing: 0.03em;
  padding: 0 16px;
  min-width: 112px;
  background: linear-gradient(180deg, #ff9c61, #f06435);
  box-shadow: 0 4px 0 #9f381d;
}

.fire-btn:active,
.keypad button:active {
  transform: translateY(2px);
}

.feedback {
  min-height: 24px;
  margin: 10px 0 8px;
  font-size: 1.03rem;
  font-weight: 800;
}

.feedback.good {
  color: var(--mint);
}

.feedback.bad {
  color: var(--danger);
}

.keypad {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.keypad button {
  border: none;
  border-radius: 12px;
  min-height: 44px;
  color: #f7fbff;
  font-weight: 800;
  font-size: 1.15rem;
  background: linear-gradient(180deg, #486dcb, #2f4b9c);
  box-shadow: 0 4px 0 #182c66;
}

@keyframes bob {
  from {
    translate: 0 0;
  }
  to {
    translate: 0 -4px;
  }
}

@keyframes burst {
  from {
    transform: translate(-50%, -50%) scale(0.5);
    opacity: 1;
  }
  to {
    transform: translate(-50%, -50%) scale(2.8);
    opacity: 0;
  }
}

@keyframes banner-pop {
  0% {
    opacity: 0;
    transform: translate(-50%, -16px) scale(0.9);
  }
  20% {
    opacity: 1;
    transform: translate(-50%, 0) scale(1);
  }
  80% {
    opacity: 1;
    transform: translate(-50%, 0) scale(1);
  }
  100% {
    opacity: 0;
    transform: translate(-50%, -10px) scale(0.98);
  }
}

@keyframes screen-shake-small {
  0% {
    transform: translate3d(0, 0, 0);
  }
  20% {
    transform: translate3d(-2px, 1px, 0);
  }
  40% {
    transform: translate3d(2px, -1px, 0);
  }
  60% {
    transform: translate3d(-1px, 1px, 0);
  }
  80% {
    transform: translate3d(1px, -1px, 0);
  }
  100% {
    transform: translate3d(0, 0, 0);
  }
}

@keyframes screen-shake-heavy {
  0% {
    transform: translate3d(0, 0, 0);
  }
  15% {
    transform: translate3d(-7px, 4px, 0);
  }
  30% {
    transform: translate3d(7px, -3px, 0);
  }
  45% {
    transform: translate3d(-6px, -2px, 0);
  }
  60% {
    transform: translate3d(6px, 3px, 0);
  }
  75% {
    transform: translate3d(-4px, 2px, 0);
  }
  90% {
    transform: translate3d(3px, -1px, 0);
  }
  100% {
    transform: translate3d(0, 0, 0);
  }
}

@keyframes fire-flicker {
  from {
    transform: scale(1) rotate(-1deg);
    filter: brightness(1);
  }
  to {
    transform: scale(1.04) rotate(1deg);
    filter: brightness(1.12);
  }
}

@keyframes enemy-walk-bob {
  0% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(-2px);
  }
  100% {
    transform: translateY(0);
  }
}

@keyframes chest-pulse {
  0%,
  100% {
    filter: drop-shadow(0 10px 14px rgba(0, 0, 0, 0.38));
  }
  50% {
    filter: drop-shadow(0 12px 18px rgba(255, 194, 86, 0.5));
  }
}

@keyframes boss-hover {
  0% {
    transform: translateX(-50%) translateY(0);
  }
  50% {
    transform: translateX(-50%) translateY(-6px);
  }
  100% {
    transform: translateX(-50%) translateY(0);
  }
}

@keyframes victory-rain {
  0% {
    transform: translateY(0) rotate(0deg);
    opacity: 0.96;
  }
  85% {
    opacity: 0.94;
  }
  100% {
    transform: translateY(135vh) rotate(540deg);
    opacity: 0;
  }
}

@media (min-width: 860px) {
  body {
    padding: 20px;
  }

  .phone-frame {
    height: min(900px, calc(100dvh - 40px));
  }

  .game-shell.debug-open .phone-frame {
    width: min(100vw, 480px);
  }
}

@media (hover: none) and (pointer: coarse) {
  :root {
    --keypad-bottom-extra: 0px;
  }

  body {
    padding: 0;
    display: block;
    width: 100dvw;
    min-height: 100svh;
    overflow-x: hidden;
  }

  .game-shell,
  .game-shell.debug-open {
    width: 100%;
    max-width: var(--app-max-width);
    margin: 0 auto;
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
    box-sizing: border-box;
    gap: 0;
  }

  .phone-frame {
    width: 100%;
    max-width: var(--app-max-width);
    height: 100svh;
    min-height: 0;
    border-radius: 0;
    border-width: 0;
    display: grid;
    grid-template-rows: auto minmax(0, 1fr) auto;
  }

  .hud {
    padding:
      calc(8px + env(safe-area-inset-top))
      calc(8px + env(safe-area-inset-right))
      8px
      calc(8px + env(safe-area-inset-left));
    gap: 6px;
  }

  .hud-label {
    font-size: 0.64rem;
  }

  .hud-item strong {
    font-size: 0.9rem;
  }

  .battlefield {
    grid-row: 2;
    min-height: 0;
    height: auto;
  }

  .question-panel {
    grid-row: 3;
  }
  .question-panel {
    max-height: none;
    overflow: visible;
    padding:
      8px
      calc(8px + env(safe-area-inset-right))
      calc(12px + env(safe-area-inset-bottom))
      calc(8px + env(safe-area-inset-left));
  }

  .question-text {
    margin: 2px 0 6px;
    font-size: clamp(1.25rem, 3.7vh, 1.8rem);
  }

  .mode-select {
    margin: 2px 0 6px;
  }

  .mode-select button {
    min-height: 34px;
    font-size: 0.78rem;
    padding: 0 6px;
  }

  .answer-row {
    gap: 6px;
  }

  #answer-input {
    font-size: 1.1rem;
    padding: 8px 10px;
  }

  .fire-btn {
    min-height: 38px;
    min-width: 118px;
    padding: 0 14px;
  }

  .feedback {
    min-height: 18px;
    margin: 6px 0;
    font-size: 0.88rem;
  }

  .keypad {
    gap: 6px;
  }

  .keypad button {
    min-height: clamp(36px, 4.8svh, 44px);
    font-size: 1rem;
  }

  .game-shell.debug-open .debug-modal {
    position: fixed;
    inset: 8px;
    z-index: 70;
    width: auto;
    background: rgba(5, 10, 24, 0.76);
    padding: 10px;
    overflow-y: auto;
    display: grid;
    place-items: center;
  }
}

@media (hover: none) and (pointer: coarse) and (min-width: 768px) {
  body {
    display: block;
  }

  .game-shell,
  .game-shell.debug-open {
    width: 100%;
    max-width: var(--app-max-width);
    margin: 0 auto;
  }

  .phone-frame {
    width: 100%;
  }
}

@media (max-height: 880px) and (hover: hover) {
  body {
    padding: 6px;
  }

  .phone-frame {
    height: calc(100dvh - 8px);
    min-height: 0;
    border-radius: 20px;
  }

  .hud {
    gap: 6px;
    padding: 8px;
  }

  .hud-label {
    font-size: 0.64rem;
  }

  .hud-item strong {
    font-size: 0.9rem;
  }

  .battlefield {
    min-height: clamp(210px, 36vh, 300px);
  }

  .question-panel {
    padding: 10px 10px calc(16px + var(--keypad-bottom-extra) + env(safe-area-inset-bottom));
  }

  .question-text {
    margin: 2px 0 8px;
    font-size: 1.72rem;
  }

  .mode-select {
    margin: 2px 0 8px;
  }

  #answer-input {
    font-size: 1.16rem;
    padding: 8px 10px;
  }

  .feedback {
    min-height: 20px;
    margin: 8px 0 6px;
    font-size: 0.95rem;
  }

  .keypad button {
    min-height: 38px;
    font-size: 1rem;
  }
}
