/*
 * Components: the reusable pieces built by js/ui/components.js, shared by the phone,
 * the host controls and the big screen. Each block styles one component and its
 * variants. Uses tokens only (tokens.css); page layout lives in phone.css and tv.css.
 *
 * The look is a sticker poster: flat colour blocks, a thick black outline (--border) and a
 * hard offset shadow (--shadow) on anything you can touch or read. Components take their
 * colours from role tokens, so they work on both the blue poster stage and the cream one.
 *
 * Variants are modifier classes on the component itself, such as .btn.primary,
 * .prompt-card.huge or .groups.large. Pages never restyle a component's insides.
 */

/* --- Logo: two thoughts overlapping --------------------------------------------------- */

.logo {
  position: relative;
  width: var(--logo-width);
  height: var(--logo-height);
  margin: 0 auto var(--space-3);
}

.logo span {
  position: absolute;
  top: var(--logo-dot-top);
  width: var(--logo-dot);
  height: var(--logo-dot);
  border: var(--border) solid var(--color-line);
  border-radius: 50%;
}

.logo span:first-child {
  right: 0;
  background: var(--color-highlight);
}

.logo span:last-child {
  left: 0;
  background: var(--color-danger);
}

.logo.small {
  width: var(--logo-width-sm);
  height: var(--logo-height-sm);
  margin: 0;
}

.logo.small span {
  top: var(--logo-dot-top-sm);
  width: var(--logo-dot-sm);
  height: var(--logo-dot-sm);
  border-width: var(--border-sm);
}

/* --- Button: .btn [.primary | .ghost | .danger-ghost] [.small] [.wide] ------------------
 * A chunky block with a hard shadow. Pressing pushes it down into its shadow. */

.btn {
  appearance: none;
  border: var(--border) solid var(--color-line);
  border-radius: var(--radius-lg);
  padding: var(--space-4) var(--space-9);
  min-height: var(--control-height);
  font-weight: var(--weight-heavy);
  background: var(--color-quiet);
  color: var(--color-ink);
  box-shadow: var(--shadow-sm);
  cursor: pointer;
  transition:
    transform var(--duration-press) var(--ease),
    box-shadow var(--duration-press) var(--ease);
}

.btn:active:not(:disabled) {
  transform: translate(var(--shadow-offset-sm), var(--shadow-offset-sm));
  box-shadow: none;
}

.btn:disabled {
  opacity: 0.5;
  box-shadow: none;
  cursor: not-allowed;
}

/* The one action to take: yellow, with a bigger shadow. */
.btn.primary {
  background: var(--color-accent);
  color: var(--color-on-accent);
  box-shadow: var(--shadow);
}

.btn.primary:active:not(:disabled) {
  transform: translate(var(--shadow-offset), var(--shadow-offset));
}

/* A secondary choice: an outline in the colour of the text around it. */
.btn.ghost {
  border-color: currentcolor;
  background: transparent;
  color: inherit;
  box-shadow: none;
}

.btn.ghost:active:not(:disabled) {
  transform: scale(0.97);
}

/* A destructive action: a red block. */
.btn.danger-ghost {
  background: var(--color-danger);
  color: var(--color-ink);
}

.btn.small {
  min-height: var(--control-height-sm);
  padding: var(--space-2) var(--space-7);
  font-size: 0.9em;
}

.btn.wide {
  width: 100%;
}

/* A text button that looks like a link. */
.link {
  background: none;
  border: 0;
  padding: var(--space-2);
  color: var(--color-link);
  font-size: inherit;
  font-weight: var(--weight-bold);
  text-decoration: underline;
  text-decoration-thickness: var(--border-sm);
  cursor: pointer;
}

/* Buttons side by side, sharing the width. */
.row {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-4);
}

.row > .btn {
  flex: 1 1 auto;
}

/* --- Fields --------------------------------------------------------------------------- */

