@import url("https://fonts.googleapis.com/css2?family=Bowlby+One&family=DM+Sans:opsz,wght@9..40,400;9..40,600;9..40,800&family=JetBrains+Mono:wght@500&display=swap");

:root {
  --bg: #14101f;
  --bg-2: #1f1830;
  --panel: #2a2140;
  --line: #3d3259;
  --text: #f6f1ff;
  --muted: #a99cc8;
  --hot: #ff3d7f;
  --sun: #ffd23f;
  --mint: #3df5b5;
  --sky: #5ac8ff;
  --danger: #ff6b5a;
  --radius: 18px;
  --display: "Bowlby One", "Arial Black", sans-serif;
  --body: "DM Sans", system-ui, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  background:
    radial-gradient(1200px 600px at 10% -10%, #3a1f5c 0%, transparent 60%),
    radial-gradient(900px 500px at 110% 110%, #4a1636 0%, transparent 60%),
    var(--bg);
  background-attachment: fixed;
  color: var(--text);
  font-family: var(--body);
  font-size: 17px;
  line-height: 1.4;
  -webkit-tap-highlight-color: transparent;
}

h1, h2, h3, .display { font-family: var(--display); font-weight: 400; letter-spacing: 0.01em; margin: 0; }
a { color: var(--sun); }
.muted { color: var(--muted); }
.mono { font-family: var(--mono); }
.hidden { display: none !important; }

/* ---------- logo ---------- */
.logo {
  font-family: var(--display);
  font-size: clamp(42px, 9vw, 96px);
  line-height: 0.9;
  display: inline-flex;
  gap: 0.18em;
  align-items: baseline;
}
.logo .clip { color: var(--sun); transform: rotate(-4deg); display: inline-block; }
.logo .game {
  color: var(--bg);
  background: var(--hot);
  padding: 0.05em 0.25em 0.1em;
  border-radius: 0.15em;
  transform: rotate(2deg);
  display: inline-block;
}
.logo.small { font-size: 28px; }

/* ---------- controls ---------- */
button, .btn {
  font: 800 18px/1 var(--body);
  border: 0;
  border-radius: 14px;
  padding: 16px 22px;
  background: var(--sun);
  color: #1a1200;
  cursor: pointer;
  box-shadow: 0 5px 0 #b38c00;
  transition: transform 0.06s, box-shadow 0.06s, opacity 0.2s;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  touch-action: manipulation;
}
button:active, .btn:active { transform: translateY(4px); box-shadow: 0 1px 0 #b38c00; }
button:disabled { opacity: 0.4; cursor: not-allowed; transform: none; }
button.hot { background: var(--hot); color: white; box-shadow: 0 5px 0 #a8164c; }
button.hot:active { box-shadow: 0 1px 0 #a8164c; }
button.mint { background: var(--mint); color: #002b1d; box-shadow: 0 5px 0 #14a476; }
button.ghost { background: var(--panel); color: var(--text); box-shadow: 0 5px 0 #17112a; }
button.small { padding: 10px 14px; font-size: 15px; border-radius: 11px; }
button.block { width: 100%; }

input, select {
  font: 600 18px var(--body);
  color: var(--text);
  background: var(--bg-2);
  border: 2px solid var(--line);
  border-radius: 12px;
  padding: 14px 14px;
  width: 100%;
  outline: none;
}
input:focus, select:focus { border-color: var(--sky); }
input.code-input {
  font-family: var(--display);
  font-size: 34px;
  letter-spacing: 0.3em;
  text-align: center;
  text-transform: uppercase;
}
label { display: block; font-weight: 600; color: var(--muted); font-size: 14px; margin: 0 0 6px; }

.panel {
  background: color-mix(in srgb, var(--panel) 85%, transparent);
  border: 2px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
}
.stack > * + * { margin-top: 14px; }
.row { display: flex; gap: 10px; align-items: center; }
.row > .grow { flex: 1; min-width: 0; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

/* ---------- toasts ---------- */
#toasts { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); z-index: 50; display: grid; gap: 8px; width: min(92vw, 420px); }
.toast { background: var(--danger); color: white; font-weight: 700; padding: 12px 16px; border-radius: 12px; box-shadow: 0 8px 24px #0008; transition: opacity 0.4s, transform 0.4s; }
.toast.info { background: var(--sky); color: #00253a; }
.toast.out { opacity: 0; transform: translateY(8px); }

.status-pill { position: fixed; top: 10px; right: 10px; font-size: 13px; font-weight: 700; padding: 6px 10px; border-radius: 99px; background: var(--danger); color: white; z-index: 40; }

/* ---------- landing ---------- */
.landing { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.landing-inner { width: min(560px, 100%); text-align: center; }
.landing .tag { font-size: 20px; color: var(--muted); margin: 18px 0 34px; }
.landing .choices { display: grid; gap: 16px; text-align: left; }
.landing .choice h2 { font-size: 24px; margin-bottom: 6px; }
.landing .choice p { margin: 0 0 14px; color: var(--muted); }

/* ---------- player (phone) ---------- */
.phone { max-width: 560px; margin: 0 auto; padding: 16px 16px 40px; }
.phone header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }
.phone .who { font-weight: 800; background: var(--panel); padding: 6px 12px; border-radius: 99px; font-size: 15px; }
.phone .prompt-card { background: var(--sun); color: #1a1200; border-radius: var(--radius); padding: 18px 20px; transform: rotate(-0.6deg); }
.phone .prompt-card .label { font-size: 13px; font-weight: 800; text-transform: uppercase; letter-spacing: 0.08em; opacity: 0.7; }
.phone .prompt-card .text { font-family: var(--display); font-size: 26px; line-height: 1.1; margin-top: 4px; }
.timer-badge { font-family: var(--mono); font-weight: 500; background: var(--bg-2); border: 2px solid var(--line); border-radius: 10px; padding: 4px 10px; font-size: 16px; }
.timer-badge.low { border-color: var(--hot); color: var(--hot); animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: 0.55; } }

.center-msg { text-align: center; padding: 40px 10px; }
.center-msg .big { font-family: var(--display); font-size: 34px; line-height: 1.1; margin-bottom: 10px; }
.center-msg .emoji { font-size: 64px; margin-bottom: 8px; }

.player-frame { position: relative; width: 100%; aspect-ratio: 16 / 9; background: #000; border-radius: 14px; overflow: hidden; }
.player-frame > div, .player-frame iframe { position: absolute; inset: 0; width: 100%; height: 100%; }
.player-frame .placeholder { display: grid; place-items: center; color: var(--muted); text-align: center; padding: 20px; }

.results-list { display: grid; gap: 8px; max-height: 340px; overflow-y: auto; }
.result-item { display: flex; gap: 10px; align-items: center; background: var(--bg-2); border: 2px solid var(--line); border-radius: 12px; padding: 8px; text-align: left; color: var(--text); font: inherit; box-shadow: none; width: 100%; cursor: pointer; }
.result-item:active { transform: none; box-shadow: none; border-color: var(--sky); }
.result-item img { width: 96px; aspect-ratio: 16/9; object-fit: cover; border-radius: 8px; flex: none; }
.result-item .t { font-weight: 700; font-size: 15px; line-height: 1.25; }
.result-item .c { font-size: 13px; color: var(--muted); }

.trim { background: var(--bg-2); border: 2px solid var(--line); border-radius: 14px; padding: 14px; }
.trim .now { font-family: var(--mono); font-size: 14px; color: var(--muted); }
/* drag-handle trimmer (trim.js) */
.trimmer { display: grid; gap: 10px; user-select: none; -webkit-user-select: none; }
.trim-overview { position: relative; height: 14px; background: #0d0a16; border-radius: 7px; cursor: pointer; touch-action: none; }
.trim-overview .ov-sel { position: absolute; top: 0; bottom: 0; min-width: 6px; background: var(--mint); border-radius: 7px; }
.trim-overview .ov-head { position: absolute; top: -3px; bottom: -3px; width: 2px; margin-left: -1px; background: var(--hot); }
.trim-track { position: relative; height: 52px; margin: 26px 26px 0; background: #0d0a16; border-radius: 10px; cursor: pointer; touch-action: none; }
.trim-track .range { position: absolute; top: 0; bottom: 0; background: color-mix(in srgb, var(--mint) 28%, transparent); border-top: 3px solid var(--mint); border-bottom: 3px solid var(--mint); cursor: grab; touch-action: none; }
.trim-track .playhead { position: absolute; top: -5px; bottom: -5px; width: 2px; margin-left: -1px; background: var(--hot); pointer-events: none; }
/* handles sit outside the selection like brackets, so they never overlap on short clips */
.trim-track .handle { position: absolute; top: -6px; bottom: -6px; width: 26px; cursor: ew-resize; touch-action: none; outline: none; }
.trim-track .handle.start { margin-left: -26px; }
.trim-track .handle::before { content: ""; position: absolute; top: 0; bottom: 0; width: 16px; background: var(--mint); box-shadow: 0 3px 0 #14a476; }
.trim-track .handle.start::before { right: 0; border-radius: 8px 0 0 8px; }
.trim-track .handle.end::before { left: 0; border-radius: 0 8px 8px 0; }
.trim-track .handle::after { content: ""; position: absolute; top: 35%; height: 30%; width: 2px; border-radius: 1px; background: #0d0a16; }
.trim-track .handle.start::after { right: 7px; }
.trim-track .handle.end::after { left: 7px; }
.trim-track .handle.active::before, .trim-track .handle:focus-visible::before { background: var(--sun); box-shadow: 0 3px 0 #b38c00; }
.trim-track .bubble { display: none; position: absolute; bottom: calc(100% + 6px); padding: 3px 7px; border-radius: 7px; background: var(--sun); color: #1a1200; font: 700 13px var(--mono); white-space: nowrap; pointer-events: none; }
.trim-track .handle.active .bubble { display: block; }
.trim-track .handle.start .bubble { right: 0; }
.trim-track .handle.end .bubble { left: 0; }
.trim-scale { display: flex; justify-content: space-between; margin: -4px 26px 0; font: 12px var(--mono); color: var(--muted); }
.trim-readout { display: flex; justify-content: space-between; gap: 8px; }
.trim-readout .grp { display: flex; align-items: center; gap: 6px; }
.trim-readout .grp button { padding: 8px 9px; font-size: 13px; border-radius: 9px; box-shadow: 0 3px 0 #17112a; }
.trim-readout .tt { display: grid; text-align: center; min-width: 58px; }
.trim-readout .tt small { font-size: 11px; font-weight: 800; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); }
.trim-readout .t { font: 700 15px var(--mono); }
.clip-len { text-align: center; font-weight: 800; margin: 12px 0 4px; }
.clip-len.bad { color: var(--danger); }

.vote-list { display: grid; gap: 12px; }
.vote-btn { display: flex; gap: 12px; align-items: center; width: 100%; padding: 10px; text-align: left; background: var(--panel); color: var(--text); box-shadow: 0 5px 0 #17112a; border: 2px solid var(--line); }
.vote-btn .letter { font-family: var(--display); font-size: 30px; width: 44px; text-align: center; color: var(--sun); flex: none; }
.vote-btn img { width: 110px; aspect-ratio: 16/9; object-fit: cover; border-radius: 8px; flex: none; }
.vote-btn .t { font-weight: 700; font-size: 15px; }
.vote-btn.chosen { border-color: var(--mint); background: color-mix(in srgb, var(--mint) 20%, var(--panel)); }
.vote-btn:disabled { opacity: 0.35; }

/* ---------- host (TV) ---------- */
.tv { min-height: 100vh; padding: 3vh 4vw; display: flex; flex-direction: column; }
.tv header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 3vh; gap: 20px; }
.tv .room-chip { display: flex; align-items: center; gap: 14px; background: var(--panel); border: 2px solid var(--line); padding: 8px 18px; border-radius: 99px; font-weight: 700; color: var(--muted); }
.tv .room-chip b { font-family: var(--display); color: var(--sun); font-size: 26px; letter-spacing: 0.15em; font-weight: 400; }
.tv main { flex: 1; display: flex; flex-direction: column; }

.lobby { display: grid; grid-template-columns: 1.1fr 1fr; gap: 4vw; align-items: start; }
.join-card { text-align: center; }
.join-card .how { font-size: 22px; color: var(--muted); }
.join-card .url { font-size: 30px; font-weight: 800; color: var(--text); margin: 6px 0 16px; word-break: break-all; }
.join-card .code { font-family: var(--display); font-size: clamp(80px, 13vw, 180px); line-height: 1; color: var(--sun); letter-spacing: 0.12em; text-shadow: 6px 6px 0 var(--hot); }
.join-card .qr { background: white; padding: 12px; border-radius: 14px; display: inline-block; margin-top: 18px; }
.join-card .qr img { display: block; width: 170px; height: 170px; image-rendering: pixelated; }

.roster { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 12px; }
.roster .p { background: var(--panel); border: 2px solid var(--line); border-radius: 14px; padding: 14px 16px; font-weight: 800; font-size: 20px; position: relative; display: flex; justify-content: space-between; align-items: center; gap: 8px; animation: pop 0.35s cubic-bezier(.2,1.6,.4,1); }
.roster .p.off { opacity: 0.4; }
.roster .p .vip { font-size: 11px; background: var(--sun); color: #1a1200; padding: 3px 6px; border-radius: 6px; letter-spacing: 0.06em; }
.roster .p .x { background: none; box-shadow: none; color: var(--muted); padding: 2px 6px; font-size: 18px; }
.roster .p.done { border-color: var(--mint); }
.roster .p.done::after { content: "✓"; color: var(--mint); font-size: 22px; }
.roster .empty { color: var(--muted); grid-column: 1 / -1; font-size: 20px; padding: 20px 0; }
@keyframes pop { from { transform: scale(0.6); opacity: 0; } }

.settings-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }

.big-prompt { text-align: center; margin: auto 0; padding: 2vh 0; }
.big-prompt .label { font-size: 24px; font-weight: 800; color: var(--muted); text-transform: uppercase; letter-spacing: 0.12em; }
.big-prompt .text { font-family: var(--display); font-size: clamp(44px, 6.5vw, 110px); line-height: 1.02; margin: 2vh auto; max-width: 18ch; color: var(--sun); }
.big-timer { font-family: var(--mono); font-size: clamp(40px, 6vw, 80px); color: var(--text); }
.big-timer.low { color: var(--hot); animation: pulse 1s infinite; }

.stage { display: grid; grid-template-rows: auto 1fr; gap: 2vh; flex: 1; }
.stage .bar { display: flex; justify-content: space-between; align-items: center; gap: 20px; }
.stage .bar .p { font-family: var(--display); font-size: clamp(22px, 2.6vw, 40px); color: var(--sun); line-height: 1.1; }
.stage .bar .n { font-family: var(--display); font-size: 28px; white-space: nowrap; }
.stage .screen { position: relative; background: #000; border-radius: 20px; overflow: hidden; border: 4px solid var(--line); min-height: 50vh; }
.stage .screen .yt-mount, .stage .screen iframe { position: absolute; inset: 0; width: 100%; height: 100%; }
.stage .overlay { position: absolute; inset: 0; display: grid; place-items: center; background: #000c; z-index: 2; }
.stage .letter-badge { position: absolute; top: 16px; left: 16px; z-index: 3; font-family: var(--display); font-size: 56px; color: var(--bg); background: var(--sun); width: 86px; height: 86px; display: grid; place-items: center; border-radius: 18px; transform: rotate(-6deg); }

.vote-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 2vw; margin-top: 3vh; }
.vote-card { background: var(--panel); border: 3px solid var(--line); border-radius: 18px; overflow: hidden; position: relative; }
.vote-card img { width: 100%; aspect-ratio: 16/9; object-fit: cover; display: block; }
.vote-card .meta { padding: 12px 14px; display: flex; gap: 12px; align-items: center; }
.vote-card .letter { font-family: var(--display); font-size: 42px; color: var(--sun); line-height: 1; }
.vote-card .t { font-weight: 700; font-size: 17px; line-height: 1.25; }
.vote-card.winner { border-color: var(--sun); box-shadow: 0 0 0 4px var(--sun), 0 12px 40px #ffd23f40; }
.vote-card .author { font-family: var(--display); font-size: 26px; }
.vote-card .pts { position: absolute; top: 10px; right: 10px; background: var(--mint); color: #002b1d; font-weight: 800; font-size: 22px; padding: 6px 12px; border-radius: 10px; }
.vote-card .voters { font-size: 15px; color: var(--muted); }
.voted-strip { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; margin-top: 3vh; }
.voted-strip span { background: var(--panel); border: 2px solid var(--line); padding: 8px 14px; border-radius: 99px; font-weight: 800; }
.voted-strip span.done { border-color: var(--mint); color: var(--mint); }

.results-layout { display: grid; grid-template-columns: 2fr 1fr; gap: 3vw; align-items: start; }
.scoreboard { display: grid; gap: 10px; }
.scoreboard .s { display: flex; justify-content: space-between; align-items: center; background: var(--panel); border: 2px solid var(--line); border-radius: 14px; padding: 12px 18px; font-weight: 800; font-size: 22px; }
.scoreboard .s .rank { color: var(--muted); width: 2ch; }
.scoreboard .s .sc { font-family: var(--mono); color: var(--sun); }
.scoreboard .s.first { border-color: var(--sun); background: color-mix(in srgb, var(--sun) 18%, var(--panel)); }

.final { text-align: center; margin: auto; width: min(760px, 100%); }
.final .crown { font-size: 90px; }
.final .winner { font-family: var(--display); font-size: clamp(60px, 9vw, 140px); color: var(--sun); line-height: 1; text-shadow: 6px 6px 0 var(--hot); }
.tv-actions { display: flex; gap: 14px; justify-content: center; margin-top: 3vh; flex-wrap: wrap; }

@media (max-width: 900px) {
  .lobby, .results-layout { grid-template-columns: 1fr; }
}
@media (max-width: 420px) {
  .vote-btn img { width: 84px; }
  .phone .prompt-card .text { font-size: 22px; }
}
