:root {
  --cream: #FFF3D6;
  --gold: #FFC93C;
  --orange: #F47B20;
  --orange-dark: #C75A12;
  --brick: #C0553A;
  --grass: #58B84A;
  --leaf: #1E6B3A;
  --leaf-dark: #15502B;
  --sky: #4FB8E8;
  --ink: #23252B;
  --display: "Lilita One", "Arial Black", sans-serif;
  --body: "Nunito", "Trebuchet MS", sans-serif;
  --score: "Chakra Petch", "Courier New", monospace;
  --ground-y: 78vh;
  --hud-pad: clamp(8px, 1.8vw, 22px);
  --gap: clamp(5px, 0.8vw, 10px);
  --rail-top: calc(max(var(--hud-pad), env(safe-area-inset-top)) + clamp(56px, 5.6vw, 66px));
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--sky);
  overscroll-behavior: none;
}

body {
  font-family: var(--body);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
}

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
  border: 0;
  background: none;
}

img {
  -webkit-user-drag: none;
  user-select: none;
}

.hidden {
  display: none !important;
}

#app {
  position: fixed;
  inset: 0;
  overflow: hidden;
  background: var(--sky);
}

#scene {
  position: absolute;
  inset: 0;
  overflow: hidden;
  background: var(--sky);
}

.bg-sky {
  position: absolute;
  inset: 0;
  background-color: var(--sky);
  background-image: url("../assets/sky_backdrop.webp");
  background-repeat: no-repeat;
  background-position: center top;
  background-size: 100% auto;
  transition: opacity 420ms ease;
}

.bg-hills {
  position: absolute;
  left: -2vw;
  right: -2vw;
  bottom: calc(100% - var(--ground-y) + 54px);
  height: min(calc(var(--ground-y) * 0.4), 300px);
  background-image: url("../assets/tropical_hills_band.webp");
  background-repeat: repeat-x;
  background-position: 0 100%;
  background-size: auto 100%;
  will-change: background-position;
  transition: opacity 420ms ease;
}

.bg-foliage {
  position: absolute;
  left: -2vw;
  right: -2vw;
  bottom: calc(100% - var(--ground-y) - 7px);
  height: min(calc(var(--ground-y) * 0.52), 430px);
  background-image: url("../assets/garden_foliage_band.webp");
  background-repeat: repeat-x;
  background-position: 0 100%;
  background-size: auto 100%;
  will-change: background-position;
  transition: opacity 420ms ease;
}

#game {
  position: absolute;
  inset: 0;
}

#game canvas {
  display: block !important;
  width: 100% !important;
  height: 100% !important;
  touch-action: none;
}

/* ---------- loading ---------- */

.loader {
  position: absolute;
  inset: 0;
  z-index: 90;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20px;
  background-color: var(--sky);
  background-image: url("../assets/sky_backdrop.webp");
  background-repeat: no-repeat;
  background-position: center top;
  background-size: 100% auto;
}

.loader-logo {
  width: auto;
  height: auto;
  max-width: min(62vw, 480px);
  max-height: 25vh;
  filter: drop-shadow(0 7px 0 rgba(35, 37, 43, 0.23));
  animation: loader-bob 2.6s ease-in-out infinite;
}

.loader-track {
  width: min(360px, 64vw);
  height: 18px;
  border: 3px solid var(--ink);
  border-radius: 999px;
  background: var(--cream);
  box-shadow: 0 4px 0 rgba(35, 37, 43, 0.25), inset 0 3px 0 #fff;
  overflow: hidden;
}

#loader-fill {
  width: 0%;
  height: 100%;
  background: var(--orange);
  border-radius: 999px;
  transition: width 160ms linear;
}

.loader-note {
  margin: 0;
  padding: 5px 14px;
  border-radius: 999px;
  background: rgba(35, 37, 43, 0.42);
  color: var(--cream);
  font-weight: 800;
  font-size: clamp(11px, 1.2vw, 15px);
  letter-spacing: 0.02em;
}

@keyframes loader-bob {
  0%, 100% { transform: translateY(0) rotate(-0.6deg); }
  50% { transform: translateY(-7px) rotate(0.6deg); }
}

/* ---------- title ---------- */

.title {
  position: absolute;
  inset: 0;
  z-index: 30;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  pointer-events: none;
  padding: 0 clamp(10px, 3vw, 30px);
}

.title-stack {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: clamp(7px, 1.5vh, 16px);
  padding-top: max(clamp(10px, 3.4vh, 38px), env(safe-area-inset-top));
  max-width: 100%;
  pointer-events: none;
}

.title-logo {
  width: auto;
  height: auto;
  max-width: min(68vw, 660px);
  max-height: min(40vh, 350px);
  filter: drop-shadow(0 9px 0 rgba(35, 37, 43, 0.26));
  animation: title-bob 3.8s ease-in-out infinite;
}

@keyframes title-bob {
  0%, 100% { transform: translateY(0) rotate(-0.4deg); }
  50% { transform: translateY(-8px) rotate(0.4deg); }
}

.title-tagline {
  margin: 0;
  max-width: min(600px, 86vw);
  padding: clamp(5px, 0.9vh, 9px) clamp(14px, 2vw, 24px);
  border: 3px solid var(--ink);
  border-radius: 18px;
  background: rgba(255, 243, 214, 0.95);
  box-shadow: 0 4px 0 rgba(35, 37, 43, 0.26);
  color: var(--ink);
  font-weight: 800;
  font-size: clamp(10px, 1.15vw, 15px);
  line-height: 1.35;
  text-align: center;
}

.title-actions {
  display: flex;
  align-items: center;
  gap: clamp(12px, 2.2vw, 28px);
  pointer-events: none;
}

.start-button {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: clamp(6px, 1vw, 12px);
  pointer-events: auto;
  padding: 0;
}

.start-icon-wrap {
  display: block;
  width: clamp(70px, 8.6vw, 108px);
  aspect-ratio: 1;
  border-radius: 50%;
  filter: drop-shadow(0 6px 0 rgba(35, 37, 43, 0.28));
  transition: transform 110ms ease-out;
}

.start-icon-wrap img {
  display: block;
  width: 100%;
  height: 100%;
}

.start-label {
  font-family: var(--display);
  font-weight: 400;
  font-size: clamp(21px, 2.3vw, 32px);
  letter-spacing: 0.04em;
  color: var(--cream);
  text-shadow:
    -2px -2px 0 var(--ink), 2px -2px 0 var(--ink),
    -2px 2px 0 var(--ink), 2px 2px 0 var(--ink),
    0 4px 0 var(--orange-dark);
}

.start-button:hover .start-icon-wrap,
.start-button:focus-visible .start-icon-wrap {
  transform: scale(1.06) rotate(-2deg);
}

.start-button:active .start-icon-wrap {
  transform: translateY(4px) scale(0.97);
}

.best-chip {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0;
  padding: 5px 16px;
  border: 3px solid var(--ink);
  border-radius: 16px;
  background: var(--cream);
  box-shadow: 0 4px 0 rgba(35, 37, 43, 0.26), inset 0 3px 0 #fff;
  transform: rotate(1.5deg);
}

.best-label {
  font-family: var(--display);
  font-weight: 400;
  font-size: clamp(10px, 1vw, 13px);
  letter-spacing: 0.16em;
  color: var(--brick);
  text-transform: uppercase;
}

.best-chip .score-font {
  font-size: clamp(15px, 1.7vw, 23px);
  line-height: 1.1;
}

.controls-hint {
  position: absolute;
  left: clamp(10px, 2.4vw, 30px);
  bottom: max(10px, env(safe-area-inset-bottom));
  margin: 0;
  padding: 5px 15px;
  border-radius: 999px;
  background: rgba(35, 37, 43, 0.48);
  color: var(--cream);
  font-weight: 800;
  font-size: clamp(10px, 1.05vw, 14px);
  line-height: 1.3;
  text-align: left;
  max-width: min(46vw, 470px);
}

