/* Pai: a clean, modern Chinese look. Ivory paper, ink, vermilion seals, jade felt. */

:root {
  --ink: #1d1b18;
  --ink-soft: #5b544a;
  --paper: #f6f0e4;
  --paper-2: #ece3cf;
  --card: #fffdf8;
  --line: #ddd2bb;
  --vermilion: #c23a2b;
  --vermilion-dark: #9e2c20;
  --jade: #2d7a5f;
  --indigo: #2f4f86;
  --gold: #b8955a;
  --felt: #1d4a3f;
  --felt-light: #2a6152;
  --felt-dark: #12332b;
  --on-felt: #e9f1ec;
  --mod-ink: #8a5a12;
  --serif:
    "Noto Serif SC", "Noto Serif CJK SC", "Source Han Serif SC", "Songti SC", "STSong", "SimSun",
    serif;
  --sans:
    system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, "PingFang SC",
    "Microsoft YaHei", sans-serif;
  /* Tile sizes: the hand, the ponds (discards) and small tiles (melds, backs). */
  --hw: clamp(28px, min(calc((100vw - 32px) / 15), calc((100dvh - 200px) / 10)), 58px);
  --hh: calc(var(--hw) * 86 / 60);
  /* Ponds as large as the window allows: the felt is about 14.6 pond tiles tall (a middle
     of nine and two rows of pond on either side); the bar, the top opponent, the buttons,
     the waits and your hand need about 440px. */
  --pw: clamp(18px, min(3.3vw, calc((100dvh - 440px) / 14.6)), 46px);
  --ph: calc(var(--pw) * 86 / 60);
  --sw: clamp(18px, 2.3vw, 30px);
  --sh: calc(var(--sw) * 86 / 60);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --ink: #efe8da;
    --ink-soft: #b8ae9c;
    --paper: #171512;
    --paper-2: #221f1a;
    --card: #211e19;
    --line: #3a342b;
    --mod-ink: #e0b56a;
    --jade: #63c49a;
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --ink: #efe8da;
  --ink-soft: #b8ae9c;
  --paper: #171512;
  --paper-2: #221f1a;
  --card: #211e19;
  --line: #3a342b;
  --mod-ink: #e0b56a;
  --jade: #63c49a;
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

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

body {
  background: var(--paper);
  color: var(--ink);
  font: 17px / 1.5 var(--sans);
  -webkit-tap-highlight-color: transparent;
}

h1,
h2,
.zh,
.code {
  font-family: var(--serif);
}

h1 {
  font-size: clamp(32px, 6vw, 52px);
  margin: 8px 0 0;
  letter-spacing: 0.02em;
}

h2 {
  font-size: 20px;
  margin: 0 0 14px;
}

h2 .zh,
h1 .zh {
  color: var(--vermilion);
  font-weight: 700;
}

button,
input,
select {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
  border: 1px solid var(--line);
  background: var(--card);
  border-radius: 8px;
  padding: 8px 14px;
}

button:disabled {
  cursor: default;
}

button.primary {
  background: var(--vermilion);
  border-color: var(--vermilion-dark);
  color: #fffaf2;
  font-weight: 600;
  padding: 11px 18px;
  box-shadow: 0 2px 0 var(--vermilion-dark);
}

button.primary:hover {
  background: var(--vermilion-dark);
}

button.quiet {
  background: transparent;
  border-color: transparent;
  color: var(--ink-soft);
  text-decoration: underline;
  text-underline-offset: 3px;
}

input,
select {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
}

input:focus-visible,
select:focus-visible,
button:focus-visible {
  outline: 2px solid var(--jade);
  outline-offset: 2px;
}

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

.link {
  display: inline-block;
  margin-top: 12px;
}

.seal {
  display: block;
}

.seal.big {
  width: 64px;
  height: 64px;
}

.seal.small {
  width: 28px;
  height: 28px;
}

/* The seal at the top left of the table: leave for the start page. */
.home-button {
  padding: 3px;
  margin: -3px;
  border: none;
  border-radius: 8px;
  background: transparent;
  cursor: pointer;
  transition: background 0.15s;
}

.home-button:hover {
  background: rgb(255 255 255 / 0.16);
}

.home-button:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 1px;
}

.modal.leave {
  width: min(420px, 100%);
}

.modal.leave p {
  margin: 0;
}

/* The start page: back to a table left during a game. */
.card.back-to {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-left: 4px solid var(--gold);
}

.card.back-to p {
  margin: 0;
}

.shown-note {
  font-size: 13px;
  color: var(--on-felt);
  opacity: 0.8;
}

.badge {
  display: inline-block;
  margin-left: 8px;
  padding: 0 7px;
  border-radius: 999px;
  font-size: 12px;
  line-height: 20px;
  background: var(--paper-2);
  color: var(--ink-soft);
  vertical-align: middle;
}

.badge.away {
  background: #f3dcc2;
  color: #7a4a14;
}

/* --- Home and lobby -------------------------------------------------------------- */

.home,
.lobby {
  max-width: 920px;
  margin: 0 auto;
  padding: 32px 16px 64px;
}

.hero {
  text-align: center;
  margin-bottom: 28px;
}

.hero .seal {
  margin: 0 auto;
}

.hero.small h1 {
  font-size: 30px;
}

