/* Tiga Mahjong — responsive table, tiles and dialogs */

:root {
  --bg: #061715;
  --bg-2: #0a2420;
  --bg-3: #0e302a;
  --panel: rgba(11, 36, 32, 0.82);
  --panel-2: rgba(16, 47, 41, 0.9);
  --line: rgba(146, 216, 190, 0.17);
  --line-strong: rgba(146, 216, 190, 0.32);
  --text: #eaf5ef;
  --muted: #9dbab0;
  --faint: #6f8d83;
  --jade: #5ed0ab;
  --jade-deep: #1c8b70;
  --gold: #e6c37c;
  --gold-deep: #b8934e;
  --red: #e5756a;
  --blue: #8bb8e8;
  --tile: #f7f1df;
  --tile-2: #e8ddc1;
  --tile-edge: #c9ba98;
  --tile-ink: #1d2a26;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.35);
  --radius: 18px;
  --serif: "Noto Serif SC", "Songti SC", "STSong", "SimSun", Georgia, serif;
  --sans: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: dark;
}

html[data-theme="light"] {
  --bg: #efe9da;
  --bg-2: #e6decb;
  --bg-3: #dcd2ba;
  --panel: rgba(255, 252, 243, 0.86);
  --panel-2: rgba(255, 253, 247, 0.95);
  --line: rgba(49, 86, 73, 0.16);
  --line-strong: rgba(49, 86, 73, 0.3);
  --text: #21302b;
  --muted: #61786f;
  --faint: #8a9c94;
  --jade: #147d66;
  --jade-deep: #0d5d4c;
  --gold: #a97b25;
  --gold-deep: #8a6218;
  --red: #b4453d;
  --blue: #3e6f9e;
  --tile: #fffdf6;
  --tile-2: #f0e8d4;
  --tile-edge: #cbbd9d;
  --tile-ink: #23302b;
  --shadow: 0 18px 44px rgba(55, 46, 28, 0.16);
  color-scheme: light;
}

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

/* Author display rules (for example `.btn`) must not defeat the hidden
   attribute used by install/update controls and the dealer badge. */
[hidden] {
  display: none !important;
}

html {
  min-height: 100%;
  background: var(--bg);
}

body {
  margin: 0;
  min-height: 100dvh;
  color: var(--text);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.45;
  background:
    radial-gradient(1100px 600px at 50% -10%, rgba(60, 160, 130, 0.25), transparent 60%),
    radial-gradient(900px 500px at 100% 100%, rgba(200, 160, 80, 0.1), transparent 55%),
    radial-gradient(700px 500px at 0% 80%, rgba(30, 120, 100, 0.15), transparent 60%),
    linear-gradient(180deg, var(--bg), var(--bg-2) 45%, var(--bg));
  background-attachment: fixed;
  overflow-x: hidden;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: 0.25;
  background-image: repeating-linear-gradient(45deg, transparent 0 22px, rgba(255, 255, 255, 0.012) 22px 23px);
  z-index: 0;
}

button,
select,
input {
  font: inherit;
}

button {
  -webkit-tap-highlight-color: transparent;
}

.app-shell {
  position: relative;
  z-index: 1;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

/* ------------------------------- top bar -------------------------------- */

.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  width: min(1240px, calc(100% - 28px));
  margin: 0 auto;
  padding: 18px 0 10px;
  flex-wrap: wrap;
}

.brand {
  display: flex;
  align-items: center;
  gap: 11px;
  margin-right: auto;
}

.brand-tile {
  width: 42px;
  height: 60px;
  border-radius: 7px;
  display: grid;
  place-items: center;
  color: #7e2e2a;
  background:
    radial-gradient(circle at 30% 18%, rgba(255, 255, 255, 0.9), transparent 55%),
    linear-gradient(160deg, #fffaf0, #e7dcc3);
  border: 1px solid var(--tile-edge);
  box-shadow: 0 3px 0 #b7a988, 0 7px 14px rgba(0, 0, 0, 0.28);
  font-family: var(--serif);
  font-size: 23px;
  font-weight: 700;
}

.brand-copy {
  display: flex;
  flex-direction: column;
  line-height: 1.15;
}

.brand-copy strong {
  font-size: 18px;
  letter-spacing: 0.01em;
}

.brand-copy small {
  color: var(--muted);
  font-size: 11.5px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.meta-row {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  align-items: center;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px 10px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.035);
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}

.win-chip {
  color: var(--gold);
  border-color: rgba(230, 195, 124, 0.28);
}

.offline-chip {
  color: var(--red);
  border-color: rgba(229, 117, 106, 0.35);
}

.offline-chip::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
}