.title-credit {
  display: none;
  position: absolute;
  right: clamp(10px, 2.4vw, 30px);
  bottom: max(12px, env(safe-area-inset-bottom));
  color: rgba(255, 243, 214, 0.78);
  font-weight: 800;
  font-size: 10px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  text-shadow: 0 1px 0 rgba(35, 37, 43, 0.45);
}

.icon-btn {
  position: absolute;
  top: max(clamp(9px, 1.6vh, 18px), env(safe-area-inset-top));
  right: max(clamp(9px, 1.8vw, 22px), env(safe-area-inset-right));
  z-index: 4;
  width: clamp(38px, 4vw, 48px);
  aspect-ratio: 1;
  border-radius: 50%;
  border: 3px solid var(--ink);
  background: var(--cream);
  box-shadow: 0 4px 0 rgba(35, 37, 43, 0.3), inset 0 3px 0 #fff;
  color: var(--ink);
  display: grid;
  place-items: center;
  pointer-events: auto;
}

.icon-btn svg {
  width: 58%;
  height: 58%;
  overflow: visible;
}

.icon-btn .spk-body {
  fill: currentColor;
}

.icon-btn .spk-wave,
.icon-btn .spk-cross {
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
}

.icon-btn .spk-cross {
  display: none;
}

.icon-btn.muted .spk-cross {
  display: block;
}

.icon-btn.muted .spk-wave {
  display: none;
}

.icon-btn:active {
  transform: translateY(2px);
  box-shadow: 0 2px 0 rgba(35, 37, 43, 0.3), inset 0 3px 0 #fff;
}

/* ---------- hud ---------- */

#hud {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: flex-start;
  gap: var(--gap);
  padding:
    max(var(--hud-pad), env(safe-area-inset-top))
    max(var(--hud-pad), env(safe-area-inset-right))
    max(var(--hud-pad), env(safe-area-inset-bottom))
    max(var(--hud-pad), env(safe-area-inset-left));
  pointer-events: none;
}

#hud > * {
  pointer-events: auto;
}

#hud > .key-hint {
  pointer-events: none;
}

.hud-group {
  display: flex;
  align-items: center;
  gap: var(--gap);
}

.hud-left {
  order: 1;
}

.hud-right {
  order: 2;
  margin-left: auto;
}

.hud-actions {
  order: 3;
  display: flex;
  align-items: center;
  gap: clamp(5px, 0.7vw, 9px);
}

.avatar-plate {
  flex: 0 0 auto;
  width: clamp(44px, 5vw, 68px);
  aspect-ratio: 1;
  border-radius: 50%;
  border: clamp(3px, 0.35vw, 4px) solid var(--ink);
  background: var(--orange);
  box-shadow: 0 4px 0 rgba(35, 37, 43, 0.3), inset 0 5px 0 rgba(255, 255, 255, 0.3);
  overflow: hidden;
}

.avatar-plate img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  transform: scale(1.1);
  object-position: 50% 28%;
}

.life-plate {
  position: relative;
  width: clamp(116px, 13vw, 184px);
  aspect-ratio: 453 / 202;
}

.plate-bg {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.lives {
  position: absolute;
  inset: 0;
}

.life {
  position: absolute;
  top: 50%;
  width: 21%;
  aspect-ratio: 1;
  border-radius: 50%;
  border: clamp(1.5px, 0.18vw, 2.5px) solid var(--ink);
  background: var(--cream);
  box-shadow: 0 1px 0 rgba(35, 37, 43, 0.3);
  overflow: hidden;
  transform: translate(-50%, -50%) scale(1);
  transition: filter 160ms, opacity 160ms, transform 160ms;
}

.life:nth-child(1) { left: 21%; }
.life:nth-child(2) { left: 49.2%; }
.life:nth-child(3) { left: 77.4%; }

.life img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  transform: scale(1.18);
  object-position: 50% 28%;
}

.life.out {
  filter: grayscale(1) brightness(0.7);
  opacity: 0.34;
  transform: translate(-50%, -50%) scale(0.88);
}

.score-plate,
.sphere-plate {
  position: relative;
  flex: 0 0 auto;
}

.score-plate {
  width: clamp(102px, 11.4vw, 168px);
  aspect-ratio: 435 / 204;
}

.sphere-plate {
  width: clamp(88px, 9.8vw, 150px);
  aspect-ratio: 435 / 205;
}

.plate-value {
  position: absolute;
  top: 50%;
  transform: translateY(-48%);
  left: 37%;
  right: 6%;
  width: auto;
  text-align: right;
  color: var(--ink);
  font-size: clamp(13px, 1.55vw, 24px);
  font-weight: 700;
  line-height: 1;
  letter-spacing: 0.01em;
  font-variant-numeric: tabular-nums;
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.55);
}

.sphere-plate .plate-value {
  left: 38%;
  right: 8%;
  width: auto;
  color: var(--ink);
}

.cushion {
  position: relative;
  flex: 0 0 auto;
  width: clamp(42px, 4.4vw, 52px);
  aspect-ratio: 1;
  padding: 0;
  border-radius: 50%;
  border: clamp(2.5px, 0.25vw, 3.5px) solid var(--ink);
  background: var(--cream);
  box-shadow:
    0 4px 0 rgba(35, 37, 43, 0.32),
    inset 0 4px 0 #fff,
    inset 0 -3px 0 rgba(192, 85, 58, 0.28);
  overflow: hidden;
  display: grid;
  place-items: center;
  touch-action: manipulation;
}

.cushion img {
  display: block;
  width: 88%;
  height: 88%;
  object-fit: contain;
  pointer-events: none;
}

.cushion:active {
  transform: translateY(3px);
  box-shadow: 0 1px 0 rgba(35, 37, 43, 0.32), inset 0 4px 0 #fff;
}

.help-button {
  background: var(--orange);
}

.help-mark {
  font-family: var(--display);
  font-weight: 400;
  font-size: clamp(19px, 2.2vw, 28px);
  line-height: 1;
  color: var(--cream);
  text-shadow: 0 2px 0 var(--orange-dark);
}

.hud-center {
  position: absolute;
  top: clamp(10px, 1.9vh, 20px);
  left: 50%;
  transform: translateX(-50%);
  pointer-events: none;
}

.level-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 13px 4px 4px;
  border: 3px solid var(--ink);
  border-radius: 13px;
  background: var(--cream);
  box-shadow: 0 4px 0 rgba(35, 37, 43, 0.26), inset 0 3px 0 #fff;
}

.level-tag {
  display: inline-block;
  padding: 2px 8px;
  border: 2px solid var(--ink);
  border-radius: 7px;
  background: var(--theme-accent, var(--orange));
  color: var(--ink);
  font-size: clamp(11px, 1vw, 14px);
  font-weight: 700;
  line-height: 1;
  letter-spacing: 0.03em;
}

.level-name {
  font-family: var(--display);
  font-weight: 400;
  font-size: clamp(13px, 1.2vw, 18px);
  color: var(--ink);
  line-height: 1;
  letter-spacing: 0.01em;
  white-space: nowrap;
}

.key-hint {
  position: absolute;
  left: 50%;
  bottom: max(7px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  padding: 4px 13px;
  border-radius: 999px;
  background: rgba(35, 37, 43, 0.48);
  color: rgba(255, 243, 214, 0.95);
  font-weight: 800;
  font-size: clamp(9px, 0.9vw, 12px);
  letter-spacing: 0.06em;
  white-space: nowrap;
  text-shadow: 0 1px 0 rgba(35, 37, 43, 0.55), 0 0 6px rgba(35, 37, 43, 0.28);
  pointer-events: none;
}

/* ---------- touch ---------- */

#touch-controls {
  position: absolute;
  left: 0;
  right: 0;
  bottom: max(22px, env(safe-area-inset-bottom));
  z-index: 42;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  padding-left: max(clamp(12px, 3.2vw, 34px), env(safe-area-inset-left));
  padding-right: max(clamp(12px, 3.2vw, 34px), env(safe-area-inset-right));
  pointer-events: none;
}

