:root {
  --bg: #0e0f14;
  --panel: #171923;
  --panel-2: #20232f;
  --border: #2c3040;
  --text: #f1f2f6;
  --muted: #9aa0b4;
  --accent: #ff4f7b;
  --accent-2: #ff8a3d;
  --like: #2fd17a;
  --nope: #ff4f5e;
  --gold: #ffc542;
  --radius: 18px;
  --focus: 0 0 0 3px rgba(255, 138, 61, .85);
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: radial-gradient(circle at 20% -10%, #2a1630 0%, transparent 45%), var(--bg);
  color: var(--text);
  font-family: 'Space Grotesk', system-ui, sans-serif;
  min-height: 100vh;
}
[hidden] { display: none !important; }
a { color: inherit; }
:focus-visible { outline: none; box-shadow: var(--focus); border-radius: 8px; }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.muted { color: var(--muted); }

/* TOPBAR */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 14px 28px; border-bottom: 1px solid var(--border);
}
.logo { margin: 0; font-size: 26px; font-weight: 700; letter-spacing: -0.5px; text-decoration: none; }
.logo span {
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.topbar-info { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; justify-content: flex-end; }
.room-badge, .progress, .conn-badge {
  font-weight: 500; font-size: 14px; padding: 5px 12px; border-radius: 999px;
  border: 1px solid var(--border); color: var(--muted);
}
.room-badge { letter-spacing: 1px; }
.conn-badge { border-color: var(--gold); color: var(--gold); animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .45; } }