input:not([type='checkbox']) {
  width: 100%;
  min-height: var(--field-height);
  border: var(--border) solid var(--color-line);
  border-radius: var(--radius-md);
  padding: var(--space-4) var(--space-6);
  background: var(--color-field);
  color: var(--color-ink);
  font-size: var(--font-size-field);
  outline: none;
  transition: box-shadow var(--duration-quick) var(--ease);
}

input:focus {
  box-shadow: var(--shadow-mine);
}

input:disabled {
  background: var(--color-surface-sunken);
}

label {
  display: block;
  margin-bottom: var(--space-5);
  font-weight: var(--weight-bold);
}

label small {
  font-weight: var(--weight-regular);
  color: var(--color-ink-soft);
}

label.check {
  display: flex;
  align-items: center;
  gap: var(--space-4);
}

label.check input {
  width: 22px;
  height: 22px;
  accent-color: var(--color-mine);
}

label.inline {
  margin: var(--space-4) 0 0;
  font-weight: var(--weight-medium);
  font-size: 0.95em;
}

label.inline input {
  margin-top: var(--space-2);
  min-height: var(--tap-min);
}

.form-error {
  min-height: 1.2em;
  margin: var(--space-3) 0 0;
  color: var(--color-danger);
  font-weight: var(--weight-bold);
}

/* Something went wrong: a red block, readable on any stage. */
.alert {
  padding: var(--space-4) var(--space-6);
  border: var(--border) solid var(--color-line);
  border-radius: var(--radius-md);
  background: var(--color-danger);
  color: var(--color-ink);
  font-weight: var(--weight-bold);
  box-shadow: var(--shadow-sm);
}

/* --- Card: an outlined panel on the stage ----------------------------------------------- */

.card {
  margin: var(--space-7) 0;
  padding: var(--space-8);
  border: var(--border) solid var(--color-line);
  border-radius: var(--radius-xl);
  background: var(--color-surface);
  color: var(--color-ink);
  box-shadow: var(--shadow);
}

.card h2 {
  margin-bottom: var(--space-5);
  font-size: 1.35em;
}

.card h2 small {
  font-family: var(--font-body);
  font-size: 0.6em;
  color: var(--color-ink-soft);
}

.card .muted {
  color: var(--color-ink-soft);
}

.card .link {
  color: var(--color-mine);
}

details.card summary {
  font-weight: var(--weight-heavy);
  cursor: pointer;
}

details.card .card {
  margin: var(--space-5) 0 0;
  padding: 0;
  border: 0;
  box-shadow: none;
}

.section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: var(--space-9) 0 var(--space-4);
  font-size: 1.25em;
}

/* --- Prompt card: the phrase with its blank. .small | .huge ----------------------------- */

.round-label {
  margin: var(--space-4) 0 var(--space-3);
  text-align: center;
  color: var(--color-on-bg-soft);
  font-weight: var(--weight-heavy);
}

.prompt-card {
  position: relative;
  padding: 34px var(--space-8);
  border: var(--border) solid var(--color-line);
  border-radius: var(--radius-xl);
  background: var(--color-surface);
  color: var(--color-ink);
  box-shadow: var(--shadow-lg);
  text-align: center;
  font-family: var(--font-display);
  font-weight: var(--weight-heavy);
  font-size: clamp(1.9em, 9vw, 2.6em);
}

.prompt-card.small {
  padding: var(--space-8);
  font-size: 1.6em;
  box-shadow: var(--shadow);
}

.prompt-card.huge {
  padding: 7vh 2vw;
  border-width: var(--border-lg);
  font-size: 4em;
}

.prompt-text {
  display: inline-flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: center;
  gap: 0.3em;
}

/* The blank draws itself from the start of the line (the right, in Arabic). */
.blank {
  display: inline-block;
  min-width: 3.2em;
  padding: 0 0.2em;
  border-bottom: 0.12em dashed var(--color-blank);
  color: var(--color-blank);
  transform-origin: right center;
}

.blank.filled {
  border-bottom-style: solid;
}

/* --- Timer: a draining bar and the seconds left in a badge. .urgent in the last 5 ------- */

