/* The app shell and the shared pieces every view is built from. Every colour, radius,
   shadow, type size and timing here is a token from tokens.css. */

/* --- Base ---------------------------------------------------------------------------- */

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  height: 100%;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

/* The page itself never scrolls or bounces; a view that needs to scroll does so inside. */
html,
body {
  margin: 0;
  overflow: hidden;
  overscroll-behavior: none;
}

body {
  position: fixed;
  inset: 0;
  background:
    linear-gradient(to bottom, transparent 55%, var(--stage-deep)),
    radial-gradient(ellipse 130% 58% at 50% 0%, var(--stage-glow), var(--stage) 68%);
  background-color: var(--stage);
  color: var(--text);
  font-family: var(--font);
  font-size: var(--text-m);
  font-weight: var(--weight-body);
  line-height: var(--leading-body);
  -webkit-font-smoothing: antialiased;
  /* A game, not a document: no double-tap zoom, text selection, callouts or tap flash. */
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}

[hidden] {
  display: none !important;
}

/* The one place text can be selected (the name being edited) uses the torch, not the
   browser's own blue. */
::selection {
  background: var(--sun);
  color: var(--sun-ink);
}

h1,
h2,
h3,
p,
ul,
dl,
dd {
  margin: 0;
  padding: 0;
}

button,
input {
  font: inherit;
  color: inherit;
  touch-action: manipulation;
}

:focus {
  outline: none;
}

