/* Color Tug-of-War — shared styles for host (big screen) and play (phone) */

:root {
  --bg: #0d1020;
  --panel: #181c30;
  --ink: #f2f4ff;
  --muted: #8b93b8;
  --r: #ff3b30;
  --g: #34c759;
  --b: #0a84ff;
  --c: #00b3e6;
  --m: #e6007e;
  --y: #ffd60a;
  --k: #20242c;
  --rgb-accent: #6ea8ff;
  --cmyk-accent: #e6007e;
  --good: #34c759;
  --bad: #ff453a;
  font-size: 16px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body { height: 100%; }

body {
  font-family: 'Avenir Next', 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--ink);
  overflow: hidden;
  -webkit-user-select: none;
  user-select: none;
}

button {
  font: inherit;
  border: 0;
  border-radius: 12px;
  cursor: pointer;
  color: var(--ink);
  background: #2a3052;
  padding: 0.6em 1.2em;
}
button:active { transform: scale(0.97); }
button.primary {
  background: linear-gradient(135deg, var(--b), var(--m));
  font-weight: 700;
}
button:disabled { opacity: 0.45; cursor: default; }

/* ════════ HOST (big screen) ════════ */

body.host { display: flex; flex-direction: column; }

.host header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  padding: 1rem 2rem 0.4rem;
}
.host header h1 {
  font-size: 1.6rem;
  letter-spacing: 0.04em;
  background: linear-gradient(90deg, var(--r), var(--g), var(--b), var(--c), var(--m), var(--y));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.host header .meta { color: var(--muted); font-size: 1.2rem; }
.host header .meta b { color: var(--ink); }

#stage {
  flex: 1;
  display: grid;
  grid-template-columns: 1fr 1.3fr 1fr;
  gap: 1rem;
  padding: 0.5rem 2rem 1rem;
  min-height: 0;
}

/* ── Team sides ── */

