:root {
  --bg-color: #0f0b14;
  --primary: #9d3bff;
  --secondary: #ff3c6e;
  --accent: #00ffc8;
  --text: #ffffff;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  padding: 0;
  width: 100vw;
  height: 100vh;
  background: var(--bg-color);
  font-family: "Courier New", Courier, monospace;
  overflow: hidden;
  color: var(--text);
}

#game-container {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: #000;
}

/* Mobile browsers resolve 100vh against the URL-bar-retracted viewport, so the
   fixed shell overhangs the visible area on first load and the touch controls
   fall off the bottom. dvh tracks the visible viewport natively; older engines
   get --app-height, which main.js measures from visualViewport. */
@supports (height: 100dvh) {
  body,
  #game-container {
    height: 100dvh;
  }
}

@supports not (height: 100dvh) {
  body,
  #game-container {
    height: var(--app-height, 100vh);
  }
}

canvas {
  width: 100%;
  height: 100%;
  image-rendering: auto;
}

#ui {
  position: absolute;
  inset: 0;
  width: 100%;
  pointer-events: none;
  z-index: 6;
}

#hud-top {
  position: absolute;
  inset: 0;
  display: block;
}

.health-panel {
  position: absolute;
  left: max(18px, calc((100vw - min(100vw, 177.778vh)) / 2 + 22px));
  bottom: max(48px, calc(env(safe-area-inset-bottom) + 48px));
  width: clamp(286px, 23vw, 380px);
  min-height: 92px;
  padding: 0;
}

#health-panel-p2 {
  right: max(18px, calc((100vw - min(100vw, 177.778vh)) / 2 + 22px));
  left: auto;
}

.health-panel.hidden {
  display: none;
}

.health-label {
  position: absolute;
  left: 24.4%;
  top: 18px;
  z-index: 3;
  font-size: 9px;
  letter-spacing: 1.4px;
  text-transform: uppercase;
  color: #a6ffe9;
  text-shadow: 0 0 9px rgba(0, 255, 232, 0.62);
}

.health-bar-shell {
  position: relative;
  width: 100%;
  aspect-ratio: 1841 / 465;
  overflow: visible;
  background: transparent;
  border: 0;
  filter: drop-shadow(0 0 16px rgba(0, 246, 255, 0.2)) drop-shadow(0 0 18px rgba(255, 52, 214, 0.16));
}

.health-bar-fill {
  position: absolute;
  left: 20.2%;
  top: 46.2%;
  width: 57.2%;
  height: 23.3%;
  border-radius: 4px;
  background:
    repeating-linear-gradient(90deg, rgba(255, 255, 255, 0.3) 0 3px, transparent 3px 14px),
    linear-gradient(90deg, #49ff9a 0%, #24ffd7 48%, #fe4df3 100%);
  box-shadow:
    inset 0 0 10px rgba(255, 255, 255, 0.34),
    0 0 14px rgba(40, 255, 222, 0.52),
    0 0 18px rgba(255, 58, 218, 0.36);
  clip-path: polygon(0 50%, 3.8% 0, 96.2% 0, 100% 50%, 96.2% 100%, 3.8% 100%);
  transform: scaleX(1);
  transform-origin: left center;
  transition: transform 120ms linear;
  z-index: 1;
}

.health-bar-frame {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  object-position: center center;
  pointer-events: none;
  image-rendering: pixelated;
  z-index: 2;
}

.health-value {
  position: absolute;
  left: 25%;
  top: 74%;
  z-index: 3;
  margin-top: 0;
  font-size: 10px;
  color: #defff8;
  letter-spacing: 0.6px;
  text-shadow: 0 0 7px rgba(0, 246, 255, 0.46);
}

.lives-value {
  position: absolute;
  left: 25%;
  top: 88%;
  z-index: 3;
  margin-top: 0;
  font-size: 10px;
  color: #ffd97b;
  text-shadow: 0 0 8px rgba(255, 174, 66, 0.35);
}

#timer {
  position: absolute;
  right: max(18px, calc((100vw - min(100vw, 177.778vh)) / 2 + 22px));
  top: auto;
  bottom: max(48px, calc(env(safe-area-inset-bottom) + 48px));
  min-width: 72px;
  text-align: center;
  padding: 9px 10px 8px;
  border-radius: 8px;
  border: 1px solid rgba(255, 92, 196, 0.42);
  background: linear-gradient(180deg, rgba(28, 9, 44, 0.88), rgba(12, 6, 20, 0.75));
  color: #ffd4f2;
  font-size: 18px;
  line-height: 1;
  text-shadow: 0 0 8px rgba(255, 92, 196, 0.45);
}

body.is-flight-level #ui {
  top: 14px;
  right: 0;
  bottom: auto;
  left: 0;
  width: min(92vw, 980px);
  height: auto;
  margin: 0 auto;
}

body.is-flight-level #hud-top {
  position: relative;
  inset: auto;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  height: auto;
}

body.is-flight-level .health-panel {
  position: relative;
  left: auto;
  right: auto;
  bottom: auto;
  width: clamp(300px, 38vw, 460px);
  min-height: 132px;
}

body.is-flight-level .health-label {
  top: 24px;
  font-size: 11px;
}

body.is-flight-level .health-value,
body.is-flight-level .lives-value {
  font-size: 12px;
}

#health-panel-p2 .health-bar-fill {
  background:
    repeating-linear-gradient(90deg, rgba(255, 255, 255, 0.3) 0 3px, transparent 3px 14px),
    linear-gradient(90deg, #ff73dc 0%, #b760ff 48%, #55d8ff 100%);
  box-shadow:
    inset 0 0 10px rgba(255, 255, 255, 0.34),
    0 0 14px rgba(255, 70, 220, 0.52),
    0 0 18px rgba(82, 206, 255, 0.36);
}

body.is-coop-active #timer {
  top: 14px;
  bottom: auto;
}

body.is-coop-active:not(.is-flight-level) #riff-meter-panel {
  bottom: max(156px, calc(env(safe-area-inset-bottom) + 156px));
}