/* BUTTONS & FORMS */
.btn {
  font: inherit; font-weight: 500; font-size: 15px; cursor: pointer; text-decoration: none; text-align: center;
  border: 1px solid var(--border); background: var(--panel-2); color: var(--text); display: inline-block;
  padding: 10px 16px; border-radius: 12px; transition: transform .1s, background .15s, border-color .15s;
  min-height: 44px;
}
.btn:hover { border-color: #4a4f66; }
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .45; cursor: not-allowed; transform: none; }
.btn.primary { background: linear-gradient(90deg, var(--accent), var(--accent-2)); border: none; color: #fff; }
.btn.ghost { background: transparent; }
.btn.big { width: 100%; padding: 16px; font-size: 18px; margin-top: 10px; min-height: 56px; }
.btn.round { border-radius: 50%; width: 44px; height: 44px; min-height: 0; padding: 0; background: rgba(0,0,0,.6); }

.panel {
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 24px;
}
.form-card { display: flex; flex-direction: column; gap: 8px; }
.form-card h2 { margin: 0; font-size: 22px; }
.form-card p { margin: 0 0 6px; }
.form-card label, .filter-label { color: var(--muted); font-size: 14px; margin-top: 6px; }
.form-card input, .code-input {
  font: inherit; font-size: 18px; padding: 12px 14px; border-radius: 12px; min-height: 52px;
  border: 1px solid var(--border); background: var(--panel-2); color: var(--text); width: 100%;
}
.code-input { text-transform: uppercase; letter-spacing: 4px; font-weight: 700; }
.code-input::placeholder { letter-spacing: 4px; }
.form-error { color: var(--nope); min-height: 1.2em; font-size: 15px; }
.narrow { width: 100%; max-width: 460px; }

/* LANDING */
#landingScreen { max-width: 980px; margin: 0 auto; padding: 48px 16px; }
.hero { text-align: center; margin-bottom: 36px; }
.hero h1 { font-size: clamp(34px, 6vw, 60px); margin: 0 0 12px; letter-spacing: -1px; }
.tagline { color: var(--muted); font-size: clamp(17px, 2.2vw, 21px); max-width: 640px; margin: 0 auto; line-height: 1.5; }
.tagline strong { color: var(--accent); }
.landing-forms { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 20px; }

/* JOIN / PLAYER LOBBY / ERROR */
#joinScreen, #lobbyPlayerScreen, #errorScreen { display: flex; justify-content: center; padding: 40px 16px; }
.code-text { font-weight: 700; letter-spacing: 3px; color: var(--accent-2); }
.waiting { font-size: 18px; line-height: 1.5; }
#lobbyPlayerScreen h3 { margin: 12px 0 0; font-size: 16px; color: var(--muted); }
.count { color: var(--muted); font-weight: 400; font-size: .8em; }
.error-card { text-align: center; align-items: center; }
.error-emoji { font-size: 56px; margin: 0; }
.error-actions { display: flex; gap: 10px; margin-top: 12px; flex-wrap: wrap; justify-content: center; }

/* PLAYER CHIPS */
.player-chips { list-style: none; padding: 0; margin: 12px 0 0; display: flex; flex-wrap: wrap; gap: 8px; }
.player-chips li {
  display: flex; align-items: center; gap: 8px; padding: 8px 14px; font-size: 17px;
  border-radius: 999px; background: var(--panel-2); border: 1px solid var(--border);
  animation: pop-in .25s ease;
}
.chip-badge {
  font-size: 11px; text-transform: uppercase; letter-spacing: 1px; color: var(--accent-2);
  border: 1px solid currentColor; border-radius: 999px; padding: 1px 7px;
}
@keyframes pop-in { from { transform: scale(.85); opacity: 0; } }

/* HOST LOBBY */
#lobbyHostScreen {
  display: grid; grid-template-columns: minmax(0, 1fr) minmax(340px, 480px); gap: 24px;
  padding: 28px; max-width: 1400px; margin: 0 auto; align-items: start;
}
.invite { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 12px; }
.invite h2 { margin: 0; font-size: 28px; }
.qr {
  width: min(52vh, 100%); max-width: 520px; height: auto; aspect-ratio: 1; border-radius: 16px;
  background: #fff; image-rendering: pixelated;
}
.invite-url { font-size: clamp(18px, 2.4vw, 30px); font-weight: 700; margin: 0; word-break: break-all; }
.invite-code { margin: 0; font-size: 20px; color: var(--muted); }
.big-code { font-size: clamp(40px, 6vw, 72px); display: block; color: var(--text); letter-spacing: 8px; }
.lobby-side h2 { margin: 0 0 12px; font-size: 20px; }
.lobby-side h2:not(:first-child) { margin-top: 28px; }
.lobby-side .player-chips { margin-bottom: 4px; }
.filter { margin-bottom: 18px; }
.filter > label, .filter-label { display: block; color: var(--muted); margin-bottom: 8px; }
.filter input[type=range] { width: 100%; accent-color: var(--accent); min-height: 32px; }
.platform-toggles { display: flex; flex-wrap: wrap; gap: 8px; }
.toggle {
  font: inherit; cursor: pointer; padding: 10px 16px; border-radius: 999px; min-height: 44px;
  border: 1px solid var(--border); background: transparent; color: var(--muted);
}
.toggle.on { border-color: var(--accent); color: var(--text); background: rgba(255,79,123,.12); }