.top-actions {
  display: flex;
  gap: 6px;
}

.btn {
  appearance: none;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.045);
  color: var(--text);
  padding: 9px 14px;
  border-radius: 999px;
  font-weight: 650;
  font-size: 13px;
  cursor: pointer;
  transition: transform 0.14s ease, background 0.14s ease, border-color 0.14s ease, opacity 0.14s ease;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  white-space: nowrap;
  min-height: 40px;
}

.btn:hover:not(:disabled) {
  transform: translateY(-1px);
  border-color: var(--line-strong);
  background: rgba(255, 255, 255, 0.08);
}

.btn:active:not(:disabled) {
  transform: translateY(0);
}

.btn:disabled {
  opacity: 0.42;
  cursor: not-allowed;
}

.btn.primary {
  background: linear-gradient(180deg, #f0d397, #d3aa5b);
  border-color: #f2dda9;
  color: #1c261f;
  box-shadow: 0 5px 16px rgba(200, 160, 80, 0.25);
}

.btn.primary:hover:not(:disabled) {
  background: linear-gradient(180deg, #f7e0ae, #ddb56a);
}

.btn.ghost {
  background: rgba(255, 255, 255, 0.035);
}

.btn.danger {
  color: #ffb9b2;
  border-color: rgba(229, 117, 106, 0.35);
}

.btn.small {
  min-height: 34px;
  padding: 6px 11px;
  font-size: 12px;
}

.btn.win {
  background: linear-gradient(180deg, #7ce3bf, #36a987);
  border-color: #9df0d4;
  color: #06231c;
  box-shadow: 0 0 24px rgba(94, 208, 171, 0.3);
}

.icon-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  display: grid;
  place-items: center;
}

.icon-btn:hover {
  border-color: var(--line-strong);
}

.live-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--faint);
  transition: background 0.2s ease, box-shadow 0.2s ease;
}

.live-dot.on {
  background: var(--jade);
  box-shadow: 0 0 0 4px rgba(94, 208, 171, 0.12);
  animation: pulse 1.8s ease-in-out infinite;
}

/* -------------------------------- board --------------------------------- */

.board {
  display: grid;
  grid-template-columns: minmax(190px, 1fr) minmax(310px, 1.28fr) minmax(190px, 1fr);
  grid-template-areas:
    "left center right"
    "self self self";
  gap: 14px;
  width: min(1240px, calc(100% - 28px));
  margin: 0 auto;
  padding: 4px 0 20px;
  flex: 1;
}

.seat {
  border: 1px solid var(--line);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.035), transparent 60%),
    var(--panel);
  border-radius: var(--radius);
  padding: 12px;
  box-shadow: var(--shadow);
  min-width: 0;
  transition: border-color 0.25s ease, box-shadow 0.25s ease;
  backdrop-filter: blur(12px);
}

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

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

.seat.is-turn {
  border-color: rgba(94, 208, 171, 0.55);
  box-shadow: 0 0 0 1px rgba(94, 208, 171, 0.18), 0 0 34px rgba(94, 208, 171, 0.13), var(--shadow);
}

.seat-head,
.self-topline {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 9px;
}

.seat-id {
  display: flex;
  align-items: center;
  gap: 7px;
  min-width: 0;
}

.wind-badge {
  width: 26px;
  height: 26px;
  flex: 0 0 26px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--line);
  color: var(--gold);
  font-family: var(--serif);
  font-size: 13px;
  font-weight: 700;
}

.seat-name {
  font-weight: 700;
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.dealer-star {
  font-size: 10px;
  font-weight: 700;
  color: var(--gold);
  border: 1px solid rgba(230, 195, 124, 0.3);
  padding: 2px 6px;
  border-radius: 999px;
  white-space: nowrap;
}

.score {
  font-variant-numeric: tabular-nums;
  font-weight: 800;
  color: var(--text);
  font-size: 14px;
}

.score.big {
  font-size: 24px;
  color: var(--gold);
  line-height: 1;
}

.self-scoreline {
  display: flex;
  align-items: baseline;
  gap: 6px;
}

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

.small {
  font-size: 11.5px;
}

/* hand backs, melds, bonuses, rivers */

.handbacks {
  display: flex;
  flex-wrap: wrap;
  gap: 2px;
  min-height: 24px;
  margin-bottom: 8px;
}

.handbacks.revealed .tile.mini {
  --tw: 20px;
}

.back {
  width: 13px;
  height: 18px;
  border-radius: 3px;
  border: 1px solid rgba(230, 195, 124, 0.45);
  background:
    repeating-linear-gradient(45deg, rgba(255, 255, 255, 0.08) 0 1px, transparent 1px 4px),
    linear-gradient(145deg, #177363, #0c443c 60%, #0f5449);
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.32);
}

.meld-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: flex-end;
  min-height: 0;
}

