:root {
  color-scheme: dark;
  --bg: #130b08;
  --panel: #24130f;
  --panel-2: #341712;
  --accent: #ff6a00;
  --accent-2: #ffb347;
  --text: #fff2e8;
  --muted: #d2b29e;
  --border: rgba(255, 179, 71, 0.22);
  --shadow: 0 18px 42px rgba(0, 0, 0, 0.35);
  font-family: 'Montserrat', Inter, system-ui, sans-serif;
}

* { box-sizing: border-box; }
html,
body {
  touch-action: manipulation;
}
body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  background:
    radial-gradient(circle at top, rgba(255, 106, 0, 0.15), transparent 30%),
    linear-gradient(180deg, #160a08 0%, #0d0504 100%);
  color: var(--text);
  overflow: hidden;
  position: relative;
}


.opening-splash {
  position: fixed;
  inset: 0;
  z-index: 9999;
  pointer-events: none;
  display: grid;
  place-items: center;
  overflow: hidden;
  background:
    linear-gradient(rgba(18, 8, 6, 0.14), rgba(9, 4, 3, 0.34)),
    url('./assets/froodos_reaper_card.jpeg') center center / contain no-repeat,
    radial-gradient(circle, rgba(255,132,0,.26), transparent 45%),
    rgba(9,4,3,.94);
  animation: splash-fadeout 4s ease forwards;
  transform-origin: center center;
}

.opening-splash::after {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at center, rgba(255, 180, 90, 0.18), transparent 52%);
  animation: splash-pulse 4s ease forwards;
}

.opening-splash-content {
  position: relative;
  z-index: 1;
  text-align: center;
  padding: 24px 18px;
  animation: splash-content-zoom 4s ease forwards;
}

.opening-leaderboard {
  width: min(92vw, 430px);
  margin: 22px auto 0;
  padding: 12px 16px 14px;
  border: 1px solid rgba(255, 179, 71, .35);
  border-radius: 16px;
  background: rgba(28, 11, 7, .72);
  box-shadow: 0 12px 32px rgba(0, 0, 0, .35), inset 0 0 24px rgba(255, 106, 0, .08);
  text-align: left;
}

.opening-leaderboard h2 {
  margin: 0 0 8px;
  color: #ffd166;
  font-family: 'Cinzel', serif;
  font-size: 1rem;
  text-align: center;
  letter-spacing: .14em;
}

.opening-leaderboard ol {
  display: grid;
  gap: 3px;
  max-height: min(34vh, 270px);
  margin: 0;
  padding: 0 4px 0 28px;
  overflow-y: auto;
  color: #ffe9d7;
  font-size: .78rem;
}

.opening-leaderboard li {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 3px 0;
  border-bottom: 1px solid rgba(255, 179, 71, .12);
}

.opening-leaderboard li span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.opening-leaderboard li strong {
  color: #ffd166;
  white-space: nowrap;
}

.opening-splash-kicker {
  margin: 0 0 10px;
  color: #ffcf8b;
  text-transform: uppercase;
  letter-spacing: .24em;
  font-size: .78rem;
  font-weight: 800;
}

.opening-splash-title {
  margin: 0;
  max-width: min(92vw, 900px);
  color: #fff0cc;
  font-family: 'Cinzel', serif;
  font-size: clamp(1.8rem, 4.8vw, 3.8rem);
  line-height: 1.08;
  text-shadow: 0 0 12px rgba(255, 196, 120, 0.35), 0 0 36px rgba(255, 106, 0, 0.28);
}

.opening-splash-hint {
  margin: 16px 0 0;
  color: #ffd7a8;
  font-size: .95rem;
  font-weight: 700;
  letter-spacing: .14em;
  text-transform: uppercase;
  animation: splash-hint-blink 900ms ease-in-out infinite alternate;
}

@keyframes splash-fadeout {
  0% {
    opacity: 1;
    transform: scale(1);
    filter: brightness(1);
  }
  68% {
    opacity: 1;
    transform: scale(1.035);
    filter: brightness(1.06);
  }
  100% {
    opacity: 0;
    visibility: hidden;
    transform: scale(1.08);
    filter: brightness(1.14);
  }
}