.touch-move {
  display: flex;
  align-items: flex-end;
  gap: clamp(8px, 1.8vw, 16px);
  pointer-events: auto;
}

.touch-key,
.jump-button {
  pointer-events: auto;
  width: clamp(56px, 13.2vmin, 84px);
  aspect-ratio: 1;
  padding: 0;
  border-radius: 50%;
  border: clamp(3px, 0.4vmin, 4px) solid var(--ink);
  background: var(--cream);
  color: var(--ink);
  box-shadow:
    0 5px 0 rgba(35, 37, 43, 0.35),
    inset 0 5px 0 #fff,
    inset 0 -4px 0 rgba(192, 85, 58, 0.3);
  display: grid;
  place-items: center;
  touch-action: none;
}

.touch-key svg {
  width: 54%;
  height: 54%;
  pointer-events: none;
}

.touch-key:active,
.touch-key.pressed {
  transform: translateY(4px);
  box-shadow: 0 1px 0 rgba(35, 37, 43, 0.35), inset 0 5px 0 #fff;
}

.jump-button {
  width: clamp(70px, 16.4vmin, 104px);
  background: var(--orange);
  color: var(--cream);
  box-shadow:
    0 6px 0 var(--orange-dark),
    0 9px 0 rgba(35, 37, 43, 0.26),
    inset 0 5px 0 rgba(255, 255, 255, 0.3);
  grid-auto-rows: min-content;
}

.jump-mark {
  font-family: var(--display);
  font-weight: 400;
  font-size: clamp(15px, 3.4vmin, 23px);
  line-height: 1;
  letter-spacing: 0.04em;
  text-shadow: 0 2px 0 var(--orange-dark);
}

.jump-sub {
  font-weight: 800;
  font-size: clamp(8px, 1.5vmin, 11px);
  line-height: 1;
  opacity: 0.86;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  margin-top: 1px;
}

.jump-button:active,
.jump-button.pressed {
  transform: translateY(5px);
  box-shadow:
    0 1px 0 var(--orange-dark),
    0 3px 0 rgba(35, 37, 43, 0.26),
    inset 0 5px 0 rgba(255, 255, 255, 0.3);
}

/* ---------- banner ---------- */

.level-banner {
  display: grid;
  grid-template-columns: auto auto;
  grid-template-areas:
    "world mode"
    "tag name";
  align-items: center;
  justify-items: end;
  column-gap: 7px;
  row-gap: 4px;
  max-width: 100%;
  padding: 6px 10px;
  border: 3px solid var(--ink);
  border-radius: 12px;
  background: var(--cream);
  box-shadow: 0 5px 0 rgba(35, 37, 43, 0.3), inset 0 3px 0 #fff;
  animation: banner-pop 320ms cubic-bezier(0.2, 1.35, 0.5, 1) both;
  pointer-events: none;
}

.level-banner.out {
  animation: banner-out 260ms ease-in both;
}

.banner-world {
  grid-area: world;
}

.banner-tag {
  grid-area: tag;
}

.banner-name {
  grid-area: name;
}

.banner-mode {
  grid-area: mode;
}

@keyframes banner-pop {
  from { opacity: 0; transform: translateX(18px) scale(0.9); }
  to { opacity: 1; transform: none; }
}

@keyframes banner-out {
  from { opacity: 1; transform: none; }
  to { opacity: 0; transform: translateX(14px) scale(0.94); }
}

.banner-tag {
  display: inline-block;
  padding: 4px 9px;
  border: 2px solid var(--ink);
  border-radius: 8px;
  background: var(--theme-accent, var(--orange));
  color: var(--ink);
  font-size: clamp(12px, 1.2vw, 15px);
  font-weight: 700;
  line-height: 1;
}

.banner-name {
  font-family: var(--display);
  font-weight: 400;
  font-size: clamp(17px, 1.9vw, 26px);
  line-height: 1;
  color: var(--ink);
  white-space: nowrap;
}

.banner-world {
  font-family: var(--score);
  font-weight: 700;
  font-size: clamp(10px, 1vw, 12px);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--brick);
  line-height: 1;
  white-space: nowrap;
}

.banner-mode {
  display: inline-block;
  padding: 4px 9px;
  border: 2px solid var(--ink);
  border-radius: 8px;
  background: var(--ink);
  color: var(--cream);
  font-family: var(--score);
  font-weight: 700;
  font-size: clamp(9px, 0.92vw, 11px);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  line-height: 1;
  white-space: nowrap;
}

/* ---------- mode badge ---------- */

.mode-badge {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 3px 10px 3px 4px;
  border: 2px solid var(--ink);
  border-radius: 999px;
  background: var(--ink);
  box-shadow: 0 3px 0 rgba(35, 37, 43, 0.24);
}

.mode-badge-label {
  padding: 2px 6px;
  border-radius: 999px;
  background: var(--gold);
  color: var(--ink);
  font-family: var(--score);
  font-weight: 700;
  font-size: clamp(8px, 0.82vw, 10px);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  line-height: 1;
}

.mode-badge-name {
  font-family: var(--score);
  font-weight: 700;
  font-size: clamp(9px, 0.95vw, 12px);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--cream);
  line-height: 1;
  white-space: nowrap;
}

/* ---------- boss bar ---------- */

.boss-bar {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 4px 13px 7px;
  border: 3px solid var(--ink);
  border-radius: 13px;
  background: rgba(255, 243, 214, 0.98);
  box-shadow: 0 4px 0 rgba(35, 37, 43, 0.26), inset 0 3px 0 #fff;
}

.boss-name {
  font-family: var(--display);
  font-weight: 400;
  font-size: clamp(11px, 1.15vw, 15px);
  line-height: 1;
  letter-spacing: 0.02em;
  color: var(--brick);
}

.boss-track {
  display: block;
  width: clamp(150px, 20vw, 250px);
  height: clamp(8px, 0.95vw, 12px);
  border: 2px solid var(--ink);
  border-radius: 999px;
  background: #6a3030;
  overflow: hidden;
}

.boss-track i {
  display: block;
  height: 100%;
  width: 100%;
  background: var(--orange);
  box-shadow: inset 0 3px 0 rgba(255, 255, 255, 0.32);
  transition: width 220ms ease;
}

@media (max-width: 700px) {
  .banner-world {
    display: none;
  }

  .boss-bar {
    padding: 3px 9px 5px;
    gap: 3px;
  }

  .boss-track {
    width: clamp(140px, 50vw, 220px);
  }
}

/* ---------- overlays ---------- */

.screen.overlay,
.overlay-panel.overlay {
  position: absolute;
  inset: 0;
  z-index: 60;
  display: grid;
  place-items: center;
  padding: clamp(10px, 2.4vw, 26px);
  background: rgba(35, 37, 43, 0.52);
}

.panel {
  position: relative;
  width: min(460px, 94vw);
  max-height: 92vh;
  overflow: auto;
  padding: clamp(18px, 3.2vw, 32px) clamp(18px, 3vw, 34px);
  border: 4px solid var(--ink);
  border-radius: clamp(20px, 3vw, 28px);
  background: var(--cream);
  box-shadow:
    0 11px 0 rgba(35, 37, 43, 0.42),
    inset 0 7px 0 #fff,
    inset 0 -5px 0 rgba(255, 201, 60, 0.22);
  text-align: center;
  animation: panel-in 240ms cubic-bezier(0.2, 1.3, 0.4, 1) both;
}