.meld {
  display: flex;
  gap: 2px;
  padding: 3px 4px;
  border-radius: 7px;
  border: 1px solid var(--line);
  background: rgba(0, 0, 0, 0.12);
  position: relative;
}

.meld-label {
  position: absolute;
  top: -7px;
  left: 5px;
  font-size: 8.5px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--faint);
  background: var(--panel);
  padding: 0 3px;
  border-radius: 3px;
}

.bonus-row {
  display: flex;
  flex-wrap: wrap;
  gap: 3px;
  margin-top: 7px;
  min-height: 0;
}

.bonus-chip {
  width: 22px;
  height: 27px;
  border-radius: 4px;
  display: grid;
  place-items: center;
  font-family: var(--serif);
  font-size: 13px;
  font-weight: 700;
  border: 1px solid rgba(255, 255, 255, 0.18);
  color: #3e2c12;
  background: linear-gradient(160deg, #fbf2d8, #e4d3a9);
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.25);
}

.bonus-chip.seasons {
  background: linear-gradient(160deg, #e7f6ea, #c6e4cf);
}

.bonus-chip.faces {
  background: linear-gradient(160deg, #f7e4e1, #e4c1bb);
}

.bonus-chip.animals {
  background: linear-gradient(160deg, #e8eef8, #c9d8ec);
}

.river {
  display: flex;
  flex-wrap: wrap;
  gap: 2px;
  margin-top: 9px;
  padding-top: 8px;
  border-top: 1px dashed var(--line);
  min-height: 30px;
  align-content: flex-start;
}

.river .tile.mini {
  opacity: 0.88;
}

.river .tile.mini.last {
  opacity: 1;
  box-shadow: 0 0 0 2px var(--gold), 0 0 16px rgba(230, 195, 124, 0.35);
  transform: translateY(-2px);
}

/* -------------------------------- center -------------------------------- */

.center {
  grid-area: center;
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 0;
}

.center-table {
  position: relative;
  min-height: 214px;
  border-radius: 26px;
  border: 1px solid var(--line);
  background:
    radial-gradient(circle at 50% 45%, rgba(94, 208, 171, 0.12), transparent 46%),
    radial-gradient(circle at 50% 50%, rgba(0, 0, 0, 0.05), transparent 60%),
    linear-gradient(155deg, rgba(255, 255, 255, 0.04), transparent 45%),
    var(--panel);
  box-shadow: var(--shadow), inset 0 0 0 8px rgba(0, 0, 0, 0.08);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 18px;
  overflow: hidden;
}

.center-table::before {
  content: "";
  position: absolute;
  inset: 12px;
  border-radius: 20px;
  border: 1px solid rgba(230, 195, 124, 0.08);
  pointer-events: none;
}

.wall-visual {
  position: absolute;
  top: 16px;
  left: 16px;
  display: grid;
  grid-template-columns: repeat(3, 12px);
  gap: 3px;
  opacity: 0.6;
}

.wall-visual .wb {
  width: 12px;
  height: 16px;
  border-radius: 2px;
  border: 1px solid rgba(230, 195, 124, 0.45);
  background: linear-gradient(145deg, #177363, #0c443c);
}

.wall-count {
  position: absolute;
  top: 14px;
  right: 16px;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  line-height: 1;
}

.wall-count strong {
  font-size: 24px;
  font-variant-numeric: tabular-nums;
  color: var(--text);
}

.wall-count span {
  font-size: 9.5px;
  letter-spacing: 0.13em;
  text-transform: uppercase;
  color: var(--faint);
  margin-top: 4px;
}

.last-discard-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 7px;
  z-index: 1;
}

.eyebrow {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--faint);
}

.last-discard {
  min-height: 68px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.last-discard .tile {
  --tw: 48px;
  animation: tileIn 0.22s ease both;
}

.round-line {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 7px;
  color: var(--muted);
  font-size: 11.5px;
  letter-spacing: 0.04em;
}

.dot-sep {
  color: var(--faint);
}

.turn-banner {
  text-align: center;
  font-weight: 700;
  font-size: 14px;
  color: var(--text);
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.04);
  border-radius: 999px;
  padding: 7px 14px;
  min-height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  transition: border-color 0.2s ease, background 0.2s ease;
}

.turn-banner.you {
  border-color: rgba(94, 208, 171, 0.5);
  background: rgba(94, 208, 171, 0.09);
  color: #baf5e2;
  box-shadow: 0 0 24px rgba(94, 208, 171, 0.1);
}

html[data-theme="light"] .turn-banner.you {
  color: #0d5d4c;
}

.turn-banner.win {
  border-color: rgba(230, 195, 124, 0.55);
  background: rgba(230, 195, 124, 0.1);
  color: var(--gold);
}

.log {
  font-size: 11.5px;
  color: var(--muted);
  min-height: 48px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 0 6px;
}

.log-entry {
  display: flex;
  gap: 6px;
  align-items: baseline;
  animation: fadeIn 0.25s ease both;
}

.log-entry .who {
  color: var(--text);
  font-weight: 650;
  white-space: nowrap;
}

.log-entry .what {
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.log-entry.win .what,
.log-entry.win .who {
  color: var(--gold);
}

/* --------------------------------- self --------------------------------- */

.self {
  grid-area: self;
  border: 1px solid var(--line);
  border-radius: 22px;
  padding: 12px 14px 10px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.045), transparent 50%),
    var(--panel-2);
  box-shadow: var(--shadow);
  min-width: 0;
  transition: border-color 0.25s ease, box-shadow 0.25s ease;
}

.self.is-turn {
  border-color: rgba(94, 208, 171, 0.5);
  box-shadow: 0 0 0 1px rgba(94, 208, 171, 0.14), 0 0 38px rgba(94, 208, 171, 0.1), var(--shadow);
}

.self-topline {
  margin-bottom: 7px;
}

.self-melds-row {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 10px;
  min-height: 0;
}

.self-melds-row .bonus-row {
  margin-top: 0;
}

.hand-wrap {
  margin: 8px 0 6px;
  overflow: visible;
}

.hand {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: center;
  gap: clamp(2px, 0.45vw, 6px);
  min-height: 78px;
  padding: 12px 2px 4px;
}

.action-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 40px;
  padding-top: 2px;
}