:focus-visible {
  outline: var(--ring) solid var(--focus);
  outline-offset: var(--ring);
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.sprite {
  position: absolute;
  width: 0;
  height: 0;
  overflow: hidden;
}

/* --- Drawing classes for the cast, tiles and icons ------------------------------------ */

.c-fur { fill: var(--fur); }
.c-fur-deep { fill: var(--fur-deep); }
.c-pale { fill: var(--fur-pale); }
.c-ink { fill: var(--ink); }
.c-white { fill: var(--eye); }
.c-blush { fill: var(--blush); }
.c-coral { fill: var(--coral); }
.c-pip { fill: var(--pip); }
.c-pip-deep { fill: var(--pip-deep); }
.c-nib { fill: var(--nib); }
.c-nib-deep { fill: var(--nib-deep); }
.c-vix { fill: var(--vix); }
.c-torch { fill: var(--torch); }
.c-torch-rim { fill: var(--torch-rim); }

.c-line {
  fill: none;
  stroke: var(--ink);
  stroke-width: 2.8;
  stroke-linecap: round;
}

.c-line-thin {
  fill: none;
  stroke: var(--ink);
  stroke-width: 1.3;
  stroke-linecap: round;
}

.c-vix-ear {
  fill: var(--vix-deep);
  stroke: var(--vix-deep);
  stroke-width: 5;
  stroke-linejoin: round;
}

.t-face { fill: var(--tile-face); }
.t-lip { fill: var(--tile-lip); }

/* Where a tile was: a dark hollow with a dashed rim. */
.t-slot {
  fill: var(--tile-slot);
  stroke: var(--panel-edge);
  stroke-width: 2;
  stroke-dasharray: 5 5;
  stroke-linecap: round;
}


.t-letter {
  fill: var(--tile-ink);
  font-family: var(--font);
  font-weight: var(--weight-display);
  font-size: calc(42px * var(--tile-letter));   /* the drawing's tiles are 42 units */
  text-anchor: middle;
}

.i-stroke {
  fill: none;
  stroke: currentColor;
  stroke-width: 2.4;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.i-fill {
  fill: currentColor;
}

.i-ring {
  fill: none;
  stroke: currentColor;
}

.icon {
  width: 24px;
  height: 24px;
  flex: none;
}

.icon--s {
  width: 16px;
  height: 16px;
}

.icon--l {
  width: 30px;
  height: 30px;
}

/* --- Players: colour and mark together ------------------------------------------------ */

[data-player="1"] { --player: var(--player-1); --player-strong: var(--player-1-strong); --player-face: var(--player-1-face); --player-mark: var(--player-1-mark); }
[data-player="2"] { --player: var(--player-2); --player-strong: var(--player-2-strong); --player-face: var(--player-2-face); --player-mark: var(--player-2-mark); }
[data-player="3"] { --player: var(--player-3); --player-strong: var(--player-3-strong); --player-face: var(--player-3-face); --player-mark: var(--player-3-mark); }
[data-player="4"] { --player: var(--player-4); --player-strong: var(--player-4-strong); --player-face: var(--player-4-face); --player-mark: var(--player-4-mark); }

.player-mark {
  width: 14px;
  height: 14px;
  flex: none;
  background: var(--player);
  -webkit-mask: var(--player-mark) center / contain no-repeat;
  mask: var(--player-mark) center / contain no-repeat;
}

/* A player's badge: a small block of their colour with their mark cut out of it. The same
   badge goes beside their name, on their lane and on their words. */
.player-badge {
  display: grid;
  place-items: center;
  flex: none;
  width: 26px;
  height: 26px;
  border-radius: var(--radius-s);
  background: var(--player);
}

.player-badge .player-mark {
  width: 12px;
  height: 12px;
  background: var(--ink);
}

/* --- Views ---------------------------------------------------------------------------- */

/* Every grid here names its one column minmax(0, 1fr): a wide piece of content (a long
   name, a long word) is then cut short in place instead of widening the screen. */
#app {
  height: 100%;
  height: 100dvh;   /* the visible height, as the browser's bars come and go */
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  place-items: center;
}

.view {
  width: min(100%, var(--column));
  height: 100%;
  max-height: var(--column-tall);
  min-height: 0;
  padding:
    calc(var(--safe-top) + var(--space-2))
    calc(var(--safe-right) + var(--gutter))
    calc(var(--safe-bottom) + var(--space-3))
    calc(var(--safe-left) + var(--gutter));
}

/* Views and the sheet take the focus when they open, so a screen reader starts there;
   they are not controls and show no ring. */
.view:focus-visible,
.sheet__panel:focus-visible {
  outline: none;
}

.view-title {
  font-size: var(--text-xl);
  font-weight: var(--weight-display);
  line-height: var(--leading-tight);
  text-wrap: balance;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  min-height: calc(var(--tap) + var(--lip-s));
}

.topbar__balance {
  width: var(--tap);
}

/* Home's buttons, together at the right edge; the name chip gives way to them. */
.topbar__actions {
  display: flex;
  flex: none;
  gap: var(--space-3);
}

/* --- Tile ------------------------------------------------------------------------------
   Set --tile-size where the tile is used; radius, lip and letter follow from it. */

.tile {
  --tile-size: 32px;
  --tile-depth: calc(var(--tile-size) * var(--tile-lip-depth));
  display: inline-grid;
  place-items: center;
  flex: none;
  width: var(--tile-size);
  height: var(--tile-size);
  margin-bottom: var(--tile-depth);
  border-radius: calc(var(--tile-size) * var(--tile-radius));
  background: var(--tile-face);
  box-shadow: 0 var(--tile-depth) 0 var(--tile-lip);
  color: var(--tile-ink);
  font-size: calc(var(--tile-size) * var(--tile-letter));
  font-weight: var(--weight-display);
  line-height: var(--leading-flat);
  text-transform: uppercase;
}

/* --- Buttons ---------------------------------------------------------------------------
   Pressable things have a lip and sink onto it. A plain .btn is the plum panel button
   (written btn--panel in the markup, to say so); btn--sun is the one primary action. */

.btn {
  --btn-bg: var(--panel);
  --btn-lip: var(--panel-lip);
  --btn-ink: var(--text);
  --btn-sub: var(--text-soft);
  --btn-depth: var(--lip-m);
  appearance: none;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-3);
  min-width: 0;
  min-height: 52px;
  margin: 0 0 var(--btn-depth);
  padding: var(--space-2) var(--space-4);
  border: 0;
  border-radius: var(--radius-m);
  background: var(--btn-bg);
  box-shadow: 0 var(--btn-depth) 0 var(--btn-lip);
  color: var(--btn-ink);
  font-size: var(--text-l);
  font-weight: var(--weight-label);
  line-height: var(--leading-tight);
  text-align: center;
  cursor: pointer;
  transition: transform var(--motion-press) linear, box-shadow var(--motion-press) linear;
}

.btn:active:not(:disabled) {
  transform: translateY(calc(var(--btn-depth) - var(--lip-down)));
  box-shadow: 0 var(--lip-down) 0 var(--btn-lip);
}

.btn--sun {
  --btn-bg: var(--sun);
  --btn-lip: var(--sun-lip);
  --btn-ink: var(--sun-ink);
  --btn-sub: var(--sun-ink);
}

.btn--xl {
  --btn-depth: var(--lip-l);
  flex-direction: column;
  gap: 0;
  min-height: 78px;
  border-radius: var(--radius-l);
}

