/* DiddlySquawk host — the television, in a browser.

   Sized for a screen across the room rather than a laptop at arm's length:
   everything scales off viewport units, so the room code is legible from the
   sofa on a 55" panel and still fits a 13" laptop. */

:root {
  --ink: #f4f1e8;
  --muted: #b9b2a2;
  --panel: rgba(18, 14, 10, 0.72);
  --panel-solid: #17120d;
  --line: rgba(244, 241, 232, 0.16);
  --accent: #ffcf5c;
  --good: #7ddc9a;
  --bad: #f08d8d;
  --shadow: 0 10px 40px rgba(0, 0, 0, 0.55);
  --display: "Futura", "Avenir Next", "Trebuchet MS", sans-serif;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  color: var(--ink);
  font-family: var(--display);
  /* The same farm the tvOS app uses, so the two hosts read as one product. */
  background: #0d0b08 url("assets/farm.jpg") center / cover no-repeat fixed;
  overflow: hidden;
}

/* A wash over the photograph. Without it the white text on a bright sky is
   unreadable from any distance. */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  background: linear-gradient(rgba(58, 10, 10, 0.72), rgba(8, 5, 3, 0.90));
  pointer-events: none;
}

/* `hidden` is only a UA-stylesheet `display: none`, so ANY author rule setting
   display beats it — including the one immediately below. Without this, every
   screen is permanently visible and the lobby never gets out of the way of the
   game. */
.screen[hidden] { display: none; }

.screen {
  position: relative;
  height: 100%;
  display: flex;
  flex-direction: column;
  padding: 2vh 2.5vw;
  gap: 1.6vh;
}

/* ----- top bar ---------------------------------------------------------- */
.bar {
  display: flex;
  align-items: baseline;
  gap: 2.5vw;
  flex-wrap: wrap;
}
.label {
  font-size: 1.6vh; letter-spacing: 0.18em; text-transform: uppercase;
  color: var(--muted);
  /* So a dot inside it sits on the same line as the word rather than being
     aligned against the whole nine-viewport-unit row. */
  display: inline-flex; align-items: center; gap: 0.55vw;
}
.room { display: flex; align-items: baseline; gap: 1vw; }
.code {
  font-size: 9vh;
  font-weight: 700;
  letter-spacing: 0.12em;
  line-height: 1;
  color: var(--accent);
  text-shadow: var(--shadow);
  font-variant-numeric: tabular-nums;
}
.counts { font-size: 4.5vh; font-weight: 600; display: flex; align-items: baseline; gap: 0.6vw; }
.ghosts { font-size: 2.4vh; color: var(--muted); }
.status { margin-left: auto; font-size: 1.9vh; color: var(--muted); }

/* The connection, in front of the room code.
   
   A dot rather than the word "connected", which was a label that only ever
   said the unremarkable thing — nobody needs telling that the ordinary case is
   happening. What is worth a word is when it is NOT, and that still gets one,
   over on the right. */
.conn {
  width: 1.15vh; height: 1.15vh;
  border-radius: 50%;
  background: var(--muted);
  flex: 0 0 auto;
  transition: background 200ms;
}
.conn.live { background: var(--good); }

/* ----- lobby ------------------------------------------------------------ */
.lobby-body { flex: 1; display: flex; gap: 2.5vw; min-height: 0; }

/* A panel behind the avatars, as the tvOS app has. Names are small and the
   photograph underneath is busy; without it the grid is hard to read from the
   far side of a room, which is the only place it is ever read from. */
.players {
  flex: 1;
  background: rgba(12, 8, 6, 0.55);
  border: 1px solid var(--line);
  border-radius: 1.6vh;
  padding: 2vh 1.6vw;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(14vh, 1fr));
  grid-auto-rows: min-content;
  gap: 1.6vh 1vw;
  align-content: flex-start;
  overflow: hidden;
}
.hint { grid-column: 1 / -1; color: var(--muted); font-size: 2.4vh; }

