* { box-sizing: border-box; }
:root {
  --bg: #060814;
  --bg2: #121a34;
  --fg: #f8fbff;
  --muted: #9aa8ca;
  --accent: #23d9ff;
  --accent2: #ff2bd6;
  --yellow: #ffe156;
  --green: #38ef7d;
  --orange: #ff9f1c;
  --danger: #ef4444;
  --border: #26365e;
}
html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background:
    radial-gradient(900px 560px at 20% 18%, rgba(35, 217, 255, .22), transparent 65%),
    radial-gradient(760px 520px at 80% 12%, rgba(255, 43, 214, .18), transparent 60%),
    linear-gradient(135deg, #060814 0%, #0b1028 48%, #12091f 100%);
  color: var(--fg);
  font-family: 'Inter', system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  overflow: hidden;
}
.hidden { display: none !important; }
.screen { width: 100vw; height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; }

.home-screen {
  position: relative;
  isolation: isolate;
  padding: clamp(20px, 4vw, 64px);
}
.home-screen::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -3;
  background-image:
    linear-gradient(rgba(255, 255, 255, .055) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, .055) 1px, transparent 1px);
  background-size: 36px 36px;
  mask-image: radial-gradient(circle at 50% 46%, black 0 52%, transparent 78%);
}
.home-screen::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -2;
  background:
    linear-gradient(180deg, transparent 0 55%, rgba(6, 8, 20, .78) 100%),
    repeating-linear-gradient(0deg, rgba(255, 255, 255, .04) 0 2px, transparent 2px 6px);
  pointer-events: none;
}
.home-shell {
  width: min(1080px, 100%);
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(340px, 440px);
  gap: clamp(28px, 6vw, 76px);
  align-items: center;
}
.home-copy {
  min-width: 0;
  text-shadow: 0 4px 28px rgba(0, 0, 0, .5);
}
.eyebrow {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 0 11px;
  border: 1px solid rgba(35, 217, 255, .45);
  color: var(--accent);
  background: rgba(6, 8, 20, .62);
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 2px;
  text-transform: uppercase;
  box-shadow: 0 0 22px rgba(35, 217, 255, .16);
}
.home-copy h1 {
  margin: 18px 0 12px;
  font-size: clamp(56px, 8vw, 112px);
  line-height: .86;
  letter-spacing: 0;
  font-weight: 950;
  text-transform: uppercase;
}
.home-copy .accent {
  display: block;
  color: var(--accent);
  text-shadow:
    0 0 16px rgba(35, 217, 255, .9),
    0 0 44px rgba(35, 217, 255, .42);
}
.home-copy .sub {
  max-width: 520px;
  margin: 0 0 28px;
  color: #c6d4ff;
  font-size: clamp(18px, 2vw, 24px);
  font-weight: 700;
}
.home-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}
.home-stats span {
  display: inline-flex;
  align-items: baseline;
  gap: 7px;
  min-height: 42px;
  padding: 0 13px;
  border: 1px solid rgba(255, 255, 255, .14);
  background: rgba(8, 12, 30, .72);
  color: #c6d4ff;
  font-size: 13px;
  font-weight: 800;
  text-transform: uppercase;
}
.home-stats b {
  color: var(--yellow);
  font-size: 22px;
}

.card {
  background: linear-gradient(180deg, rgba(18, 26, 52, 0.92), rgba(9, 13, 31, 0.94));
  border: 1px solid rgba(255, 255, 255, .12);
  border-radius: 8px;
  padding: 32px;
  width: min(520px, 95vw);
  box-shadow: 0 22px 80px rgba(0, 0, 0, 0.58), inset 0 1px 0 rgba(255, 255, 255, .08);
}
.home-card {
  position: relative;
  width: 100%;
  overflow: hidden;
  border-color: rgba(35, 217, 255, .35);
}
.home-card::before {
  content: "";
  position: absolute;
  inset: 0 0 auto;
  height: 4px;
  background: linear-gradient(90deg, var(--accent), var(--accent2), var(--yellow), var(--green));
}
.card h1 { font-size: 42px; margin: 0 0 4px; letter-spacing: 1px; }
.card h2 { margin: 0 0 8px; }
.card .sub { color: var(--muted); margin: 0 0 24px; }
.accent { color: var(--accent); }

