/* The game screen: the scoreboard strip, the table, the typed word and the keyboard.

   Sizes that the tile geometry depends on are not written here. views/game.js sets them as
   custom properties from the layout module (public/js/layout.js), so this sheet and the
   positions the tiles are given cannot drift:
     --g-bar    the top bar            --g-pad    the padding round the table
     --g-line   the line of words      --g-typed  the typed row
     --g-keys   the keyboard           --g-tile   the table's tile
   The values below are only what shows before the first game is laid out.

   The table itself is quiet: butter tiles in the pool, tiles tinted with their owner's colour
   in the lanes. The one gold thing on the screen is GO, when it can be pressed. A word that
   is about to be taken is caught in the torch.

   Motion. A piece is put in its place with `translate` (table.js) and glides there. The
   flights, flips and landings are fx.js, which animates `transform` on top of that; what is
   here is the rest: the marks an event leaves behind (a taken word's ghost, the ring on a new
   word, the event line, a score flashing) and last call. With motion reduced nothing here
   moves: the same marks fade in and out. */

.game {
  position: relative;
  --g-bar: 36px;
  --g-pad: 12px;
  --g-line: 22px;
  --g-typed: 44px;
  --g-keys: 152px;
  --g-tile: 32px;
  display: flex;
  flex-direction: column;
  padding: var(--safe-top) var(--safe-right) var(--safe-bottom) var(--safe-left);
}

.game > * {
  flex: none;
}

/* Online, while the connection comes back: a card over the table (which stays in view), and
   nothing in the way of the keys, which still work. */
.reconnecting {
  position: absolute;
  z-index: var(--layer-overlay);
  top: calc(var(--safe-top) + var(--g-bar));
  left: 0;
  right: 0;
  bottom: calc(var(--safe-bottom) + var(--g-line) + var(--g-typed) + var(--g-keys));
  display: grid;
  place-items: center;
  padding: var(--g-pad);
  background: var(--scrim);
  pointer-events: none;
  animation: fade-in var(--motion-quick) linear both;
}

.reconnecting__card {
  display: grid;
  justify-items: center;
  gap: var(--space-2);
  padding: var(--space-4) var(--space-5);
  border-radius: var(--radius-l);
  background: var(--stage);
  box-shadow: var(--shadow-soft);
  text-align: center;
}

.reconnecting__card .hop .tile {
  --tile-size: 28px;
}

.reconnecting__title {
  font-size: var(--text-l);
  font-weight: var(--weight-display);
  line-height: var(--leading-tight);
}

.reconnecting__note {
  color: var(--text-soft);
  font-size: var(--text-s);
  line-height: var(--leading-snug);
}

/* Quick match, the opponent's connection gone: a note pinned under the scores, over the top
   of the table, and from 15 s on the way to take the win. The game goes on around it. */
.away-note {
  position: absolute;
  z-index: var(--layer-overlay);
  top: calc(var(--safe-top) + var(--g-bar) + var(--space-3));
  left: 50%;
  translate: -50% 0;
  display: flex;
  align-items: center;
  gap: var(--space-3);
  width: max-content;
  max-width: calc(100% - 2 * var(--g-pad));
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius-l);
  background: var(--panel-up);
  box-shadow: var(--shadow-soft);
  animation: fade-in var(--motion-quick) linear both;
}

/* A long name takes a second line rather than being cut short beside the button. */
.away-note__text {
  display: -webkit-box;
  min-width: 0;
  overflow: hidden;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  font-size: var(--text-s);
  font-weight: var(--weight-label);
  line-height: var(--leading-snug);
  overflow-wrap: break-word;
}

/* The note's own height holds it; a plain button would be taller than the strip it sits in. */
.away-note__win {
  --btn-depth: var(--lip-s);
  flex: none;
  min-height: var(--tap);
  padding-block: 0;
  border-radius: var(--radius-pill);
  font-size: var(--text-m);
}

/* Pressed: it stays down while the win is on its way. */
.away-note__win.is-waiting {
  transform: translateY(calc(var(--btn-depth) - var(--lip-down)));
  box-shadow: 0 var(--lip-down) 0 var(--btn-lip);
  cursor: default;
}

.away-note:has(.away-note__win:not([hidden])) {
  padding: var(--space-2) var(--space-2) calc(var(--space-2) + var(--lip-s)) var(--space-4);
}

/* --- The top bar: who is winning ---------------------------------------------------------- */

.game-bar {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  height: var(--g-bar);
  padding: 0 var(--g-pad);
}

/* Small and out of the way; the touch target reaches past what is drawn. */
.game-leave {
  appearance: none;
  position: relative;
  display: grid;
  place-items: center;
  flex: none;
  width: 26px;
  height: 26px;
  margin: 0 0 var(--lip-xs);
  padding: 0;
  border: 0;
  border-radius: var(--radius-round);
  background: var(--panel);
  box-shadow: 0 var(--lip-xs) 0 var(--panel-lip);
  color: var(--text-soft);
  cursor: pointer;
  transition: transform var(--motion-press) linear, box-shadow var(--motion-press) linear;
}