.side {
  display: flex;
  flex-direction: column;
  border-radius: 20px;
  padding: 1rem;
  min-height: 0;
  position: relative;
}
.side-RGB {
  background: radial-gradient(ellipse at 30% 20%, #14264d 0%, #0b0f22 70%);
  box-shadow: inset 0 0 60px rgba(10, 132, 255, 0.12);
}
.side-CMYK {
  background:
    radial-gradient(circle at 1px 1px, rgba(0, 0, 0, 0.16) 1px, transparent 0) 0 0 / 9px 9px,
    linear-gradient(165deg, #f6f3ec, #e8e2d6);
  color: #20242c;
}
.side h2 { font-size: 1.5rem; text-align: center; letter-spacing: 0.06em; }
.side-RGB h2 { text-shadow: 0 0 18px rgba(110, 168, 255, 0.8); }
.side-CMYK h2 { color: #20242c; }
.side .score { text-align: center; color: var(--muted); font-size: 0.95rem; margin-top: 2px; }
.side-CMYK .score { color: #7a7466; }
.team-stats { text-align: center; font-size: 1.05rem; font-weight: 600; margin-top: 4px; }
.side-CMYK .team-stats { color: #4a4438; }

.side.mixing { outline: 3px solid var(--rgb-accent); animation: pulse 1.4s infinite; }
.side-CMYK.mixing { outline-color: var(--cmyk-accent); }
@keyframes pulse {
  50% { outline-offset: 5px; }
}
.side.shake { animation: shake 0.5s; }
@keyframes shake {
  20% { transform: translate(3px, -2px); }
  40% { transform: translate(-4px, 2px); }
  60% { transform: translate(3px, 1px); }
  80% { transform: translate(-2px, -1px); }
}

.roster {
  list-style: none;
  margin-top: 0.5rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem 0.7rem;
  justify-content: center;
  font-size: 0.95rem;
  max-height: 5.2em;
  overflow: hidden;
}
.roster li { opacity: 0.9; white-space: nowrap; }
.roster li.off { opacity: 0.35; text-decoration: line-through; }
.roster li .tick { color: var(--good); font-weight: 700; }

/* Live team-average swatch, shown in each column during the mix. */
.live-mix {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.35rem;
  margin-top: 0.7rem;
}
.live-mix .lm-chip {
  width: clamp(64px, 8vw, 116px);
  aspect-ratio: 1;
  border-radius: 50%;
  background: #1c2138;
  border: 3px solid rgba(255, 255, 255, 0.18);
  box-shadow: 0 0 26px rgba(0, 0, 0, 0.35), inset 0 0 18px rgba(0, 0, 0, 0.25);
  transition: background 0.25s ease;
  display: flex;
  align-items: center;
  justify-content: center;
}
.live-mix .lm-de {
  font-size: 1.05rem;
  font-weight: 800;
  color: #fff;
  background: rgba(0, 0, 0, 0.5);
  padding: 2px 9px;
  border-radius: 999px;
  font-variant-numeric: tabular-nums;
}
.live-mix .lm-chip.empty { border-style: dashed; }
.live-mix .lm-chip.empty {
  background: repeating-linear-gradient(45deg, #2a3052 0 9px, #1c2138 9px 18px);
}
.side-CMYK .live-mix .lm-chip { border-color: rgba(60, 50, 30, 0.2); }
.side-CMYK .live-mix .lm-chip.empty {
  background: repeating-linear-gradient(45deg, #d8d0bf 0 9px, #c7bea8 9px 18px);
}
.live-mix .lm-cap { font-size: 0.85rem; font-weight: 600; color: var(--muted); }
.side-CMYK .live-mix .lm-cap { color: #7a7466; }

/* Colored channel bars of the team's current average (latecomer reference). */
.chan-bars {
  width: min(78%, 230px);
  margin: 0.6rem auto 0;
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}
.cbar { display: grid; grid-template-columns: 1.2em 1fr 2.6em; align-items: center; gap: 0.5rem; }
.cbar-label { font-weight: 800; text-align: center; }
.cbar-track { height: 0.7rem; border-radius: 999px; background: #2a3052; overflow: hidden; }
.side-CMYK .cbar-track { background: #d8d0bf; }
.cbar-fill { height: 100%; border-radius: 999px; transition: width 0.25s ease; }
.cbar-val { font-size: 0.85rem; font-variant-numeric: tabular-nums; text-align: right; color: var(--muted); }
.side-CMYK .cbar-val { color: #7a7466; }

.tower-wrap {
  flex: 1;
  position: relative;
  min-height: 0;
  margin-top: 0.6rem;
}
.tower { position: absolute; inset: 0; }

.block {
  position: absolute;
  left: 50%;
  width: 72%;
  transform: translateX(-50%);
  border-radius: 5px;
  transition: bottom 0.5s ease;
}
.block.sheet {
  background:
    linear-gradient(90deg, var(--c) 0 7%, var(--m) 7% 14%, var(--y) 14% 21%, var(--k) 21% 28%, #fdfdfa 28%);
  border: 1px solid #b9b2a2;
  box-shadow: 0 2px 3px rgba(0, 0, 0, 0.25);
}
.block.sheet::after {
  content: '✛';
  position: absolute;
  right: 7px;
  top: 50%;
  transform: translateY(-52%);
  font-size: 0.6em;
  color: #9a917d;
}
.block.screen {
  background: repeating-linear-gradient(90deg, #101727 0 6px, #0c1120 6px 12px);
  border: 2px solid #2c3a64;
  box-shadow: 0 0 14px rgba(10, 132, 255, 0.5), inset 0 0 8px rgba(52, 199, 89, 0.25);
}
.block.falling {
  animation: blockFall 0.65s ease-in forwards;
}
@keyframes blockFall {
  30% { transform: translateX(-50%) rotate(4deg); }
  100% { transform: translateX(70%) rotate(38deg) translateY(160px); opacity: 0; }
}

/* ── Gorilla ── */

.gorilla {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  width: clamp(64px, 9vw, 130px);
  transition: bottom 0.55s cubic-bezier(0.34, 1.3, 0.5, 1);
  z-index: 2;
}
.gorilla-svg { width: 100%; display: block; overflow: visible; }
.g-body, .g-head, .g-foot { fill: #3c4252; }
.side-CMYK .g-body, .side-CMYK .g-head, .side-CMYK .g-foot { fill: #4a4438; }
.g-belly, .g-face { fill: #8e96ad; }
.side-CMYK .g-belly, .side-CMYK .g-face { fill: #c9bfa8; }
.g-eye { fill: #11131c; }
.g-mouth { stroke: #11131c; stroke-width: 2.5; fill: none; stroke-linecap: round; }
.arm rect { fill: #3c4252; }
.side-CMYK .arm rect { fill: #4a4438; }
.arm {
  transform-box: fill-box;
  transform-origin: center 6px;
  transition: transform 0.4s ease;
}
.gorilla.cheer .arm-l { transform: rotate(-150deg); }
.gorilla.cheer .arm-r { transform: rotate(150deg); }
.gorilla.cheer { animation: hop 0.6s ease infinite alternate; }
@keyframes hop { to { margin-bottom: 14px; } }
.gorilla.sad { filter: saturate(0.4) brightness(0.75); }
.gorilla.sad .g-mouth { transform: translateY(4px) scaleY(-0.8); transform-origin: 60px 40px; transform-box: view-box; }

/* ── Center column ── */

#center {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  min-height: 0;
  text-align: center;
}

/* The in-game center is a 1fr / auto / 1fr grid: the QR lives in the top row,
   the circle in the middle, the message in the bottom row. Because the two 1fr
   rows are always equal, the circle stays dead-centre no matter how tall the QR
   or message are or how they change between phases — so it never jumps. */
#gameCenter {
  flex: 1;
  align-self: stretch;
  width: 100%;
  min-height: 0;
  display: grid;
  grid-template-rows: 1fr auto 1fr;
  justify-items: center;
  align-items: center;
}

/* In-game join QR, above the (now smaller) countdown circle. The extra
   margin-bottom puts clear air between the QR and the circle. */
#gameJoin {
  align-self: end;            /* sit at the bottom of the top row, near the circle */
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.4rem;
  margin-bottom: 2.4rem;
}
#gameQr {
  width: min(22vh, 230px);
  aspect-ratio: 1;            /* reserve square space before the image loads */
  background: #fff;
  padding: 8px;
  border-radius: 12px;
  display: block;
}
#gameJoinCap { color: var(--muted); font-size: 1rem; }
#gameJoinCap b { color: var(--ink); letter-spacing: 0.18em; font-size: 1.15em; }

.swatch-ring { position: relative; width: min(26vh, 19vw); aspect-ratio: 1; }
.swatch-ring svg { position: absolute; inset: -7%; width: 114%; height: 114%; transform: rotate(-90deg); }
.swatch-ring circle {
  fill: none;
  stroke-width: 5;
  stroke-linecap: round;
}
.swatch-ring .ring-bg { stroke: #2a3052; }
.swatch-ring .ring-fg { stroke: var(--g); transition: stroke 0.3s; }
.swatch-ring.urgent .ring-fg { stroke: var(--bad); }
#swatch {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  box-shadow: 0 0 60px rgba(255, 255, 255, 0.15), inset 0 0 30px rgba(0, 0, 0, 0.18);
}
#countdown {
  position: absolute;
  inset: auto 0 -3.2rem 0;
  font-size: 2.4rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

/* Lives in the bottom 1fr row, anchored just under the circle. Its height no
   longer affects the circle's position (the grid keeps the circle centred). */
#phaseMsg { align-self: start; font-size: 1.9rem; font-weight: 700; margin-top: 2.6rem; min-height: 2.4em; }
#phaseMsg small { display: block; font-size: 0.55em; color: var(--muted); font-weight: 500; margin-top: 0.3em; }

/* ── Lobby / QR card ── */

#lobbyCard {
  background: var(--panel);
  border-radius: 24px;
  padding: 1.6rem 2rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.8rem;
  max-width: 90%;
}
#lobbyCard img {
  width: min(30vh, 320px);
  border-radius: 14px;
  background: #fff;
  padding: 8px;
}
#roomCode { font-size: 3rem; font-weight: 800; letter-spacing: 0.35em; text-indent: 0.35em; }
#joinUrl { color: var(--muted); font-size: 1.1rem; }
#lobbyHint { color: var(--muted); font-size: 0.95rem; }
#lobbyConfig {
  display: flex;
  gap: 1.4rem;
  flex-wrap: wrap;
  justify-content: center;
}
#lobbyConfig label {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.3rem;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 600;
}
#lobbyConfig input {
  font: inherit;
  width: 5em;
  text-align: center;
  padding: 0.35em 0.4em;
  border-radius: 10px;
  border: 2px solid #2a3052;
  background: #11142a;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}
#startBtn { font-size: 1.4rem; padding: 0.7em 2em; margin-top: 0.4rem; }

/* ── Reveal & victory overlays ── */

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(8, 10, 22, 0.92);
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1.6rem;
  z-index: 10;
  text-align: center;
}
.overlay.show { display: flex; }

#revealRow { display: flex; align-items: center; gap: 4vw; }
.reveal-col { display: flex; flex-direction: column; align-items: center; gap: 0.7rem; }
.reveal-col .label { font-size: 1.3rem; font-weight: 700; letter-spacing: 0.05em; }
.reveal-swatch {
  width: min(22vh, 16vw);
  aspect-ratio: 1;
  border-radius: 50%;
  box-shadow: 0 0 40px rgba(0, 0, 0, 0.5), inset 0 0 24px rgba(0, 0, 0, 0.2);
}
.reveal-col.target .reveal-swatch { width: min(30vh, 21vw); box-shadow: 0 0 60px rgba(255, 255, 255, 0.22); }
.reveal-col.slide-l { animation: slideL 0.6s ease both; }
.reveal-col.slide-r { animation: slideR 0.6s ease both; }
@keyframes slideL { from { transform: translateX(-50vw); opacity: 0; } }
@keyframes slideR { from { transform: translateX(50vw); opacity: 0; } }
.deltae { font-size: 2.6rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.deltae small { font-size: 0.45em; color: var(--muted); font-weight: 600; }
.reveal-col .vals { color: var(--muted); font-size: 0.95rem; font-variant-numeric: tabular-nums; }
/* A team that didn't submit: hatched placeholder instead of a color swatch. */
.reveal-swatch.no-sub {
  background:
    repeating-linear-gradient(45deg, #2a3052 0 10px, #1c2138 10px 20px) !important;
  box-shadow: inset 0 0 24px rgba(0, 0, 0, 0.4);
}
.reveal-col.loser { opacity: 0.45; transition: opacity 0.5s; }
.reveal-col.winner .deltae { color: var(--good); }
#revealBanner { font-size: 2.6rem; font-weight: 800; min-height: 1.3em; }
#revealBanner.tie { color: var(--y); }

#victoryOverlay h2 { font-size: 4rem; }
#victoryOverlay .gorilla-stage { width: 200px; position: relative; height: 200px; }
#victoryOverlay .gorilla { position: static; transform: none; width: 200px; }
#victoryOverlay p { color: var(--muted); font-size: 1.4rem; }

.confetti {
  position: fixed;
  top: -20px;
  width: 10px;
  height: 16px;
  z-index: 11;
  animation: confettiFall linear forwards;
}
@keyframes confettiFall {
  to { transform: translateY(105vh) rotate(720deg); }
}

/* Firework burst particles — fired at reveal when a team hits ΔE ≤ 2.
   Above the reveal overlay so they're visible during the reveal. */
.firework {
  position: fixed;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  z-index: 14;
  pointer-events: none;
  box-shadow: 0 0 8px currentColor;
  animation: fireworkFly 1.2s ease-out forwards;
}
@keyframes fireworkFly {
  0% { transform: translate(0, 0) scale(1.2); opacity: 1; }
  70% { opacity: 1; }
  100% { transform: translate(var(--dx), var(--dy)) scale(0.3); opacity: 0; }
}

/* ── Host control footer ── */

#hostControls {
  display: flex;
  gap: 0.5rem;
  justify-content: center;
  padding: 0.4rem 0 0.7rem;
  opacity: 0.35;
  transition: opacity 0.2s;
}
#hostControls:hover { opacity: 1; }
#hostControls button { font-size: 0.8rem; padding: 0.4em 0.8em; background: #222742; }

.toast {
  position: fixed;
  bottom: 4rem;
  left: 50%;
  transform: translateX(-50%);
  background: var(--bad);
  padding: 0.7em 1.4em;
  border-radius: 12px;
  font-weight: 700;
  z-index: 20;
  animation: fadeOut 3s forwards;
}
@keyframes fadeOut { 0%, 70% { opacity: 1; } 100% { opacity: 0; } }

/* ════════ PLAY (phone controller) ════════ */

body.play {
  overflow: auto;
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  padding: 1rem;
  gap: 1rem;
}
body.play.team-CMYK {
  background:
    radial-gradient(circle at 1px 1px, rgba(0, 0, 0, 0.12) 1px, transparent 0) 0 0 / 8px 8px,
    linear-gradient(170deg, #f7f4ee, #eae4d8);
  color: #20242c;
}
body.play.team-CMYK .panel { background: #fffdf8; box-shadow: 0 2px 10px rgba(60, 50, 20, 0.12); }
body.play.team-CMYK .muted { color: #7a7466; }

.play .panel {
  background: var(--panel);
  border-radius: 18px;
  padding: 1.1rem;
}
.play .muted { color: var(--muted); }

#joinCard { margin: auto; width: 100%; max-width: 420px; display: flex; flex-direction: column; gap: 0.9rem; }
#joinCard h1 { font-size: 1.5rem; text-align: center; }
#joinCard input {
  font: inherit;
  font-size: 1.2rem;
  padding: 0.7em 1em;
  border-radius: 12px;
  border: 2px solid #2a3052;
  background: #11142a;
  color: var(--ink);
  text-align: center;
}
#joinCard input#roomInput { text-transform: uppercase; letter-spacing: 0.3em; }
#joinErr { color: var(--bad); text-align: center; min-height: 1.2em; font-weight: 600; }

#teamBanner {
  text-align: center;
  padding: 0.8rem;
  border-radius: 18px;
  font-weight: 800;
  font-size: 1.25rem;
  letter-spacing: 0.04em;
}
.team-RGB #teamBanner { background: linear-gradient(110deg, #2b0f12, #0f2b16, #0f1a2b); box-shadow: 0 0 24px rgba(10, 132, 255, 0.35); }
.team-CMYK #teamBanner { background: #fffdf8; box-shadow: 0 2px 10px rgba(60, 50, 20, 0.15); }
#teamBanner small { display: block; font-weight: 500; font-size: 0.75rem; opacity: 0.7; }

#statusMsg { text-align: center; font-size: 1.15rem; font-weight: 600; min-height: 1.4em; }

#timerBar { height: 8px; border-radius: 4px; background: #2a3052; overflow: hidden; }
.team-CMYK #timerBar { background: #d8d0bf; }
#timerFill { height: 100%; width: 100%; background: var(--good); border-radius: 4px; }
#timerFill.urgent { background: var(--bad); }

#swatches { display: flex; gap: 0.8rem; justify-content: center; }
.mini-swatch { flex: 1; max-width: 46%; text-align: center; }
.mini-swatch .chip { width: 100%; aspect-ratio: 1.5; border-radius: 14px; box-shadow: inset 0 0 14px rgba(0, 0, 0, 0.2); }
.mini-swatch .cap { font-size: 0.8rem; margin-top: 0.3rem; opacity: 0.75; font-weight: 600; }

.slider-row { display: grid; grid-template-columns: 2.2em 1fr 3em; align-items: center; gap: 0.7rem; margin: 0.85rem 0; }
.slider-row label { font-weight: 800; font-size: 1.1rem; text-align: center; }
.slider-row output { font-variant-numeric: tabular-nums; text-align: right; font-weight: 600; }
.slider-row input[type='range'] { width: 100%; height: 2.2rem; }

#submitBtn { width: 100%; font-size: 1.3rem; padding: 0.8em; }
#submitBtn.done { background: var(--good); color: #06250f; }

#resultCard { text-align: center; }
#resultCard h2 { font-size: 1.7rem; margin-bottom: 0.4rem; }
#resultCard .win { color: var(--good); }
#resultCard .lose { color: var(--bad); }
#resultCard .tie { color: var(--y); }
.result-swatches { display: flex; gap: 0.6rem; justify-content: center; margin-top: 0.7rem; }
.result-swatches div { width: 64px; height: 64px; border-radius: 12px; }
.result-swatches .no-sub { background: repeating-linear-gradient(45deg, #555 0 8px, #333 8px 16px); }
.team-CMYK .result-swatches .no-sub { background: repeating-linear-gradient(45deg, #cfc8b8 0 8px, #b3ab98 8px 16px); }
.result-deltas { margin-top: 0.5rem; font-variant-numeric: tabular-nums; }

.hidden { display: none !important; }