body.is-flight-level #timer {
  right: 0;
  top: 0;
  bottom: auto;
  min-width: 86px;
  padding: 12px 12px 11px;
  font-size: 22px;
}

body.is-flight-level #status {
  position: static;
  width: auto;
  margin-top: 8px;
  margin-left: 12px;
  font-size: 13px;
  line-height: normal;
}

#loading {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 24px;
  text-transform: uppercase;
  letter-spacing: 2px;
  text-shadow: 0 0 10px var(--accent);
  display: flex;
}

#status {
  position: absolute;
  left: max(18px, calc((100vw - min(100vw, 177.778vh)) / 2 + 22px));
  bottom: max(144px, calc(env(safe-area-inset-bottom) + 144px));
  width: clamp(286px, 23vw, 380px);
  margin: 0;
  font-size: 11px;
  line-height: 1.2;
  color: #d5fffa;
  white-space: normal;
}

#status {
  color: var(--accent);
  text-shadow: 0 0 6px rgba(0, 255, 200, 0.45);
}

#editor-toggle {
  margin-top: 8px;
  margin-left: 12px;
  border: 1px solid rgba(114, 208, 255, 0.56);
  background: linear-gradient(180deg, rgba(10, 14, 24, 0.92), rgba(7, 10, 17, 0.82));
  color: #d7f3ff;
  font-size: 11px;
  letter-spacing: 0.7px;
  text-transform: uppercase;
  padding: 7px 10px;
  border-radius: 5px;
  cursor: pointer;
  pointer-events: auto;
}

#editor-toggle,
#editor-panel {
  display: none !important;
}

#editor-panel {
  margin-top: 8px;
  margin-left: 12px;
  width: min(92vw, 360px);
  padding: 10px 10px 12px;
  border-radius: 8px;
  border: 1px solid rgba(124, 212, 255, 0.45);
  background: linear-gradient(180deg, rgba(8, 13, 20, 0.92), rgba(5, 8, 13, 0.8));
  box-shadow: 0 0 16px rgba(96, 174, 255, 0.22);
  pointer-events: auto;
}

#editor-panel.hidden {
  display: none;
}

.editor-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 11px;
  color: #c9ebff;
  margin-top: 7px;
  letter-spacing: 0.4px;
}

#editor-panel input[type='range'] {
  width: 100%;
  margin-top: 4px;
  accent-color: #63d0ff;
}

#editor-reset {
  margin-top: 10px;
  width: 100%;
  border: 1px solid rgba(255, 162, 132, 0.5);
  border-radius: 4px;
  background: linear-gradient(180deg, rgba(31, 15, 10, 0.9), rgba(20, 10, 8, 0.84));
  color: #ffd6c4;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  padding: 7px 8px;
  cursor: pointer;
  pointer-events: auto;
}

#boss-panel {
  /* Fixed, not absolute: #ui collapses to content height under 720px, so an
     absolute bottom would resolve against the top HUD rather than the screen. */
  position: fixed;
  left: 50%;
  bottom: max(72px, calc(env(safe-area-inset-bottom) + 72px));
  width: min(72vw, 520px);
  padding: 6px 10px 8px;
  margin: 0;
  transform: translateX(-50%);
  border-radius: 6px;
  border: 1px solid rgba(255, 132, 112, 0.46);
  background: linear-gradient(180deg, rgba(20, 8, 12, 0.86), rgba(6, 4, 7, 0.7));
  box-shadow: 0 0 18px rgba(255, 92, 83, 0.2);
  opacity: 1;
  visibility: visible;
  transition:
    opacity 260ms ease,
    transform 260ms ease,
    visibility 260ms ease;
  z-index: 10;
}

#boss-panel.hidden {
  opacity: 0;
  visibility: hidden;
  transform: translateX(-50%) translateY(12px);
}

#boss-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 6px;
}

#boss-name {
  font-size: 11px;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: #ffd1be;
}

#boss-health {
  font-size: 11px;
  color: #ffc7a8;
}

#boss-bar-shell {
  position: relative;
  height: 12px;
  border-radius: 4px;
  overflow: hidden;
  background: rgba(16, 7, 9, 0.92);
  border: 1px solid rgba(255, 132, 112, 0.4);
}

#boss-bar-fill {
  position: absolute;
  inset: 2px auto 2px 2px;
  width: calc(100% - 4px);
  border-radius: 4px;
  background: linear-gradient(90deg, #ff8e64, #ff495f 56%, #b91f47 100%);
  box-shadow: inset 0 0 8px rgba(255, 235, 214, 0.26), 0 0 9px rgba(255, 86, 86, 0.35);
  transition: width 320ms ease-out;
}

#boss-telegraph {
  position: fixed;
  left: 50%;
  bottom: max(104px, calc(env(safe-area-inset-bottom) + 104px));
  margin: 0;
  transform: translateX(-50%);
  z-index: 11;
  font-size: 12px;
  letter-spacing: 0.9px;
  color: #ffd68a;
  text-shadow: 0 0 8px rgba(255, 189, 89, 0.5);
}

#boss-telegraph.hidden {
  display: none;
}

#riff-meter-panel {
  position: fixed;
  right: max(18px, calc((100vw - min(100vw, 177.778vh)) / 2 + 22px));
  top: auto;
  bottom: max(96px, calc(env(safe-area-inset-bottom) + 96px));
  z-index: 9;
  width: 134px;
  padding: 7px 9px 8px;
  border: 1px solid rgba(0, 255, 200, 0.48);
  border-radius: 4px;
  background: linear-gradient(180deg, rgba(13, 8, 28, 0.82), rgba(4, 4, 12, 0.76));
  box-shadow: 0 0 16px rgba(0, 255, 200, 0.16), inset 0 0 14px rgba(255, 68, 220, 0.08);
  pointer-events: none;
}

#riff-meter-label {
  font-size: 10px;
  letter-spacing: 1.2px;
  text-transform: uppercase;
  color: #bafff2;
  text-shadow: 0 0 8px rgba(0, 255, 200, 0.54);
}