.btn--xl .btn__label {
  font-size: var(--text-2xl);
  font-weight: var(--weight-display);
  line-height: var(--leading-display);
}

.btn--row {
  justify-content: flex-start;
  padding-inline: var(--space-3);
  text-align: left;
}

.btn__stack {
  display: grid;
  min-width: 0;
}

.btn__sub {
  color: var(--btn-sub);
  font-size: var(--text-s);
  font-weight: var(--weight-body);
  line-height: var(--leading-snug);
}

/* Not available: flat, outlined, nothing to press. */
.btn:disabled {
  --btn-ink: var(--text-faint);
  --btn-sub: var(--text-faint);
  margin-bottom: 0;
  margin-top: var(--btn-depth);
  background: none;
  box-shadow: inset 0 0 0 var(--rule) var(--panel);
  cursor: default;
}

.btn--text {
  --btn-ink: var(--text-soft);
  min-height: var(--tap);
  margin: 0;
  background: none;
  box-shadow: none;
  font-size: var(--text-m);
  text-decoration: underline;
  text-decoration-thickness: var(--rule);
  text-underline-offset: 5px;
  text-decoration-color: var(--panel-edge);
}

.btn--text:active:not(:disabled) {
  transform: none;
  box-shadow: none;
  color: var(--text);
}

.icon-btn {
  appearance: none;
  display: grid;
  place-items: center;
  flex: none;
  width: var(--tap);
  height: var(--tap);
  margin: 0 0 var(--lip-s);
  padding: 0;
  border: 0;
  border-radius: var(--radius-round);
  background: var(--panel);
  box-shadow: 0 var(--lip-s) 0 var(--panel-lip);
  color: var(--text);
  cursor: pointer;
  transition: transform var(--motion-press) linear, box-shadow var(--motion-press) linear;
}

.icon-btn:active {
  transform: translateY(calc(var(--lip-s) - var(--lip-down)));
  box-shadow: 0 var(--lip-down) 0 var(--panel-lip);
}

.icon-btn--sun {
  background: var(--sun);
  box-shadow: 0 var(--lip-s) 0 var(--sun-lip);
  color: var(--sun-ink);
}

.icon-btn--sun:active {
  box-shadow: 0 var(--lip-down) 0 var(--sun-lip);
}

/* --- Portraits: a face on a torch-coloured disc ----------------------------------------- */

.portrait {
  display: grid;
  place-items: center;
  flex: none;
  width: 40px;
  height: 40px;
  border-radius: var(--radius-round);
  background: var(--torch);
  overflow: hidden;
}

.portrait svg {
  width: 84%;
  height: 84%;
  margin-top: 6%;
}

.portrait--l {
  width: 60px;
  height: 60px;
}

.portrait--xl {
  width: 128px;
  height: 128px;
}

/* --- Home ------------------------------------------------------------------------------ */

/* A column: the top bar, the picture and the menu. Height to spare is shared out, not left
   in one band: four parts around the picture (half above it, half between it and the menu)
   to one part under the menu. */
.home {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

/* A one-line note from the way here (a room that ended under the player), over the foot of
   the screen for a moment. A tap puts it away. */
.home-note {
  position: absolute;
  z-index: var(--layer-overlay);
  left: calc(var(--safe-left) + var(--gutter));
  right: calc(var(--safe-right) + var(--gutter));
  bottom: calc(var(--safe-bottom) + var(--space-4));
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-m);
  background: var(--panel-up);
  box-shadow: var(--shadow-soft);
  font-size: var(--text-s);
  font-weight: var(--weight-label);
  line-height: var(--leading-snug);
  text-align: center;
  animation: fade-in var(--motion-settle) linear both;
}

/* The server is newer than this page: a way to reload, until it is used. It stays, so it is not
   laid over the screen: it takes the foot of the screen. */
.home-note--update {
  position: static;
  order: 2;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  column-gap: var(--space-2);
  padding-block: 0;
}

.home-note__reload {
  min-height: var(--tap);
  margin-block: var(--space-2);
  padding: var(--space-1) var(--space-4);
  font-size: var(--text-s);
}

.home > * {
  flex: none;
}

.home::after {
  content: "";
  flex: 1 1 0;
  order: 1;
}

.name {
  display: flex;
  min-width: 0;
}