@keyframes splash-content-zoom {
  0% {
    opacity: 0;
    transform: scale(.9) translateY(10px);
  }
  18% {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
  68% {
    opacity: 1;
    transform: scale(1.03) translateY(-2px);
  }
  100% {
    opacity: 0;
    transform: scale(1.08) translateY(-8px);
  }
}

@keyframes splash-pulse {
  0%, 100% { opacity: .7; }
  50% { opacity: 1; }
}

@keyframes splash-hint-blink {
  from { opacity: .55; }
  to { opacity: 1; }
}

.page-shell {
  width: min(1220px, calc(100vw - 24px));
  margin: 0 auto;
  padding: 12px 0 16px;
  min-height: 100vh;
  position: relative;
  z-index: 1;
}

.floating-chili {
  position: fixed;
  z-index: 0;
  opacity: .14;
  pointer-events: none;
  filter: drop-shadow(0 18px 40px rgba(255,106,0,.28));
  animation: float-bob 7s ease-in-out infinite;
}

.floating-chili-left {
  width: 180px;
  left: 2vw;
  top: 12vh;
  transform: rotate(-18deg);
}

.floating-chili-right {
  width: 220px;
  right: 1vw;
  bottom: 8vh;
  transform: rotate(14deg);
  animation-duration: 9s;
}

@keyframes float-bob {
  0%, 100% { transform: translateY(0) rotate(-18deg); }
  50% { transform: translateY(-18px) rotate(-12deg); }
}

.game-header,
.hud-card,
.canvas-panel {
  background: linear-gradient(180deg, rgba(52, 23, 18, 0.95), rgba(26, 11, 9, 0.95));
  border: 1px solid var(--border);
  border-radius: 20px;
  box-shadow: var(--shadow);
}

.game-header {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 18px;
  margin-bottom: 12px;
  align-items: center;
}

.eyebrow, .build-version {
  margin: 0;
  color: var(--accent-2);
  font-weight: 700;
  letter-spacing: .16em;
  text-transform: uppercase;
  font-size: .76rem;
}

.build-version { margin-top: 8px; font-size: .74rem; }

h1, h2 {
  margin: 0;
  font-family: 'Cinzel', serif;
  color: #ffe7be;
  text-shadow: 0 2px 10px rgba(0,0,0,.35);
}

h1 { font-size: clamp(1.4rem, 2.6vw, 2.4rem); }
h2 { font-size: 1.1rem; margin-bottom: 10px; }

.header-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.hud-button {
  border: 1px solid #ffb36b;
  background: linear-gradient(180deg, #a34724, #6b2410);
  color: #fff4de;
  border-radius: 12px;
  padding: 10px 14px;
  font-weight: 800;
  cursor: pointer;
}

.hud-button:disabled {
  opacity: .68;
  cursor: wait;
}

.game-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(280px, 360px);
  gap: 14px;
  align-items: start;
  min-height: 0;
}

.canvas-panel {
  position: relative;
  padding: 12px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  gap: 10px;
  min-height: 0;
  isolation: isolate;
  touch-action: manipulation;
}

.canvas-panel::before {
  content: '';
  position: absolute;
  left: 50%;
  top: 50%;
  width: calc(100% - 24px);
  height: calc(100% - 24px);
  transform: translate(-50%, -50%);
  background: url('./assets/froodos_reaper_card.jpeg') center center / contain no-repeat;
  opacity: .56;
  filter: saturate(1.08) brightness(1.14) contrast(1.16);
  pointer-events: none;
  z-index: 0;
}

#gameCanvas {
  display: block;
  position: relative;
  z-index: 2;
  background: transparent;
  border-radius: 16px;
  width: auto;
  max-width: 100%;
  height: min(100%, calc(100dvh - 240px));
  max-height: calc(100dvh - 240px);
  aspect-ratio: 1 / 2;
  box-shadow: inset 0 0 30px rgba(255,120,40,.08), 0 24px 50px rgba(0,0,0,.34);
  touch-action: auto;
}