.player { text-align: center; animation: pop 380ms cubic-bezier(.2,1.4,.5,1); }
.player img { width: 100%; max-width: 16vh; aspect-ratio: 1; object-fit: contain; }
.player .name {
  display: block;
  font-size: 2vh;
  margin-top: -0.4vh;
  text-shadow: 0 2px 8px rgba(0,0,0,.8);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
/* A dropped player keeps their seat and fades, rather than vanishing — the
   service holds their session and they can come back to it. */
.player.away { opacity: 0.32; filter: grayscale(1); }
.player.answered img { filter: drop-shadow(0 0 1.6vh var(--good)); }

@keyframes pop { from { transform: scale(.4); opacity: 0; } to { transform: none; opacity: 1; } }

.join {
  width: 26vh;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 1.6vh;
  padding: 1.6vh;
  text-align: center;
  align-self: flex-start;
  backdrop-filter: blur(6px);
}
.qr { background: #fff; border-radius: 1vh; padding: 1vh; line-height: 0; }
.qr img, .qr canvas, .qr table { width: 100% !important; height: auto !important; }
.join-url { font-size: 1.7vh; word-break: break-all; margin: 1vh 0 0.4vh; }
.join-hint { font-size: 1.5vh; color: var(--muted); margin: 0; }

/* ----- controls --------------------------------------------------------- */
.controls { display: flex; align-items: center; gap: 1.4vw; flex-wrap: wrap; }
.controls label { font-size: 1.8vh; color: var(--muted); display: flex; align-items: center; gap: 0.5vw; }
.controls label.check { gap: 0.4vw; }
select {
  font: inherit; font-size: 1.9vh; padding: 0.7vh 1vh;
  border-radius: 0.9vh; border: 1px solid var(--line);
  background: var(--panel-solid); color: var(--ink);
}
button {
  font: inherit; font-size: 2.1vh; font-weight: 600;
  padding: 1.1vh 2.2vh; border-radius: 1vh; cursor: pointer;
  border: 1px solid var(--line); background: var(--panel-solid); color: var(--ink);
}
button:hover:not(:disabled) { border-color: var(--accent); }
button:disabled { opacity: 0.4; cursor: default; }
button.primary { background: var(--accent); color: #2a1c00; border-color: transparent; }
button.danger { background: rgba(120, 20, 20, 0.7); }

/* The one button a screen offers, bottom right.
   
   Both screens put theirs in the same corner: ending a game and leaving a
   scoreboard are the same kind of act, and a button that moves between them is
   a button somebody has to look for. */
.screen-actions {
  position: absolute;
  right: 2.5vw; bottom: 2.5vh;
  z-index: 5;
  display: flex; gap: 1vw;
}

/* ----- game ------------------------------------------------------------- */
.round { font-size: 3vh; font-weight: 700; }
.qprogress { font-size: 2.2vh; color: var(--muted); }
.timer {
  font-size: 4vh; font-weight: 700; font-variant-numeric: tabular-nums;
  min-width: 3ch; text-align: right;
}
.timer.urgent { color: var(--bad); }

.stage {
  position: relative;
  flex: 1; display: flex; flex-direction: column; justify-content: center;
  gap: 2vh; min-height: 0;
}

.banner {
  text-align: center; font-size: 4vh; font-weight: 700;
  text-shadow: var(--shadow); min-height: 5vh;
}

/* The categories on offer, while the room decides.
   Sized in viewport units like everything else on this screen: it is a
   television across a room, not a page at arm's length. Wraps rather than
   scrolls — a list that needs scrolling on a TV is a list nobody can read, and
   there are never many. */
.categories {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 1.5vh;
  list-style: none;
  margin: 2vh 0 0;
  padding: 0;
}

.categories li {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 1.5vh;
  padding: 1.2vh 2.4vh;
  font-size: 2.6vh;
  font-weight: 600;
  text-shadow: var(--shadow);
  backdrop-filter: blur(8px);
}

.categories[hidden] { display: none; }

.question-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 2vh;
  padding: 3vh 4vh;
  backdrop-filter: blur(8px);
  box-shadow: var(--shadow);
}
.category { font-size: 1.8vh; letter-spacing: 0.2em; text-transform: uppercase; color: var(--accent); margin: 0 0 1vh; }
.question { font-size: 4.6vh; line-height: 1.2; margin: 0 0 2.5vh; }

.answers { list-style: none; margin: 0; padding: 0; display: grid; gap: 1.2vh; grid-template-columns: 1fr 1fr; }
.answers li {
  display: flex; align-items: center; gap: 1.4vh;
  font-size: 2.9vh; padding: 1.4vh 2vh;
  border: 1px solid var(--line); border-radius: 1.2vh;
  background: rgba(255,255,255,0.04);
}
.answers li .key {
  flex: none; width: 4.4vh; height: 4.4vh; border-radius: 50%;
  display: grid; place-items: center; font-size: 2.2vh; font-weight: 700;
  background: rgba(255,255,255,0.1);
}
/* Revealed only when the question closes. The service withholds the correct
   index until then, so this cannot leak early even if the page wanted it to. */
.answers li.correct { background: rgba(125, 220, 154, 0.22); border-color: var(--good); }
.answers li.correct .key { background: var(--good); color: #08260f; }

.answered { display: flex; gap: 0.8vw; justify-content: center; flex-wrap: wrap; min-height: 8vh; }
.answered .player { width: 9vh; }

/* ----- results ---------------------------------------------------------- */
.results-title { font-size: 5vh; text-align: center; margin: 4vh 0 2vh; text-shadow: var(--shadow); }
.scoreboard { list-style: none; margin: 0 auto; padding: 0; width: min(80vw, 90vh); flex: 1; overflow: auto; }
.scoreboard li {
  display: flex; align-items: center; gap: 2vh;
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 1.4vh; padding: 1.4vh 2.4vh; margin-bottom: 1.2vh;
  font-size: 3vh;
}
.scoreboard img { width: 8vh; height: 8vh; object-fit: contain; }
.scoreboard .rank { font-size: 4vh; font-weight: 700; width: 2ch; color: var(--accent); }
.scoreboard .who { flex: 1; }
.scoreboard .sub { display: block; font-size: 1.8vh; color: var(--muted); }
.scoreboard .points { font-weight: 700; font-variant-numeric: tabular-nums; }

#toast {
  position: fixed; bottom: 3vh; left: 50%; transform: translateX(-50%);
  background: var(--panel-solid); border: 1px solid var(--line);
  border-radius: 1vh; padding: 1.2vh 2.4vh; font-size: 2vh;
  box-shadow: var(--shadow); display: none; z-index: 20;
}

/* Narrow screens — a tablet propped on the table rather than a television. */
@media (max-aspect-ratio: 1/1) {
  .lobby-body { flex-direction: column-reverse; }
  .join { width: 100%; display: flex; align-items: center; gap: 2vw; text-align: left; }
  .qr { width: 22vh; flex: none; }
  .answers { grid-template-columns: 1fr; }
  .code { font-size: 7vh; }
}

/* Which build this is. Deliberately faint and out of the way — it exists to be
   read when something is wrong, not to be part of the design. */
#version-badge {
  position: fixed;
  right: .6rem;
  bottom: .5rem;
  z-index: 50;
  font: 11px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
  letter-spacing: .04em;
  color: currentColor;
  opacity: .38;
  pointer-events: none;
  text-shadow: 0 1px 3px rgba(0, 0, 0, .6);
}
#version-badge:hover { opacity: .8; }

/* Where everyone ended up after a question. Two pens side by side: the good
   field and the pig pen. Deliberately large — this is the bit of the round
   people look up at and shout about. */
.pen {
  display: flex; align-items: center; gap: 1.2vw;
  padding: 1vh 1.6vh; border-radius: 1.2vh;
  border: 1px solid var(--line);
  background: rgba(12, 8, 6, 0.55);
  max-width: 46%;
}
.pen.good { border-color: var(--good); background: rgba(125, 220, 154, 0.12); }
.pen.bad  { border-color: var(--bad);  background: rgba(240, 141, 141, 0.12); }
.pen-label {
  flex: none; max-width: 9vw;
  font-size: 1.9vh; font-weight: 700; line-height: 1.15;
  text-transform: lowercase;
}
.pen.good .pen-label { color: var(--good); }
.pen.bad  .pen-label { color: var(--bad); }
.pen-animals { display: flex; gap: 0.6vw; flex-wrap: wrap; }
.pen .player { width: 8vh; animation: pop 380ms cubic-bezier(.2,1.4,.5,1); }

/* Shown only when the browser has refused to play audio. Sits where it will be
   seen from across a room but does not cover the room code. */
/* The announcer and subtitle toggles.
   
   Icons rather than a checkbox in the footer, because these are read from
   across a room and because the state has to be obvious at a glance: a person
   talking, with a circle-and-slash over them when they are not. */
#audio-controls {
  position: fixed;
  top: 2vh; right: 2vh;
  z-index: 30;
  display: flex; gap: 1.2vh;
}