.name-chip {
  appearance: none;
  display: flex;
  align-items: center;
  gap: var(--space-2);
  min-width: 0;
  height: var(--tap);
  margin: 0 0 var(--lip-s);
  padding: 0 var(--space-4) 0 var(--space-2);
  border: 0;
  border-radius: var(--radius-pill);
  background: var(--panel);
  box-shadow: 0 var(--lip-s) 0 var(--panel-lip);
  color: var(--text);
  font-weight: var(--weight-label);
  cursor: pointer;
  transition: transform var(--motion-press) linear, box-shadow var(--motion-press) linear;
}

.name-chip:active {
  transform: translateY(calc(var(--lip-s) - var(--lip-down)));
  box-shadow: 0 var(--lip-down) 0 var(--panel-lip);
}

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

.name-chip .icon {
  color: var(--text-faint);
}

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

.name-input {
  width: 11.5em;
  min-width: 0;
  height: var(--tap);
  margin: 0 0 var(--lip-s);
  padding: 0 var(--space-4);
  border: 0;
  border-radius: var(--radius-pill);
  background: var(--tile-face);
  box-shadow: 0 var(--lip-s) 0 var(--tile-lip);
  color: var(--tile-ink);
  font-weight: var(--weight-label);
  -webkit-user-select: text;
  user-select: text;
}

/* The wordmark and its line sit together in the middle of the height they are given. The
   torch and the thief are drawn larger than the wordmark's own scale (--hero-scale), so the
   torch spans the whole word; the picture's box is the wordmark's, and room is left above
   it for the rest. When height is short the whole picture shrinks. */
.home .hero {
  --hero-scale: 1.22;
  display: flex;
  flex: 4 1 auto;
  flex-direction: column;
  justify-content: center;
  gap: var(--space-3);
  min-height: 0;
}

.hero__art {
  position: relative;
  flex: 0 1 auto;
  min-height: 0;
  /* The torch's top is 145 of the drawing's 340 units above its base. */
  margin-top: calc((var(--hero-scale) - 1) * 145 / 340 * 100%);
  aspect-ratio: 340 / 200;
}

/* Grows from the middle of the wordmark's top edge. */
.hero-scale {
  transform-origin: 170px 141px;
  transform: scale(var(--hero-scale));
}

.hero-art {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: visible;
}

/* The slogan is the headline at every phone size; the line under it is the quieter one. */
.hero__tag {
  color: var(--text);
  font-size: var(--text-l);
  font-weight: var(--weight-display);
  line-height: var(--leading-tight);
  text-align: center;
}

.hero-tail,
.hero-tail-rings,
.hero-arm,
.hero-zip {
  fill: none;
  stroke-linecap: round;
}

.hero-tail {
  stroke: var(--fur);
  stroke-width: 19;
}

.hero-tail-rings {
  stroke: var(--fur-pale);
  stroke-width: 19;
  stroke-linecap: butt;
  stroke-dasharray: 9 12;
  stroke-dashoffset: -3;
}

.hero-arm {
  stroke: var(--fur-deep);
  stroke-width: 15;
}

.hero-zip {
  stroke: var(--torch-ink);
  stroke-width: 4;
}

/* The one flourish: on arrival the thief pops up from behind the wordmark with its loot. */
.is-arriving .hero-rise {
  animation: hero-rise var(--motion-entrance) var(--ease-pop) calc(var(--motion-stagger) * 2) both;
}

.is-arriving .hero-paw {
  transform-box: fill-box;
  transform-origin: center;
  animation: hero-pop var(--motion-settle) var(--ease-pop) calc(var(--motion-stagger) * 2 + var(--motion-entrance) * 0.6) both;
}

@keyframes hero-rise {
  from { transform: translateY(calc(var(--travel) * 130px)); }
}

@keyframes hero-pop {
  from { transform: scale(calc(1 - var(--travel))); }
}

.menu {
  display: grid;
  gap: var(--space-3);
}

.menu__pair {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: var(--space-3);
}

/* Labels here wrap onto a second line (and the button grows) rather than run into the
   edge, if the words get longer or the reader's type is larger. */
.menu__pair .btn {
  gap: var(--space-2);
  min-height: 62px;
}

.menu__pair .btn__label {
  font-size: var(--text-m);
  overflow-wrap: break-word;
}

.menu__pair .btn__sub {
  font-size: var(--text-xs);
  overflow-wrap: break-word;
}

.menu .btn--text {
  justify-self: center;
  margin-top: calc(var(--space-2) * -1);
}

/* --- Sheet: a panel that rises over the current view ------------------------------------ */

.sheet {
  position: fixed;
  inset: 0;
  z-index: var(--layer-sheet);
  display: grid;
  align-items: end;
  justify-items: center;
}