.sidebar {
  display: grid;
  gap: 14px;
  align-content: start;
  min-height: 0;
}

@media (min-width: 981px) {
  .page-shell {
    height: 100vh;
    height: 100dvh;
    min-height: 0;
    display: flex;
    flex-direction: column;
  }

  .game-header {
    flex: 0 0 auto;
  }

  .game-layout {
    flex: 1 1 auto;
    height: auto;
    min-height: 0;
    align-items: stretch;
  }

  .canvas-panel {
    height: 100%;
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto minmax(0, 1fr);
    justify-items: center;
    align-items: center;
  }

  #gameCanvas {
    grid-column: 1;
    justify-self: center;
    width: auto;
    height: 100%;
    max-width: 100%;
    max-height: 100%;
    min-height: 0;
  }

  .sidebar {
    height: 100%;
    overflow-y: auto;
    overscroll-behavior: contain;
    padding-right: 3px;
    scrollbar-width: thin;
    scrollbar-color: rgba(255, 179, 71, 0.46) rgba(0, 0, 0, 0.16);
  }

  .sidebar::-webkit-scrollbar {
    width: 8px;
  }

  .sidebar::-webkit-scrollbar-thumb {
    border-radius: 999px;
    background: rgba(255, 179, 71, 0.46);
  }

  .sidebar::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.16);
  }
}

@media (min-width: 981px) and (max-height: 800px) {
  .page-shell {
    padding: 6px 0 8px;
  }

  .game-header {
    gap: 10px;
    padding: 8px 12px;
    margin-bottom: 7px;
    border-radius: 15px;
  }

  .eyebrow {
    font-size: .58rem;
  }

  .build-version {
    margin-top: 3px;
    font-size: .56rem;
  }

  h1 {
    font-size: clamp(1rem, 2vw, 1.65rem);
    line-height: 1.08;
  }

  .header-actions {
    gap: 6px;
  }

  .hud-button {
    padding: 7px 10px;
    border-radius: 9px;
    font-size: .72rem;
  }

  .game-layout,
  .sidebar {
    gap: 8px;
  }

  .canvas-panel {
    gap: 6px;
    padding: 7px;
    border-radius: 15px;
  }

  .canvas-panel::before {
    width: calc(100% - 14px);
    height: calc(100% - 14px);
  }

  .level-banner {
    min-width: min(240px, 100%);
    padding: 6px 16px 7px;
  }

  .level-banner-kicker {
    font-size: .56rem;
  }

  .level-banner-name {
    font-size: clamp(1rem, 2vw, 1.35rem);
  }

  .hud-card {
    padding: 9px;
    border-radius: 14px;
  }

  .hud-card h2 {
    margin-bottom: 6px;
    font-size: .86rem;
  }

  .hud-stats {
    gap: 5px;
  }

  .hud-stats li {
    padding: 6px 8px;
    border-radius: 9px;
    font-size: .72rem;
  }

  .mini-boards {
    gap: 8px;
  }

  .mini-boards canvas {
    max-height: 96px;
  }
}

.mobile-controls {
  display: none;
  gap: 12px;
  touch-action: manipulation;
}

html:not(.is-mobile-controls) .mobile-controls {
  display: none !important;
}

html.is-mobile-controls .mobile-controls {
  display: grid;
}

html.is-mobile-controls .canvas-panel,
html.is-mobile-controls .mobile-controls {
  touch-action: none;
  overscroll-behavior: none;
}

.mobile-dpad,
.mobile-actions {
  display: grid;
  gap: 10px;
}