.timer {
  display: flex;
  align-items: center;
  gap: var(--space-4);
  margin: var(--space-7) 0 0;
}

.timer-track {
  flex: 1;
  height: var(--timer-track-height);
  overflow: hidden;
  border: var(--border) solid var(--color-line);
  border-radius: var(--radius-pill);
  background: var(--color-quiet);
  box-shadow: var(--shadow-sm);
}

.timer-fill {
  height: 100%;
  background: var(--color-success);
  transform-origin: right;
  transition: transform var(--duration-base) linear;
}

.timer-secs {
  display: grid;
  place-items: center;
  min-width: 2.3em;
  height: 2.3em;
  border: var(--border) solid var(--color-line);
  border-radius: 50%;
  background: var(--color-quiet);
  color: var(--color-ink);
  font-weight: var(--weight-heavy);
  font-size: 1.15em;
  box-shadow: var(--shadow-sm);
}

.timer.urgent .timer-fill {
  background: var(--color-danger);
}

.timer.urgent .timer-secs {
  background: var(--color-danger);
}

/* --- Answered count and name chips. .chip [.done] [.away], .chips.large ----------------- */

.count {
  margin: var(--space-7) 0 var(--space-4);
  text-align: center;
  color: var(--color-on-bg-soft);
  font-weight: var(--weight-bold);
}

.count b {
  color: var(--color-on-bg);
  font-size: 1.2em;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: var(--space-3);
}

.chip {
  padding: var(--space-1) var(--space-5);
  border: var(--border-sm) solid var(--color-line);
  border-radius: var(--radius-pill);
  background: var(--color-quiet);
  color: var(--color-ink);
  font-size: 0.9em;
  font-weight: var(--weight-bold);
  box-shadow: var(--shadow-sm);
}

.chip.done {
  background: var(--color-success);
}

.chip.away {
  opacity: 0.55;
  box-shadow: none;
}

/* The big screen: bigger chips that read across the room. */
.chips.large {
  gap: var(--space-5);
}

.chips.large .chip {
  padding: 0.25em 0.9em;
  border-width: var(--border);
  font-size: 1.15em;
}

/* --- Banner: a round's outcome. .win (yellow) | .some (green) | .none, .big -------------
 * Stuck on with a slight tilt, like a label. */

.banner {
  margin: var(--space-5) var(--space-2) var(--space-3);
  padding: var(--space-5) var(--space-6);
  border: var(--border) solid var(--color-line);
  border-radius: var(--radius-lg);
  background: var(--color-quiet);
  color: var(--color-ink);
  text-align: center;
  font-weight: var(--weight-heavy);
  font-size: 1.25em;
  box-shadow: var(--shadow);
  rotate: var(--tilt-sm);
}

.banner.win {
  background: var(--color-highlight);
}

.banner.some {
  background: var(--color-success);
}

.banner.big {
  padding: var(--space-7);
  font-size: 1.6em;
}

.hint {
  margin: var(--space-6) 0 0;
  text-align: center;
  color: var(--color-link);
  font-size: 0.9em;
  font-weight: var(--weight-bold);
}

/* --- Answer groups: revealed answers. .group.pair | .crowd | .alone [.selected] ---------
 * Yellow for a pair (+3 each), green for a crowd (+1 each), white for no match. The points
 * sit in a round badge stuck on at an angle. */

.groups {
  display: grid;
  gap: var(--space-6);
  margin-top: var(--space-7);
}

.group {
  position: relative;
  display: grid;
  grid-template-columns: auto 1fr;
  grid-template-areas:
    'pts word'
    'pts names';
  align-items: center;
  column-gap: var(--space-6);
  width: 100%;
  padding: var(--space-5) var(--space-6);
  border: var(--border) solid var(--color-line);
  border-radius: var(--radius-lg);
  background: var(--color-quiet);
  color: var(--color-ink);
  box-shadow: var(--shadow);
  text-align: start;
  font: inherit;
}