.game-leave::before {
  content: "";
  position: absolute;
  inset: -9px;
}

.game-leave:active {
  transform: translateY(calc(var(--lip-xs) - var(--lip-down)));
  box-shadow: 0 var(--lip-down) 0 var(--panel-lip);
}

.scores {
  display: flex;
  align-items: center;
  flex: 1 1 0;
  gap: var(--space-2);
  min-width: 0;
  height: 100%;
}

/* One player: badge, name and score. The player's own is mirrored, so in a two-player game
   the two scores face each other across the tug-of-war. */
.score {
  position: relative;
  display: flex;
  align-items: center;
  gap: var(--space-2);
  min-width: 0;
  height: 100%;
}

.score--you {
  flex: none;
  flex-direction: row-reverse;
}

.score__who {
  display: flex;
  align-items: center;
  gap: 5px;
  min-width: 0;
}

.score--you .score__who {
  flex-direction: row-reverse;
}

.score .player-badge {
  width: 20px;
  height: 20px;
  border-radius: calc(var(--radius-s) * 0.6);
}

.score .player-badge .player-mark {
  width: 10px;
  height: 10px;
}

.score__face {
  width: 24px;
  height: 24px;
}

.score__name {
  min-width: 0;
  overflow: hidden;
  font-size: var(--text-s);
  font-weight: var(--weight-label);
  line-height: var(--leading-snug);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.score__figure {
  position: relative;
  display: flex;
  align-items: center;
  flex: none;
  gap: 3px;
}

.score__num {
  min-width: 1.1em;
  padding-top: 2px;
  font-size: var(--text-xl);
  font-weight: var(--weight-display);
  font-variant-numeric: tabular-nums;
  line-height: var(--leading-flat);
  text-align: center;
}

/* The player's own score flashes as it starts to count: mint and a jump for more, coral and a
   dip for fewer. */
.score.is-up .score__num {
  animation: score-up var(--motion-flash) var(--ease-out);
}

.score.is-down .score__num {
  animation: score-down var(--motion-flash) var(--ease-out);
}

@keyframes score-up {
  0% { color: var(--mint); transform: none; }
  18% { color: var(--mint); transform: translateY(-3px) scale(1.4); }
  60% { color: var(--mint); transform: none; }
}

@keyframes score-down {
  0% { color: var(--coral); transform: none; }
  18% { color: var(--coral); transform: translateY(3px) scale(0.78); }
  60% { color: var(--coral); transform: none; }
}

:root[data-motion="reduced"] .score.is-up .score__num {
  animation-name: score-up-still;
}

:root[data-motion="reduced"] .score.is-down .score__num {
  animation-name: score-down-still;
}

@keyframes score-up-still {
  0%, 60% { color: var(--mint); }
}

@keyframes score-down-still {
  0%, 60% { color: var(--coral); }
}

/* The leader's score wears the crown. It sits above the figure, so nothing shifts when it moves. */
.score__crown {
  position: absolute;
  bottom: 100%;
  left: 50%;
  width: 14px;
  height: 9px;
  margin: 0 0 -5px -7px;
  color: var(--torch);
  opacity: 0;
  transition: opacity var(--motion-quick) linear;
}

.score.is-leading .score__crown {
  opacity: 1;
}

.score.is-gone {
  opacity: 0.5;
}

/* Online: a seat whose connection has dropped. Its words are still on the table. */
.score__away {
  flex: none;
  padding: 0 5px;
  border-radius: var(--radius-pill);
  box-shadow: inset 0 0 0 var(--rule) var(--panel-edge);
  color: var(--text-soft);
  font-size: var(--text-xs);
  font-weight: var(--weight-label);
  line-height: var(--leading-snug);
}

.scores--many .score__away {
  grid-area: 2 / 1 / 3 / 3;
  justify-self: start;
  line-height: var(--leading-flat);
}

.scores--many .score.is-away .score__name {
  visibility: hidden;
}

/* The name and, when that player is typing, "typing" with three dots in their colour. Both sit in
   one cell, so the label always has the room it needs and nothing around it moves when it shows. */
.score__label {
  display: grid;
  align-items: center;
  min-width: 0;
}

.score__label > * {
  grid-area: 1 / 1;
  min-width: 0;
}

.score__typing {
  display: flex;
  align-items: baseline;
  gap: 2px;
  visibility: hidden;
  color: var(--player);
  font-size: var(--text-xs);
  font-weight: var(--weight-display);
  line-height: var(--leading-flat);
  white-space: nowrap;
}

.score.is-typing .score__typing {
  visibility: visible;
}

.score.is-typing .score__name {
  visibility: hidden;
}

.score__dots {
  display: inline-flex;
  gap: 2px;
}

.score__dots i {
  width: 3px;
  height: 3px;
  border-radius: var(--radius-round);
  background: currentColor;
  animation: typing-dot var(--motion-loop) linear infinite;
}

.score__dots i:nth-child(2) { animation-delay: calc(var(--motion-loop) / 3); }
.score__dots i:nth-child(3) { animation-delay: calc(var(--motion-loop) * 2 / 3); }

@keyframes typing-dot {
  0%, 60%, 100% { opacity: 0.35; }
  30% { opacity: 1; }
}

/* Reduced motion: the label alone, still. */
:root[data-motion="reduced"] .score__dots i {
  animation: none;
}

/* Two players: a rope between the scores. The join slides toward whoever is behind; the
   notch marks the middle. */
.tug {
  --tug: 0.5;
  position: relative;
  display: flex;
  flex: 1 1 44px;
  gap: 2px;
  min-width: 44px;
  height: 10px;
  border-radius: var(--radius-pill);
  overflow: hidden;
}

.tug__side {
  flex: var(--tug) 0 0;
  background: var(--player);
  transition: flex-grow var(--motion-settle) var(--ease-out);
}

.tug__side:last-child {
  flex-grow: calc(1 - var(--tug));
}

.tug::after {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  left: calc(50% - 1px);
  width: 2px;
  background: var(--stage-deep);
}

/* Three or four players: a column each, the score over the name. */
.scores--many {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(0, 1fr);
  gap: var(--space-2);
}

.scores--many .score,
.scores--many .score--you {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  grid-template-rows: auto auto;
  align-content: center;
  align-items: center;
  justify-items: start;
  gap: 1px 5px;
}

.scores--many .score__who {
  display: contents;
}

.scores--many .player-badge {
  grid-area: 1 / 1;
  width: 16px;
  height: 16px;
}

.scores--many .score .player-badge .player-mark {
  width: 8px;
  height: 8px;
}

.scores--many .score__figure {
  grid-area: 1 / 2;
}

.scores--many .score__num {
  min-width: 0;
  padding-top: 0;
  font-size: var(--text-l);
}

/* No room above the figure here: the crown goes beside it. */
.scores--many .score__crown {
  position: static;
  width: 12px;
  height: 9px;
  margin: 0;
}

.scores--many .score__label {
  grid-area: 2 / 1 / 3 / 3;
  max-width: 100%;
}

.scores--many .score__name {
  max-width: 100%;
  color: var(--text-soft);
  font-size: var(--text-xs);
  line-height: var(--leading-flat);
}

.scores--many .score__face {
  display: none;
}

/* --- The table ---------------------------------------------------------------------------
   Everything in it is placed by table.js with `translate`, from the layout module's numbers.
   Nothing is clipped: the owner's mark sits in the padding to the left of its lane. */

.game-table {
  position: relative;
  flex: 1 1 0;
  min-height: 0;
  margin: var(--g-pad);
}

.gt,
.word,
.pool-tray,
.lane-mark,
.lane-tag,
.lane-hint,
.bag,
.countdown {
  position: absolute;
  top: 0;
  left: 0;
  margin: 0;
}

/* Pieces glide to a new place. The flights and flips are fx.js. */
.gt,
.word,
.pool-tray,
.lane-mark,
.lane-tag,
.lane-hint,
.bag {
  transition: translate var(--motion-settle) var(--ease-out);
}

.game-table.is-still > * {
  transition: none;
}

/* Reduced motion drops the travel: pieces are simply in their new place. */
:root[data-motion="reduced"] .game-table > * {
  transition: none;
}

.gt {
  z-index: 2;
}

.gt.is-new {
  animation: fade-in var(--motion-quick) linear both;
}

.gt.is-pool {
  cursor: pointer;
}

/* In the air: fx.js is moving it, above everything on the table. */
.gt.is-flying {
  z-index: 6;
  transition: none;
}

/* A tile in a word wears its owner's colour: a tinted face over a lip of the stronger tone. */
.gt[data-player],
.typed__tile[data-from="word"] {
  background: var(--player-face);
  box-shadow: 0 var(--tile-depth) 0 var(--player-strong);
}

.word {
  z-index: 1;
  pointer-events: none;
}

/* The word the typed word would take, caught in the torch beam. */
.word::before {
  content: "";
  position: absolute;
  inset: calc(var(--g-tile) * -0.13);
  border-radius: calc(var(--g-tile) * (var(--tile-radius) + 0.13));
  background: var(--torch);
  opacity: 0;
  transition: opacity var(--motion-quick) linear;
}

.word.is-target::before {
  opacity: 1;
}

/* A word that has just been made wears a ring of torchlight from the moment it lands (--land,
   set by fx.js) for as long as the event line talks about it. */
.word::after {
  content: "";
  position: absolute;
  inset: calc(var(--g-tile) * -0.13);
  border: var(--rule) solid var(--torch);
  border-radius: calc(var(--g-tile) * (var(--tile-radius) + 0.13));
  opacity: 0;
}

.word.is-new::after {
  animation: word-new var(--hold-line) linear var(--land, 0ms) both;
}

@keyframes word-new {
  0% { opacity: 0; }
  4%, 70% { opacity: 1; }
  100% { opacity: 0; }
}

/* A word the player stole lands in the full beam, for a moment. */
.word.is-won::before {
  animation: word-won var(--motion-flash) var(--ease-out) var(--land, 0ms);
}

@keyframes word-won {
  0%, 25% { opacity: 1; }
  100% { opacity: 0; }
}

/* A word that was taken fades out where it lay: its letters, with nothing under them. One
   taken from the player is marked in the warning colour. */
.ghost {
  position: absolute;
  top: 0;
  left: 0;
  z-index: 1;
  pointer-events: none;
  animation: ghost-fade var(--hold-ghost) linear both;
}

.ghost__tile {
  position: absolute;
  top: 0;
  left: 0;
  display: grid;
  place-items: center;
  width: var(--tile-size);
  height: var(--tile-size);
  border-radius: calc(var(--tile-size) * var(--tile-radius));
  background: var(--tile-slot);
  color: var(--text-faint);
  font-size: calc(var(--tile-size) * var(--tile-letter));
  font-weight: var(--weight-display);
  line-height: var(--leading-flat);
  text-transform: uppercase;
}

.ghost[data-tone="loss"] .ghost__tile {
  box-shadow: inset 0 0 0 var(--rule) var(--coral);
  color: var(--coral);
}

@keyframes ghost-fade {
  0% { opacity: 0; }
  10%, 40% { opacity: 1; }
  100% { opacity: 0; }
}

/* The pool's tray: where loose tiles lie and the next ones will land. */
.pool-tray {
  z-index: 0;
  pointer-events: none;
}

.pool-tray::before {
  content: "";
  position: absolute;
  inset: calc(var(--g-tile) * -0.07) calc(var(--g-pad) * -0.5) calc(var(--g-tile) * -0.07 + 1px);
  border-radius: calc(var(--g-tile) * var(--tile-radius) + var(--g-pad) * 0.5);
  background: var(--tile-slot);
}

/* A lane's owner: their mark, in the side padding beside the lane. */
.lane-mark {
  z-index: 0;
  width: 8px;
  height: 8px;
  pointer-events: none;
}

.lane-tag {
  display: flex;
  align-items: flex-start;
  overflow: hidden;
  color: var(--player);
  font-size: var(--text-xs);
  font-weight: var(--weight-label);
  line-height: var(--leading-flat);
  white-space: nowrap;
  pointer-events: none;
}

.lane-hint {
  display: flex;
  align-items: center;
  padding-left: 2px;
  color: var(--text-faint);
  font-size: var(--text-xs);
  line-height: var(--leading-flat);
  white-space: nowrap;
  pointer-events: none;
}

.lane-mark.is-gone,
.lane-tag.is-gone {
  opacity: 0.5;
}

/* An emptied lane's hint waits until the ghost of the word that was taken has gone. */
.game-table.has-ghost .lane-hint {
  visibility: hidden;
}

/* --- The bag: a count, a level that drains, and a ring that runs down to the next flip ----- */

.bag {
  z-index: 1;
  display: grid;
  place-items: center;
  width: var(--g-tile);
  height: var(--g-tile);
}

.bag__well {
  position: absolute;
  inset: 0;
  border-radius: var(--radius-round);
  background: var(--well);
  overflow: hidden;
}

.bag__level {
  position: absolute;
  right: 0;
  bottom: 0;
  left: 0;
  height: calc(var(--bag-left, 1) * 100%);
  background: var(--panel-up);
  transition: height var(--motion-settle) var(--ease-out);
}

.bag__ring {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  transform: rotate(-90deg);
}

.bag__track,
.bag__sweep {
  fill: none;
  stroke-width: 3.5;
}

.bag__track {
  stroke: var(--panel-edge);
}

.bag__sweep {
  stroke: var(--torch);
  stroke-dasharray: 100;
  stroke-linecap: round;
}

@keyframes bag-sweep {
  from { stroke-dashoffset: 0; }
  to { stroke-dashoffset: 100; }
}

.bag__count {
  position: relative;
  color: var(--text);
  font-size: calc(var(--g-tile) * 0.46);
  font-weight: var(--weight-display);
  font-variant-numeric: tabular-nums;
  line-height: var(--leading-flat);
}

/* Last call: the bag is empty and the ring counts the seconds, in the warning colour. */
.bag.is-lastcall .bag__sweep {
  stroke: var(--coral);
}

.bag.is-lastcall .bag__count {
  color: var(--coral);
  font-size: calc(var(--g-tile) * 0.56);
}

.bag.is-over .bag__sweep {
  stroke: none;
}

/* Each second of last call lands with a beat. */
.bag.is-lastcall.is-beat .bag__count {
  animation: bag-beat var(--motion-settle) var(--ease-out);
}

@keyframes bag-beat {
  from { transform: scale(calc(1 + 0.45 * var(--travel))); }
}

/* A paused game: the ring and the lock on GO stop where they are. So does the ring while the
   lesson's clock waits for the learner. */
.game.is-paused .bag__sweep,
.game.is-waiting .bag__sweep,
.game.is-paused .key__lock-fill {
  animation-play-state: paused !important;
}

/* --- Last call: the table tightens ---------------------------------------------------------
   The light closes in round the table (the whole stage darkens behind the pieces, from the
   edges), the tray takes the warning colour, and the bag counts the seconds (above), with a
   tick on each (fx.js). */

.game::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  background: radial-gradient(ellipse 80% 46% at 50% 40%, transparent 40%, var(--well));
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--motion-entrance) linear;
}