@keyframes panel-in {
  from { opacity: 0; transform: translateY(14px) scale(0.94); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.panel-title {
  margin: 0 0 3px;
  font-family: var(--display);
  font-weight: 400;
  font-size: clamp(29px, 4.2vw, 44px);
  line-height: 1;
  letter-spacing: 0.015em;
  color: var(--orange);
  text-shadow:
    0 2px 0 var(--ink),
    0 4px 0 rgba(35, 37, 43, 0.16);
}

.panel-sub {
  margin: 0 auto 16px;
  max-width: 34ch;
  color: var(--brick);
  font-weight: 800;
  font-size: clamp(12px, 1.3vw, 16px);
  line-height: 1.35;
}

.panel-eyebrow {
  margin: 0 0 3px;
  color: var(--brick);
  font-size: clamp(10px, 1vw, 13px);
  font-weight: 700;
  letter-spacing: 0.15em;
  text-transform: uppercase;
}

.panel-buttons {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 9px;
  margin-top: 12px;
}

.pill-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  padding: clamp(10px, 1.4vh, 14px) clamp(22px, 3vw, 34px);
  border: 3px solid var(--ink);
  border-radius: 999px;
  background: var(--orange);
  color: var(--cream);
  font-family: var(--display);
  font-weight: 400;
  font-size: clamp(18px, 2vw, 24px);
  line-height: 1;
  letter-spacing: 0.02em;
  text-shadow: 0 2px 0 var(--orange-dark);
  box-shadow:
    0 5px 0 var(--orange-dark),
    inset 0 4px 0 rgba(255, 255, 255, 0.3);
  transition: transform 100ms ease-out;
}

.pill-btn:hover,
.pill-btn:focus-visible {
  filter: brightness(1.04);
  transform: translateY(-1px);
}

.pill-btn:active {
  transform: translateY(4px);
  box-shadow: 0 1px 0 var(--orange-dark), inset 0 4px 0 rgba(255, 255, 255, 0.3);
}

.play-tri {
  width: 0;
  height: 0;
  border-top: 8px solid transparent;
  border-bottom: 8px solid transparent;
  border-left: 13px solid var(--cream);
  filter: drop-shadow(0 2px 0 var(--orange-dark));
}

.pill-arrow {
  font-family: var(--body);
  font-weight: 900;
  font-size: 0.9em;
}

.panel-btn {
  padding: clamp(9px, 1.2vh, 12px) 18px;
  border: 3px solid var(--ink);
  border-radius: 14px;
  background: var(--cream);
  color: var(--ink);
  font-family: var(--body);
  font-weight: 900;
  font-size: clamp(13px, 1.3vw, 16px);
  box-shadow: 0 4px 0 rgba(35, 37, 43, 0.24), inset 0 3px 0 #fff;
}

.panel-btn:active {
  transform: translateY(3px);
  box-shadow: 0 1px 0 rgba(35, 37, 43, 0.24), inset 0 3px 0 #fff;
}

.panel-button {
  display: inline-block;
  margin-top: 16px;
  padding: 11px 28px;
  border: 3px solid var(--ink);
  border-radius: 999px;
  background: var(--orange);
  color: var(--cream);
  font-family: var(--display);
  font-weight: 400;
  font-size: clamp(17px, 1.9vw, 22px);
  letter-spacing: 0.02em;
  text-shadow: 0 2px 0 var(--orange-dark);
  box-shadow: 0 5px 0 var(--orange-dark), inset 0 3px 0 rgba(255, 255, 255, 0.3);
}

.panel-button:active {
  transform: translateY(4px);
  box-shadow: 0 1px 0 var(--orange-dark), inset 0 3px 0 rgba(255, 255, 255, 0.3);
}

.panel-text-btn {
  display: block;
  margin: 10px auto 0;
  padding: 6px 10px;
  color: rgba(35, 37, 43, 0.68);
  font-family: var(--body);
  font-weight: 900;
  font-size: clamp(12px, 1.2vw, 15px);
  text-decoration: underline;
  text-underline-offset: 3px;
}

.panel-text-btn:hover {
  color: var(--ink);
}

.help-panel {
  width: min(480px, 94vw);
}

.help-mode {
  margin: 2px 0 0;
  font-family: var(--score);
  font-weight: 700;
  font-size: clamp(10px, 1.05vw, 13px);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--brick);
}

.help-rows {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin: 10px 0 2px;
}

.help-row {
  display: flex;
  align-items: center;
  gap: clamp(9px, 1.4vw, 14px);
  padding: 7px 2px;
  border-bottom: 2px dashed rgba(35, 37, 43, 0.16);
  font-weight: 800;
  font-size: clamp(11px, 1.2vw, 15px);
  line-height: 1.25;
  text-align: left;
}

.help-row:last-child {
  border-bottom: 0;
}

.help-key {
  flex: 0 0 auto;
  min-width: clamp(60px, 7vw, 78px);
  padding: 4px 7px;
  border: 2px solid var(--ink);
  border-radius: 8px;
  background: var(--gold);
  color: var(--ink);
  font-size: clamp(10px, 1vw, 12px);
  font-weight: 700;
  text-align: center;
  box-shadow: 0 2px 0 rgba(35, 37, 43, 0.22);
}

.panel-hint {
  margin: 10px 0 0;
  color: rgba(35, 37, 43, 0.72);
  font-weight: 800;
  font-size: clamp(10px, 1.05vw, 13px);
  line-height: 1.35;
}

.result-grid {
  display: flex;
  justify-content: center;
  gap: clamp(8px, 2.4vw, 22px);
  margin: 4px 0 16px;
  padding: 0;
}

.result-grid > div {
  min-width: 82px;
}