.mobile-dpad {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.mobile-actions {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.mobile-control {
  border: 1px solid #ffb36b;
  background: linear-gradient(180deg, #a34724, #6b2410);
  color: #fff4de;
  border-radius: 14px;
  padding: 14px 10px;
  font-weight: 800;
  font-size: 1rem;
  min-height: 54px;
  touch-action: manipulation;
  user-select: none;
}

.mobile-control:active {
  transform: scale(.98);
  filter: brightness(1.08);
}

.hud-card { padding: 14px; }

.hud-stats {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 10px;
}

.hud-stats li {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  border-radius: 12px;
  background: rgba(255,255,255,.03);
  border: 1px solid rgba(255,179,71,.12);
}

.hud-stats span { color: var(--muted); }

.hud-stats strong {
  text-align: right;
  max-width: 56%;
}

.hud-meter-row {
  align-items: center;
}

.hud-meter {
  width: 56%;
  height: 12px;
  border-radius: 999px;
  overflow: hidden;
  background: rgba(0, 0, 0, 0.28);
  border: 1px solid rgba(255, 179, 71, 0.18);
}

.hud-meter-fill {
  width: 0%;
  height: 100%;
  border-radius: 999px;
  transition: width 180ms ease;
}

.hud-meter-fill.heat {
  background: linear-gradient(90deg, #ff8a4d, #ff3b1d);
  box-shadow: 0 0 14px rgba(255, 70, 20, 0.45);
}

.hud-meter-fill.sauce {
  background: linear-gradient(90deg, #ffd166, #ff8c32);
  box-shadow: 0 0 14px rgba(255, 160, 40, 0.35);
}

.mini-boards {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

.mini-boards canvas {
  border: 1px solid rgba(255,179,71,.12);
  width: 100%;
  height: auto;
  max-height: 140px;
}

.level-banner {
  position: relative;
  top: auto;
  left: auto;
  transform: none;
  z-index: 4;
  min-width: min(300px, 100%);
  width: fit-content;
  max-width: calc(100% - 8px);
  text-align: center;
  padding: 12px 24px 14px;
  border-radius: 999px;
  background: linear-gradient(180deg, rgba(74, 38, 14, 0.42), rgba(26, 10, 6, 0.82));
  border: 1px solid rgba(255, 214, 120, 0.32);
  box-shadow: 0 0 32px rgba(255,120,40,.18);
  overflow: hidden;
}

.level-banner::after {
  content: '';
  position: absolute;
  inset: -25% 12%;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,.16), transparent);
  transform: translateX(-140%) rotate(8deg);
  animation: banner-sheen 4s linear infinite;
}

.level-banner-kicker {
  display: block;
  font-size: .72rem;
  letter-spacing: .28em;
  color: #ffd78c;
  font-weight: 800;
}

.level-banner-name {
  display: block;
  font-family: 'Cinzel', serif;
  font-size: clamp(1.2rem, 2.6vw, 2rem);
  color: #ffb347;
  text-shadow: 0 0 10px currentColor, 0 0 28px color-mix(in srgb, currentColor 45%, transparent);
}

.level-banner.level-flash {
  animation: banner-burst 900ms ease;
}

.level-banner.level-banner-final {
  background: linear-gradient(180deg, rgba(28, 10, 8, 0.92), rgba(18, 6, 5, 0.96));
  border-color: rgba(255, 214, 120, 0.5);
  backdrop-filter: blur(6px);
}

.level-banner.level-banner-final .level-banner-kicker {
  color: #ffd78c;
  text-shadow: 0 1px 8px rgba(0,0,0,0.65);
}

.level-banner.level-banner-final .level-banner-name {
  color: #ffe7be;
}

.level-banner.level-banner-incoming {
  background: linear-gradient(180deg, rgba(88, 28, 12, 0.92), rgba(42, 12, 8, 0.96));
  border-color: rgba(255, 176, 94, 0.62);
  box-shadow: 0 0 32px rgba(255, 116, 40, 0.3);
}

.level-banner.level-banner-incoming .level-banner-kicker {
  color: #ffd48d;
}

.level-banner.level-banner-incoming .level-banner-name {
  color: #fff3d4;
}

.level-banner.level-banner-incoming.incoming-mild {
  background: linear-gradient(180deg, rgba(84, 42, 18, 0.9), rgba(44, 20, 10, 0.95));
}

.level-banner.level-banner-incoming.incoming-warm {
  background: linear-gradient(180deg, rgba(130, 44, 12, 0.95), rgba(72, 20, 8, 0.98));
  box-shadow: 0 0 38px rgba(255, 133, 39, 0.38);
}

.level-banner.level-banner-incoming.incoming-hot {
  background: linear-gradient(180deg, rgba(122, 18, 18, 0.96), rgba(64, 8, 8, 0.99));
  border-color: rgba(255, 120, 90, 0.72);
  box-shadow: 0 0 42px rgba(255, 72, 30, 0.42);
}

.level-banner.level-banner-incoming.incoming-extreme {
  background: linear-gradient(180deg, rgba(18, 18, 18, 0.94), rgba(70, 8, 8, 0.99));
  border-color: rgba(255, 210, 140, 0.82);
  box-shadow: 0 0 20px rgba(255,255,255,0.18), 0 0 54px rgba(255, 44, 20, 0.5);
  animation: incoming-extreme-pulse 220ms ease-in-out 4 alternate;
}

.level-banner.level-banner-incoming.incoming-extreme .level-banner-kicker {
  color: #fff0c4;
  letter-spacing: .34em;
}

.level-banner.level-banner-incoming.incoming-extreme .level-banner-name {
  color: #fff8ea;
  text-shadow: 0 2px 12px rgba(0,0,0,0.88), 0 0 22px rgba(255,110,70,0.4);
}

@keyframes incoming-extreme-pulse {
  from { transform: scale(1); }
  to { transform: scale(1.035); }
}

@keyframes banner-sheen {
  from { transform: translateX(-140%) rotate(8deg); }
  to { transform: translateX(140%) rotate(8deg); }
}

@keyframes banner-burst {
  0% { transform: scale(.9); filter: brightness(1.4); }
  35% { transform: scale(1.08); filter: brightness(1.9); }
  100% { transform: scale(1); filter: brightness(1); }
}

.effect-text {
  position: absolute;
  z-index: 3;
  inset: 42% 0 auto;
  z-index: 8;
  text-align: center;
  font-family: 'Cinzel', serif;
  font-size: clamp(1.8rem, 4vw, 3.6rem);
  font-weight: 800;
  letter-spacing: .1em;
  color: #ffd166;
  text-shadow: 0 0 12px rgba(255,209,102,.75), 0 0 30px rgba(255,106,0,.45);
  opacity: 0;
  transform: translateY(10px) scale(.94);
  pointer-events: none;
}

.effect-text.show {
  animation: effect-pop 850ms ease forwards;
}

@keyframes effect-pop {
  0% { opacity: 0; transform: translateY(18px) scale(.9); }
  18% { opacity: 1; transform: translateY(0) scale(1.06); }
  72% { opacity: 1; transform: translateY(-4px) scale(1); }
  100% { opacity: 0; transform: translateY(-18px) scale(1.03); }
}

.line-flash {
  position: absolute;
  left: 16px;
  right: 16px;
  height: 48px;
  z-index: 6;
  border-radius: 14px;
  background: linear-gradient(90deg, rgba(255,106,0,0), rgba(255,209,102,.55), rgba(255,106,0,0));
  box-shadow: 0 0 20px rgba(255,132,0,.32);
  opacity: 0;
  pointer-events: none;
}

.line-flash.show {
  animation: line-flash 420ms ease forwards;
}

@keyframes line-flash {
  0% { opacity: 0; transform: scaleX(.8); }
  25% { opacity: 1; transform: scaleX(1); }
  100% { opacity: 0; transform: scaleX(1.02); }
}

.screen-overlay {
  position: absolute;
  inset: 16px;
  z-index: 3;
  display: none;
  place-items: center;
  text-align: center;
  background: rgba(10, 4, 3, 0.66);
  border-radius: 16px;
  padding: 24px;
}

.screen-overlay.visible { display: grid; }

.overlay-card h3 {
  margin: 0 0 10px;
  font-family: 'Cinzel', serif;
  color: #ffe7be;
  font-size: 1.6rem;
}

.overlay-card p { margin: 6px 0; color: var(--muted); }

.leaderboard-overlay h2 {
  margin-bottom: 10px;
}

.leaderboard-block {
  margin-top: 16px;
  padding: 14px;
  border-radius: 16px;
  background: rgba(255,255,255,.04);
  border: 1px solid rgba(255,179,71,.16);
}

.leaderboard-list {
  margin: 0;
  padding-left: 22px;
  display: grid;
  gap: 10px;
}

.leaderboard-list li {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  color: #fff1dc;
}

.leaderboard-list li span {
  color: var(--muted);
}

.leaderboard-list li strong {
  color: #ffd166;
  white-space: nowrap;
}

.leaderboard-list.compact {
  padding-left: 18px;
  gap: 8px;
}

.leaderboard-form {
  margin-top: 16px;
  display: grid;
  gap: 10px;
}

.leaderboard-form label {
  color: #ffe7be;
  font-weight: 700;
}

.leaderboard-form input {
  width: 100%;
  border-radius: 12px;
  border: 1px solid rgba(255,179,71,.28);
  background: rgba(255,247,242,.96);
  color: #2a120f;
  padding: 12px 14px;
  font: inherit;
}

.leaderboard-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
}

.leaderboard-note {
  margin-top: 14px;
}

.leaderboard-note.success {
  color: #ffd166;
}

@media (max-width: 980px) and (hover: none) and (pointer: coarse) {
  body { overflow: hidden; }
  .game-layout { grid-template-columns: 1fr; height: auto; }
  .canvas-panel { min-height: auto; }
  #gameCanvas {
    width: min(100%, 340px);
    max-width: 340px;
    height: auto;
    max-height: 62vh;
  }
  .mobile-controls { display: grid; }
  .mini-boards { grid-template-columns: 1fr 1fr; }
}

@media (min-width: 641px) and (max-width: 980px) and (hover: none) and (pointer: coarse) {
  .page-shell {
    width: min(100vw, calc(100vw - 18px));
    padding: 10px 0 14px;
  }

  .game-header {
    padding: 10px 12px;
    gap: 10px;
    margin-bottom: 10px;
  }

  h1 {
    font-size: clamp(1rem, 2.8vw, 1.4rem);
    line-height: 1.08;
  }

  .canvas-panel {
    padding: 8px;
    gap: 8px;
  }

  .level-banner {
    min-width: 0;
    max-width: calc(100% - 8px);
    padding: 10px 16px 12px;
  }

  .mobile-control {
    min-height: 48px;
    padding: 11px 8px;
    font-size: .9rem;
  }

  .hud-card {
    padding: 12px;
  }

  .mini-boards canvas {
    max-height: 110px;
  }
}

@media (max-width: 640px) and (hover: none) and (pointer: coarse) {
  html,
  body { overscroll-behavior: none; }
  body { overflow: hidden; }
  .page-shell {
    width: 100vw;
    padding: max(18px, env(safe-area-inset-top, 0px)) 4px calc(10px + env(safe-area-inset-bottom, 0px));
    height: 100svh;
    min-height: 100svh;
    overflow: hidden;
  }
  .floating-chili { display: none; }
  .game-header {
    padding: 6px 8px;
    gap: 4px;
    margin-bottom: 6px;
    align-items: stretch;
    flex-direction: column;
  }
  .game-header > div:first-child {
    min-width: 0;
    flex: 1 1 auto;
  }
  .eyebrow {
    font-size: .5rem;
    letter-spacing: .05em;
    margin-bottom: 2px;
  }
  .build-version {
    font-size: .48rem;
    letter-spacing: .04em;
    margin-top: 2px;
  }
  h1 {
    font-size: clamp(.74rem, 3.2vw, .9rem);
    line-height: 1.02;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .header-actions {
    width: 100%;
    gap: 4px;
    flex-wrap: nowrap;
    flex: 0 0 auto;
  }
  .hud-button {
    flex: 1 1 25%;
    padding: 6px 4px;
    font-size: .62rem;
    min-width: 0;
  }
  .game-layout {
    grid-template-columns: minmax(0, 1fr) 124px;
    gap: 6px;
    align-items: start;
  }
  .canvas-panel {
    grid-column: 1;
    grid-row: 1;
    padding: 4px;
    gap: 4px;
    touch-action: none;
    overscroll-behavior: none;
  }
  #gameCanvas {
    width: min(calc(100vw - 148px), calc((100svh - 232px) / 2));
    max-width: none;
    height: auto;
    max-height: calc(100svh - 232px);
    touch-action: none;
    -webkit-user-select: none;
    user-select: none;
  }
  .level-banner {
    min-width: 0;
    padding: 6px 10px 8px;
    max-width: calc(100% - 2px);
  }
  .level-banner-kicker {
    font-size: .52rem;
    letter-spacing: .14em;
  }
  .level-banner-name {
    font-size: clamp(.8rem, 3.6vw, 1rem);
  }
  .sidebar {
    grid-column: 2;
    grid-row: 1;
    gap: 6px;
    align-content: start;
    align-self: start;
    position: sticky;
    top: max(8px, env(safe-area-inset-top, 0px));
    max-height: calc(100svh - 16px - env(safe-area-inset-top, 0px));
    overflow-y: auto;
    overflow-x: hidden;
    overscroll-behavior: contain;
    scrollbar-width: thin;
    -webkit-overflow-scrolling: touch;
    touch-action: pan-y;
  }
  .sidebar .hud-card:nth-of-type(n + 3) {
    display: none;
  }
  .hud-card {
    padding: 8px 9px;
    border-radius: 14px;
  }
  .hud-card h2 {
    font-size: .8rem;
    margin-bottom: 6px;
  }
  .hud-stats {
    gap: 5px;
  }
  .hud-stats li {
    display: grid;
    grid-template-columns: 1fr;
    gap: 4px;
    padding: 7px 8px;
    font-size: .62rem;
  }
  .hud-stats span {
    font-size: .58rem;
    line-height: 1.12;
  }
  .hud-stats strong {
    max-width: none;
    text-align: left;
    font-size: .76rem;
    line-height: 1.22;
    word-break: break-word;
    overflow-wrap: anywhere;
  }
  .hud-meter-row {
    align-items: stretch;
  }
  .hud-meter {
    width: 100%;
    height: 10px;
  }
  .mini-boards {
    grid-template-columns: 1fr;
    gap: 6px;
  }
  .mini-boards canvas {
    max-height: 64px;
  }
  .mobile-controls {
    position: fixed;
    left: 4px;
    right: 4px;
    bottom: 0;
    width: calc(100vw - 8px);
    gap: 6px;
    z-index: 10;
    padding: 6px 0 calc(2px + env(safe-area-inset-bottom, 0px));
    background: linear-gradient(180deg, rgba(13,5,4,0), rgba(13,5,4,0.92) 22%, rgba(13,5,4,0.98) 100%);
  }
  .mobile-dpad,
  .mobile-actions {
    gap: 6px;
  }
  .mobile-control {
    min-height: 48px;
    padding: 8px 4px;
    font-size: .72rem;
    border-radius: 10px;
    touch-action: none;
    -webkit-tap-highlight-color: transparent;
  }
}

@media (max-width: 430px) and (hover: none) and (pointer: coarse) {
  .eyebrow,
  .build-version {
    display: none;
  }

  .game-layout {
    grid-template-columns: minmax(0, 1fr) 110px;
  }

  #gameCanvas {
    width: min(calc(100vw - 128px), calc((100svh - 216px) / 2));
    max-height: calc(100svh - 216px);
    touch-action: none;
  }

  .level-banner {
    padding: 5px 8px 7px;
  }

  .hud-card {
    padding: 7px 8px;
  }

  .hud-card h2 {
    font-size: .74rem;
  }

  .hud-stats li {
    padding: 5px 6px;
    font-size: .58rem;
  }

  .hud-stats span {
    font-size: .54rem;
  }

  .hud-stats strong {
    font-size: .68rem;
    line-height: 1.18;
  }

  .mini-boards canvas {
    max-height: 56px;
  }

  .mobile-control {
    min-height: 48px;
    font-size: .68rem;
    padding: 7px 3px;
  }
}