.action-bar .spacer {
  flex: 1;
}

.hint {
  text-align: center;
  min-height: 18px;
  font-size: 11.5px;
  color: var(--faint);
  padding-top: 2px;
}

.self-river {
  margin-top: 4px;
  padding-top: 7px;
  min-height: 26px;
}

/* -------------------------------- tiles --------------------------------- */

.tile {
  --tw: clamp(38px, 4.7vw, 56px);
  width: var(--tw);
  height: calc(var(--tw) * 1.44);
  border-radius: calc(var(--tw) * 0.12);
  border: 1px solid var(--tile-edge);
  background:
    radial-gradient(circle at 30% 16%, rgba(255, 255, 255, 0.95), transparent 52%),
    linear-gradient(160deg, var(--tile), var(--tile-2));
  box-shadow:
    0 2px 0 var(--tile-edge),
    0 4px 0 rgba(0, 0, 0, 0.16),
    0 8px 14px rgba(0, 0, 0, 0.24);
  color: var(--tile-ink);
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  padding: calc(var(--tw) * 0.08);
  flex: 0 0 auto;
  cursor: pointer;
  transform-origin: bottom center;
  transition: transform 0.15s ease, box-shadow 0.15s ease, filter 0.15s ease;
  user-select: none;
  -webkit-user-select: none;
}

.tile:hover:not(:disabled) {
  transform: translateY(-4px);
  box-shadow:
    0 2px 0 var(--tile-edge),
    0 6px 0 rgba(0, 0, 0, 0.16),
    0 12px 20px rgba(0, 0, 0, 0.3);
}

.tile.selected {
  transform: translateY(-12px);
  box-shadow:
    0 0 0 3px var(--jade),
    0 2px 0 var(--tile-edge),
    0 10px 0 rgba(0, 0, 0, 0.14),
    0 16px 24px rgba(0, 0, 0, 0.3);
  z-index: 3;
}

.tile:disabled {
  cursor: default;
}

.tile.mini {
  --tw: 26px;
  border-radius: 5px;
  box-shadow: 0 1px 0 var(--tile-edge), 0 2px 4px rgba(0, 0, 0, 0.16);
  padding: 2px;
  cursor: default;
}

.tile.mini:hover {
  transform: none;
}