.result-grid dt {
  color: var(--brick);
  font-weight: 900;
  font-size: clamp(9px, 0.95vw, 12px);
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.result-grid dd {
  margin: 1px 0 0;
  color: var(--ink);
  font-size: clamp(19px, 2.2vw, 28px);
  font-weight: 700;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.victory-panel {
  width: min(490px, 94vw);
}

.over-choices {
  display: flex;
  flex-direction: column;
  gap: 9px;
  margin-top: 2px;
}

.over-choices .pill-btn,
.over-choices .panel-btn {
  width: 100%;
}

.victory-burst {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: clamp(6px, 1.6vw, 16px);
  margin: 2px 0 12px;
}

.victory-burst img {
  width: clamp(38px, 6vw, 62px);
  height: auto;
  filter: drop-shadow(0 4px 0 rgba(35, 37, 43, 0.24));
  animation: orb-float 2.8s ease-in-out infinite;
}

.victory-burst img:nth-child(2) {
  animation-delay: 0.22s;
  transform: scale(1.22);
}

.victory-burst img:nth-child(3) {
  animation-delay: 0.44s;
}

@keyframes orb-float {
  0%, 100% { translate: 0 0; rotate: -2deg; }
  50% { translate: 0 -7px; rotate: 2deg; }
}

.confetti {
  position: absolute;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
  border-radius: inherit;
}

.panel > :not(.confetti) {
  position: relative;
  z-index: 1;
}

.confetti i {
  position: absolute;
  top: -18px;
  width: 8px;
  height: 12px;
  border: 2px solid var(--ink);
  border-radius: 2px;
  animation: confetti-fall linear forwards;
}

@keyframes confetti-fall {
  from { transform: translateY(-10px) rotate(0deg); opacity: 1; }
  to { transform: translateY(340px) rotate(420deg); opacity: 0.7; }
}

@keyframes plate-bump {
  0% { transform: translateY(-48%) scale(1); }
  35% { transform: translateY(-48%) scale(1.15) rotate(-1.5deg); }
  100% { transform: translateY(-48%) scale(1); }
}

.bump {
  animation: plate-bump 280ms ease-out;
}

/* ---------- power meter ---------- */

.hud-center {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.power-rail {
  position: absolute;
  top: var(--rail-top);
  right: max(var(--hud-pad), env(safe-area-inset-right));
  z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 5px;
  max-width: min(58vw, 280px);
  pointer-events: none;
}

.power-rail > * {
  pointer-events: auto;
}

.power-rail > .level-banner,
.power-rail > .power-toast {
  pointer-events: none;
}

.power-meter {
  display: grid;
  grid-template-columns: repeat(2, auto);
  gap: 4px clamp(6px, 0.9vw, 11px);
  padding: 5px clamp(7px, 0.9vw, 11px);
  border: 3px solid var(--ink);
  border-radius: 14px;
  background: rgba(255, 243, 214, 0.98);
  box-shadow: 0 4px 0 rgba(35, 37, 43, 0.26), inset 0 3px 0 #fff;
}

.meter-chip {
  position: relative;
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 5px;
  padding: 2px 5px;
  border: 2px solid transparent;
  border-radius: 9px;
  --chip: #f4a62a;
}

.meter-chip[data-element="fire"] { --chip: #e8a800; }
.meter-chip[data-element="ice"] { --chip: #2f9ad0; }
.meter-chip[data-element="lightning"] { --chip: #d63329; }
.meter-chip[data-element="stone"] { --chip: #8a5a3b; }

.power-meter img {
  width: clamp(18px, 1.95vw, 24px);
  height: clamp(18px, 1.95vw, 24px);
  display: block;
  object-fit: contain;
  filter: drop-shadow(0 1px 0 rgba(35, 37, 43, 0.32));
}

.meter-count {
  min-width: 2.2em;
  font-size: clamp(10px, 1.05vw, 13px);
  font-weight: 700;
  line-height: 1;
  letter-spacing: 0.02em;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.meter-bar {
  display: flex;
  gap: 2px;
  padding: 2px;
  border-radius: 5px;
  background: rgba(35, 37, 43, 0.34);
  box-shadow: inset 0 1px 3px rgba(35, 37, 43, 0.42);
}

.meter-bar i {
  display: block;
  width: clamp(7px, 0.85vw, 11px);
  height: clamp(7px, 0.8vw, 10px);
  border-radius: 2px;
  background: rgba(255, 255, 255, 0.36);
}

.meter-bar i.on {
  background: var(--chip);
  box-shadow: 0 0 4px var(--chip), inset 0 1px 0 rgba(255, 255, 255, 0.45);
}

.meter-chip.active {
  border-color: var(--chip);
  background: rgba(255, 255, 255, 0.62);
}

.meter-chip.ready {
  background: var(--chip);
  animation: meter-ready 700ms ease-in-out infinite alternate;
}

.meter-chip.ready .meter-count {
  color: #fff;
}

.meter-chip.ready .meter-bar {
  background: rgba(35, 37, 43, 0.3);
}

.meter-chip.ready .meter-bar i {
  background: rgba(255, 255, 255, 0.35);
}

.meter-chip.ready .meter-bar i.on {
  background: #fff;
  box-shadow: 0 0 4px #fff;
}

.meter-chip.bump {
  animation: meter-bump 260ms ease-out;
}

.meter-chip.lvl2 {
  background: var(--chip);
  border-color: var(--ink);
}

.meter-chip.lvl2 .meter-count {
  color: #fff;
  text-shadow: 0 1px 0 rgba(35, 37, 43, 0.35);
}

.meter-chip.lvl2 .meter-bar {
  background: rgba(35, 37, 43, 0.3);
}

.meter-chip.lvl2 .meter-bar i {
  background: rgba(255, 255, 255, 0.35);
}

.meter-chip.lvl2 .meter-bar i.on {
  background: #fff;
}

@keyframes meter-bump {
  0% { transform: scale(1); }
  40% { transform: scale(1.22) rotate(-2deg); }
  100% { transform: scale(1); }
}

@keyframes meter-ready {
  from { box-shadow: 0 0 0 0 rgba(255, 201, 60, 0); }
  to { box-shadow: 0 0 0 4px rgba(255, 201, 60, 0.55); }
}

.transform-prompt {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 5px 10px 7px;
  max-width: 100%;
  border: 3px solid var(--ink);
  border-radius: 16px;
  background: var(--cream);
  box-shadow: 0 5px 0 rgba(35, 37, 43, 0.3), inset 0 3px 0 #fff;
  animation: transform-in 280ms cubic-bezier(0.2, 1.4, 0.4, 1) both;
  pointer-events: auto;
}

.transform-lead {
  font-family: var(--display);
  font-weight: 400;
  font-size: clamp(10px, 1vw, 13px);
  letter-spacing: 0.14em;
  text-transform: uppercase;
  line-height: 1;
  color: var(--brick);
}

.transform-options {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px;
}

.transform-btn {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 3px 10px 3px 4px;
  border: 2px solid var(--ink);
  border-radius: 999px;
  background: var(--power, var(--gold));
  color: var(--ink);
  font-family: var(--display);
  font-weight: 400;
  font-size: clamp(10px, 1.05vw, 13px);
  line-height: 1;
  letter-spacing: 0.02em;
  box-shadow: 0 3px 0 rgba(35, 37, 43, 0.3), inset 0 2px 0 rgba(255, 255, 255, 0.5);
  cursor: pointer;
}

.transform-btn img {
  width: clamp(18px, 2vw, 25px);
  height: clamp(18px, 2vw, 25px);
  display: block;
  object-fit: contain;
}

.transform-btn:active {
  transform: translateY(2px);
  box-shadow: 0 1px 0 rgba(35, 37, 43, 0.3), inset 0 2px 0 rgba(255, 255, 255, 0.5);
}

@keyframes transform-in {
  from { opacity: 0; transform: translateY(-6px) scale(0.88); }
  to { opacity: 1; transform: none; }
}

/* ---------- focus ---------- */

button:focus-visible {
  outline: 3px solid var(--gold);
  outline-offset: 3px;
}

/* ---------- responsive ---------- */

@media (max-width: 1130px) {
  .hud-center {
    top: clamp(84px, 12vh, 104px);
  }

  .level-chip {
    display: none;
  }
}

@media (max-width: 700px) {
  #hud {
    display: grid;
    grid-template-columns: 1fr auto;
    grid-template-areas:
      "left actions"
      "right right"
      "meter meter";
    align-items: start;
    align-content: start;
    grid-auto-rows: min-content;
    row-gap: clamp(5px, 1.2vw, 8px);
  }

  .hud-left { grid-area: left; }
  .hud-actions { grid-area: actions; justify-self: end; }
  .hud-right {
    grid-area: right;
    justify-self: center;
    margin-left: 0;
  }

  .hud-center {
    position: static;
    grid-area: meter;
    justify-self: center;
    transform: none;
    top: auto;
    left: auto;
  }

  :root {
    --rail-top: calc(max(var(--hud-pad), env(safe-area-inset-top)) + 132px);
  }

  .power-rail {
    max-width: min(58vw, 280px);
  }

  .score-plate {
    width: clamp(104px, 25vw, 142px);
  }

  .sphere-plate {
    width: clamp(90px, 21vw, 124px);
  }

  .level-chip {
    display: none;
  }
}

@media (max-width: 700px) {
  .controls-hint {
    left: 50%;
    bottom: max(8px, env(safe-area-inset-bottom));
    transform: translateX(-50%);
    max-width: 92vw;
    text-align: center;
  }

  .title-credit {
    display: none;
  }
}

@media (max-width: 420px) {
  .avatar-plate {
    width: clamp(42px, 11.5vw, 52px);
  }

  .power-meter {
    gap: 2px 6px;
    padding: 4px 6px;
  }

  .meter-chip {
    gap: 3px;
    padding: 1px 3px;
  }

  .meter-bar {
    gap: 1px;
    padding: 1px;
  }

  .meter-bar i {
    width: 5px;
    height: 6px;
  }

  .meter-chip .meter-count {
    font-size: 9px;
    min-width: 2.1em;
  }

  .meter-chip .meter-icon,
  .meter-chip img {
    width: 14px;
    height: 14px;
  }

  .transform-prompt {
    padding: 4px 7px 6px;
  }

  .transform-btn {
    padding: 3px 8px 3px 3px;
  }

  .power-toast {
    gap: 6px;
    padding: 3px 9px 3px 3px;
    font-size: 13px;
  }

  .power-toast img {
    width: 22px;
    height: 22px;
  }

  .life-plate {
    width: clamp(108px, 31vw, 142px);
  }

  .hud-actions .cushion {
    width: clamp(42px, 11.6vw, 46px);
  }

  .help-mark {
    font-size: 19px;
  }

  .score-plate {
    width: clamp(108px, 30vw, 132px);
  }

  .sphere-plate {
    width: clamp(84px, 22vw, 108px);
  }

  .plate-value {
    left: 42%;
    right: 4%;
    font-size: clamp(13px, 3.6vw, 17px);
  }
}

@media (max-height: 540px) {
  .title-stack {
    padding-top: 2vh;
    gap: 5px;
  }

  .title-logo {
    max-height: 34vh;
  }

  .title-tagline {
    display: none;
  }

  .title-credit {
    display: none;
  }

  .title-actions {
    margin-top: 1vh;
  }

  .start-icon-wrap {
    width: clamp(58px, 9vh, 78px);
  }

  .start-label {
    font-size: clamp(18px, 3.2vh, 24px);
  }

  .level-banner {
    padding: 4px 8px;
  }

  .banner-name {
    font-size: 16px;
  }

  .panel {
    max-height: 94vh;
    padding: 14px 20px;
  }

  .panel-title {
    font-size: clamp(25px, 6vh, 34px);
  }

  .panel-sub {
    margin-bottom: 8px;
    font-size: 12px;
  }

  .help-row {
    padding: 4px 2px;
  }

  .help-rows {
    margin: 4px 0 0;
  }

  .panel-button {
    margin-top: 9px;
    padding: 8px 24px;
  }

  .result-grid {
    margin-bottom: 10px;
  }

  .victory-burst {
    margin-bottom: 6px;
  }

  .victory-burst img {
    width: 38px;
  }
}

@media (max-height: 400px) {
  .controls-hint {
    font-size: 9px;
  }

  .title-logo {
    max-height: 30vh;
  }

  .panel-buttons {
    gap: 6px;
    margin-top: 8px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .title-logo,
  .loader-logo,
  .victory-burst img {
    animation: none;
  }

  .panel,
  .level-banner {
    animation-duration: 1ms;
  }
}

/* ---------- element power ---------- */

.avatar-plate {
  position: relative;
}

.avatar-plate.powered {
  background: var(--element, var(--orange));
  box-shadow:
    0 0 0 3px rgba(255, 255, 255, 0.55),
    0 4px 0 rgba(35, 37, 43, 0.3),
    inset 0 5px 0 rgba(255, 255, 255, 0.3);
}

.element-badge {
  position: absolute;
  right: 4%;
  bottom: 4%;
  width: 42%;
  aspect-ratio: 1;
  border-radius: 50%;
  border: 2px solid var(--ink);
  background: var(--cream);
  box-shadow: 0 2px 0 rgba(35, 37, 43, 0.28);
  overflow: hidden;
  pointer-events: none;
}

.element-badge img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  transform: none;
  object-position: 50% 50%;
}

.power-toast {
  position: relative;
  z-index: 55;
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 5px 18px 5px 5px;
  border: 3px solid var(--ink);
  border-radius: 999px;
  background: var(--cream);
  box-shadow:
    0 6px 0 rgba(35, 37, 43, 0.34),
    inset 0 4px 0 #fff;
  font-family: var(--display);
  font-weight: 400;
  font-size: clamp(17px, 2.4vw, 26px);
  line-height: 1;
  letter-spacing: 0.02em;
  pointer-events: none;
  animation: power-toast-pop 260ms cubic-bezier(0.2, 1.4, 0.4, 1) both;
}

.power-toast img {
  width: clamp(30px, 4.6vw, 44px);
  height: clamp(30px, 4.6vw, 44px);
  object-fit: contain;
}

.power-toast span {
  color: var(--power, var(--orange));
  text-shadow: 0 1px 0 #fff;
  white-space: nowrap;
}

@keyframes power-toast-pop {
  from { opacity: 0; transform: translateX(16px) scale(0.8); }
  to { opacity: 1; transform: none; }
}

.touch-act {
  display: flex;
  align-items: flex-end;
  gap: clamp(8px, 1.8vw, 16px);
  pointer-events: none;
}

.touch-act > * {
  pointer-events: auto;
}

#touch-controls.solo-right {
  justify-content: stretch;
}

#touch-controls.solo-right #touch-act-main {
  flex: 1;
  justify-content: space-between;
}

#touch-controls.solo-right .jump-button {
  order: -1;
}

.touch-act-bike {
  align-items: flex-end;
  gap: clamp(6px, 1.2vw, 12px);
}

.touch-speed {
  display: flex;
  flex-direction: column;
  gap: clamp(5px, 1vmin, 9px);
  pointer-events: auto;
}

.speed-button {
  width: clamp(50px, 11vmin, 70px);
  aspect-ratio: 1.16;
  border-radius: 16px;
  border: clamp(2.5px, 0.35vmin, 3.5px) solid var(--ink);
  background: var(--cream);
  color: var(--ink);
  box-shadow:
    0 4px 0 rgba(35, 37, 43, 0.32),
    inset 0 4px 0 #fff,
    inset 0 -3px 0 rgba(192, 85, 58, 0.24);
  display: grid;
  place-items: center;
  padding: 0;
  touch-action: none;
}

.speed-mark {
  font-family: var(--display);
  font-weight: 400;
  font-size: clamp(11px, 2vmin, 15px);
  line-height: 1;
  letter-spacing: 0.04em;
}

#boost-button {
  background: var(--gold);
}

#brake-button {
  background: var(--sky);
}

#back-button {
  background: #d8f0c8;
}

.speed-button:active,
.speed-button.pressed {
  transform: translateY(3px);
  box-shadow: 0 1px 0 rgba(35, 37, 43, 0.32), inset 0 4px 0 rgba(255, 255, 255, 0.7);
}

.laser-button {
  background: var(--element, var(--orange));
}

.laser-button .shoot-mark {
  font-size: clamp(10px, 1.8vmin, 14px);
}

.shoot-button {
  width: clamp(58px, 13.6vmin, 86px);
  aspect-ratio: 1;
  border-radius: 50%;
  border: clamp(3px, 0.4vmin, 4px) solid var(--ink);
  background: var(--element, var(--gold));
  color: var(--ink);
  box-shadow:
    0 5px 0 rgba(35, 37, 43, 0.35),
    inset 0 5px 0 rgba(255, 255, 255, 0.42),
    inset 0 -4px 0 rgba(35, 37, 43, 0.18);
  display: grid;
  place-items: center;
  touch-action: none;
  padding: 0;
}

.shoot-mark {
  font-family: var(--display);
  font-weight: 400;
  font-size: clamp(11px, 2.1vmin, 16px);
  line-height: 1;
  letter-spacing: 0.04em;
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.55);
}