button.group {
  cursor: pointer;
}

.group .pts {
  grid-area: pts;
  display: grid;
  place-items: center;
  width: var(--points-badge);
  height: var(--points-badge);
  border: var(--border) solid var(--color-line);
  border-radius: 50%;
  background: var(--color-quiet);
  font-weight: var(--weight-heavy);
  font-size: 1.2em;
  rotate: var(--tilt-lg);
}

.group .word {
  grid-area: word;
  font-family: var(--font-display);
  font-weight: var(--weight-heavy);
  font-size: 1.5em;
  line-height: var(--line-height-tight);
}

.group .names {
  grid-area: names;
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-1) var(--space-4);
  color: var(--color-ink-soft);
  font-size: 0.92em;
  font-weight: var(--weight-bold);
}

.group.pair {
  background: var(--color-highlight);
}

.group.crowd {
  background: var(--color-success);
}

.group.alone .pts {
  background: var(--color-surface-sunken);
}

.group.selected {
  box-shadow: var(--ring-mine), var(--shadow-lg);
}

/* The big screen: a grid of bigger cards with the badge on the corner. .dense packs many
 * answers (more than six) into smaller cards so all of them fit on one screen. */
.groups.large {
  grid-template-columns: repeat(auto-fill, minmax(12em, 1fr));
  gap: 1.6vw;
  margin-top: 2.4vh;
}

.groups.large .group {
  grid-template-columns: 1fr;
  grid-template-areas:
    'word'
    'names';
  align-content: start;
  min-height: 5.5em;
  padding: 0.9em 1em 0.8em;
}

.groups.large .group .word {
  font-size: 2em;
}

.groups.large .group .names {
  font-size: 1em;
}

.groups.large .group .pts {
  position: absolute;
  top: -0.9em;
  left: -0.7em;
  width: 2.6em;
  height: 2.6em;
  font-size: 1.2em;
}

.groups.large.dense {
  grid-template-columns: repeat(auto-fill, minmax(8.5em, 1fr));
  gap: 1.2vw;
}

.groups.large.dense .group {
  min-height: 0;
  padding: 0.6em 0.8em 0.5em;
}

.groups.large.dense .group .word {
  font-size: 1.5em;
}

.groups.large.dense .group .names {
  font-size: 0.85em;
}

.groups.large.dense .group .pts {
  top: -0.8em;
  left: -0.6em;
  width: 2.2em;
  height: 2.2em;
  font-size: 1em;
}

/* --- Scoreboard: players in rows. li.mine, li.lead, li.away; .scores.lobby has no ranks,
 * .scores.compact has tight rows, .scores.cols-2 splits them into two columns (--rows per
 * column, set by the component). */

.scores {
  display: grid;
  gap: var(--space-3);
  margin: 0;
  padding: 0;
  list-style: none;
}

.scores li {
  display: flex;
  align-items: center;
  gap: var(--space-4);
  min-height: var(--row-min-height);
  padding: var(--space-3) var(--space-5);
  border: var(--border-sm) solid var(--color-line);
  border-radius: var(--radius-md);
  background: var(--color-quiet);
  color: var(--color-ink);
  box-shadow: var(--shadow-sm);
}

.scores li.lead {
  background: var(--color-highlight);
}

.scores li.mine {
  background: var(--color-mine);
  color: var(--color-on-mine);
}

.scores li.away {
  opacity: 0.6;
  box-shadow: none;
}

.scores.compact {
  gap: var(--space-1);
}

.scores.compact li {
  min-height: 0;
  padding: 2px var(--space-4);
  box-shadow: none;
}

/* Two columns: ranks run down the first column, then the second (right to left). */
.scores.cols-2 {
  grid-template-rows: repeat(var(--rows), auto);
  grid-template-columns: repeat(2, minmax(0, 1fr));
  grid-auto-flow: column;
  column-gap: var(--space-5);
}

.rank {
  width: 1.6em;
  font-weight: var(--weight-heavy);
  opacity: 0.7;
}