#riff-meter-shell {
  position: relative;
  height: 9px;
  margin-top: 5px;
  overflow: hidden;
  border: 1px solid rgba(255, 92, 218, 0.48);
  border-radius: 2px;
  background: rgba(4, 2, 12, 0.86);
}

#riff-meter-fill {
  width: 100%;
  height: 100%;
  transform: scaleX(0);
  transform-origin: left center;
  transition: transform 130ms linear;
  background:
    repeating-linear-gradient(90deg, rgba(255, 255, 255, 0.28) 0 2px, transparent 2px 9px),
    linear-gradient(90deg, #00ffc8, #6df6ff 48%, #ff4ee2);
  box-shadow: 0 0 12px rgba(0, 255, 200, 0.48);
}

#riff-meter-value {
  margin-top: 4px;
  font-size: 10px;
  color: #fff3ff;
  text-align: right;
}

body.is-flight-level #riff-meter-panel {
  right: max(20px, env(safe-area-inset-right));
  top: max(86px, calc(env(safe-area-inset-top) + 86px));
  bottom: auto;
  width: 150px;
  padding: 8px 10px 9px;
}

body.is-flight-level #riff-meter-label {
  font-size: 11px;
}

body.is-flight-level #riff-meter-shell {
  height: 11px;
}

body.is-flight-level #riff-meter-value {
  font-size: 11px;
}

#pause-menu {
  position: absolute;
  inset: 0;
  z-index: 13;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(circle at 50% 42%, rgba(111, 28, 146, 0.24), rgba(0, 0, 0, 0.72) 58%),
    rgba(0, 0, 0, 0.52);
}

#pause-menu.hidden {
  display: none;
}

#pause-panel {
  width: min(92vw, 440px);
  padding: 22px;
  border: 2px solid rgba(0, 255, 200, 0.58);
  border-radius: 4px;
  background:
    linear-gradient(180deg, rgba(20, 8, 35, 0.94), rgba(5, 5, 16, 0.96)),
    repeating-linear-gradient(0deg, rgba(255, 255, 255, 0.04) 0 2px, transparent 2px 5px);
  box-shadow:
    0 0 0 3px rgba(5, 4, 13, 0.82),
    0 0 34px rgba(0, 255, 200, 0.2),
    inset 0 0 26px rgba(255, 56, 210, 0.1);
}

#pause-title {
  font-size: 26px;
  font-weight: 900;
  letter-spacing: 1.6px;
  text-transform: uppercase;
  color: #fff7ff;
  text-shadow: 0 0 12px rgba(255, 90, 222, 0.7);
}

#pause-subtitle {
  margin-top: 4px;
  font-size: 12px;
  color: #91fff0;
}

#pause-status {
  display: grid;
  gap: 6px;
  margin: 18px 0;
  font-size: 13px;
  color: #f7f0ff;
}

#pause-status span {
  padding: 8px 10px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  background: rgba(255, 255, 255, 0.06);
}

#pause-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

#pause-actions button {
  min-height: 42px;
  border: 1px solid rgba(0, 255, 200, 0.54);
  border-radius: 3px;
  background: linear-gradient(180deg, rgba(0, 255, 200, 0.18), rgba(255, 70, 210, 0.12));
  color: #ffffff;
  font: 800 13px/1 "Courier New", monospace;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  cursor: pointer;
}

#pause-actions button:hover,
#pause-actions button:focus-visible {
  outline: none;
  border-color: rgba(255, 94, 220, 0.86);
  box-shadow: 0 0 16px rgba(255, 94, 220, 0.26);
}

#boss-title-card {
  margin-top: 9px;
  margin-left: 12px;
  width: min(88vw, 680px);
  padding: 10px 12px;
  border: 1px solid rgba(255, 184, 106, 0.58);
  border-radius: 9px;
  background: linear-gradient(180deg, rgba(26, 11, 16, 0.9), rgba(11, 7, 11, 0.74));
  box-shadow: 0 0 18px rgba(255, 170, 98, 0.24);
}

#boss-title-card.hidden {
  display: none;
}

#boss-title-line {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 1.3px;
  color: #ffd7a3;
}

#boss-title-subline {
  margin-top: 3px;
  font-size: 16px;
  color: #fff2da;
  letter-spacing: 0.8px;
}

#intro-video-screen {
  position: absolute;
  inset: 0;
  z-index: 12;
  display: grid;
  place-items: center;
  background: #020208;
  overflow: hidden;
}

#intro-video-screen.hidden {
  display: none;
}

#intro-video {
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #020208;
}

#intro-skip-button {
  position: absolute;
  right: max(18px, env(safe-area-inset-right));
  bottom: max(18px, env(safe-area-inset-bottom));
  z-index: 1;
  min-width: 112px;
  min-height: 44px;
  padding: 10px 18px;
  border: 2px solid rgba(0, 240, 255, 0.72);
  border-radius: 2px;
  background:
    linear-gradient(180deg, rgba(28, 12, 46, 0.82), rgba(7, 8, 22, 0.92)),
    repeating-linear-gradient(90deg, rgba(255, 255, 255, 0.06) 0 5px, transparent 5px 10px);
  box-shadow:
    0 0 0 2px rgba(5, 6, 14, 0.72),
    0 0 18px rgba(0, 245, 255, 0.28);
  color: #fff9ff;
  font: 800 14px/1 "Courier New", monospace;
  text-transform: uppercase;
  letter-spacing: 1px;
  cursor: pointer;
}

#intro-skip-button:hover,
#intro-skip-button:focus-visible {
  border-color: rgba(255, 92, 196, 0.82);
  outline: none;
  box-shadow:
    0 0 0 2px rgba(5, 6, 14, 0.72),
    0 0 22px rgba(255, 92, 196, 0.36);
}

#start-screen {
  position: absolute;
  inset: 0;
  z-index: 8;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  background:
    radial-gradient(circle at 50% 36%, rgba(51, 16, 79, 0.28), rgba(5, 3, 12, 0.78) 66%),
    linear-gradient(180deg, rgba(1, 1, 8, 0.38), rgba(1, 0, 6, 0.82)),
    url("../assets/ui/riffbreakers_splash.jpg");
  background-position: center;
  background-size: cover;
  background-repeat: no-repeat;
  text-align: center;
  padding: 24px;
  overflow: hidden;
}

