:root { font-family: "Segoe UI", "Microsoft YaHei", sans-serif; color: #18352e; background: #e9eee7; font-synthesis: none; }
* { box-sizing: border-box; }
body { margin: 0; min-width: 320px; }
button { font: inherit; cursor: pointer; }
button:disabled { cursor: default; }
[hidden] { display: none !important; }
.app { max-width: 1480px; margin: auto; padding: 24px clamp(12px, 3vw, 40px); }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 24px; margin-bottom: 19px; }
.eyebrow, .section-kicker { margin: 0 0 5px; font-size: 11px; letter-spacing: .18em; font-weight: 800; color: #aa6b32; }
h1 { margin: 0; font: 700 clamp(30px, 4vw, 48px)/1.15 Georgia, "Microsoft YaHei", serif; }
h2 { margin: 0; font-size: 20px; }
.intro { margin: 9px 0 0; color: #657b70; }
.top-actions { display: flex; gap: 9px; flex-wrap: wrap; }
.primary-button, .ghost-button { border-radius: 10px; min-height: 42px; padding: 9px 16px; font-weight: 700; }
.tutorial-link { text-decoration: none; }
.top-actions > .tutorial-link { display: inline-flex; align-items: center; justify-content: center; }
.tutorial-link:focus-visible { outline: 2px solid #b48a44; outline-offset: 3px; }
.rules-tutorial { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 14px; }
.rules-tutorial > a { color: #795522; font-weight: 700; }
.rules-tutorial > span { color: #718269; font-size: 12px; }
.primary-button { border: 1px solid #11614f; background: #11614f; color: #fff; }
.primary-button:hover:not(:disabled) { background: #0b483b; }
.ghost-button { border: 1px solid #b7c9bb; background: #fff; color: #1f6350; }
.ghost-button:hover:not(:disabled) { background: #eef6ef; }
.panel { border: 1px solid #d6e1d8; border-radius: 15px; background: #fff; box-shadow: 0 8px 25px #244a3010; }
.rules { padding: 19px 22px; margin-bottom: 14px; line-height: 1.65; }
.rules p { margin: 9px 0 0; }
.notice { min-height: 42px; margin-bottom: 14px; padding: 11px 14px; border-radius: 10px; background: #dcebe0; color: #24654a; font-weight: 650; }
.notice.error { background: #fae1dc; color: #a8372e; }
.game-layout { display: block; }
.main-column { min-width: 0; }
.stats { display: flex; justify-content: center; gap: 28px; padding: 0 0 20px; color: #e1eadb; font-size: 12px; }
.stats > div { display: flex; align-items: baseline; gap: 5px; }
.stats span { color: #b7cdbd; }
.stats strong { font-size: 18px; font-variant-numeric: tabular-nums; }
.stats small { color: #b7cdbd; }
.table-wrap { border: 0; border-radius: 20px; background: radial-gradient(ellipse at 50% 35%, #205641, #123d31 85%); padding: 24px 28px; box-shadow: none; }
.table { display: grid; grid-template-columns: minmax(0, 1fr) minmax(110px, .35fr) minmax(0, 1fr); gap: 14px; align-items: start; color: #fff; }
.opponent { padding: 8px; border: 0; border-radius: 0; background: transparent; min-height: 190px; }
.player-title { display: flex; justify-content: space-between; align-items: center; gap: 8px; font-size: 13px; }
.player-title strong { color: #ead29b; white-space: nowrap; }
.back-stack { display: flex; align-items: center; gap: 10px; margin: 14px 0; color: #cbe2d3; font-size: 12px; }
.tile.face-down { display: inline-grid; place-items: center; border: 3px double #fff8; color: #fff; background: repeating-linear-gradient(45deg, #a94d3b, #a94d3b 5px, #893b30 5px, #893b30 10px); }
.center { text-align: center; }
.turn-badge { display: inline-block; border-radius: 99px; padding: 7px 15px; background: #e2bc73; color: #2b392d; font-weight: 800; }
.area-label { display: block; margin-bottom: 8px; color: #d1e1d2; font-size: 12px; }
.exposed-card, .exposed-placeholder { min-height: 80px; display: grid; place-items: center; }
.exposed-card .tile { width: 52px; height: 70px; font-size: 25px; }
.exposed-placeholder { color: #bdd5c6; font-size: 30px; }
.source-label { min-height: 18px; color: #e1d6b6; font-size: 12px; }
.discards { display: flex; justify-content: center; flex-wrap: wrap; gap: 3px; min-height: 80px; align-content: center; color: #c2d7c8; font-size: 12px; }
.tile { display: inline-grid; place-items: center; flex: 0 0 auto; width: 40px; height: 58px; border: 1px solid #cbbfa5; border-radius: 6px; background: #fff9e9; box-shadow: 0 2px 5px #0b241c55; font-size: 20px; font-weight: 800; }
.tile.red { color: #c02b27; }
.tile.black { color: #1a2a27; }
.tile.small-tile { width: 25px; height: 35px; font-size: 14px; }
.empty-meld { color: #a8c5b5; font-size: 12px; }
.action-panel { display: flex; align-items: center; justify-content: space-between; gap: 20px; padding: 16px 18px; margin-top: 13px; }
.action-panel h2 { font-size: 18px; }
.action-panel p:not(.section-kicker) { margin: 6px 0 0; color: #6a7e72; font-size: 13px; }
.action-buttons { display: flex; align-items: center; justify-content: end; flex-wrap: wrap; gap: 7px; }
.my-area { margin-top: 13px; padding: 16px 18px; }
.my-heading { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.own-seat { display: flex; flex-direction: column; gap: 7px; }
#own-role { color: #ead29b; font-size: 14px; font-weight: 700; }
#count-0 { font-size: 12px; color: #b7cdbd; font-weight: 400; }
.my-heading > strong { color: #ead29b; font-size: 18px; font-variant-numeric: tabular-nums; }
.hand { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; min-height: 73px; }
.hand-tile { padding: 0; }
.result { margin-bottom: 12px; padding: 12px; border-radius: 9px; background: #e2efe5; color: #286447; }
footer { padding: 24px 0 5px; color: #7b8c7e; font-size: 12px; text-align: center; }
@media (max-width: 680px) {
  .app { padding: 15px 10px; }
  .topbar, .action-panel { display: grid; }
  .table-wrap { padding: 18px 10px; border-radius: 14px; }
  .opponent { min-height: 145px; }
  .player-title { display: grid; }
  .action-buttons { justify-content: start; }
}

/* 竖牌与可调整的分组布局 */
.tile {
  position: relative;
  width: 42px;
  height: 126px;
  aspect-ratio: 1 / 3;
  padding: 0;
  overflow: hidden;
  font-family: "STKaiti", "KaiTi", "Microsoft YaHei", serif;
  background: linear-gradient(100deg, #fffdf3 0%, #fff8e4 79%, #eaddbb 100%);
  border: 1px solid #c9b78e;
  border-radius: 5px;
  box-shadow: 2px 3px 5px #0b241c33;
}
.tile::after {
  content: "";
  position: absolute;
  inset: 5px 4px;
  border: 1px solid currentColor;
  border-radius: 2px;
  opacity: .13;
  pointer-events: none;
}
.tile-glyph {
  position: absolute;
  left: 0;
  right: 0;
  display: grid;
  place-items: center;
  height: 26%;
  font-size: 21px;
  font-weight: 800;
  line-height: 1;
}
.tile-glyph.top { top: 1%; }
.tile-glyph.bottom { bottom: 1%; transform: rotate(180deg); }
.tile.face-down {
  font-size: 16px;
  border: 3px double #fff8;
  background: repeating-linear-gradient(45deg, #a94d3b, #a94d3b 5px, #893b30 5px, #893b30 10px);
}
.tile.face-down::after { display: none; }
.exposed-card, .exposed-placeholder { min-height: 146px; }
.exposed-card .tile { width: 48px; height: 144px; }
.exposed-card .tile-glyph { font-size: 26px; }
.discards { min-height: 82px; }
.tile.small-tile { width: 22px; height: 66px; }
.tile.small-tile .tile-glyph { font-size: 12px; }

.hand-tools {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 0 0 10px;
  color: #6b8073;
  font-size: 12px;
}
.compact-button { min-height: 32px; padding: 5px 10px; white-space: nowrap; }
.hand {
  --tile-w: 46px;
  --tile-h: 138px;
  --stack-x: 3px;
  --stack-y: 37px;
  display: flex;
  align-items: flex-start;
  gap: 8px 4px;
  min-height: 160px;
  padding: 2px 0 8px;
}
.hand-stack {
  flex: 0 0 auto;
  width: calc(var(--tile-w) + 2 * var(--stack-x));
  display: grid;
  justify-items: center;
  align-content: start;
  position: relative;
}
.stack-cards {
  position: relative;
  width: var(--tile-w);
  height: var(--tile-h);
}
.stack-cards .hand-tile {
  position: absolute;
  top: 0;
  left: 0;
  width: var(--tile-w);
  height: var(--tile-h);
  border: 2px solid #c5984c;
  box-shadow: 1px 3px 8px #213d2c44;
  touch-action: none;
  user-select: none;
  cursor: grab;
  transition: background .15s ease;
}
.stack-cards .hand-tile.can-discard:hover,
.stack-cards .hand-tile:focus-visible {
  background: #fff1c4;
}
.stack-cards .hand-tile:focus-visible { outline: 2px solid #bd8d37; outline-offset: -2px; }
.stack-cards .hand-tile.dragging-card { cursor: grabbing; transition: none; }
.stack-cards .hand-tile.locked-card { cursor: default; }
.stack-controls { display: flex; gap: 3px; margin-top: 3px; }
.stack-handle {
  min-height: 26px;
  padding: 2px 5px;
  border: 1px solid #d5dfd2;
  border-radius: 6px;
  background: #f7faf4;
  color: #516e5f;
  font-size: 11px;
}
.stack-handle { touch-action: none; cursor: grab; min-width: 28px; font-size: 16px; line-height: 1; }
.stack-handle:active { cursor: grabbing; }
.stack-handle:focus-visible { outline: 2px solid #c79342; }


/* Horizontal door cards align fully across their width and stagger only along their length. */
.melds {
  --meld-long: clamp(66px, 6.2vw, 84px);
  --meld-short: calc(var(--meld-long) / 3);
  --meld-length-step: clamp(18px, 1.75vw, 24px);
  --meld-font: clamp(12px, 1.1vw, 15px);
  display: grid;
  grid-template-rows: repeat(var(--meld-rows, 4), var(--meld-short));
  grid-auto-flow: column;
  grid-auto-columns: max-content;
  align-content: start;
  justify-content: start;
  gap: 8px 10px;
  min-width: 0;
}
.meld {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  width: fit-content;
  max-width: 100%;
  min-width: 0;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
}
.meld-cards {
  display: block;
  position: relative;
  flex: 0 0 auto;
  width: var(--meld-long);
  height: var(--meld-short);
}
.meld .tile {
  position: absolute;
  width: var(--meld-short);
  height: var(--meld-long);
  aspect-ratio: 1 / 3;
  transform-origin: 0 0;
  transform: translateX(var(--meld-long)) rotate(90deg);
  font-size: var(--meld-font);
}
.meld .tile-glyph { font-size: var(--meld-font); }
.own-wei { cursor: help; -webkit-user-select: none; user-select: none; }
.own-wei:focus-visible { outline: 2px solid #c79342; outline-offset: 3px; }
@media (max-width: 680px) {
  .melds {
    --meld-long: 60px;
    --meld-short: 20px;
    --meld-length-step: 16px;
    --meld-font: 12px;
  }
}

@media (max-width: 680px) {
  .hand-tools { align-items: flex-start; }
  .hand-tools span { max-width: 210px; }
  .hand { --tile-w: 34px; --tile-h: 102px; --stack-x: 2px; --stack-y: 28px; gap: 8px 3px; min-height: 140px; }
  .hand-stack { width: calc(var(--tile-w) + 2 * var(--stack-x)); }
  .stack-cards .tile-glyph { font-size: 19px; }
  .exposed-card .tile { width: 40px; height: 120px; }
  .exposed-card, .exposed-placeholder { min-height: 126px; }
  .exposed-card .tile-glyph { font-size: 22px; }
}

/* 手牌保持纯牌面；固定坎不进入门前。 */
.hand-tools { justify-content: flex-end; }
.hand-stack .stack-controls { margin-top: 3px; }
.action-title-row { display: flex; align-items: center; flex-wrap: wrap; gap: 10px; }
.decision-timer {
  display: inline-flex;
  justify-content: center;
  min-width: 68px;
  padding: 4px 8px;
  background: transparent;
  color: #ffd45a;
  font-size: 44px;
  line-height: 1;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}
.decision-timer[hidden] { display: none; }
.decision-timer.urgent { color: #ff5252; }
@media (max-width: 680px) {
  .decision-timer { min-width: 56px; padding: 4px 6px; font-size: 36px; }
}
/* Actions settle into their real regions; no full-table flying or fading. */
.opponent, .my-area { position: relative; }
.action-callout {
  position: absolute;
  right: 12px;
  bottom: 12px;
  z-index: 5;
  padding: 6px 15px;
  border: 1px solid #d4ab60;
  border-radius: 9px;
  background: #fff3cc;
  color: #8a3d1f;
  font: 800 28px/1.2 "KaiTi", "Microsoft YaHei", serif;
  box-shadow: 0 3px 8px #142f2025;
  pointer-events: none;
}
.action-highlight { filter: brightness(1.12); }
@media (max-width: 680px) {
  .action-callout { padding: 5px 10px; font-size: 24px; }
}

.opponent-hand { padding-bottom: 3px; margin-bottom: 8px; }

/* Opponents expose a uniform back-card fan and total count only. */
.back-stack { flex-direction: column; align-items: flex-start; gap: 7px; width: 100%; }
.opponent-backs {
  --back-w: 26px;
  --back-h: 78px;
  --back-step: 3px;
  position: relative;
  flex: 0 0 auto;
  height: var(--back-h);
}
.opponent-backs .tile {
  position: absolute;
  top: 0;
  width: var(--back-w);
  height: var(--back-h);
  font-size: 12px;
}

/* Mirror the upper seats: hands and melds anchor to the outer table edges. */
.opponent-left { grid-area: 1 / 1; }
.opponent-right { grid-area: 1 / 3; }
.table > .opponent { min-width: 0; min-height: 0; padding: 4px; }
.seat-play-area {
  display: grid;
  grid-template-columns: minmax(26px, 1fr) 48px minmax(36px, .7fr);
  grid-template-areas: "hand response discards";
  gap: 10px;
  align-items: start;
  margin-top: 10px;
}
.seat-play-area .opponent-hand, .seat-play-area .back-stack { margin: 0; padding: 0; min-width: 0; }
.seat-play-area > .opponent-hand { grid-area: hand; }
.seat-play-area > .exchange { grid-area: response; }
.seat-play-area > .discard-zone { grid-area: discards; }
.opponent > .player-title { display: flex; flex-wrap: wrap; }
.opponent-right > .player-title { flex-direction: row-reverse; }
.opponent-right > .seat-play-area {
  grid-template-columns: minmax(36px, .7fr) 48px minmax(26px, 1fr);
  grid-template-areas: "discards response hand";
}
.opponent-right .back-stack { align-items: flex-end; text-align: right; }
.opponent-right .opponent-door > .melds { direction: rtl; justify-content: start; justify-items: start; }
.opponent-right .opponent-door .meld { direction: ltr; }
.opponent-right .discard-zone > .discards { direction: rtl; justify-content: start; }
.opponent-right .discard-zone .tile { direction: ltr; }
.opponent-door { min-height: 136px; margin-top: 10px; }
.table-hub {
  grid-area: 1 / 2;
  align-self: center;
  display: grid;
  justify-items: center;
  gap: 8px;
  padding: 4px 0;
}
.table-mark { font: 700 26px/1.2 "KaiTi", "Microsoft YaHei", serif; color: #e3c989; letter-spacing: .12em; }
.table-hub .turn-badge { padding: 5px 10px; font-size: 12px; }
.table > .my-area {
  grid-area: 2 / 1 / 3 / 4;
  width: 100%;
  min-width: 0;
  margin: 0;
  padding: 8px 0 0;
  color: #e8f0e4;
  border: 0;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
}
.exchange { min-width: 0; padding: 0; border: 0; background: transparent; text-align: center; }
.exchange.has-response .source-label { color: #efce8e; }
.response-zone { position: relative; min-width: 0; }
.response-zone > .action-callout {
  top: calc(var(--response-card-height, 114px) / 2);
  bottom: auto;
  left: calc(100% + 8px);
  right: auto;
  width: max-content;
  transform: translateY(-50%);
  white-space: nowrap;
}
.opponent-right .response-zone > .action-callout { left: auto; right: calc(100% + 8px); }
.exchange .exposed-card, .exchange .exposed-placeholder { height: var(--response-card-height, 114px); min-height: var(--response-card-height, 114px); }
.exchange .exposed-card .tile { width: 38px; height: 114px; }
.exchange .exposed-card .tile-glyph { font-size: 21px; }
.exchange .source-label { height: var(--response-label-height, 28px); min-height: var(--response-label-height, 28px); font-size: 10px; line-height: 14px; overflow: hidden; overflow-wrap: anywhere; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.discard-zone { min-width: 0; margin: 0; padding: 0; }
.discard-zone .discards {
  display: grid;
  grid-template-columns: repeat(auto-fill, 18px);
  grid-auto-rows: 20px;
  justify-content: start;
  align-content: start;
  gap: 3px;
  min-height: 0;
  padding-bottom: 34px;
}
.discard-zone .discards:empty { padding: 0; }
.discard-zone .small-tile { width: 18px; height: 54px; border-radius: 3px; }
.discard-zone .small-tile .tile-glyph { font-size: 10px; }
.own-play-area {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(76px, 112px);
  gap: 16px;
  align-items: start;
}
.own-play-area > .hand { grid-column: 1; min-width: 0; }
.own-meld-panel { grid-column: 2; min-width: 0; }
.own-play-area > .discard-zone { grid-column: 3; }
#own-meld-toggle { display: none; }
.own-meld-panel > .melds { margin: 0; }
@media (max-width: 680px) {
  .table { grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 10px 8px; }
  .opponent-left { grid-area: 1 / 1 / 2 / 4; }
  .opponent-right { grid-area: 1 / 4 / 2 / 7; }
  .table > .opponent { padding: 2px; }
  .seat-play-area { grid-template-columns: minmax(26px, 1fr) 32px minmax(16px, .65fr); gap: 5px; }
  .opponent-right > .seat-play-area { grid-template-columns: minmax(16px, .65fr) 32px minmax(26px, 1fr); }
  .table-hub { grid-area: 2 / 1 / 3 / 7; padding: 0; gap: 5px; }
  .table-mark { display: none; }
  .table > .my-area { grid-area: 3 / 1 / 4 / 7; padding: 4px 0 0; }
  .table .player-title { font-size: 12px; gap: 4px; }
  .table .player-title strong { font-size: 11px; }
  .back-stack > span { font-size: 10px; }
  .table { --response-card-height: 87px; --response-label-height: 24px; }
  .opponent-door { min-height: 104px; margin-top: 8px; }
  .exchange .exposed-card .tile { width: 29px; height: 87px; }
  .exchange .exposed-card .tile-glyph { font-size: 17px; }
  .exchange .source-label { font-size: 9px; line-height: 12px; }
  .discard-zone .discards { grid-template-columns: repeat(auto-fill, 16px); grid-auto-rows: 18px; gap: 2px; padding-bottom: 30px; }
  .discard-zone .discards:empty { padding: 0; }
  .discard-zone .small-tile { width: 16px; height: 48px; }
  .melds { display: flex; flex-direction: column; align-items: flex-start; }
  .opponent-right .opponent-door > .melds { align-items: flex-start; }
  .own-play-area { grid-template-columns: minmax(0, 1fr) minmax(56px, 22%); gap: 8px; padding-top: 36px; }
  .own-play-area > .discard-zone { grid-column: 2; }
  .own-meld-panel { position: absolute; right: 0; top: 0; z-index: 6; }
  #own-meld-toggle { display: block; margin-left: auto; font-size: 11px; }
  .own-meld-panel > .melds {
    position: absolute;
    right: 0;
    top: calc(100% + 6px);
    width: max-content;
    max-width: min(340px, calc(100vw - 40px));
    max-height: min(45dvh, 320px);
    overflow: auto;
    padding: 12px;
    border-radius: 12px;
    background: #153f33;
    box-shadow: 0 10px 26px #06201977;
  }
  .own-meld-panel.is-minimized > .melds { display: none; }
}

/* One floating glass sheet, anchored to the hand column's right edge beside the melds. */
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; border: 0; }
.response-choices {
  --choice-w: 36px;
  --choice-h: 108px;
  --choice-x: 3px;
  --choice-y: 30px;
  position: absolute;
  grid-area: 1 / 1 / 2 / 2;
  top: 0;
  right: 0;
  z-index: 12;
  width: max-content;
  max-width: min(460px, 100%);
  min-width: 72px;
  max-height: min(56dvh, 430px);
  overflow: auto;
  padding: 8px 12px 12px;
  border: 1px solid #e5f8ee30;
  border-radius: 18px;
  background: linear-gradient(125deg, #c4e7d51c, #092c274d);
  -webkit-backdrop-filter: blur(18px) saturate(145%);
  backdrop-filter: blur(18px) saturate(145%);
  box-shadow: 0 14px 32px #061f1b40, inset 0 1px 0 #f3fff324;
  isolation: isolate;
}
.response-choices::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  border-radius: inherit;
  background: linear-gradient(115deg, transparent 30%, #e7fff012 48%, transparent 66%);
  background-size: 220% 100%;
  animation: choice-glass-sheen 9s ease-in-out infinite alternate;
}
@keyframes choice-glass-sheen { from { background-position: 0% 0; } to { background-position: 100% 0; } }
.response-choice-heading { display: flex; justify-content: flex-end; min-height: 26px; margin-bottom: 4px; }
#response-choice-back { display: grid; place-items: center; width: 28px; min-height: 26px; padding: 0; border: 0; background: transparent; color: #e4eee0; font-size: 23px; line-height: 1; }
#response-choice-back:hover { color: #fff5cf; }
.response-choices.is-follow .response-choice-heading { display: none; }
.response-choices.is-follow { padding-top: 12px; }
.response-choice-list { display: flex; flex-wrap: wrap; align-items: flex-start; justify-content: flex-end; gap: 8px; }
.claim-choice {
  display: grid;
  justify-items: center;
  align-content: start;
  flex: 0 0 auto;
  min-width: 62px;
  padding: 5px 9px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  box-shadow: none;
}
.claim-choice:hover:not(:disabled) .claim-stack { filter: brightness(1.08); }
.claim-choice:focus-visible { outline: 2px solid #d8ba77; outline-offset: 1px; }
.claim-stack { display: block; position: relative; pointer-events: none; }
.claim-stack .claim-card { position: absolute; width: var(--choice-w); height: var(--choice-h); pointer-events: none; }
.claim-card .tile-glyph { font-size: 19px; }
.claim-card.response-card { border: 2px solid #b88b36; }
@media (max-width: 680px) {
  .response-choices { --choice-w: 31px; --choice-h: 93px; --choice-x: 2px; --choice-y: 26px; padding: 6px 8px 10px; border-radius: 14px; }
  .response-choice-list { gap: 6px; }
  .claim-choice { min-width: 49px; padding: 4px 7px; }
  .claim-card .tile-glyph { font-size: 17px; }
}
@media (prefers-reduced-motion: reduce) { .response-choices::before { animation: none; } }

.game-result { margin: 13px 0 0; }

/* The local draw sits above the hand, alongside seat details and response controls. */
.my-header { position: relative; display: grid; grid-template-columns: minmax(0, 1fr) 96px minmax(0, 1fr); align-items: start; gap: 16px; margin-bottom: 8px; min-height: calc(var(--response-card-height, 114px) + var(--response-label-height, 28px)); }
.my-header > .exchange { position: absolute; left: 50%; top: 0; width: 64px; transform: translateX(-50%); }
.my-header > .my-heading { position: relative; grid-column: 1; display: grid; grid-template-columns: auto auto; align-items: start; align-content: start; justify-content: start; gap: 6px 12px; margin: 0; min-width: 0; }
.my-header .my-heading > strong { white-space: nowrap; }
.my-header .hand-tools { grid-column: 1 / -1; margin: 0; }
.my-header > .action-panel { grid-column: 3; display: flex; flex-direction: column; align-items: flex-end; min-width: 0; margin: 0; padding: 0; gap: 7px; text-align: right; }
.my-header .action-panel > div:first-child { min-width: 0; }
.my-header .action-panel .section-kicker { display: none; }
.my-header .action-title-row { justify-content: flex-end; flex-wrap: nowrap; min-height: 56px; }
.my-header .action-panel h2 { min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 14px; }
.my-header .action-panel p:not(.section-kicker) { min-height: 4.5em; font-size: 11px; line-height: 1.5; }
.my-header .action-buttons { justify-content: flex-end; align-content: flex-start; min-height: 42px; }

@media (max-width: 680px) {
  .my-header { grid-template-columns: minmax(0, 1fr) 44px minmax(0, 1fr); gap: 8px; }
  .my-header > .exchange { width: 36px; }
  .my-header > .my-heading { grid-template-columns: 1fr; gap: 5px; }
  .my-header .my-heading > strong { font-size: 14px; }
  .my-header .hand-tools { flex-wrap: wrap; }
  .my-header .hand-tools > button { padding: 5px 6px; font-size: 11px; }
  .my-header .action-buttons { gap: 5px; min-height: 69px; }
  .my-header .action-buttons > button { padding: 6px 8px; min-height: 32px; font-size: 12px; }
}

/* Nickname entrance and the three-seat room. */
.top-actions { align-items: center; }
.session-name { padding: 8px 0; font-size: 13px; color: #547060; overflow-wrap: anywhere; }
.login-screen { display: grid; grid-template-columns: 1.1fr 1fr; overflow: hidden; min-height: 470px; margin: 22px auto; max-width: 980px; }
.login-story { position: relative; padding: 48px; background: #174b3c; color: #edf4e9; overflow: hidden; }
.login-story .eyebrow { color: #e3c58d; }
.login-story h2 { margin: 24px 0 16px; font: 700 clamp(32px, 4vw, 46px)/1.25 "KaiTi", "Microsoft YaHei", serif; letter-spacing: .08em; }
.login-story > p:last-of-type { max-width: 250px; color: #c2d9c8; font-size: 14px; line-height: 1.8; }
.login-cards { display: flex; gap: 4px; margin: 25px 0 -60px; justify-content: flex-end; transform: rotate(-12deg); }
.welcome-card { display: grid; align-content: start; justify-items: center; padding-top: 10px; width: 46px; height: 138px; color: #b5372f; background: #fff4d9; border: 2px solid #c5aa70; border-radius: 6px; font: 800 27px/1.4 "KaiTi", serif; box-shadow: 0 9px 18px #04281d55; }
.welcome-card:nth-child(2) { margin-top: 26px; }
.welcome-card:nth-child(3) { margin-top: 52px; }
.login-form { display: grid; align-content: center; gap: 12px; padding: 44px; }
.login-form h3 { margin: 0; font-size: 27px; }
.form-intro { margin: 0 0 10px; color: #728475; font-size: 13px; line-height: 1.8; }
.login-form label { font-size: 13px; color: #3c5f4c; font-weight: 700; }
.login-form input, .invite-bar input { min-width: 0; width: 100%; border: 1px solid #c2d2bd; border-radius: 9px; background: #f9fbf6; padding: 12px; font: inherit; color: #244b38; }
.login-form input:focus, .invite-bar input:focus { outline: 2px solid #8da772; outline-offset: 2px; }
.form-note { color: #718575; font-size: 12px; line-height: 1.6; }
.form-error { margin: 5px 0 0; color: #aa3b30; font-size: 13px; line-height: 1.6; }
.login-form > button { margin-top: 5px; text-align: left; display: flex; justify-content: space-between; }
.waiting-screen { max-width: 620px; margin: 30px auto; padding: 36px; text-align: center; }
.waiting-symbol { display: inline-block; margin-bottom: 16px; color: #b18b44; font-size: 42px; }
.waiting-screen h2 { margin: 8px 0 14px; }
.waiting-screen > p { line-height: 1.8; }
.waiting-screen button { margin-top: 12px; }
.room-screen { margin-bottom: 18px; padding: 24px; }
.room-heading { display: flex; justify-content: space-between; align-items: center; gap: 15px; }
.connection-status { border-radius: 999px; background: #edf4e6; padding: 6px 12px; color: #517441; font-size: 12px; white-space: nowrap; }
.invite-bar { display: flex; align-items: center; flex-wrap: wrap; gap: 9px; margin: 20px 0; }
.invite-bar label { font-size: 12px; color: #6a7e6a; }
.invite-bar input { flex: 1 1 190px; padding: 9px 11px; font-size: 12px; }
.room-seats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
.room-seat { display: flex; flex-direction: column; align-items: center; min-width: 0; min-height: 205px; padding: 22px 12px; border: 1px solid #d9e3d1; border-radius: 14px; background: #f7faf3; text-align: center; }
.room-seat.empty-seat { border-style: dashed; background: #fcfdf9; }
.seat-avatar { display: grid; place-items: center; width: 54px; height: 54px; margin-bottom: 12px; border-radius: 50%; background: #dbe8cc; color: #3c643f; font: 750 24px/1 "KaiTi", "Microsoft YaHei", serif; }
.empty-seat .seat-avatar { background: #eef2e7; color: #9bac92; }
.room-seat h3 { margin: 0; max-width: 100%; overflow-wrap: anywhere; font-size: 16px; }
.seat-note { color: #778a70; font-size: 12px; margin: 9px 0 12px; line-height: 1.5; }
.room-seat button { margin-top: auto; }
.room-footer { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 12px; margin-top: 20px; }
.room-footer > p { margin: 0; color: #6d806b; font-size: 13px; }
.room-actions { display: flex; gap: 9px; }
@media (max-width: 680px) {
  .login-screen { grid-template-columns: 1fr; min-height: 0; margin: 14px 0; }
  .login-story { padding: 25px; }
  .login-story h2 { margin: 12px 0; }
  .login-story h2 br { display: none; }
  .login-story > p:last-of-type { max-width: none; margin-bottom: 3px; }
  .login-cards { display: none; }
  .login-form { padding: 26px; }
  .room-screen { padding: 17px 12px; }
  .room-heading h2 { font-size: 20px; }
  .room-heading { align-items: flex-start; gap: 8px; }
  .room-seats { gap: 7px; }
  .room-seat { min-height: 190px; padding: 16px 6px; }
  .seat-avatar { width: 42px; height: 42px; font-size: 21px; }
  .room-seat h3 { font-size: 14px; }
  .room-seat button { padding: 6px; font-size: 11px; }
  .room-footer { align-items: flex-start; }
  .room-actions { width: 100%; justify-content: flex-end; }
  .waiting-screen { padding: 28px 18px; }
}

/* Room rule selection and private settlement breakdown. */
.room-settings { display: flex; align-items: center; flex-wrap: wrap; gap: 10px; margin-top: 18px; font-size: 13px; }
.room-settings label { font-weight: 700; color: #365c45; }
.room-settings select { border: 1px solid #b9cdb0; border-radius: 8px; padding: 9px 30px 9px 12px; background: #f8fbf4; color: #244b38; font: inherit; }
.room-settings span { color: #74856c; font-size: 12px; }
.settlement-title { margin: 0 0 12px; font-weight: 700; }
.settlement-mode { display: inline-block; font-size: 12px; color: #53744d; margin-bottom: 10px; }
.settlement-figures { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.settlement-figures > div { padding: 14px 10px; border-radius: 10px; background: #f3f6e9; }
.settlement-figures span { display: block; color: #738063; font-size: 12px; }
.settlement-figures strong { display: block; margin-top: 6px; font-size: clamp(18px, 3vw, 26px); color: #365b39; }
.settlement-patterns { display: flex; gap: 7px; flex-wrap: wrap; margin: 14px 0 10px; }
.settlement-tag { border: 1px solid #d5c395; background: #fbf4df; border-radius: 999px; padding: 5px 10px; color: #806329; font-size: 12px; }
.settlement-formula { color: #526b4d; font-size: 13px; line-height: 1.8; overflow-wrap: anywhere; }
.settlement-details { padding-left: 20px; color: #738068; font-size: 12px; line-height: 1.9; margin-bottom: 0; }
@media (max-width: 480px) { .settlement-figures { gap: 6px; } .settlement-figures > div { padding: 11px 7px; } }

.scoring-rule-label { display: inline-block; padding: 4px 10px; font-size: 12px; color: #d8e7c4; }

/* One open felt surface; the cards define their regions. */
.table .ghost-button { border-color: #a8c7ad66; background: #113d3180; color: #e2e9d6; }
.table .ghost-button:hover:not(:disabled) { background: #285c46; }
.table .primary-button { border-color: #d8b674; background: #dec28b; color: #273d2f; }
.table .primary-button:hover:not(:disabled) { background: #ead3a4; }
.table .action-panel p:not(.section-kicker) { color: #b7cdbd; }
.table .stack-handle { border: 0; background: transparent; color: #a8c5b5; }
.my-area > .melds { margin-bottom: 16px; }
.stack-cards .tile-glyph { font-size: 23px; }
.exchange .exposed-placeholder { color: transparent; }
.exchange .area-label, .discard-zone .area-label {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}
@media (max-width: 680px) {
  .stack-cards .tile-glyph { font-size: 19px; }
  .stats { gap: 22px; padding-bottom: 12px; }
  .table .my-heading > strong { font-size: 16px; }
}

/* Fill the available viewport, keeping login/room screens in their normal layout. */
html:has(#game:not([hidden])) { scrollbar-gutter: stable; background: #123d31; }
body:has(#game:not([hidden])) { background: #123d31; }
.app:has(#game:not([hidden])) { max-width: none; width: 100%; margin: 0; padding: 8px 12px; min-height: 100svh; display: flex; flex-direction: column; }
.app:has(#game:not([hidden])) main { display: flex; flex-direction: column; flex: 1; min-width: 0; }
.app:has(#game:not([hidden])) #game { display: flex; flex: 1; min-width: 0; }
.app:has(#game:not([hidden])) .main-column { display: flex; flex-direction: column; flex: 1; }
.app:has(#game:not([hidden])) .table-wrap { display: flex; flex-direction: column; flex: 1; padding: 12px 16px; border-radius: 0; }
.app:has(#game:not([hidden])) .table { flex: 1; grid-template-rows: auto minmax(min-content, 1fr); }
.app:has(#game:not([hidden])) .my-area { align-self: end; }
.app:has(#game:not([hidden])) .topbar { flex: 0 0 auto; margin-bottom: 6px; gap: 12px; color: #e7efdf; }
.app:has(#game:not([hidden])) .topbar h1 { font-size: 24px; }
.app:has(#game:not([hidden])) .session-name { color: #b6cbb8; }
.app:has(#game:not([hidden])) .topbar .ghost-button { min-height: 32px; padding: 5px 10px; border-color: #9dbca94d; color: #dfe9d5; background: #1a4a3a; font-size: 12px; }
.app:has(#game:not([hidden])) .eyebrow,
.app:has(#game:not([hidden])) .intro,
.app:has(#game:not([hidden])) footer { display: none; }
.app:has(#game:not([hidden])) .notice { flex: 0 0 32px; height: 32px; min-height: 32px; padding: 7px 10px; margin-bottom: 6px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 12px; background: transparent; color: #b7d3be; }
.app:has(#game:not([hidden])) .notice.error { color: #ffd7c8; }
.app:has(#game:not([hidden])) .stats { flex: 0 0 auto; padding-bottom: 8px; }
@media (max-width: 680px) {
  .app:has(#game:not([hidden])) { padding: 6px; }
  .app:has(#game:not([hidden])) .topbar { display: flex; align-items: center; flex-wrap: wrap; }
  .app:has(#game:not([hidden])) .topbar h1 { font-size: 20px; }
  .app:has(#game:not([hidden])) .top-actions { gap: 5px; }
  .app:has(#game:not([hidden])) .top-actions > :is(button, .tutorial-link) { padding: 5px 8px; min-height: 30px; font-size: 11px; }
  .app:has(#game:not([hidden])) .table-wrap { padding: 8px 6px; }
  .app:has(#game:not([hidden])) .table { grid-template-rows: auto auto minmax(min-content, 1fr); }
}
/* A shorter laptop keeps fixed draw/label slots instead of collapsing empty ones. */
@media (min-width: 681px) and (max-height: 820px) {
  .table { --response-card-height: 96px; --response-label-height: 28px; gap: 10px; }
  .app:has(#game:not([hidden])) .table-wrap { padding: 10px 14px; }
  .app:has(#game:not([hidden])) .stats { padding-bottom: 6px; }
  .hand { --tile-w: 40px; --tile-h: 120px; --stack-y: 31px; gap: 6px 3px; min-height: 140px; }
  .stack-cards .tile-glyph { font-size: 21px; }
  .melds { --meld-long: 72px; --meld-short: 24px; --meld-length-step: 20px; --meld-font: 13px; gap: 6px 8px; }
  .opponent-door { min-height: 114px; margin-top: 8px; }
  .exchange .exposed-card .tile { width: 32px; height: 96px; }
  .seat-play-area { margin-top: 7px; }
  .my-header { margin-bottom: 5px; }
}

/* Rules stay in the browser's modal layer and never change the table geometry. */
dialog.rules { width: min(780px, calc(100vw - 28px)); max-height: calc(100svh - 40px); margin: auto; padding: 20px 24px; overflow: auto; border: 0; border-radius: 16px; background: #f5f7ed; color: #244a39; box-shadow: 0 24px 80px #061c1a66; }
dialog.rules::backdrop { background: #061e18a6; -webkit-backdrop-filter: blur(4px); backdrop-filter: blur(4px); }
.rules-heading { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 12px; }
#rules-close { padding: 0; width: 32px; min-height: 32px; font-size: 24px; line-height: 1; }
@media (max-width: 680px) { dialog.rules { padding: 16px; font-size: 13px; max-height: calc(100svh - 24px); } }
