:root {
  color-scheme: dark;
  font-family: "Instrument Sans", "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  color: #fbf1d8;
  background: #10241f;
  --muted: #b8d3c5;
  --gold: #f4cc80;
  --felt: #184b3c;
  --line: #639080;
}
* { box-sizing: border-box; }
body { margin: 0; }
[hidden] { display: none !important; }
a { color: inherit; text-decoration: none; }
button { font: inherit; cursor: pointer; }
button:disabled { cursor: default; }
:focus-visible { outline: 2px solid #fff0b1; outline-offset: 3px; }
header { background: #132d26; border-bottom: 1px solid #31574b; }
.page { width: min(1100px, 100%); margin-inline: auto; padding-inline: clamp(8px, 2vw, 24px); }
.top { position: relative; min-height: 50px; display: flex; align-items: center; justify-content: center; }
.top > a { position: absolute; inset-inline-start: clamp(8px, 2vw, 24px); color: var(--muted); font-size: 13px; font-weight: 650; }
.top > a::before { content: '‹'; margin-inline-end: 5px; }
.game-title, .brand { display: flex; align-items: center; gap: 7px; }
.brand { font-weight: 700; font-size: 13px; }
h1 { margin: 0; border-inline-start: 1px solid var(--line); padding-inline-start: 8px; font-size: clamp(18px, 2.5vw, 27px); }

.table {
  margin-top: 12px;
  border: 1px solid #9b754b;
  border-radius: 22px;
  background: #16352d;
  padding: 8px;
  box-shadow: 0 8px 25px #090f0c73;
}
.felt {
  display: grid;
  min-height: 350px;
  padding: 8px;
  border: 1px solid #729487;
  border-radius: 16px;
  background: radial-gradient(ellipse at 50% 42%, #236451, var(--felt) 74%);
  grid-template-columns: 1fr 1.38fr 1fr;
  grid-template-rows: minmax(116px, auto) minmax(124px, auto) minmax(76px, auto);
  gap: 5px;
}
.seats { display: contents; }
.seat {
  min-width: 0;
  padding: 4px 6px;
  border: 1px solid transparent;
  border-radius: 9px;
  text-align: center;
}
.seat[data-active] { border-color: var(--gold); background: #113f33; }
.seat-0 { grid-area: 3 / 2; }
.seat-1 { grid-area: 2 / 3; }
.seat-2 { grid-area: 1 / 2; }
.seat-3 { grid-area: 2 / 1; }
.seat-heading {
  display: flex;
  justify-content: center;
  align-items: center;
  flex-wrap: wrap;
  gap: 2px 6px;
  min-height: 22px;
  line-height: 1.15;
  font-size: 13px;
}
.wind {
  padding: 2px 5px;
  border: 1px solid #82a69a;
  border-radius: 4px;
  color: #ecf4eb;
  font-size: 10px;
}
.seat-kind { color: var(--muted); font-size: 10px; }
.seat-backs, .melds, .river {
  display: flex;
  justify-content: center;
  gap: 2px;
  flex-wrap: wrap;
}
.seat-backs { margin: 3px auto 4px; }
.seat-0 .seat-backs { display: none; }
.seat-backs .tile { width: clamp(4px, 1.6vw, 14px); height: clamp(12px, 2vw, 23px); }
.river { max-width: 196px; max-height: 71px; overflow: auto; margin: 3px auto 0; padding: 2px; }
.river .tile { width: clamp(12px, 2.8vw, 24px); height: auto; aspect-ratio: 30 / 41; }
.melds:not(:empty) { margin: 3px auto; }
.meld {
  display: inline-flex;
  align-items: center;
  gap: 1px;
  padding: 2px;
  border-radius: 4px;
  background: #133b30;
}
.meld-label { padding-inline: 2px; color: #e5d39b; font-size: 10px; }
.meld .tile { width: 16px; height: 22px; }
.center {
  grid-area: 2 / 2;
  align-self: center;
  min-width: 0;
  text-align: center;
  pointer-events: none;
}
.wall { color: #d0e5d8; font-size: 12px; font-weight: 650; }
.last-action {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 5px;
  min-height: 48px;
  color: #fff3d2;
  font-size: clamp(12px, 2vw, 16px);
  font-weight: 650;
}
.last-action .tile { width: 26px; height: 36px; }
.player-panel { padding: 7px 2px 0; text-align: center; }
.player-heading { margin-bottom: 6px; color: var(--muted); font-size: 12px; font-weight: 650; }
.hand { display: flex; flex-wrap: wrap; justify-content: center; gap: 4px; margin-inline: auto; }
.tile {
  display: inline-grid;
  place-items: center;
  flex: none;
  width: 34px;
  height: 46px;
  padding: 1px;
  border: 1px solid #bdac86;
  border-bottom: 3px solid #9e8d64;
  border-radius: 5px;
  background: #fff6de;
  color: #172c27;
}
.tile svg { display: block; width: 100%; height: 100%; overflow: visible; }
.tile svg text { text-anchor: middle; font: 700 14px "Songti SC", "Noto Serif CJK SC", serif; }
.tile svg .tile-mark { font-size: 13px; }
.tile svg .tile-honor { font-size: 22px; }
.tile .red { fill: #a52828; }
.tile .blue { fill: #254266; }
.tile .green { fill: #0c6246; }
.tile .pip-inlay { fill: #fff6de; opacity: .62; }
.tile .bamboo { fill: none; stroke: #106a4d; stroke-width: 1.8; stroke-linecap: round; }
.tile .bamboo.red { stroke: #b5382d; }
.tile .white-dragon { fill: none; stroke: #345c84; stroke-width: 2.7; }
.tile-back { background: repeating-linear-gradient(130deg,#0d4537 0 4px,#1f6151 4px 7px); border-color: #7cb4a0; }
.tile[data-latest], .hand .tile[aria-pressed=true] { outline: 2px solid var(--gold); outline-offset: 1px; }
.hand .tile { width: clamp(28px, 5vw, 46px); height: clamp(41px, 6.5vw, 62px); touch-action: manipulation; }
.hand .tile[aria-pressed=true] { translate: 0 -3px; background: #ffe9ad; }
.hand .tile[data-drawn] { margin-inline-start: 5px; }
.status { min-height: 18px; margin: 6px 0 3px; font-size: 13px; font-weight: 650; }
.actions { display: flex; min-height: 46px; justify-content: center; flex-wrap: wrap; gap: 4px 6px; }
.actions button, .result button {
  min-width: 52px;
  min-height: 44px;
  padding: 2px 12px;
  color: #fff3d5;
  border: 1px solid #8ab5a2;
  border-radius: 7px;
  background: #244d3e;
  font-size: 13px;
  font-weight: 750;
  touch-action: manipulation;
}
.actions .primary, .result .primary { color: #242018; background: var(--gold); border-color: var(--gold); }
.actions button:disabled { opacity: .54; }
.result { margin-top: 9px; padding: 10px; border: 1px solid #8e7958; border-radius: 11px; text-align: center; }
.result h2, .result p { margin: 4px 0; }
.result-score { color: var(--muted); }
.result-tiles { display: flex; flex-wrap: wrap; justify-content: center; gap: 3px; margin: 8px 0; }
.result-tiles .tile { width: 23px; height: 32px; }
.rules-guide { margin: 7px 0 16px; color: var(--muted); font-size: 13px; }
.rules-guide summary { display: list-item; cursor: pointer; width: fit-content; min-height: 44px; padding: 12px 10px 12px 0; box-sizing: border-box; font-weight: 650; }
.rules-guide li { margin: 0 0 6px; max-width: 75ch; }

@media (max-width: 480px) {
  .top { justify-content: flex-end; }
  .table { margin-top: 8px; padding: 5px; }
  .felt { min-height: 299px; padding: 3px; }
  .felt { grid-template-rows: minmax(96px, auto) minmax(124px, auto) minmax(66px, auto); gap: 2px; }
  .seat { padding: 3px 2px; }
  .seat-heading { font-size: 12px; }
  .hand { max-width: 290px; }
  .hand .tile { width: 34px; }
}
@media (orientation: landscape) and (max-height: 480px) {
  .top { min-height: 37px; }
  h1 { font-size: 18px; }
  .table { margin-top: 5px; padding: 5px; }
  .felt { min-height: 0; padding: 2px; }
  .felt { grid-template-rows: 58px 74px 44px; gap: 2px; }
  .seat { display: flex; flex-direction: column; padding: 1px 3px; }
  .seat-heading, .seat-backs { flex: none; }
  .seat-tiles { min-height: 0; overflow-y: auto; scrollbar-width: thin; }
  .seat-heading { min-height: 18px; font-size: 12px; }
  .seat-backs { margin: 1px auto 2px; }
  .seat-backs .tile { height: 10px; }
  .river { max-width: 180px; max-height: 34px; margin-top: 2px; }
  .river .tile { width: 13px; }
  .melds:not(:empty) { margin: 1px auto; }
  .seat-0 .river { max-height: 23px; }
  .meld .tile { width: 12px; height: 16px; }
  .player-heading { margin-bottom: 3px; }
  .hand .tile { width: 30px; height: 41px; }
  .player-panel { padding-top: 4px; }
  .status { margin-top: 4px; }
}

body.integrated-flow { --room-ink:#fff4db; --room-soft:#d4e4d9; --gold:#e9c47b; }
.tile-index { text-anchor:end; fill:#182a22; font:bold 8px system-ui,sans-serif; paint-order:stroke; stroke:#fff4d5; stroke-width:1.5; }
.flow-score .mini-cards { display:flex; flex-wrap:wrap; gap:3px; }
[data-dealing] #last-action { visibility:hidden; }

@media (orientation: landscape) and (max-height:480px) {
  .felt { grid-template-rows:55px 68px 41px; }
  .river .tile { width:15px; }
  .river .tile[data-latest] { outline-offset:0; }
  .seat-tiles { padding-inline:2px; display:flex; flex-wrap:wrap; justify-content:center; align-items:start; }
  .seat-tiles .river { margin-inline:0; }
  .seat-tiles .melds:empty, .seat-tiles .river:empty { display:none; }
  .seat-tiles:has(.meld) .river { max-width:58%; }
  .seat-backs .tile { border-bottom-width:1px; }
  .seat-0 .river { max-height:24px; }
}

/* Character avatars and a clear turn badge on the seat that acts. */
.seat-heading .lp-avatar { flex: none; width: 24px; height: 24px; border-radius: 50%; border: 2px solid #f4e7c4; overflow: hidden; box-shadow: 0 1px 3px #0005; }
.seat-heading .lp-avatar svg { display: block; width: 100%; height: 100%; }
.seat[data-active] .seat-heading .lp-avatar { border-color: var(--gold); }
.seat-turn { padding: 1px 7px; border-radius: 9px; background: var(--gold); color: #241c0e; font: 800 10px/16px system-ui, sans-serif; }
@media (max-width: 420px), (orientation: landscape) and (max-height: 480px) { .seat-heading .lp-avatar { width: 18px; height: 18px; border-width: 1px; } }
