:root {
  color-scheme: dark;
  --bg: #0b1020;
  --panel: #141c31;
  --panel-soft: #1a2440;
  --line: rgba(255, 255, 255, 0.1);
  --text: #f7f8ff;
  --muted: #aab4cf;
  --cyan: #58e6ff;
  --blue: #568dff;
  --violet: #aa73ff;
  --green: #54e6a5;
  --red: #ff6f91;
  --white-key: #f8f9ff;
  --black-key: #14192a;
}

* { box-sizing: border-box; }
html { height: 100%; }

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background:
    radial-gradient(circle at 15% 5%, rgba(74, 100, 205, 0.22), transparent 34rem),
    radial-gradient(circle at 88% 86%, rgba(76, 212, 230, 0.12), transparent 34rem),
    var(--bg);
  overflow: hidden;
}

button { font: inherit; }

.app-shell {
  position: relative;
  z-index: 1;
  width: min(1180px, calc(100% - 32px));
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 12px;
  height: 100dvh;
  margin: 0 auto;
  padding: 14px 0 12px;
}

.ambient-music-notes {
  position: fixed;
  z-index: 0;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
}
.ambient-flying-note {
  position: absolute;
  top: var(--note-top);
  left: -12vw;
  color: var(--note-color);
  font-family: Georgia, "Times New Roman", serif;
  font-size: var(--note-size);
  font-weight: 700;
  opacity: 0;
  filter: drop-shadow(0 0 7px currentColor);
  will-change: transform, opacity;
  animation: ambientNoteFly var(--note-duration) linear var(--note-delay) infinite;
}
.ambient-flying-note-glyph {
  display: inline-block;
  transform-origin: center;
  animation: ambientNoteSpin var(--spin-duration) linear infinite;
  animation-direction: var(--spin-direction);
}
@keyframes ambientNoteFly {
  0% { transform: translate3d(-10vw, 30px, 0) rotate(-10deg) scale(0.74); opacity: 0; }
  12% { opacity: 0.14; }
  48% { transform: translate3d(62vw, -28px, 0) rotate(6deg) scale(1.04); opacity: 0.23; }
  88% { opacity: 0.12; }
  100% { transform: translate3d(132vw, 18px, 0) rotate(16deg) scale(0.88); opacity: 0; }
}
@keyframes ambientNoteSpin { to { transform: rotate(1turn); } }

.topbar,
.game-meta,
.game-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
}

.topbar { margin-bottom: 0; }
.topbar-controls { display: flex; align-items: center; gap: 10px; }
.first-note-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  color: #dbe2f6;
  font-size: 0.82rem;
  font-weight: 800;
  white-space: nowrap;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel-soft);
  cursor: pointer;
}
.first-note-toggle input {
  width: 17px;
  height: 17px;
  margin: 0;
  accent-color: var(--cyan);
  cursor: pointer;
}
.first-note-toggle:focus-within { outline: 3px solid rgba(88, 230, 255, 0.65); outline-offset: 3px; }