.game[data-phase="lastcall"]::before {
  opacity: 0.9;
}

.pool-tray::after {
  content: "";
  position: absolute;
  inset: calc(var(--g-tile) * -0.07) calc(var(--g-pad) * -0.5) calc(var(--g-tile) * -0.07 + 1px);
  border: var(--rule) solid var(--coral);
  border-radius: calc(var(--g-tile) * var(--tile-radius) + var(--g-pad) * 0.5);
  opacity: 0;
  transition: opacity var(--motion-settle) linear;
}

.game[data-phase="lastcall"] .pool-tray::after {
  opacity: 1;
}

.game[data-phase="lastcall"] .game-line[data-kind="idle"] .game-line__note {
  color: var(--coral);
}

/* --- Before the deal: the count runs in the tray the tiles are about to land in ------------ */

.countdown {
  z-index: 3;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-3);
  pointer-events: none;
}

/* The number is a plain numeral beside the label, never a tile: a tile looks playable. */
.countdown__num {
  min-width: 1ch;
  color: var(--text);
  font-size: var(--text-2xl);
  font-weight: var(--weight-display);
  line-height: var(--leading-flat);
  font-variant-numeric: tabular-nums;
}

.countdown__label {
  color: var(--text-soft);
  font-size: var(--text-m);
  font-weight: var(--weight-label);
  line-height: var(--leading-flat);
}