#start-screen::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background:
    linear-gradient(90deg, rgba(2, 1, 8, 0.24), transparent 22%, transparent 78%, rgba(2, 1, 8, 0.24)),
    linear-gradient(180deg, rgba(3, 0, 10, 0.58), rgba(3, 0, 10, 0.06) 38%, rgba(3, 0, 10, 0.72));
}

#start-screen > * {
  position: relative;
  z-index: 1;
}

#start-screen.hidden {
  display: none;
}

#start-screen.is-splash {
  justify-content: space-between;
  padding-top: clamp(32px, 7vh, 76px);
  padding-bottom: clamp(40px, 9vh, 84px);
}

#start-screen.is-loading {
  justify-content: center;
  gap: clamp(14px, 3vh, 28px);
}

#start-screen.is-select {
  justify-content: flex-start;
  gap: clamp(6px, 1.2vh, 12px);
  padding-top: clamp(8px, 1.5vh, 18px);
  padding-bottom: clamp(10px, 1.8vh, 18px);
  overflow-y: auto;
}

#start-title {
  max-width: min(94vw, 1120px);
  margin: 0;
  font-size: 52px;
  line-height: 1.08;
  color: #ffffff;
  text-shadow: 0 0 12px rgba(157, 59, 255, 0.75);
  letter-spacing: 0;
}

#start-screen.is-splash #start-title,
#start-screen.is-loading #start-title,
#start-screen.is-select #start-title {
  width: min(92vw, 1040px);
  aspect-ratio: 1773 / 823;
  padding: 0;
  color: transparent;
  font-size: 0;
  line-height: 0;
  text-shadow: none;
  background: url("../assets/ui/riffbreakers_logo_snes_v2.png") center / contain no-repeat;
  filter:
    drop-shadow(0 0 10px rgba(0, 238, 255, 0.62))
    drop-shadow(0 10px 28px rgba(0, 0, 0, 0.72));
}

#start-screen.is-loading #start-title {
  width: min(88vw, 900px);
}

#start-screen.is-select #start-title {
  width: min(48vw, 430px);
  flex: 0 0 auto;
  filter:
    drop-shadow(0 0 7px rgba(0, 238, 255, 0.48))
    drop-shadow(0 6px 16px rgba(0, 0, 0, 0.7));
}

#start-body {
  max-width: 620px;
  margin: 0;
  color: #d8d8f6;
  font-size: clamp(14px, 1.7vw, 20px);
  line-height: 1.4;
}

#start-screen.is-splash #start-body {
  display: none;
}

#start-screen.is-loading #start-body,
#start-screen.is-select #start-body {
  color: #fff8ff;
  font-size: clamp(14px, 1.45vw, 18px);
  letter-spacing: 0.9px;
  text-shadow:
    0 0 8px rgba(255, 76, 213, 0.72),
    0 0 12px rgba(0, 239, 255, 0.38);
}

#start-screen.is-select #start-body {
  display: none;
}

#loading-bar-container {
  --loading-progress: 0%;
  position: relative;
  width: min(82vw, 600px);
  height: 32px;
  padding: 5px;
  border: 2px solid rgba(198, 250, 255, 0.86);
  border-radius: 4px;
  background:
    linear-gradient(180deg, rgba(24, 36, 53, 0.96), rgba(4, 5, 15, 0.96)),
    repeating-linear-gradient(90deg, rgba(0, 255, 220, 0.12) 0 8px, transparent 8px 16px);
  box-shadow:
    0 0 0 3px rgba(7, 8, 18, 0.78),
    0 0 22px rgba(0, 245, 255, 0.28),
    inset 0 0 12px rgba(255, 82, 210, 0.2);
  overflow: hidden;
}

#loading-bar-container::before,
#loading-bar-container::after {
  content: "";
  position: absolute;
  pointer-events: none;
}

#loading-bar-container::before {
  inset: 0;
  z-index: 2;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.22), transparent 34%, rgba(0, 0, 0, 0.32) 76%),
    repeating-linear-gradient(90deg, transparent 0 25px, rgba(255, 255, 255, 0.12) 25px 27px);
  mix-blend-mode: screen;
}

#loading-bar-container::after {
  inset: 7px auto 7px calc(var(--loading-progress, 0%) - 10px);
  z-index: 3;
  width: 26px;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.86), transparent);
  opacity: 0.72;
  transform: skewX(-18deg);
}

#loading-bar-container.hidden {
  display: none;
}

#loading-bar-fill {
  position: relative;
  z-index: 1;
  display: block;
  height: 100%;
  width: 100%;
  background:
    repeating-linear-gradient(90deg, rgba(255, 255, 255, 0.28) 0 6px, transparent 6px 13px),
    linear-gradient(90deg, #00f0ff 0%, #37ffbc 35%, #ad5cff 72%, #ff4ccc 100%);
  border-radius: 2px;
  box-shadow:
    0 0 14px rgba(0, 255, 224, 0.65),
    inset 0 0 8px rgba(255, 255, 255, 0.32);
  transform: scaleX(0);
  transform-origin: left center;
  transition: transform 0.15s ease-out;
}

#run-summary {
  width: min(92vw, 420px);
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid rgba(0, 255, 200, 0.34);
  background: linear-gradient(180deg, rgba(8, 15, 20, 0.86), rgba(10, 9, 17, 0.76));
  box-shadow: 0 0 18px rgba(0, 255, 200, 0.18);
}

#run-summary.hidden {
  display: none;
}

.summary-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  padding: 4px 0;
  font-size: 13px;
  letter-spacing: 0.8px;
  color: #d8fffb;
}

.summary-row strong {
  font-size: 16px;
  color: #ffffff;
}

#summary-rank[data-rank='S'] {
  color: #ffe978;
}

#summary-rank[data-rank='A'] {
  color: #9dff8e;
}

#summary-rank[data-rank='B'] {
  color: #8ec9ff;
}

#summary-rank[data-rank='C'] {
  color: #ffc6a5;
}