.lede {
  max-width: 560px;
  margin: 12px auto 0;
  color: var(--ink-soft);
  font-size: 18px;
}

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 18px;
}

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 22px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  box-shadow: 0 1px 0 var(--line);
}

.card.narrow {
  max-width: 420px;
  margin: 0 auto;
}

.card.how {
  margin-top: 18px;
}

.card.how ul {
  margin: 0;
  padding-left: 20px;
  color: var(--ink-soft);
}

.fields {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.field span {
  display: block;
  font-size: 13px;
  color: var(--ink-soft);
  margin-bottom: 4px;
}

.check {
  display: flex;
  gap: 8px;
  align-items: center;
  font-size: 14px;
}

.check input {
  width: auto;
}

.volume {
  display: flex;
  gap: 10px;
  align-items: center;
  padding-left: 26px;
  font-size: 14px;
}

.volume input {
  flex: 1;
  accent-color: var(--vermilion);
}

.code {
  color: var(--vermilion);
  letter-spacing: 0.12em;
}

.code-input {
  text-transform: uppercase;
  letter-spacing: 0.3em;
  font-family: var(--serif);
  font-size: 22px;
}

.invite {
  display: flex;
  gap: 8px;
  max-width: 520px;
  margin: 14px auto 0;
}

.invite input {
  flex: 1;
  min-width: 0;
}

.seats {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.seat {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--paper);
  border: 1px solid var(--line);
}

.seat.empty {
  border-style: dashed;
}

.seat-no {
  width: 28px;
  height: 28px;
  border-radius: 6px;
  display: grid;
  place-items: center;
  background: var(--felt);
  color: var(--on-felt);
  font-family: var(--serif);
}

.dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  margin-left: 8px;
  border-radius: 50%;
  background: #b9b1a3;
  vertical-align: middle;
}

.dot.on {
  background: #3aa36b;
}

#toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  z-index: 50;
  pointer-events: none;
}

.toast {
  background: var(--ink);
  color: var(--paper);
  padding: 10px 16px;
  border-radius: 10px;
  max-width: 90vw;
  box-shadow: 0 6px 20px rgb(0 0 0 / 0.25);
}

/* --- The table ------------------------------------------------------------------- */

.table-page {
  height: 100dvh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  background: radial-gradient(
    ellipse at 50% 40%,
    var(--felt-light),
    var(--felt) 55%,
    var(--felt-dark)
  );
  color: var(--on-felt);
}

.bar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 16px;
  background: rgb(0 0 0 / 0.18);
  position: relative;
}

.bar .spacer {
  flex: 1;
}

.bar .code {
  color: #f2c9a0;
}

.conn {
  font-size: 13px;
  color: #f2c9a0;
}

.log summary {
  cursor: pointer;
  font-size: 14px;
  list-style: none;
  padding: 4px 10px;
  border: 1px solid rgb(255 255 255 / 0.25);
  border-radius: 8px;
}

.log ol {
  position: absolute;
  right: 16px;
  top: 44px;
  z-index: 20;
  width: min(420px, calc(100vw - 32px));
  max-height: 60vh;
  overflow: auto;
  margin: 0;
  padding: 12px 16px 12px 32px;
  background: var(--card);
  color: var(--ink);
  border-radius: 12px;
  font-size: 13px;
  box-shadow: 0 10px 30px rgb(0 0 0 / 0.35);
}

/* The space below the bar. The table fills it, and is scaled down to fit when its
   content is taller (see fitTable in main.ts). */
.fit {
  flex: 1;
  min-height: 0;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  overflow: hidden;
}

.table {
  flex: none;
  min-height: 100%;
  transform-origin: top center;
  display: grid;
  grid-template-columns: auto 1fr auto;
  grid-template-rows: auto 1fr auto;
  grid-template-areas:
    ". top ."
    "left felt right"
    "mine mine mine";
  gap: 6px 10px;
  padding: 8px 12px 12px;
  max-width: 1200px;
  width: 100%;
  margin: 0 auto;
}

.tile {
  display: block;
  user-select: none;
  -webkit-user-drag: none;
}

/* Opponents */

.opponent {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 14px;
}

.opponent.top {
  grid-area: top;
  flex-direction: column;
}

.opponent.left {
  grid-area: left;
  flex-direction: column;
  justify-content: center;
}

.opponent.right {
  grid-area: right;
  flex-direction: column;
  justify-content: center;
}

.nameplate {
  padding: 4px 14px;
  font-size: 16px;
  border-radius: 999px;
  background: rgb(0 0 0 / 0.22);
  white-space: nowrap;
}

.opponent.turn .nameplate,
.mine.turn .hand {
  box-shadow: 0 0 0 2px var(--gold);
}

.nameplate .badge {
  background: rgb(255 255 255 / 0.15);
  color: var(--on-felt);
}

.backs {
  display: flex;
}

.backs .tile {
  width: var(--sw);
  height: var(--sh);
  margin-right: -1px;
}

.opponent.left .backs,
.opponent.right .backs {
  flex-direction: column;
}

.opponent.left .backs .tile,
.opponent.right .backs .tile {
  width: var(--sh);
  height: var(--sw);
  margin: 0 0 -4px;
  object-fit: fill;
}

