/* deck, the modes: roles, piles and wheel, poll and copy, closest, bowl, play.
 *
 * render.mjs links this sheet as the first child of .deck, and only on a page
 * whose tool object names a mode, so a plain deck never downloads it
 * (README.md, "Weights"). It holds the layout of the FIRST paint: every control
 * a mode adds has its room from the start and nothing moves when the script
 * wakes up. The full-screen layout is play.css, fetched by mode-play.js.
 *
 * Colours, sizes and motion come from the engine's custom properties only.
 */

/* ------------------------------------------------------------------ shared */

.deck__panel {
  display: grid;
  gap: var(--space-3);
  padding: var(--space-4);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

/* A control that only a script can work is not offered where there is none. */
@media (scripting: none) {
  .deck__panel,
  .deck__full,
  .deck__copy,
  .deck__spin,
  .deck__wheel {
    display: none;
  }
}

/* ---------------------------------------------------- room for the longest card */

/* modes.mjs counts the lines the longest card of the dataset needs, on a phone
   (data-lines) and on a wide screen (data-lines-wide), and the answer block of
   a question the same way. The text keeps that room from the first paint, so a
   long card after a short one moves nothing under it. `lh` follows whatever
   size a brand kit gives the text; the em line is for a browser without it. */
.deck__card[data-lines-wide="2"] { --deck-lines: 2; }
.deck__card[data-lines-wide="3"] { --deck-lines: 3; }
.deck__card[data-lines-wide="4"] { --deck-lines: 4; }
.deck__card[data-lines-wide="5"] { --deck-lines: 5; }
.deck__card[data-lines-wide="6"] { --deck-lines: 6; }
.deck__card[data-lines-wide="7"] { --deck-lines: 7; }
.deck__card[data-lines-wide="8"] { --deck-lines: 8; }
.deck__card[data-answer-lines-wide="2"] { --deck-answer-lines: 2; }
.deck__card[data-answer-lines-wide="3"] { --deck-answer-lines: 3; }
.deck__card[data-answer-lines-wide="4"] { --deck-answer-lines: 4; }
.deck__card[data-answer-lines-wide="5"] { --deck-answer-lines: 5; }
.deck__card[data-answer-lines-wide="6"] { --deck-answer-lines: 6; }
.deck__card[data-answer-lines-wide="7"] { --deck-answer-lines: 7; }
.deck__card[data-answer-lines-wide="8"] { --deck-answer-lines: 8; }

.deck__card:is([data-lines], [data-lines-wide], [data-phase]) [data-deck-text] {
  display: grid;
  align-content: center;
  justify-items: center;
  min-height: calc(var(--deck-lines, 1) * 1.2em);
  min-height: calc(var(--deck-lines, 1) * 1lh);
}

/* A word deck of whole sentences (truths and dares) is set like a question. */
.deck__card[data-sentences] .deck__text {
  max-width: 32ch;
  font-size: var(--step-3);
  line-height: 1.2;
}

/* -------------------------------------------------------------------- play */

.deck__full {
  grid-column: 1 / -1;
  justify-self: start;
}

/* ------------------------------------------------------------------- roles */

/* The card keeps the height of its tallest state (an open role with its line,
   and the last screen with "who starts"), so passing the phone moves nothing. */
.deck__card[data-seat] {
  align-content: start;
  min-height: 17rem;
}

.deck__role,
.deck__after {
  display: grid;
  justify-items: center;
  align-content: start;
  gap: var(--space-3);
  width: 100%;
  /* The button, the word at its most lines, and three lines under it. */
  min-height: calc(var(--tap) + 2 * var(--space-3) + var(--deck-lines, 1) * 1.15 * var(--step-5) + 4.8 * var(--step-0));
  margin-top: var(--space-2);
}

.deck__role > summary {
  min-width: 14rem;
}

.deck__role-line,
.deck__starter,
.deck__unmask-text {
  max-width: 36ch;
  margin: 0;
}

.deck__role-line {
  color: var(--ink-muted);
}

.deck__starter {
  font: var(--display-weight) var(--step-2) / 1.2 var(--font-display);
  text-wrap: balance;
}

.deck__starter:focus-visible {
  outline: 3px solid var(--ring);
  outline-offset: 4px;
  border-radius: var(--radius-sm);
}

.deck__unmask {
  display: grid;
  justify-items: center;
  gap: var(--space-2);
}

.deck__unmask > summary {
  cursor: pointer;
}

.deck__unmask > summary::-webkit-details-marker {
  display: none;
}

.deck__unmask-text {
  min-height: 2.8em;
  font-weight: 700;
}

.deck__table {
  grid-template-columns: auto auto 1fr;
  align-items: center;
  gap: var(--space-3) var(--space-5);
}

.deck__table > .deck__heading {
  grid-column: 1 / -1;
}

.deck__stepper {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.deck__players {
  min-width: 2.5ch;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.deck__table .check:has(:disabled) {
  color: var(--ink-muted);
}

/* ---------------------------------------------------------- piles and wheel */

.deck[data-modes~="piles"] > .deck__controls {
  grid-template-columns: 1fr 1fr;
}

/* On a wide screen the four buttons share one row, so the words of the first card stay in the first screen. */
@container (min-width: 44rem) {
  .deck[data-modes~="piles"][data-modes~="wheel"] > .deck__controls {
    grid-template-columns: repeat(4, 1fr);
    max-width: none;
  }
}

/* Without a wheel beside it, Skip takes the whole second row. */
.deck[data-modes~="piles"]:not([data-modes~="wheel"]) .deck__skip {
  grid-column: 1 / -1;
}

/* The ring fills on the pile the card on the table came from. */
.deck__swatch {
  flex: none;
  width: 0.75rem;
  height: 0.75rem;
  margin-right: var(--space-2);
  border: 2px solid currentColor;
  border-radius: 50%;
}

[data-on] > .deck__swatch {
  background: currentColor;
}

.deck__card[data-pile] {
  border-top: 0.375rem solid var(--brand);
}

.deck__card[data-pile="1"] {
  border-top-color: var(--accent);
}

.deck__wheel {
  position: relative;
  display: grid;
  justify-items: center;
  width: 6rem;
  height: 6.5rem;
  padding-top: 0.5rem;
}

.deck__pointer {
  position: absolute;
  top: 0;
  z-index: 1;
  fill: var(--ink);
  stroke: var(--surface);
  stroke-width: 1.5;
}

.deck__wheel-face {
  border-radius: 50%;
  box-shadow: 0 0 0 2px var(--line-strong);
  transform: rotate(var(--deck-turn, 0deg));
}

.deck__wedge {
  stroke: var(--surface);
  stroke-width: 1;
}

.deck__wedge--0 { fill: var(--brand); }
.deck__wedge--1 { fill: var(--accent); }

.deck__wedge-letter {
  font: 700 0.75rem / 1 var(--font-body);
}

.deck__wedge-letter--0 { fill: var(--brand-ink); }
.deck__wedge-letter--1 { fill: var(--accent-ink); }

.deck__hub {
  fill: var(--surface);
  stroke: var(--line-strong);
  stroke-width: 2;
}

/* While the wheel turns the old card steps back: it is not the answer. */
.deck__card[data-spinning] > .deck__text,
.deck__card[data-spinning] > [data-deck-label] {
  opacity: 0.35;
}

/* -------------------------------------------------------------------- poll */

.deck__poll {
  grid-template-columns: 1fr 1fr;
  align-content: start;
}

.deck__poll[data-most="3"],
.deck__poll[data-most="4"] {
  min-height: calc(13rem + var(--space-3));
}

.deck__poll[data-most="3"] > .deck__option,
.deck__poll[data-most="4"] > .deck__option {
  min-height: 6.5rem;
}

/* Three options: the third takes the whole second row. */
.deck__poll[data-count="3"] > :nth-child(3) {
  grid-column: 1 / -1;
}

.deck__letter {
  position: absolute;
  top: var(--space-2);
  left: var(--space-2);
  display: grid;
  place-items: center;
  width: 1.5rem;
  height: 1.5rem;
  border-radius: 50%;
  background: var(--surface-2);
  color: var(--ink-muted);
  font-size: var(--step--1);
  font-weight: 700;
}

.deck__poll-line {
  flex-direction: column;
  gap: var(--space-1);
}

.deck__poll-line > .deck__vote-tools {
  flex-wrap: wrap;
  justify-content: center;
}

/* ----------------------------------------------------------------- closest */

.deck__guesses {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 11rem), 1fr));
  gap: var(--space-3);
  margin: 0;
  padding: 0;
  list-style: none;
}