#character-select-panel {
  position: relative;
  isolation: isolate;
  width: min(96vw, 1060px);
  min-height: clamp(330px, 34vw, 430px);
  padding:
    clamp(34px, 4vw, 46px)
    clamp(50px, 5.6vw, 76px)
    clamp(34px, 4.5vw, 50px);
  border: 0;
  border-radius: 0;
  background:
    radial-gradient(circle at 50% 22%, rgba(255, 74, 223, 0.16), transparent 34%),
    linear-gradient(180deg, rgba(4, 8, 20, 0.46), rgba(3, 3, 12, 0.62));
  box-shadow:
    0 24px 55px rgba(0, 0, 0, 0.42),
    0 0 32px rgba(0, 245, 255, 0.12);
}

#character-select-panel::before {
  content: "";
  position: absolute;
  inset: -5% -4%;
  z-index: -1;
  background: url("../assets/ui/character_select_panel_snes_v1.png") center / 100% 100% no-repeat;
  filter:
    drop-shadow(0 0 12px rgba(0, 239, 255, 0.28))
    drop-shadow(0 18px 28px rgba(0, 0, 0, 0.74));
  pointer-events: none;
}

#character-select-panel::after {
  content: "";
  position: absolute;
  inset: 9% 10% 17%;
  z-index: -1;
  background:
    linear-gradient(rgba(255, 255, 255, 0.06) 50%, transparent 50%),
    radial-gradient(circle at 25% 20%, rgba(255, 63, 211, 0.14), transparent 28%),
    radial-gradient(circle at 74% 20%, rgba(0, 222, 255, 0.14), transparent 30%);
  background-size: 100% 4px, auto, auto;
  opacity: 0.72;
  pointer-events: none;
}

#character-select-panel.hidden {
  display: none;
}

#character-select-label {
  margin: 0 0 10px;
  font-size: 13px;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: #f4fdff;
  text-shadow:
    0 0 8px rgba(0, 239, 255, 0.8),
    0 0 12px rgba(255, 68, 218, 0.46);
}

#character-select-options {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: clamp(16px, 3vw, 38px);
  align-items: stretch;
}

.character-select-card {
  --character-accent: #00ffc8;
  position: relative;
  display: grid;
  grid-template-columns: clamp(102px, 10.4vw, 132px) minmax(0, 1fr);
  align-items: center;
  gap: clamp(12px, 1.8vw, 20px);
  min-height: clamp(172px, 16vw, 212px);
  padding: clamp(12px, 1.5vw, 18px);
  border: 2px solid color-mix(in srgb, var(--character-accent) 38%, #172a44);
  border-radius: 2px;
  background:
    linear-gradient(rgba(255, 255, 255, 0.04) 50%, transparent 50%),
    radial-gradient(circle at 18% 22%, color-mix(in srgb, var(--character-accent) 22%, transparent), transparent 36%),
    linear-gradient(180deg, rgba(9, 11, 25, 0.92), rgba(3, 5, 13, 0.94));
  background-size: 100% 4px, auto, auto;
  color: #f3fbff;
  text-align: left;
  cursor: pointer;
  overflow: hidden;
  transition:
    transform 120ms ease,
    border-color 120ms ease,
    box-shadow 120ms ease,
    background 120ms ease;
}

.character-select-card:hover {
  transform: translateY(-3px);
  border-color: color-mix(in srgb, var(--character-accent) 62%, white);
  box-shadow:
    0 0 0 2px rgba(255, 255, 255, 0.08),
    0 12px 28px color-mix(in srgb, var(--character-accent) 24%, transparent);
}

.character-select-card.is-selected {
  border-color: color-mix(in srgb, var(--character-accent) 76%, white);
  box-shadow:
    inset 0 0 24px color-mix(in srgb, var(--character-accent) 12%, transparent),
    0 0 0 2px color-mix(in srgb, var(--character-accent) 42%, transparent),
    0 0 26px color-mix(in srgb, var(--character-accent) 34%, transparent);
}

.character-select-card.is-selected::after {
  content: "P1";
  position: absolute;
  top: 12px;
  right: 12px;
  min-width: 36px;
  padding: 4px 6px;
  border: 1px solid color-mix(in srgb, var(--character-accent) 70%, white);
  background: rgba(3, 7, 15, 0.78);
  box-shadow: 0 0 12px color-mix(in srgb, var(--character-accent) 36%, transparent);
  font-size: 12px;
  letter-spacing: 0.8px;
  text-transform: uppercase;
  text-align: center;
  color: color-mix(in srgb, var(--character-accent) 82%, white);
}

.character-select-card.is-coop-partner {
  border-color: color-mix(in srgb, var(--character-accent) 54%, #ffffff);
  box-shadow:
    inset 0 0 18px color-mix(in srgb, var(--character-accent) 10%, transparent),
    0 0 18px color-mix(in srgb, var(--character-accent) 24%, transparent);
}

.character-select-card.is-coop-partner::after {
  content: "P2";
  position: absolute;
  top: 12px;
  right: 12px;
  min-width: 36px;
  padding: 4px 6px;
  border: 1px solid color-mix(in srgb, var(--character-accent) 58%, white);
  background: rgba(3, 7, 15, 0.78);
  box-shadow: 0 0 12px color-mix(in srgb, var(--character-accent) 28%, transparent);
  font-size: 12px;
  letter-spacing: 0.8px;
  text-transform: uppercase;
  text-align: center;
  color: color-mix(in srgb, var(--character-accent) 74%, white);
}

.character-select-card__portrait {
  position: relative;
  display: grid;
  place-items: center;
  width: 100%;
  aspect-ratio: 1;
  background: url("../assets/ui/character_select_portrait_frame_snes_v1.png") center / contain no-repeat;
  filter:
    drop-shadow(0 0 8px color-mix(in srgb, var(--character-accent) 38%, transparent))
    drop-shadow(0 8px 10px rgba(0, 0, 0, 0.46));
}

.character-select-card__portrait::before {
  content: "";
  position: absolute;
  inset: 27%;
  z-index: 0;
  border-radius: 50%;
  background:
    radial-gradient(circle, color-mix(in srgb, var(--character-accent) 58%, white) 0 5%, transparent 6%),
    radial-gradient(circle, color-mix(in srgb, var(--character-accent) 32%, transparent), transparent 68%);
  box-shadow:
    inset 0 0 18px rgba(255, 255, 255, 0.18),
    0 0 20px color-mix(in srgb, var(--character-accent) 36%, transparent);
}

.character-select-card__portrait-image {
  position: absolute;
  inset: 10%;
  z-index: 1;
  width: 80%;
  height: 80%;
  object-fit: cover;
  object-position: center 16%;
  clip-path: polygon(12% 4%, 88% 4%, 97% 13%, 97% 87%, 88% 96%, 12% 96%, 3% 87%, 3% 13%);
  image-rendering: pixelated;
  filter: drop-shadow(0 0 7px color-mix(in srgb, var(--character-accent) 42%, transparent));
}

.character-select-card__initials {
  display: none;
  position: relative;
  z-index: 2;
  font-size: clamp(26px, 3vw, 40px);
  color: #ffffff;
  text-shadow:
    2px 2px 0 #090614,
    0 0 10px color-mix(in srgb, var(--character-accent) 74%, transparent);
}

.character-select-card.has-portrait-error .character-select-card__portrait-image {
  display: none;
}

.character-select-card.has-portrait-error .character-select-card__initials {
  display: block;
}

.character-select-card__copy {
  display: flex;
  min-width: 0;
  flex-direction: column;
  gap: 8px;
}

.character-select-card__name {
  font-size: clamp(19px, 2.1vw, 27px);
  line-height: 1;
  color: #ffffff;
  letter-spacing: 0.8px;
  text-shadow: 0 0 9px color-mix(in srgb, var(--character-accent) 34%, transparent);
}

.character-select-card__subtitle {
  font-size: clamp(10px, 1vw, 12px);
  letter-spacing: 1.2px;
  text-transform: uppercase;
  color: color-mix(in srgb, var(--character-accent) 62%, white);
}

.character-select-card__description {
  margin: 0;
  font-size: clamp(11px, 1.16vw, 14px);
  line-height: 1.36;
  color: #d7e6f7;
}

#controls-overlay {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-top: clamp(10px, 1.5vw, 16px);
}

#coop-toggle {
  display: block;
  width: min(100%, 180px);
  margin: 12px auto 0;
  padding: 9px 14px;
  border: 2px solid rgba(0, 240, 255, 0.48);
  border-radius: 2px;
  background: linear-gradient(180deg, rgba(9, 18, 30, 0.94), rgba(4, 6, 14, 0.96));
  color: #eaffff;
  font-size: 12px;
  letter-spacing: 1px;
  text-transform: uppercase;
  cursor: pointer;
  box-shadow:
    inset 0 -8px 12px rgba(0, 0, 0, 0.24),
    0 0 12px rgba(0, 255, 200, 0.12);
}