/* An open riichi's hand, face up in the place of the backs (so nothing moves): upright
   above, turned towards the middle at the sides, in the player's own order. */
.opponent.left .backs .tile.face,
.opponent.right .backs .tile.face {
  width: var(--sw);
  height: var(--sh);
  margin: calc((var(--sw) - var(--sh)) / 2 - 2px) calc((var(--sh) - var(--sw)) / 2);
}

.opponent.left .backs .tile.face {
  transform: rotate(90deg);
}

.opponent.right .backs .tile.face {
  transform: rotate(-90deg);
}

.opponent.right .backs.shown {
  flex-direction: column-reverse;
}

.melds {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: center;
}

.meld {
  display: inline-flex;
  align-items: flex-end;
}

.meld .tile,
.tile.small {
  width: var(--sw);
  height: var(--sh);
}

.meld .tile.sideways {
  transform: rotate(-90deg) translateX(calc((var(--sh) - var(--sw)) / -2));
  margin: 0 calc((var(--sh) - var(--sw)) / 2);
}

/* The felt: four ponds around the centre box. */

.felt {
  grid-area: felt;
  position: relative;
  display: grid;
  place-content: center;
  grid-template-columns: auto auto auto;
  grid-template-rows: auto auto auto;
  grid-template-areas:
    ". top ."
    "left centre right"
    ". bottom .";
  gap: 4px;
}

.pond {
  position: relative;
}

.pond.top {
  grid-area: top;
}

.pond.bottom {
  grid-area: bottom;
}

.pond.left {
  grid-area: left;
}

.pond.right {
  grid-area: right;
}

/* Two rows of nine, starting at each player's left corner of the middle. The second row
   runs on into the empty corner of the felt to its right (each pond has its own corner),
   so about twenty discards fit; a rare third row spills into the space around. */
.pond.top,
.pond.bottom {
  width: calc(9 * var(--pw));
  height: calc(2 * var(--ph));
}

.pond.left,
.pond.right {
  width: calc(2 * var(--ph));
  height: calc(9 * var(--pw));
}

.pond.bottom {
  justify-self: start;
}

.pond.top {
  justify-self: end;
}

.pond.left {
  align-self: start;
}

.pond.right {
  align-self: end;
}

.pond-tiles {
  position: absolute;
  left: 50%;
  top: 50%;
  width: calc(9 * var(--pw));
  height: calc(2 * var(--ph));
  display: flex;
  flex-direction: column;
  transform: translate(-50%, -50%);
}

.pond-row {
  display: flex;
  flex: none;
  height: var(--ph);
}

.pond.top .pond-tiles {
  transform: translate(-50%, -50%) rotate(180deg);
}

.pond.left .pond-tiles {
  transform: translate(-50%, -50%) rotate(90deg);
}

.pond.right .pond-tiles {
  transform: translate(-50%, -50%) rotate(-90deg);
}

.pond .tile {
  width: var(--pw);
  height: var(--ph);
}

.pond .tile.sideways {
  transform: rotate(90deg);
  margin: 0 calc((var(--ph) - var(--pw)) / 2);
}

.pond .tile.called {
  opacity: 0.4;
}