.pname {
  flex: 1;
  min-width: 0;
  font-weight: var(--weight-bold);
  overflow-wrap: anywhere;
}

.pname small {
  font-weight: var(--weight-regular);
  opacity: 0.75;
}

.pname .away-tag {
  color: var(--color-danger);
  opacity: 1;
}

.pscore {
  display: inline-flex;
  align-items: center;
  gap: var(--space-3);
  font-weight: var(--weight-heavy);
  font-size: 1.2em;
}

/* A number that counts up keeps its width steady while it changes. */
.pnum {
  display: inline-block;
  min-width: 1.4ch;
  font-variant-numeric: tabular-nums;
  text-align: center;
}

/* Points waiting to be added when the next round starts. */
.pending {
  display: inline-block;
  padding: 0 var(--space-3);
  border: var(--border-sm) solid var(--color-line);
  border-radius: var(--radius-pill);
  background: var(--color-highlight);
  color: var(--color-ink);
  font-size: 0.7em;
  font-weight: var(--weight-heavy);
}

.tools {
  display: flex;
  gap: var(--space-2);
}

/* Small square icon buttons in a row (host: −, +, ✕). */
.mini {
  width: var(--control-height-sm);
  height: var(--control-height-sm);
  border: var(--border-sm) solid var(--color-line);
  border-radius: var(--radius-sm);
  background: var(--color-surface);
  color: var(--color-ink);
  font-size: 1.1em;
  font-weight: var(--weight-heavy);
  cursor: pointer;
}

.mini:active {
  transform: scale(0.92);
}

.mini.danger {
  background: var(--color-danger);
}

/* --- Segmented choice: .segs > .seg[.on] ----------------------------------------------- */

.segs {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-3);
}

.seg {
  min-width: 56px;
  min-height: var(--tap-min);
  border: var(--border-sm) solid var(--color-line);
  border-radius: var(--radius-md);
  background: var(--color-field);
  color: var(--color-ink);
  font-weight: var(--weight-heavy);
  cursor: pointer;
  transition: transform var(--duration-quick) var(--ease-bounce);
}

.seg.on {
  background: var(--color-accent);
  color: var(--color-on-accent);
  box-shadow: var(--shadow-sm);
  transform: translateY(calc(var(--shadow-offset-sm) * -1));
}

.seg-note {
  margin-inline-start: var(--space-1);
  color: var(--color-ink-soft);
}

/* --- QR code and room code -------------------------------------------------------------- */

.qr svg {
  display: block;
  width: 100%;
  height: auto;
  border-radius: var(--radius-sm);
  background: var(--palette-white); /* scanners need pure white */
}

.qr.big {
  width: min(100%, 42vh);
  margin: 0 auto;
}

.big-code {
  margin: 0 0 var(--space-2);
  direction: ltr;
  text-align: right;
  font-size: 2.4em;
  font-weight: var(--weight-heavy);
  letter-spacing: 0.12em;
}

/* --- Dialog sheet ----------------------------------------------------------------------- */

dialog {
  width: min(520px, calc(100% - 24px));
  max-height: calc(100% - 40px);
  padding: 0;
  border: var(--border) solid var(--color-line);
  border-radius: var(--radius-xl);
  background: var(--color-surface);
  color: var(--color-ink);
  box-shadow: var(--shadow-lg);
}

dialog::backdrop {
  background: var(--scrim);
}

.sheet {
  padding: 20px;
}

.sheet h2 {
  margin-bottom: var(--space-3);
}

.sheet hr {
  margin: var(--space-7) 0;
  border: 0;
  border-top: var(--border-sm) dashed var(--color-line);
}

.sheet .muted {
  color: var(--color-ink-soft);
}

.sheet .btn.ghost {
  color: var(--color-ink);
}

.sheet .label {
  margin: var(--space-5) 0 var(--space-2);
  font-weight: var(--weight-bold);
}

/* --- Rules ------------------------------------------------------------------------------ */