.iconbtn {
  display: flex; flex-direction: column; align-items: center; gap: 0.4vh;
  background: rgba(8, 5, 3, 0.55);
  border: 0.22vh solid rgba(255, 255, 255, 0.18);
  border-radius: 1.4vh;
  padding: 1vh 1.2vh 0.8vh;
  cursor: pointer;
  color: var(--ink, #f6efe4);
  transition: border-color 140ms, background 140ms;
}
.iconbtn:hover { border-color: var(--accent); }
.iconbtn svg { width: 4.4vh; height: 4.4vh; display: block; }
.iconbtn .iconlabel {
  font-size: 1.35vh; font-weight: 700; letter-spacing: 0.04em;
  text-transform: uppercase; opacity: 0.75;
}

/* The parts of each glyph. `fill` is the body of the icon, `stroke` its
   outlines, `wave` the sound coming off the speaker. */
.iconbtn .fill { fill: currentColor; }
.iconbtn .stroke, .iconbtn .wave path {
  fill: none; stroke: currentColor;
  stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round;
}

/* Off: dimmed, and struck through. The slash is drawn in the icon rather than
   layered over it so it scales with the glyph and cannot drift. */
.iconbtn .slash { display: none; }
.iconbtn[aria-pressed="false"] { color: #9a8f80; background: rgba(8, 5, 3, 0.35); }
.iconbtn[aria-pressed="false"] .wave { display: none; }
.iconbtn[aria-pressed="false"] .slash { display: block; }
.iconbtn[aria-pressed="false"] .slash circle,
.iconbtn[aria-pressed="false"] .slash line {
  fill: none; stroke: #e2553d; stroke-width: 2.4; stroke-linecap: round;
}

/* Waiting for a tap: the browser has refused sound and only a gesture will
   lift it, so this one asks for attention rather than sitting quietly. */
.iconbtn.blocked {
  color: #2a1c00; background: var(--accent);
  border-color: var(--accent);
  animation: pop 380ms cubic-bezier(.2,1.4,.5,1);
}
.iconbtn.blocked .iconlabel { opacity: 1; }

#audio-controls[hidden] { display: none; }

/* What the announcer is saying, for a television that cannot say it.
   
   Bottom-centre and wide, the way a caption always is — read at a glance while
   looking at something else on the screen. */
#caption {
  position: fixed;
  /* Clear of the very bottom edge: on a television that is where the picture
     gets cropped, and where a set's own overlays land. */
  left: 50%; bottom: calc(4vh + 50px); transform: translateX(-50%);
  z-index: 29;
  max-width: 78vw;
  padding: 1.4vh 2.6vh;
  background: rgba(8, 5, 3, 0.82);
  border-radius: 1.2vh;
  box-shadow: var(--shadow);
  text-align: center;
}
#caption[hidden] { display: none; }
#caption-text {
  font-size: 2.6vh; font-weight: 650; line-height: 1.35;
  color: #f6efe4;
}