.sheet__scrim {
  position: absolute;
  inset: 0;
  background: var(--scrim);
  animation: fade-in var(--motion-quick) linear both;
}

.sheet__panel {
  position: relative;
  display: grid;
  gap: var(--space-4);
  width: min(100%, var(--column));
  max-height: 100%;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding:
    var(--space-4)
    calc(var(--safe-right) + var(--gutter))
    calc(var(--safe-bottom) + var(--space-5))
    calc(var(--safe-left) + var(--gutter));
  border-radius: var(--radius-l) var(--radius-l) 0 0;
  background: var(--stage);
  box-shadow: var(--shadow-float);
  animation: sheet-up var(--motion-settle) var(--ease-out) both;
}

.sheet__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
}

@keyframes sheet-up {
  from { transform: translateY(calc(var(--travel) * 100%)); opacity: 0; }
}

@keyframes fade-in {
  from { opacity: 0; }
}

.bot-list {
  display: grid;
  gap: var(--space-3);
  list-style: none;
}

.bot-card {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  justify-content: stretch;
  width: 100%;
  min-height: 80px;
  padding: var(--space-2) var(--space-4) var(--space-2) var(--space-3);
  text-align: left;
}

.bot-card__name {
  font-size: var(--text-l);
  font-weight: var(--weight-display);
}

.bot-card__level {
  display: grid;
  justify-items: end;
  gap: var(--space-1);
  color: var(--text-soft);
  font-size: var(--text-s);
}

.bot-card__yours {
  padding: 1px var(--space-2);
  border-radius: var(--radius-pill);
  background: var(--text);
  color: var(--ink);
  font-size: var(--text-xs);
  font-weight: var(--weight-label);
  white-space: nowrap;
}

/* Your level: a lighter card with a pale ring (gold is kept for the primary action). */
.bot-card[aria-current="true"] {
  --btn-bg: var(--panel-up);
  box-shadow: 0 var(--btn-depth) 0 var(--btn-lip), inset 0 0 0 var(--ring) var(--text);
}

.bot-card[aria-current="true"]:active {
  box-shadow: 0 var(--lip-down) 0 var(--btn-lip), inset 0 0 0 var(--ring) var(--text);
}

/* --- Waiting: finding a player, loading the words ---------------------------------------- */

.wait {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: minmax(0, 1fr) auto;
  gap: var(--space-4);
}

.wait__body {
  display: grid;
  align-content: center;
  justify-items: center;
  gap: var(--space-4);
  text-align: center;
}

.wait__note {
  max-width: 28ch;
  color: var(--text-soft);
  text-wrap: balance;
}

.wait__actions {
  display: grid;
  gap: var(--space-3);
}

.hop {
  display: flex;
  gap: var(--space-1);
}

.hop .tile {
  --tile-size: 40px;
  animation: hop var(--motion-loop) var(--ease-in-out) infinite;
}

.hop .tile:nth-child(2) { animation-delay: var(--motion-stagger); }
.hop .tile:nth-child(3) { animation-delay: calc(var(--motion-stagger) * 2); }
.hop .tile:nth-child(4) { animation-delay: calc(var(--motion-stagger) * 3); }
.hop .tile:nth-child(5) { animation-delay: calc(var(--motion-stagger) * 4); }

@keyframes hop {
  0%, 40%, 100% { transform: none; }
  20% { transform: translateY(calc(var(--travel) * -12px)); }
}

.meter {
  width: min(100%, 240px);
  height: 14px;
  border-radius: var(--radius-pill);
  background: var(--well);
  overflow: hidden;
}

.meter__fill {
  display: block;
  width: 0;
  height: 100%;
  border-radius: var(--radius-pill);
  background: var(--sun);
  transition: width var(--motion-settle) var(--ease-out);
}

/* --- Stats: big figures on one panel -------------------------------------------------------- */

.stats {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: auto minmax(0, 1fr);
  gap: var(--space-3);
}

.stats__body {
  display: grid;
  align-content: start;
  gap: var(--space-4);
  padding-top: var(--space-3);
}

/* Six columns: three figures across the top row, then two across. */
.stats__grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: var(--space-5) var(--space-3);
  padding: var(--space-5) var(--space-4);
  border-radius: var(--radius-m);
  background: var(--panel);
}

.stat {
  grid-column: span 3;
  display: flex;
  flex-direction: column-reverse;
  min-width: 0;
  text-align: center;
}