.rules {
  margin: var(--space-3) 0;
  padding-inline-start: 1.3em;
}

.rules li {
  margin: var(--space-1) 0;
}

.rules-tip {
  margin: var(--space-3) 0 0;
  padding: var(--space-4) var(--space-5);
  border: var(--border-sm) dashed var(--color-line);
  border-radius: var(--radius-md);
  background: var(--tint-highlight-wash);
}

/* --- Toast ------------------------------------------------------------------------------ */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + env(safe-area-inset-bottom));
  z-index: var(--z-toast);
  max-width: calc(100% - 32px);
  padding: var(--space-4) var(--space-8);
  border: var(--border) solid var(--color-line);
  border-radius: var(--radius-pill);
  background: var(--color-accent);
  color: var(--color-on-accent);
  font-weight: var(--weight-bold);
  text-align: center;
  box-shadow: var(--shadow-sm);
  opacity: 0;
  transform: translate(-50%, 20px);
  transition: all var(--duration-base) var(--ease-bounce);
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

/* --- Sticker: a hand-drawn decoration. .sticker-<kind> .tone-<role> ----------------------
 * Every colour comes from a role token. .fill takes the tone, .outline and .ink take the
 * outline colour, .white takes the field colour. */

.sticker {
  display: block;
  width: 100%;
  height: auto;
  overflow: visible;
  pointer-events: none;
}

.sticker.tone-line {
  --sticker-tone: var(--color-line);
}

.sticker.tone-highlight {
  --sticker-tone: var(--color-highlight);
}

.sticker.tone-success {
  --sticker-tone: var(--color-success);
}

.sticker.tone-danger {
  --sticker-tone: var(--color-danger);
}

.sticker.tone-mine {
  --sticker-tone: var(--color-mine);
}

.sticker.tone-quiet {
  --sticker-tone: var(--color-quiet);
}

.sticker .fill {
  fill: var(--sticker-tone);
}

.sticker .outline {
  stroke: var(--color-line);
  stroke-width: 6;
  stroke-linejoin: round;
}

.sticker .ink {
  fill: var(--color-line);
}

.sticker .white {
  fill: var(--color-field);
}

.sticker .stroke-tone {
  stroke: var(--sticker-tone);
  stroke-width: 13;
  stroke-linecap: round;
}

.sticker text {
  fill: var(--color-ink);
  font-family: var(--font-display);
  font-weight: var(--weight-heavy);
  font-size: var(--sticker-text);
}

/* The eyes look around and blink now and then. */
.sticker-eyes .pupils {
  animation: look var(--duration-look) ease-in-out infinite;
}

.sticker-eyes .eyeballs {
  transform-box: fill-box;
  transform-origin: center;
  animation: eye-blink var(--duration-look) linear infinite;
}

/* --- Stage: the decorations behind a page --------------------------------------------------
 * A fixed layer under #app: the wavy band and the idle stickers. The page's layout file
 * places each .slot-N with top/left/right/bottom, --size and --turn. */

.stage {
  position: fixed;
  inset: 0;
  z-index: var(--z-stage);
  overflow: hidden;
  pointer-events: none;
}

.stage .band {
  position: absolute;
  inset: auto 0 0;
  height: var(--band-height);
  background: var(--color-band);
}

.stage .wave {
  position: absolute;
  bottom: calc(100% - var(--border-sm)); /* overlap the band a little: no hairline gap */
  left: 0;
  width: 100%;
  height: var(--wave-height);
  fill: var(--color-band);
}

.stage-item {
  position: absolute;
  width: var(--size, var(--sticker-md));
  transform: rotate(var(--turn, 0deg));
}

.sticker-loop.float {
  animation: float var(--duration-float) ease-in-out infinite;
  animation-delay: var(--delay, 0s);
}

.sticker-loop.still {
  animation: none;
}

.sticker-loop.spin {
  animation: spin var(--duration-spin) linear infinite;
  animation-delay: var(--delay, 0s);
}