.brand { display: flex; align-items: center; gap: 14px; }
.brand-mark {
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  border-radius: 15px;
  color: #08101e;
  font-size: 27px;
  font-weight: 900;
  background: linear-gradient(135deg, var(--cyan), #b4f8ff);
  box-shadow: 0 0 30px rgba(88, 230, 255, 0.25);
}
.brand h1 { margin: 0; font-size: clamp(1.25rem, 3vw, 1.72rem); letter-spacing: -0.035em; }
.brand p { margin: 3px 0 0; color: var(--muted); font-size: 0.9rem; }

.midi-button,
.secondary-button,
.primary-button {
  border: 0;
  border-radius: 12px;
  cursor: pointer;
  transition: transform 150ms ease, background 150ms ease, opacity 150ms ease;
}
.midi-button:hover,
.secondary-button:hover,
.primary-button:hover { transform: translateY(-1px); }
.midi-button:focus-visible,
.secondary-button:focus-visible,
.primary-button:focus-visible { outline: 3px solid rgba(88, 230, 255, 0.65); outline-offset: 3px; }

.midi-button {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 11px 15px;
  color: var(--text);
  background: var(--panel-soft);
  border: 1px solid var(--line);
}
.status-light { width: 9px; height: 9px; flex: 0 0 auto; border-radius: 50%; background: #66708b; box-shadow: 0 0 0 4px rgba(102, 112, 139, 0.13); }
.connected .status-light,
.midi-status.connected .status-light { background: var(--green); box-shadow: 0 0 0 4px rgba(84, 230, 165, 0.14), 0 0 16px rgba(84, 230, 165, 0.5); }

.game-card {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  min-height: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 24px;
  background: rgba(20, 28, 49, 0.96);
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.32);
}

.game-layout { display: grid; grid-template-columns: minmax(0, 1fr) 310px; gap: 16px; min-height: 0; }
.game-meta,
.game-footer { padding: 18px 22px; }
.game-meta { grid-row: 1; }
.message-panel { grid-row: 2; }
.stage { grid-row: 3; }
.game-footer { grid-row: 4; }
.game-meta { position: relative; border-bottom: 1px solid var(--line); }
.eyebrow { display: block; margin-bottom: 3px; color: var(--cyan); font-size: 0.67rem; font-weight: 800; letter-spacing: 0.14em; }
#challengeLabel { font-size: 1rem; }

.game-stats { display: flex; align-items: center; gap: 9px; }
.stat-box {
  min-width: 76px;
  padding: 7px 11px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: rgba(255,255,255,0.035);
}
.stat-box > span:first-child { display: block; margin-bottom: 2px; color: #8e9ab7; font-size: 0.58rem; font-weight: 850; letter-spacing: 0.12em; }
.stat-box strong { font-size: 0.95rem; }
.lives-display { display: flex; gap: 4px; overflow: visible; }
.life-heart { display: inline-block; position: relative; color: var(--red); font-size: 1rem; line-height: 1; text-shadow: 0 0 12px rgba(255,111,145,0.5); transform-origin: center; }
.life-heart.lost { color: #3d4763; text-shadow: none; }
.life-heart.heart-pop { z-index: 2; animation: lifeLostPop 720ms cubic-bezier(.16,.84,.24,1); }
@keyframes lifeLostPop {
  0% { color: var(--red); opacity: 1; transform: scale(1); text-shadow: 0 0 12px rgba(255,111,145,0.55); }
  28% { color: #fff; opacity: 1; transform: translateY(-4px) scale(2.25) rotate(-10deg); text-shadow: 0 0 8px #fff, 0 0 28px rgba(255,70,120,0.95); }
  58% { color: var(--red); opacity: 0.92; transform: translateY(-8px) scale(1.55) rotate(9deg); text-shadow: 0 0 22px rgba(255,70,120,0.9); }
  100% { color: #3d4763; opacity: 1; transform: scale(1); text-shadow: none; }
}

.length-track { display: flex; align-items: flex-start; padding-bottom: 18px; }
.length-step {
  display: grid;
  position: relative;
  place-items: center;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  color: #7e89a7;
  font-size: 0.7rem;
  font-weight: 800;
  background: #232d4a;
  border: 1px solid rgba(255,255,255,0.06);
}
.length-step::after {
  content: attr(data-games);
  position: absolute;
  top: 30px;
  left: 50%;
  width: 38px;
  transform: translateX(-50%);
  color: #7e89a7;
  font-size: 0.56rem;
  font-weight: 800;
  text-align: center;
  white-space: nowrap;
}
.length-step.active::after { color: var(--cyan); }
.length-step.complete::after { color: var(--green); }
.length-step.active,
.length-step.complete { color: #071420; background: var(--cyan); box-shadow: 0 0 20px rgba(88, 230, 255, 0.24); }
.length-step.complete { background: var(--green); }
.length-line { width: 14px; height: 2px; margin-top: 12px; background: #2c3654; }
.length-line.complete { background: var(--green); }

.stage {
  position: relative;
  height: auto;
  min-height: 0;
  overflow: hidden;
  background:
    linear-gradient(rgba(88, 230, 255, 0.035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(88, 230, 255, 0.035) 1px, transparent 1px),
    linear-gradient(180deg, #10182c, #10172a 70%, #18213a);
  background-size: 42px 42px, 42px 42px, auto;
}
.stage::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: 28px;
  height: 2px;
  z-index: 2;
  background: linear-gradient(90deg, transparent, rgba(88, 230, 255, 0.72), transparent);
  box-shadow: 0 0 18px rgba(88, 230, 255, 0.45);
}
.stage-glow { position: absolute; inset: auto 10% -25px; height: 180px; background: radial-gradient(ellipse, rgba(88, 230, 255, 0.16), transparent 68%); pointer-events: none; }

.falling-layer { position: absolute; inset: 0 0 30px; z-index: 4; pointer-events: none; }
.falling-note {
  position: absolute;
  top: 10px;
  left: 50%;
  width: min(215px, 41vw);
  height: 58px;
  transform: translateX(-50%);
  filter: drop-shadow(0 16px 20px rgba(0,0,0,0.35));
}
.mini-piano {
  position: absolute;
  inset: 0;
  display: flex;
  padding: 2px 3px 4px;
  border-radius: 5px 5px 8px 8px;
  background: #080c16;
  border: 1px solid rgba(255,255,255,0.16);
  box-shadow: 0 0 30px rgba(88,230,255,0.16);
}
.mini-white-key {
  position: relative;
  flex: 1;
  height: 100%;
  margin: 0 0.5px;
  border-radius: 0 0 4px 4px;
  background: linear-gradient(90deg, #dbe1ec, #fff 20%, #f8faff 78%, #c8d0df);
  box-shadow: inset 0 -3px 0 #bcc5d6;
}
.mini-black-key {
  position: absolute;
  z-index: 2;
  top: 2px;
  width: 7%;
  height: 58%;
  transform: translateX(-50%);
  border-radius: 0 0 3px 3px;
  background: linear-gradient(90deg, #070a10, #252b3b 60%, #090c14);
  box-shadow: inset 0 -2px 0 #03050a, 0 3px 5px rgba(0,0,0,0.48);
}
.mini-white-key.marked {
  background: linear-gradient(90deg, #78e9ff, #edfeff 50%, #42d3ef);
  box-shadow: inset 0 -3px 0 #33b8d1, 0 0 20px rgba(88,230,255,0.78);
}
.mini-black-key.marked {
  background: linear-gradient(90deg, #207f98, #8ff2ff 52%, #17677d);
  box-shadow: inset 0 -2px 0 #0b4558, 0 0 22px rgba(88,230,255,0.95);
}
.mini-white-key.marked::after {
  content: "";
  position: absolute;
  left: 24%;
  right: 24%;
  bottom: 7px;
  height: 4px;
  border-radius: 99px;
  background: #082237;
  box-shadow: 0 0 12px rgba(8,34,55,0.5);
}
.mini-white-key.marked.sounding,
.mini-black-key.marked.sounding { animation: marked-pulse 1200ms ease-out; }
.mini-white-key.player-pressed {
  background: linear-gradient(90deg, #42c98c, #d9ffed 50%, #38ba7f);
  box-shadow: inset 0 -3px 0 #209761, 0 0 25px rgba(84,230,165,0.95);
  filter: brightness(1.14);
}
.mini-black-key.player-pressed {
  background: linear-gradient(90deg, #176843, #72f0b2 52%, #105336);
  box-shadow: inset 0 -2px 0 #0a3925, 0 0 24px rgba(84,230,165,0.95);
  filter: brightness(1.18);
}
@keyframes marked-pulse {
  0% { filter: brightness(1.5); box-shadow: 0 0 45px rgba(88,230,255,1); }
  100% { filter: brightness(1); box-shadow: 0 0 24px rgba(88,230,255,0.65); }
}

.start-panel,
.hall-entry-panel {
  position: absolute;
  z-index: 8;
  top: 42%;
  left: 50%;
  width: min(520px, calc(100% - 32px));
  transform: translate(-50%, -50%);
  text-align: center;
}
.start-panel { padding: 28px; border-radius: 22px; background: rgba(19, 29, 51, 0.9); border: 1px solid rgba(255,255,255,0.11); box-shadow: 0 18px 48px rgba(0,0,0,0.32); backdrop-filter: blur(10px); }
.start-panel.hidden { display: none; }
.start-icon { margin: 0 auto 12px; color: var(--cyan); font-size: 2rem; }
.start-panel h2,
.message-panel h2,
.hall-entry-panel h2 { margin: 0; font-size: clamp(1.35rem, 4vw, 2rem); letter-spacing: -0.04em; }
.start-panel p,
.message-panel p,
.hall-entry-panel > p { margin: 9px auto 18px; max-width: 470px; color: var(--muted); line-height: 1.5; }
.start-panel small { display: block; margin-top: 12px; color: #7f8aa8; }
.player-name-field { display: grid; gap: 6px; width: min(310px, 100%); margin: 0 auto 14px; color: #b9c3dc; font-size: 0.72rem; font-weight: 750; text-align: left; }
.player-name-field input {
  width: 100%;
  padding: 10px 12px;
  color: var(--text);
  font: inherit;
  border: 1px solid rgba(255,255,255,0.16);
  border-radius: 10px;
  background: #111a30;
}
.player-name-field input:focus { outline: 3px solid rgba(88,230,255,0.4); border-color: var(--cyan); }

.primary-button { padding: 13px 22px; color: #06121d; font-weight: 850; background: linear-gradient(135deg, var(--cyan), #a5f4ff); box-shadow: 0 8px 25px rgba(88, 230, 255, 0.25); }
.message-panel {
  display: none;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 13px;
  min-height: 76px;
  padding: 12px 22px;
  border-bottom: 1px solid var(--line);
  background: rgba(11,18,34,0.92);
  text-align: left;
}
.message-panel.visible { display: grid; }
.message-copy { min-width: 0; }
.message-panel h2 { font-size: 1rem; letter-spacing: -0.02em; }
.message-panel p { margin: 3px 0 0; max-width: none; font-size: 0.72rem; line-height: 1.35; }
.message-panel .phase-badge { margin: 0; padding: 5px 9px; font-size: 0.56rem; }
.hall-entry-panel { padding: 28px; border: 1px solid rgba(255,255,255,0.14); border-radius: 22px; background: rgba(19,29,51,0.96); box-shadow: 0 18px 48px rgba(0,0,0,0.42); backdrop-filter: blur(10px); }
.hall-entry-panel[hidden] { display: none; }
.save-score-status { min-height: 22px; margin-bottom: 0 !important; font-size: 0.78rem; }
.save-score-status.success { color: var(--green); }
.save-score-status.error { color: #ff9caa; }
.phase-badge { display: inline-block; margin-bottom: 10px; padding: 5px 10px; border-radius: 99px; color: #071421; font-size: 0.66rem; font-weight: 900; letter-spacing: 0.13em; background: var(--cyan); }
.phase-badge.play { background: var(--violet); color: white; }
.phase-badge.correct { background: var(--green); }
.phase-badge.wrong { background: var(--red); color: white; }

.attempt-dots { display: flex; justify-content: flex-start; gap: 7px; min-height: 14px; }
.attempt-dot { width: 12px; height: 12px; border-radius: 50%; background: #303b5b; border: 1px solid rgba(255,255,255,0.1); transition: all 140ms ease; }
.attempt-dot.done { background: var(--green); box-shadow: 0 0 12px rgba(84, 230, 165, 0.6); }
.attempt-dot.wrong { background: var(--red); transform: scale(1.2); }

.great-celebration {
  position: absolute;
  z-index: 14;
  top: 48%;
  left: 50%;
  color: #baffdd;
  font-size: clamp(4rem, 12vw, 8.5rem);
  font-weight: 1000;
  letter-spacing: -0.07em;
  line-height: 1;
  text-align: center;
  text-shadow: 0 0 18px rgba(84,230,165,0.95), 0 0 55px rgba(84,230,165,0.7), 0 10px 35px rgba(0,0,0,0.55);
  pointer-events: none;
}
.great-celebration[hidden] { display: none; }
.great-celebration.active { animation: greatZoom 1250ms cubic-bezier(.16,.82,.24,1) forwards; }
@keyframes greatZoom {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(.12); }
  20% { opacity: 1; transform: translate(-50%, -50%) scale(1.22); }
  58% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -50%) scale(1.65); }
}

.pause-panel {
  position: absolute;
  z-index: 16;
  inset: 0;
  display: grid;
  place-content: center;
  justify-items: center;
  text-align: center;
  background: rgba(7,12,24,0.78);
  backdrop-filter: blur(6px);
}
.pause-panel[hidden] { display: none; }
.pause-panel h2 { margin: 4px 0 6px; font-size: clamp(2rem, 6vw, 4rem); }
.pause-panel p { margin: 0; color: var(--muted); }

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

.admin-panel {
  position: fixed;
  z-index: 100;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(4,8,17,0.82);
  backdrop-filter: blur(8px);
}
.admin-panel[hidden] { display: none; }
.admin-card {
  position: relative;
  width: min(440px, 100%);
  max-height: calc(100dvh - 40px);
  padding: 28px;
  overflow-y: auto;
  border: 1px solid rgba(255,255,255,0.15);
  border-radius: 22px;
  background: #141d33;
  box-shadow: 0 28px 80px rgba(0,0,0,0.55);
}
.admin-card h2 { margin: 0; font-size: 1.75rem; }
.admin-card > p { color: var(--muted); line-height: 1.45; }
.admin-close {
  position: absolute;
  top: 12px;
  right: 14px;
  width: 38px;
  height: 38px;
  color: #dbe2f6;
  font-size: 1.6rem;
  line-height: 1;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: #202a45;
  cursor: pointer;
}
.admin-confirm-field { display: grid; gap: 7px; margin: 20px 0 12px; color: #b9c3dc; font-size: 0.8rem; }
.admin-confirm-field input {
  width: 100%;
  padding: 12px;
  color: var(--text);
  font: inherit;
  text-transform: uppercase;
  border: 1px solid rgba(255,255,255,0.18);
  border-radius: 10px;
  background: #0e1629;
}
.admin-confirm-field input:focus { outline: 3px solid rgba(255,111,145,0.35); border-color: var(--red); }
.danger-button { width: 100%; padding: 12px 16px; color: white; font: inherit; font-weight: 850; border: 0; border-radius: 11px; background: var(--red); cursor: pointer; }
.danger-button:disabled { cursor: not-allowed; opacity: 0.38; }
.admin-status { min-height: 22px; margin-bottom: 0; font-size: 0.78rem; }
.midi-library-section { margin-top: 20px; padding-top: 20px; border-top: 1px solid var(--line); }
.midi-library-section h3 { margin: 0; font-size: 1.25rem; }
.midi-library-section > p { margin: 7px 0 13px; color: var(--muted); font-size: 0.78rem; line-height: 1.4; }
.midi-upload-button {
  display: grid;
  place-items: center;
  width: 100%;
  min-height: 42px;
  color: #071421;
  font-size: 0.82rem;
  font-weight: 900;
  border-radius: 11px;
  background: linear-gradient(135deg, var(--cyan), #a5f4ff);
  cursor: pointer;
}
.midi-library-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 17px; }
.midi-library-head strong { font-size: 0.86rem; }
.midi-library-head span { color: var(--cyan); font-size: 0.7rem; font-weight: 850; }
.midi-library-status { min-height: 18px; margin: 7px 0; color: #8f9bb8; font-size: 0.68rem; }
.midi-tune-list { display: grid; gap: 6px; max-height: 180px; margin: 0; padding: 0; overflow-y: auto; list-style: none; }
.midi-tune-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 9px; padding: 8px 9px; border-radius: 9px; background: rgba(255,255,255,0.045); }
.midi-tune-info { min-width: 0; }
.midi-tune-info strong { display: block; overflow: hidden; color: #e9edfa; font-size: 0.74rem; text-overflow: ellipsis; white-space: nowrap; }
.midi-tune-info small { display: block; margin-top: 2px; color: #7f8ba7; font-size: 0.61rem; }
.midi-tune-remove { padding: 6px 8px; color: #ffb6c5; font-size: 0.65rem; font-weight: 850; border: 1px solid rgba(255,111,145,0.28); border-radius: 7px; background: rgba(255,111,145,0.08); cursor: pointer; }
.midi-tune-empty { padding: 15px 9px; color: #7f8ba7; font-size: 0.72rem; text-align: center; border-radius: 9px; background: rgba(255,255,255,0.03); }

.game-footer { border-top: 1px solid var(--line); }
.midi-routing { display: flex; align-items: center; gap: 18px; min-width: 0; }
.midi-status { display: flex; align-items: center; gap: 9px; margin: 0; color: var(--muted); font-size: 0.86rem; }
.sound-output-controls { display: flex; align-items: center; gap: 10px; }
.output-picker { display: flex; align-items: center; gap: 8px; color: #9ca7c4; font-size: 0.76rem; white-space: nowrap; }
.output-picker[hidden] { display: none; }
.output-picker select {
  max-width: 210px;
  padding: 8px 28px 8px 10px;
  color: #e8edfb;
  font: inherit;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: #1a2440;
}
.output-picker select:focus-visible { outline: 3px solid rgba(88, 230, 255, 0.65); outline-offset: 2px; }
.output-picker select:disabled { cursor: not-allowed; opacity: 0.55; }
.actions { display: flex; gap: 9px; }
.secondary-button { padding: 10px 13px; color: #dbe2f6; background: var(--panel-soft); border: 1px solid var(--line); }
.secondary-button:disabled { cursor: not-allowed; opacity: 0.4; transform: none; }
.tip { margin: 0 6px; color: #8e99b7; text-align: center; font-size: 0.8rem; }
.tip strong { color: #c9d1e7; }

.hall-card {
  display: flex;
  min-height: 0;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: rgba(20,28,49,0.96);
  box-shadow: 0 24px 60px rgba(0,0,0,0.25);
}
.hall-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; padding: 17px 16px 13px; border-bottom: 1px solid var(--line); }
.hall-head h2 { margin: 0; font-size: 1.15rem; letter-spacing: -0.03em; }
.hall-tabs { display: flex; padding: 3px; border-radius: 9px; background: #0d1426; }
.hall-tab { padding: 7px 8px; color: #8591ae; font-size: 0.66rem; font-weight: 800; border: 0; border-radius: 7px; background: transparent; cursor: pointer; }
.hall-tab.active { color: #071421; background: var(--cyan); }
.hall-status { min-height: 32px; margin: 0; padding: 10px 16px 7px; color: #8490ac; font-size: 0.7rem; }
.hall-list { display: grid; gap: 5px; margin: 0; padding: 0 11px 13px; overflow-y: auto; list-style: none; }
.hall-row { display: grid; grid-template-columns: 28px minmax(0, 1fr) auto; align-items: center; gap: 7px; min-height: 38px; padding: 7px 8px; border-radius: 9px; background: rgba(255,255,255,0.035); }
.hall-row.top-three { background: linear-gradient(90deg, rgba(88,230,255,0.11), rgba(255,255,255,0.035)); }
.hall-rank { color: #8e99b5; font-size: 0.76rem; font-weight: 900; text-align: center; }
.hall-player { overflow: hidden; color: #e4e9f7; font-size: 0.78rem; font-weight: 750; text-overflow: ellipsis; white-space: nowrap; }
.hall-meta { display: block; margin-top: 2px; color: #77839f; font-size: 0.6rem; font-weight: 600; }
.hall-score { color: var(--green); font-size: 0.78rem; font-weight: 900; }
.hall-empty { padding: 24px 12px; color: #7f8aa6; text-align: center; font-size: 0.78rem; }

@media (max-width: 980px) {
  body { overflow-y: auto; }
  .app-shell { display: block; height: auto; min-height: 100dvh; padding: 20px 0 28px; }
  .topbar { margin-bottom: 18px; }
  .game-layout { grid-template-columns: 1fr; }
  .game-card { display: block; }
  .game-meta,
  .message-panel,
  .stage,
  .game-footer { grid-row: auto; }
  .stage { min-height: 430px; height: 60vh; }
  .hall-card { width: 100%; min-height: 300px; margin-top: 16px; }
  .tip { margin-top: 16px; }
}

@media (max-width: 700px) {
  .app-shell { width: min(100% - 18px, 1180px); padding-top: 14px; }
  .brand p { display: none; }
  .topbar { gap: 10px; }
  .topbar-controls { gap: 6px; }
  .first-note-toggle { padding: 9px; font-size: 0.7rem; }
  .midi-button { padding: 10px 12px; }
  .game-meta { align-items: flex-start; flex-direction: column; gap: 12px; }
  .game-stats { position: absolute; top: 71px; right: 18px; }
  .length-track { align-self: stretch; justify-content: center; }
  .length-line { flex: 1; max-width: 35px; }
  .stage { min-height: 420px; height: 62vh; }
  .game-footer { align-items: stretch; flex-direction: column; }
  .midi-routing { align-items: flex-start; flex-direction: column; gap: 10px; }
  .sound-output-controls { width: 100%; align-items: stretch; flex-direction: column; }
  .output-picker { width: 100%; justify-content: space-between; }
  .output-picker select { max-width: 55%; }
  .actions { display: grid; grid-template-columns: 1fr 1fr; }
  .secondary-button { font-size: 0.8rem; }
  .message-panel { grid-template-columns: auto minmax(0, 1fr); padding: 11px 14px; }
  .message-panel .attempt-dots { grid-column: 1 / -1; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: 0.01ms !important; animation-duration: 0.01ms !important; }
  .ambient-flying-note { display: none; }
}