.stat--third {
  grid-column: span 2;
}

.stat dt {
  color: var(--text-soft);
  font-size: var(--text-xs);
  line-height: var(--leading-snug);
}

.stat dd {
  font-size: var(--text-xl);
  font-weight: var(--weight-display);
  line-height: var(--leading-tight);
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}

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

/* --- Settings ---------------------------------------------------------------------------- */

.settings {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: auto minmax(0, 1fr);
  gap: var(--space-3);
}

/* The page scrolls under the title (the licences are long). No fade at the edges: a faded last
   line looks cut off. */
.settings__body {
  display: grid;
  align-content: start;
  gap: var(--space-6);
  margin-inline: calc(var(--gutter) * -1);
  padding: var(--space-3) var(--gutter) var(--space-6);
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

.rows {
  list-style: none;
  border-radius: var(--radius-m);
  background: var(--panel);
}

.row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  min-height: 64px;
  padding: var(--space-3) var(--space-4);
}

.row + .row {
  border-top: var(--rule) solid var(--stage);
}

.row--stacked {
  flex-direction: column;
  align-items: stretch;
  gap: var(--space-3);
}

/* A row that is a link to another page: the whole row is the target. */
.row--link {
  padding: 0;
}

.row__anchor {
  display: flex;
  flex: 1;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  min-height: var(--tap);
  padding: var(--space-3) var(--space-4);
  color: inherit;
  text-decoration: none;
  border-radius: inherit;
}

.row__anchor:focus-visible {
  outline: var(--ring) solid var(--focus);
  outline-offset: calc(var(--ring) * -1);
}

.row__anchor:active {
  background: var(--panel-up);
}

/* The back arrow, turned to point on. */
.row__chev {
  flex: none;
  width: 20px;
  height: 20px;
  color: var(--text-soft);
  transform: scaleX(-1);
}

.row__text {
  display: grid;
  gap: 2px;
}

.row__label {
  font-size: var(--text-m);
  font-weight: var(--weight-label);
}

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

.switch {
  appearance: none;
  position: relative;
  flex: none;
  width: 60px;
  height: 36px;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: var(--radius-pill);
  background: var(--well);
  cursor: pointer;
  transition: background-color var(--motion-quick) linear;
}

/* The touch target is taller than the track. */
.switch::before {
  content: "";
  position: absolute;
  inset: -6px 0;
}

.switch__knob {
  position: absolute;
  top: 4px;
  left: 4px;
  width: 26px;
  height: 26px;
  border-radius: var(--radius-round);
  background: var(--text-faint);
  box-shadow: 0 var(--lip-xs) 0 var(--stage);
  transition: transform var(--motion-quick) var(--ease-out), background-color var(--motion-quick) linear;
}

.switch[aria-checked="true"] {
  background: var(--mint);
}

.switch[aria-checked="true"] .switch__knob {
  transform: translateX(24px);
  background: var(--tile-face);
  box-shadow: 0 var(--lip-xs) 0 var(--mint-lip);
}

.segmented {
  display: grid;
  grid-template-columns: 1.6fr 1fr 1fr;
  gap: var(--space-1);
  padding: var(--space-1);
  border-radius: var(--radius-m);
  background: var(--well);
}

.segmented__option {
  position: relative;
  display: grid;
  cursor: pointer;
}

.segmented__option input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  opacity: 0;
  cursor: pointer;
}

.segmented__option span {
  display: grid;
  place-items: center;
  min-height: 40px;
  border-radius: var(--radius-s);
  color: var(--text-soft);
  font-size: var(--text-s);
  font-weight: var(--weight-label);
  transition: background-color var(--motion-quick) linear, color var(--motion-quick) linear;
}

.segmented__option input:checked + span {
  background: var(--tile-face);
  color: var(--tile-ink);
}

.segmented__option input:focus-visible + span {
  outline: var(--ring) solid var(--focus);
  outline-offset: var(--lip-xs);
}

.about {
  display: grid;
  gap: var(--space-3);
  color: var(--text-soft);
  font-size: var(--text-s);
  font-weight: var(--weight-prose);
  -webkit-user-select: text;
  user-select: text;
}

.about__title {
  color: var(--text);
  font-size: var(--text-l);
  font-weight: var(--weight-display);
}

.about__file {
  overflow-wrap: anywhere;
  color: var(--text);
}

.about__notices {
  display: grid;
  gap: var(--space-3);
}

