/* Dune Rummy. Tiles are bone coloured with the number in its own colour, the
   way the real ones are, because a tile that is itself coloured turns a table
   of forty of them into a mess. */

:root {
  --night: #101d27;
  --night-deep: #0a141c;
  --felt: #16323f;
  --line: rgba(173, 203, 219, 0.16);
  --ink: #e7f0f5;
  --muted: #8ea7b4;
  --sand: #e3b261;
  --sand-soft: rgba(227, 178, 97, 0.18);

  --bone: #f2ead8;
  --bone-edge: #cdc3ab;
  --bone-shade: #d9cfb8;

  --c-sand: #b4791c;
  --c-water: #1f7fa8;
  --c-ember: #b83a2b;
  --c-night: #3b4a86;

  --good: #58b27a;
  --bad: #d4634f;

  /* The tiles grow with the window. Fixed at 44px they were a row of crumbs
     along the bottom of a wide screen, with the table empty above them.
     Taken from the height as well as the width, because the two run out at
     different moments: a wide short screen has room across for tiles it has no
     room down for, and sizing on width alone there leaves the table with one
     row of sets squeezed between the header and the rack. Whichever runs out
     first wins. */
  --tile-base: clamp(46px, min(7vw, 10vh), 124px);
  --tile-w: var(--tile-base);
  --tile-h: calc(var(--tile-w) * 1.36);
  --radius: 13px;
}

* { box-sizing: border-box; }

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

html, body { height: 100%; margin: 0; }

body {
  display: flex;
  flex-direction: column;
  background: radial-gradient(130% 90% at 50% 0%, #15293a 0%, var(--night) 48%, var(--night-deep) 100%);
  color: var(--ink);
  font: 500 16px/1.45 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
  overflow: hidden;
  touch-action: manipulation;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) 0 env(safe-area-inset-left);
}

[hidden] { display: none !important; }

/* Header */

.bar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 9px 14px;
  border-bottom: 1px solid var(--line);
  flex: none;
}

.home {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: 9px;
  border: 1px solid var(--line);
  color: var(--muted);
  text-decoration: none;
  flex: none;
}
.home:hover, .home:focus-visible { color: var(--ink); border-color: var(--sand); }

.bar h1 { font-size: 17px; margin: 0; flex: none; }

.seats { display: flex; gap: 8px; margin-left: auto; min-width: 0; }

.seat {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 13px;
  color: var(--muted);
  /* Four players and a long name each will outrun any header. The chips give
     way before the bar does, and a name runs out with dots rather than
     pushing the player beside it off the screen. */
  min-width: 0;
  flex: 0 1 auto;
}
.seat > span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.seat b { color: var(--ink); font-variant-numeric: tabular-nums; }

/* The running score. Kept plainly apart from the count of tiles beside it,
   which is a different number about the same player and was the one thing
   the chip already said. */