.tile.back-tile {
  cursor: default;
  border-color: rgba(230, 195, 124, 0.45);
  background:
    repeating-linear-gradient(45deg, rgba(255, 255, 255, 0.08) 0 1px, transparent 1px 5px),
    linear-gradient(145deg, #177363, #0c443c 60%, #0f5449);
  box-shadow: 0 2px 0 #082f29, 0 4px 8px rgba(0, 0, 0, 0.24);
}

.tile.back-tile::after {
  content: "";
  width: 42%;
  height: 34%;
  border: 1px solid rgba(230, 195, 124, 0.55);
  border-radius: 2px;
  opacity: 0.7;
}

.tile-face {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}

.dots {
  position: relative;
  width: 94%;
  height: 88%;
}

.dots .d {
  position: absolute;
  aspect-ratio: 1;
  border-radius: 50%;
  opacity: 0;
  transform: translate(-50%, -50%) scale(0.55);
  transition: opacity 0.1s, transform 0.1s;
}

.dots .d.on {
  opacity: 1;
  transform: translate(-50%, -50%) scale(1);
  background:
    radial-gradient(circle at 50% 50%, rgba(255, 255, 255, 0.94) 0 18%, transparent 20%),
    radial-gradient(circle at 34% 28%, rgba(255, 255, 255, 0.5), transparent 48%),
    var(--dot-color, var(--tile-ink));
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.14), 0 1px 1px rgba(0, 0, 0, 0.16);
}

.dots .d.dot-green {
  --dot-color: #1c7a4b;
}

.dots .d.dot-red {
  --dot-color: #a83232;
}

.dots .d.dot-blue {
  --dot-color: #1d5f8c;
}

/* The one-circle tile is a large classic coin with concentric coloured rings. */
.dots .d.dot-coin.on {
  background:
    radial-gradient(
      circle at 50% 50%,
      #a83232 0 18%,
      var(--tile) 18% 25%,
      #1c7a4b 25% 43%,
      var(--tile) 43% 50%,
      #1d5f8c 50% 68%,
      var(--tile) 68% 74%,
      #a83232 74% 100%
    );
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.2), 0 1px 2px rgba(0, 0, 0, 0.2);
}

.glyph {
  font-family: var(--serif);
  font-size: calc(var(--tw) * 0.6);
  font-weight: 700;
  line-height: 1;
  letter-spacing: -0.02em;
}

.tile-wind .glyph {
  color: #175f50;
}

.tile-dragon .glyph {
  color: #a83232;
}

.tile-dragon.green .glyph {
  color: #1c7a4b;
}

.tile-dragon.white .glyph {
  color: #2c4f86;
  border: 2px solid currentColor;
  padding: 0.06em 0.12em 0.1em;
  font-size: calc(var(--tw) * 0.42);
}

.tile-fly .glyph {
  color: #9a6b16;
}

.tile-fly {
  border-color: #d9b466;
  background:
    radial-gradient(circle at 30% 16%, rgba(255, 255, 255, 0.95), transparent 52%),
    linear-gradient(160deg, #fff7df, #ecd9a8);
}

.tile-bonus .glyph {
  color: #5a3a18;
  font-size: calc(var(--tw) * 0.5);
}

.tile-bonus.seasons {
  background: linear-gradient(160deg, #f1fbf3, #cfe8d5);
}

.tile-bonus.faces {
  background: linear-gradient(160deg, #fff1ef, #ecd2cc);
}

.tile-bonus.animals {
  background: linear-gradient(160deg, #eff4fb, #d3e0f0);
}

.rank {
  position: absolute;
  right: calc(var(--tw) * 0.07);
  bottom: calc(var(--tw) * 0.03);
  font-size: calc(var(--tw) * 0.17);
  font-weight: 800;
  color: var(--tile-ink);
  opacity: 0.36;
}

.tile.mini .rank {
  font-size: 7px;
  right: 2px;
  bottom: 1px;
}

/* ------------------------------- footer --------------------------------- */

.foot {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px;
  color: var(--faint);
  font-size: 10.5px;
  letter-spacing: 0.03em;
  padding: 0 14px 16px;
  text-align: center;
}

.foot-sep {
  opacity: 0.5;
}

/* ------------------------------- dialogs -------------------------------- */

dialog.modal {
  border: 1px solid var(--line-strong);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.04), transparent 30%),
    var(--panel-2);
  color: var(--text);
  border-radius: 20px;
  padding: 0;
  width: min(680px, calc(100vw - 28px));
  max-height: min(90dvh, 860px);
  box-shadow: 0 30px 100px rgba(0, 0, 0, 0.55);
  overflow: hidden;
}

dialog.modal.wide {
  width: min(840px, calc(100vw - 28px));
}

dialog.modal::backdrop {
  background: rgba(2, 10, 8, 0.62);
  backdrop-filter: blur(7px);
}

dialog[open] {
  animation: modalIn 0.22s ease both;
}

.modal-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 18px 20px 12px;
  border-bottom: 1px solid var(--line);
}

.modal-head h2 {
  margin: 2px 0 0;
  font-size: 22px;
  letter-spacing: -0.01em;
}

.modal-body {
  padding: 16px 20px 20px;
  overflow-y: auto;
  max-height: calc(90dvh - 120px);
}

.modal-body p {
  margin: 0 0 10px;
  color: var(--muted);
}

.modal-body p.lead {
  color: var(--text);
  font-size: 14.5px;
  line-height: 1.55;
}

.modal-body h3 {
  margin: 18px 0 7px;
  font-size: 13px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--gold);
}