#coop-toggle[aria-pressed="true"] {
  border-color: rgba(255, 99, 216, 0.72);
  color: #fff3fb;
  box-shadow:
    inset 0 0 18px rgba(255, 99, 216, 0.12),
    0 0 18px rgba(255, 99, 216, 0.26);
}

#coop-toggle.hidden {
  display: none;
}

.control-chip {
  min-height: 48px;
  padding: 8px 10px;
  border: 2px solid rgba(0, 240, 255, 0.42);
  border-radius: 2px;
  background:
    linear-gradient(180deg, rgba(9, 18, 30, 0.92), rgba(4, 6, 14, 0.94)),
    repeating-linear-gradient(90deg, rgba(255, 255, 255, 0.05) 0 4px, transparent 4px 8px);
  box-shadow:
    inset 0 -8px 12px rgba(0, 0, 0, 0.24),
    0 0 12px rgba(0, 255, 200, 0.12);
}

.control-chip span,
.control-chip strong {
  display: block;
  letter-spacing: 0;
}

.control-chip span {
  margin-bottom: 5px;
  font-size: 10px;
  text-transform: uppercase;
  color: #8be9ff;
}

.control-chip strong {
  font-size: 13px;
  line-height: 1.15;
  color: #ffffff;
}

#character-select-hint {
  display: none;
  margin: 9px 0 0;
  font-size: 12px;
  color: #d9efff;
  letter-spacing: 0.7px;
  text-shadow: 0 0 8px rgba(0, 239, 255, 0.34);
}

#start-button {
  position: relative;
  border: 1px solid rgba(0, 255, 200, 0.65);
  background: linear-gradient(180deg, rgba(14, 8, 24, 0.94), rgba(28, 10, 45, 0.94));
  color: #eaffff;
  font-size: 16px;
  letter-spacing: 1px;
  text-transform: uppercase;
  padding: 11px 20px;
  border-radius: 4px;
  cursor: pointer;
  box-shadow: 0 0 18px rgba(0, 255, 200, 0.25);
  overflow: hidden;
  transition:
    border-color 120ms ease,
    box-shadow 120ms ease,
    filter 120ms ease,
    transform 120ms ease;
}

#start-button::after {
  content: "";
  position: absolute;
  inset: 12%;
  border: 2px solid rgba(255, 255, 255, 0);
  border-radius: inherit;
  pointer-events: none;
}

#start-screen.is-splash #start-button {
  display: block;
  width: min(72vw, 540px);
  aspect-ratio: 1890 / 608;
  min-width: 0;
  padding: 0;
  border: 0;
  color: transparent;
  font-size: 0;
  line-height: 0;
  text-indent: -9999px;
  overflow: hidden;
  background: url("../assets/ui/riffbreakers_start_button_snes_v1.png") center / contain no-repeat;
  box-shadow: none;
  filter:
    drop-shadow(0 0 12px rgba(0, 245, 255, 0.42))
    drop-shadow(0 0 18px rgba(255, 86, 214, 0.32));
  transform-origin: center;
  animation:
    press-start-float 1.65s ease-in-out infinite,
    press-start-pulse 1.25s ease-in-out infinite alternate;
}