.about__notices summary {
  display: flex;
  align-items: center;
  min-height: var(--tap);
  color: var(--text);
  font-weight: var(--weight-label);
  text-decoration: underline;
  text-decoration-thickness: var(--rule);
  text-underline-offset: 5px;
  text-decoration-color: var(--panel-edge);
  cursor: pointer;
}

/* Open, the summary is the section's heading, not a link: no underline. */
.about__notices[open] > summary {
  text-decoration: none;
}

.about__notices h3 {
  margin-top: var(--space-4);
  color: var(--text);
  font-size: var(--text-m);
  font-weight: var(--weight-label);
}

.about__notices p {
  margin-top: var(--space-2);
  overflow-wrap: anywhere;
}

/* --- Phones play upright ----------------------------------------------------------------- */

.rotate {
  display: none;
  position: fixed;
  inset: 0;
  z-index: var(--layer-rotate);
  align-content: center;
  justify-items: center;
  gap: var(--space-3);
  padding: var(--space-5);
  background: var(--stage);
  font-size: var(--text-l);
  font-weight: var(--weight-label);
  text-align: center;
}

.rotate__icon {
  width: 64px;
  height: 64px;
  color: var(--sun);
}

@media (orientation: landscape) and (max-height: 500px) and (pointer: coarse) {
  .rotate {
    display: grid;
  }
}

/* --- Short screens: the browser's bars leave an iPhone SE about 550 px ------------------- */

@media (max-height: 600px) {
  .home,
  .menu {
    gap: var(--space-2);
  }

  .btn--xl {
    min-height: 66px;
  }

  .menu__pair .btn {
    min-height: 56px;
  }

}

/* --- Tall phones: the spare height goes into the picture and the buttons, not into gaps ---- */

@media (min-height: 760px) {
  .home {
    gap: var(--space-5);
  }

  .home .hero {
    --hero-scale: 1.32;
    gap: var(--space-4);
  }

  /* On a tall screen the headline grows and takes one sentence to a row. */
  .hero__tag {
    font-size: var(--text-xl);
  }

  .hero__tag span {
    display: block;
  }

  .menu {
    gap: var(--space-4);
  }

  .btn--xl {
    min-height: 108px;
  }

  .menu__pair .btn {
    min-height: 78px;
  }
}

/* --- Play a friend: start or join, the invite, the lobby, the wait -------------------------- */

/* One panel at a time fills the view. A split panel has its content above and its actions at
   the foot, like the waiting screens. */
.friend__panel {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: auto minmax(0, 1fr);
  gap: var(--space-3);
  height: 100%;
}

.friend__panel--split,
.friend__panel.wait {
  grid-template-rows: minmax(0, 1fr) auto;
  gap: var(--space-4);
}

.friend__body {
  display: grid;
  align-content: center;
  justify-items: stretch;
  gap: var(--space-4);
  min-height: 0;
}

.friend__body > .portrait,
.friend__body--center > * {
  justify-self: center;
}

.friend__body--center {
  text-align: center;
}

.friend__body--center .field {
  justify-self: stretch;
  text-align: left;
}

/* A labelled text field: here, and only on these screens, the phone's own keyboard is fine. */
.field {
  display: grid;
  gap: var(--space-1);
  min-width: 0;
}

.field__label {
  color: var(--text-soft);
  font-size: var(--text-s);
  font-weight: var(--weight-label);
}

.field__input {
  width: 100%;
  min-width: 0;
  height: 52px;
  margin: 0 0 var(--lip-s);
  padding: 0 var(--space-4);
  border: 0;
  border-radius: var(--radius-m);
  background: var(--tile-face);
  box-shadow: 0 var(--lip-s) 0 var(--tile-lip);
  color: var(--tile-ink);
  font-size: var(--text-l);
  font-weight: var(--weight-label);
  -webkit-user-select: text;
  user-select: text;
}

.field__input::placeholder {
  color: var(--tile-lip);
}

.field__input--code {
  font-weight: var(--weight-display);
  letter-spacing: 0.3em;
  text-transform: uppercase;
}

.code-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: end;
  gap: var(--space-3);
}

.code-form .btn {
  min-width: 96px;
}

/* A disabled button sits lower (no lip): line its foot up with the field's. */
.code-form .btn:disabled {
  margin-bottom: var(--lip-s);
  margin-top: 0;
}

.friend__hint {
  margin-top: calc(var(--space-2) * -1);
  color: var(--text-faint);
  font-size: var(--text-s);
  line-height: var(--leading-snug);
}

.friend__or {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  color: var(--text-faint);
  font-size: var(--text-s);
}