/* The "no room" notice. Covers everything, because a room code left on screen
   after its room has gone is worse than no code at all — people read it out. */
#blocked {
  position: fixed; inset: 0; z-index: 40;
  display: grid; place-items: center;
  background: rgba(8, 5, 3, 0.86);
  backdrop-filter: blur(4px);
}
#blocked[hidden] { display: none; }
.blocked-card {
  background: var(--panel-solid);
  border: 1px solid var(--line);
  border-radius: 2vh;
  padding: 4vh 5vh;
  text-align: center;
  max-width: 60vw;
  box-shadow: var(--shadow);
}
.blocked-card h2 { font-size: 4.4vh; margin: 0 0 1.4vh; }
.blocked-card p { font-size: 2.3vh; color: var(--muted); margin: 0 0 3vh; }
.blocked-card .controls { justify-content: center; }

.spinner {
  display: inline-block; width: 3vh; height: 3vh;
  border: 3px solid var(--line); border-top-color: var(--accent);
  border-radius: 50%; animation: spin 900ms linear infinite;
  margin-bottom: 2vh;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* How long until the next question.
   
   Centred on the stage, where the question itself appears — so the room is
   already looking at the right part of the screen when it arrives. Shown while
   the announcer is finishing a thought, which is exactly when an empty stage
   looks like something has gone wrong. */
.countdown {
  position: absolute; inset: 0;
  display: grid; place-content: center; gap: 0.6vh;
  pointer-events: none;
  text-align: center;
  /* Half see-through. It sits over the stage while the host finishes a
     thought, and a solid number there hides what the room was looking at —
     the point is to say "something is coming", not to take the screen. */
  opacity: 0.5;
}
.countdown[hidden] { display: none; }
.countdown-n {
  font-size: 18vh; font-weight: 700; line-height: 0.9;
  color: var(--accent); text-shadow: var(--shadow);
  font-variant-numeric: tabular-nums;
}
.countdown-k {
  font-size: 2.4vh; letter-spacing: 0.18em; text-transform: uppercase;
  color: var(--muted);
}