.shoot-button:active,
.shoot-button.pressed {
  transform: translateY(4px);
  box-shadow: 0 1px 0 rgba(35, 37, 43, 0.35), inset 0 5px 0 rgba(255, 255, 255, 0.42);
}

/* Compact right-edge rail for short landscape screens. */
@media (max-height: 540px) and (orientation: landscape) {
  :root {
    --rail-top: calc(max(var(--hud-pad), env(safe-area-inset-top)) + clamp(50px, 4.8vw, 62px));
  }

  .power-rail {
    gap: 4px;
    max-width: min(58vw, 190px);
  }

  .level-banner {
    padding: 3px 8px;
    row-gap: 2px;
  }

  .banner-world {
    display: none;
  }

  .banner-tag {
    padding: 2px 6px;
    font-size: 10px;
  }

  .banner-name {
    font-size: 15px;
  }

  .banner-mode {
    padding: 2px 6px;
    font-size: 9px;
  }

  body.transform-ready .mode-badge {
    display: none;
  }

  .mode-badge {
    padding: 1px 8px 1px 3px;
  }

  .mode-badge-label {
    font-size: 8px;
  }

  .mode-badge-name {
    font-size: 9px;
  }

  .power-meter {
    gap: 2px 5px;
    padding: 3px 6px;
  }

  .meter-chip {
    gap: 3px;
    padding: 1px 3px;
  }

  .meter-bar {
    gap: 1px;
    padding: 1px;
  }

  .meter-bar i {
    width: 4px;
    height: 6px;
  }

  .meter-count {
    font-size: 9px;
    min-width: 2em;
  }

  .power-meter img {
    width: 14px;
    height: 14px;
  }

  .transform-prompt {
    padding: 4px 7px 5px;
  }

  .transform-btn {
    padding: 2px 7px 2px 3px;
    font-size: 10px;
  }

  .transform-btn img {
    width: 16px;
    height: 16px;
  }

  .power-toast {
    gap: 5px;
    padding: 2px 10px 2px 2px;
    font-size: 12px;
  }

  .power-toast img {
    width: 20px;
    height: 20px;
  }

  body.transform-ready .power-toast {
    display: none;
  }
}