.pts {
  font-style: normal;
  font-size: 12px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  padding: 1px 7px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.07);
  color: var(--muted);
}
.pts.up { color: var(--good); background: rgba(126, 200, 136, 0.14); }
.pts.down { color: #e39090; background: rgba(227, 144, 144, 0.14); }
/* With room to spare the score says what it is, since two numbers in a row on
   the same chip is a riddle. Narrower than this the pill has to speak for
   itself, and the title attribute carries the rest. */
@media (min-width: 900px) { .pts::after { content: " pts"; font-size: 10px; opacity: 0.75; } }
@media (max-width: 520px) {
  .seat { padding: 4px 7px; gap: 4px; font-size: 12px; }
  .pts { padding: 1px 5px; font-size: 11px; }
}
.seat.now { border-color: var(--sand); color: var(--sand); background: var(--sand-soft); }

/* The turn arriving here. Once, as it lands, not for the whole of somebody's
   turn: a chip that pulses while you think is a chip that nags. */
.seat.arriving { animation: landedOn 620ms cubic-bezier(0.2, 0.8, 0.3, 1); }

@keyframes landedOn {
  0% { box-shadow: 0 0 0 0 rgba(227, 178, 97, 0.55); }
  45% { box-shadow: 0 0 0 7px rgba(227, 178, 97, 0); transform: scale(1.06); }
  100% { box-shadow: 0 0 0 0 rgba(227, 178, 97, 0); transform: scale(1); }
}
/* Somebody whose browser is not answering. The seat stays theirs, which is
   why it has to look different rather than disappear. */
.seat.away { opacity: 0.55; border-style: dashed; }

/* The backs of somebody else's hand. Small, fanned tight, and never a drop
   target: it says how much they are holding, nothing more. */
.held {
  display: flex;
  align-items: center;
  margin-left: 2px;
  pointer-events: none;
}
.held i {
  position: relative;
  width: 7px;
  height: 15px;
  border-radius: 2px;
  flex: none;
  background: linear-gradient(165deg, #2b5668, #142c37);
  border: 1px solid rgba(173, 203, 219, 0.3);
  box-shadow: -1px 0 0 rgba(0, 0, 0, 0.35);
}
.held i + i { margin-left: -3px; }

/* Under the card skin they are the deck's own back, like everything else. */
body[data-skin="cards"] .held i {
  background: url("/assets/img/cards/back.webp") center / cover no-repeat;
  border-color: rgba(255, 240, 230, 0.35);
}

@media (max-width: 760px) {
  /* No room across a phone for the fans as well as the names. */
  .held { display: none; }
}
.seat.is-bot { opacity: 0.8; }
.seat.now b { color: var(--sand); }
.seat .opened { font-size: 11px; opacity: 0.75; }

/* Four seats and a word each will not fit across a phone, so the word goes
   and the seat simply stays dim until that player has opened. */
@media (max-width: 700px) {
  .seat .opened { display: none; }
  .bar h1 { display: none; }
}

.pouch { display: flex; flex-direction: column; align-items: flex-end; line-height: 1.1; }
.pouch-label { font-size: 10px; letter-spacing: 0.13em; text-transform: uppercase; color: var(--muted); }
#pouch { font-variant-numeric: tabular-nums; font-weight: 700; }

.says {
  margin: 0;
  padding: 7px 14px;
  font-size: 13px;
  color: var(--muted);
  flex: none;
  min-height: 32px;
}
.says.warn { color: var(--bad); }
.says.good { color: var(--good); }

/* Your turn, said across the middle of the table where you are already
   looking, rather than in small letters along the top where it was easy to
   miss entirely. It never takes a tap, and it takes itself away. */
.turn-call {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  pointer-events: none;
  z-index: 400;
}

.turn-call .band {
  width: 100%;
  padding: clamp(16px, 3.4vw, 26px) 0;
  text-align: center;
  background: linear-gradient(90deg,
    transparent,
    rgba(12, 20, 27, 0.92) 12%,
    rgba(20, 32, 42, 0.95) 50%,
    rgba(12, 20, 27, 0.92) 88%,
    transparent);
  border-top: 1px solid rgba(227, 178, 97, 0.55);
  border-bottom: 1px solid rgba(227, 178, 97, 0.55);
  box-shadow: 0 0 60px rgba(227, 178, 97, 0.22);
  animation: callIn 1800ms cubic-bezier(0.2, 0.8, 0.3, 1) forwards;
}

.turn-call b {
  display: block;
  font-size: clamp(30px, 8.6vw, 48px);
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: #f0c27a;
  font-weight: 800;
  line-height: 1.05;
}

.turn-call i {
  display: block;
  margin-top: 6px;
  font-style: normal;
  font-size: clamp(12px, 3.3vw, 15px);
  color: var(--muted);
  letter-spacing: 0.05em;
}

@keyframes callIn {
  0% { opacity: 0; transform: scale(0.94); }
  12% { opacity: 1; transform: scale(1); }
  70% { opacity: 1; transform: scale(1); }
  100% { opacity: 0; transform: scale(1.02); }
}

/* The table */

/* The frame around the table. The table scrolls when there are a lot of sets
   on it, so neither the pile nor the moving backdrop can live inside it: they
   would scroll away with the sets. */
.felt {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  /* A pool of light over the middle, so it reads as a surface with something
     happening on it rather than a dark rectangle. */
  background:
    radial-gradient(70% 55% at 50% 42%, rgba(79, 195, 223, 0.07), transparent 70%),
    radial-gradient(120% 90% at 50% 0%, rgba(227, 178, 97, 0.05), transparent 60%);
}

.table {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  padding: 16px 18px 20px;
  display: flex;
  flex-wrap: wrap;
  /* Centred both ways. Pinned to the top left, a few sets sat in one corner
     of a wide screen and the rest of the table looked like a mistake. */
  align-content: center;
  justify-content: center;
  align-items: center;
  gap: calc(var(--tile-w) * 0.15);
  position: relative;
  z-index: 1;
  /* Set from script when the table has more on it than it has room for. The
     rack and the pile sit outside this and keep their size. */
  --tile-w: calc(var(--tile-base) * var(--table-scale, 1));
  --tile-h: calc(var(--tile-w) * 1.36);
}

/* The moving table. The engine is shared with Sand & Suits and knows nothing
   about tiles: it is handed the table and paints behind it. */
.backdrop {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 0;
}

/* Each scene tints the table a little, so the surface reads as the same place
   as whatever is drifting across it. */
.felt[data-bg="dune"] { background: radial-gradient(120% 90% at 50% 0%, #2a2118 0%, #130f0a 72%), #0d0a07; }
.felt[data-bg="night"] { background: radial-gradient(120% 90% at 50% 0%, #10243c 0%, #060b16 72%), #05080f; }
.felt[data-bg="aurora"] { background: radial-gradient(120% 95% at 50% 10%, #10263a 0%, #070f1c 70%), #050a12; }
.felt[data-bg="rain"] { background: radial-gradient(120% 90% at 50% 0%, #1b2733 0%, #0a1119 72%), #070c12; }
.felt[data-bg="snow"] { background: radial-gradient(120% 90% at 50% 0%, #243247 0%, #0d1522 72%), #0a111b; }
.felt[data-bg="fireflies"] { background: radial-gradient(120% 90% at 50% 100%, #14240f 0%, #080d06 70%), #060903; }
.felt[data-bg="deep"] { background: radial-gradient(130% 100% at 50% -10%, #0f4a44 0%, #04201d 68%), #03110f; }

/* The pouch, as a pile you take from rather than a button at the bottom of the
   screen. Three backs stacked with a small offset, which is the whole of what
   makes a pile look like a pile. */
.pile {
  position: absolute;
  right: 18px;
  bottom: 16px;
  z-index: 2;
  width: var(--tile-w);
  height: var(--tile-h);
  padding: 0;
  border: 0;
  background: none;
  cursor: pointer;
  font: inherit;
  color: var(--ink);
  transition: transform 140ms cubic-bezier(0.2, 0.75, 0.3, 1);
}

.pile-back {
  position: absolute;
  inset: 0;
  border-radius: calc(var(--tile-w) * 0.16);
  background:
    repeating-linear-gradient(135deg,
      rgba(255, 255, 255, 0.05) 0 4px, transparent 4px 8px),
    linear-gradient(165deg, #2b5668 0%, #1b3a48 60%, #142c37 100%);
  border: 1px solid rgba(173, 203, 219, 0.22);
  box-shadow:
    0 2px 2px rgba(0, 0, 0, 0.4),
    0 7px 14px rgba(0, 0, 0, 0.36),
    inset 0 1px 0 rgba(255, 255, 255, 0.14);
}
/* The two underneath peep out from behind the top one, up and to the left so
   the pile grows away from the edge of the table rather than over it. */
.pile-back:nth-child(1) { transform: translate(-5px, -5px); }
.pile-back:nth-child(2) { transform: translate(-2.5px, -2.5px); }

.pile-face {
  display: grid;
  place-content: center;
  gap: 2px;
  text-align: center;
}

.pile-count {
  font-size: calc(var(--tile-w) * 0.34);
  font-weight: 800;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.pile-word {
  font-size: clamp(9px, calc(var(--tile-w) * 0.15), 13px);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
}

.pile:hover:not(:disabled), .pile:focus-visible { transform: translateY(-5px); }
.pile:focus-visible { outline: 2px solid var(--sand); outline-offset: 4px; }
.pile:not(:disabled) .pile-face { border-color: rgba(227, 178, 97, 0.45); }

/* Off, rather than gone. A pile that vanished when it was not your turn would
   take the count of what is left with it, and that is worth watching. */
.pile:disabled { cursor: default; opacity: 0.45; }

/* Your turn, nothing played yet, so this is the other thing a turn can be.
   Drawn as a halo behind the pile rather than a shadow on it, because the
   pile loses its shadow once it is empty and that is the moment somebody
   most needs telling where to press. */
.pile.ready::before {
  content: "";
  position: absolute;
  inset: -26px;
  border-radius: 50%;
  background: radial-gradient(50% 50% at 50% 50%, rgba(240, 194, 122, 0.75) 0%, rgba(227, 178, 97, 0.34) 45%, transparent 72%);
  animation: breathe 2.2s ease-in-out infinite;
  pointer-events: none;
  z-index: -1;
}

/* And a rim on the pile itself, so the glow still reads on a pale table where
   a halo alone washes out. */
.pile.ready .pile-face { border-color: rgba(255, 226, 168, 0.95); box-shadow: 0 0 0 2px rgba(227, 178, 97, 0.55), 0 2px 2px rgba(0, 0, 0, 0.4), 0 7px 14px rgba(0, 0, 0, 0.36); }

@keyframes breathe {
  0%, 100% { opacity: 0.4; transform: scale(0.94); }
  50% { opacity: 1; transform: scale(1.08); }
}

/* Nothing left to take. The turn still passes, so the pile stays where it is
   and says what pressing it will now do. */
.pile.empty .pile-back { background: rgba(255, 255, 255, 0.03); border-style: dashed; box-shadow: none; }
.pile.empty .pile-back:nth-child(1),
.pile.empty .pile-back:nth-child(2) { display: none; }

/* Play, on the table and opposite the pile.
   In the bottom bar it looked exactly like Undo, Hint, Sort and Menu, so the
   one button that ends a turn was the hardest of the five to find. Here the
   two things a turn can be are the two things on the table, built to the same
   size and set out the same way: a mark over a word, one in each corner. */
.go {
  position: absolute;
  left: 18px;
  bottom: 16px;
  z-index: 2;
  width: var(--tile-w);
  height: var(--tile-h);
  display: grid;
  place-content: center;
  gap: 2px;
  text-align: center;
  padding: 0;
  border: 1px solid rgba(227, 178, 97, 0.5);
  border-radius: calc(var(--tile-w) * 0.16);
  background: rgba(20, 30, 38, 0.72);
  color: var(--muted);
  font: inherit;
  cursor: default;
  transition: transform 140ms cubic-bezier(0.2, 0.75, 0.3, 1), background 160ms ease, color 160ms ease, box-shadow 160ms ease;
}

.go .glyph { font-size: calc(var(--tile-w) * 0.38); line-height: 1; }
.go .label {
  font-size: clamp(9px, calc(var(--tile-w) * 0.15), 13px);
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

/* Nothing to play yet. Dim rather than gone, the same as the pile: a button
   that comes and goes is one you have to look for. */
.go:disabled { opacity: 0.4; border-color: var(--line); }

/* There is a move waiting, and this is the thing to press. */
.go:not(:disabled) {
  background: linear-gradient(170deg, #f0c27a 0%, #e3b261 60%, #cf9c47 100%);
  border-color: rgba(255, 233, 190, 0.6);
  color: #241a0c;
  cursor: pointer;
  box-shadow: 0 2px 2px rgba(0, 0, 0, 0.35), 0 10px 22px rgba(227, 178, 97, 0.28);
}

.go:not(:disabled):hover, .go:not(:disabled):focus-visible { transform: translateY(-5px); }
.go:focus-visible { outline: 2px solid var(--sand); outline-offset: 4px; }

/* The card skin gets a card back rather than a tile back. */
body[data-skin="cards"] .pile-back {
  border-radius: calc(var(--tile-w) * 0.07);
  background: url("/assets/img/cards/back.webp") center / cover no-repeat;
  border-color: rgba(255, 240, 230, 0.35);
}

.set {
  display: flex;
  gap: 2px;
  position: relative;
  z-index: 1;
  /* Wider at the ends than at the top, so that dropping a tile in front of a
     run or behind it is a real target rather than seven pixels of luck. */
  padding: calc(var(--tile-w) * 0.09) calc(var(--tile-w) * 0.2);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid transparent;
  min-height: calc(var(--tile-h) + 14px);
}

/* Where the tile being carried will land. */
.gap {
  position: absolute;
  top: 6px;
  bottom: 6px;
  width: 3px;
  border-radius: 2px;
  background: var(--sand);
  box-shadow: 0 0 6px rgba(227, 178, 97, 0.7);
  pointer-events: none;
}

/* A set only shows as wrong once there is enough of it to judge. Flashing red
   at two tiles, when the third is on its way, would be nagging rather than
   telling. */
.set.bad { border-color: var(--bad); background: rgba(212, 99, 79, 0.1); }
.set.ok { border-color: rgba(88, 178, 122, 0.4); }
.set.hinted { border-color: var(--sand); background: var(--sand-soft); }

/* The moment a set is finished, which is a thing that happens rather than a
   thing that is true, so it is said once and then it stops. */
.set.closing { animation: closed 760ms cubic-bezier(0.2, 0.8, 0.3, 1); }

@keyframes closed {
  0% { box-shadow: inset 0 0 0 1px rgba(227, 178, 97, 0.12); }
  35% {
    box-shadow:
      inset 0 0 0 2px rgba(255, 226, 168, 0.9),
      0 0 26px rgba(227, 178, 97, 0.55);
    transform: translateY(-4px);
  }
  100% { box-shadow: inset 0 0 0 1px rgba(227, 178, 97, 0.12); transform: translateY(0); }
}

/* Finished. A group holding all four colours, or a run that has reached both
   ends, can never be added to by anybody. Marked quietly rather than loudly:
   it is a fact about the table worth knowing at a glance, not an event. */
.set.full {
  border-color: rgba(227, 178, 97, 0.55);
  background: linear-gradient(180deg, rgba(227, 178, 97, 0.1), rgba(227, 178, 97, 0.03));
  box-shadow: inset 0 0 0 1px rgba(227, 178, 97, 0.12);
}

/* And folded up, for the one set that is always thirteen wide. The cards
   overlap like a hand held in one hand, which is the only honest thing to do
   with a run whose every number is already given by its two ends. Nothing is
   hidden from reach: each one still answers to a press on the part of it that
   shows, and lifts clear of its neighbours when you go for it. */
.set.stacked .tile + .tile { margin-left: calc(var(--tile-w) * -0.46); }
.set.stacked .tile { transition: transform 140ms cubic-bezier(0.2, 0.75, 0.3, 1), margin 180ms ease, box-shadow 140ms ease; }
.set.stacked .tile:hover,
.set.stacked .tile:active,
.set.stacked .tile.chosen { z-index: 200; }

/* The first and last say what the run is, so they stay clear of the fold. */
.set.stacked .tile:last-child { margin-left: calc(var(--tile-w) * -0.2); }

/* A set still being built, and the empty places it is waiting for. */
.set.building { border-color: rgba(227, 178, 97, 0.5); background: rgba(227, 178, 97, 0.08); }

.slot {
  width: var(--tile-w);
  height: var(--tile-h);
  flex: none;
  border-radius: calc(var(--tile-w) * 0.16);
  border: 2px dashed rgba(227, 178, 97, 0.45);
  background: rgba(227, 178, 97, 0.05);
}

/* Starting another set is nearly always the wrong thing to do while one is
   half built, so it steps back rather than competing for the eye. */
.new-set.later { opacity: 0.35; }

/* Its own line, right across the table, so the box that starts a set is in
   the same place every turn: under the middle of whatever is already down. */
.new-row {
  flex: 0 0 100%;
  display: flex;
  justify-content: center;
  position: relative;
  z-index: 1;
}

.new-set {
  display: grid;
  place-items: center;
  position: relative;
  z-index: 1;
  min-width: calc(var(--tile-w) + 22px);
  min-height: calc(var(--tile-h) + 14px);
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  color: var(--muted);
  font-size: 12px;
  padding: 0 10px;
  text-align: center;
}
.new-set.over { border-color: var(--sand); color: var(--sand); }

/* Tiles */

.tile {
  width: var(--tile-w);
  height: var(--tile-h);
  border-radius: calc(var(--tile-w) * 0.16);
  background: linear-gradient(170deg, var(--bone) 0%, var(--bone) 62%, var(--bone-shade) 100%);
  border: 1px solid var(--bone-edge);
  /* A tight shadow where the tile meets the table and a wide soft one for the
     space above it, plus a strip of its own thickness along the bottom. A
     tile with one flat shadow looks printed on rather than sitting there. */
  box-shadow:
    0 2px 2px rgba(0, 0, 0, 0.4),
    0 7px 14px rgba(0, 0, 0, 0.36),
    inset 0 1px 0 rgba(255, 255, 255, 0.85),
    inset 0 -3px 0 rgba(90, 76, 48, 0.22);
  display: grid;
  place-items: center;
  position: relative;
  font-weight: 800;
  font-size: calc(var(--tile-w) * 0.62);
  line-height: 1;
  user-select: none;
  -webkit-user-select: none;
  cursor: grab;
  flex: none;
  transition: transform 140ms cubic-bezier(0.2, 0.75, 0.3, 1), box-shadow 140ms ease;
}

/* Reaching for a tile raises it, the same way the cards do. */
.tile:hover, .tile:active {
  transform: translateY(-5px);
  box-shadow:
    0 4px 4px rgba(0, 0, 0, 0.3),
    0 16px 26px rgba(0, 0, 0, 0.45),
    inset 0 1px 0 rgba(255, 255, 255, 0.9),
    inset 0 -3px 0 rgba(90, 76, 48, 0.22);
}

.tile[data-colour="0"] { color: var(--c-sand); }
.tile[data-colour="1"] { color: var(--c-water); }
.tile[data-colour="2"] { color: var(--c-ember); }
.tile[data-colour="3"] { color: var(--c-night); }

/* A little circle at the foot, the way a real tile has one. It is also the
   only thing telling a six from an upside down nine. */
.tile::after {
  content: "";
  position: absolute;
  bottom: 5px;
  width: calc(var(--tile-w) * 0.16);
  height: calc(var(--tile-w) * 0.16);
  border-radius: 50%;
  background: currentColor;
  opacity: 0.4;
}

.tile.joker { color: var(--c-ember); font-size: calc(var(--tile-w) * 0.5); }
.tile.joker::after { display: none; }

/* Skins.

   Every one of them works by moving the variables the rules above already
   read, so there is only ever one description of what a tile is and the
   swatch in the menu cannot drift away from the tile on the table. */

/* Large print. The numbers go up by about a third, the dot shrinks to make
   room, and nothing else changes. */
body[data-skin="bold"] .tile { font-size: calc(var(--tile-w) * 0.82); font-weight: 900; }
body[data-skin="bold"] .tile::after { width: calc(var(--tile-w) * 0.11); height: calc(var(--tile-w) * 0.11); bottom: 4px; }
body[data-skin="bold"] .tile.joker { font-size: calc(var(--tile-w) * 0.62); }

/* Marked. The colour's initial in the corner, so a tile says what it is in
   writing as well as in colour. Not decoration: about one boy in twelve
   cannot rely on the colour alone. */
body[data-skin="plain"] .tile::before {
  content: attr(data-mark);
  position: absolute;
  top: 3px;
  left: 5px;
  font-size: calc(var(--tile-w) * 0.24);
  font-weight: 800;
  line-height: 1;
  opacity: 0.65;
}
body[data-skin="plain"] .tile.joker::before { content: none; }

/* Playing cards. For anyone who would rather be holding a hand of cards than a
   rack of tiles. A one becomes an ace and a thirteen a king, each colour gains
   a suit, and the cards are taller than the tiles because that is the shape a
   card is.

   The four colours keep their colours. A printed deck makes hearts and
   diamonds both red, which would turn four colours into two, and telling all
   four apart is the game.

   The corner index is the thing that actually makes a card read as a card: it
   is what lets you fan a hand and still see what is in it. Upright in one
   corner and upside down in the opposite one, so the card reads the same
   either way up, which is where the convention comes from. */
body[data-skin="cards"] {
  /* The deck's own proportions, so nothing is stretched. */
  --tile-h: calc(var(--tile-w) * 1.384);
  --bone: #fdfbf6;
  --bone-edge: #c9c4b8;
  --bone-shade: #eeeae0;
}

body[data-skin="cards"] .tile {
  /* The deck's own shape: 1063 by 768, which is a real card. */
  border-radius: calc(var(--tile-w) * 0.07);
  background: #ffffff;
  display: block;
  padding: 0;
  overflow: hidden;
}

/* The face is the card itself. Nothing is drawn over it, so the indices, the
   pips and the figures are the ones the deck was printed with. */
body[data-skin="cards"] .card-art {
  width: 100%;
  height: 100%;
  display: block;
  border-radius: inherit;
  user-select: none;
  -webkit-user-select: none;
  pointer-events: none;
}

/* The dot at the foot belongs to a tile. A card has an index in both corners,
   which says which way up it is better than a dot ever did. */
body[data-skin="cards"] .tile::after { display: none; }

.tile.mine { box-shadow: 0 2px 0 rgba(0, 0, 0, 0.28), inset 0 1px 0 rgba(255, 255, 255, 0.7), 0 0 0 2px var(--sand); }
.tile.lifted { opacity: 0.3; }

/* Picked up by tapping and waiting to be told where to go. It has to read as
   off the table rather than merely chosen, since the next tap moves it: hence
   the lift and the tilt as well as the ring. */
.tile.chosen {
  transform: translateY(-10px) rotate(-3deg);
  box-shadow:
    0 6px 6px rgba(0, 0, 0, 0.3),
    0 20px 30px rgba(0, 0, 0, 0.5),
    inset 0 1px 0 rgba(255, 255, 255, 0.9),
    0 0 0 3px var(--sand);
  z-index: 300 !important;
}

/* Somewhere to aim. Tapping is only easier than dragging if the places a tile
   may go are visible before you tap one of them. */
body.placing .set,
body.placing .new-set { outline: 2px dashed rgba(227, 178, 97, 0.5); outline-offset: 3px; }
body.placing .new-set { color: var(--sand); border-color: var(--sand); }
.tile.hint { animation: nudge 900ms ease infinite; }

@keyframes nudge {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-5px); }
}

.floating {
  position: fixed;
  z-index: 100;
  pointer-events: none;
  transform: translate(-50%, -50%) rotate(-3deg) scale(1.08);
  box-shadow: 0 10px 22px rgba(0, 0, 0, 0.45);
  cursor: grabbing;
}

/* The tile on its way from the pile to your hand. Sized and placed from
   script, since where it is going depends on how wide the hand already is. */
.flying {
  position: fixed;
  z-index: 110;
  pointer-events: none;
  box-shadow: 0 12px 26px rgba(0, 0, 0, 0.5);
}

/* Movement. Three things move, and each says something different: a hand
   being dealt, a set arriving on the table, and a tile you just put down. */

@keyframes dealIn {
  from { transform: translateY(34px) scale(0.86); opacity: 0; }
  to { transform: translateY(0) scale(1); opacity: 1; }
}

@keyframes setIn {
  0% { transform: scale(0.84) translateY(10px); opacity: 0; }
  70% { transform: scale(1.04) translateY(0); opacity: 1; }
  100% { transform: scale(1) translateY(0); opacity: 1; }
}

@keyframes landed {
  0% { transform: translateY(-14px); }
  60% { transform: translateY(2px); }
  100% { transform: translateY(0); }
}

@keyframes completed {
  0%, 100% { box-shadow: 0 0 0 0 rgba(88, 178, 122, 0); }
  40% { box-shadow: 0 0 0 4px rgba(88, 178, 122, 0.35); }
}

.rack .tile.dealt { animation: dealIn 420ms cubic-bezier(0.2, 0.8, 0.3, 1) backwards; }
.set.fresh { animation: setIn 320ms cubic-bezier(0.2, 0.8, 0.3, 1); }
.set.ok.fresh { animation: setIn 320ms cubic-bezier(0.2, 0.8, 0.3, 1), completed 620ms ease 320ms; }
.tile.landed { animation: landed 300ms cubic-bezier(0.2, 0.8, 0.3, 1); }

@media (prefers-reduced-motion: reduce) {
  .rack .tile.dealt, .set.fresh, .set.ok.fresh, .tile.landed,
  .set.closing, .seat.arriving { animation: none; }
  /* Still said, just held still and then taken away by script. */
  .turn-call .band { animation: none; }
  /* Still marked, just not moving. */
  .pile.ready::before { animation: none; opacity: 0.8; }
  .tile { transition: none; }
}

/* The rack */

.rack-wrap {
  flex: none;
  padding: 8px 12px;
  border-top: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(10, 20, 28, 0), rgba(10, 20, 28, 0.6));
}

.rack {
  display: flex;
  /* The hand sizes its own cards, the way the table does, so a hand too wide
     to fan without burying itself shrinks instead. Set from fanRack(). */
  --tile-w: calc(var(--tile-base) * var(--hand-scale, 1));
  --tile-h: calc(var(--tile-w) * 1.36);
  /* A hand that will not fit is fanned, not wrapped: see fanRack(). */
  flex-wrap: nowrap;
  justify-content: center;
  /* A tray the width of the hand it holds. Stretched across a wide screen it
     was mostly empty tray with the tiles huddled in the middle of it. */
  width: fit-content;
  max-width: 100%;
  margin: 0 auto;
  gap: 4px;
  /* The tray keeps the height of a full sized card even when the hand in it
     has shrunk, so the bottom of the screen does not move about. */
  min-height: calc(var(--tile-base) * 1.36 + 14px);
  align-items: center;
  padding: 7px 10px;
  border-radius: var(--radius);
  /* A tray rather than a box: lit along the top lip, dark in the well. */
  background:
    linear-gradient(180deg, rgba(227, 178, 97, 0.1), rgba(0, 0, 0, 0.3) 40%),
    rgba(0, 0, 0, 0.28);
  border: 1px solid var(--line);
  border-top-color: rgba(227, 178, 97, 0.28);
  box-shadow: inset 0 8px 14px rgba(0, 0, 0, 0.4);
}

/* The fan. Each card is pulled back over the one before it, and reaching for
   one brings it to the front so the whole card can be seen. */
.rack .tile + .tile { margin-left: calc(-1 * var(--fan, 0px)); }
.rack .tile:hover, .rack .tile:active { z-index: 200 !important; }
.rack.over { border-color: var(--sand); }

/* Tools */

.tools {
  display: flex;
  gap: 6px;
  padding: 8px 12px calc(8px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  flex: none;
}

.tools button {
  appearance: none;
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  border: 1px solid var(--sand);
  background: var(--sand-soft);
  color: var(--sand);
  border-radius: 11px;
  padding: 7px 4px;
  font: inherit;
  cursor: pointer;
}
.tools button:disabled { opacity: 0.32; cursor: default; }
.tools button:not(:disabled):hover { background: rgba(227, 178, 97, 0.3); }
.tools .glyph { font-size: 16px; line-height: 1; }
.tools .label { font-size: 11px; font-weight: 600; letter-spacing: 0.03em; }

#play:not(:disabled) {
  background: var(--sand);
  color: #241a08;
}

/* Panels */

.scrim { position: fixed; inset: 0; background: rgba(6, 12, 17, 0.7); z-index: 50; }

.panel {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  z-index: 60;
  padding: 18px;
}

.panel-inner {
  width: min(400px, 100%);
  background: #162b38;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
}

.panel-inner h2 { margin: 0 0 12px; font-size: 19px; }
.panel-inner p { margin: 0 0 14px; color: var(--muted); font-size: 14px; }

.choice { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin-bottom: 10px; }
.choice-label { font-size: 11px; letter-spacing: 0.12em; text-transform: uppercase; color: var(--muted); width: 100%; }

.chip {
  appearance: none;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.04);
  color: var(--ink);
  border-radius: 999px;
  padding: 7px 15px;
  font: inherit;
  font-size: 14px;
  cursor: pointer;
}
.chip[aria-pressed="true"] { border-color: var(--sand); color: var(--sand); background: var(--sand-soft); }

.note { font-size: 13px; min-height: 2.6em; }
.note.warn { color: var(--bad); min-height: 0; margin-bottom: 10px; }

/* The card faces are somebody else's work, used under a licence that asks for
   a credit. It belongs where the cards are chosen. */
.credit { font-size: 12px; color: var(--muted); margin: -4px 0 14px; line-height: 1.4; }
.credit a { color: var(--sand); }

.scores { margin: 0 0 16px; }
.scores div { display: flex; justify-content: space-between; gap: 14px; padding: 5px 0; border-bottom: 1px solid var(--line); }
.scores dt { flex: 1 1 auto; }
.scores dd { min-width: 4.5em; text-align: right; }
/* The running total, which is the number that matters by the third or fourth
   hand, set apart from the one for the hand just played. */
.scores dd.total { color: var(--sand); }
.scores .head { border-bottom-color: transparent; padding-bottom: 0; }
.scores .head dd { font-size: 10px; letter-spacing: 0.1em; text-transform: uppercase; color: var(--muted); font-weight: 600; }
.scores dt { color: var(--muted); font-size: 14px; }
.scores dd { margin: 0; font-variant-numeric: tabular-nums; font-weight: 700; }
.scores div.won dt, .scores div.won dd { color: var(--sand); }

.panel-actions { display: flex; gap: 8px; }
.panel-actions button {
  appearance: none;
  flex: 1;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.04);
  color: var(--ink);
  border-radius: 10px;
  padding: 11px;
  font: inherit;
  cursor: pointer;
}
.panel-actions .primary { background: var(--sand); border-color: var(--sand); color: #241a08; font-weight: 700; }

.picker { display: flex; flex-wrap: wrap; gap: 6px; }

/* The menu is a long panel now, and on a phone it has to be able to scroll
   inside the screen rather than run off the bottom of it. */
#menu-panel .panel-inner { max-height: calc(100dvh - 36px); overflow-y: auto; }

/* The rules. Wider than the rest of the panels, because eight lines of prose
   down a 400px column on a phone is a wall. */
#rules-panel .panel-inner { width: min(560px, 100%); max-height: calc(100dvh - 36px); overflow-y: auto; }
#rules-panel .lead { color: var(--ink); }

.rules { margin: 0 0 14px; padding: 0; list-style: none; }
.rules li {
  position: relative;
  padding: 0 0 11px 16px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.5;
}
.rules li::before {
  content: "";
  position: absolute;
  left: 0;
  top: 9px;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--sand);
  opacity: 0.7;
}
.rules strong { color: var(--ink); font-weight: 700; }

/* Rooms */

/* The menu grew a second half, so the two need telling apart. */
.sub {
  margin: 22px 0 10px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
  font-size: 15px;
  letter-spacing: 0.01em;
}

.field { display: block; margin: 0 0 8px; }
.field span {
  display: block;
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 5px;
}
.field input {
  width: 100%;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.04);
  color: var(--ink);
  border-radius: 10px;
  padding: 10px 12px;
  font: inherit;
  font-size: 15px;
}
.field input:focus-visible { outline: 2px solid var(--sand); outline-offset: 1px; }

/* A code is read off one screen and typed into another, so it is set wide and
   in a fixed-width face: nothing here should turn on telling O from 0. */
.code-field, .code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  letter-spacing: 0.3em;
  text-transform: uppercase;
}
.code { color: var(--sand); }

.panel-actions + .field { margin-top: 12px; }

.lobby-players {
  list-style: none;
  margin: 0 0 14px;
  padding: 0;
}
.lobby-players li {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 2px;
  border-bottom: 1px solid var(--line);
  font-size: 15px;
}
.lobby-players li::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex: none;
  background: var(--muted);
}
.lobby-players li.here::before { background: var(--good); }
.lobby-players li.away::before { background: var(--bad); }
.lobby-players li.empty { color: var(--muted); font-size: 14px; }
.lobby-players li.empty::before { background: transparent; border: 1px dashed var(--muted); }

/* Shown only while the socket is down, which on a school network is usually
   for a second or two and not worth a panel over the game. */
.offline {
  margin: 0;
  padding: 5px 14px;
  text-align: center;
  font-size: 13px;
  color: #241a08;
  background: var(--sand);
}

@media (min-width: 760px) {
  .bar h1 { font-size: 19px; }
  .tools { padding-left: 20px; padding-right: 20px; }
  .tools button { flex: 0 1 130px; flex-direction: row; gap: 7px; padding: 10px; }
  .tools { justify-content: flex-end; }
}

@media (prefers-reduced-motion: reduce) {
  .tile.hint { animation: none; outline: 2px solid var(--sand); }
}
