:root {
  color-scheme: dark;
  --bg: #050b14;
  --panel: rgba(12, 25, 43, 0.82);
  --panel-strong: rgba(8, 18, 33, 0.96);
  --line: rgba(132, 205, 255, 0.16);
  --text: #edf8ff;
  --muted: #8da8bb;
  --cyan: #55e6ff;
  --pink: #ff6fd8;
  --yellow: #ffd166;
  --green: #7cf29a;
  --danger: #ff647c;
  --radius: 22px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html, body { min-height: 100%; }
body {
  margin: 0;
  background:
    radial-gradient(circle at 15% 20%, rgba(31, 170, 255, 0.12), transparent 32%),
    radial-gradient(circle at 85% 10%, rgba(255, 70, 197, 0.1), transparent 30%),
    linear-gradient(145deg, #030711, #07111f 55%, #030813);
  color: var(--text);
  overflow-x: hidden;
}
button, input { font: inherit; }
button { color: inherit; }
.hidden { display: none !important; }

.ambient { position: fixed; width: 420px; height: 420px; border-radius: 999px; filter: blur(100px); opacity: 0.13; pointer-events: none; }
.ambient-a { background: var(--cyan); top: -160px; left: -100px; }
.ambient-b { background: var(--pink); bottom: -180px; right: -130px; }

.app-shell { width: min(1480px, 100%); min-height: 100vh; margin: auto; padding: 18px clamp(14px, 3vw, 42px) 38px; position: relative; z-index: 1; }
.topbar { display: flex; align-items: center; gap: 18px; min-height: 66px; }
.brand { display: inline-flex; align-items: center; gap: 11px; color: var(--text); text-decoration: none; letter-spacing: 0.11em; }
.brand-mark { display: grid; place-items: center; width: 42px; height: 42px; border-radius: 13px; color: #04101b; font-weight: 1000; font-size: 22px; background: linear-gradient(135deg, var(--cyan), var(--green)); box-shadow: 0 0 35px rgba(85,230,255,.28); }
.brand strong, .brand em { display: block; font-style: normal; line-height: 1; }
.brand strong { font-size: 17px; }
.brand em { color: var(--cyan); font-size: 11px; margin-top: 4px; }
.room-badge { margin-left: auto; padding: 9px 13px; border: 1px solid var(--line); border-radius: 999px; color: var(--muted); background: rgba(255,255,255,.035); }
.room-badge strong { color: var(--yellow); letter-spacing: .18em; margin-left: 5px; }
.icon-button { margin-left: auto; width: 42px; height: 42px; border: 1px solid var(--line); border-radius: 13px; background: rgba(255,255,255,.04); cursor: pointer; }
.room-badge + .icon-button { margin-left: 0; }

.glass { background: linear-gradient(160deg, rgba(18,37,61,.9), rgba(6,15,28,.82)); border: 1px solid var(--line); box-shadow: 0 20px 70px rgba(0,0,0,.32), inset 0 1px rgba(255,255,255,.04); backdrop-filter: blur(18px); }
.landing-view { min-height: calc(100vh - 110px); display: grid; grid-template-columns: minmax(0, 1.2fr) minmax(320px, .75fr); gap: clamp(32px, 7vw, 100px); align-items: center; padding: 50px 4vw 90px; }
.eyebrow { margin: 0 0 15px; color: var(--cyan); font-size: 12px; font-weight: 800; letter-spacing: .18em; text-transform: uppercase; }
.hero-copy h1 { margin: 0; font-size: clamp(48px, 7.7vw, 108px); line-height: .9; letter-spacing: -.065em; max-width: 890px; }
.hero-copy h1 span { background: linear-gradient(90deg, var(--cyan), var(--green) 45%, var(--yellow)); -webkit-background-clip: text; color: transparent; }
.lead { max-width: 690px; margin: 28px 0 22px; color: #b5cad8; font-size: clamp(16px, 1.5vw, 20px); line-height: 1.65; }
.feature-pills { display: flex; flex-wrap: wrap; gap: 9px; }
.feature-pills span { padding: 9px 13px; border-radius: 999px; border: 1px solid var(--line); color: #cbe0ed; background: rgba(255,255,255,.035); font-size: 13px; }
.start-card { width: 100%; padding: 28px; border-radius: var(--radius); }
.start-card label { display: block; color: var(--muted); margin-bottom: 8px; font-size: 13px; }
input { width: 100%; min-height: 50px; border: 1px solid rgba(157,215,255,.22); border-radius: 14px; outline: none; background: rgba(0,0,0,.24); color: var(--text); padding: 0 15px; transition: .2s; }
input:focus { border-color: var(--cyan); box-shadow: 0 0 0 4px rgba(85,230,255,.09); }
.primary-button, .secondary-button { min-height: 50px; border-radius: 14px; border: 0; padding: 0 18px; font-weight: 850; cursor: pointer; transition: transform .15s, filter .15s, opacity .15s; }
.primary-button { width: 100%; margin-top: 12px; color: #03101a; background: linear-gradient(135deg, var(--cyan), var(--green)); box-shadow: 0 10px 35px rgba(85,230,255,.19); }
.secondary-button { border: 1px solid var(--line); background: rgba(255,255,255,.06); }
.primary-button:hover, .secondary-button:hover { transform: translateY(-1px); filter: brightness(1.08); }
.primary-button:disabled { opacity: .45; cursor: not-allowed; transform: none; }
.join-row { display: grid; grid-template-columns: 1fr auto; gap: 9px; }
.join-row input { text-transform: uppercase; font-weight: 900; letter-spacing: .2em; }
.divider { display: flex; align-items: center; gap: 11px; margin: 18px 0; color: #6f899c; font-size: 12px; }
.divider::before, .divider::after { content: ""; height: 1px; background: var(--line); flex: 1; }
.inline-error { min-height: 20px; color: #ff8ea0; font-size: 13px; margin: 12px 0 0; }
.privacy-note { color: #617b8e; font-size: 11px; line-height: 1.5; margin: 8px 0 0; }

.lobby-view { min-height: calc(100vh - 100px); display: grid; grid-template-columns: minmax(0, 720px) minmax(260px, 370px); gap: 24px; align-content: center; justify-content: center; }
.lobby-panel, .rules-card { border-radius: var(--radius); padding: clamp(24px, 4vw, 42px); }
.lobby-panel h2 { margin: 0 0 25px; font-size: clamp(32px, 5vw, 58px); letter-spacing: -.04em; }
.share-code { display: grid; grid-template-columns: 1fr auto; gap: 12px; align-items: center; padding: 14px 14px 14px 20px; background: rgba(0,0,0,.25); border: 1px solid var(--line); border-radius: 16px; }
.share-code span { font-size: clamp(26px, 5vw, 42px); font-weight: 1000; letter-spacing: .22em; color: var(--yellow); }
.lobby-players { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin: 22px 0 12px; }
.lobby-player { display: flex; align-items: center; gap: 11px; padding: 13px; border-radius: 14px; background: rgba(255,255,255,.04); border: 1px solid var(--line); }
.player-dot { width: 12px; height: 12px; border-radius: 50%; box-shadow: 0 0 16px currentColor; }
.lobby-hint, .host-hint { color: var(--muted); font-size: 13px; }
.rules-card h3 { margin-top: 0; }
.rules-card ol { padding-left: 21px; color: #b7cbd8; line-height: 1.7; }
.rules-card li { margin: 10px 0; }

.game-view { display: grid; grid-template-columns: minmax(0, 1fr) 310px; gap: 14px; align-items: start; }
.game-main { min-width: 0; }
.status-strip { display: grid; grid-template-columns: repeat(4, minmax(80px, 1fr)) minmax(130px, 1.2fr); gap: 1px; border-radius: 17px; overflow: hidden; margin: 8px 0 12px; }
.status-strip > div { padding: 12px 16px; background: rgba(2,10,19,.34); }
.status-strip span { display: block; color: #7590a2; font-size: 10px; letter-spacing: .12em; text-transform: uppercase; }
.status-strip strong { display: block; margin-top: 4px; font-size: 18px; }
.meter { height: 7px; border-radius: 99px; background: rgba(255,255,255,.08); margin-top: 9px; overflow: hidden; }
.meter i { display: block; height: 100%; width: 100%; border-radius: inherit; background: linear-gradient(90deg, var(--pink), var(--yellow)); transition: width .2s; }
.board-wrap { position: relative; width: 100%; border-radius: var(--radius); overflow: hidden; aspect-ratio: 1000 / 620; min-height: 390px; }
#gameCanvas { width: 100%; height: 100%; display: block; cursor: crosshair; touch-action: manipulation; }
.wave-banner { position: absolute; top: 50%; left: 50%; transform: translate(-50%,-50%); padding: 15px 28px; border-radius: 16px; background: rgba(3,10,20,.89); border: 1px solid var(--cyan); color: var(--cyan); font-size: clamp(24px, 4vw, 48px); font-weight: 1000; text-transform: uppercase; letter-spacing: .08em; animation: pop .6s both; pointer-events: none; }
.toast { position: absolute; left: 50%; bottom: 20px; transform: translateX(-50%); max-width: 80%; padding: 10px 16px; border-radius: 999px; background: rgba(3,10,20,.92); border: 1px solid var(--line); box-shadow: 0 12px 30px rgba(0,0,0,.3); font-size: 13px; pointer-events: none; }
@keyframes pop { from { transform: translate(-50%,-50%) scale(.8); opacity: 0; } }
.controls { margin-top: 12px; border-radius: 17px; display: flex; justify-content: space-between; gap: 16px; padding: 10px; }
.control-group { display: flex; align-items: center; gap: 8px; min-width: 0; }
.control-label { color: #7893a7; font-size: 10px; text-transform: uppercase; letter-spacing: .12em; padding: 0 5px; }
.tower-button { display: flex; align-items: center; gap: 8px; min-height: 48px; padding: 6px 12px; border-radius: 13px; border: 1px solid transparent; background: rgba(255,255,255,.045); cursor: pointer; }
.tower-button.active { border-color: var(--cyan); background: rgba(85,230,255,.1); }
.tower-button b { font-size: 20px; }
.tower-button span, .tower-button small { display: block; text-align: left; }
.tower-button span { font-size: 12px; font-weight: 800; }
.tower-button small { color: var(--yellow); margin-top: 2px; }
.color-controls small { color: #6e8799; font-size: 10px; }
.color-button { width: 34px; height: 34px; border: 3px solid transparent; border-radius: 50%; cursor: pointer; box-shadow: inset 0 0 0 2px rgba(0,0,0,.3); }
.color-button.active { border-color: white; transform: scale(1.08); }
.color-button[data-color="cyan"] { background: var(--cyan); }
.color-button[data-color="pink"] { background: var(--pink); }
.color-button[data-color="yellow"] { background: var(--yellow); }
.color-button[data-color="green"] { background: var(--green); }

.sidebar { display: grid; gap: 12px; padding-top: 8px; }
.side-card { border-radius: 17px; padding: 15px; }
.side-heading { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.side-heading h3, .legend-card h3 { margin: 0; font-size: 14px; }
.side-heading span { color: var(--green); font-size: 10px; text-transform: uppercase; letter-spacing: .13em; }
.scoreboard { display: grid; gap: 7px; }
.score-row { display: grid; grid-template-columns: 25px 1fr auto; gap: 8px; align-items: center; padding: 9px; border-radius: 11px; background: rgba(255,255,255,.035); }
.score-row.me { outline: 1px solid rgba(255,255,255,.14); }
.score-rank { color: #678195; font-size: 11px; }
.score-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 12px; }
.score-value { color: var(--yellow); font-weight: 900; font-size: 12px; }
.event-log { display: grid; gap: 7px; max-height: 230px; overflow: hidden; }
.event-item { color: #8ea7b8; font-size: 11px; line-height: 1.45; padding-left: 10px; border-left: 2px solid rgba(85,230,255,.25); }
.legend-card p { color: #829bad; font-size: 11px; line-height: 1.55; margin-bottom: 0; }

.modal { position: fixed; inset: 0; z-index: 20; display: grid; place-items: center; padding: 20px; background: rgba(1,5,12,.74); backdrop-filter: blur(10px); }
.modal-card { width: min(520px, 100%); border-radius: 24px; background: linear-gradient(160deg, #142b47, #07111f); border: 1px solid rgba(142,220,255,.23); padding: clamp(24px, 5vw, 40px); box-shadow: 0 30px 120px rgba(0,0,0,.55); }
.challenge-meta { display: flex; justify-content: space-between; color: var(--cyan); text-transform: uppercase; letter-spacing: .13em; font-size: 11px; }
.challenge-meta b { display: grid; place-items: center; width: 34px; height: 34px; border-radius: 50%; border: 1px solid var(--line); }
.challenge-card h2, .end-card h2 { margin: 8px 0 12px; font-size: clamp(28px, 6vw, 48px); letter-spacing: -.04em; }
.challenge-card p, .end-card > p { color: #b9cedb; line-height: 1.6; }
.challenge-options { display: grid; grid-template-columns: repeat(2, 1fr); gap: 9px; margin-top: 22px; }
.challenge-option { min-height: 58px; border: 1px solid var(--line); border-radius: 14px; background: rgba(255,255,255,.055); cursor: pointer; font-weight: 800; }
.challenge-option:hover { border-color: var(--cyan); background: rgba(85,230,255,.1); }
.final-scores { display: grid; gap: 8px; margin: 20px 0; }
.final-row { display: grid; grid-template-columns: 32px 1fr auto; gap: 8px; padding: 12px; border-radius: 13px; background: rgba(255,255,255,.05); }
.final-row:first-child { outline: 1px solid var(--yellow); }

@media (max-width: 1050px) {
  .game-view { grid-template-columns: 1fr; }
  .sidebar { grid-template-columns: repeat(3, 1fr); }
  .event-log { max-height: 150px; }
}
@media (max-width: 780px) {
  .app-shell { padding: 10px 10px 25px; }
  .landing-view { grid-template-columns: 1fr; padding: 38px 6px 55px; }
  .hero-copy h1 { font-size: clamp(50px, 15vw, 78px); }
  .lobby-view { grid-template-columns: 1fr; align-content: start; padding-top: 30px; }
  .rules-card { display: none; }
  .game-view { gap: 8px; }
  .status-strip { grid-template-columns: repeat(4, 1fr); }
  .energy-status { grid-column: 1 / -1; }
  .status-strip > div { padding: 8px 9px; }
  .status-strip strong { font-size: 14px; }
  .board-wrap { min-height: 0; border-radius: 15px; }
  .controls { flex-direction: column; }
  .control-group { overflow-x: auto; padding-bottom: 2px; }
  .tower-button { flex: 0 0 auto; }
  .sidebar { grid-template-columns: 1fr 1fr; }
  .legend-card { display: none; }
  .color-controls small { display: none; }
}
@media (max-width: 500px) {
  .topbar { min-height: 56px; }
  .brand-mark { width: 36px; height: 36px; }
  .room-badge { font-size: 11px; }
  .lobby-players { grid-template-columns: 1fr; }
  .share-code { grid-template-columns: 1fr; }
  .share-code .secondary-button { width: 100%; }
  .sidebar { grid-template-columns: 1fr; }
  .side-card:nth-child(2) { display: none; }
  .challenge-options { grid-template-columns: 1fr; }
  .tower-button { padding: 5px 9px; }
}