.modal-body h3:first-child {
  margin-top: 0;
}

.modal-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin-top: 16px;
}

.modal-actions .btn {
  min-height: 42px;
}

.result-actions {
  padding: 0 20px 20px;
  margin-top: 0;
}

.result-hand {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 4px;
  padding: 12px;
  margin: 12px 0 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(0, 0, 0, 0.16);
}

.result-hand .meld {
  display: flex;
  gap: 2px;
  padding-left: 9px;
  margin-left: 5px;
  border-left: 1px dashed var(--line-strong);
}

.result-patterns {
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
  margin-bottom: 4px;
}

.result-pattern {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 7px 11px;
  font-size: 12.5px;
  border-bottom: 1px solid var(--line);
}

.result-pattern:last-child {
  border-bottom: 0;
}

.result-pattern .fan {
  color: var(--gold);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.result-pattern.total {
  background: rgba(94, 208, 171, 0.08);
  font-weight: 800;
}

.result-payments {
  margin-top: 14px;
}

.payment-row {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 6px 0;
  border-bottom: 1px solid var(--line);
  font-size: 12.5px;
  color: var(--muted);
}

.payment-row:last-child {
  border-bottom: 0;
}

.payment-row .amount {
  color: var(--gold);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.result-scoreline {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin-top: 16px;
}

.result-score {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 9px 6px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.12);
  text-align: center;
}

.result-score strong {
  font-size: 18px;
  font-variant-numeric: tabular-nums;
}

.history-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: min(52vh, 480px);
  overflow-y: auto;
  margin-top: 14px;
  padding-right: 4px;
  overscroll-behavior: contain;
}

.history-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(0, 0, 0, 0.12);
}

.history-main {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.history-main strong {
  font-size: 13px;
}

.history-detail {
  font-size: 12px;
  color: var(--text);
  opacity: 0.9;
}

.history-patterns {
  font-size: 11px;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history-when {
  font-size: 10.5px;
  color: var(--faint);
}

.history-deltas {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 2px;
  font-size: 11.5px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.history-deltas .up {
  color: var(--jade);
}

.history-deltas .down {
  color: var(--red);
}

.history-empty {
  margin: 0;
  padding: 18px 4px;
  color: var(--muted);
  font-size: 13px;
}

@media (max-width: 560px) {
  .history-row {
    grid-template-columns: minmax(0, 1fr);
  }

  .history-deltas {
    flex-direction: row;
    flex-wrap: wrap;
    justify-content: flex-start;
    gap: 8px;
  }
}

@media (max-width: 560px) {
  .result-pattern {
    padding: 6px 9px;
  }

  .result-hand {
    padding: 9px;
  }
}


.fine {
  font-size: 11.5px !important;
  color: var(--faint) !important;
  line-height: 1.5;
}

kbd {
  font-family: var(--sans);
  font-size: 10.5px;
  font-weight: 700;
  border: 1px solid var(--line-strong);
  border-bottom-width: 2px;
  border-radius: 5px;
  padding: 1px 5px;
  background: rgba(255, 255, 255, 0.05);
  color: var(--text);
}

.welcome-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 9px;
  margin: 14px 0 4px;
}

.info-card {
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.028);
  border-radius: 13px;
  padding: 12px;
}

.info-card h3 {
  margin: 7px 0 5px;
  font-size: 12px;
  letter-spacing: 0.06em;
  color: var(--text);
}

.info-card p {
  font-size: 11.5px;
  line-height: 1.5;
  margin: 0 !important;
}

.card-icon {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 8px;
  background: rgba(230, 195, 124, 0.11);
  border: 1px solid rgba(230, 195, 124, 0.24);
  color: var(--gold);
  font-family: var(--serif);
  font-weight: 700;
  font-size: 15px;
}

.rules-body section {
  padding-bottom: 6px;
}

.score-table {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0;
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
}

.score-table .row {
  display: contents;
}

.score-table .label,
.score-table .value {
  padding: 7px 10px;
  border-bottom: 1px solid var(--line);
  font-size: 12px;
}

.score-table .label {
  color: var(--muted);
}

.score-table .value {
  color: var(--gold);
  font-weight: 750;
  text-align: right;
  white-space: nowrap;
}

.score-table .row:last-child .label,
.score-table .row:last-child .value {
  border-bottom: 0;
}

.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 13px 0;
  border-bottom: 1px solid var(--line);
}