label { display: block; margin-bottom: 16px; }
label span { display: block; font-size: 12px; color: var(--muted); margin-bottom: 6px; text-transform: uppercase; letter-spacing: 1px; font-weight: 800; }
input {
  width: 100%;
  padding: 13px 14px;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, .12);
  background: rgba(2, 5, 18, 0.68);
  color: var(--fg);
  font-size: 16px;
  font-weight: 700;
}
input:focus { outline: 2px solid var(--accent); border-color: transparent; box-shadow: 0 0 22px rgba(35, 217, 255, .22); }

button {
  background: linear-gradient(180deg, var(--accent2), #7c19ff);
  color: white;
  border: 0;
  padding: 12px 18px;
  border-radius: 8px;
  font-size: 16px;
  font-weight: 900;
  cursor: pointer;
  transition: transform .08s ease, filter .08s ease, box-shadow .08s ease;
  box-shadow: 0 10px 26px rgba(124, 25, 255, .28);
}
button:hover:not(:disabled) { transform: translateY(-1px); filter: saturate(1.12); box-shadow: 0 14px 34px rgba(124, 25, 255, .38); }
button:disabled { opacity: 0.4; cursor: not-allowed; }
button.primary { background: linear-gradient(180deg, var(--accent), #0891b2); }

.row { display: flex; gap: 8px; margin-top: 12px; }
.row input { flex: 1; }
.row button { flex-shrink: 0; }

.err { color: var(--danger); margin-top: 12px; min-height: 18px; }
.hint { color: var(--muted); font-size: 13px; margin: 12px 0 0; }

.mini-board {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  margin: 0 0 22px;
  padding: 12px;
  background:
    linear-gradient(rgba(255, 255, 255, .045) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, .045) 1px, transparent 1px),
    rgba(2, 5, 18, .54);
  background-size: 22px 22px;
  border: 1px solid rgba(255, 255, 255, .1);
  border-radius: 8px;
}
.cell {
  aspect-ratio: 1;
  min-height: 34px;
  border: 1px solid rgba(255, 255, 255, .34);
  box-shadow: inset 0 0 0 3px rgba(255, 255, 255, .12), 0 8px 20px rgba(0, 0, 0, .28);
}
.cell.empty { opacity: .16; box-shadow: none; background: rgba(255, 255, 255, .08); }
.c1 { background: linear-gradient(135deg, #23d9ff, #0878ff); }
.c2 { background: linear-gradient(135deg, #ff2bd6, #7c19ff); }
.c3 { background: linear-gradient(135deg, #ffe156, #ff9f1c); }
.c4 { background: linear-gradient(135deg, #38ef7d, #0fb15c); }
.c5 { background: linear-gradient(135deg, #ff4d4d, #c1121f); }

.tetromino {
  position: absolute;
  z-index: -1;
  width: calc(var(--block, 28px) * 4);
  height: calc(var(--block, 28px) * 4);
  opacity: .76;
  filter: drop-shadow(0 0 18px currentColor);
  pointer-events: none;
  animation-duration: var(--float-time, 14s);
  animation-timing-function: ease-in-out;
  animation-iteration-count: infinite;
}
.tetromino span {
  position: absolute;
  width: var(--block, 28px);
  height: var(--block, 28px);
  background: currentColor;
  border: 1px solid rgba(255, 255, 255, .4);
  box-shadow:
    inset 0 0 0 4px rgba(255, 255, 255, .13),
    inset -6px -6px 0 rgba(0, 0, 0, .16),
    0 8px 18px rgba(0, 0, 0, .24);
}

.piece-i {
  --block: 24px;
  --float-time: 16s;
  top: 11%;
  left: 7%;
  color: var(--accent);
  animation-name: floatOne;
}
.piece-o {
  --block: 25px;
  --float-time: 18s;
  top: 12%;
  right: 11%;
  color: var(--yellow);
  animation-name: floatTwo;
  animation-delay: -5s;
}
.piece-t {
  --block: 30px;
  --float-time: 15s;
  top: 35%;
  left: 16%;
  color: var(--accent2);
  animation-name: floatThree;
  animation-delay: -2s;
}
.piece-l {
  --block: 27px;
  --float-time: 17s;
  bottom: 12%;
  left: 11%;
  color: var(--orange);
  animation-name: floatFour;
  animation-delay: -8s;
}
.piece-j {
  --block: 23px;
  --float-time: 19s;
  bottom: 18%;
  right: 9%;
  color: #4d7cff;
  animation-name: floatFive;
  animation-delay: -3s;
}
.piece-s {
  --block: 26px;
  --float-time: 14s;
  bottom: 9%;
  right: 27%;
  color: var(--green);
  animation-name: floatSix;
  animation-delay: -6s;
}
.piece-z {
  --block: 22px;
  --float-time: 20s;
  top: 55%;
  right: 19%;
  color: #ff4d4d;
  animation-name: floatSeven;
  animation-delay: -10s;
}

.piece-i span:nth-child(1) { left: 0; top: var(--block); }
.piece-i span:nth-child(2) { left: var(--block); top: var(--block); }
.piece-i span:nth-child(3) { left: calc(var(--block) * 2); top: var(--block); }
.piece-i span:nth-child(4) { left: calc(var(--block) * 3); top: var(--block); }

.piece-o span:nth-child(1) { left: var(--block); top: var(--block); }
.piece-o span:nth-child(2) { left: calc(var(--block) * 2); top: var(--block); }
.piece-o span:nth-child(3) { left: var(--block); top: calc(var(--block) * 2); }
.piece-o span:nth-child(4) { left: calc(var(--block) * 2); top: calc(var(--block) * 2); }

.piece-t span:nth-child(1) { left: 0; top: var(--block); }
.piece-t span:nth-child(2) { left: var(--block); top: var(--block); }
.piece-t span:nth-child(3) { left: calc(var(--block) * 2); top: var(--block); }
.piece-t span:nth-child(4) { left: var(--block); top: calc(var(--block) * 2); }

.piece-l span:nth-child(1) { left: var(--block); top: 0; }
.piece-l span:nth-child(2) { left: var(--block); top: var(--block); }
.piece-l span:nth-child(3) { left: var(--block); top: calc(var(--block) * 2); }
.piece-l span:nth-child(4) { left: calc(var(--block) * 2); top: calc(var(--block) * 2); }

.piece-j span:nth-child(1) { left: calc(var(--block) * 2); top: 0; }
.piece-j span:nth-child(2) { left: calc(var(--block) * 2); top: var(--block); }
.piece-j span:nth-child(3) { left: calc(var(--block) * 2); top: calc(var(--block) * 2); }
.piece-j span:nth-child(4) { left: var(--block); top: calc(var(--block) * 2); }

.piece-s span:nth-child(1) { left: var(--block); top: var(--block); }
.piece-s span:nth-child(2) { left: calc(var(--block) * 2); top: var(--block); }
.piece-s span:nth-child(3) { left: 0; top: calc(var(--block) * 2); }
.piece-s span:nth-child(4) { left: var(--block); top: calc(var(--block) * 2); }

.piece-z span:nth-child(1) { left: 0; top: var(--block); }
.piece-z span:nth-child(2) { left: var(--block); top: var(--block); }
.piece-z span:nth-child(3) { left: var(--block); top: calc(var(--block) * 2); }
.piece-z span:nth-child(4) { left: calc(var(--block) * 2); top: calc(var(--block) * 2); }

@keyframes floatOne {
  0%, 100% { transform: translate3d(0, 0, 0) rotate(8deg); }
  35% { transform: translate3d(7vw, 8vh, 0) rotate(24deg); }
  70% { transform: translate3d(2vw, 18vh, 0) rotate(-8deg); }
}
@keyframes floatTwo {
  0%, 100% { transform: translate3d(0, 0, 0) rotate(-10deg); }
  42% { transform: translate3d(-9vw, 11vh, 0) rotate(8deg); }
  76% { transform: translate3d(-4vw, -3vh, 0) rotate(-22deg); }
}
@keyframes floatThree {
  0%, 100% { transform: translate3d(0, 0, 0) rotate(14deg); }
  45% { transform: translate3d(5vw, -12vh, 0) rotate(-20deg); }
  78% { transform: translate3d(10vw, 6vh, 0) rotate(32deg); }
}
@keyframes floatFour {
  0%, 100% { transform: translate3d(0, 0, 0) rotate(-16deg); }
  30% { transform: translate3d(12vw, -10vh, 0) rotate(11deg); }
  72% { transform: translate3d(4vw, -22vh, 0) rotate(-28deg); }
}
@keyframes floatFive {
  0%, 100% { transform: translate3d(0, 0, 0) rotate(18deg); }
  38% { transform: translate3d(-13vw, -7vh, 0) rotate(36deg); }
  80% { transform: translate3d(-5vw, 9vh, 0) rotate(-12deg); }
}
@keyframes floatSix {
  0%, 100% { transform: translate3d(0, 0, 0) rotate(-8deg); }
  36% { transform: translate3d(-8vw, -15vh, 0) rotate(18deg); }
  74% { transform: translate3d(6vw, -4vh, 0) rotate(-30deg); }
}
@keyframes floatSeven {
  0%, 100% { transform: translate3d(0, 0, 0) rotate(12deg); }
  40% { transform: translate3d(-7vw, 13vh, 0) rotate(-18deg); }
  82% { transform: translate3d(4vw, -9vh, 0) rotate(26deg); }
}

.player-list {
  max-height: 320px;
  overflow-y: auto;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 6px;
  margin: 16px 0;
}
.player-pill {
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 13px;
  display: flex;
  justify-content: space-between;
}
.player-pill.host { border-color: var(--accent); }
.player-pill .role { font-size: 10px; color: var(--accent); }
.player-pill.bot { opacity: 0.7; }
.player-pill.bot .role { color: var(--muted); }

/* === GAME LAYOUT === */
.game-grid {
  display: grid;
  grid-template-columns: 140px 320px 140px 1fr;
  grid-template-areas: "left main right opps";
  gap: 14px;
  width: 100vw;
  height: 100vh;
  padding: 14px;
}
.game-grid .side:nth-of-type(1) { grid-area: left; }
.game-grid .main { grid-area: main; display: flex; flex-direction: column; align-items: center; position: relative; }
.game-grid .side:nth-of-type(2) { grid-area: right; }
.opponents { grid-area: opps; display: flex; flex-direction: column; }

.side { display: flex; flex-direction: column; gap: 12px; }
.panel {
  background: rgba(15, 23, 42, 0.65);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px;
}
.panel-title { font-size: 11px; letter-spacing: 2px; color: var(--muted); margin-bottom: 6px; text-align: center; }
.panel-title.small { text-align: left; padding-left: 4px; }
.stats div { display: flex; justify-content: space-between; font-size: 13px; padding: 3px 0; }
.stats span { color: var(--muted); }
.stats b { color: var(--accent); }

.targets { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; }
.tgt {
  background: rgba(0, 0, 0, 0.3);
  color: var(--muted);
  padding: 6px 4px;
  font-size: 11px;
  border-radius: 6px;
  font-weight: 600;
}
.tgt.active { background: linear-gradient(180deg, var(--accent2), #6d28d9); color: white; }

.alive-panel #alive-count { font-size: 36px; font-weight: 800; text-align: center; color: var(--accent); }

#board { background: #0f172a; border-radius: 12px; border: 2px solid var(--border); display: block; }
#hold, #next { background: #0f172a; border-radius: 8px; display: block; margin: 0 auto; }
#mini { background: rgba(0, 0, 0, 0.2); border-radius: 12px; flex: 1; width: 100%; }

#attack-feed {
  position: absolute;
  top: 50%;
  right: -90px;
  width: 80px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  pointer-events: none;
}
.attack-toast {
  background: rgba(239, 68, 68, 0.85);
  padding: 4px 8px;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 700;
  animation: toast 2s ease forwards;
}
@keyframes toast {
  0% { transform: translateX(-30px); opacity: 0; }
  10% { transform: translateX(0); opacity: 1; }
  80% { transform: translateX(0); opacity: 1; }
  100% { transform: translateX(20px); opacity: 0; }
}

#music-ctl {
  position: fixed;
  top: 14px;
  right: 14px;
  z-index: 250;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px;
  border-radius: 999px;
  background: rgba(15, 23, 42, .85);
  border: 1px solid var(--border);
}
#music-ctl:hover { border-color: var(--accent); }
#btn-music {
  width: 38px;
  height: 38px;
  padding: 0;
  font-size: 18px;
  border-radius: 50%;
  background: transparent;
  border: 0;
  line-height: 1;
}
#music-vol {
  width: 0;
  opacity: 0;
  transition: width .2s ease, opacity .2s ease;
  accent-color: var(--accent);
  cursor: pointer;
}
#music-ctl:hover #music-vol,
#music-vol:focus {
  width: 110px;
  opacity: 1;
  margin-left: 10px;
}

/* === DEATH OVERLAY (arcade style) === */
#death-overlay {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    repeating-linear-gradient(0deg, rgba(0, 0, 0, 0.18) 0 2px, transparent 2px 4px),
    radial-gradient(900px 500px at 50% 40%, rgba(127, 29, 29, 0.45), rgba(5, 8, 20, 0.88));
  backdrop-filter: blur(3px);
}
.death-box { text-align: center; }
.death-title {
  font-family: Impact, 'Arial Black', 'Haettenschweiler', sans-serif;
  font-size: clamp(64px, 12vw, 130px);
  color: #ef4444;
  letter-spacing: 12px;
  line-height: 1;
  text-shadow:
    0 0 14px #ef4444,
    0 0 50px #dc2626,
    0 0 110px #991b1b,
    4px 4px 0 #450a0a;
  animation:
    deathSlam .5s cubic-bezier(.2, 2.2, .4, 1) both,
    deathFlicker 2.8s steps(1) .6s infinite;
}
.death-place {
  margin-top: 10px;
  font-size: 30px;
  font-weight: 800;
  color: #fbbf24;
  letter-spacing: 4px;
  text-shadow: 0 0 18px rgba(251, 191, 36, .7);
  min-height: 36px;
  animation: deathSlam .5s .12s cubic-bezier(.2, 2.2, .4, 1) both;
}
.death-buttons {
  margin-top: 34px;
  display: flex;
  gap: 14px;
  justify-content: center;
  animation: fadeUp .4s .3s both;
}
.death-btn {
  font-size: 15px;
  font-weight: 800;
  letter-spacing: 2px;
  text-transform: uppercase;
  padding: 14px 22px;
  border-radius: 8px;
  background: rgba(0, 0, 0, .45);
  color: var(--fg);
  border: 2px solid var(--border);
}
.death-btn:hover { border-color: var(--accent); box-shadow: 0 0 18px rgba(34, 211, 238, .35); }
.death-btn.primary { border-color: var(--accent); color: var(--accent); }
.death-btn.ghost { color: var(--muted); }
@keyframes deathSlam {
  from { transform: scale(2.6); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}
@keyframes deathFlicker {
  0%, 100% { opacity: 1; }
  7% { opacity: .82; }
  9% { opacity: 1; }
  53% { opacity: .75; }
  55% { opacity: 1; }
}
@keyframes fadeUp {
  from { transform: translateY(16px); opacity: 0; }
  to { transform: none; opacity: 1; }
}

#spectate-bar {
  position: fixed;
  left: 50%;
  bottom: 18px;
  transform: translateX(-50%);
  z-index: 150;
  display: flex;
  gap: 14px;
  align-items: center;
  background: rgba(15, 23, 42, .85);
  border: 1px solid var(--danger);
  border-radius: 999px;
  padding: 8px 10px 8px 18px;
  color: #fca5a5;
  font-weight: 700;
  letter-spacing: 2px;
  font-size: 13px;
  box-shadow: 0 0 24px rgba(239, 68, 68, .25);
}
#spectate-bar button { padding: 7px 14px; font-size: 13px; border-radius: 999px; }

#countdown {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  font-size: 200px;
  font-weight: 900;
  color: var(--accent);
  text-shadow: 0 0 40px var(--accent);
  z-index: 100;
  pointer-events: none;
}

@media (max-width: 1100px) {
  .game-grid {
    grid-template-columns: 100px 240px 100px 1fr;
    grid-template-rows: 1fr;
    gap: 8px;
    padding: 8px;
  }
  #board { width: 100%; height: auto; }
}

@media (max-width: 820px) {
  html, body { height: auto; min-height: 100%; overflow: auto; }
  .screen { min-height: 100vh; height: auto; }
  .home-screen {
    align-items: flex-start;
    padding: 58px 18px 28px;
  }
  .home-shell {
    grid-template-columns: 1fr;
    gap: 22px;
  }
  .home-copy h1 {
    font-size: clamp(46px, 16vw, 74px);
  }
  .home-copy .sub {
    font-size: 17px;
    margin-bottom: 18px;
  }
  .home-stats span {
    min-height: 36px;
    font-size: 12px;
  }
  .home-stats b { font-size: 18px; }
  .card { padding: 24px; }
  .mini-board {
    grid-template-columns: repeat(6, 1fr);
    gap: 4px;
    margin-bottom: 18px;
    padding: 10px;
  }
  .cell { min-height: 0; }
  .row {
    flex-direction: column;
  }
  .row button {
    width: 100%;
  }
  .tetromino {
    opacity: .34;
    scale: .78;
  }
  #music-ctl {
    top: 10px;
    right: 10px;
  }
}