/* --- The line above the typed word: why GO will not go, or what the host said -------------- */

.game-line {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  height: var(--g-line);
  padding: 0 var(--g-pad);
  color: var(--text-soft);
  font-size: var(--text-s);
  font-weight: var(--weight-label);
  line-height: var(--leading-flat);
  white-space: nowrap;
}

.game-line__note {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Why GO will not go: plain light text, one step larger than the idle line, so it reads at arm's length. */
.game-line[data-kind="reason"] .game-line__note {
  color: var(--text);
  font-size: var(--text-m);
  font-weight: var(--weight-display);
}

.game-line[data-kind="refused"] .game-line__note {
  color: var(--coral);
}

.game-line__ask {
  appearance: none;
  position: relative;
  flex: none;
  margin: 0;
  padding: 0;
  border: 0;
  background: none;
  color: var(--text);
  font-weight: var(--weight-label);
  text-decoration: underline;
  text-decoration-thickness: var(--rule);
  text-underline-offset: 3px;
  text-decoration-color: var(--panel-edge);
  cursor: pointer;
}

.game-line__ask::before {
  content: "";
  position: absolute;
  inset: -11px -8px;
}

.game-line__noted {
  flex: none;
  color: var(--mint);
}

/* What just happened (fx.js): who, what, and what it did to the player's score. It gives way
   to a note about the word being typed, and shows over the idle text. */
.game-line__event {
  display: none;
  align-items: baseline;
  gap: 0.32em;
  min-width: 0;
  color: var(--text);
}

.game-line.has-event[data-kind="idle"] .game-line__event {
  display: flex;
}

.game-line.has-event[data-kind="idle"] .game-line__note {
  display: none;
}

.game-line__event > * {
  flex: none;
}

.game-line__event.is-in {
  animation: line-in var(--motion-quick) var(--ease-out);
}

.game-line__event.is-leaving {
  opacity: 0;
  transition: opacity var(--motion-quick) linear;
}

@keyframes line-in {
  from { opacity: 0; transform: translateY(calc(var(--travel) * 7px)); }
}

/* The name gives way first when the line is too long, then the word that was taken. */
.game-line__event > .ev__who {
  flex: 0 1 auto;
  min-width: 2ch;
  overflow: hidden;
  color: var(--player, var(--text));
  text-overflow: ellipsis;
}

.ev__verb,
.ev__tag,
.ev__arrow {
  color: var(--text-soft);
}

.ev__word {
  font-weight: var(--weight-display);
  letter-spacing: 0.03em;
}

.game-line__event > .ev__word--from {
  flex: 0 2 auto;
  min-width: 3ch;
  overflow: hidden;
  color: var(--text-soft);
  text-overflow: ellipsis;
}

.ev__delta {
  margin-left: 0.3em;
  font-weight: var(--weight-display);
  font-variant-numeric: tabular-nums;
}

.game-line__event[data-tone="gain"] .ev__delta {
  color: var(--mint);
}

.game-line__event[data-tone="loss"] .ev__delta {
  color: var(--coral);
}

.game-line__event > .ev__note {
  flex: 0 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* A press of GO that cannot go through points here. */
.game-line.is-pointed .game-line__note {
  animation: line-point var(--motion-settle) var(--ease-out);
}

@keyframes line-point {
  40% { transform: scale(calc(1 + 0.14 * var(--travel))); color: var(--text); }
}

/* --- The typed word, as tiles: the preview of the claim ------------------------------------ */

/* A box sunk into the stage, ringed in the player's colour, so it reads as the place the
   keys type into. The ring brightens once a letter is in it. */
.typed {
  position: relative;
  display: grid;
  place-items: center;
  height: var(--g-typed);
  padding: 0 var(--g-pad);
}

.typed::before {
  content: "";
  position: absolute;
  inset: 1px calc(var(--g-pad) * 0.5);
  border-radius: 12px;
  background: var(--well);
  box-shadow: inset 0 0 0 2px color-mix(in srgb, var(--player, var(--text-faint)) 70%, transparent);
  transition: box-shadow var(--motion-quick) linear;
  pointer-events: none;
}

.typed.is-empty::before {
  box-shadow: inset 0 0 0 2px color-mix(in srgb, var(--player, var(--text-faint)) 35%, transparent);
}

.typed__line {
  position: relative;
  display: flex;
  align-items: center;
  gap: 4px;
  max-width: 100%;
}

.typed__hint {
  color: var(--text-faint);
  font-size: var(--text-s);
  line-height: var(--leading-flat);
}

/* The cursor: where the next letter goes. It blinks only while motion is welcome. */
.typed__caret {
  flex: none;
  width: 2px;
  height: calc(var(--typed-tile, 33px) * 0.8);
  border-radius: 1px;
  background: var(--player, var(--text));
  animation: typed-caret 1.06s steps(1, end) infinite;
}

.typed.is-pending .typed__caret {
  visibility: hidden;
}

:root[data-motion="reduced"] .typed__caret {
  animation: none;
}

@keyframes typed-caret {
  50% { opacity: 0; }
}

.typed__tiles {
  display: flex;
  gap: 2px;
  transition: opacity var(--motion-quick) linear;
}

.typed__tile {
  --tile-size: var(--typed-tile, 33px);
  position: relative;
}

/* From a word on the table: the owner's colour, and the owner's mark in the corner. */
.typed__tile .player-mark {
  position: absolute;
  top: 8%;
  right: 8%;
  width: 20%;
  height: 20%;
  background: var(--player-strong);
}

/* A letter that is not there to take: a hollow where the tile would be. */
.typed__tile[data-from="none"] {
  border: var(--rule) dashed var(--text-faint);
  background: var(--tile-slot);
  box-shadow: none;
  color: var(--text-soft);
}

/* Sent, and not answered yet. */
.typed.is-pending .typed__tiles {
  opacity: 0.55;
}

.typed.is-shaking .typed__tiles {
  animation: typed-shake calc(var(--motion-settle) * 1.6) var(--ease-in-out);
}

@keyframes typed-shake {
  15% { transform: translateX(calc(var(--travel) * -7px)); }
  35% { transform: translateX(calc(var(--travel) * 7px)); }
  55% { transform: translateX(calc(var(--travel) * -5px)); }
  75% { transform: translateX(calc(var(--travel) * 4px)); }
}

/* --- The keyboard -------------------------------------------------------------------------
   Three rows that never move. Keys are plum pieces with a lip, quieter than the tiles; they
   answer on touch-down (input.js), so nothing here waits for :active. A letter that is nowhere
   on the table lies flat and cannot be pressed; one whose every copy is typed dims. */

.keys {
  position: relative;
  display: flex;
  flex-direction: column;
  height: var(--g-keys);
  padding: 4px 3px;
  touch-action: none;
}

.keys__row {
  display: flex;
  flex: 1 1 0;
  min-height: 0;
}

.keys__row--2 {
  padding: 0 5%;
}

.key {
  appearance: none;
  display: block;
  flex: 1 1 0;
  min-width: 0;
  margin: 0;
  padding: 2px 2.5px calc(3px + var(--lip-s));
  border: 0;
  background: none;
  color: var(--text);
  cursor: pointer;
}

.key__cap {
  display: grid;
  place-items: center;
  width: 100%;
  height: 100%;
  border-radius: var(--radius-s);
  background: var(--panel-up);
  box-shadow: 0 var(--lip-s) 0 var(--panel-lip);
  font-size: var(--text-l);
  font-weight: var(--weight-label);
  line-height: var(--leading-flat);
  text-transform: uppercase;
  transition: transform var(--motion-press) linear, box-shadow var(--motion-press) linear;
}

.key.is-down .key__cap {
  transform: translateY(calc(var(--lip-s) - var(--lip-down)));
  box-shadow: 0 var(--lip-down) 0 var(--panel-lip);
}

.key.is-used .key__cap {
  background: var(--panel);
  color: var(--text-faint);
}

.key.is-absent {
  cursor: default;
}

.key.is-absent .key__cap {
  transform: translateY(var(--lip-s));
  background: none;
  box-shadow: inset 0 0 0 var(--rule) var(--panel);
  color: var(--panel-edge);
}

.key--go,
.key--back {
  flex-grow: 1.5;
}

/* GO. Flat until there is something to send; gold when there is; it stays down while the
   host is deciding; locked, it shows the time left as a bar that drains. */
.key--go .key__cap {
  position: relative;
  align-content: center;
  gap: 1px;
  overflow: hidden;
  transform: translateY(var(--lip-s));
  background: none;
  box-shadow: inset 0 0 0 var(--rule) var(--panel);
  color: var(--text-faint);
  font-weight: var(--weight-display);
  text-transform: none;
}

.key--go.is-ready .key__cap,
.key--go.is-pending .key__cap {
  background: var(--sun);
  color: var(--sun-ink);
}

.key--go.is-ready .key__cap {
  transform: none;
  box-shadow: 0 var(--lip-s) 0 var(--sun-lip);
}

.key--go.is-ready.is-down .key__cap,
.key--go.is-pending .key__cap {
  transform: translateY(calc(var(--lip-s) - var(--lip-down)));
  box-shadow: 0 var(--lip-down) 0 var(--sun-lip);
}

.key--go.is-locked .key__cap {
  background: var(--well);
  box-shadow: none;
  color: var(--text-faint);
}

/* STEAL and GROW are longer words than GO. */
.key--go[data-says="long"] .key__label {
  font-size: var(--text-s);
}

.key__sub {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 3px;
  max-width: 100%;
  padding: 0 3px;
  font-size: var(--text-xs);
  font-weight: var(--weight-label);
}

.key__sub .player-mark {
  width: 8px;
  height: 8px;
  background: var(--player-strong);
}

.key__name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.key__lock {
  display: none;
  position: absolute;
  right: 6px;
  bottom: 5px;
  left: 6px;
  height: 4px;
  border-radius: var(--radius-pill);
  background: var(--stage);
  overflow: hidden;
}

.key--go.is-locked .key__lock {
  display: block;
}

.key__lock-fill {
  display: block;
  height: 100%;
  border-radius: var(--radius-pill);
  background: var(--coral);
  transform-origin: left;
}

@keyframes key-lock-drain {
  from { transform: scaleX(1); }
  to { transform: scaleX(0); }
}

/* A pressed letter pops up above the finger as the tile it is about to become. */
.key-pop {
  --tile-size: 46px;
  position: absolute;
  z-index: 5;
  margin: 0;
  transform: translate(-50%, calc(-100% - var(--tile-depth) - 6px));
  box-shadow: 0 var(--tile-depth) 0 var(--tile-lip), var(--shadow-soft);
  pointer-events: none;
}

.keys__desk {
  display: none;
  color: var(--text-soft);
  font-size: var(--text-s);
}

/* --- Paused: the table is out of sight until the player is back at it ----------------------- */

.sheet--pause .sheet__scrim {
  -webkit-backdrop-filter: blur(9px);
  backdrop-filter: blur(9px);
}

.sheet--pause .sheet__panel {
  text-align: center;
}

.sheet__note {
  color: var(--text-soft);
}

/* --- The lesson (views/tutorial.js) ---------------------------------------------------------
   The coach is the opponent talking: a bubble in their colour with their face on it, just
   above their lane, in the height the table is not using (the script puts it there and the
   game view keeps the tiles clear of it). It is sized for the longest line it will ever say
   (the hidden probe), so it never jumps as the lines change. Skip is a small pressable pill
   where the way out is in a game. What the coach is talking about is caught in the torch. */

.game-skip {
  appearance: none;
  position: relative;
  flex: none;
  height: 26px;
  margin: 0 0 var(--lip-xs);
  padding: 0 var(--space-3);
  border: 0;
  border-radius: var(--radius-pill);
  background: var(--panel);
  box-shadow: 0 var(--lip-xs) 0 var(--panel-lip);
  color: var(--text-soft);
  font-size: var(--text-xs);
  font-weight: var(--weight-label);
  line-height: var(--leading-flat);
  cursor: pointer;
  transition: transform var(--motion-press) linear, box-shadow var(--motion-press) linear;
}

/* The lesson teaches the rule about related words: no arguing with it in mid-lesson. */
.game.is-lesson .game-line__ask {
  display: none;
}

.game-skip::before {
  content: "";
  position: absolute;
  inset: -9px -6px;
}

.game-skip:active {
  transform: translateY(calc(var(--lip-xs) - var(--lip-down)));
  box-shadow: 0 var(--lip-down) 0 var(--panel-lip);
}

.coach {
  position: absolute;
  top: 0;
  right: 0;
  left: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3) var(--space-2) var(--space-2);
  border-radius: var(--radius-m);
  background: var(--player-face);
  box-shadow: var(--shadow-soft);
  color: var(--ink);
  pointer-events: none;
  transition: opacity var(--motion-quick) linear;
}

/* In its place before the game's first snapshot, with nothing to say yet. */
.coach.is-unsaid {
  opacity: 0;
}

.coach__face {
  width: 36px;
  height: 36px;
}

.coach__say {
  display: grid;
  align-items: center;
  flex: 1 1 0;
  min-width: 0;
  font-size: var(--text-m);
  font-weight: var(--weight-body);
  line-height: var(--leading-snug);
}

/* Lines run the bubble's width (balanced lines left its right third empty); pretty wrapping
   still keeps a lone word off the last line. */
.coach__say > * {
  grid-area: 1 / 1;
  text-wrap: pretty;
}

.coach__probe {
  visibility: hidden;
}

.coach.is-fresh .coach__line {
  animation: coach-in var(--motion-settle) var(--ease-out);
}

@keyframes coach-in {
  from { opacity: 0; transform: translateY(calc(var(--travel) * 6px)); }
}

/* A word or a tile from the game, in a sentence. */
.coach__word {
  font-weight: var(--weight-display);
  letter-spacing: 0.03em;
}

/* The hint: the word, spelled out in tiles. */
.coach__spell {
  display: inline-flex;
  gap: 2px;
  margin-left: var(--space-1);
  vertical-align: middle;
}

.coach__spell .tile {
  --tile-size: 24px;
}

/* What the coach is pointing at: the player's score, or the bag. */
.game[data-coach-point="score"] .score--you .score__figure::before,
.game[data-coach-point="bag"] .bag::after {
  content: "";
  position: absolute;
  inset: -2px -3px;   /* close round the figure: clear of the name and the rope beside it */
  border-radius: var(--radius-pill);
  box-shadow: 0 0 0 var(--rule) var(--torch);
  pointer-events: none;
  animation: coach-point var(--motion-flash) var(--ease-out) 3;
}

.game[data-coach-point="bag"] .bag::after {
  inset: -5px;
}

@keyframes coach-point {
  from { opacity: 0.2; transform: scale(calc(1 + 0.5 * var(--travel))); }
}

/* The end of the lesson: the teacher, one line, and the way on. The bar on the button runs
   down to the moment the game starts by itself. */
.sheet--handoff .sheet__panel {
  justify-items: center;
  text-align: center;
}

.sheet--handoff .wait__actions {
  justify-self: stretch;
}

.handoff__go {
  position: relative;
}

.handoff__timer {
  position: absolute;
  right: var(--space-4);
  bottom: 6px;
  left: var(--space-4);
  height: 4px;
  border-radius: var(--radius-pill);
  background: var(--sun-lip);
  overflow: hidden;
}

.handoff__left {
  display: block;
  height: 100%;
  border-radius: var(--radius-pill);
  background: var(--sun-ink);
  transform-origin: left;
  animation: key-lock-drain var(--hold-handoff) linear forwards;
}

/* --- A hardware keyboard: only GO stays on screen ------------------------------------------ */

.keys.is-desk {
  flex-direction: row;
  align-items: center;
  justify-content: center;
  gap: var(--space-4);
  padding: 0 var(--g-pad);
}

.keys.is-desk .keys__row--1,
.keys.is-desk .keys__row--2,
.keys.is-desk .key:not(.key--go) {
  display: none;
}

.keys.is-desk .keys__row--3 {
  flex: none;
  height: 56px;
}

.keys.is-desk .key--go {
  flex: none;
  width: 176px;
}

.keys.is-desk .key--go .key__label {
  font-size: var(--text-l);
}

.keys.is-desk .keys__desk {
  display: block;
}

/* --- Roomier screens: the same layout, centred, with a wider table -------------------------- */

@media (pointer: fine) and (min-width: 700px) {
  .game {
    --column: var(--column-game);
    padding-top: calc(var(--safe-top) + var(--space-4));
    padding-bottom: calc(var(--safe-bottom) + var(--space-4));
  }

  /* The top bar is taller here (layout.js DESK) and its type grows with the column. */
  .game-leave {
    width: 32px;
    height: 32px;
  }

  .score .player-badge {
    width: 26px;
    height: 26px;
  }

  .score .player-badge .player-mark {
    width: 13px;
    height: 13px;
  }

  .score__face {
    width: 32px;
    height: 32px;
  }

  .score__name {
    font-size: var(--text-m);
  }

  .score__typing {
    font-size: var(--text-s);
  }

  .score__num {
    font-size: var(--text-2xl);
  }

  .tug {
    height: 14px;
  }

  .scores--many .player-badge {
    width: 20px;
    height: 20px;
  }

  .scores--many .score .player-badge .player-mark {
    width: 10px;
    height: 10px;
  }

  .scores--many .score__num {
    font-size: var(--text-xl);
  }

  .scores--many .score__name {
    font-size: var(--text-s);
  }
}

@media (hover: hover) {
  .game-leave:hover,
  .game-skip:hover,
  .gt.is-pool:hover,
  .key:not(.is-absent):hover .key__cap {
    filter: brightness(var(--hover-bright));
  }
}