/* VOTING (host layout by default) */
#votingScreen {
  display: grid; grid-template-columns: minmax(0, 1.5fr) minmax(360px, 1fr);
  gap: 24px; padding: 24px 28px; align-items: start; max-width: 1600px; margin: 0 auto;
}
.card {
  position: relative; border-radius: var(--radius); overflow: hidden;
  background: var(--panel); border: 1px solid var(--border);
  touch-action: pan-y; user-select: none; cursor: grab;
  box-shadow: 0 20px 60px rgba(0,0,0,.5);
}
.card.dragging { cursor: grabbing; }
.media { position: relative; aspect-ratio: 16 / 9; background: #000; }
.media video, .media img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; pointer-events: none; }
.media-actions { position: absolute; right: 12px; bottom: 12px; display: flex; gap: 8px; }
.media .placeholder {
  position: absolute; inset: 0; display: grid; place-items: center; font-size: 48px; font-weight: 700;
  background: linear-gradient(135deg, #3a1d4a, #1d2b4a); text-align: center; padding: 20px;
}
.shots { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; padding: 8px; }
.shots button { padding: 0; border: 2px solid transparent; border-radius: 8px; overflow: hidden; cursor: pointer; background: none; aspect-ratio: 16/9; }
.shots button.active { border-color: var(--accent); }
.shots img { width: 100%; height: 100%; object-fit: cover; display: block; }
.shots .trailer-thumb { display: grid; place-items: center; background: var(--panel-2); color: var(--text); font: inherit; font-size: 14px; }

.stamp {
  position: absolute; top: 28px; z-index: 5; font-size: 44px; font-weight: 700; letter-spacing: 3px;
  padding: 4px 18px; border: 5px solid; border-radius: 10px; opacity: 0; pointer-events: none;
  background: rgba(0,0,0,.35); transition: opacity .15s;
}
.stamp.like { left: 28px; color: var(--like); transform: rotate(-14deg); }
.stamp.nope { right: 28px; color: var(--nope); transform: rotate(14deg); }
.card.voted-like .stamp.like, .card.voted-nope .stamp.nope { opacity: .9; }

.card-body, .side { display: flex; flex-direction: column; gap: 14px; }
/* Wraps so a long name + discounted price never pushes the price past the card on phones. */
.title-row { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 8px 12px; align-items: flex-start; }
.title-row h2 { margin: 0; font-size: 32px; line-height: 1.1; flex: 1 1 12ch; min-width: 0; overflow-wrap: anywhere; }
.price {
  white-space: nowrap; font-weight: 700; font-size: 20px; padding: 6px 12px; border-radius: 10px;
  background: var(--panel-2); border: 1px solid var(--border);
}
.price.free { color: var(--like); border-color: var(--like); }
.price .old { text-decoration: line-through; color: var(--muted); font-size: 14px; margin-right: 6px; font-weight: 400; }
.price .off { color: var(--like); font-size: 14px; margin-left: 6px; }
.meta, .tags { display: flex; flex-wrap: wrap; gap: 8px; }
.pill {
  padding: 5px 11px; border-radius: 999px; font-size: 14px;
  background: var(--panel-2); border: 1px solid var(--border);
}
.pill.good { border-color: var(--like); color: var(--like); }
.pill.bad { border-color: #555a70; color: var(--muted); }
.pill.warn { border-color: var(--gold); color: var(--gold); }
.tag { color: var(--accent-2); font-size: 14px; }
.pitch { margin: 0; font-size: 18px; line-height: 1.5; }
.steam-desc { margin: 0; color: var(--muted); font-size: 14px; font-style: italic; line-height: 1.4; }
.steam-desc:empty { display: none; }
.links { display: flex; flex-wrap: wrap; gap: 8px; }
.links a {
  text-decoration: none; padding: 10px 14px; border-radius: 10px; font-size: 14px; font-weight: 500;
  background: var(--panel-2); border: 1px solid var(--border);
}
.links a:hover { border-color: var(--accent); }

/* who voted (host) */
.voters { border-top: 1px solid var(--border); padding-top: 14px; }
.voters h3 { margin: 0 0 10px; font-size: 18px; }
.voter-list { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 8px; }
.voter-list li {
  display: flex; justify-content: space-between; align-items: center; gap: 8px;
  padding: 8px 12px; border-radius: 12px; background: var(--panel-2); border: 1px solid var(--border);
}
.voter-name { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.voter-list li.voted { border-color: var(--like); }
.voter-list li.voted .voter-mark { color: var(--like); font-weight: 700; }
.voter-list li.pending .voter-mark { color: var(--muted); animation: pulse 1.2s ease-in-out infinite; }
.voter-list li .voter-name { flex: 1; }
/* host-only "remove player" button, in the lobby chips and the who-voted panel */
.kick-btn {
  flex: none; width: 26px; height: 26px; padding: 0; border-radius: 50%; cursor: pointer;
  font: inherit; font-size: 13px; line-height: 1; color: var(--muted);
  background: transparent; border: 1px solid var(--border);
}
.kick-btn:hover, .kick-btn:focus-visible { color: var(--nope); border-color: currentColor; }
.host-controls { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 12px; }
/* "Cerrar sala": host only (lobby, voting host controls, results) */
body:not(.is-host) .close-room-btn { display: none; }
.host-controls .close-room-btn { grid-column: 1 / -1; }
.lobby-side .close-room-btn { margin-top: 12px; }
.kbd-help { color: var(--muted); font-size: 13px; margin: 10px 0 0; line-height: 1.8; }
kbd {
  font: inherit; font-size: 12px; padding: 1px 6px; border-radius: 5px;
  border: 1px solid var(--border); background: var(--panel-2); color: var(--text);
}

/* vote bar (own vote) */
.vote-bar { display: grid; gap: 10px; }
.vote-status { margin: 0; color: var(--muted); font-size: 15px; text-align: center; min-height: 1.3em; }
.vote-bar.has-vote .vote-status { color: var(--like); }
.vote-buttons { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.vote-btn {
  font: inherit; font-size: 34px; min-height: 64px; border-radius: 18px; cursor: pointer;
  background: transparent; border: 2px solid var(--border); color: var(--text);
  transition: transform .1s, background .15s, border-color .15s;
}
.vote-btn:active { transform: scale(.95); }
.vote-btn.like { border-color: var(--like); }
.vote-btn.nope { border-color: var(--nope); }
.vote-btn.played { border-color: var(--gold); }
.vote-label { display: block; font-size: 13px; line-height: 1.2; margin-top: 2px; }
.vote-btn.like[aria-pressed="true"] { background: rgba(47,209,122,.25); box-shadow: 0 0 0 2px var(--like); }
.vote-btn.nope[aria-pressed="true"] { background: rgba(255,79,94,.25); box-shadow: 0 0 0 2px var(--nope); }
.vote-btn.played[aria-pressed="true"] { background: rgba(255,197,66,.25); box-shadow: 0 0 0 2px var(--gold); }
.vote-bar.has-vote .vote-btn[aria-pressed="false"] { opacity: .5; }

/* RESULTS */
#resultsScreen { padding: 28px; display: flex; justify-content: center; }
.results { width: 100%; max-width: 1000px; }
.results-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.results-head h2 { margin: 0; }
#resultsNote:empty { display: none; }
.ranking { list-style: none; padding: 0; margin: 20px 0 0; display: grid; gap: 10px; }
.ranking li {
  display: grid; grid-template-columns: 40px 184px 1fr auto; gap: 16px; align-items: center;
  padding: 10px; border-radius: 14px; background: var(--panel-2); border: 1px solid var(--border);
}
.ranking li.match { border-color: var(--gold); box-shadow: 0 0 0 1px var(--gold), 0 0 24px rgba(255,197,66,.2); }
.rank { font-size: 22px; font-weight: 700; text-align: center; color: var(--muted); }
.ranking img, .ranking .thumb-ph { width: 184px; aspect-ratio: 460/215; border-radius: 8px; object-fit: cover; display: block; }
.ranking .thumb-ph { background: linear-gradient(135deg, #3a1d4a, #1d2b4a); display: grid; place-items: center; font-weight: 700; text-align: center; padding: 6px; }
.r-name { font-size: 19px; font-weight: 700; margin: 0 0 4px; }
.r-sub { color: var(--muted); font-size: 14px; margin: 0; }
.r-sub .likers { color: var(--like); }
.bar { height: 8px; border-radius: 4px; background: var(--border); margin-top: 8px; overflow: hidden; }
.bar span { display: block; height: 100%; width: 0; background: linear-gradient(90deg, var(--accent), var(--accent-2)); }
.r-right { text-align: right; display: grid; gap: 6px; justify-items: end; }
.r-right a { font-size: 14px; color: var(--muted); }
.empty { color: var(--muted); text-align: center; padding: 40px 0; }

/* OVERLAYS */
.loading, .match-overlay {
  position: fixed; inset: 0; z-index: 50; display: grid; place-content: center; justify-items: center; gap: 16px;
  background: rgba(8,9,12,.85); backdrop-filter: blur(4px); text-align: center; padding: 16px;
}
.spinner {
  width: 48px; height: 48px; border-radius: 50%;
  border: 4px solid var(--border); border-top-color: var(--accent); animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.match-overlay { pointer-events: none; }
.match-overlay.play { animation: fade 1.8s ease forwards; }
.match-text {
  font-size: clamp(40px, 8vw, 96px); font-weight: 700; font-style: italic;
  background: linear-gradient(90deg, var(--gold), var(--accent)); -webkit-background-clip: text; background-clip: text; color: transparent;
}
.match-overlay.play .match-text { animation: pop .5s cubic-bezier(.2,1.6,.4,1); }
.match-overlay p { font-size: clamp(18px, 3vw, 26px); margin: 0; }
@keyframes pop { from { transform: scale(.3); } to { transform: scale(1); } }
@keyframes fade { 0%, 75% { opacity: 1; } 100% { opacity: 0; } }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 60;
  max-width: min(92vw, 520px); padding: 12px 18px; border-radius: 12px;
  background: var(--panel-2); border: 1px solid var(--accent); box-shadow: 0 10px 30px rgba(0,0,0,.5);
  animation: pop-in .2s ease;
}

/* PHONE PLAYER LAYOUT */
body.is-phone #votingScreen {
  grid-template-columns: 1fr; gap: 12px; padding: 12px 12px 190px; max-width: 560px;
}
body.is-phone .shots, body.is-phone .host-only, body.is-phone .tags,
body.is-phone .steam-desc, body.is-phone .pill.extra { display: none !important; }
body.is-phone .card-body { padding: 16px; gap: 10px; }
/* Phones: the side panel only holds the fixed vote bar. */
body.is-phone .side { padding: 0; border: 0; background: none; }
body.is-phone .title-row h2 { font-size: 24px; }
body.is-phone .price { font-size: 16px; }
body.is-phone .pitch { font-size: 16px; }
body.is-phone .stamp { font-size: 30px; top: 16px; }
body.is-phone .stamp.like { left: 16px; }
body.is-phone .stamp.nope { right: 16px; }
body.is-phone .vote-bar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  padding: 12px 16px calc(14px + env(safe-area-inset-bottom));
  background: linear-gradient(transparent, var(--bg) 22%); padding-top: 28px;
}
body.is-phone .vote-btn { min-height: 88px; font-size: 40px; padding: 0 4px; }
.host-only { display: block; }

@media (max-width: 960px) {
  .topbar { padding: 12px 16px; flex-wrap: wrap; }
  .logo { font-size: 22px; }
  #votingScreen, #lobbyHostScreen { grid-template-columns: 1fr; padding: 16px; }
  .ranking li { grid-template-columns: 30px 1fr; }
  .ranking img, .ranking .thumb-ph { width: 100%; }
  .ranking li > :nth-child(3), .ranking li > :nth-child(4) { grid-column: 1 / -1; text-align: left; justify-items: start; }
  #resultsScreen { padding: 16px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
  /* Fading is not motion: keep the match overlay readable. */
  .match-overlay.play { animation-duration: 1.8s !important; }
}

/* ===== "Ya lo jugué" (already played) ===== */
.stamp.played {
  left: 50%; top: 40%; color: var(--gold); white-space: nowrap;
  transform: translate(-50%, -50%) rotate(-8deg);
}
/* Majority had played it: stamp shows first, then the card shrinks and fades (not a LIKE/NOPE swipe). */
.card.played-out { transition: transform .7s ease, opacity .35s ease .35s; }
.card.played-out .stamp.played { opacity: 1; }
body.is-phone .stamp.played { font-size: 26px; }
/* The played toast lands right when people vote the next card: keep it above the fixed vote bar. */
body.is-phone .toast { bottom: calc(170px + env(safe-area-inset-bottom)); }
.played-group { margin-top: 24px; }
.played-group h3 { margin: 0 0 8px; font-size: 17px; }
.played-list { list-style: none; padding: 0; margin: 0; display: flex; flex-wrap: wrap; gap: 8px; }
.unvoted-group { margin-top: 24px; }
.unvoted-group h3 { margin: 0 0 8px; font-size: 17px; }
.unvoted-list { list-style: none; padding: 0; margin: 0 0 12px; display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 10px; }
.unvoted-list li { display: grid; gap: 6px; padding: 8px; border-radius: 12px; background: var(--panel-2); border: 1px solid var(--border); }
.unvoted-list img, .unvoted-list .thumb-ph { width: 100%; aspect-ratio: 460/215; border-radius: 8px; object-fit: cover; display: block; }
.unvoted-list .thumb-ph { background: linear-gradient(135deg, #3a1d4a, #1d2b4a); display: grid; place-items: center; font-weight: 700; text-align: center; padding: 6px; }
.unvoted-list .r-name { font-size: 15px; margin: 0; }
#unvotedMoreBtn { min-height: 48px; }
.played-list li {
  padding: 6px 12px; border-radius: 999px; background: var(--panel-2); border: 1px solid var(--border); color: var(--muted);
}

/* ===== MEDIA: volume slider + fullscreen gallery ===== */
.media-actions { align-items: center; z-index: 6; }
.gallery-btn {
  min-height: 44px; padding: 8px 14px; font-size: 15px;
  background: rgba(0,0,0,.6); border-color: rgba(255,255,255,.2);
}
.volume-slider {
  width: 120px; min-height: 44px; padding: 0 12px; border-radius: 999px; cursor: pointer;
  background: rgba(0,0,0,.6); accent-color: var(--accent);
}
/* Phones get the slider too (iOS through Web Audio, see audio.js): longer track and a 44px
   hit area so a thumb can grab it. Horizontal drags here are the slider's, never the card's. */
body.is-phone .volume-slider { width: 140px; min-height: 48px; touch-action: none; }
.gallery-volume { flex: none; width: 140px; }
@media (max-width: 600px) { .gallery-volume { width: 96px; } }
body.gallery-open { overflow: hidden; }

.gallery {
  position: fixed; inset: 0; width: 100%; height: 100%; max-width: none; max-height: none; margin: 0;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  border: 0; background: #000; color: var(--text); overflow: hidden;
}
.gallery[open] { display: grid; grid-template-rows: auto minmax(0, 1fr) auto; }
.gallery::backdrop { background: #000; }
.gallery-bar { display: flex; align-items: center; gap: 16px; padding: 10px 16px; }
.gallery-title {
  margin: 0; flex: 1; min-width: 0; font-size: clamp(18px, 2.4vw, 34px);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.gallery-count { color: var(--muted); font-size: clamp(14px, 1.6vw, 22px); white-space: nowrap; }
.gallery-close {
  flex: none; width: 56px; height: 56px; min-height: 56px; padding: 0; border-radius: 50%;
  font-size: 24px; line-height: 1;
}
.gallery-stage { position: relative; min-height: 0; overflow: hidden; touch-action: pan-y pinch-zoom; }
.gallery-stage video, .gallery-stage img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; background: #000; }
.gallery-nav {
  position: absolute; top: 50%; transform: translateY(-50%); z-index: 2;
  width: 64px; height: 64px; border-radius: 50%; cursor: pointer;
  font: inherit; font-size: 40px; line-height: 1; color: var(--text);
  background: rgba(0,0,0,.55); border: 1px solid rgba(255,255,255,.25);
}
.gallery-nav:hover { background: rgba(0,0,0,.8); }
.gallery-nav.prev { left: 16px; }
.gallery-nav.next { right: 16px; }
.gallery-thumbs {
  display: flex; gap: 10px; overflow-x: auto; padding: 12px 16px 16px;
  scroll-snap-type: x proximity; scrollbar-width: thin;
}
.gallery-thumb {
  position: relative; flex: none; width: clamp(110px, 11vw, 220px); aspect-ratio: 16 / 9; padding: 0;
  border: 3px solid transparent; border-radius: 10px; overflow: hidden; cursor: pointer;
  background: var(--panel-2); scroll-snap-align: center; opacity: .7;
}
.gallery-thumb:hover, .gallery-thumb[aria-current="true"] { opacity: 1; }
.gallery-thumb[aria-current="true"] { border-color: var(--accent); }
.gallery-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb-badge {
  position: absolute; inset: 0; display: grid; place-items: center;
  font-size: 26px; color: #fff; background: rgba(0,0,0,.35); text-shadow: 0 1px 4px #000;
}

@media (max-width: 600px) {
  .gallery-bar { padding: 8px 12px; gap: 10px; }
  .gallery-close { width: 48px; height: 48px; min-height: 48px; }
  .gallery-nav { width: 48px; height: 48px; font-size: 30px; }
  .gallery-nav.prev { left: 8px; }
  .gallery-nav.next { right: 8px; }
  .gallery-thumbs { padding: 8px 12px 12px; gap: 8px; }
  .gallery-thumb { width: 96px; }
}

/* ===== Finish early + partial ranking ===== */
.finish-row { display: flex; flex-wrap: wrap; gap: 8px; }
.finish-row .btn { min-height: 48px; }
/* Ending the vote is the host's call; players only get the partial ranking. */
body:not(.is-host) .finish-btn, body:not(.is-host) .resume-voting-btn { display: none !important; }
.finish-btn { border-color: var(--gold); color: var(--gold); }
body.is-phone .finish-row .btn { flex: 1 1 100%; }

.ranking-sheet {
  width: min(960px, 100%); max-width: 100%; max-height: min(88vh, 900px); margin: auto auto 0;
  padding: 0; border: 1px solid var(--border); border-bottom: 0; border-radius: var(--radius) var(--radius) 0 0;
  background: var(--panel); color: var(--text); overflow: hidden;
}
.ranking-sheet[open] { display: flex; flex-direction: column; }
.ranking-sheet::backdrop { background: rgba(8,9,12,.75); backdrop-filter: blur(3px); }
.ranking-sheet-body {
  overflow-y: auto; overscroll-behavior: contain;
  padding: 20px 20px calc(20px + env(safe-area-inset-bottom));
}
.ranking-sheet-head {
  display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap;
  position: sticky; top: -20px; z-index: 1; margin: -20px -20px 0; padding: 20px 20px 12px; background: var(--panel);
}
.ranking-sheet-head h2 { margin: 0; }
.ranking-sheet-head .btn { min-height: 48px; }
#rankingSheetNote { margin: 10px 0 0; }
#rankingSheetNote:empty { display: none; }
#partialRanking { margin-top: 14px; }
@media (min-width: 961px) {
  .ranking-sheet { margin: auto; border-bottom: 1px solid var(--border); border-radius: var(--radius); }
}

/* ===== CARD STACK & SWIPE (swipe.js, gesture.js, stack.js) ===== */
/* Open card and next-card preview share one grid cell; the preview stretches to the card's height. */
.card-stack { display: grid; min-width: 0; }
.card-stack > .card, .card-stack > .card-under { grid-area: 1 / 1; }
.card { z-index: 1; -webkit-user-select: none; -webkit-touch-callout: none; }
.card img { -webkit-user-drag: none; }
.card-body { padding: 20px 24px 24px; }
.card.moving { will-change: transform; } /* only during a gesture/animation: a permanent layer costs memory */
.card.dragging .stamp { transition: none; } /* stamps track the finger, no lag */
.card.fading { transition: opacity .16s ease-out; }
.card-under {
  position: relative; z-index: 0; border-radius: var(--radius); overflow: hidden; pointer-events: none;
  background: var(--panel); border: 1px solid var(--border); transform: scale(.95);
}
.under-media { position: relative; aspect-ratio: 16 / 9; background: linear-gradient(135deg, #3a1d4a, #1d2b4a); }
.under-media img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.under-name { margin: 0; padding: 20px 24px; font-size: 32px; font-weight: 700; line-height: 1.1; }
body.is-phone .under-name { padding: 16px; font-size: 24px; }
/* No horizontal overscroll (bounce / history swipe on trackpads) fighting the card swipe. */
html { overscroll-behavior-x: none; }

@media (prefers-reduced-motion: reduce) {
  /* The card fades instead of flying; the global rule above would make the fade instant. */
  .card.fading { transition: opacity .2s linear !important; }
}
