:root {
  --ink: #f4f1e8;
  --trash: #8a93a3;
  --recycle: #2f80ed;
  --compost: #4f9b3a;
  --danger: #e23b3b;
  --gold: #ffd23f;
  --pink: #ff3d7f;
  --purple: #2a1144;
}

* { box-sizing: border-box; }

html, body {
  margin: 0; height: 100%;
  background: #06040c;
  color: var(--ink);
  font-family: "Courier New", ui-monospace, monospace;
  overflow: hidden;
}

#stage {
  position: relative;
  width: 1280px; height: 720px;
  margin: 0 auto;
  max-width: 100vw; aspect-ratio: 16 / 9;
}

#game {
  width: 100%; height: 100%;
  display: block;
  background: #0a0716;
}

.overlay {
  position: absolute; inset: 0;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 12px;
  background: radial-gradient(ellipse at 50% 30%, rgba(60,20,90,0.9), rgba(6,4,12,0.97));
  text-align: center; padding: 24px;
}
.hidden { display: none !important; }

/* ---- Touch controls (mobile/tablet stand-in for MIDI pad + keyboard) ---- */
.touch-controls {
  position: absolute; left: 0; right: 0; bottom: 0;
  display: flex; gap: 10px; justify-content: center;
  padding: 10px 14px calc(10px + env(safe-area-inset-bottom));
  background: linear-gradient(rgba(6,4,12,0), rgba(6,4,12,0.85) 40%);
  touch-action: none;
}
.tbtn {
  flex: 1 1 0; max-width: 160px;
  font-family: inherit; font-weight: bold; font-size: 13px; letter-spacing: 1px;
  line-height: 1.5; color: #06040c;
  padding: 10px 6px; border: none; border-radius: 12px;
  border-bottom: 4px solid rgba(0,0,0,0.35);
  cursor: pointer; touch-action: manipulation;
}
.tbtn:active { transform: translateY(2px); border-bottom-width: 2px; }
.tbtn.trash { background: var(--trash); }
.tbtn.recycle { background: var(--recycle); color: #fff; }
.tbtn.compost { background: var(--compost); color: #fff; }
.tbtn.rinse { background: var(--gold); }

/* ---- Title / marquee ---- */
.marquee-title {
  border: 4px solid var(--gold);
  border-radius: 14px;
  padding: 14px 40px;
  box-shadow: 0 0 0 4px #06040c, 0 0 40px rgba(255,210,63,0.5);
  background: linear-gradient(180deg, #3a1560, #1a0a2e);
  position: relative;
}
.marquee-title::before, .marquee-title::after {
  content: "";
  position: absolute; left: 8px; right: 8px; height: 8px;
  background-image: radial-gradient(circle, var(--gold) 38%, transparent 42%);
  background-size: 22px 8px;
  animation: chase 0.8s steps(2) infinite;
}
.marquee-title::before { top: -2px; }
.marquee-title::after { bottom: -2px; }
@keyframes chase { to { background-position: 22px 0; } }

h1 {
  font-size: 60px; margin: 0; letter-spacing: 4px;
  color: #fff;
  text-shadow: 0 0 12px var(--pink), 3px 3px 0 var(--pink), 6px 6px 0 #7a1540;
}
h2 { font-size: 40px; margin: 0; color: var(--gold); }
.host { margin: 10px auto 0; color: var(--gold); font-size: 15px; letter-spacing: 1px; max-width: 540px; line-height: 1.4; }

/* ---- Rules legend ---- */
.rules {
  display: grid; grid-template-columns: 1fr 1fr 1fr;
  gap: 8px 18px; margin: 6px 0; max-width: 720px;
  font-size: 14px;
}
.rule { display: flex; align-items: center; gap: 8px; justify-content: center; }
.rule.full { grid-column: 1 / -1; opacity: 0.9; }
.chip {
  display: inline-block; padding: 3px 10px; border-radius: 20px;
  font-weight: bold; color: #06040c; font-size: 13px;
}
.chip.trash { background: var(--trash); }
.chip.recycle { background: var(--recycle); color: #fff; }
.chip.compost { background: var(--compost); color: #fff; }

/* ---- Buttons ---- */
.btnrow { display: flex; gap: 12px; flex-wrap: wrap; justify-content: center; }
button { font-family: inherit; cursor: pointer; letter-spacing: 1px; }
button.big {
  font-size: 22px; padding: 16px 38px;
  background: var(--pink); color: #fff; border: none;
  border-bottom: 5px solid #b71b54; border-radius: 10px;
  box-shadow: 0 0 24px rgba(255,61,127,0.5);
}
button.big:hover { filter: brightness(1.1); }
button.ghost {
  font-size: 15px; padding: 10px 20px;
  background: transparent; color: var(--gold);
  border: 2px solid var(--gold); border-radius: 8px;
}
button.ghost:disabled { opacity: 0.35; cursor: not-allowed; }

.midi-status {
  font-size: 13px; padding: 5px 12px;
  border: 1px solid #553; border-radius: 4px; opacity: 0.85;
}
.midi-status.ok { color: var(--compost); border-color: var(--compost); }

.calib-readout { font-size: 22px; color: var(--gold); min-height: 30px; }
#calibPrompt { font-size: 22px; }

/* ---- Name entry ---- */
.ready-player { font-size: 30px; color: var(--gold); letter-spacing: 3px; margin: 0; }
.ready-sub { font-size: 20px; opacity: 0.85; margin: 4px 0 10px; }
#nameInput {
  font-family: inherit; font-size: 30px; text-align: center; text-transform: uppercase;
  letter-spacing: 3px; color: #fff; background: rgba(0,0,0,0.4);
  border: 3px solid var(--gold); border-radius: 10px;
  padding: 12px 20px; width: 380px; max-width: 80vw; margin-bottom: 8px; outline: none;
}
#nameInput::placeholder { color: #8a7f5c; letter-spacing: 2px; }

/* ---- Results ---- */
.result-player { font-size: 26px; color: var(--gold); letter-spacing: 2px; margin: 0; }
.result-round { font-size: 15px; color: var(--pink); letter-spacing: 3px; margin: 2px 0 6px; }
.share-msg { font-size: 13px; color: var(--compost); min-height: 16px; }
.lb-title { font-size: 12px; letter-spacing: 2px; color: #9b8f6c; margin-bottom: 4px; text-align: center; }
.leaderboard .lbrow small { color: #9b8f6c; font-weight: normal; }
.grade {
  font-size: 96px; font-weight: bold; line-height: 1;
  color: var(--gold);
  text-shadow: 0 0 24px var(--gold), 4px 4px 0 #7a1540;
}
.tally {
  font-size: 17px; line-height: 1.9; min-width: 360px;
  background: rgba(0,0,0,0.35); padding: 12px 24px; border-radius: 10px;
  border: 1px solid #443;
}
.tally .row { display: flex; justify-content: space-between; gap: 40px; }
.tally .row b { color: var(--gold); }
.final { font-size: 64px; font-weight: bold; color: #fff; text-shadow: 0 0 20px var(--pink); }
.final-label { margin: 0; letter-spacing: 4px; color: var(--gold); font-size: 14px; }
.leaderboard {
  font-size: 15px; line-height: 1.7; min-width: 360px;
  margin-top: 6px;
}
.leaderboard .lbrow { display: flex; justify-content: space-between; padding: 2px 14px; }
.leaderboard .lbrow.you { background: rgba(255,210,63,0.15); border-radius: 6px; }
.leaderboard .crown { color: var(--gold); }