#start-screen.is-select #start-button {
  min-width: min(72vw, 420px);
  margin-top: -4px;
  padding: 13px 24px;
  border: 2px solid rgba(0, 240, 255, 0.72);
  border-radius: 2px;
  background:
    linear-gradient(180deg, rgba(28, 12, 46, 0.94), rgba(7, 8, 22, 0.96)),
    repeating-linear-gradient(90deg, rgba(255, 255, 255, 0.06) 0 5px, transparent 5px 10px);
  box-shadow:
    0 0 0 2px rgba(5, 6, 14, 0.78),
    0 0 18px rgba(0, 245, 255, 0.28),
    inset 0 -8px 12px rgba(0, 0, 0, 0.28);
  color: #fff9ff;
  text-shadow:
    0 0 8px rgba(255, 76, 213, 0.64),
    0 0 12px rgba(0, 239, 255, 0.36);
}

@keyframes press-start-float {
  0%,
  100% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(-8px);
  }
}

@keyframes press-start-pulse {
  from {
    filter:
      brightness(0.94)
      drop-shadow(0 0 10px rgba(0, 245, 255, 0.38))
      drop-shadow(0 0 14px rgba(255, 86, 214, 0.26));
  }
  to {
    filter:
      brightness(1.22)
      drop-shadow(0 0 18px rgba(0, 245, 255, 0.72))
      drop-shadow(0 0 28px rgba(255, 86, 214, 0.58));
  }
}

@keyframes start-click-burst {
  from {
    inset: 18%;
    opacity: 0.92;
    border-color: rgba(255, 255, 255, 0.86);
  }
  to {
    inset: -10%;
    opacity: 0;
    border-color: rgba(0, 245, 255, 0);
  }
}

#start-button:hover {
  border-color: rgba(255, 92, 196, 0.75);
  box-shadow: 0 0 18px rgba(255, 92, 196, 0.32);
}

#start-screen.is-splash #start-button:hover {
  box-shadow: none;
  filter:
    brightness(1.1)
    drop-shadow(0 0 14px rgba(0, 245, 255, 0.5))
    drop-shadow(0 0 22px rgba(255, 86, 214, 0.4));
}

#start-button:active {
  transform: translateY(2px) scale(0.98);
}

#start-button.is-clicked::after {
  animation: start-click-burst 240ms ease-out;
}

#start-screen.is-splash #start-button:active {
  animation-play-state: paused;
  transform: translateY(5px) scale(0.97);
}

#start-screen.is-splash #start-button.is-clicked,
#start-screen.is-select #start-button.is-clicked {
  filter:
    brightness(1.34)
    drop-shadow(0 0 22px rgba(0, 245, 255, 0.84))
    drop-shadow(0 0 30px rgba(255, 86, 214, 0.62));
}

#start-button.hidden {
  display: none;
}

#mobile-controls {
  position: absolute;
  left: 0;
  right: 0;
  bottom: max(18px, env(safe-area-inset-bottom));
  z-index: 7;
  display: none;
  justify-content: space-between;
  align-items: flex-end;
  gap: 14px;
  padding: 0 max(16px, env(safe-area-inset-left)) 0 max(16px, env(safe-area-inset-right));
  pointer-events: none;
}

.mobile-control-cluster {
  display: grid;
  pointer-events: auto;
  touch-action: none;
  user-select: none;
}

.mobile-control {
  width: clamp(56px, 12vw, 66px);
  height: clamp(56px, 12vw, 66px);
  border: 1px solid rgba(0, 255, 200, 0.5);
  border-radius: 8px;
  background:
    linear-gradient(180deg, rgba(12, 16, 28, 0.88), rgba(5, 8, 14, 0.82)),
    radial-gradient(circle at 45% 20%, rgba(0, 255, 200, 0.16), transparent 58%);
  color: #f4ffff;
  font: 700 20px/1 "Courier New", monospace;
  box-shadow: 0 0 15px rgba(0, 255, 200, 0.18);
  text-shadow: 0 0 8px rgba(0, 255, 200, 0.45);
  -webkit-tap-highlight-color: transparent;
}

.mobile-control.is-pressed {
  border-color: rgba(255, 92, 196, 0.78);
  background:
    linear-gradient(180deg, rgba(36, 12, 40, 0.95), rgba(10, 8, 20, 0.9)),
    radial-gradient(circle at 45% 20%, rgba(255, 92, 196, 0.22), transparent 58%);
  transform: translateY(2px);
}

.mobile-control-dpad {
  grid-template-columns: repeat(3, clamp(56px, 12vw, 66px));
  grid-template-rows: repeat(3, clamp(56px, 12vw, 66px));
  gap: 7px;
}

.mobile-control-up {
  grid-column: 2;
  grid-row: 1;
}

.mobile-control-left {
  grid-column: 1;
  grid-row: 2;
}

.mobile-control-right {
  grid-column: 3;
  grid-row: 2;
}

.mobile-control-down {
  grid-column: 2;
  grid-row: 3;
}

.mobile-control-actions {
  grid-template-columns: repeat(3, clamp(54px, 11vw, 64px));
  grid-template-rows: repeat(2, clamp(58px, 13vw, 70px));
  gap: 9px;
}

.mobile-control-actions .mobile-control {
  width: clamp(58px, 13vw, 70px);
  height: clamp(58px, 13vw, 70px);
  border-color: rgba(255, 92, 196, 0.5);
  box-shadow: 0 0 15px rgba(255, 92, 196, 0.16);
}

.mobile-control-jump {
  grid-column: 1;
  grid-row: 2;
}

.mobile-control-attack {
  grid-column: 2;
  grid-row: 1;
}

.mobile-control-fire {
  grid-column: 2;
  grid-row: 2;
}

.mobile-control-dash {
  grid-column: 1;
  grid-row: 1;
}

.mobile-control-super {
  grid-column: 3;
  grid-row: 1 / span 2;
  height: 100%;
}