.setting-row:last-of-type {
  border-bottom: 0;
}

.setting-row strong {
  font-size: 13.5px;
}

.setting-row p {
  margin: 2px 0 0 !important;
  font-size: 11.5px;
}

select {
  appearance: none;
  min-width: 132px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--panel);
  color: var(--text);
  padding: 9px 30px 9px 11px;
  cursor: pointer;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 15px) 17px, calc(100% - 10px) 17px;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
}

.switch {
  position: relative;
  width: 44px;
  height: 25px;
  flex: 0 0 44px;
  cursor: pointer;
}

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

.switch span {
  position: absolute;
  inset: 0;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid var(--line);
  transition: background 0.18s ease;
  pointer-events: none;
}

.switch span::after {
  content: "";
  position: absolute;
  width: 17px;
  height: 17px;
  left: 3px;
  top: 3px;
  border-radius: 50%;
  background: var(--muted);
  transition: transform 0.18s ease, background 0.18s ease;
}

.switch input:checked + span {
  background: rgba(94, 208, 171, 0.28);
  border-color: rgba(94, 208, 171, 0.5);
}

.switch input:checked + span::after {
  transform: translateX(19px);
  background: var(--jade);
}

.switch input:focus-visible + span {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
}

/* --------------------------------- AI ----------------------------------- */

.ai-status-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.03em;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.035);
  color: var(--muted);
}

.status-pill.training {
  color: #baf5e2;
  border-color: rgba(94, 208, 171, 0.4);
  background: rgba(94, 208, 171, 0.1);
}

.status-pill.training::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--jade);
  animation: pulse 1.5s ease-in-out infinite;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 12px;
}

.stat {
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.028);
  border-radius: 11px;
  padding: 9px 10px;
  min-width: 0;
}

.stat .k {
  display: block;
  font-size: 9.5px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--faint);
  margin-bottom: 4px;
}

.stat .v {
  font-size: 17px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  color: var(--text);
}

.chart-card {
  border: 1px solid var(--line);
  background: rgba(0, 0, 0, 0.1);
  border-radius: 13px;
  padding: 11px 12px 8px;
  margin-bottom: 9px;
}

.chart-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 4px;
}

.chart-head h3 {
  margin: 0;
  font-size: 11.5px;
  letter-spacing: 0.05em;
  text-transform: none;
  color: var(--text);
}

canvas {
  display: block;
  width: 100%;
  height: auto;
}

/* ------------------------------- animation ------------------------------- */

.fx-layer {
  position: fixed;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
  z-index: 60;
}

.fx-tile {
  position: absolute;
  margin: 0;
  pointer-events: none;
  transform-origin: center center;
  will-change: transform, opacity;
}

.fx-arriving .tile:last-child {
  opacity: 0;
}

/* -------------------------------- toast --------------------------------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: max(22px, env(safe-area-inset-bottom));
  transform: translate(-50%, 20px);
  opacity: 0;
  pointer-events: none;
  background: var(--panel-2);
  border: 1px solid var(--line-strong);
  color: var(--text);
  border-radius: 999px;
  padding: 9px 16px;
  font-size: 12px;
  font-weight: 600;
  box-shadow: var(--shadow);
  z-index: 50;
  transition: opacity 0.2s ease, transform 0.2s ease;
  max-width: calc(100vw - 32px);
  text-align: center;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

/* ------------------------------ responsive ------------------------------ */

@media (max-width: 980px) {
  .board {
    grid-template-columns: minmax(160px, 1fr) minmax(260px, 1.1fr) minmax(160px, 1fr);
    gap: 10px;
  }
  .tile {
    --tw: clamp(34px, 4.9vw, 48px);
  }
  .brand-copy small {
    display: none;
  }
}