.pond .tile.fresh {
  animation: drop 0.35s ease-out;
  filter: drop-shadow(0 0 3px #ffd98a);
}

@keyframes drop {
  from {
    transform: translateY(-14px);
    opacity: 0;
  }
}

.pond .tile.sideways.fresh {
  animation: none;
}

/* The middle of the table. Its size is --cw, and the text in it scales with that, so it
   is as large as the box allows. */
.centre {
  grid-area: centre;
  position: relative;
  /* At least a pond row long, up to 400px where the window has room: on phones the ponds
     beside it limit the width, on short screens the hand below limits the height. */
  --cw: max(
    calc(9 * var(--pw)),
    min(400px, calc(100vw - 4 * var(--ph) - 32px), calc(100dvh - 4 * var(--ph) - 360px))
  );
  width: var(--cw);
  height: var(--cw);
  justify-self: center;
  align-self: center;
  border-radius: 14px;
  background: var(--felt-dark);
  box-shadow:
    inset 0 0 0 1px rgb(255 255 255 / 0.12),
    0 4px 14px rgb(0 0 0 / 0.3);
  display: grid;
  place-items: center;
}

.round {
  text-align: center;
  line-height: 1.15;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: calc(var(--cw) * 0.012);
}

.round-zh {
  font-family: var(--serif);
  font-size: calc(var(--cw) * 0.16);
  font-weight: 700;
  line-height: 1.05;
}

.round-en,
.wall-left {
  font-size: max(14px, calc(var(--cw) * 0.072));
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.wall-left {
  opacity: 0.85;
}

/* Honba and riichi deposits, in the top corners: a number over its name. */
.count {
  position: absolute;
  top: calc(var(--cw) * 0.05);
  display: flex;
  flex-direction: column;
  align-items: center;
  line-height: 1;
  gap: 2px;
  font-variant-numeric: tabular-nums;
}

.count strong {
  font-size: max(15px, calc(var(--cw) * 0.08));
}

.count .zh {
  font-family: var(--serif);
  font-size: max(11px, calc(var(--cw) * 0.05));
  opacity: 0.8;
}

.count.none {
  opacity: 0.45;
}

.count.honba {
  left: calc(var(--cw) * 0.06);
}

.count.deposits {
  right: calc(var(--cw) * 0.06);
}

/* Dora: the indicators, as they lie on the wall. */
.dora {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 4px;
  max-width: calc(var(--cw) * 0.62);
  margin-top: calc(var(--cw) * 0.02);
}

.dora-label {
  margin-right: 2px;
  font-size: max(11px, calc(var(--cw) * 0.05));
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #ffd98a;
}

.dora .tile.indicator {
  width: calc(var(--cw) * 0.12);
  height: auto;
}

.dora.many .tile.indicator {
  width: calc(var(--cw) * 0.09);
}

.score {
  position: absolute;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  font-size: max(14px, calc(var(--cw) * 0.074));
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.score-row {
  display: flex;
  align-items: center;
  gap: 5px;
}

/* The stick sits above the score (towards the middle); rotating the box turns it to face each seat. */
.score.bottom {
  bottom: 6px;
  left: 50%;
  transform: translateX(-50%);
}

.score.top {
  top: 6px;
  left: 50%;
  transform: translateX(-50%) rotate(180deg);
}

.score.left {
  left: 6px;
  top: 50%;
  transform: translate(-50%, -50%) rotate(90deg) translateY(-50%);
  transform-origin: center;
}

.score.right {
  right: 6px;
  top: 50%;
  transform: translate(50%, -50%) rotate(-90deg) translateY(-50%);
}

.score.turn .points {
  color: #ffd98a;
}

.wind {
  font-family: var(--serif);
  font-weight: 700;
}

.wind.dealer {
  color: #ff9d8a;
}

/* A riichi stick: a 1,000-point stick with its red dot, large enough to see at a glance. */
.stick {
  display: block;
  width: calc(var(--cw) * 0.3);
  height: max(8px, calc(var(--cw) * 0.04));
  border-radius: 6px;
  background: linear-gradient(#fffdf7, #e6dcc6);
  box-shadow:
    0 1px 3px rgb(0 0 0 / 0.5),
    0 0 12px rgb(255 217 138 / 0.6);
  position: relative;
  animation: stick-in 0.4s ease-out;
}

.stick::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  height: 62%;
  aspect-ratio: 1;
  border-radius: 50%;
  background: var(--vermilion);
  transform: translate(-50%, -50%);
}

@keyframes stick-in {
  from {
    transform: translateY(-10px) scale(1.3);
    opacity: 0;
  }
}

.badge.riichi {
  background: var(--vermilion);
  color: #fff;
  font-weight: 700;
}

/* Calls: a seal stamped near the caller. */

.banner {
  position: absolute;
  z-index: 10;
  padding: 6px 14px;
  border-radius: 10px;
  background: var(--vermilion);
  color: #fffaf2;
  font-family: var(--serif);
  font-size: clamp(22px, 3vw, 34px);
  font-weight: 700;
  box-shadow:
    0 0 0 3px rgb(255 250 242 / 0.8),
    0 8px 24px rgb(0 0 0 / 0.35);
  animation: stamp 0.25s ease-out;
  pointer-events: none;
}

.banner.bottom {
  bottom: 10%;
  left: 50%;
  translate: -50% 0;
}

.banner.top {
  top: 10%;
  left: 50%;
  translate: -50% 0;
}

.banner.left {
  left: 8%;
  top: 50%;
  translate: 0 -50%;
}

.banner.right {
  right: 8%;
  top: 50%;
  translate: 0 -50%;
}

@keyframes stamp {
  from {
    transform: scale(1.6);
    opacity: 0;
  }
}

/* Your area */

.mine {
  grid-area: mine;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.actions {
  min-height: 44px;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 8px;
  position: relative;
}

.action {
  background: var(--card);
  color: var(--ink);
  border: none;
  border-radius: 10px;
  padding: 10px 20px;
  font-size: 17px;
  font-weight: 600;
  box-shadow: 0 3px 0 rgb(0 0 0 / 0.35);
  animation: rise 0.2s ease-out;
}

.action .zh {
  color: var(--vermilion);
  font-size: 21px;
}

.action.tsumo,
.action.ron {
  background: var(--vermilion);
  color: #fffaf2;
}

.action.tsumo .zh,
.action.ron .zh {
  color: #fffaf2;
}

.action.riichi.active {
  background: #fff3d6;
  box-shadow:
    0 0 0 2px var(--gold),
    0 3px 0 rgb(0 0 0 / 0.35);
}

.action.pass {
  background: rgb(255 255 255 / 0.85);
}

.actions .quiet {
  color: var(--on-felt);
}

.actions .badge.away {
  margin: 0;
}

@keyframes rise {
  from {
    transform: translateY(6px);
    opacity: 0;
  }
}

.timer {
  position: absolute;
  left: 0;
  right: 0;
  bottom: -4px;
  height: 3px;
  border-radius: 2px;
  overflow: hidden;
  background: rgb(255 255 255 / 0.15);
}

.timer span {
  display: block;
  height: 100%;
  background: #ffd98a;
  transform-origin: left;
  animation: shrink var(--ms) linear forwards;
}

@keyframes shrink {
  to {
    transform: scaleX(0);
  }
}

.picker {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  align-items: center;
}

.picker .option {
  display: flex;
  gap: 1px;
  padding: 6px;
  background: var(--card);
}

.hand-row {
  display: flex;
  align-items: flex-end;
  justify-content: center;
  gap: 16px;
  flex-wrap: wrap;
}

.hand {
  display: flex;
  align-items: flex-end;
  padding: 4px;
  border-radius: 10px;
}

.hand-tile {
  padding: 0;
  margin: 0;
  border: none;
  background: none;
  border-radius: 6px;
  transition: transform 0.12s ease;
}

.hand-tile .tile {
  width: var(--hw);
  height: var(--hh);
}

.hand-tile.drawn {
  margin-left: calc(var(--hw) * 0.45);
}

.hand-tile:not(:disabled):hover,
.hand-tile:not(:disabled):focus-visible {
  transform: translateY(-8px);
}

.hand-tile.hinted {
  transform: translateY(-8px);
  filter: drop-shadow(0 0 6px #ffd98a);
}

.mine.turn .hand-tile:disabled .tile {
  filter: brightness(0.75) saturate(0.7);
}

.hand-tile.riichi-ok .tile {
  filter: drop-shadow(0 0 4px #ffd98a);
}

/* Round results and the end of the game */

.overlay {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgb(10 20 17 / 0.55);
  backdrop-filter: blur(2px);
}

.modal {
  width: min(560px, 100%);
  max-height: calc(100dvh - 32px);
  overflow: auto;
  background: var(--card);
  color: var(--ink);
  border-radius: 16px;
  padding: 24px;
  border-top: 6px solid var(--vermilion);
  box-shadow: 0 20px 50px rgb(0 0 0 / 0.4);
  display: flex;
  flex-direction: column;
  gap: 14px;
  animation: rise 0.25s ease-out;
}

/* How a win's points add up: labels left, amounts right, a rule above the total. */
.breakdown {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 2px 0;
  margin: 0;
  font-variant-numeric: tabular-nums;
}

.breakdown dt {
  color: var(--ink-soft);
}

.breakdown dd {
  margin: 0;
  padding-left: 16px;
  text-align: right;
}

.breakdown dd.add {
  color: var(--jade);
}

.breakdown .total {
  margin-top: 4px;
  padding-top: 4px;
  border-top: 1px solid var(--line);
  color: var(--ink);
  font-weight: 600;
}

.modal h2 {
  margin: 0;
}

.winner {
  margin: 0;
  font-weight: 600;
}

.win-hand {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 1px;
}

.win-hand .gap {
  width: 8px;
}

.win-hand .meld {
  margin-left: 8px;
}

.win-hand .tile.won {
  filter: drop-shadow(0 0 4px var(--gold));
}

.yaku {
  list-style: none;
  margin: 0;
  padding: 0;
}

.yaku li,
.deltas li {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 12px;
  padding: 4px 0;
  border-bottom: 1px dashed var(--line);
}

.yaku .zh {
  color: var(--ink-soft);
}

.yaku .han {
  min-width: 64px;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.value {
  margin: 0;
  text-align: right;
  color: var(--ink-soft);
}

.value strong {
  color: var(--vermilion);
  font-size: 20px;
}

.deltas {
  list-style: none;
  margin: 0;
  padding: 0;
  font-variant-numeric: tabular-nums;
}

.deltas .plus {
  color: var(--jade);
  font-weight: 600;
}

.deltas .minus {
  color: var(--vermilion);
  font-weight: 600;
}

.standings {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.standings li {
  display: grid;
  grid-template-columns: 36px 1fr auto;
  align-items: center;
  padding: 10px 14px;
  border-radius: 10px;
  background: var(--paper);
  font-variant-numeric: tabular-nums;
}

.standings li.first {
  background: #fbe7d6;
  color: #3a1d10;
}

.standings .place {
  font-family: var(--serif);
  font-weight: 700;
  color: var(--vermilion);
  font-size: 20px;
}

/* Small screens: opponents shrink to nameplates and melds. */

@media (max-width: 720px) {
  .table {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    grid-template-areas:
      "left top right"
      "felt felt felt"
      "mine mine mine";
    padding: 6px 4px 10px;
  }

  .opponent .backs {
    display: none;
  }

  /* An open riichi's hand still shows, small and upright, under the name. */
  .opponent .backs.shown {
    display: flex;
    flex-flow: row wrap;
    justify-content: center;
    max-width: 100%;
  }

  .opponent .backs.shown .tile {
    display: none;
  }

  .opponent .backs.shown .tile.face {
    display: block;
    width: 16px;
    height: 23px;
    margin: 0;
    transform: none;
  }

  /* Three name tags share the width: long names and badges are cut short. */
  .opponent {
    min-width: 0;
  }

  .nameplate {
    max-width: 100%;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
    font-size: 13px;
  }

  .nameplate .badge {
    margin-left: 4px;
    padding: 0 5px;
  }

  .opponent.left,
  .opponent.right {
    justify-content: flex-start;
  }

  :root {
    --pw: clamp(16px, min(5vw, calc((100dvh - 330px) / 14.6)), 30px);
    /* Fourteen tiles across a phone. */
    --hw: clamp(20px, min(calc((100vw - 32px) / 15), calc((100dvh - 200px) / 10)), 58px);
  }
}

/* --- Waits: what a discard leaves the hand waiting on ------------------------------ */

/* A fixed height, so showing the waits never moves the hand. A longer box (many waits,
   or advice, as when picking a riichi discard) grows upwards over the felt, never cut. */
.waits {
  position: relative;
  align-self: stretch;
  height: 58px;
}

.waits-box {
  position: absolute;
  z-index: 6;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: max-content;
  max-width: min(760px, calc(100vw - 24px));
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 2px 12px;
  padding: 4px 14px;
  border-radius: 12px;
  background: rgb(10 30 24 / 0.88);
  box-shadow: 0 4px 14px rgb(0 0 0 / 0.3);
  font-size: 15px;
}

.waits-title {
  font-weight: 600;
}

.wait {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.wait.gone {
  opacity: 0.45;
}

.wait .left {
  font-variant-numeric: tabular-nums;
  font-weight: 600;
}

.wait .why {
  font-size: 12px;
  padding: 0 6px;
  border-radius: 999px;
  background: #f3dcc2;
  color: #7a4a14;
}

.waits-total {
  color: #ffd98a;
  font-weight: 600;
}

.waits-box.dead .waits-total {
  color: #ff9d8a;
}

.advice {
  flex-basis: 100%;
  text-align: center;
  font-size: 12.5px;
  line-height: 1.3;
  color: #f2c9a0;
}

/* A hand tile whose discard leaves the hand waiting: a small gold dot above it. */
.hand-tile.readies {
  position: relative;
}

.hand-tile.readies::before {
  content: "";
  position: absolute;
  top: -9px;
  left: 50%;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #ffd98a;
  box-shadow: 0 0 6px #ffd98a;
  transform: translateX(-50%);
}

/* --- Your settings --------------------------------------------------------------- */

.prefs-button {
  position: fixed;
  top: 8px;
  right: 12px;
  z-index: 40;
  width: 38px;
  height: 38px;
  padding: 0;
  border-radius: 50%;
  font-size: 20px;
  line-height: 1;
  background: var(--card);
  color: var(--ink);
  box-shadow: 0 2px 8px rgb(0 0 0 / 0.25);
}

.prefs-panel {
  position: fixed;
  top: 54px;
  right: 12px;
  z-index: 40;
  width: min(320px, calc(100vw - 24px));
  padding: 18px;
  border-radius: 14px;
  background: var(--card);
  color: var(--ink);
  border: 1px solid var(--line);
  box-shadow: 0 12px 32px rgb(0 0 0 / 0.35);
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-height: calc(100dvh - 70px);
  overflow-y: auto;
}

.prefs-panel h2 {
  margin: 0;
}

.check-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.check-row button {
  padding: 4px 6px;
}

.characters {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(72px, 1fr));
  gap: 6px;
  margin-top: 6px;
}

.character {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 6px 4px;
  font-size: 12px;
  color: inherit;
}

.character.picked {
  border-color: var(--vermilion);
  box-shadow: 0 0 0 2px var(--vermilion);
}

.character-face {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  overflow: hidden;
  border: 2px solid var(--e, var(--line));
  border-radius: 50%;
  background: radial-gradient(
    circle,
    var(--c, var(--paper-2)),
    var(--b, var(--paper-2)) 60%,
    var(--a, var(--paper-2))
  );
  color: #fff;
  font-family: var(--serif);
  font-size: 22px;
  font-weight: 700;
  text-shadow: 0 1px 2px rgb(0 0 0 / 0.5);
}

.character-face img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: top;
}

.character-name {
  line-height: 1.2;
  text-align: center;
}

.cutin-switches {
  margin: 0;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.cutin-switches legend {
  padding: 0 4px;
  font-size: 13px;
}

.seat-character {
  margin-left: 6px;
  font-size: 12px;
  color: var(--ink-soft);
}

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

/* Room for the settings button at the right of the table's bar. */
.bar {
  padding-right: 62px;
}

/* --- Table settings: presets, rules and mods ------------------------------------- */

.summary {
  padding: 12px 14px;
  border-radius: 10px;
  background: var(--paper);
  border: 1px solid var(--line);
}

.summary-title {
  margin: 0 0 4px;
  font-weight: 700;
}

.summary-list {
  margin: 0;
  padding-left: 18px;
  font-size: 14px;
  color: var(--ink-soft);
}

.summary-list .mods {
  color: var(--mod-ink);
  font-weight: 600;
}

.row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.settings-button,
.yaku-button {
  background: var(--paper-2);
  color: var(--ink);
}

.modal.settings {
  width: min(680px, 100%);
  border-top-color: var(--jade);
}

.settings-section {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

.settings-section h3 {
  margin: 0;
  font-size: 16px;
}

.settings-section .h3-zh {
  color: var(--ink-soft);
  font-family: var(--serif);
  font-weight: 500;
}

.settings-section .muted {
  margin: 0;
}

.presets {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
  gap: 8px;
}

.preset {
  display: grid;
  grid-template-columns: auto 1fr;
  grid-template-rows: auto auto;
  column-gap: 10px;
  align-items: center;
  text-align: left;
  padding: 10px 12px;
  border-radius: 10px;
  border: 2px solid var(--line);
  background: var(--card);
  color: var(--ink);
}

.preset .preset-zh {
  grid-row: span 2;
  font-family: var(--serif);
  font-size: 22px;
  font-weight: 700;
  color: var(--vermilion);
}

.preset small {
  color: var(--ink-soft);
  font-size: 12px;
  line-height: 1.3;
}

.preset.on {
  border-color: var(--jade);
  background: color-mix(in srgb, var(--jade) 10%, var(--card));
}

.toggle {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  cursor: pointer;
}

.toggle input {
  width: 18px;
  height: 18px;
  margin: 2px 0 0;
  flex: none;
  accent-color: var(--jade);
}

.toggle span {
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.toggle small {
  color: var(--ink-soft);
  font-size: 13px;
  line-height: 1.35;
}

.toggle.off {
  cursor: default;
}

.toggle.off strong {
  opacity: 0.6;
}

.version {
  margin: 24px 0 8px;
  text-align: center;
  font-size: 13px;
  color: var(--ink-soft);
}

/* --- The yaku list: a pop-out at the top left ------------------------------------ */

.bar .yaku-button {
  padding: 4px 10px;
  font-size: 14px;
  background: rgb(255 255 255 / 0.12);
  color: var(--on-felt);
  border: 1px solid rgb(255 255 255 / 0.25);
  border-radius: 8px;
}

.yaku-glyph {
  font-family: var(--serif);
  font-weight: 700;
}

.yaku-button[aria-expanded="true"] {
  background: #ffd98a;
  color: #3a2a0c;
}

.yaku-panel {
  position: fixed;
  top: 54px;
  left: 12px;
  z-index: 35;
  width: min(400px, calc(100vw - 24px));
  max-height: calc(100dvh - 70px);
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 14px 16px;
  border-radius: 14px;
  background: var(--card);
  color: var(--ink);
  border: 1px solid var(--line);
  box-shadow: 0 12px 32px rgb(0 0 0 / 0.35);
  animation: rise 0.2s ease-out;
}

.yaku-top {
  display: flex;
  align-items: center;
  gap: 8px;
}

.yaku-top h2 {
  margin: 0;
  flex: 1;
}

.yaku-top select {
  width: auto;
}

.yaku-panel > .muted {
  margin: 0;
  font-size: 13px;
}

.yaku-list {
  list-style: none;
  margin: 0;
  padding: 0;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.yaku-group {
  position: sticky;
  top: 0;
  padding: 6px 0 4px;
  background: var(--card);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--vermilion);
}

.yaku-entry {
  padding: 6px 8px;
  border-radius: 8px;
}

.yaku-entry.mod {
  background: color-mix(in srgb, var(--gold) 18%, var(--card));
  box-shadow: inset 3px 0 0 var(--gold);
}

.yaku-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 2px 8px;
}

.yaku-en {
  font-weight: 600;
}

.yaku-ja {
  font-family: var(--serif);
  color: var(--ink-soft);
}

.yaku-value {
  margin-left: auto;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  color: var(--ink-soft);
  white-space: nowrap;
}

.badge.mod {
  margin-left: 0;
  background: var(--gold);
  color: #2a1d08;
}

.yaku-desc {
  margin: 2px 0 0;
  font-size: 13px;
  line-height: 1.35;
  color: var(--ink-soft);
}

/* --- Dora in your hand: a pearlescent sheen and a glint ------------------------- */

/* Pearlescent, like mother-of-pearl: soft pastels drift slowly across the tile, and now
   and then a little star glints at its corner. Red fives and dora alike. Every tile's
   --phase is the same clock, so a redraw never restarts either animation. */
.hand-tile.shine {
  position: relative;
  filter: drop-shadow(0 0 3px rgb(255 244 225 / 0.8));
}

.hand-tile.shine::after {
  content: "";
  position: absolute;
  inset: 0 0 calc(var(--hh) * 0.07);
  border-radius: 6px;
  pointer-events: none;
  background: linear-gradient(
    125deg,
    #ffe2ee 0%,
    #e0efff 20%,
    #efe4ff 38%,
    #ddf8ec 56%,
    #fff1d8 74%,
    #ffe2ee 100%
  );
  background-size: 260% 260%;
  mix-blend-mode: multiply;
  animation: pearl 12s ease-in-out infinite;
  animation-delay: var(--phase, 0s);
}

@keyframes pearl {
  0%,
  100% {
    background-position: 0% 30%;
  }
  50% {
    background-position: 100% 70%;
  }
}

/* The glint: a four-pointed star on the tile's top right corner, out over the felt. */
.glint {
  position: absolute;
  z-index: 1;
  top: calc(var(--hw) * -0.24);
  right: calc(var(--hw) * -0.24);
  width: calc(var(--hw) * 0.5);
  aspect-ratio: 1;
  pointer-events: none;
  background:
    radial-gradient(closest-side, #fff 0%, rgb(255 255 255 / 0) 100%) center / 100% 13% no-repeat,
    radial-gradient(closest-side, #fff 0%, rgb(255 255 255 / 0) 100%) center / 13% 100% no-repeat,
    radial-gradient(closest-side, #fff 30%, rgb(255 214 140 / 0.7) 60%, rgb(255 214 140 / 0)) center
    / 42% 42% no-repeat;
  filter: drop-shadow(0 0 2px rgb(255 205 120 / 0.9));
  opacity: 0;
  animation: glint 4.8s ease-in-out infinite;
  animation-delay: var(--phase, 0s);
}

@keyframes glint {
  0%,
  72%,
  100% {
    opacity: 0;
    transform: scale(0.2) rotate(0deg);
  }
  82% {
    opacity: 1;
    transform: scale(1) rotate(45deg);
  }
  92% {
    opacity: 0;
    transform: scale(0.4) rotate(90deg);
  }
}

/* A window that was already open when the page was redrawn: no entrance again. */
[data-keep].kept {
  animation: none;
}

@media (prefers-reduced-motion: reduce) {
  .hand-tile.shine::after,
  .stick {
    animation: none;
  }

  /* Without motion: the sheen stands still, and the glint stays lit. */
  .glint {
    animation: none;
    opacity: 0.9;
    transform: scale(0.8) rotate(45deg);
  }
}

/* Cut-ins: the banner that announces a riichi (web/client/cutin/). Over the table, under
   the result screens; clicks go through to the table. */
#cutin {
  position: fixed;
  inset: 0;
  z-index: 25;
  pointer-events: none;
  overflow: hidden;
}

.cutin,
.ci-backdrop,
.ci-band,
.ci-layer,
.ci-flash {
  position: absolute;
  inset: 0;
}

.ci-backdrop {
  background: radial-gradient(ellipse at 50% 45%, transparent 20%, var(--ci-backdrop) 75%);
}

.ci-band {
  filter: drop-shadow(0 0 1.4vmin var(--ci-glow));
}

.ci-bands {
  width: 100%;
  height: 100%;
  overflow: visible;
}

.ci-portrait {
  position: absolute;
  display: flex;
  align-items: flex-end;
}

.ci-portrait.emblem {
  align-items: center;
}

.ci-portrait-inner {
  height: 100%;
  display: flex;
  align-items: inherit;
}

.ci-portrait-inner.flip {
  transform: scaleX(-1);
}

.ci-art {
  height: 100%;
  max-width: 60vw;
  object-fit: contain;
  object-position: bottom;
  filter: drop-shadow(0 0 1.2vmin var(--ci-glow));
}

.ci-emblem {
  width: min(44vh, 42vw);
  height: min(44vh, 42vw);
  filter: drop-shadow(0 0 2vmin var(--ci-glow));
}

.ci-glyph {
  font-family: var(--serif);
  font-size: 92px;
  font-weight: 700;
}

.ci-word {
  position: absolute;
  width: 0;
  height: 0;
}

.ci-word-inner {
  position: absolute;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  line-height: 1;
  white-space: nowrap;
  filter: drop-shadow(0 0 0.08em var(--ci-glow)) drop-shadow(0 0.04em 0 var(--ci-text-edge));
}

.ci-sub {
  margin: 0 0 0.08em 0.3em;
  font-size: 0.26em;
  letter-spacing: 0.2em;
  color: var(--ci-edge);
}

.ci-letter {
  display: inline-block;
  color: var(--ci-text);
  -webkit-text-stroke: var(--ci-stroke) var(--ci-text-edge);
  paint-order: stroke fill;
}

/* A gradient fill is the letter's background, under any stroke: outlined with shadows instead. */
.ci-letter.gradient {
  background: linear-gradient(180deg, var(--ci-text) 40%, var(--ci-accent));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  -webkit-text-stroke: 0;
  filter: drop-shadow(var(--ci-stroke) 0 0 var(--ci-text-edge))
    drop-shadow(calc(var(--ci-stroke) * -1) 0 0 var(--ci-text-edge))
    drop-shadow(0 var(--ci-stroke) 0 var(--ci-text-edge))
    drop-shadow(0 calc(var(--ci-stroke) * -1) 0 var(--ci-text-edge));
}

.ci-caption {
  position: absolute;
  translate: -50% 0;
  padding: 0.3em 0.9em;
  border: 1px solid var(--ci-edge);
  border-radius: 999px;
  background: rgb(0 0 0 / 0.5);
  color: #fff;
  font-family: var(--sans);
  font-size: clamp(12px, 2.2vmin, 20px);
  font-weight: 600;
  white-space: nowrap;
}

.ci-sprite {
  position: absolute;
  translate: -50% -50%;
}

.ci-streak {
  border-radius: 999px;
  background: linear-gradient(90deg, transparent, var(--c) 70%, #fff);
  box-shadow: 0 0 0.8vmin var(--c);
}

.ci-petal {
  border-radius: 80% 0;
  background: radial-gradient(ellipse at 30% 30%, rgb(255 255 255 / 0.6), var(--c) 60%);
}

.ci-spark {
  border-radius: 50%;
  background: radial-gradient(circle, #fff 20%, var(--c) 55%, transparent 72%);
  box-shadow: 0 0 1vmin var(--c);
}

.ci-ring {
  border: 0.5vmin solid var(--c);
  border-radius: 50%;
  box-shadow:
    0 0 2vmin var(--c),
    inset 0 0 2vmin var(--c);
}

.ci-flash {
  translate: none;
  background: radial-gradient(ellipse at 60% 40%, #fff 0%, var(--c) 45%, transparent 80%);
  mix-blend-mode: screen;
}
