:root {
  color-scheme: light;
  --paper: #f5f2e9;
  --surface: #fffcf4;
  --ink: #242b24;
  --muted: #5d685d;
  --line: #dcd7c8;
  --jade: #25483a;
  --jade-dark: #193429;
  --brass: #d8c48c;
  --danger: #983f32;
  --ok: #326447;
  --serif: "Songti SC", "Noto Serif CJK SC", "STSong", Georgia, serif;
  --sans: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif;
  --tile-width: clamp(20px, 5.4vw, 48px);
  --river-width: clamp(15px, 2.6vw, 26px);
}
* { box-sizing: border-box; }
body {
  margin: 0;
  background: radial-gradient(ellipse at 50% 12%, #fbf8ef, transparent 58%), var(--paper);
  color: var(--ink);
  font: 14px/1.45 var(--sans);
  -webkit-tap-highlight-color: transparent;
}
button, select, input, textarea { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: default; }
:focus-visible { outline: 2px solid #90642e; outline-offset: 3px; }

.hud {
  max-width: 1328px;
  min-height: 88px;
  margin: auto;
  padding: 16px clamp(16px, 4vw, 54px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  border-bottom: 1px solid var(--line);
}
.brand, .hud-right { display: flex; align-items: center; gap: 12px; min-width: 0; }
.logo {
  display: grid;
  place-items: center;
  width: 43px;
  height: 43px;
  flex: 0 0 auto;
  border-radius: 10px 10px 10px 3px;
  outline: 1px solid #c48774;
  outline-offset: -4px;
  background: #864835;
  color: #fff5de;
  font: 600 25px var(--serif);
}
.brand h1 { margin: 0; font: 700 29px/1.07 var(--serif); letter-spacing: .12em; }
.brand p { margin: 4px 0 0; font-size: 11px; color: var(--muted); white-space: nowrap; }
.hbtn, .abtn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  white-space: nowrap;
  padding: 7px 15px;
  border: 1px solid #d4cebd;
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  font-weight: 650;
  transition: background .15s, border-color .15s, color .15s;
}
.hbtn:hover, .abtn.ghost:hover { background: #eee8d7; border-color: #ad9a72; }
.hbtn.primary, .abtn { background: var(--jade); color: #fffaf0; border-color: var(--jade); }
.hbtn.primary:hover, .abtn:not(.ghost):hover { background: #315947; }
.abtn.ghost { background: var(--surface); color: var(--jade-dark); border-color: #d4cebd; }
.abtn.win, .abtn.win:hover { background: #884939; border-color: #884939; }
.hbtn:disabled, .abtn:disabled { opacity: .48; }

.game { max-width: 1248px; margin: auto; padding: 24px clamp(16px, 3vw, 38px) 30px; }
.stage {
  display: grid;
  grid-template-columns: minmax(122px, 176px) minmax(0, 1fr) minmax(122px, 176px);
  grid-template-areas: ". north ." "west table east" ". dialogue .";
  gap: 13px clamp(12px, 2.1vw, 27px);
  align-items: center;
}
.opponent { min-width: 0; }
.opponent-card {
  position: relative;
  min-width: 0;
  overflow: hidden;
  border: 1px solid #ded6c4;
  border-radius: 14px;
  background: var(--surface);
  box-shadow: 0 5px 15px #443b2310;
}
.opponent-card.active {
  border-color: #5c8069;
  box-shadow: 0 0 0 2px #5c806933, 0 8px 20px #2f4c381a;
}
.opponent-west { grid-area: west; }
.opponent-east { grid-area: east; }
.opponent-north { grid-area: north; justify-self: center; width: min(100%, 300px); }
.opponent-art {
  display: block;
  width: 100%;
  aspect-ratio: 4 / 5;
  object-fit: cover;
  object-position: center 40%;
  background: #ded7c5;
}
.opponent-info { padding: 10px 12px 11px; }
.seat-title { display: flex; justify-content: space-between; align-items: center; gap: 5px; }
.seat-name { font: 700 22px/1.13 var(--serif); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.wind {
  border: 1px solid #dcd3bd;
  border-radius: 5px;
  padding: 2px 6px;
  font-size: 11px;
  color: #5e553d;
}
.active .wind { color: #fff9e9; border-color: var(--jade); background: var(--jade); }
.seat-role { margin-top: 3px; font-size: 11px; color: var(--muted); }
.seat-meta { display: flex; justify-content: space-between; gap: 6px; margin-top: 9px; font-size: 11px; color: var(--muted); }
.seat-melds { overflow-wrap: anywhere; }
.seat-melds:empty { display: none; }
.seat-melds, .my-melds { display: flex; align-items: center; justify-content: flex-start; flex-wrap: wrap; gap: 4px; }
.meld-group { display: inline-flex; align-items: center; gap: 1px; }
.meld-group img, .meld-back { display: block; width: 12px; height: 16px; border-radius: 2px; }
.meld-back { background: linear-gradient(#6a9478, #345644); border: 1px solid #42634d; box-shadow: inset 0 0 0 1px #ffffff30; }
.my-melds .meld-group img, .my-melds .meld-back { width: 17px; height: 23px; }
.seat-score { font-weight: 700; color: var(--ok); white-space: nowrap; }
.seat-score.negative { color: var(--danger); }
.opponent-north .opponent-card { display: flex; align-items: stretch; }
.opponent-north .opponent-art { width: 69px; aspect-ratio: 1; flex: none; }
.opponent-north .opponent-info { flex: 1; min-width: 0; padding: 8px 11px; }
.opponent-north .seat-name { font-size: 18px; }
.opponent-north .seat-meta { margin-top: 4px; }
.opponent-north .seat-role { margin-top: 1px; }

.table {
  grid-area: table;
  position: relative;
  isolation: isolate;
  height: clamp(334px, 46vh, 490px);
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  grid-template-rows: minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: center;
  padding: 18px;
  overflow: hidden;
  border: 7px solid #243a2e;
  border-radius: 25px;
  background:
    radial-gradient(ellipse at 50% 42%, #35664f 0%, #264d3c 76%),
    #284c3b;
  box-shadow: 0 0 0 1px #98875f, 0 17px 27px #372b191b;
}
.table::before, .table::after {
  position: absolute;
  z-index: -1;
  inset: 5px;
  border: 1px solid #e1c78770;
  border-radius: 16px;
  content: "";
  pointer-events: none;
}
.table::after {
  inset: 10px;
  border-color: #ddc88e22;
  border-radius: 12px;
  background: repeating-linear-gradient(128deg, #f6e7b904 0 1px, transparent 1px 4px);
}
.table-corner {
  position: absolute;
  width: 18px;
  height: 18px;
  border: solid #c6af7066;
  pointer-events: none;
}
.nw { top: 14px; left: 14px; border-width: 1px 0 0 1px; border-radius: 6px 0 0; }
.ne { top: 14px; right: 14px; border-width: 1px 1px 0 0; border-radius: 0 6px 0 0; }
.sw { bottom: 14px; left: 14px; border-width: 0 0 1px 1px; border-radius: 0 0 0 6px; }
.se { bottom: 14px; right: 14px; border-width: 0 1px 1px 0; border-radius: 0 0 6px; }
.center-dial {
  grid-area: 2 / 2;
  width: clamp(86px, 12vw, 129px);
  aspect-ratio: 1;
  display: grid;
  align-content: center;
  justify-items: center;
  gap: 3px;
  border: 1px solid #c9b47e8c;
  border-radius: 50%;
  background: #1b3b30;
  box-shadow: inset 0 0 0 5px #1b3b30, inset 0 0 0 6px #c9b47e29;
  color: #f5e9c9;
  text-align: center;
}
.dial-round { font-size: 11px; letter-spacing: .12em; }
.dial-count { color: #fff9e8; font: 500 clamp(27px, 4.4vw, 45px)/1 var(--serif); font-variant-numeric: lining-nums; }
.dial-caption { font-size: 10px; }
.dial-turn { color: #e1d4b3; font-size: 10px; line-height: 1.25; white-space: nowrap; }
.dial-turn.yours { color: #fff0ba; font-weight: 700; }
@media (max-width: 520px) { .center-dial { gap: 2px; } }
.river {
  display: grid;
  grid-template-columns: repeat(6, var(--river-width));
  gap: 3px;
  align-content: start;
  justify-content: center;
  max-height: 100%;
  overflow: auto;
  scrollbar-width: thin;
}
.river-top { grid-area: 1 / 1 / 2 / 4; }
.river-bottom { grid-area: 3 / 1 / 4 / 4; }
.river-left, .river-right { grid-template-columns: repeat(5, var(--river-width)); grid-row: 1 / 4; }
.river-left { grid-column: 1; justify-self: start; }
.river-right { grid-column: 3; justify-self: end; }
.tile { display: block; padding: 0; border: 0; background: transparent; }
.tile img { display: block; width: 100%; height: auto; }
.tile.riv { position: relative; border-radius: 4px; }
.tile.riv.last::after { position: absolute; inset: 0; border: 2px solid #d7b46c; border-radius: inherit; content: ""; }
.river-top { --tile-in-y: -11px; }
.river-bottom { --tile-in-y: 11px; }
.river-left { --tile-in-x: -11px; }
.river-right { --tile-in-x: 11px; }
.land { animation: tile-land .24s cubic-bezier(.18,.72,.32,1) both; }
.draw-in img { animation: tile-land .24s cubic-bezier(.18,.72,.32,1) both; --tile-in-y: -8px; }
@keyframes tile-land {
  from { opacity: .3; transform: translate(var(--tile-in-x, 0), var(--tile-in-y, 0)) scale(.91); }
  to { opacity: 1; transform: translate(0,0) scale(1); }
}

.bubbles {
  grid-area: dialogue;
  width: 100%;
  min-height: 36px;
  min-width: 0;
  display: grid;
  align-content: center;
  color: #4b5a4d;
  font-size: 12px;
}
.bubble { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; text-align: center; }
.bubble b { color: var(--jade); }
.bubble .rs { margin-left: 8px; color: var(--muted); }
.dock {
  max-width: 900px;
  margin: 17px auto 0;
  padding: 13px 17px 12px;
  border: 1px solid #ded7c5;
  border-radius: 16px;
  background: #fffcf3e0;
  box-shadow: 0 7px 20px #443b230c;
}
.dock-info { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 5px 15px; font-size: 12px; color: var(--muted); }
.chip.me { color: var(--jade); font-weight: 750; }
.hand-row { display: flex; justify-content: center; align-items: flex-end; gap: 8px; padding: 16px 0 10px; min-height: 61px; }
.hand, .drawn { display: flex; gap: 3px; }
.drawn:empty { display: none; }
.hand-tile {
  width: var(--tile-width);
  flex: 0 0 var(--tile-width);
  border-radius: 5px;
  transform-origin: bottom center;
  transition: transform .14s, box-shadow .14s;
  box-shadow: 0 2px 0 #9a927a, 0 5px 8px #3e372530;
}
.hand-tile:hover:not(:disabled) { transform: translateY(-3px); }
.hand-tile.sel { transform: translateY(-7px); outline: 2px solid #a1753d; outline-offset: 1px; }
.action-row { min-height: 40px; display: flex; align-items: center; justify-content: center; gap: 9px 18px; flex-wrap: wrap; }
.status { font-size: 12px; color: var(--muted); text-align: center; }
.status.attention { color: #76452e; font-weight: 700; }
.actions { display: flex; gap: 6px; flex-wrap: wrap; justify-content: center; }
.actions:empty { display: none; }

.banner {
  position: absolute; z-index: 3; top: 50%; left: 50%; display: none;
  min-width: 100px; max-width: 84%; pointer-events: none; text-align: center;
  transform: translate(-50%,-50%);
  padding: 9px 20px 11px; border: 1px solid #dbc591; border-radius: 9px;
  background: #193b30; color: #faefce; box-shadow: 0 7px 19px #14251c70;
}
.banner.show {
  display: grid; gap: 3px;
  animation: call-arrive .91s cubic-bezier(.2,.67,.3,1) both;
}
.banner.win { background: #653c2e; animation-duration: .58s; }
.banner-actor { font: 600 11px var(--sans); color: #f2dfb5; letter-spacing: .08em; }
.banner-label { font: 700 clamp(28px, 5vw, 40px)/1.06 var(--serif); white-space: nowrap; }
@keyframes call-arrive {
  0% { opacity: 0; transform: translate(-50%,-42%) scale(.95); }
  20%, 79% { opacity: 1; transform: translate(-50%,-50%) scale(1); }
  100% { opacity: 0; transform: translate(-50%,-55%) scale(1); }
}
.result-overlay { position: fixed; z-index: 30; inset: 0; display: none; place-items: center; padding: 16px; background: #17271ecc; }
.result-overlay.show { display: grid; }
.result-overlay.celebrate.show { animation: reveal-result .22s .46s both; }
@keyframes reveal-result {
  from { opacity: 0; }
  to { opacity: 1; }
}
.result-card { width: min(100%, 630px); max-height: 90vh; overflow: auto; padding: 26px 18px; border-radius: 17px; background: var(--surface); text-align: center; }
.result-title { color: var(--jade-dark); font: 700 26px/1.3 var(--serif); }
.result-fans, .result-delta { margin: 10px 0; color: var(--muted); }
.result-hands { margin: 12px 0; }
.rh { display: flex; flex-wrap: wrap; justify-content: center; align-items: center; gap: 3px; margin-top: 5px; }
.rh .lbl { width: 100%; margin-bottom: 3px; }
.rh .tile { width: clamp(16px, 5vw, 30px); }

@media (min-width: 851px) and (max-height: 800px) {
  .hud { min-height: 68px; padding-block: 9px; }
  .game { padding-top: 16px; padding-bottom: 15px; }
  .stage { row-gap: 9px; }
  .table { height: clamp(294px, 43vh, 334px); }
  .opponent-north .opponent-art { width: 61px; }
  .opponent-north .opponent-info { padding-block: 5px; }
  .bubbles { min-height: 26px; }
  .dock { margin-top: 7px; padding-block: 9px; }
  .hand-row { padding-top: 12px; }
}
@media (max-width: 850px) {
  .stage {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    grid-template-areas: "west north east" "table table table" "dialogue dialogue dialogue";
    align-items: stretch;
    gap: 11px;
  }
  .opponent-north { width: 100%; }
  .opponent .opponent-card { display: block; height: 100%; }
  .opponent .opponent-art { width: 100%; height: clamp(82px, 18vw, 146px); aspect-ratio: auto; }
  .opponent .opponent-info { padding: 7px 8px; }
  .opponent .seat-name { font-size: 18px; }
  .opponent .seat-meta { margin-top: 4px; }
  .seat-role { display: none; }
  .dock { margin-top: 4px; }
}
@media (max-width: 520px) {
  .hud { min-height: 64px; gap: 7px; padding: 9px 12px; }
  .brand, .hud-right { gap: 6px; }
  .brand h1 { font-size: 23px; }
  .brand p { font-size: 10px; }
  .logo { width: 34px; height: 34px; font-size: 21px; }
  .hbtn { min-height: 34px; padding: 5px 8px; font-size: 12px; }
  .game { padding: 12px 12px 18px; }
  .stage { gap: 8px; }
  .table { height: 310px; border-width: 5px; border-radius: 18px; padding: 13px; }
  .river-left, .river-right { grid-template-columns: repeat(3, var(--river-width)); }
  .opponent .opponent-art { object-position: center 37%; }
  .dock { padding: 9px 3px; }
  .hand-row { gap: 4px; }
  .hand, .drawn { gap: 2px; }
  .action-row { gap: 6px; padding: 0 6px; }
  .abtn { min-height: 34px; padding: 5px 9px; font-size: 12px; }
  .status { width: 100%; }
}
@media (max-width: 360px) {
  :root { --tile-width: 18px; }
  .game { padding-inline: 8px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