.deck__guess {
  display: grid;
  align-content: start;
  gap: var(--space-1);
  min-width: 0;
}

.deck__guess-name {
  overflow: hidden;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.deck__guess-input {
  width: 100%;
  min-height: var(--tap);
  font-variant-numeric: tabular-nums;
}

/* Two lines are kept free under every field, so a ranking moves nothing. */
.deck__guess-out {
  min-height: 2.7em;
  color: var(--ink-muted);
  font-size: var(--step--1);
  line-height: 1.35;
}

/* A distance of thirteen digits or more breaks once: a third line for a deck with such an answer. */
[data-long-numbers] .deck__guess-out {
  min-height: 4.05em;
}

[data-state="first"] > .deck__guess-out {
  color: var(--ok);
  font-weight: 700;
}

[data-state="first"] > .deck__guess-input {
  border-color: var(--ok);
  box-shadow: 0 0 0 1px var(--ok);
}

[data-state="bad"] > .deck__guess-out {
  color: var(--bad);
}

[data-state="bad"] > .deck__guess-input {
  border-color: var(--bad);
}

[data-state="over"] > .deck__guess-input {
  color: var(--ink-muted);
  text-decoration: line-through;
}

.deck__closest-tools {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
}

/* Three whole lines, four on a phone: a tie names every team and the number. */
.deck__verdict {
  min-height: 4.8em;
  min-height: 3lh;
  margin: 0;
}

/* The answer block keeps the room of its longest answer and note: the button,
   the small "Answer" label, and every line at the height of the taller of the
   two kinds (the answer itself, style.css). */
.deck[data-modes~="closest"] .deck__answer {
  min-height: calc(var(--tap) + var(--space-2) + 1.3 * var(--step--1) + var(--deck-answer-lines, 1) * 1.2 * var(--step-2));
}

[data-ranked] > .deck__verdict {
  color: var(--ink);
  font-weight: 700;
}

/* -------------------------------------------------------------------- bowl */

.deck__bowl-line {
  margin: 0;
  color: var(--ink-muted);
  font-size: var(--step--1);
  font-variant-numeric: tabular-nums;
}

/* "Pass the phone", "Round 2" and the final score are sentences, not slips. */
.deck__card[data-phase]:not([data-phase="slip"]) .deck__text {
  max-width: 24ch;
  font-size: var(--step-3);
  line-height: 1.2;
}

/* A slip and a sentence keep the same room, whichever is on the card. */
.deck__card[data-phase] {
  --deck-phase-lines: 2;
}

.deck__card[data-phase="slip"] [data-deck-text] {
  min-height: max(calc(var(--deck-lines, 1) * 1lh), calc(var(--deck-phase-lines) * 1.2 * var(--step-3)));
}

.deck__card[data-phase]:not([data-phase="slip"]) [data-deck-text] {
  min-height: max(calc(var(--deck-phase-lines) * 1lh), calc(var(--deck-lines, 1) * 1.15 * var(--step-5)));
}

/* A deck with pictures keeps the picture's room while the card shows a sentence. */
.deck__card[data-phase] .deck__emoji:empty {
  display: block;
  height: calc(1.265 * var(--step-5));
}

.deck__bowl-rounds {
  margin: 0;
  white-space: pre-wrap;
}

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

/* The team whose turn it is. */
.deck__team[data-turn] {
  border-color: var(--brand);
  box-shadow: inset 0.25rem 0 0 var(--brand);
}

/* ------------------------------------------------------------------- phone */

@container (max-width: 34rem) {
  .deck__card[data-lines="2"] { --deck-lines: 2; }
  .deck__card[data-lines="3"] { --deck-lines: 3; }
  .deck__card[data-lines="4"] { --deck-lines: 4; }
  .deck__card[data-lines="5"] { --deck-lines: 5; }
  .deck__card[data-lines="6"] { --deck-lines: 6; }
  .deck__card[data-lines="7"] { --deck-lines: 7; }
  .deck__card[data-lines="8"] { --deck-lines: 8; }
  .deck__card[data-answer-lines="2"] { --deck-answer-lines: 2; }
  .deck__card[data-answer-lines="3"] { --deck-answer-lines: 3; }
  .deck__card[data-answer-lines="4"] { --deck-answer-lines: 4; }
  .deck__card[data-answer-lines="5"] { --deck-answer-lines: 5; }
  .deck__card[data-answer-lines="6"] { --deck-answer-lines: 6; }
  .deck__card[data-answer-lines="7"] { --deck-answer-lines: 7; }
  .deck__card[data-answer-lines="8"] { --deck-answer-lines: 8; }

  /* "Round 3 of 3: One word only" and a long team name take two lines here. */
  .deck__card[data-phase] {
    --deck-phase-lines: 3;
  }

  .deck__card[data-phase] > [data-deck-label] {
    min-height: 3.2em;
    min-height: 2lh;
  }

  /* "Round 1 of 3 · 60 of 60 slips left · Turn: Team 1" is two lines here, "All rounds played · 0 of 60 slips left" is one. */
  .deck__bowl-line {
    min-height: 3.2em;
    min-height: 2lh;
  }

  .deck__verdict {
    min-height: 6.4em;
    min-height: 4lh;
  }

  .deck__table {
    grid-template-columns: 1fr;
    gap: var(--space-2);
  }

  /* A row each: letter, words, count, and the bar under them. */
  .deck__poll {
    grid-template-columns: 1fr;
    gap: var(--space-2);
  }

  .deck__poll > .deck__option,
  .deck__poll[data-most] > .deck__option {
    grid-template-columns: auto 1fr auto;
    grid-template-rows: 1fr auto;
    align-items: center;
    gap: var(--space-2) var(--space-3);
    min-height: 4.5rem;
    padding: var(--space-3);
    text-align: left;
  }

  .deck__poll .deck__letter {
    position: static;
  }

  .deck__poll .deck__option-text {
    font-size: var(--step-0);
    text-wrap: wrap;
  }

  .deck__poll .deck__bar {
    grid-column: 1 / -1;
  }

  .deck__poll .deck__picked {
    top: calc(var(--space-1) * -1);
    right: calc(var(--space-1) * -1);
  }

  .deck__poll[data-most="2"] { min-height: calc(9rem + var(--space-2)); }
  .deck__poll[data-most="3"] { min-height: calc(13.5rem + 2 * var(--space-2)); }
  .deck__poll[data-most="4"] { min-height: calc(18rem + 3 * var(--space-2)); }

  .deck__poll[data-count="3"] > :nth-child(3) {
    grid-column: auto;
  }

  /* Two whole lines for the words, and two rows for the three small buttons. */
  .deck__poll-line > .deck__vote-text {
    min-height: 3.2em;
    min-height: 2lh;
  }

  .deck__poll-line > .deck__vote-tools:has(.deck__copy) {
    min-height: calc(2 * var(--tap) + var(--space-1));
    align-content: start;
  }

  .deck__bowl-row > .segmented {
    width: 100%;
  }
}

/* ------------------------------------------------------------------ motion */

/* The wheel is the one move longer than 400 ms: a wheel that stopped in less
   would read as a glitch. It is transform only, and a visitor who asked for
   less motion gets the answer at once (mode-piles.js sets data-still). */
@media (prefers-reduced-motion: no-preference) {
  .deck__wheel:not([data-still]) > .deck__wheel-face {
    transition: transform 1400ms cubic-bezier(0.12, 0.6, 0.12, 1);
  }

  .deck__card > .deck__text,
  .deck__card > [data-deck-label] {
    transition: opacity 200ms var(--ease);
  }

  [data-state="first"] > .deck__guess-out {
    animation: deck-place 250ms var(--ease);
  }
}

@keyframes deck-place {
  from { opacity: 0; transform: translateY(0.25rem); }
}

/* ------------------------------------------------------------------- print */

@media print {
  /* A poll on paper: every option with a box to tick, black on white. */
  .deck__poll {
    grid-template-columns: 1fr;
    min-height: 0 !important;
  }

  .deck__poll > .deck__option {
    display: flex;
    align-items: baseline;
    gap: 0.5rem;
    min-height: 0 !important;
    padding: 0.25rem 0;
    border: 0;
    text-align: left;
  }

  .deck__poll > .deck__option::before {
    content: "";
    flex: none;
    width: 0.8rem;
    height: 0.8rem;
    border: 1.5px solid #000;
  }

  .deck__poll .deck__letter {
    position: static;
    background: none;
    color: #000;
  }

  /* Paper keeps no room free. */
  .deck__card [data-deck-text],
  .deck__card > [data-deck-label],
  .deck__role,
  .deck[data-modes] .deck__answer {
    min-height: 0 !important;
  }

  .deck__poll .deck__votes,
  .deck__poll .deck__bar,
  .deck__poll .deck__picked,
  .deck__bowl-line,
  .deck__after {
    display: none;
  }
}