@media (max-width: 820px) {
  .topbar {
    padding-top: 12px;
    gap: 9px;
  }
  .brand {
    width: auto;
  }
  .brand-copy strong {
    font-size: 16px;
  }
  .brand-tile {
    width: 34px;
    height: 49px;
    font-size: 19px;
  }
  .meta-row {
    order: 3;
    width: 100%;
    overflow-x: auto;
    padding-bottom: 2px;
    flex-wrap: nowrap;
    scrollbar-width: none;
  }
  .meta-row::-webkit-scrollbar {
    display: none;
  }
  .top-actions {
    margin-left: auto;
  }
  .top-actions .btn {
    padding: 8px 10px;
    font-size: 12px;
  }
  .board {
    grid-template-columns: 1fr 1fr;
    grid-template-areas:
      "left right"
      "center center"
      "self self";
    gap: 8px;
  }
  .seat {
    padding: 10px;
    border-radius: 15px;
  }
  .seat-left .handbacks,
  .seat-right .handbacks {
    max-height: 40px;
    overflow: hidden;
  }
  .seat-left .river,
  .seat-right .river {
    max-height: 96px;
    overflow-y: auto;
    scrollbar-width: thin;
  }
  .center-table {
    min-height: 178px;
    border-radius: 20px;
    padding: 14px;
  }
  .wall-count strong {
    font-size: 20px;
  }
  .last-discard .tile {
    --tw: 42px;
  }
  .turn-banner {
    font-size: 13px;
    padding: 6px 12px;
  }
  .log {
    min-height: 38px;
    max-height: 44px;
    overflow: hidden;
  }
  .self {
    position: sticky;
    bottom: 0;
    z-index: 12;
    border-radius: 18px;
    backdrop-filter: blur(18px);
    padding-bottom: max(8px, env(safe-area-inset-bottom));
  }
  .hand {
    min-height: 66px;
    padding-top: 10px;
  }
  .tile {
    --tw: clamp(33px, 7.8vw, 46px);
  }
  .foot {
    padding-bottom: 10px;
  }
  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
  }
  .welcome-grid {
    grid-template-columns: 1fr;
  }
  dialog.modal {
    width: calc(100vw - 16px);
    max-height: 92dvh;
  }
  .modal-body {
    max-height: calc(92dvh - 110px);
  }
}

@media (max-width: 520px) {
  .topbar,
  .board {
    width: calc(100% - 16px);
  }
  .brand-copy strong {
    font-size: 15px;
  }
  .top-actions {
    gap: 4px;
  }
  .top-actions .btn {
    padding: 7px 9px;
    font-size: 11.5px;
  }
  .chip {
    font-size: 10.5px;
    padding: 4px 8px;
  }
  .seat-name {
    font-size: 12.5px;
  }
  .score {
    font-size: 12.5px;
  }
  .score.big {
    font-size: 20px;
  }
  .wind-badge {
    width: 22px;
    height: 22px;
    flex-basis: 22px;
    font-size: 11px;
  }
  .dealer-star {
    display: none;
  }
  .tile {
    --tw: clamp(31px, 8.6vw, 40px);
  }
  .tile.mini {
    --tw: 23px;
  }
  .meld .tile.mini {
    --tw: 21px;
  }
  .bonus-chip {
    width: 19px;
    height: 24px;
    font-size: 11px;
  }
  .center-table {
    min-height: 158px;
  }
  .wall-visual {
    display: none;
  }
  .last-discard .tile {
    --tw: 38px;
  }
  .turn-banner {
    font-size: 12px;
  }
  .action-bar {
    gap: 5px;
  }
  .action-bar .btn {
    padding: 7px 10px;
    font-size: 12px;
    min-height: 36px;
  }
  .modal-head {
    padding: 14px 15px 10px;
  }
  .modal-body {
    padding: 13px 15px 16px;
  }
  .modal-head h2 {
    font-size: 19px;
  }
  .setting-row {
    gap: 8px;
  }
  select {
    min-width: 112px;
    padding-right: 24px;
  }
  .stat .v {
    font-size: 15px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

html[data-animations="off"] *,
html[data-animations="off"] *::before,
html[data-animations="off"] *::after {
  animation-duration: 0.01ms !important;
  animation-iteration-count: 1 !important;
  transition-duration: 0.01ms !important;
}

/* ------------------------------- keyframes ------------------------------ */

@keyframes pulse {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.45;
  }
}

@keyframes tileIn {
  from {
    opacity: 0;
    transform: translateY(10px) scale(0.88);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

@keyframes modalIn {
  from {
    opacity: 0;
    transform: translateY(8px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}
