:root {
  --bg: #0d1b2a;
  --fg: #e0e1dd;
  --accent: #52b788;
  --accent-2: #f4a261;
  --danger: #e76f51;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: linear-gradient(180deg, #87ceeb 0%, #c9e9ff 60%, #d9f2ff 100%);
  color: var(--bg);
  font: 16px/1.4 system-ui, -apple-system, Segoe UI, Roboto, Ubuntu, Cantarell, Noto Sans, Helvetica, Arial, "Apple Color Emoji", "Segoe UI Emoji";
  display: grid;
  grid-template-rows: auto 1fr auto;
  min-height: 100vh;
}

.hud {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  background: rgba(255,255,255,0.7);
  backdrop-filter: blur(6px);
  position: sticky;
  top: 0;
}
.hud-left, .hud-right { display: flex; gap: 12px; align-items: center; }
.hud button {
  padding: 6px 10px;
  border-radius: 8px;
  border: 1px solid #0001;
  background: white;
  cursor: pointer;
}
.hud #muteBtn.active { background: #f3f3f3; }
.hud #songSelect {
  padding: 6px 8px;
  border-radius: 8px;
  border: 1px solid #0001;
  background: white;
}

#game {
  display: block;
  margin: 16px auto;
  width: 100%;
  max-width: 1100px;
  aspect-ratio: 16 / 9;
  height: auto;
  border-radius: 12px;
  background: #9fe7ff;
  box-shadow: 0 10px 30px #00000022;
}

.mobile-controls {
  display: none;
  position: fixed;
  left: 50%;
  bottom: 10px;
  transform: translateX(-50%);
  gap: 10px;
  grid-template-columns: repeat(5, minmax(64px, 1fr));
  width: min(96vw, 640px);
  background: rgba(255,255,255,0.7);
  backdrop-filter: blur(6px);
  padding: 8px;
  border-radius: 12px;
  box-shadow: 0 8px 20px #00000022;
}
.mobile-controls .ctl {
  font-size: 16px;
  padding: 10px 8px;
  border-radius: 10px;
  border: 1px solid #0001;
  background: white;
  touch-action: manipulation;
}

@media (pointer: coarse), (max-width: 780px) {
  .mobile-controls { display: grid; }
}

.overlay {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(0,0,0,0.35);
}
.overlay.hidden { display: none; }
.panel {
  width: min(1000px, 95vw);
  background: white;
  padding: 20px;
  border-radius: 12px;
  box-shadow: 0 10px 40px #00000055;
}
.panel-grid { display: grid; grid-template-columns: 1.5fr 1fr; gap: 16px; align-items: start; }
.panel-right { background: #f9fafb; border: 1px solid #00000010; border-radius: 10px; padding: 10px; max-height: 300px; overflow: auto; }
.panel-right h3 { margin: 0 0 8px; font-size: 16px; }
.panel-left h1 { margin-top: 0; }
.panel-left button { margin-top: 8px; }

@media (max-width: 780px) {
  .panel { width: min(92vw, 720px); }
  .panel-grid { grid-template-columns: 1fr; }
}
.controls { margin: 8px 0 16px; }
.controls li { margin: 4px 0; }
.primary { background: var(--accent); color: white; border: none; padding: 10px 16px; border-radius: 10px; }

.message {
  position: fixed;
  left: 50%;
  top: 20px;
  transform: translateX(-50%);
  background: rgba(0,0,0,0.8);
  color: white;
  padding: 10px 16px;
  border-radius: 999px;
  opacity: 0;
  transition: opacity .25s ease;
  pointer-events: none;
}
.message.show { opacity: 1; }
.message.hidden { display: none; }

.leaderboard {
  max-width: 1100px;
  margin: 12px auto 20px;
  padding: 12px;
  background: rgba(255,255,255,0.75);
  border: 1px solid #0001;
  border-radius: 10px;
}
.leaderboard h2 { margin: 0 0 8px; font-size: 18px; }
.lb-list { margin: 0; padding-left: 20px; }
.lb-list li { margin: 4px 0; }
.lb-note { margin: 8px 0 0; opacity: .8; font-size: 14px; }

dialog {
  border: none;
  border-radius: 12px;
  width: min(720px, 92vw);
}
dialog::backdrop { background: rgba(0,0,0,0.35); }
dialog header { display: flex; align-items: center; gap: 12px; }
dialog header .spacer { flex: 1; }
.hat-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px,1fr)); gap: 12px; margin: 12px 0; }
.hat {
  background: #f7f7f7;
  border: 1px solid #0001;
  border-radius: 10px;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.hat .preview { height: 80px; background: white; border-radius: 8px; display: grid; place-items: center; font-size: 32px; }
.hat button { padding: 6px 10px; border-radius: 8px; cursor: pointer; }
.hat .owned { color: var(--accent); font-weight: 600; }
.hat .equipped { color: var(--accent-2); font-weight: 600; }

/* Canvas fills available middle row; no special mobile override needed */

.site-footer {
  margin-top: 8px;
  background: rgba(255,255,255,0.8);
  border-top: 1px solid #0001;
}
.site-footer .footer-inner {
  max-width: 1100px;
  margin: 0 auto;
  padding: 10px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}
.site-footer .footer-left, .site-footer .footer-right { display: flex; gap: 12px; align-items: center; }
.site-footer a { color: inherit; text-decoration: none; border-bottom: 1px dashed #0003; }
.site-footer a:hover { border-bottom-style: solid; }
.site-footer .music-attr { opacity: .8; }
