:root {
  --bg: #0b0b0b;
  --panel: #161616;
  --line: #2a2a2a;
  --text: #e8e8e8;
  --muted: #9a9a9a;
  --blood: #c1121f;
  --blood-dark: #7a0b14;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font-family: system-ui, -apple-system, sans-serif; }
body { min-height: 100vh; padding: 16px; }
main { max-width: 720px; margin: 0 auto; }
h1 { color: var(--blood); font-size: 1.8rem; margin: 8px 0 16px; text-align: center; letter-spacing: 0.02em; }
h2 { font-size: 1.3rem; margin: 16px 0 8px; }
p { line-height: 1.5; }
.muted { color: var(--muted); }
.center { text-align: center; }
.hidden { display: none !important; }

button, input { font: inherit; }
button {
  background: var(--blood); color: #fff; border: 0; border-radius: 8px;
  padding: 12px 18px; font-weight: 600; cursor: pointer; touch-action: manipulation;
}
button:disabled { opacity: 0.35; cursor: default; }
button.secondary { background: var(--panel); border: 1px solid var(--line); color: var(--text); }
input {
  width: 100%; padding: 12px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--panel); color: var(--text);
}
form.row { display: flex; gap: 8px; }
form.row input { flex: 1; min-width: 0; }
input:disabled { opacity: 0.35; }
/* Search results: rows short enough that several fit above a phone's keyboard. */
.results { display: grid; gap: 6px; margin-top: 8px; }
.results p { margin: 0; }
.result {
  display: grid; grid-template-columns: 36px 1fr; gap: 10px; align-items: center; width: 100%;
  padding: 4px 10px 4px 4px; text-align: left; font-weight: 400;
  background: var(--panel); border: 1px solid var(--line); color: var(--text);
}
.result img { width: 36px; aspect-ratio: 2 / 3; object-fit: cover; border-radius: 4px; background: #222; }
form.stack { display: grid; gap: 8px; max-width: 360px; margin: 0 auto; }
form.stack button { margin-top: 8px; }
.error { color: #ff6b6b; min-height: 1.5em; }
a { color: var(--text); }
a.button { padding: 10px 14px; border-radius: 8px; font-weight: 600; text-decoration: none; white-space: nowrap; }
a.button.secondary { background: var(--bg); border: 1px solid var(--line); }
.invite { word-break: break-all; font-size: 0.85rem; }

.votes-left { font-size: 1.4rem; font-weight: 700; text-align: center; margin: 4px 0; }
.ominous { text-align: center; color: var(--muted); font-style: italic; margin: 0 0 16px; }

.cards { display: grid; gap: 12px; }
.card {
  display: grid; grid-template-columns: 80px 1fr; gap: 12px; align-items: center;
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 10px;
}
.card img { width: 80px; aspect-ratio: 2 / 3; object-fit: cover; border-radius: 6px; background: #222; }
.card .title { font-weight: 700; }
.card a { color: var(--muted); }
.card.nomination { grid-template-columns: 80px 1fr auto; }
.card.night { grid-template-columns: 1fr auto; padding: 14px; }
.card.night .title { color: var(--text); font-size: 1.1rem; }
.stepper { display: flex; align-items: center; gap: 10px; margin-top: 8px; }
.stepper button { width: 44px; height: 44px; padding: 0; font-size: 1.4rem; }
.stepper .count { min-width: 2em; font-size: 1.3rem; text-align: center; }

/* Comments: always the last thing before Log out, and one line until tapped, so they never crowd the stage. */
.comments { max-width: 720px; width: 100%; margin: 32px auto 0; border-top: 1px solid var(--line); }
.comments-line {
  display: block; width: 100%; padding: 12px 4px; background: none; border-radius: 0;
  color: var(--muted); font-weight: 400; text-align: left;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.comments-line .new { color: var(--blood); font-weight: 700; }
.thread { padding: 0 4px 8px; }
.thread-list { display: grid; gap: 8px; margin-bottom: 10px; }
.comment { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px; }
.comment .who { display: flex; gap: 8px; align-items: baseline; }
.comment .who .muted { font-size: 0.8rem; }
.comment p { margin: 4px 0 0; overflow-wrap: anywhere; }
/* The app's own entries: who won and how, and the dead being raised. */
.comment.auto { background: none; border-style: dashed; color: var(--muted); font-style: italic; }
.comment .remove { margin-left: auto; padding: 0 6px; background: none; color: var(--muted); font-weight: 400; }
/* Reactions: small chips under an entry, the viewer's own outlined in red, and a muted button to add one. */
.reactions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; font-style: normal; }
.reactions button {
  padding: 2px 9px; border-radius: 999px; background: var(--bg); border: 1px solid var(--line);
  color: var(--text); font-size: 0.9rem; font-weight: 400;
}
.reactions .mine { border-color: var(--blood); background: #2a0d10; }
.reactions .add { color: var(--muted); border-style: dashed; }

.disrupted { position: fixed; top: 10px; right: 12px; font-size: 1.5rem; }

/* Host / TV */
body.host main { max-width: 1100px; }
.qr { background: #fff; padding: 12px; border-radius: 12px; width: min(320px, 80vw); display: block; margin: 0 auto; }
.big { font-size: 1.6rem; text-align: center; }
/* The QR code beside the host's own ballot; one above the other on a narrow screen. */
.split { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; align-items: start; }
@media (max-width: 800px) { .split { grid-template-columns: 1fr; } }
/* Seal the crypt comes last: under both columns, or after the ballot when they stack. */
.split > .toolbar { grid-column: 1 / -1; }
.toolbar { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; margin: 16px 0; }

/* The count, the tie and the winner are watched on a TV, mirrored from whatever the host has: a phone turned
   sideways (about 844x390), a laptop or a desktop. So they are sized from the screen, not in fixed pixels. */
body.host { --announce-size: clamp(18px, min(5.5vh, 5vw), 60px); --screen-h: 100vh; }
/* On a phone, 100vh includes what is under the browser's bars; dvh is only what can be seen. */
@supports (height: 100dvh) { body.host { --screen-h: 100dvh; } }
body.host.on-tv main { max-width: none; }
body.on-tv #revealing, body.on-tv #tie {
  min-height: calc(var(--screen-h) - 32px - var(--tv-name)); display: flex; flex-direction: column; justify-content: center;
}
.upright-only { display: none; }
@media (orientation: portrait) { .upright-only { display: block; } }

/* The reveal: a poster per movie. --rows and --cols come from the script, and --above (set per stage below) is
   the height the stage needs for everything that isn't a row of posters. The tile height is what is left of
   the screen shared out between the rows, so every row fits without scrolling. */
.posters {
  --name-size: clamp(11px, 2.2vh, 22px);
  --n-size: clamp(13px, 3vh, 30px);
  --gap: clamp(6px, 1.6vh, 18px);
  /* What a row needs besides its poster: the title, the count and the gap to the next row. */
  --row-extra: calc(var(--name-size) * 1.3 + var(--n-size) * 1.2 + 6px + var(--gap));
  --tile-h: calc((var(--screen-h) - 32px - var(--tv-name) - var(--above) - var(--rows) * var(--row-extra)) / var(--rows));
  --tile: max(48px, calc(var(--tile-h) / 1.5));
  display: grid; grid-template-columns: repeat(var(--cols), minmax(0, var(--tile)));
  gap: var(--gap); justify-content: center;
}
/* Two lines of vote text and its margins. */
#posters { --above: calc(var(--announce-size) * 2.5 + 3vh + 8px); }
/* "It's a tie!" and the Start runoff button. */
#tie-posters { --above: calc(var(--announce-size) * 1.25 + 3vh + 84px); }
/* A phone turned sideways has no height to spare, and the posters carry the titles. */
@media (max-height: 500px) {
  .posters { --name-size: 0px; }
  .poster-tile .name { display: none; }
}
.poster-tile { text-align: center; min-width: 0; }
.poster { position: relative; aspect-ratio: 2 / 3; border-radius: 10px; overflow: hidden; background: var(--panel); }
.poster > * { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.poster .drained { filter: grayscale(1) brightness(0.35); }
/* The coloured copy, cut off above the fill line. */
.poster .filled { clip-path: inset(calc(100% - var(--fill, 0%)) 0 0 0); transition: clip-path 0.6s ease; }
.poster .no-poster { display: grid; place-items: center; padding: 4px; font-size: var(--n-size); font-weight: 700; overflow-wrap: break-word; }
.poster .no-poster.drained { color: var(--muted); filter: none; }
.poster .no-poster.filled { background: linear-gradient(0deg, var(--blood-dark), var(--blood)); color: #fff; }
.poster-tile .name {
  font-size: var(--name-size); line-height: 1.3; font-weight: 700; margin-top: 6px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.poster-tile .n { font-size: var(--n-size); line-height: 1.2; }
/* The movie that just got a vote: the winner screen's red glow, flaring up and settling. */
.poster-tile.lit .poster { box-shadow: 0 0 30px var(--blood); animation: flash 0.9s ease-out; }
@keyframes flash {
  0% { box-shadow: 0 0 0 var(--blood); }
  30% { box-shadow: 0 0 70px 10px var(--blood); }
  100% { box-shadow: 0 0 30px var(--blood); }
}
.announce { font-size: var(--announce-size, 2rem); line-height: 1.25; text-align: center; min-height: 1.25em; }
#revealing .announce, #tie .announce { margin: 1.5vh 0; }
/* Room for a vote line that wraps to two lines, so the posters don't jump. */
#revealing .announce { min-height: 2.5em; }

/* On the TV (see host.js): the content leads, and the heading and navigation follow it, small and muted. */
/* The host screen is a process to step through, so only the night's name stays on top. The app title and the
   navigation follow the content, small and muted, at every stage. */
body.host main { display: flex; flex-direction: column; }
body.host main > h1 { order: 2; margin: 40px 0 0; color: var(--muted); font-size: 1rem; font-weight: 400; }
body.host main > nav { order: 3; }
body.host #logout-bar { order: 4; }
body.host main > nav, body.host #logout-bar { margin: 8px 0; font-size: 0.9rem; }
body.host #logout-bar button { padding: 6px 12px; }
/* On the TV (see host.js) the night's name is one small line, and the stages sized to the screen leave room
   for it: --tv-name is its height. */
body.host { --tv-name: 0px; }
body.host.on-tv { --tv-name: calc(clamp(13px, 2.6vh, 24px) * 1.3 + 1vh); }
body.on-tv #night-name { margin: 0 0 1vh; color: var(--muted); font-size: clamp(13px, 2.6vh, 24px); font-weight: 400; line-height: 1.3; }
.set-apart { margin-top: 56px; }

.winner { text-align: center; }
.winner img { width: min(300px, 70vw); border-radius: 12px; box-shadow: 0 0 60px var(--blood-dark); }
.winner .title { font-size: 2rem; font-weight: 800; margin: 12px 0 4px; }
.winner a { color: var(--muted); }
/* The winner on the TV fills the screen: the poster beside the words on a wide screen, above them on a tall one. */
body.host .winner {
  min-height: calc(var(--screen-h) - 32px - var(--tv-name)); display: flex; align-items: center; justify-content: center; gap: 5vw; text-align: left;
}
body.host .winner > img {
  height: calc(var(--screen-h) * 0.8); width: auto; max-width: 45vw; object-fit: contain; border-radius: 1.5vh; box-shadow: 0 0 8vh var(--blood-dark);
}
body.host .winner .muted, body.host .winner a { font-size: clamp(14px, min(3vh, 3vw), 34px); }
body.host .winner p { margin: 1vh 0; }
body.host .winner .title { font-size: clamp(24px, min(8vh, 6vw), 90px); line-height: 1.1; margin: 1vh 0; }
body.host .winner .blame { font-size: clamp(18px, min(4.5vh, 4vw), 54px); margin-top: 4vh; }
/* The winner's entrance, straight after the reveal (see host.js): a dark beat, "Tonight we watch…", then the
   poster fades up as its glow swells and settles, about 2 seconds in all. The rest waits until it is over. */
.winner.entering > div > p:first-child { animation: fade-in 0.4s ease-out 0.3s both; }
.winner.entering > img { animation: winner-poster 1.4s ease-out 0.7s both; }
.winner.entering > div > :not(:first-child), .winner.entering ~ .set-apart { animation: fade-in 0.5s ease-out 2.1s both; }
@keyframes fade-in { from { opacity: 0; } }
@keyframes winner-poster {
  0% { opacity: 0; transform: scale(0.94); box-shadow: 0 0 0 var(--blood); }
  60% { opacity: 1; box-shadow: 0 0 16vh 2vh var(--blood); }
  100% { transform: none; }
}
@media (prefers-reduced-motion: reduce) {
  .winner.entering *, .winner.entering ~ .set-apart { animation: none; }
}
@media (orientation: portrait) {
  body.host .winner { flex-direction: column; gap: 2vh; text-align: center; }
  /* The card's lines join the column, so "Tonight we watch…" can go above the poster. */
  body.host .winner > div { display: contents; }
  body.host .winner > div > p:first-child { order: -1; }
  body.host .winner > img { height: calc(var(--screen-h) * 0.55); max-width: 86vw; }
}

.setup-list { display: grid; gap: 8px; margin: 12px 0; }
.setup-list .card { grid-template-columns: 60px 1fr auto; }
.setup-list .card img { width: 60px; }