/* Narrow screens: keep the pickup notice inside the right rail. */
@media (max-width: 420px) {
  .power-toast {
    gap: 6px;
    padding: 3px 9px 3px 3px;
    font-size: 13px;
  }

  .power-toast img {
    width: 22px;
    height: 22px;
  }
}

/* ---------- maths puzzle lock ---------- */

.puzzle-panel {
  width: min(650px, 96vw);
}

.puzzle-pick .panel-sub {
  margin-bottom: 10px;
}

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

.year-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-height: 46px;
  padding: 7px 8px;
  border: 3px solid var(--ink);
  border-radius: 14px;
  background: var(--gold);
  box-shadow: 0 4px 0 rgba(35, 37, 43, 0.28), inset 0 3px 0 rgba(255, 255, 255, 0.55);
  transition: transform 90ms ease-out;
}

.year-btn:active,
.year-btn:focus-visible {
  transform: translateY(3px);
  box-shadow: 0 1px 0 rgba(35, 37, 43, 0.28), inset 0 3px 0 rgba(255, 255, 255, 0.55);
}

.year-name {
  color: var(--ink);
  font-size: clamp(13px, 1.5vw, 16px);
  font-weight: 700;
  line-height: 1;
}

.year-note {
  color: var(--brick);
  font-size: clamp(9px, 1vw, 11px);
  font-weight: 800;
  line-height: 1.15;
}

.puzzle-top {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 8px;
  margin: 1px 0 8px;
}

.puzzle-year {
  padding: 2px 9px;
  border: 2px solid var(--ink);
  border-radius: 999px;
  background: var(--gold);
  font-size: 11px;
  font-weight: 700;
}

.puzzle-dots {
  display: flex;
  gap: 5px;
}

.puzzle-dots i {
  width: 12px;
  height: 12px;
  border: 2px solid var(--ink);
  border-radius: 50%;
  background: rgba(35, 37, 43, 0.14);
}

.puzzle-dots i.on {
  background: var(--grass);
}

.puzzle-progress {
  color: var(--brick);
  font-family: var(--score);
  font-size: 12px;
  font-weight: 700;
}

.puzzle-main {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: clamp(10px, 3vw, 26px);
}

.puzzle-question-col {
  min-width: 0;
}

.puzzle-question {
  margin: 0;
  color: var(--ink);
  font-family: var(--display);
  font-size: clamp(26px, 4.6vw, 42px);
  line-height: 1.12;
}

.puzzle-answer-row {
  margin: 8px 0 0;
}

.puzzle-answer {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 3.2em;
  min-height: 1.45em;
  padding: 0 10px;
  border: 3px dashed rgba(35, 37, 43, 0.35);
  border-radius: 12px;
  background: #fff;
  color: var(--ink);
  font-family: var(--score);
  font-size: clamp(22px, 3vw, 30px);
  font-weight: 700;
}

.puzzle-answer.filled {
  border-style: solid;
  border-color: var(--ink);
}

.puzzle-answer.shake {
  animation: answer-shake 260ms ease-in-out;
}

@keyframes answer-shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-6px); }
  75% { transform: translateX(6px); }
}

.puzzle-feedback {
  min-height: 1.2em;
  margin: 6px 0 0;
  color: var(--brick);
  font-weight: 900;
  font-size: clamp(12px, 1.4vw, 15px);
}

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

.puzzle-feedback.bad {
  color: #D9382F;
}

.puzzle-keypad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  width: clamp(168px, 23vw, 208px);
}

.key-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  height: clamp(33px, 5vh, 43px);
  padding: 0;
  border: 3px solid var(--ink);
  border-radius: 12px;
  background: var(--cream);
  color: var(--ink);
  font-family: var(--score);
  font-size: clamp(15px, 1.9vw, 19px);
  font-weight: 700;
  box-shadow: 0 3px 0 rgba(35, 37, 43, 0.3), inset 0 2px 0 #fff;
}

.key-btn:active {
  transform: translateY(2px);
  box-shadow: 0 1px 0 rgba(35, 37, 43, 0.3), inset 0 2px 0 #fff;
}

.key-tool {
  background: var(--gold);
  font-size: 15px;
}

.key-ok {
  background: var(--grass);
  color: #fff;
  font-family: var(--body);
  font-size: 14px;
  font-weight: 900;
}

.puzzle-hint {
  margin: 8px 0 0;
  color: rgba(35, 37, 43, 0.62);
  font-weight: 800;
  font-size: clamp(9px, 1vw, 12px);
}