@media (max-width: 720px) {
  #ui {
    top: max(6px, env(safe-area-inset-top));
    bottom: auto;
    left: 0;
    right: 0;
    width: min(97vw, 980px);
    height: auto;
    margin: 0 auto;
  }

  #hud-top {
    position: relative;
    top: auto;
    right: auto;
    bottom: auto;
    left: auto;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    height: auto;
  }

  .health-panel {
    position: relative;
    left: auto;
    right: auto;
    bottom: auto;
    width: clamp(286px, 48vw, 390px);
    min-height: 104px;
  }

  body.is-coop-active .health-panel {
    width: min(47vw, 360px);
  }

  .health-bar-shell {
    width: 100%;
  }

  #timer {
    position: absolute;
    right: 0;
    top: 0;
    bottom: auto;
    min-width: 72px;
    font-size: 18px;
    padding: 10px 8px;
  }

  #riff-meter-panel {
    right: max(10px, env(safe-area-inset-right));
    top: max(86px, calc(env(safe-area-inset-top) + 86px));
    bottom: auto;
    width: 150px;
    padding: 8px 10px 9px;
  }

  #riff-meter-label {
    font-size: 11px;
  }

  #riff-meter-shell {
    height: 11px;
  }

  #riff-meter-value {
    font-size: 11px;
  }

  #status {
    position: static;
    width: auto;
    max-width: calc(100vw - 20px);
    margin-top: 8px;
    margin-left: 6px;
    font-size: 11px;
    line-height: 1.25;
    white-space: normal;
  }

  #boss-panel {
    width: min(88vw, 460px);
    padding: 6px 8px 7px;
  }

  #boss-name {
    font-size: 10px;
  }

  #boss-telegraph {
    font-size: 11px;
  }

  #boss-title-card {
    width: min(94vw, 680px);
    margin-left: 8px;
    padding: 8px 9px;
  }

  #boss-title-subline {
    font-size: 14px;
  }

  #run-summary {
    width: min(95vw, 420px);
    padding: 9px 10px;
  }

  #character-select-panel {
    width: min(96vw, 760px);
    min-height: auto;
    padding:
      clamp(46px, 8vw, 62px)
      clamp(22px, 5vw, 34px)
      clamp(48px, 8vw, 64px);
  }

  #character-select-panel::before {
    inset: -20px -16px;
  }

  #character-select-options {
    grid-template-columns: 1fr;
    gap: 12px;
  }

  #controls-overlay {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .character-select-card {
    grid-template-columns: clamp(98px, 24vw, 126px) minmax(0, 1fr);
    min-height: 150px;
  }

  .summary-row {
    font-size: 12px;
  }

  .summary-row strong {
    font-size: 14px;
  }

  #editor-panel {
    width: min(95vw, 360px);
    margin-left: 8px;
  }

  #editor-toggle {
    margin-left: 8px;
  }
}

@media (max-width: 720px), (pointer: coarse) {
  #mobile-controls {
    display: flex;
  }

  /* --mobile-controls-h is the distance from the bottom of the play area to the
     top of the touch cluster, so these clear it without guessing at breakpoints.
     The fallback is the worst-case reserve, for browsers without ResizeObserver. */
  #boss-panel {
    bottom: calc(var(--mobile-controls-h, 220px) + 14px);
  }

  #boss-telegraph {
    bottom: calc(var(--mobile-controls-h, 220px) + 70px);
  }
}

@media (max-width: 720px) {
  #start-screen {
    justify-content: flex-start;
    gap: 12px;
    padding: 22px 12px max(24px, env(safe-area-inset-bottom));
    overflow-y: auto;
  }

  #start-title {
    font-size: 36px;
  }

  #start-screen.is-splash {
    padding-top: max(24px, env(safe-area-inset-top));
    padding-bottom: max(30px, env(safe-area-inset-bottom));
    overflow: hidden;
  }

  #start-screen.is-splash #start-title,
  #start-screen.is-loading #start-title,
  #start-screen.is-select #start-title {
    width: min(96vw, 760px);
    font-size: 0;
  }

  #start-screen.is-select #start-title {
    width: min(74vw, 360px);
  }

  #start-screen.is-splash #start-button {
    width: min(82vw, 430px);
    min-width: 0;
    padding: 0;
    font-size: 0;
  }

  #start-body {
    max-width: 92vw;
    font-size: 15px;
  }

  #loading-bar-container {
    width: min(88vw, 520px);
    height: 28px;
  }

  #character-select-panel {
    width: min(96vw, 760px);
    padding:
      clamp(42px, 8vw, 56px)
      clamp(18px, 5vw, 30px)
      clamp(44px, 8vw, 58px);
  }

  .character-select-card {
    padding: 12px;
  }

  .character-select-card__name {
    font-size: 20px;
  }

  .character-select-card__description {
    font-size: 12px;
  }
}

@media (max-width: 420px) {
  #start-title {
    font-size: 32px;
  }

  #start-screen.is-splash #start-title,
  #start-screen.is-loading #start-title,
  #start-screen.is-select #start-title {
    width: 96vw;
    font-size: 0;
  }

  .character-select-card {
    grid-template-columns: 1fr;
    justify-items: center;
    text-align: center;
  }

  .character-select-card__portrait {
    width: min(54vw, 150px);
  }

  #mobile-controls {
    gap: 8px;
    padding-left: 8px;
    padding-right: 8px;
    bottom: max(12px, env(safe-area-inset-bottom));
  }

  .mobile-control-dpad {
    grid-template-columns: repeat(3, 52px);
    grid-template-rows: repeat(3, 52px);
    gap: 5px;
  }

  .mobile-control,
  .mobile-control-actions .mobile-control {
    width: 52px;
    height: 52px;
    font-size: 18px;
  }

  .mobile-control-actions .mobile-control {
    width: 48px;
  }

  .mobile-control-actions {
    grid-template-columns: repeat(3, 48px);
    grid-template-rows: repeat(2, 54px);
    gap: 6px;
  }
}

@media (max-width: 560px) {
  #status {
    display: none;
  }

  .health-panel {
    width: min(62vw, 260px);
  }

  body.is-coop-active .health-panel {
    width: 49vw;
  }

  #timer {
    min-width: 64px;
    font-size: 16px;
  }
}