.friend__or::before,
.friend__or::after {
  content: "";
  flex: 1 1 0;
  height: var(--rule);
  background: var(--panel);
}

/* A room's code, as tiles. */
.room-code {
  display: flex;
  justify-content: center;
  gap: var(--space-2);
}

.room-code .tile {
  --tile-size: 52px;
}

.room-code--s .tile {
  --tile-size: 40px;
}

/* The rules in three lines, for someone who came by a link and has not had the lesson. */
.rules-card {
  display: grid;
  gap: var(--space-2);
  justify-self: stretch;
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-m);
  background: var(--panel);
  list-style: none;
  text-align: left;
}

.rules-card li {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  font-size: var(--text-s);
  line-height: var(--leading-snug);
}

.rules-card__num {
  --tile-size: 24px;
}

/* The lobby. */
.lobby__code {
  display: grid;
  justify-items: center;
  gap: var(--space-2);
}

.lobby__label {
  color: var(--text-soft);
  font-size: var(--text-s);
  font-weight: var(--weight-label);
}

.lobby__share {
  min-height: var(--tap);
  margin-top: var(--space-1);
  font-size: var(--text-m);
}

.lobby__seats {
  display: grid;
  gap: var(--space-2);
  list-style: none;
}

.lobby-seat {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  min-width: 0;
  min-height: 48px;
  padding: 0 var(--space-3);
  border-radius: var(--radius-m);
  background: var(--panel);
}

.lobby-seat__name {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  font-weight: var(--weight-label);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.lobby-seat__tag {
  flex: none;
  padding: 1px var(--space-2);
  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);
}

.lobby-seat__tag--you {
  background: var(--text);
  box-shadow: none;
  color: var(--ink);
}

.lobby-seat.is-away .player-badge,
.lobby-seat.is-away .lobby-seat__name {
  opacity: 0.5;
}

.lobby-seat--free {
  background: none;
  box-shadow: inset 0 0 0 var(--rule) var(--panel);
  color: var(--text-faint);
}

.lobby-seat__slot {
  flex: none;
  width: 26px;
  height: 26px;
  border: var(--rule) dashed var(--panel-edge);
  border-radius: var(--radius-s);
}

.lobby__note {
  min-height: calc(var(--text-s) * var(--leading-snug));
  color: var(--text-soft);
  font-size: var(--text-s);
  line-height: var(--leading-snug);
  text-align: center;
}

/* The 3-2-1, in the place of Start and as tall as it, so nothing below it moves. */
.lobby__countdown {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-3);
  min-height: calc(78px + var(--lip-l));
  font-size: var(--text-l);
  font-weight: var(--weight-label);
}

.lobby__count {
  --tile-size: 52px;
  animation: hero-pop var(--motion-settle) var(--ease-pop) both;
}

.lobby__countdown .btn {
  margin-left: var(--space-2);
}

/* The game going on, for someone waiting for the next one. */
.live-card {
  display: grid;
  gap: var(--space-2);
  width: min(100%, 320px);
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-l);
  background: var(--panel);
}

.live-card__seats {
  display: grid;
  gap: var(--space-2);
  list-style: none;
}

.live-seat {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  min-width: 0;
}

.live-seat__name {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  font-weight: var(--weight-label);
  text-align: left;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.live-seat__score {
  font-size: var(--text-xl);
  font-weight: var(--weight-display);
  font-variant-numeric: tabular-nums;
  line-height: var(--leading-flat);
}

.live-card__time {
  padding-top: var(--space-2);
  border-top: var(--rule) solid var(--panel-edge);
  color: var(--text-soft);
  font-size: var(--text-s);
}

/* --- Roomier screens: tablets and desktops keep the phone layout, centred ----------------- */

@media (min-width: 600px) and (min-height: 700px) {
  .view {
    padding-top: calc(var(--safe-top) + var(--space-5));
    padding-bottom: calc(var(--safe-bottom) + var(--space-6));
  }
}

/* Home and the results take more width on a desk. */
@media (pointer: fine) and (min-width: 700px) {
  .view[data-view="home"] {
    --column: var(--column-wide);
  }

  .view[data-view="results"] {
    --column: var(--column-results);
  }
}

/* --- With a mouse: a pressable thing brightens under the pointer ------------------------- */

@media (hover: hover) {
  .btn:hover:not(:disabled),
  .icon-btn:hover,
  .name-chip:hover {
    filter: brightness(var(--hover-bright));
  }
}