@media (max-width: 560px) {
  .year-options {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .puzzle-main {
    grid-template-columns: 1fr;
    gap: 10px;
    justify-items: center;
  }

  .puzzle-question-col {
    text-align: center;
  }

  .puzzle-keypad {
    width: 100%;
    max-width: 290px;
  }

  .key-btn {
    height: 40px;
  }

  .puzzle-hint {
    text-align: center;
  }
}

@media (max-height: 430px) and (orientation: landscape) {
  .puzzle-panel {
    padding: 10px 18px;
  }

  .puzzle-panel .panel-title {
    font-size: 26px;
  }

  .puzzle-panel .panel-eyebrow {
    font-size: 9px;
  }

  .year-btn {
    min-height: 40px;
    padding: 4px 7px;
  }

  .puzzle-top {
    margin-bottom: 5px;
  }

  .puzzle-question {
    font-size: clamp(24px, 4.4vw, 34px);
  }

  .puzzle-answer {
    min-height: 1.35em;
    font-size: 22px;
  }

  .puzzle-feedback {
    margin-top: 3px;
    font-size: 11px;
  }

  .key-btn {
    height: 32px;
  }

  .puzzle-hint {
    display: none;
  }

  .puzzle-play .panel-text-btn {
    margin-top: 4px;
    padding: 2px 8px;
    font-size: 10px;
  }
}

/* ---------- compact mobile hud ---------- */
.level-mode {
  display: none;
}

@media (max-width: 700px), (pointer: coarse) and (max-height: 540px) {
  :root {
    --hud-pad: 6px;
  }

  #hud {
    display: flex;
    align-items: flex-start;
    gap: 4px;
    padding:
      max(5px, env(safe-area-inset-top))
      max(6px, env(safe-area-inset-right))
      0
      max(6px, env(safe-area-inset-left));
  }

  .hud-left {
    order: 1;
    flex: 0 0 auto;
    gap: 4px;
  }

  .hud-right {
    order: 2;
    margin-left: auto;
    gap: 4px;
  }

  .hud-actions {
    order: 3;
    margin-left: 4px;
    gap: 4px;
  }

  .avatar-plate {
    width: 30px;
    border-width: 2px;
    box-shadow: 0 2px 0 rgba(35, 37, 43, 0.28), inset 0 2px 0 rgba(255, 255, 255, 0.3);
  }

  .life-plate {
    width: 64px;
  }

  .life {
    border-width: 1.5px;
    box-shadow: none;
  }

  .score-plate {
    width: 64px;
  }

  .sphere-plate {
    width: 52px;
  }

  .plate-value {
    left: 33%;
    right: 5%;
    font-size: 9.5px;
    text-shadow: none;
  }

  .sphere-plate .plate-value {
    left: 35%;
    right: 6%;
  }

  .hud-actions .cushion {
    width: 34px;
    border-width: 2px;
    box-shadow: 0 2px 0 rgba(35, 37, 43, 0.3), inset 0 3px 0 #fff;
  }

  .cushion img {
    width: 92%;
    height: 92%;
  }

  .help-mark {
    font-size: 14px;
    text-shadow: 0 1px 0 var(--orange-dark);
  }

  .hud-center {
    position: absolute;
    top: calc(max(5px, env(safe-area-inset-top)) + 41px);
    left: max(6px, env(safe-area-inset-left));
    right: auto;
    transform: none;
    flex-direction: column;
    align-items: flex-start;
    gap: 3px;
    max-width: calc(100% - 120px);
  }

  .level-chip {
    display: inline-flex;
    gap: 4px;
    padding: 1px 6px 1px 1px;
    border-width: 2px;
    border-radius: 8px;
    box-shadow: 0 2px 0 rgba(35, 37, 43, 0.22);
  }

  .level-tag {
    padding: 1px 4px;
    border-width: 1.5px;
    border-radius: 5px;
    font-size: 8.5px;
  }

  .level-name {
    max-width: 26vw;
    overflow: hidden;
    text-overflow: ellipsis;
    font-size: 10.5px;
  }

  .level-mode {
    display: inline-block;
    max-width: 30vw;
    padding: 1px 4px;
    border-radius: 5px;
    background: var(--ink);
    color: var(--cream);
    overflow: hidden;
    text-overflow: ellipsis;
    font-size: 8.5px;
    font-weight: 700;
    line-height: 1;
    letter-spacing: 0.03em;
    text-transform: uppercase;
    white-space: nowrap;
  }

  .level-mode::before {
    content: "MODE ";
    opacity: 0.62;
  }

  .boss-bar {
    padding: 2px 6px 3px;
    gap: 2px;
    border-width: 2px;
    border-radius: 8px;
  }

  .boss-name {
    font-size: 8.5px;
  }

  .boss-track {
    width: 84px;
    height: 6px;
    border-width: 1.5px;
  }

  /* The rail's pieces are placed in their own corners so the middle stays clear. */
  .power-rail {
    display: contents;
  }

  #mode-badge {
    display: none;
  }

  #power-meter {
    position: absolute;
    top: calc(max(5px, env(safe-area-inset-top)) + 41px);
    right: max(5px, env(safe-area-inset-right));
    display: grid;
    grid-template-columns: repeat(2, auto);
    gap: 2px 4px;
    padding: 2px 4px;
    border-width: 2px;
    border-radius: 8px;
    background: rgba(255, 243, 214, 0.92);
    box-shadow: 0 2px 0 rgba(35, 37, 43, 0.2);
  }

  .meter-chip {
    gap: 2px;
    padding: 1px 2px;
    border-width: 1px;
    border-radius: 5px;
  }

  .power-meter img {
    width: 11px;
    height: 11px;
  }

  .meter-bar {
    gap: 1px;
    padding: 0;
  }

  .meter-bar i {
    width: 3px;
    height: 4px;
    border-radius: 1px;
  }

  .meter-count {
    font-size: 8px;
    text-align: right;
  }

  #banner {
    position: absolute;
    top: calc(max(5px, env(safe-area-inset-top)) + 41px);
    left: max(6px, env(safe-area-inset-left));
    display: flex;
    flex-wrap: nowrap;
    align-items: center;
    gap: 4px;
    width: auto;
    max-width: 62vw;
    padding: 2px 7px;
    border-width: 2px;
    border-radius: 8px;
    box-shadow: 0 2px 0 rgba(35, 37, 43, 0.22);
  }

  #banner .banner-world {
    display: none;
  }

  .banner-tag {
    padding: 1px 4px;
    border-width: 1.5px;
    border-radius: 5px;
    font-size: 8px;
  }

  .banner-name {
    max-width: 24vw;
    overflow: hidden;
    text-overflow: ellipsis;
    font-size: 10.5px;
  }

  .banner-mode {
    padding: 1px 4px;
    border-width: 1.5px;
    border-radius: 5px;
    font-size: 7.5px;
  }

  #power-toast {
    position: absolute;
    top: calc(max(5px, env(safe-area-inset-top)) + 79px);
    left: max(6px, env(safe-area-inset-left));
    gap: 4px;
    padding: 2px 7px 2px 2px;
    border-width: 2px;
    font-size: 9px;
    box-shadow: 0 2px 0 rgba(35, 37, 43, 0.24);
  }

  .power-toast img {
    width: 14px;
    height: 14px;
  }

  #transform-prompt {
    position: absolute;
    top: calc(max(5px, env(safe-area-inset-top)) + 94px);
    right: max(5px, env(safe-area-inset-right));
    gap: 2px;
    max-width: 52vw;
    padding: 3px 5px 4px;
    border-width: 2px;
    border-radius: 10px;
    box-shadow: 0 3px 0 rgba(35, 37, 43, 0.24);
  }

  .transform-lead {
    font-size: 7px;
  }

  .transform-options {
    gap: 3px;
  }

  .transform-btn {
    gap: 3px;
    padding: 1px 6px 1px 2px;
    border-width: 1.5px;
    font-size: 8px;
  }

  .transform-btn img {
    width: 14px;
    height: 14px;
  }

  .key-hint {
    display: none;
  }
}

@media (max-width: 700px) and (max-height: 540px) and (orientation: landscape),
  (pointer: coarse) and (max-height: 540px) and (orientation: landscape) {
  .hud-center {
    top: calc(max(4px, env(safe-area-inset-top)) + 29px);
  }

  /* Four chips in one row keep the meter below the buttons and above the fly lane. */
  #power-meter {
    top: calc(max(4px, env(safe-area-inset-top)) + 37px);
    display: flex;
    flex-direction: row;
    gap: 2px;
  }

  #banner {
    top: calc(max(4px, env(safe-area-inset-top)) + 29px);
  }

  #power-toast {
    top: calc(max(4px, env(safe-area-inset-top)) + 62px);
  }

  #transform-prompt {
    top: calc(max(4px, env(safe-area-inset-top)) + 62px);
    flex-direction: row;
    align-items: center;
    gap: 4px;
    max-width: 92vw;
    padding: 2px 6px;
  }

  .transform-options {
    flex-wrap: nowrap;
    gap: 3px;
  }

  .transform-lead {
    font-size: 7px;
    white-space: nowrap;
  }
}

@media (max-width: 700px) and (max-width: 340px) {
  .avatar-plate { width: 26px; }

  .life-plate { width: 56px; }
  .score-plate { width: 56px; }
  .sphere-plate { width: 44px; }

  .hud-actions .cushion { width: 30px; }

  .hud-center {
    max-width: calc(100% - 174px);
  }

  .level-chip {
    flex-wrap: wrap;
    row-gap: 1px;
    max-width: 100%;
  }

  .level-name { max-width: 30vw; }
  .level-mode { max-width: 56vw; }
}
