:root {
  --hand-band: 72px;
  --avatar-size: 84px;
  --avatar-size-opp: 96px;
  --dock-band: 48px;
  --public-band: 36px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: dark;
  font-family: "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", system-ui, sans-serif;
  --felt: #174b3e;
  --felt-deep: #0b2d27;
  --felt-light: #246552;
  --cream: #f5ecd8;
  --ink: #211f1a;
  --gold: #e7b95b;
  --red: #c94f45;
  --muted: #b9c9c3;
  --line: rgba(255, 255, 255, 0.14);
}
@font-face {
  font-family: "Nunito Sans";
  src: url("/play/fonts/nunito-sans/NunitoSans-variable.ttf") format("truetype");
  font-style: normal;
  font-weight: 200 1000;
  font-display: swap;
}
html[lang="en-US"] body,
html[lang="fr-FR"] body { font-family: "Nunito Sans", system-ui, sans-serif; }
.locale-picker { display: inline-flex; align-items: center; gap: 8px; width: fit-content; color: #fff1c5; font-size: .9rem; }
.locale-picker select { min-height: 40px; max-width: 10rem; padding: 7px 10px; border: 1px solid #d3b86d; border-radius: 9px; background: #102f29; color: inherit; font: inherit; }
.settings-card > .locale-picker { width: 100%; min-width: 0; justify-content: space-between; flex-wrap: wrap; }
.settings-card > .locale-picker select { min-width: 0; max-width: 100%; }

* { box-sizing: border-box; }

html, body { min-height: 100%; margin: 0; background: #081f1b; }

body {
  min-width: 320px;
  color: #fffaf0;
  background:
    radial-gradient(circle at 50% 0, rgba(49, 126, 102, 0.5), transparent 46%),
    linear-gradient(180deg, #102f29, #071b18);
}

button { font: inherit; }
button:focus-visible { outline: 3px solid #ffe19a; outline-offset: 2px; }
[hidden] { display: none !important; }

.app-shell {
  width: min(100%, 1280px);
  min-height: 100dvh;
  margin: 0 auto;
  background: linear-gradient(160deg, rgba(23,75,62,.82) 0%, rgba(11,45,39,.88) 76%), var(--locale-home-scene) center / cover fixed;
  box-shadow: 0 0 44px rgba(0, 0, 0, 0.45);
  overflow-x: hidden;
}

.screen { min-height: 100dvh; padding: max(18px, env(safe-area-inset-top)) 12px max(14px, env(safe-area-inset-bottom)); }
.screen-center { display: grid; align-content: center; justify-items: center; text-align: center; padding-inline: 24px; }
.brand-mark {
  display: grid; place-items: center; width: 82px; height: 82px; border: 2px solid var(--gold);
  border-radius: 24px; color: var(--gold); font-family: serif; font-size: 30px; font-weight: 800;
  transform: rotate(-3deg); box-shadow: inset 0 0 0 5px rgba(231, 185, 91, 0.09);
}
.eyebrow { margin: 14px 0 3px; color: var(--gold); font-size: 12px; font-weight: 800; letter-spacing: 0.18em; }
h1 { margin: 0; font-family: serif; font-size: clamp(27px, 8vw, 38px); letter-spacing: 0.06em; }
.lead { max-width: 310px; color: #d8e4df; line-height: 1.7; }
.commit-card {
  width: min(100%, 400px); margin: 18px 0 14px; padding: 0; border: 1px solid rgba(231, 185, 91, 0.4);
  border-radius: 16px; background: rgba(4, 26, 22, 0.5); text-align: left;
}
.commit-summary {
  display: grid; gap: 6px; padding: 14px 16px; cursor: pointer; list-style: none;
  min-height: 44px;
}
.commit-summary::-webkit-details-marker { display: none; }
.commit-title { color: var(--gold); font-size: 13px; font-weight: 800; letter-spacing: 0.06em; }
.commit-body { padding: 0 16px 14px; }
.commit-card small { display: block; color: var(--muted); font-size: 12px; margin-top: 6px; }
.commitment-hash {
  display: block; margin: 4px 0; color: #ffe4a9;
  font-size: 12px; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  overflow-wrap: anywhere; word-break: break-word;
}
.commitment-preview { color: #f0e2b8; font-size: 13px; }
.primary-button, .action-button, .dialog-button, .outline-button, .secondary-button {
  min-width: 44px; min-height: 44px; border: 0; border-radius: 13px; padding: 0 22px; cursor: pointer; font-weight: 800;
}
.primary-button { width: 100%; max-width: 360px; color: #282013; background: linear-gradient(#f6d382, #dfaa42); box-shadow: 0 7px 18px rgba(0, 0, 0, 0.25); }
.outline-button {
  width: 100%; color: #f5ecd8; background: transparent;
  border: 1.5px solid rgba(231, 185, 91, 0.75);
}
.error-text { min-height: 24px; color: #ffbbb3; }

.select-screen[hidden] { display: none !important; }
.select-screen {
  display: flex; flex-direction: column; align-items: center; gap: 12px;
  padding-inline: max(14px, env(safe-area-inset-left)) max(14px, env(safe-area-inset-right));
  text-align: center;
}
.select-screen .lead { max-width: 360px; margin: 0; }
.select-panel {
  width: min(100%, 980px);
  margin: 12px auto 0;
  padding: 16px;
  border: 1px solid rgba(231, 185, 91, 0.42);
  border-radius: 18px;
  background: rgba(4, 26, 22, 0.52);
  text-align: left;
}

.select-panel-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.select-panel-heading > div { flex: 1 1 auto; min-width: 0; }
.select-panel-heading > button { width: auto; min-width: 64px; }
.select-panel-heading .eyebrow { margin: 0 0 3px; }
.select-panel-heading h2 { margin: 0; font-family: serif; font-size: clamp(18px, 4vw, 24px); line-height: 1.3; }
.select-lead { margin: 4px 0 0; color: var(--muted); font-size: 13px; }
.select-panel .select-stage { display: block; width: 100%; margin-top: 8px; }
.select-panel .select-seats { width: 100%; max-width: none; grid-template-columns: repeat(4, minmax(0, 1fr)); }
.select-panel .select-seat { min-height: 205px; grid-template-rows: minmax(0, 1fr) auto; }
.select-panel .select-seat-main { min-height: 150px; }
.select-panel .select-seat img.select-fullbody { height: 120px; min-height: 80px; max-height: 24dvh; }
.select-panel .select-grid { display: grid; width: 100%; max-width: none; max-height: min(34dvh, 340px); grid-template-columns: repeat(auto-fit, minmax(min(100%, 180px), 1fr)); }
.select-panel .select-actions { grid-template-columns: 1fr 1.4fr; margin-top: 10px; }
.select-panel .select-actions .primary-button { max-width: 260px; }
.select-panel .select-hint { margin: 8px 0 0; color: var(--muted); font-size: 13px; text-align: center; }
.select-panel .select-seat-shuffle { min-height: 38px; }
.select-panel .dialog-button { flex: 0 0 auto; width: auto; }
@media (max-width: 480px) {
  .select-panel { padding: 12px 9px; }
  .select-panel .select-seats { gap: 5px; }
  .select-panel .select-seat { padding: 8px 4px; }
  .select-panel .select-seat { min-height: 182px; }
  .select-panel .select-seat-main { min-height: 132px; }
  .select-panel .select-seat img { width: 46px; height: 46px; border-radius: 11px; }
  .select-panel .select-seat img.select-fullbody { height: 100px; min-height: 70px; }
  .select-panel .select-seat .seat-label, .select-panel .select-seat .seat-name { font-size: 11px; }
  .select-panel .select-seat .seat-diff { font-size: 10px; }
  .select-panel .select-seat-shuffle { padding-inline: 6px; font-size: 11px; }
  .select-panel .select-grid { grid-template-columns: repeat(auto-fit, minmax(min(100%, 145px), 1fr)); }
}
.select-seats {
  display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px;
  width: min(100%, 560px); margin-top: 4px;
}
.select-seat {
  display: grid; gap: 6px; justify-items: center; padding: 10px 8px;
  border: 1px solid var(--line); border-radius: 14px; background: rgba(3, 24, 20, 0.4);
  color: inherit;
}
.select-seat.is-active {
  border-color: rgba(231, 185, 91, 0.85);
  box-shadow: 0 0 0 2px rgba(231, 185, 91, 0.18);
}
.select-seat-main {
  display: grid; gap: 6px; justify-items: center; width: 100%;
  border: 0; padding: 0; background: transparent; color: inherit; cursor: pointer;
}
.select-seat .seat-label { color: var(--gold); font-size: 12px; font-weight: 800; letter-spacing: 0.08em; }
.select-seat img, .select-card img {
  width: 64px; height: 64px; border-radius: 14px; object-fit: cover; background: #35685b;
}
.select-seat-main { min-height: 44px; }
.select-seat img.is-missing, .select-card img.is-missing { visibility: hidden; }
.select-seat .seat-name { font-size: 13px; font-weight: 800; }
.select-seat .seat-diff { color: var(--muted); font-size: 11px; }
.select-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 10px;
  width: min(100%, 760px); max-height: min(46dvh, 440px); overflow: auto;
  padding: 4px; text-align: left;
}
.select-card {
  position: relative;
  display: grid; grid-template-columns: 56px 1fr; gap: 10px; align-items: center;
  min-width: 0; min-height: 88px; padding: 10px; border: 1px solid var(--line); border-radius: 14px;
  background: rgba(3, 24, 20, 0.45); cursor: pointer; color: inherit; text-align: left;
}
.select-card img { width: 56px; height: 56px; min-width: 52px; min-height: 52px; border-radius: 12px; }
.select-card strong { display: block; font-size: 15px; }
.select-card .meta { color: #afc6bd; font-size: 12px; line-height: 1.4; margin-top: 2px; }
.select-card.is-taken,
.select-card.is-picked {
  opacity: 1;
  border-color: rgba(231, 185, 91, 0.85);
  background: rgba(231, 185, 91, 0.14);
  box-shadow: 0 0 0 1px rgba(231, 185, 91, 0.2);
}
.select-card .seat-badge {
  position: absolute; top: 8px; right: 8px;
  min-width: 44px; min-height: 22px; padding: 2px 8px;
  border-radius: 999px; background: var(--gold); color: #282013;
  font-size: 11px; font-weight: 800; line-height: 1.4; text-align: center;
}
.select-card .pick-check {
  position: absolute; left: 6px; bottom: 6px;
  width: 22px; height: 22px; border-radius: 50%;
  display: grid; place-items: center;
  background: var(--gold); color: #282013; font-size: 13px; font-weight: 900;
}
.select-card:disabled { cursor: default; }
.select-card.is-locked { opacity: 1; background: #284a40; border-style: dashed; }
.select-card.is-locked img { filter: brightness(0); background: transparent; object-fit: contain; }
.select-actions {
  display: grid; grid-template-columns: 1fr 1fr 1.35fr; gap: 8px;
  width: min(100%, 480px); margin-top: 4px;
}
.select-actions .primary-button, .select-actions .dialog-button { width: 100%; max-width: none; }
.select-seat-shuffle {
  min-width: 44px; min-height: 44px; margin-top: 4px; padding: 0 12px; border: 1px solid var(--line);
  border-radius: 999px; color: #d8e4df; background: rgba(0,0,0,.22); cursor: pointer; font-size: 12px; font-weight: 800;
}
.select-hint { min-height: 20px; margin: 0; color: var(--muted); font-size: 13px; }
.select-actions .outline-button { width: 100%; max-width: none; }

@media (max-width: 420px) {
  .select-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); max-height: 42dvh; }
  .select-seat img { width: 52px; height: 52px; }
}


.table-screen { display: flex; flex-direction: column; gap: 8px; padding-inline: 10px; }
.table-screen.game-table { background: linear-gradient(160deg, rgba(23,75,62,.62), rgba(11,45,39,.76)), var(--locale-table-scene) center / cover fixed; }
.game-table { max-width: min(1480px, 98vw); margin-inline: auto; width: 100%; }
.table-header { display: flex; align-items: center; justify-content: space-between; gap: 8px; min-height: 52px; padding: 0 4px; }
.table-header .eyebrow { margin: 0; }
.table-header h1 { font-size: 19px; }
.turn-status {
  justify-self: center; min-width: 88px; min-height: 36px;
  display: grid; place-items: center; padding: 6px 14px; border-radius: 999px;
  background: rgba(0, 0, 0, 0.28); color: #d8e4df; font-size: 13px; font-weight: 800;
  box-shadow: 0 0 0 1px rgba(255,255,255,0.08);
}
.turn-status.is-mine {
  color: #2b2010; background: var(--gold);
  box-shadow: 0 0 18px rgba(231, 185, 91, 0.45);
  animation: turn-pulse 1.6s ease-in-out infinite;
}
@keyframes turn-pulse {
  0%, 100% { box-shadow: 0 0 10px rgba(231, 185, 91, 0.28); }
  50% { box-shadow: 0 0 22px rgba(231, 185, 91, 0.55); }
}

.opponents { display: grid; gap: 6px; }
.opponent {
  position: relative; display: grid; grid-template-columns: 54px 1fr auto; gap: 8px; align-items: center;
  min-height: 64px; padding: 6px; border: 1px solid var(--line); border-radius: 14px; background: rgba(3, 24, 20, 0.33);
}
.avatar-button {
  width: 72px; height: 72px; border: 0; border-radius: 18px; padding: 0; overflow: hidden;
  color: white; background: #35685b;
  box-shadow:
    0 10px 18px rgba(0, 0, 0, 0.45),
    0 2px 0 rgba(255, 220, 140, 0.35),
    inset 0 1px 0 rgba(255, 255, 255, 0.25);
  transform: perspective(420px) rotateX(6deg) translateZ(0);
  transform-origin: 50% 100%;
}
.avatar-button img {
  width: 100%; height: 100%; display: block; object-fit: cover;
  filter: contrast(1.05) saturate(1.08);
}
.opponent-main { min-width: 0; }
.opponent-name { display: flex; align-items: baseline; gap: 6px; margin-bottom: 4px; }
.opponent-name strong { font-size: 14px; }
.opponent-name span { color: #afc6bd; font-size: 12px; }
.river, .meld-row, .flower-row { display: flex; flex-wrap: wrap; gap: 2px; min-height: 21px; align-items: center; }
.opponent-meta { text-align: right; font-size: 12px; color: #afc6bd; white-space: nowrap; }
.opponent-meta strong { display: block; color: white; font-size: 14px; }
.opponent-backs {
  display: flex; gap: 2px; margin-top: 4px; min-height: 14px; justify-content: flex-start; flex-wrap: wrap;
}
.tile-back {
  width: 12px; height: 16px; border-radius: 2px;
  background: linear-gradient(160deg, #2f6b5a, #1a4339);
  border: 1px solid rgba(231,185,91,0.35);
  box-shadow: inset 0 0 0 1px rgba(255,255,255,0.06);
}
.speech {
  position: absolute;
  z-index: 4;
  left: 50%;
  top: auto;
  bottom: 0;
  transform: translate(-50%, calc(100% + 6px));
  max-width: min(160px, 42vw);
  padding: 6px 10px;
  border-radius: 12px 12px 12px 4px;
  color: var(--ink);
  background: #fff7e7;
  font-size: 12px;
  font-weight: 800;
  line-height: 1.25;
  box-shadow: 0 4px 12px rgba(0,0,0,.28);
  pointer-events: none;
}

.table-center {
  /* Declutter 2026-09-19: center = rivers well ONLY (HUD moved to header) */
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding: 2px;
  border: 0;
  border-radius: 0;
  background: transparent;
  pointer-events: auto;
}
.table-center .turn-status {
  grid-area: turn;
  margin: 0;
  align-self: center;
  justify-self: start;
  min-width: 0;
  min-height: 28px;
  padding: 4px 12px;
  font-size: 12px;
  background: rgba(0, 0, 0, 0.42);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}
.round-info {
  grid-area: info;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 6px;
  font-size: 11px;
  min-width: 0;
}
.round-info > span {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 9px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.38);
  border: 1px solid rgba(255, 255, 255, 0.08);
  color: #c9d8d2;
  white-space: nowrap;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}
.round-info strong { color: var(--gold); font-weight: 800; }
.last-discard {
  grid-area: discard;
  align-self: center;
  min-width: 52px;
  padding: 4px 8px 6px;
  text-align: center;
  color: #afc6bd;
  font-size: 11px;
  border-radius: 12px;
  background: rgba(0, 0, 0, 0.38);
  border: 1px solid rgba(255, 255, 255, 0.08);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}
.last-discard .tile { margin: 0 auto; }
.last-discard:not([hidden]) { min-width: 40px; }

/* Center discard well — green felt surface */
.rivers-board {
  grid-area: rivers;
  position: relative;
  display: block;
  margin-top: 0;
  min-height: 96px;
  padding: 12px 14px 14px;
  border-radius: 16px;
  border: 2px solid rgba(210, 180, 110, 0.42);
  background:
    radial-gradient(ellipse 80% 55% at 50% 42%, rgba(58, 150, 118, 0.28), transparent 62%),
    linear-gradient(168deg, #1c614e 0%, #124438 42%, #0b2f28 100%);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.1),
    inset 0 -10px 28px rgba(0, 0, 0, 0.42),
    inset 0 0 0 3px rgba(12, 48, 40, 0.45),
    0 10px 22px rgba(0, 0, 0, 0.32);
  /* No perspective tilt — keeps rim square (was reading as skewed) */
  transform: none;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
}
.rivers-board {
  display: flex;
  flex-direction: column;
  justify-content: center;
}
.river-chrono {
  flex: 1 1 auto;
  min-height: 72px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  width: 100%;
}
.river-chrono.is-empty::after {
  content: attr(data-empty-label);
  display: block;
  text-align: center;
  color: rgba(200, 220, 210, 0.35);
  font-size: 12px;
  padding: 18px 8px;
}
.river-chrono-tiles {
  display: flex;
  flex-wrap: wrap;
  gap: 3px 4px;
  align-content: center;
  justify-content: center;
  max-width: 100%;
}
/* Claimed tiles in chrono river: fade only — no 90deg rotate (looked like a side pile by the opposite seat) */
.river-chrono .tile.claimed,
.rivers-board .river-chrono-tiles .tile.claimed {
  opacity: 0.4;
  transform: none !important;
  filter: grayscale(0.25);
  margin-inline: 2px;
}
/* Soft seat tint only — chronological order stays left-to-right, row wrap */
.rivers-board .tile.from-seat-0 { box-shadow: 0 0 0 1px rgba(255, 220, 140, 0.35); }
.rivers-board .tile.from-seat-1 { box-shadow: 0 0 0 1px rgba(140, 200, 255, 0.35); }
.rivers-board .tile.from-seat-2 { box-shadow: 0 0 0 1px rgba(180, 255, 180, 0.3); }
.rivers-board .tile.from-seat-3 { box-shadow: 0 0 0 1px rgba(255, 170, 200, 0.3); }
.river-lane {
  min-height: 26px;
  padding: 3px 5px;
  border-radius: 8px;
  border: 1px solid transparent;
  background: transparent;
}
.river-lane.is-empty {
  min-height: 0;
  padding: 1px 4px;
  border: 1px dotted rgba(255, 255, 255, 0.07);
  opacity: 0.42;
  background: transparent;
}
.river-lane.is-empty::after {
  content: attr(data-empty-label);
  color: rgba(175, 198, 189, 0.4);
  font-size: 10px;
}
.river-lane-label {
  display: inline-block;
  margin-right: 5px;
  color: rgba(231, 185, 91, 0.45);
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.04em;
}
.river-lane .river {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 2px;
  vertical-align: middle;
  min-height: 0;
}

.player-public {
  min-height: 33px;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  padding: 0 4px;
  color: #afc6bd;
  font-size: 12px;
  overflow-x: auto;
  overflow-y: visible;
  -webkit-overflow-scrolling: touch;
}
.player-public .meld-row { display: flex; flex-wrap: wrap; gap: 4px; max-width: 100%; }
.player-public .score { margin-left: auto; color: white; font-weight: 800; }

.bot-advice {
  display: none;
  align-items: stretch;
  justify-content: flex-start;
  flex-direction: column;
  gap: 3px;
  min-height: 38px;
  max-height: min(25vh, 176px);
  margin: 0 4px 4px;
  padding: 8px 12px;
  border-radius: 14px;
  border: 1px solid rgba(231, 185, 91, 0.35);
  background: rgba(11, 45, 39, 0.92);
  color: #f0e2b8;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.02em;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.28);
  overflow-y: auto;
}
.bot-advice.is-visible { display: flex; }
.advice-heading { display: flex; align-items: center; gap: 9px; min-height: 40px; }
.advice-avatar { width: 30px; height: 40px; object-fit: contain; flex: 0 0 auto; }
.bot-advice .advice-label { color: var(--gold); font-weight: 800; }
.bot-advice .advice-reason { margin: 0; color: #d5e0dc; font-weight: 500; font-size: 12px; }
.advice-details summary { width: fit-content; color: #f4cf76; font-size: 12px; cursor: pointer; }
.advice-details ul { margin: 4px 0; padding-left: 20px; color: #f0e2b8; font-size: 12px; }
.advice-details li + li { margin-top: 3px; }
.bot-advice .advice-caveat { margin: 2px 0 0; color: #afc6bd; font-size: 11px; font-weight: 400; }

@media (max-width: 520px) {
  .bot-advice { max-height: min(22vh, 148px); padding: 7px 10px; font-size: 12px; }
  .bot-advice .advice-reason, .advice-details ul { font-size: 11px; }
}

.actions { display: flex; justify-content: center; align-content: flex-end; gap: 8px; min-height: 0; flex-wrap: wrap; padding-bottom: 2px; position: relative; z-index: 25; }
.action-button { min-width: 58px; min-height: 44px; padding: 0 14px; color: #fff; background: #3f7165; border: 1px solid rgba(255,255,255,.15); }
.action-button.win { min-width: 88px; color: #fff; background: linear-gradient(#df655a, #b83c34); font-size: 18px; }
.action-button.pass { background: #485b56; }

.hand-zone {
  margin-top: auto; padding-top: 4px;
  padding-bottom: max(12px, env(safe-area-inset-bottom));
}
.hand-heading { display: flex; justify-content: space-between; align-items: end; min-height: 24px; padding: 0 3px; color: #afc6bd; font-size: 12px; }
.hand-heading > span:first-child { color: white; font-size: 13px; font-weight: 800; }
.hand, .player-hand {
  display: flex; align-items: flex-end; gap: 2px; width: 100%; min-height: 72px;
  padding: 8px 12px max(12px, env(safe-area-inset-bottom));
  overflow-x: auto; scroll-snap-type: x proximity;
  touch-action: manipulation; isolation: isolate; -webkit-overflow-scrolling: touch;
}
.tile-button {
  position: relative; flex: 0 0 clamp(40px, 11vw, 58px); width: auto;
  min-width: 40px; min-height: 64px; height: 64px; margin-left: 0; padding: 0;
  border: 0;
  border-bottom: 6px solid #b9a67a;
  border-right: 2px solid #d2c6a4;
  border-radius: 7px 7px 5px 5px;
  cursor: pointer; color: var(--ink);
  background: linear-gradient(155deg, #fffef8 0%, #f5ecd8 52%, #e6d9b8 100%);
  box-shadow:
    1px 2px 0 #a89468,
    2px 5px 8px rgba(0, 0, 0, 0.32),
    inset 0 1px 0 rgba(255, 255, 255, 0.7);
  font-weight: 900; font-size: 13px; line-height: 1.05;
  transition: transform .12s ease, filter .12s ease, box-shadow .12s ease;
  scroll-snap-align: center;
  /* Standing hand feel */
  transform: perspective(480px) rotateX(10deg);
  transform-origin: 50% 100%;
}
.tile-button.drawn { margin-left: 10px; }
.tile-face { display: grid; place-items: center; align-content: center; height: 100%; line-height: 1; }
.tile-rank { font-size: 16px; }
.tile-suit { margin-top: 3px; font-size: 11px; }
.tile-face-single { font-size: 18px; }
.tile-button > .tile-art, .tile > .tile-art { display: block; width: 100%; height: 100%; min-width: 0; min-height: 0; object-fit: contain; pointer-events: none; user-select: none; }
.tile > .tile-art { grid-area: 1 / 1; }
.tile-button:has(> .tile-art) > .tile-legacy, .tile:has(> .tile-art) > .tile-legacy { display: none; }
.text-tiles .tile-button > .tile-art, .text-tiles .tile > .tile-art,
.tile-button.tile-art-failed > .tile-art, .tile.tile-art-failed > .tile-art { display: none; }
.text-tiles .tile-button > .tile-legacy, .text-tiles .tile > .tile-legacy,
.tile-button.tile-art-failed > .tile-legacy, .tile.tile-art-failed > .tile-legacy { display: grid; }
.tile-style-setting { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.tile-style-setting select { min-height: 44px; max-width: 100%; border: 1px solid #8eaa98; border-radius: 8px; background: #163f36; color: #fffaf0; padding: 6px 10px; font: inherit; }
.tile-button:first-child { margin-left: 0; }
.tile-button.selected {
  z-index: 30 !important;
  transform: perspective(480px) rotateX(6deg) translateY(-10px);
  filter: drop-shadow(0 6px 4px rgba(0,0,0,.35));
  box-shadow:
    1px 3px 0 #a89468,
    3px 8px 12px rgba(0, 0, 0, 0.38),
    inset 0 1px 0 rgba(255, 255, 255, 0.75);
}
.tile-button.drawn { border-bottom-color: var(--gold); }
.hand .tile-button.drawn::after,
.player-hand .tile-button.drawn::after {
  content: var(--locale-draw-tag, "Draw");
  position: absolute;
  top: auto;
  bottom: 0;
  right: 0;
  display: grid;
  place-items: center;
  width: 12px;
  height: 12px;
  border-radius: 3px;
  color: #241b0d;
  background: var(--gold);
  font-size: 9px;
  font-weight: 900;
  line-height: 1;
  pointer-events: none;
  box-shadow: none;
}
.player-caption {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  min-width: 0;
  max-width: 100%;
}
.player-caption strong {
  display: block;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.player-caption .player-score {
  color: #ead8aa;
  font-size: 10px;
  font-weight: 500;
  line-height: 1.15;
  white-space: nowrap;
}
.tile-button[disabled] { cursor: default; opacity: .72; }
.tile-button.suit-m { color: #b2312b; }
.tile-button.suit-p { color: #245b9e; }
.tile-button.suit-s { color: #17764e; }
.tile-button.suit-z, .tile-button.suit-f { color: #25221d; }
.tile {
  display: grid; place-items: center; width: 27px; height: 34px; border-radius: 4px;
  color: var(--ink);
  background: linear-gradient(180deg, #f8f1e2, #efe4cc);
  border-bottom: 3px solid #c6b383;
  border-right: 1px solid #d8cdb0;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.22);
  font-size: 9px; font-weight: 900;
}
/* Discard tiles — flatter on felt (vs standing hand) */
.rivers-board .tile,
.river-lane .tile,
.river .tile {
  border-bottom-width: 2px;
  border-right-width: 1px;
  box-shadow: 0 1px 1px rgba(0, 0, 0, 0.28), 1px 1px 0 rgba(0, 0, 0, 0.1);
  background: linear-gradient(180deg, #f6efe0, #e8dcc0);
}

/* Latest discard glow — stays on until next discard / claim */
.tile.latest-discard {
  border: 2px solid #ffd978;
  border-bottom-color: #e0a820;
  box-shadow:
    0 0 0 2px rgba(255, 220, 120, 0.85),
    0 0 14px 4px rgba(255, 200, 70, 0.75),
    0 0 28px rgba(255, 180, 40, 0.45);
  animation: latest-discard-pulse 1.4s ease-in-out infinite;
  z-index: 3;
  position: relative;
  filter: brightness(1.08);
}
#last-discard .tile.latest-discard,
.last-discard .tile.latest-discard {
  border: 2px solid #ffd978;
  box-shadow:
    0 0 0 2px rgba(255, 220, 120, 0.9),
    0 0 16px 4px rgba(255, 200, 70, 0.8);
  animation: latest-discard-pulse 1.4s ease-in-out infinite;
}
@keyframes latest-discard-pulse {
  0%, 100% {
    box-shadow:
      0 0 0 2px rgba(255, 220, 120, 0.75),
      0 0 12px 3px rgba(255, 200, 70, 0.65),
      0 0 22px rgba(255, 180, 40, 0.35);
  }
  50% {
    box-shadow:
      0 0 0 3px rgba(255, 230, 140, 0.95),
      0 0 20px 6px rgba(255, 210, 80, 0.9),
      0 0 36px rgba(255, 190, 50, 0.55);
  }
}

.river .tile.claimed { opacity: .42; transform: rotate(90deg); margin-inline: 3px; }
.rivers-board .river .tile.claimed,
.river-chrono .tile.claimed { transform: none !important; opacity: 0.38; }
.tile.suit-m { color: #b2312b; } .tile.suit-p { color: #245b9e; } .tile.suit-s { color: #17764e; }
.tiny-label { color: var(--gold); }

.result-dialog {
  width: min(calc(100% - 28px), 440px); max-height: calc(100dvh - 28px); border: 1px solid rgba(231,185,91,.55);
  overflow: hidden; border-radius: 20px; padding: 0; color: #fff; background: linear-gradient(160deg, #17483c, #0a2822); box-shadow: 0 24px 70px rgba(0,0,0,.65);
}
.result-dialog::backdrop { background: rgba(2, 13, 11, .78); backdrop-filter: blur(3px); }
.result-dialog #result-content { max-height: inherit; }
.result-body {
  display: grid; grid-template-rows: minmax(0, 1fr) auto; max-height: calc(100dvh - 28px); padding: 0; text-align: center;
}
.result-scroll { min-height: 0; padding: 22px 22px 10px; overflow-y: auto; overscroll-behavior: contain; }
.result-body h2 { margin: 0 0 6px; color: var(--gold); font-family: serif; font-size: 28px; }
.result-body p { color: #d2dfda; }
.yaku-list, .score-list { margin: 15px 0; padding: 0; list-style: none; text-align: left; }
.yaku-list li, .score-list li { display: flex; justify-content: space-between; min-height: 34px; align-items: center; border-bottom: 1px solid var(--line); }
.score-list li.me { color: #ffe09b; font-weight: 800; }
.seed-box { margin: 14px 0; padding: 12px; border-radius: 12px; background: rgba(0,0,0,.24); text-align: left; }
.seed-box div { margin: 8px 0; }
.seed-box span { display: block; color: var(--muted); font-size: 10px; }
.seed-box code { display: block; color: #ffe7b4; font-size: 10px; overflow-wrap: anywhere; }
.dialog-actions { display: grid; gap: 8px; }
.result-dialog .dialog-actions {
  position: sticky; z-index: 2; bottom: 0; padding: 12px 22px 16px;
  background: #0a2822; box-shadow: 0 -10px 22px rgba(0, 0, 0, .34);
}
.result-scroll-cue { margin: 0; padding: 3px 6px 1px; color: #ffe399 !important; font-size: 12px; font-weight: 800; line-height: 1.35; text-align: center; }
.result-scroll-cue[hidden] { display: none !important; }
.dialog-button { width: 100%; color: #271d0d; background: var(--gold); }
.dialog-button.secondary { color: white; background: #3d6d61; }
.verify-state { min-height: 24px; margin: 8px 0 0; color: #b8efce; font-weight: 800; }
.toast { position: fixed; z-index: 99; left: 50%; bottom: 88px; transform: translateX(-50%); width: max-content; max-width: calc(100% - 36px); padding: 10px 14px; border-radius: 999px; color: white; background: #812e29; box-shadow: 0 5px 20px rgba(0,0,0,.35); font-size: 13px; }

.settings-panel { position: relative; z-index: 80; }
.settings-panel summary { min-width: 44px; min-height: 44px; display: grid; place-items: center; padding: 0 14px; border: 1px solid var(--line); border-radius: 999px; color: #e7f0ed; background: rgba(0,0,0,.2); cursor: pointer; font-size: 13px; list-style: none; }
.settings-panel summary::-webkit-details-marker { display: none; }
.settings-card { position: absolute; right: 0; top: calc(100% + 6px); width: 220px; display: grid; gap: 11px; padding: 14px; border: 1px solid rgba(231,185,91,.35); border-radius: 14px; background: #0b2d27; box-shadow: 0 12px 32px rgba(0,0,0,.5); font-size: 13px; }
.settings-card label { display: flex; align-items: center; gap: 8px; }
.settings-card input[type="checkbox"] { width: 19px; height: 19px; accent-color: var(--gold); }
.settings-card .volume-label { display: grid; grid-template-columns: auto 1fr; }
.settings-card input[type="range"] { width: 100%; accent-color: var(--gold); }
.settings-card .music-track-setting { display: grid; gap: 4px; }
.settings-card .music-track-setting select { width: 100%; min-height: 44px; border: 1px solid rgba(231,185,91,.45); border-radius: 8px; padding: 4px 8px; color: #f8f2df; background: #103b32; font: inherit; }
.settings-actions { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.35fr); gap: 8px; margin-top: 4px; }
.settings-actions button { min-width: 44px; min-height: 44px; border-radius: 10px; font: inherit; font-weight: 750; cursor: pointer; }
.settings-card .settings-close { border: 1px solid rgba(231,185,91,.65); color: #ffe6a0; background: #17483c; }
.settings-card .settings-close:hover { background: #236552; }
.settings-card .settings-leave { min-height: 44px; margin-top: 4px; border: 1px solid rgba(224,112,91,.55); border-radius: 10px; color: #ffe9df; background: #703a32; font: inherit; font-weight: 750; cursor: pointer; }
.settings-card .settings-leave:hover { background: #87473d; }
.rotate-hint { position: fixed; z-index: 120; left: 50%; bottom: max(14px, env(safe-area-inset-bottom)); transform: translateX(-50%); display: flex; align-items: center; gap: 8px; width: max-content; max-width: calc(100% - 24px); padding: 9px 10px 9px 14px; border: 1px solid rgba(231,185,91,.5); border-radius: 999px; color: #251e12; background: #ffe4a3; box-shadow: 0 8px 24px rgba(0,0,0,.35); font-weight: 800; font-size: 13px; }
.rotate-hint button { width: 27px; height: 27px; border: 0; border-radius: 50%; color: white; background: #775f31; cursor: pointer; font-size: 20px; line-height: 1; }
.player-speech { left: 12px; top: -37px; }
.opponent[data-thinking="true"] { border-color: rgba(231,185,91,.75); box-shadow: 0 0 0 2px rgba(231,185,91,.12); }
.hand-break { display: none; }


/* P0 0918-2: large-tiles must enlarge across orientations */
.app-shell.large-tiles {
  --hand-band: 88px;
}
.app-shell.large-tiles .tile-button {
  flex: 0 0 clamp(48px, 13.2vw, 70px);
  width: auto;
  min-width: 48px;
  min-height: 76px;
  height: 76px;
  font-size: 15px;
}
.app-shell.large-tiles .tile-rank { font-size: 18px; }
.app-shell.large-tiles .tile-suit { font-size: 13px; }
.app-shell.large-tiles .tile-face-single { font-size: 20px; }
.app-shell.large-tiles .hand,
.app-shell.large-tiles .player-hand { min-height: 84px; }

@media (orientation: portrait) {
  .table-screen.game-table {
    display: grid;
    grid-template-areas:
      "header"
      "opponents"
      "center"
      "public"
      "goal"
      "coach"
      "advice"
      "actions"
      "hand";
    grid-template-rows: auto auto 1fr auto auto auto auto auto auto;
    gap: 6px;
    min-height: 100dvh;
  }
  .table-header { grid-area: header; }
  .opponents { grid-area: opponents; grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .table-center { grid-area: center; align-self: stretch; }
  .player-public { grid-area: public; overflow: visible; min-height: 36px; }
  .mode-goal-banner { grid-area: goal; }
  .coach-bubble { grid-area: coach; }
  .bot-advice { grid-area: advice; }
  .actions { grid-area: actions; position: relative; bottom: auto; z-index: 25; flex-wrap: wrap; align-content: flex-end; }
  .hand-zone { grid-area: hand; }
  .opponent { display: block; min-width: 0; min-height: 74px; padding: 6px; text-align: center; cursor: pointer; }
  .avatar-button { width: 64px; height: 64px; margin: 0 auto 2px; border-radius: 16px; }
  .opponent-main { min-width: 0; }
  .opponent-name { display: block; margin: 0; line-height: 1.15; }
  .opponent-name strong { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; }
  .opponent-name span { font-size: 11px; }
  .opponent .river, .opponent-meta, .opponent-backs { display: none !important; }
  .opponent .meld-row { display: flex; justify-content: center; margin-top: 2px; }
  .speech {
  position: absolute;
  z-index: 4;
  left: 50%;
  top: auto;
  bottom: 0;
  transform: translate(-50%, calc(100% + 6px));
  max-width: min(160px, 42vw);
  padding: 6px 10px;
  border-radius: 12px 12px 12px 4px;
  color: var(--ink);
  background: #fff7e7;
  font-size: 12px;
  font-weight: 800;
  line-height: 1.25;
  box-shadow: 0 4px 12px rgba(0,0,0,.28);
  pointer-events: none;
}
  .hand, .player-hand {
    justify-content: flex-start; overflow-x: auto; -webkit-overflow-scrolling: touch;
    flex-wrap: nowrap; scroll-snap-type: x proximity;
    padding-bottom: max(10px, env(safe-area-inset-bottom));
  }
  .hand-zone { z-index: 30; padding-bottom: max(4px, env(safe-area-inset-bottom)); }
  .tile-button { touch-action: manipulation; scroll-snap-align: start; }
  .tile-button.selected { transform: perspective(480px) rotateX(6deg) translateY(-8px); }
  .app-shell.large-tiles .hand { flex-wrap: nowrap; min-height: 84px; }
  .app-shell.large-tiles .tile-button {
    flex: 0 0 clamp(48px, 13.2vw, 70px); width: auto;
    min-width: 48px; min-height: 76px; height: 76px; margin-left: 0;
    font-size: 15px;
  }
  .app-shell.large-tiles .tile-rank { font-size: 18px; }
  .app-shell.large-tiles .tile-suit { font-size: 13px; }
  .app-shell.large-tiles .tile-face-single { font-size: 20px; }
  .app-shell.large-tiles .hand-break { display: none; }
  .app-shell.large-tiles .tile-button.drawn { margin-left: 12px; }
  /* P0: actions stay in grid flow above hand — no sticky bottom magic */
  .table-center {
    padding: 2px 2px 0;
    gap: 5px 6px;
  }
  .table-center .turn-status { min-height: 26px; font-size: 12px; }
  .round-info { font-size: 11px; }
  .rivers-board {
    /* chrono single well */
    min-height: 110px;
    transform: none;
  }
  .river-lane[data-seat-role="opposite"] { grid-column: 1 / -1; }
  .river-lane[data-seat-role="self"] { grid-column: 1 / -1; }
}

@media (orientation: landscape) {
  body { padding: 0; }
  .app-shell, .screen { min-height: 100dvh; }
  .app-shell { border-radius: 0; }
  .select-screen {
    justify-content: flex-start; gap: 8px;
    padding-block: max(6px, env(safe-area-inset-top)) max(6px, env(safe-area-inset-bottom));
    overflow: auto;
  }
  .select-screen h1 { font-size: 20px; margin: 0; }
  .select-screen .lead { font-size: 13px; max-width: 480px; }
  .select-seats { width: min(100%, 640px); gap: 6px; }
  .select-seat { padding: 6px 6px; gap: 4px; }
  .select-seat img { width: 48px; height: 48px; }
  .select-seat .seat-name { font-size: 12px; }
  .select-seat-shuffle { min-width: 44px; min-height: 44px; font-size: 12px; }
  .select-grid {
    grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
    max-height: min(38dvh, 300px); width: min(100%, 900px); gap: 8px;
  }
  .select-card { min-height: 72px; padding: 8px; grid-template-columns: 52px 1fr; }
  .select-card img { width: 52px; height: 52px; }
  .select-actions { width: min(100%, 520px); margin-top: 2px; }
  .select-hint { font-size: 11px; }
  .table-screen { position: relative; display: block; height: 100dvh; min-height: 320px; max-height: none; padding: max(5px, env(safe-area-inset-top)) max(8px, env(safe-area-inset-right)) max(4px, env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left)); overflow: hidden; }
  .table-header { position: absolute; z-index: 10; inset: 5px 8px auto; min-height: 44px; }
  .table-header h1 { font-size: 15px; }
  .table-header .eyebrow { display: none; }
  .opponents { position: absolute; inset: 36px 4px calc(var(--hand-band) + var(--dock-band) + var(--public-band) + 8px); display: block; z-index: 28; pointer-events: none; }
  .opponent { position: absolute; width: 22%; min-height: 88px; max-height: 120px; grid-template-columns: 1fr; justify-items: center; padding: 0; overflow: visible; z-index: 28; pointer-events: auto; background: transparent; }
  .opponent:nth-child(1) { top: -6px; left: 50%; transform: translateX(-50%); width: 28%; }
  .opponent:nth-child(2) { top: 48px; left: 2px; }
  .opponent:nth-child(3) { top: 48px; right: 2px; }
  .avatar-button { width: 88px; height: 88px; border-radius: 22px; }
  .opponent-main { text-align: center; margin-top: 2px; }
  .opponent-name { margin-bottom: 0; justify-content: center; }
  .opponent-name strong { font-size: 13px; text-shadow: 0 1px 2px rgba(0,0,0,.65); }
  .opponent-name span { font-size: 11px; }
  .opponent .meld-row { justify-content: center; margin-top: 2px; }
  .opponent .meld-row .tile { width: 22px; height: 28px; font-size: 8px; }
  .table-center {
    /* Center discard well — leave side corridors for 上家/下家 cards */
    position: absolute; left: 27%; right: 27%; top: 88px;
    bottom: calc(var(--hand-band) + var(--dock-band) + var(--public-band) + 8px);
    min-height: 0; max-height: none; padding: 2px 4px;
    align-content: stretch;
    overflow: hidden;
    z-index: 18;
  }
  .table-center .turn-status { min-height: 26px; font-size: 12px; padding: 3px 10px; }
  .round-info { gap: 3px 5px; font-size: 11px; }
  .round-info > span { padding: 2px 7px; }
  .last-discard { padding: 3px 6px 4px; font-size: 10px; }
  .last-discard .tile { width: 30px; height: 38px; }
  .rivers-board {
    display: block;
    min-height: 0;
    height: 100%;
    padding: 10px 12px;
    transform: none;
  }
  .river-chrono { min-height: 100%; }
  .player-public {
    position: absolute;
    left: 8px;
    right: max(160px, 28%);
    bottom: calc(var(--hand-band) + var(--dock-band) + var(--safe-bottom));
    min-height: var(--public-band);
    max-height: 56px;
    overflow-x: auto;
    overflow-y: visible;
    z-index: 24;
  }
  .bot-advice {
    position: absolute;
    z-index: 25;
    left: max(8px, env(safe-area-inset-left));
    right: auto;
    bottom: calc(var(--hand-band) + var(--safe-bottom));
    max-width: min(42%, 360px);
    margin: 0;
    justify-content: flex-start;
  }
  /* coach visible → hide E1 advice so they do not fight one dock lane */
  .table-screen:has(#coach-bubble:not([hidden])) .bot-advice {
    display: none !important;
  }
  .actions {
    position: absolute;
    z-index: 25;
    right: max(8px, env(safe-area-inset-right));
    bottom: calc(var(--hand-band) + var(--safe-bottom));
    justify-content: flex-end;
    align-content: flex-end;
    flex-wrap: wrap-reverse; /* multi 吃 options grow upward, away from hand */
    max-width: 55%;
    max-height: calc(var(--dock-band) + 96px);
  }
  .action-button { min-width: 50px; min-height: 44px; padding: 0 10px; }
  .action-button.win { min-width: 66px; }
  .hand-zone {
    position: absolute;
    z-index: 30;
    left: max(6px, env(safe-area-inset-left));
    right: max(6px, env(safe-area-inset-right));
    bottom: 0;
    height: calc(var(--hand-band) + var(--safe-bottom));
    min-height: calc(var(--hand-band) + var(--safe-bottom));
    padding: 0 0 max(4px, env(safe-area-inset-bottom));
    pointer-events: auto;
  }
  .hand-heading { display: none; }
  .hand, .player-hand {
    justify-content: flex-start; overflow-x: auto; -webkit-overflow-scrolling: touch;
    min-height: 54px; gap: 2px;
    padding: 4px 6px max(6px, env(safe-area-inset-bottom));
    scroll-snap-type: x proximity;
  }
  .tile-button {
    flex: 0 0 clamp(30px, 5.2vw, 44px); width: auto;
    min-width: 30px; max-width: 44px; min-height: 50px; height: 50px; margin-left: 0;
    touch-action: manipulation;
  }
  .tile-button.selected { transform: perspective(480px) rotateX(6deg) translateY(-6px); }
  .tile-rank { font-size: 14px; }
  .tile-suit { font-size: 10px; }
  .tile-face-single { font-size: 15px; }
  .rivers-board { gap: 3px; min-height: 0; }
  .river-lane { min-height: 24px; padding: 2px 4px; }
  .rivers-board .tile, .river-lane .tile, .last-discard .tile {
    width: 28px; height: 36px; font-size: 10px; border-radius: 4px;
  }
  .tile-button.drawn { margin-left: 10px; }
  .result-dialog { max-height: calc(100dvh - 12px); }
  .result-body { padding: 13px 18px; }
  .result-body h2 { font-size: 23px; }
  .result-body p { margin-block: 5px; }
  .yaku-list, .score-list { margin: 8px 0; }
  .yaku-list li, .score-list li { min-height: 27px; }
  .seed-box { margin: 7px 0; padding: 7px 10px; }
  .seed-box div { margin: 4px 0; }

  .app-shell.large-tiles {
    --hand-band: 78px;
    --dock-band: 48px;
  }
  .app-shell.large-tiles .tile-button {
    flex: 0 0 clamp(36px, 6.2vw, 54px); width: auto;
    min-width: 36px; max-width: 54px; min-height: 60px; height: 60px;
    font-size: 15px;
  }
  .app-shell.large-tiles .tile-rank { font-size: 16px; }
  .app-shell.large-tiles .tile-suit { font-size: 12px; }
  .app-shell.large-tiles .tile-face-single { font-size: 17px; }
  .app-shell.large-tiles .hand,
  .app-shell.large-tiles .player-hand { min-height: 64px; }
}

@media (orientation: landscape) and (max-height: 420px) {
  .opponents { inset: 38px 4px calc(var(--hand-band) + var(--dock-band) + var(--public-band) + 4px); }
  .opponent { width: 28%; max-height: 64px; min-height: 48px; }
  .opponent:nth-child(1) { width: 34%; }
  .opponent:nth-child(2), .opponent:nth-child(3) { top: 24px; }
  .avatar-button { width: 72px; height: 72px; }
  .table-center { top: 64px; bottom: calc(var(--hand-band) + var(--dock-band) + var(--public-band) + 4px); left: 26%; right: 26%; padding: 2px 3px; z-index: 18; }
  .table-center .turn-status { min-height: 22px; font-size: 11px; padding: 2px 8px; }
  .round-info { font-size: 10px; }
  .rivers-board { padding: 6px 8px; transform: none; }
  .hand, .player-hand { min-height: 48px; padding: 2px 4px max(4px, env(safe-area-inset-bottom)); }
  .tile-button {
    flex: 0 0 clamp(28px, 5vw, 40px);
    min-width: 28px; max-width: 40px; min-height: 46px; height: 46px;
  }
  .app-shell { --hand-band: 56px; --dock-band: 44px; --public-band: 28px; }
  .actions { bottom: calc(var(--hand-band) + var(--safe-bottom)); }
  .bot-advice { bottom: calc(var(--hand-band) + var(--safe-bottom)); }
  .player-public { bottom: calc(var(--hand-band) + var(--dock-band) + var(--safe-bottom)); }
  .rivers-board .tile, .river-lane .tile { width: 24px; height: 31px; font-size: 9px; }
  .select-screen { gap: 4px; }
  .select-screen .eyebrow, .select-screen .lead { display: none; }
  .select-grid { max-height: min(32dvh, 200px); }
  .select-seat img { width: 40px; height: 40px; }

  .result-dialog { max-height: calc(100dvh - 12px); }
  .result-body { max-height: calc(100dvh - 12px); }
  .result-scroll { padding: 10px 18px 4px; }
  .result-scroll > .eyebrow { margin: 0 0 2px; line-height: 1.1; }
  .result-body h2 { margin-bottom: 3px; font-size: 21px; line-height: 1.1; }
  .result-body p { margin-block: 3px; line-height: 1.2; }
  .yaku-list, .score-list { margin-block: 5px; }
  .yaku-list li, .score-list li { min-height: 24px; line-height: 1.15; }
  .seed-box { margin-block: 5px; padding: 6px 9px; }
  .seed-box div { margin-block: 3px; }
  .result-dialog .dialog-actions { gap: 6px; padding: 8px 18px 10px; }
  .result-dialog .verify-state { min-height: 0; margin-top: 2px; font-size: 12px; line-height: 1.15; }
}

/* 平板橫式中等高度：手牌略放大但仍留牌河 */
@media (orientation: landscape) and (min-height: 421px) and (max-width: 1023px) {
  .table-center { top: 92px; bottom: calc(var(--hand-band) + var(--dock-band) + var(--public-band) + 8px); left: 24%; right: 24%; z-index: 18; }
  .tile-button {
    flex: 0 0 clamp(34px, 5vw, 48px);
    min-width: 34px; max-width: 48px; min-height: 54px; height: 54px;
  }
  .rivers-board .tile, .river-lane .tile { width: 30px; height: 38px; font-size: 11px; }
}

@media (min-width: 1024px) {
  body { padding-block: 0; }
  .app-shell { min-height: 100dvh; border-radius: 0; }
  .screen { min-height: 100dvh; }
  .table-screen { max-height: none; }
  .game-table { max-width: min(1680px, 98vw); }
  .opponents { inset-inline: 28px; z-index: 28; }
  .opponent { z-index: 28; }
  .opponent { max-height: 140px; }
  .table-center { top: 108px; bottom: calc(var(--hand-band) + var(--dock-band) + var(--public-band) + 16px); left: 22%; right: 22%; min-height: 0; z-index: 18; }
  .tile-button {
    flex: 0 0 clamp(56px, 4.2vw, 86px); width: auto;
    max-width: 86px; min-width: 56px; min-height: 88px; height: 88px; font-size: 15px;
  }
  .tile-rank { font-size: 22px; }
  .tile-suit { font-size: 13px; }
  .tile-face-single { font-size: 22px; }
  .rivers-board .tile, .river-lane .tile, .last-discard .tile {
    width: 40px; height: 52px; font-size: 13px;
  }
  .hand { min-height: 96px; gap: 4px; }
}


@media (min-width: 1024px) {
  .app-shell.large-tiles {
    --hand-band: 110px;
  }
  .app-shell.large-tiles .tile-button {
    flex: 0 0 clamp(68px, 5vw, 104px);
    max-width: 104px; min-width: 68px; min-height: 106px; height: 106px;
    font-size: 17px;
  }
  .app-shell.large-tiles .tile-rank { font-size: 24px; }
  .app-shell.large-tiles .tile-suit { font-size: 15px; }
  .app-shell.large-tiles .tile-face-single { font-size: 24px; }
  .app-shell.large-tiles .hand { min-height: 116px; }
}

@media (min-width: 1440px) and (orientation: landscape) {
  .game-table { max-width: min(1840px, 98vw); }
  .table-center { left: 14%; right: 14%; }
  .tile-button {
    flex: 0 0 clamp(64px, 3.8vw, 94px);
    max-width: 94px; min-width: 64px; min-height: 96px; height: 96px;
  }
  .tile-rank { font-size: 24px; }
}

@media (max-width: 380px) {
  .table-screen { gap: 6px; }
  .opponent { min-height: 60px; }
  .avatar-button { width: 96px; height: 96px; }
  .opponent { grid-template-columns: 50px 1fr auto; }
  .tile-button { min-width: 40px; min-height: 64px; height: 64px; }
}

@media (min-width: 700px) and (orientation: portrait) {
  body { padding-block: 18px; }
  .app-shell { min-height: calc(100dvh - 36px); border-radius: 24px; }
  .screen { min-height: calc(100dvh - 36px); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; animation: none !important; }
  .rivers-board,
  .tile-button,
  .tile-button.selected { transform: none !important; }
}


/* —— 練習場／教學 MVP —— */
.tutorial-entry {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 14px;
  width: min(100%, 430px);
  margin: 18px 0 12px;
  padding: 14px 16px;
  border: 1px solid rgba(231, 185, 91, 0.72);
  border-radius: 17px;
  background: linear-gradient(120deg, rgba(231, 185, 91, 0.16), rgba(4, 26, 22, 0.62));
  text-align: left;
}
.tutorial-entry strong,
.tutorial-entry span { display: block; }
.tutorial-entry strong { color: #ffe19a; font-size: 15px; }
.tutorial-entry span { margin-top: 4px; color: var(--muted); font-size: 13px; line-height: 1.45; }
.tutorial-entry .primary-button { width: auto; min-height: 48px; padding-inline: 16px; white-space: nowrap; }
.lobby-actions {
  display: grid;
  gap: 10px;
  width: min(100%, 330px);
  margin-top: 4px;
}
.lobby-actions .primary-button,
.lobby-actions .secondary-button { width: 100%; max-width: none; }
.lobby-actions a.secondary-button { display: grid; place-items: center; text-decoration: none; }
.lobby-intro { max-width: 34rem; margin: 0 0 12px; color: var(--muted); }
.lobby-learning { width: min(100%, 330px); margin-top: 14px; text-align: left; }
.lobby-learning > summary { cursor: pointer; padding: 12px 14px; border: 1px solid rgba(231, 185, 91, .45); border-radius: 12px; color: #ffe19a; font-weight: 800; }
.lobby-learning[open] > summary { border-radius: 12px 12px 0 0; }
.lobby-learning > p { margin: 0; padding: 12px 14px 0; color: var(--muted); font-size: .9rem; line-height: 1.5; }
.lobby-learning-actions { display: grid; gap: 8px; padding: 12px; border: 1px solid rgba(231, 185, 91, .45); border-top: 0; border-radius: 0 0 12px 12px; }
.secondary-button {
  min-height: 48px;
  border: 1px solid rgba(231, 185, 91, 0.45);
  border-radius: 13px;
  padding: 0 22px;
  cursor: pointer;
  font-weight: 800;
  color: #f5ecd8;
  background: rgba(4, 26, 22, 0.55);
}
.secondary-button:hover { border-color: rgba(231, 185, 91, 0.85); background: rgba(231, 185, 91, 0.12); }

.mode-list-screen { gap: 12px; }
.mode-list-screen .lead { max-width: 360px; }
#tutorial { display: block; height: 100dvh; min-height: 0; overflow-y: auto; padding: 24px clamp(16px,4vw,48px); text-align: left; }
#tutorial > .eyebrow, #tutorial > h1, #tutorial > .lead, #tutorial > .learning-progress-note, #tutorial > #tutorial-practice-shortcut, #tutorial > #tutorial-back { display: block; margin-inline: auto; text-align: center; }
#tutorial > h1, #tutorial > .lead, #tutorial > .learning-progress-note { max-width: 760px; }
#tutorial > .lead { margin-block: 8px 4px; }
#tutorial > #tutorial-practice-shortcut { margin-block: 8px 18px; }
.learning-progress-note { color: var(--muted); font-size: 13px; }
#tutorial .mode-list { display: grid; width: min(100%,1200px); max-width: none; gap: 24px; margin: 0 auto 20px; }
.learning-section { min-width: 0; padding: 16px; border: 1px solid rgba(231,185,91,.38); border-radius: 18px; background: rgba(4,26,22,.28); scroll-margin-top: 16px; }
.learning-section > header { display: flex; align-items: flex-start; justify-content: space-between; gap: 14px; margin-bottom: 12px; }
.learning-section h2 { margin: 0; color: var(--gold); font-size: 20px; }
.learning-section header p { margin: 4px 0 0; color: var(--muted); font-size: 13px; line-height: 1.5; }
.learning-section header > strong { flex: none; color: var(--gold); font-size: 13px; }
.learning-modules { display: grid; grid-template-columns: repeat(auto-fit,minmax(min(100%,220px),1fr)); align-items: start; gap: 10px; }
.learning-module { display: grid; align-content: start; gap: 8px; min-width: 0; }
.learning-lesson, .learning-practice { width: 100%; min-height: 112px; }
.learning-state { color: var(--muted); font-size: 12px; }
.learning-lesson.is-complete, .learning-practice.is-complete { border-color: rgba(231,185,91,.75); background: rgba(231,185,91,.12); }
.learning-lesson.is-complete .learning-state, .learning-practice.is-complete .learning-state { color: var(--gold); font-weight: 800; }
.learning-practice { min-height: 84px; border-style: dashed; }
#tutorial > #tutorial-back { margin-block: 22px; }
@media (max-width: 520px) {
  #tutorial { padding-inline: 12px; }
  .learning-section { padding: 12px; }
  .learning-modules { grid-template-columns: 1fr; }
  .learning-lesson, .learning-practice { min-height: 0; }
}
.campaign-friends { display: flex; justify-content: center; gap: 16px; flex-wrap: wrap; }
.campaign-friends figure { margin: 0; }
.campaign-friends img { display: block; width: 76px; height: 76px; object-fit: contain; }
.campaign-friends figcaption { margin-top: 6px; }
.campaign-note { max-width: 430px; color: var(--muted); font-size: 14px; line-height: 1.6; }
.campaign-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 12px; }
#campaign { padding-block: 24px; overflow-y: auto; }
#campaign-progress { margin: 0; color: var(--gold); font-weight: 700; }
.campaign-result { color: var(--gold); font-weight: 700; }
#campaign { height: 100dvh; min-height: 0; display: block; padding: 24px 16px; text-align: center; }
#campaign > h1 { margin: 10px 0 18px; }
.campaign-stops { display: grid; grid-template-columns: repeat(4,minmax(0,1fr)); gap: 12px; width: min(100%,1000px); margin: 20px auto; }
.campaign-stop { display: flex; flex-direction: column; gap: 8px; align-items: center; padding: 16px 10px; min-width: 0; min-height: 44px; border: 1px solid var(--line); border-radius: 18px; background: #103a31; color: #fff8e6; cursor: pointer; }
.campaign-stop img { width: 64px; height: 76px; object-fit: contain; border-radius: 10px; }
.campaign-stop small, .campaign-stop span { color: var(--muted); font-size: 12px; }
.campaign-stop.completed { border-color: var(--gold); }
.campaign-stop[aria-pressed="true"] { outline: 2px solid var(--gold); outline-offset: 2px; background: #285747; }
.campaign-info { width: min(100%,720px); margin: 16px auto; padding: 20px; border: 1px solid var(--line); border-radius: 18px; background: #0b3028; }
.campaign-info h2 { color: var(--gold); margin: 0 0 12px; }
.campaign-info .campaign-note { margin: 16px auto; }
.campaign-info .primary-button { min-height: 48px; }
.campaign-actions { max-width: 720px; margin: 20px auto 12px; }
.campaign-actions .dialog-button { width: auto; flex: 1 1 170px; }
.result-dialog .campaign-result-actions { grid-template-columns: repeat(2,minmax(0,1fr)); }
.campaign-result-actions .dialog-button { padding: 8px 10px; min-height: 44px; white-space: normal; }
.campaign-seal { display: grid; place-items: center; width: 82px; height: 82px; margin: 12px auto 18px; border: 4px double var(--gold); border-radius: 50%; color: var(--gold); font-size: 25px; font-weight: 800; transform: rotate(-8deg); }
.campaign-next { display: flex; justify-content: center; align-items: center; gap: 18px; margin: 18px auto; padding: 14px; border-top: 1px solid var(--line); }
.campaign-next img { width: 60px; height: 70px; object-fit: contain; border-radius: 8px; }
.campaign-card .result-scroll { padding-block: 24px; }
@media (max-width: 600px) { .campaign-stops { grid-template-columns: repeat(2,minmax(0,1fr)); } .campaign-info { padding: 16px 12px; } }
@media (max-height: 500px) and (orientation: landscape) {
  #campaign { padding-block: 12px; }
  .campaign-stops { gap: 8px; }
  .campaign-stop { padding: 10px; }
  .campaign-stop img { height: 52px; width: 52px; }
  .campaign-seal { width: 58px; height: 58px; font-size: 20px; margin: 4px auto 10px; }
  .campaign-card .result-scroll { padding-block: 10px; }
  .campaign-card .result-scroll:has(.campaign-next) { display: grid; grid-template-columns: 64px minmax(0,1fr) minmax(0,1fr); gap: 8px 16px; align-items: center; }
  .campaign-card .result-scroll:has(.campaign-next) > .campaign-seal { grid-column: 1; grid-row: 1 / span 5; }
  .campaign-card .result-scroll:has(.campaign-next) > h2,
  .campaign-card .result-scroll:has(.campaign-next) > p { grid-column: 2; }
  .campaign-card .result-scroll > .campaign-next { grid-column: 3; grid-row: 1 / span 5; flex-direction: column; margin: 0; padding: 6px; border: 0; }
}


.mode-list {
  display: grid;
  gap: 10px;
  width: min(100%, 420px);
  margin: 8px 0 12px;
  text-align: left;
}
.mode-card {
  display: grid;
  gap: 4px;
  min-height: 44px;
  padding: 14px 16px;
  border: 1px solid var(--line, rgba(255,255,255,0.14));
  border-radius: 14px;
  background: rgba(3, 24, 20, 0.45);
  color: inherit;
  cursor: pointer;
  text-align: left;
}
.mode-card strong { font-size: 16px; }
.mode-card small, .mode-card .card-coach { color: var(--muted, #b9c9c3); font-size: 12px; line-height: 1.45; }
.mode-card em { color: var(--gold, #e7b95b); font-style: normal; font-size: 11px; font-weight: 800; }
.mode-card.is-locked {
  opacity: 1; cursor: not-allowed;
  border-style: dashed; color: #afc6bd;
  background: rgba(3, 24, 20, 0.28);
}
.mode-card.is-locked em::after { content: var(--locale-coming-soon, "Coming soon"); }
.mode-card:not(.is-locked):hover {
  border-color: rgba(231, 185, 91, 0.75);
  background: rgba(231, 185, 91, 0.1);
}

.mode-goal-banner {
  margin: 0 8px 6px;
  padding: 8px 12px;
  border-radius: 12px;
  border: 1px solid rgba(231, 185, 91, 0.45);
  background: rgba(8, 36, 30, 0.92);
  color: #ffe4a9;
  font-size: 13px;
  font-weight: 700;
  text-align: center;
}
.coach-bubble {
  margin: 0 8px 8px;
  padding: 10px 14px;
  border-radius: 14px;
  border: 1px solid rgba(255,255,255,0.12);
  background: rgba(245, 236, 216, 0.95);
  color: #211f1a;
  font-size: 14px;
  line-height: 1.55;
  text-align: left;
}
.exit-mode-button {
  min-width: 44px;
  min-height: 44px;
  margin-left: 8px;
  padding: 0 14px;
  border: 1px solid rgba(255,255,255,0.2);
  border-radius: 999px;
  color: #d8e4df;
  background: rgba(0,0,0,0.25);
  cursor: pointer;
  font-size: 13px;
  font-weight: 800;
}


/* Chrono river + slim HUD additions */
.last-discard[hidden] { display: none !important; }
.river-lane { display: none !important; } /* legacy seat piles retired */
@media (min-width: 1024px) {
  .avatar-button { width: 104px; height: 104px; border-radius: 24px; }
  .opponent:nth-child(1) .avatar-button { width: 112px; height: 112px; }
}


/* star3 carry-over: 胡 button pops above action row */
.actions { position: relative; }
.action-button.win {
  position: absolute;
  right: 0;
  bottom: calc(100% + 8px);
  min-width: 72px;
  min-height: 72px;
  padding: 12px 18px;
  border-radius: 999px;
  font-size: 22px;
  font-weight: 900;
  z-index: 6;
  box-shadow:
    0 0 0 3px rgba(255, 220, 120, 0.55),
    0 8px 24px rgba(0, 0, 0, 0.45),
    0 0 28px rgba(255, 190, 60, 0.55);
  animation: win-button-glow 1.6s ease-in-out infinite;
}
@keyframes win-button-glow {
  0%, 100% { box-shadow: 0 0 0 3px rgba(255, 220, 120, 0.45), 0 8px 24px rgba(0,0,0,0.45), 0 0 18px rgba(255,190,60,0.4); }
  50% { box-shadow: 0 0 0 4px rgba(255, 230, 150, 0.75), 0 10px 28px rgba(0,0,0,0.5), 0 0 36px rgba(255,200,80,0.7); }
}
@media (prefers-reduced-motion: reduce) {
  .action-button.win { animation: none; }
}


/* ============================================================
   Declutter / Star3 layout pass — 2026-09-19
   Goals: separate avatar / melds / round HUD / river glow;
   kill double last-discard ghost; own melds beside hand;
   larger bottom hand; action dock must not cover hand hit area.
   ============================================================ */

.table-header {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.table-title { min-width: 0; }
.table-hud {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 8px;
  margin-left: auto;
  margin-right: 8px;
  max-width: min(100%, 420px);
}
.table-hud .turn-status {
  margin: 0;
  min-height: 28px;
  padding: 4px 12px;
  font-size: 12px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.42);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}
.table-hud .round-info {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 6px;
  margin: 0;
}
.table-hud .round-info > span {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 9px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.38);
  border: 1px solid rgba(255, 255, 255, 0.08);
  color: #c9d8d2;
  white-space: nowrap;
  font-size: 11px;
}

/* Ghost kill: never show the duplicate callout tile */
#last-discard,
.last-discard {
  display: none !important;
}

.table-center .rivers-board {
  flex: 1 1 auto;
  width: 100%;
  min-height: 96px;
  margin: 0;
}

.player-public { display: none !important; }

.hand-zone {
  display: flex;
  flex-direction: column;
  gap: 4px;
  z-index: 30;
}
.hand-row {
  display: flex;
  flex-direction: row;
  align-items: flex-end;
  gap: 8px;
  width: 100%;
  min-width: 0;
}
.hand-melds {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 4px;
  flex: 0 0 auto;
  max-width: 38%;
  min-height: 0;
  padding-bottom: 4px;
}
.hand-melds:empty { display: none; }
.hand-melds .meld-row {
  display: inline-flex;
  gap: 2px;
  padding: 2px 4px;
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.28);
  border: 1px solid rgba(255, 255, 255, 0.1);
}
.hand-melds .tile {
  width: 28px;
  height: 36px;
  font-size: 11px;
}
.hand-row .hand,
.hand-row .player-hand {
  flex: 1 1 auto;
  min-width: 0;
}

@media (orientation: portrait) {
  .table-header { position: relative; z-index: 12; }
  .table-hud { width: 100%; margin: 0; max-width: none; justify-content: flex-start; }
  .hand-melds { max-width: 42%; }
  .hand-melds .tile { width: 26px; height: 34px; font-size: 10px; }
  .actions {
    position: relative;
    z-index: 25;
    margin-bottom: 4px;
  }
  .hand, .player-hand { min-height: 76px; }
  .tile-button {
    flex: 0 0 clamp(44px, 12vw, 62px);
    min-width: 44px;
    min-height: 70px;
    height: 70px;
  }
}

@media (orientation: landscape) {
  :root {
    --hand-band: 96px;
    --dock-band: 52px;
    --public-band: 0px;
    --edge-gutter: 10px;
    --seat-corridor: 22%;
  }

  .table-header {
    position: absolute;
    z-index: 40;
    inset: 4px 8px auto;
    min-height: 40px;
    padding: 0;
    background: transparent;
    pointer-events: none;
  }
  .table-header > * { pointer-events: auto; }
  .table-title .eyebrow { display: none; }
  .table-title h1 { font-size: 14px; margin: 0; text-shadow: 0 1px 2px rgba(0,0,0,.55); }
  .table-hud {
    margin-left: 12px;
    margin-right: 8px;
    max-width: min(52vw, 480px);
  }
  .table-hud .turn-status { min-height: 26px; font-size: 11px; padding: 3px 10px; }
  .table-hud .round-info > span { font-size: 10px; padding: 2px 7px; }

  .opponents {
    position: absolute;
    inset: 44px var(--edge-gutter) calc(var(--hand-band) + var(--dock-band) + 10px);
    z-index: 28;
    pointer-events: none;
  }
  .opponent {
    position: absolute;
    width: var(--seat-corridor);
    max-width: 160px;
    min-height: 96px;
    max-height: 140px;
    padding: 0;
    overflow: visible;
    background: transparent;
    border: 0;
    box-shadow: none;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    z-index: 28;
    pointer-events: auto;
  }
  .opponent:nth-child(1) { top: 0; left: 50%; transform: translateX(-50%); width: 26%; }
  .opponent:nth-child(2) { top: 36px; left: 0; align-items: flex-start; }
  .opponent:nth-child(3) { top: 36px; right: 0; left: auto; align-items: flex-end; }

  .avatar-button {
    width: 72px;
    height: 72px;
    border-radius: 18px;
    box-shadow: 0 6px 16px rgba(0,0,0,.35);
  }
  .opponent-main { width: 100%; text-align: center; }
  .opponent:nth-child(2) .opponent-main { text-align: left; }
  .opponent:nth-child(3) .opponent-main { text-align: right; }
  .opponent-name { margin: 0; justify-content: center; }
  .opponent:nth-child(2) .opponent-name { justify-content: flex-start; }
  .opponent:nth-child(3) .opponent-name { justify-content: flex-end; }
  .opponent-name strong {
    font-size: 12px;
    text-shadow: 0 1px 2px rgba(0,0,0,.7);
  }
  .opponent .meld-row {
    justify-content: center;
    margin-top: 2px;
    max-width: 100%;
    padding: 2px;
    border-radius: 8px;
    background: rgba(0,0,0,.25);
  }
  .opponent:nth-child(2) .meld-row { justify-content: flex-start; }
  .opponent:nth-child(3) .meld-row { justify-content: flex-end; }
  .opponent .meld-row .tile { width: 20px; height: 26px; font-size: 8px; }
  .opponent .river,
  .opponent-meta,
  .opponent-backs { display: none !important; }

  .table-center {
    position: absolute;
    left: calc(var(--seat-corridor) + 14px);
    right: calc(var(--seat-corridor) + 14px);
    top: 86px;
    bottom: calc(var(--hand-band) + var(--dock-band) + 12px);
    z-index: 18;
    overflow: hidden;
    padding: 0;
  }
  .rivers-board {
    height: 100%;
    min-height: 0;
    transform: none !important;
    padding: 10px 12px;
  }

  .actions {
    position: absolute;
    z-index: 32;
    left: 50%;
    transform: translateX(-50%);
    right: auto;
    bottom: calc(var(--hand-band) + env(safe-area-inset-bottom, 0px) + 4px);
    width: max-content;
    max-width: min(70%, 520px);
    justify-content: center;
    flex-wrap: wrap;
    gap: 10px;
    pointer-events: auto;
  }
  .action-button {
    min-width: 56px;
    min-height: 52px;
    border-radius: 999px;
    font-size: 16px;
    font-weight: 800;
    box-shadow: 0 4px 14px rgba(0,0,0,.35);
  }
  .action-button.win {
    min-width: 72px;
    min-height: 72px;
    border-radius: 999px;
    font-size: 22px;
  }

  .bot-advice {
    position: absolute;
    z-index: 31;
    left: max(8px, env(safe-area-inset-left));
    bottom: calc(var(--hand-band) + env(safe-area-inset-bottom, 0px) + 8px);
    max-width: min(36%, 280px);
  }
  .table-screen:has(#coach-bubble:not([hidden])) .bot-advice {
    display: none !important;
  }

  .hand-zone {
    position: absolute;
    z-index: 30;
    left: max(6px, env(safe-area-inset-left));
    right: max(6px, env(safe-area-inset-right));
    bottom: 0;
    height: calc(var(--hand-band) + env(safe-area-inset-bottom, 0px));
    min-height: calc(var(--hand-band) + env(safe-area-inset-bottom, 0px));
    padding: 0 0 max(4px, env(safe-area-inset-bottom));
    margin: 0;
    background: linear-gradient(180deg, transparent, rgba(0,0,0,.28) 35%);
  }
  .hand-heading { display: none; }
  .hand-row { height: 100%; padding: 0 4px; }
  .hand-melds {
    max-width: 30%;
    padding-bottom: max(6px, env(safe-area-inset-bottom));
  }
  .hand-melds .tile { width: 30px; height: 40px; font-size: 12px; }
  .hand, .player-hand {
    min-height: 72px;
    height: 100%;
    align-items: flex-end;
    gap: 3px;
    padding: 4px 4px max(6px, env(safe-area-inset-bottom));
    overflow-x: auto;
  }
  .tile-button {
    flex: 0 0 clamp(40px, 5.6vw, 58px);
    width: auto;
    min-width: 40px;
    max-width: 58px;
    min-height: 64px;
    height: 64px;
  }
  .tile-button.selected {
    transform: perspective(480px) rotateX(8deg) translateY(-10px);
  }

  .app-shell.large-tiles {
    --hand-band: 110px;
  }
  .app-shell.large-tiles .tile-button {
    flex: 0 0 clamp(48px, 6.4vw, 68px);
    min-width: 48px;
    max-width: 68px;
    min-height: 76px;
    height: 76px;
  }
}

@media (orientation: landscape) and (min-width: 1024px) {
  :root { --hand-band: 118px; --seat-corridor: 18%; }
  .avatar-button { width: 96px; height: 96px; border-radius: 24px; }
  .opponent { max-height: 160px; }
  .hand-melds .tile { width: 36px; height: 48px; font-size: 14px; }
  .tile-button {
    flex: 0 0 clamp(56px, 4.4vw, 84px);
    min-width: 56px; max-width: 84px; min-height: 88px; height: 88px;
  }
}

/* --- midgame: keep river in well center; keep opponent melds out of the felt --- */
.table-center .rivers-board {
  /* 牌池必須從頂端自然排列，否則長牌河置中後，上半段會落在捲動範圍之外。 */
  display: block;
}
.river-chrono { min-height: 100%; justify-content: flex-start; }
.river-chrono-tiles { flex-shrink: 0; align-content: flex-start; }
.opponents .opponent .meld-row {
  max-width: 100%;
  flex-wrap: wrap;
  justify-content: center;
}
/* Desktop/portrait 3-up strip: leave a clear gutter under avatars before river tiles */
@media (orientation: portrait), (min-width: 900px) {
  .table-center .rivers-board {
    padding-top: 18px;
    padding-bottom: 18px;
  }
  .opponents .opponent {
    overflow: hidden;
  }
  .opponents .opponent .meld-row .tile {
    width: 20px;
    height: 26px;
    font-size: 8px;
  }
  .avatar-button {
    width: 96px;
    height: 96px;
  }
}
@media (orientation: landscape) {
  .river-chrono-tiles {
    max-width: 92%;
    margin-inline: auto;
  }
  /* Opposite seat (first child = seat 2) sits on top edge — keep melds above the well */
  .opponents .opponent:nth-child(1) {
    max-height: none;
  }
  .opponents .opponent:nth-child(1) .meld-row {
    position: relative;
    z-index: 29;
  }
}
/* === avatar scale + remaining polish 2026-09-19 === */
:root, .app-shell {
  --avatar-size: 84px;
  --avatar-size-opp: 96px;
}

.avatar-button {
  width: var(--avatar-size) !important;
  height: var(--avatar-size) !important;
  border-radius: 22px !important;
  box-shadow:
    0 10px 22px rgba(0, 0, 0, 0.45),
    0 2px 0 rgba(255, 220, 140, 0.25),
    inset 0 1px 0 rgba(255, 255, 255, 0.2);
  transform: perspective(420px) rotateX(6deg);
  overflow: hidden;
}
.avatar-button img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center top;
  display: block;
}
.opponent:nth-child(1) .avatar-button {
  width: var(--avatar-size-opp) !important;
  height: var(--avatar-size-opp) !important;
  border-radius: 26px !important;
}

@media (orientation: portrait) {
  .app-shell {
    --avatar-size: 76px;
    --avatar-size-opp: 84px;
  }
}

@media (max-width: 430px) {
  .app-shell {
    --avatar-size: 64px;
    --avatar-size-opp: 70px;
  }
  .avatar-button {
    transform: perspective(360px) rotateX(4deg);
    border-radius: 16px !important;
  }
}

@media (orientation: landscape) and (max-height: 500px) {
  .app-shell {
    --avatar-size: 68px;
    --avatar-size-opp: 76px;
  }
}

@media (orientation: landscape) and (min-width: 900px) {
  .app-shell {
    --avatar-size: 108px;
    --avatar-size-opp: 124px;
  }
  .opponents .opponent:nth-child(2),
  .opponents .opponent:nth-child(3) {
    top: 28px;
  }
  .opponents .opponent:nth-child(1) {
    top: -4px;
  }
}

@media (min-width: 1024px) {
  .app-shell {
    --avatar-size: 112px;
    --avatar-size-opp: 128px;
  }
}

.table-hud .turn-status,
.turn-status.is-mine {
  color: #ffe6a8 !important;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.65);
  font-weight: 700;
}

.hand-melds .tile {
  width: 34px;
  height: 46px;
  font-size: 13px;
}
@media (min-width: 900px) {
  .hand-melds .tile {
    width: 40px;
    height: 54px;
    font-size: 15px;
  }
}

@media (orientation: landscape) {
  .actions .action-button {
    min-width: 52px;
    min-height: 52px;
    font-size: 16px;
    border-radius: 999px;
  }
  .actions .action-button.win {
    min-width: 64px;
    min-height: 64px;
    font-size: 20px;
  }
}
/* === speech + river fill 2026-09-19b === */
.opponent {
  overflow: visible;
}
.opponent .avatar-button {
  position: relative;
  z-index: 6;
}
.opponent .opponent-main {
  position: relative;
  z-index: 5;
}
.opponent .speech {
  z-index: 3;
}

/* Point speech toward the table, not over the face */
.opponent:nth-child(1) .speech {
  left: 50%;
  top: auto;
  bottom: 0;
  transform: translate(-50%, calc(100% + 8px));
  max-width: 180px;
}
.opponent:nth-child(2) .speech {
  left: calc(100% + 8px);
  top: 12px;
  bottom: auto;
  transform: none;
  border-radius: 4px 12px 12px 12px;
  max-width: 140px;
}
.opponent:nth-child(3) .speech {
  left: auto;
  right: calc(100% + 8px);
  top: 12px;
  bottom: auto;
  transform: none;
  border-radius: 12px 4px 12px 12px;
  max-width: 140px;
}
#player-speech,
.player-speech {
  left: 12px !important;
  top: auto !important;
  bottom: calc(100% + 8px) !important;
  transform: none !important;
  z-index: 34;
}

/* River tiles: use the empty felt — bigger faces */
.rivers-board .tile,
.river-chrono-tiles .tile {
  width: 36px !important;
  height: 48px !important;
  font-size: 14px !important;
}
.river-chrono-tiles {
  gap: 5px 6px !important;
  max-width: 96%;
  margin-inline: auto;
}
@media (min-width: 900px) {
  .rivers-board .tile,
  .river-chrono-tiles .tile {
    width: 44px !important;
    height: 58px !important;
    font-size: 17px !important;
  }
  .river-chrono-tiles {
    gap: 6px 8px !important;
  }
}
@media (min-width: 1200px) {
  .rivers-board .tile,
  .river-chrono-tiles .tile {
    width: 50px !important;
    height: 66px !important;
    font-size: 19px !important;
  }
}
@media (orientation: landscape) and (max-height: 500px) {
  .rivers-board .tile,
  .river-chrono-tiles .tile {
    width: 28px !important;
    height: 36px !important;
    font-size: 11px !important;
  }
}
@media (max-width: 430px) {
  .rivers-board .tile,
  .river-chrono-tiles .tile {
    width: 30px !important;
    height: 40px !important;
    font-size: 12px !important;
  }
  .opponent:nth-child(2) .speech,
  .opponent:nth-child(3) .speech {
    max-width: 110px;
    font-size: 11px;
  }
}

/* Claimed discards: keep in-flow but don't look like a second glowing ghost under latest */
.river-chrono .tile.claimed {
  opacity: 0.32 !important;
  filter: grayscale(0.4);
  box-shadow: none !important;
  animation: none !important;
  z-index: 0 !important;
}
.river-chrono .tile.latest-discard {
  z-index: 5 !important;
}
/* === PC hand fit fix 2026-09-19 — all tiles visible, no scrollbar === */
@media (min-width: 900px) {
  .hand-zone,
  .hand-row {
    width: 100%;
    max-width: 100%;
    min-width: 0;
    box-sizing: border-box;
  }
  .hand-row {
    display: flex;
    flex-direction: row;
    align-items: flex-end;
    gap: 6px;
    overflow: hidden;
  }
  .hand-melds {
    flex: 0 1 auto;
    max-width: 28%;
    min-width: 0;
    overflow: hidden;
  }
  .hand,
  .player-hand {
    flex: 1 1 auto;
    display: flex !important;
    flex-wrap: nowrap !important;
    justify-content: center !important;
    align-items: flex-end;
    gap: 2px !important;
    width: auto !important;
    min-width: 0 !important;
    max-width: 100% !important;
    overflow-x: hidden !important;
    overflow-y: visible !important;
    scrollbar-width: none;
  }
  .hand::-webkit-scrollbar,
  .player-hand::-webkit-scrollbar {
    display: none !important;
    height: 0 !important;
  }
  /* Scale tiles to fit ~17 in the remaining row (melds already took some width) */
  .hand .tile-button,
  .player-hand .tile-button {
    flex: 1 1 0 !important;
    width: auto !important;
    min-width: 0 !important;
    max-width: 56px !important;
    height: auto !important;
    aspect-ratio: 30 / 40;
    margin-left: 0 !important;
    box-sizing: border-box;
  }
  .hand .tile-button.drawn,
  .player-hand .tile-button.drawn {
    margin-left: 6px !important;
    flex: 1.05 1 0 !important;
  }
  .app-shell.large-tiles .hand .tile-button,
  .app-shell.large-tiles .player-hand .tile-button {
    max-width: 62px !important;
  }
}

/* Wide desktop: still fit, allow slightly larger cap */
@media (min-width: 1200px) {
  .hand .tile-button,
  .player-hand .tile-button {
    max-width: 60px !important;
  }
  .app-shell.large-tiles .hand .tile-button,
  .app-shell.large-tiles .player-hand .tile-button {
    max-width: 66px !important;
  }
}

/* === W7：窄螢幕直式牌桌（2.5D 僅保留在橫式／桌機） === */
@media (orientation: portrait) and (max-width: 700px) {
  #app {
    width: 100%;
    max-width: 100vw;
    overflow-x: visible;
  }

  #table {
    width: 100%;
    max-width: 100%;
    min-width: 0;
    height: 100dvh;
    min-height: 0;
    padding: max(8px, env(safe-area-inset-top)) 8px max(6px, env(safe-area-inset-bottom));
    overflow: hidden;
    grid-template-rows: auto auto minmax(0, 1fr) auto auto auto auto auto auto;
    gap: 5px;
  }

  #table > *,
  #table header > *,
  #table .hand-row > * {
    min-width: 0;
    max-width: 100%;
  }

  .table-header {
    min-height: 44px;
    flex-wrap: nowrap;
    gap: 6px;
    padding: 0;
  }
  .table-title { flex: 0 1 auto; }
  .table-title .eyebrow { display: none; }
  .table-header h1 {
    font-size: 17px;
    letter-spacing: 0.02em;
    white-space: nowrap;
  }
  .table-hud {
    flex: 1 1 auto;
    width: auto;
    margin: 0;
    gap: 3px;
    flex-wrap: wrap;
  }
  .table-hud .turn-status {
    min-height: 24px;
    padding: 2px 8px;
    font-size: 11px;
  }
  .table-hud .round-info { gap: 3px; }
  .table-hud .round-info > span {
    padding: 2px 6px;
    font-size: 10px;
  }
  .settings-panel { flex: 0 0 auto; }
  .settings-panel summary {
    min-width: 44px;
    min-height: 44px;
    padding-inline: 8px;
  }

  /* 三家固定在牌桌上緣；卡片只保留可辨識且不撐寬的資訊。 */
  .opponents {
    width: 100%;
    max-width: 100%;
    min-width: 0;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 4px;
  }
  .opponents .opponent {
    display: grid;
    grid-template-columns: 44px minmax(0, 1fr);
    align-items: center;
    gap: 4px;
    width: 100%;
    min-width: 0;
    min-height: 58px;
    padding: 4px;
    overflow: visible;
    text-align: left;
    transform: none;
  }
  .opponents .opponent .avatar-button,
  .opponents .opponent:nth-child(1) .avatar-button {
    width: 44px !important;
    height: 44px !important;
    margin: 0;
    border-radius: 12px !important;
    transform: none !important;
  }
  .opponents .opponent-main {
    width: 100%;
    min-width: 0;
    text-align: left;
  }
  .opponents .opponent-name {
    display: block;
    margin: 0;
    line-height: 1.15;
  }
  .opponents .opponent-name strong {
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 11px;
  }
  .opponents .opponent-name span {
    display: block;
    font-size: 9px;
  }
  .opponents .opponent-main > .meld-row {
    display: block;
    min-height: 14px;
    margin: 2px 0 0;
    padding: 0;
    overflow: hidden;
    background: none;
  }
  .opponents .opponent-main > .meld-row > .meld-row { display: none; }
  .opponents .opponent-main > .meld-row::after {
    content: var(--locale-meld-1, "Meld 1");
    color: #afc6bd;
    font-size: 9px;
    white-space: nowrap;
  }
  .opponents .opponent-main > .meld-row:has(> .meld-row:nth-child(2))::after { content: var(--locale-meld-2, "Meld 2"); }
  .opponents .opponent-main > .meld-row:has(> .meld-row:nth-child(3))::after { content: var(--locale-meld-3, "Meld 3"); }
  .opponents .opponent-main > .meld-row:has(> .meld-row:nth-child(4))::after { content: var(--locale-meld-4, "Meld 4"); }

  /* 泡泡朝牌桌展開，但三個定位點都留在視窗內。 */
  .opponents .opponent .speech,
  .opponents .opponent:nth-child(1) .speech,
  .opponents .opponent:nth-child(2) .speech,
  .opponents .opponent:nth-child(3) .speech {
    top: calc(100% + 4px);
    bottom: auto;
    width: max-content;
    max-width: min(104px, 28vw);
    padding: 5px 7px;
    font-size: 10px;
  }
  .opponents .opponent:nth-child(1) .speech {
    left: 0;
    right: auto;
    transform: none;
  }
  .opponents .opponent:nth-child(2) .speech {
    left: 50%;
    right: auto;
    transform: translateX(-50%);
  }
  .opponents .opponent:nth-child(3) .speech {
    left: auto;
    right: 0;
    transform: none;
  }

  /* 中央牌河吃掉剩餘高度，內容多時只在牌河內捲動。 */
  .table-center {
    width: 100%;
    max-width: 100%;
    min-width: 0;
    min-height: 0;
    padding: 0;
    overflow: hidden;
  }
  .table-center .rivers-board {
    width: 100%;
    max-width: 100%;
    min-width: 0;
    min-height: 0;
    height: 100%;
    padding: 10px 8px;
    overflow: auto;
    transform: none !important;
  }
  .river-chrono,
  .river-chrono-tiles {
    width: 100%;
    max-width: 100%;
    min-width: 0;
  }
  .river-chrono.is-empty::after {
    padding: 12px 6px;
    color: rgba(200, 220, 210, 0.28);
  }

  .actions {
    width: 100%;
    max-width: 100%;
    margin-bottom: 2px;
    gap: 5px;
  }
  .action-button {
    min-width: 52px;
    min-height: 44px;
    padding-inline: 10px;
  }

  /* 副露獨立一列；17 張手牌由 hand-break 固定切成 9 + 8。 */
  .hand-zone,
  .hand-row,
  .hand,
  .player-hand {
    width: 100%;
    max-width: 100%;
    min-width: 0;
  }
  .hand-zone {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    grid-template-rows: minmax(36px, auto) auto;
    align-items: center;
    height: auto;
    min-height: 0;
    padding: 0 0 max(3px, env(safe-area-inset-bottom));
    overflow: visible;
  }
  .hand-zone .player-identity {
    grid-column: 1;
    grid-row: 1;
  }
  .hand-zone .hand-heading {
    grid-column: 2;
    grid-row: 1;
  }
  .hand-zone .player-speech,
  .hand-zone .hand-row {
    grid-column: 1 / -1;
  }
  .hand-zone .hand-row { grid-row: 2; }
  .hand-row {
    height: auto;
    flex-direction: column;
    align-items: stretch;
    gap: 2px;
    padding: 0;
    overflow: visible;
  }
  .hand-melds {
    width: 100%;
    max-width: 100%;
    padding: 0 2px;
    overflow-x: auto;
    overflow-y: hidden;
  }
  .hand-melds .tile {
    width: 26px;
    height: 34px;
    font-size: 10px;
  }
  .hand,
  .player-hand,
  .app-shell.large-tiles .hand,
  .app-shell.large-tiles .player-hand {
    display: flex;
    flex: 0 0 auto;
    flex-wrap: wrap;
    justify-content: center;
    align-items: flex-end;
    gap: 2px 0;
    height: auto;
    min-height: 124px;
    padding: 2px 3px 0;
    overflow: visible;
    scroll-snap-type: none;
  }
  .hand-break,
  .app-shell.large-tiles .hand-break {
    display: block;
    flex: 0 0 100%;
    width: 0;
    height: 0;
  }
  .hand .tile-button,
  .player-hand .tile-button,
  .app-shell.large-tiles .hand .tile-button,
  .app-shell.large-tiles .player-hand .tile-button {
    flex: 0 0 44px;
    width: 44px;
    min-width: 44px;
    max-width: 44px;
    min-height: 60px;
    height: 60px;
    margin-left: -7px;
    font-size: 12px;
    transform: none;
    scroll-snap-align: none;
  }
  .hand .tile-button:first-child,
  .hand-break + .tile-button,
  .player-hand .tile-button:first-child,
  .player-hand .hand-break + .tile-button {
    margin-left: 0;
  }
  .hand .tile-button.drawn,
  .player-hand .tile-button.drawn,
  .app-shell.large-tiles .hand .tile-button.drawn,
  .app-shell.large-tiles .player-hand .tile-button.drawn {
    margin-left: -7px;
    border-bottom-color: var(--gold);
    box-shadow:
      0 0 0 2px rgba(231, 185, 91, 0.72),
      2px 5px 8px rgba(0, 0, 0, 0.32);
  }
  .hand .tile-button.selected,
  .player-hand .tile-button.selected {
    transform: translateY(-5px);
  }
}

/* === W8 playtest fixes: four-seat selection, role HUD, calls, audio mixer === */
.select-seats { grid-template-columns: repeat(4, minmax(0, 1fr)); width: min(100%, 700px); }
.avatar-wrap, .player-avatar-wrap { position: relative; display: inline-grid; place-items: center; }
.dealer-badge {
  position: absolute; z-index: 12; top: -7px; right: -7px;
  display: grid; place-items: center; min-width: 28px; min-height: 28px; padding: 2px 6px;
  border: 2px solid #fff0b8; border-radius: 999px; color: #271d0d; background: #f2bf55;
  box-shadow: 0 3px 10px rgba(0,0,0,.45); font-size: 13px; font-weight: 950; line-height: 1;
}
.dealer-badge small { display: block; margin-top: 2px; font-size: 9px; white-space: nowrap; }
.action-banner {
  position: absolute; z-index: 40; left: 50%; bottom: -10px; transform: translate(-50%, 100%);
  min-width: 58px; padding: 8px 13px; border: 2px solid #fff0b8; border-radius: 12px;
  color: #271d0d; background: #ffd36f; box-shadow: 0 8px 22px rgba(0,0,0,.48);
  font-size: clamp(20px, 3vw, 28px); font-weight: 950; line-height: 1; text-align: center;
  pointer-events: none; animation: action-banner-life 1.2s ease-out both;
}
@keyframes action-banner-life {
  0% { opacity: 0; transform: translate(-50%, 85%) scale(.82); }
  14%, 72% { opacity: 1; transform: translate(-50%, 100%) scale(1); }
  100% { opacity: 0; transform: translate(-50%, 92%) scale(.94); }
}
.river-chrono .tile.claimed.claim-flash,
.rivers-board .tile.claimed.claim-flash {
  opacity: 1 !important; filter: brightness(1.2);
  outline: 3px solid #ff7a65; outline-offset: 2px;
  animation: claimed-tile-flash 1.2s ease-out both;
}
@keyframes claimed-tile-flash {
  0%, 55% { box-shadow: 0 0 0 3px #fff0b8, 0 0 24px 8px rgba(255,100,76,.9); }
  100% { box-shadow: none; opacity: .38; }
}
.player-identity {
  display: flex; align-items: center; gap: 8px; min-height: 42px; padding: 2px 4px;
  color: #fff5d8; font-size: 13px;
}
.player-identity img {
  display: block; width: 40px; height: 40px; border: 2px solid rgba(231,185,91,.8);
  border-radius: 11px; object-fit: cover; object-position: center top; background: #35685b;
}
.player-identity .dealer-badge { top: -6px; right: -9px; min-width: 24px; min-height: 24px; font-size: 11px; }
.turn-status.is-mine,
.table-hud .turn-status.is-mine {
  color: #10251f !important; background: #ffe18b !important; border: 2px solid #fff5cf;
  text-shadow: none !important; box-shadow: 0 0 0 2px rgba(32,78,65,.8), 0 0 22px rgba(255,225,139,.62);
  font-weight: 950;
}
.settings-card { width: min(260px, calc(100vw - 28px)); }
.settings-card .volume-label { grid-template-columns: 38px minmax(0, 1fr); }
.lobby-settings { margin-top: 12px; }
.lobby-settings .settings-card { left: 50%; right: auto; transform: translateX(-50%); text-align: left; }

@media (max-width: 520px) {
  .select-seats { gap: 4px; }
  .select-seat { gap: 3px; padding: 6px 3px; }
  .select-seat img { width: 44px; height: 44px; }
  .select-seat .seat-name { max-width: 76px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 11px; }
  .select-seat .seat-diff { display: none; }
  .select-seat-shuffle { min-height: 40px; margin-top: 1px; padding: 0 7px; font-size: 11px; }
  .action-banner { min-width: 52px; padding: 7px 10px; font-size: 20px; }
}

@media (orientation: landscape) {
  .player-identity { position: absolute; z-index: 35; left: 6px; bottom: 6px; }
  .hand-zone .hand-row { padding-left: 62px; }
}

@media (orientation: portrait) and (max-width: 700px) {
  .hand-zone .player-identity {
    gap: 6px;
    min-height: 36px;
    padding: 1px 4px;
    font-size: 12px;
  }
  .hand-zone .player-identity img {
    width: 34px;
    height: 34px;
    border-radius: 9px;
  }
  .hand-zone .player-identity .dealer-badge {
    top: -5px;
    right: -7px;
    min-width: 20px;
    min-height: 20px;
    padding: 1px 4px;
    font-size: 10px;
  }
  .hand-zone .hand-heading {
    min-height: 36px;
    align-items: center;
    padding-left: 8px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .action-banner, .river-chrono .tile.claimed.claim-flash { animation: none; }
}

/* === W9：玩家頭像依可用空間分級 === */
.player-identity {
  gap: 10px;
  min-height: 60px;
  font-size: 15px;
  font-weight: 800;
}
.player-identity img {
  width: 56px;
  height: 56px;
  border-width: 3px;
  border-radius: 14px;
  transition: border-color .18s ease, box-shadow .18s ease, filter .18s ease;
}
.player-identity .dealer-badge {
  top: -7px;
  right: -9px;
  min-width: 24px;
  min-height: 24px;
  padding: 2px 5px;
  font-size: 14px;
}
.player-identity.is-thinking img {
  border-color: #ffe18b;
  filter: brightness(1.08) saturate(1.08);
  box-shadow:
    0 0 0 3px rgba(255, 245, 207, .92),
    0 0 18px 7px rgba(231, 185, 91, .72);
  animation: player-turn-glow 1.6s ease-in-out infinite;
}
@keyframes player-turn-glow {
  50% {
    box-shadow:
      0 0 0 4px rgba(255, 245, 207, 1),
      0 0 28px 10px rgba(231, 185, 91, .88);
  }
}

@media (orientation: portrait) and (max-width: 700px) {
  .hand-zone .player-identity {
    gap: 7px;
    min-height: 60px;
    padding: 2px 4px;
    font-size: 14px;
  }
  .hand-zone .player-identity img {
    width: 56px;
    height: 56px;
    border-radius: 14px;
  }
  .hand-zone .player-identity .dealer-badge {
    top: -7px;
    right: -9px;
    min-width: 24px;
    min-height: 24px;
    padding: 2px 5px;
    font-size: 14px;
  }
  .hand-zone .hand-heading {
    min-height: 60px;
  }
}

@media (orientation: landscape) {
  .player-identity {
    bottom: 0;
    flex-direction: column;
    gap: 0;
    width: 64px;
    min-height: 0;
    padding: 0;
    font-size: 14px;
    line-height: 1.1;
    text-align: center;
  }
  .player-identity img {
    width: 56px;
    height: 56px;
    border-radius: 14px;
  }
  .player-identity > strong {
    position: absolute;
    z-index: 2;
    left: 50%;
    bottom: 2px;
    display: block;
    max-width: 58px;
    padding: 1px 4px;
    overflow: hidden;
    border-radius: 999px;
    background: rgba(5, 29, 24, .84);
    box-shadow: 0 1px 4px rgba(0, 0, 0, .45);
    text-overflow: ellipsis;
    transform: translateX(-50%);
    white-space: nowrap;
  }
  .hand-zone .hand-row { padding-left: 72px; }
}

@media (min-width: 1024px) {
  .player-identity {
    flex-direction: row;
    gap: 10px;
    width: auto;
    min-height: 104px;
    font-size: 17px;
    text-align: left;
  }
  .player-identity img {
    width: 104px;
    height: 104px;
    border-width: 3px;
    border-radius: 22px;
  }
  .player-identity > strong { max-width: 90px; }
  .player-identity > strong {
    position: static;
    padding: 0;
    overflow: visible;
    border-radius: 0;
    background: none;
    box-shadow: none;
    text-overflow: clip;
    transform: none;
  }
  .player-identity .dealer-badge {
    top: -8px;
    right: -10px;
    min-width: 28px;
    min-height: 28px;
    font-size: 15px;
  }
  .hand-zone .hand-row { padding-left: 212px; }
}

@media (prefers-reduced-motion: reduce) {
  .player-identity.is-thinking img { animation: none; }
}

/* ============================================================
   W11：六級響應式牌桌（M-P／M-L／N-P／T-L／D／DW）
   ============================================================ */
.app-shell {
  width: 100%;
  max-width: none;
}

#table {
  container: table / size;
}

.standee { display: none; }
.opponent-score {
  margin-left: auto;
  color: #f5d98e !important;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

/* M-L：短高橫向仍以觸控尺寸與完整手牌優先。 */
@media (orientation: landscape) and (max-height: 500px) {
  .hand .tile-button,
  .player-hand .tile-button,
  .app-shell.large-tiles .hand .tile-button,
  .app-shell.large-tiles .player-hand .tile-button {
    /* 17 張（剛摸牌、無副露）時整列會超出右緣，允許縮到 38px 讓最後一張看得到 */
    flex: 0 1 42px !important;
    width: 42px !important;
    min-width: 38px !important;
    max-width: 42px !important;
    height: 59px !important;
    min-height: 59px !important;
    aspect-ratio: auto;
  }
  .hand-zone .hand-row { padding-left: 66px; }
  .actions .action-button { min-height: 44px; }
}

/* N-P：不再落入手機固定 44px；上、中、下三列各自伸縮。 */
@media (min-width: 481px) and (max-width: 899px) and (orientation: portrait) and (min-height: 700px) {
  #table {
    display: grid;
    grid-template-areas:
      "header"
      "opponents"
      "center"
      "goal"
      "coach"
      "advice"
      "actions"
      "hand";
    /* 手牌列改由內容決定高度（兩列牌＋標題），中央牌桌吃剩餘空間，
       否則手牌內層會比外框高，最後幾張被切掉。 */
    grid-template-rows: auto minmax(126px, 15vh) minmax(0, 1fr) auto auto auto auto auto;
    gap: 6px;
    width: 100%;
    height: 100dvh;
    min-height: 0;
    max-height: 100dvh;
    padding: 10px 12px 8px;
    overflow: hidden;
  }
  .table-header { grid-area: header; }
  .opponents { grid-area: opponents; }
  .table-center { grid-area: center; min-height: 0; overflow: hidden; }
  #mode-goal-banner { grid-area: goal; }
  #coach-bubble { grid-area: coach; }
  #bot-advice { grid-area: advice; }
  .actions { grid-area: actions; }
  .hand-zone { grid-area: hand; }
  .opponents {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 8px;
  }
  .opponents .opponent {
    position: relative;
    display: grid;
    grid-template-columns: clamp(56px, 12cqw, 78px) minmax(0, 1fr);
    width: 100%;
    min-width: 0;
    min-height: 88px;
    padding: 6px;
    transform: none;
  }
  /* 對家半身立繪鋪在三張資訊卡後方，填實窄高桌機的上方區帶。 */
  .opponents .opponent:nth-child(1) .standee {
    position: absolute;
    z-index: 0;
    inset: 0 auto 0 0;
    display: block;
    width: calc(300% + 16px);
    height: 100%;
    overflow: hidden;
    border-radius: 14px;
    opacity: .78;
    pointer-events: none;
  }
  .opponents .opponent:nth-child(1) .standee-body {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: center 22%;
  }
  .opponents .avatar-wrap,
  .opponents .opponent-main { position: relative; z-index: 1; }
  .opponents .opponent .avatar-button,
  .opponents .opponent:nth-child(1) .avatar-button {
    width: clamp(56px, 12cqw, 78px) !important;
    height: clamp(56px, 12cqw, 78px) !important;
    border-radius: 16px !important;
  }
  .opponents .opponent-main { min-width: 0; text-align: left; }
  .opponents .opponent-name { display: grid; gap: 1px; justify-content: start; }
  .opponents .opponent-name strong { overflow: hidden; font-size: 12px; text-overflow: ellipsis; white-space: nowrap; }
  .opponents .opponent-name span { font-size: 10px; }
  .opponents .opponent-main > .meld-row { max-height: 26px; overflow: hidden; }
  .table-center .rivers-board { height: 100%; min-height: 0; }
  .rivers-board .tile,
  .river-chrono-tiles .tile {
    width: clamp(38px, 7cqw, 46px) !important;
    height: clamp(51px, 9.33cqw, 62px) !important;
  }
  .hand-zone {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    grid-template-rows: 42px minmax(0, 1fr);
    margin: 0;
    padding: 0;
    overflow: visible;
  }
  .hand-zone .player-identity { grid-column: 1; grid-row: 1; min-height: 42px; }
  .hand-zone .player-identity img { width: 40px; height: 40px; }
  .hand-zone .hand-heading { grid-column: 2; grid-row: 1; min-height: 42px; }
  .hand-zone .hand-row { grid-column: 1 / -1; grid-row: 2; height: 100%; padding: 0; }
  .hand, .player-hand,
  .app-shell.large-tiles .hand,
  .app-shell.large-tiles .player-hand {
    display: flex !important;
    flex-wrap: wrap !important;
    align-content: end;
    justify-content: center !important;
    gap: 2px 0 !important;
    min-height: 118px;
    padding: 0 5px;
    overflow: visible !important;
  }
  .hand-break,
  .app-shell.large-tiles .hand-break { display: block; flex: 0 0 100%; height: 0; }
  .hand .tile-button,
  .player-hand .tile-button,
  .app-shell.large-tiles .hand .tile-button,
  .app-shell.large-tiles .player-hand .tile-button {
    flex: 0 0 clamp(52px, 8.8cqw, 60px) !important;
    width: clamp(52px, 8.8cqw, 60px) !important;
    min-width: 52px !important;
    max-width: 60px !important;
    height: clamp(72px, 12.32cqw, 84px) !important;
    min-height: 72px !important;
    margin-left: -3px !important;
    aspect-ratio: auto;
  }
  .hand .tile-button:first-child,
  .hand .hand-break + .tile-button { margin-left: 0 !important; }
}

/* T-L：加大牌桌內容，不放全身立繪。 */
@media (min-width: 900px) and (max-width: 1279px) and (orientation: landscape) and (min-height: 501px) {
  #table { max-width: none; }
  .table-center { left: 19%; right: 19%; }
  .rivers-board .tile,
  .river-chrono-tiles .tile {
    width: clamp(32px, 3.1cqw, 40px) !important;
    height: clamp(43px, 4.15cqw, 54px) !important;
  }
  .hand .tile-button,
  .player-hand .tile-button,
  .app-shell.large-tiles .hand .tile-button,
  .app-shell.large-tiles .player-hand .tile-button {
    flex: 0 0 clamp(60px, 5.2cqw, 68px) !important;
    width: clamp(60px, 5.2cqw, 68px) !important;
    min-width: 60px !important;
    max-width: 68px !important;
    height: clamp(84px, 7.28cqw, 95px) !important;
    min-height: 84px !important;
    aspect-ratio: auto;
  }
}

/* D／DW：左右站姿、對家半身、中欄牌河；底部手牌使用全寬。 */
@media (min-width: 1280px) and (min-height: 700px) {
  #table {
    display: grid;
    grid-template-columns: minmax(220px, 1.1fr) minmax(620px, 2.2fr) minmax(220px, 1.1fr);
    grid-template-rows: 58px minmax(142px, 21vh) minmax(210px, 1fr) auto minmax(90px, 16vh) minmax(132px, 18vh);
    grid-template-areas:
      "header header header"
      "left opposite right"
      "left center right"
      "left actions right"
      "advice advice advice"
      "hand hand hand";
    gap: 6px 14px;
    width: 100%;
    max-width: none;
    height: 100dvh;
    padding: 6px 14px 8px;
    overflow: hidden;
  }
  #bot-advice {
    grid-area: advice;
    position: relative;
    inset: auto;
    width: min(100%, 900px);
    max-width: none;
    max-height: 100%;
    margin: 0 auto;
    z-index: 31;
  }
  .table-header {
    grid-area: header;
    position: relative;
    inset: auto;
    min-height: 0;
    padding: 0 4px;
  }
  .table-hud { font-size: clamp(12px, 1.1cqw, 16px); }
  .opponents { display: contents; }
  .opponents .opponent {
    position: relative;
    inset: auto;
    display: flex;
    width: 100%;
    max-width: none;
    max-height: none;
    min-height: 0;
    padding: 0;
    border: 0;
    background: transparent;
    box-shadow: none;
    transform: none;
    overflow: visible;
  }
  .opponents .opponent:nth-child(1) {
    grid-area: opposite;
    flex-direction: row;
    justify-content: center;
    align-items: center;
  }
  .opponents .opponent:nth-child(2) {
    grid-area: left;
    flex-direction: column;
    justify-content: flex-end;
    align-items: center;
  }
  .opponents .opponent:nth-child(3) {
    grid-area: right;
    flex-direction: column;
    justify-content: flex-end;
    align-items: center;
  }
  .standee {
    position: relative;
    display: grid;
    place-items: end center;
    width: min(100%, clamp(220px, 20cqw, 380px));
    min-height: 0;
    overflow: hidden;
    pointer-events: none;
    filter: drop-shadow(0 16px 18px rgba(0, 0, 0, .42));
  }
  .opponent:nth-child(2) .standee,
  .opponent:nth-child(3) .standee { flex: 1 1 auto; max-height: calc(100dvh - 210px); }
  .opponent:nth-child(1) .standee { width: clamp(130px, 11cqw, 210px); height: 100%; }
  .standee-body {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: contain;
    object-position: center bottom;
  }
  .opponent:nth-child(1) .standee-body { object-fit: cover; object-position: center top; }
  .standee-expression {
    position: absolute;
    z-index: 2;
    top: 5%;
    left: 50%;
    width: clamp(54px, 30%, 104px);
    aspect-ratio: 1;
    border: 3px solid #ffe18b;
    border-radius: 50%;
    object-fit: cover;
    object-position: center top;
    box-shadow: 0 0 26px 8px rgba(255, 214, 102, .72);
    transform: translateX(-50%);
  }
  .opponent.is-reacting .standee {
    animation: standee-react .72s ease-out both;
    filter: drop-shadow(0 0 24px rgba(255, 213, 105, .9));
  }
  @keyframes standee-react {
    0% { transform: translateY(8px) scale(.98); }
    35% { transform: translateY(-8px) scale(1.025); }
    100% { transform: translateY(0) scale(1); }
  }
  .opponents .avatar-wrap {
    position: absolute;
    z-index: 8;
    left: 12px;
    bottom: 12px;
  }
  .opponents .opponent:nth-child(3) .avatar-wrap { left: auto; right: 12px; }
  .opponents .opponent:nth-child(1) .avatar-wrap { left: calc(50% + 62px); bottom: 10px; }
  .opponents .opponent .avatar-button,
  .opponents .opponent:nth-child(1) .avatar-button {
    width: 48px !important;
    height: 48px !important;
    border-radius: 13px !important;
    transform: none;
  }
  .opponents .opponent-main {
    position: absolute;
    z-index: 7;
    left: 66px;
    bottom: 12px;
    /* 橫向通用規則有 width: 100%，會蓋掉左右定位造成右側溢出，這裡要歸零 */
    width: auto;
    right: 12px;
    min-width: 0;
    max-width: calc(100% - 78px);
    overflow: hidden;
    padding: 5px 8px;
    border-radius: 10px;
    background: rgba(3, 24, 20, .82);
    text-align: left;
  }
  .opponents .opponent:nth-child(3) .opponent-main { left: 12px; right: 66px; max-width: none; }
  .opponents .opponent:nth-child(1) .opponent-main { left: calc(50% + 122px); right: 12px; bottom: 12px; max-width: none; }
  .opponents .opponent-name { min-width: 0; max-width: 100%; margin: 0; overflow: hidden; justify-content: flex-start; }
  .opponents .opponent-name strong { min-width: 0; overflow: hidden; font-size: 12px; text-overflow: ellipsis; white-space: nowrap; }
  .opponents .opponent-name span { font-size: 10px; }
  .opponents .opponent-score { flex: 0 0 auto; }
  .opponents .opponent-main > .meld-row { margin-top: 3px; }
  .opponents .opponent-main > .meld-row .tile { width: 20px; height: 27px; font-size: 8px; }
  /* 左右立繪與牌況各佔一列，副露增加時由內容自動保留高度。 */
  .opponents .opponent:nth-child(2),
  .opponents .opponent:nth-child(3) {
    display: grid;
    grid-template-columns: 48px minmax(0, 1fr);
    grid-template-rows: minmax(0, 1fr) auto;
    gap: 10px 6px;
    padding: 0 12px 12px;
    align-items: end;
  }
  .opponents .opponent:nth-child(2) .standee,
  .opponents .opponent:nth-child(3) .standee {
    grid-area: 1 / 1 / 2 / 3;
    justify-self: center;
    height: 100%;
    max-height: 100%;
  }
  .opponents .opponent:nth-child(2) .avatar-wrap,
  .opponents .opponent:nth-child(3) .avatar-wrap {
    grid-area: 2 / 1;
    position: relative;
    inset: auto;
  }
  .opponents .opponent:nth-child(2) .opponent-main,
  .opponents .opponent:nth-child(3) .opponent-main {
    grid-area: 2 / 2;
    position: relative;
    inset: auto;
    width: 100%;
    max-width: none;
  }
  .opponents .opponent:nth-child(3) { grid-template-columns: minmax(0, 1fr) 48px; }
  .opponents .opponent:nth-child(3) .avatar-wrap { grid-area: 2 / 2; }
  .opponents .opponent:nth-child(3) .opponent-main { grid-area: 2 / 1; }
  .opponents .speech { z-index: 10; }
  /* 大立繪已能辨認角色；只保留一份牌況與莊家標記。 */
  .opponents .avatar-wrap {
    position: absolute !important;
    z-index: 8;
    top: 20%;
    right: auto !important;
    bottom: auto !important;
    left: 50% !important;
    transform: translateX(-50%);
    pointer-events: none;
  }
  .opponents .avatar-button,
  .opponents .avatar-wrap .dealer-badge { display: none !important; }
  .opponents .opponent:nth-child(1) .opponent-main { left: calc(50% + 62px); }
  .opponents .opponent:nth-child(2) .opponent-main,
  .opponents .opponent:nth-child(3) .opponent-main { grid-area: 2 / 1 / 3 / 3; }
  .table-center {
    grid-area: center;
    position: relative;
    inset: auto;
    width: 100%;
    max-width: 1100px;
    min-height: 0;
    justify-self: center;
    overflow: hidden;
  }
  .table-center .rivers-board { height: 100%; min-height: 0; padding: 12px; }
  .rivers-board .tile,
  .river-chrono-tiles .tile {
    width: clamp(36px, 2.4cqw, 40px) !important;
    height: clamp(48px, 3.2cqw, 54px) !important;
    font-size: 15px !important;
  }
  .actions {
    grid-area: actions;
    position: relative;
    inset: auto;
    transform: none;
    width: 100%;
    max-width: 1100px;
    justify-self: center;
    padding: 2px;
  }
  .actions .action-button {
    min-height: clamp(44px, 5.5cqh, 52px);
  }
  #mode-goal-banner,
  #coach-bubble,
  #bot-advice { position: fixed; z-index: 50; }
  .hand-zone {
    grid-area: hand;
    position: relative;
    inset: auto;
    width: 100%;
    height: 100%;
    min-height: 0;
    margin: 0;
    padding: 0;
  }
  .hand-heading { display: none; }
  .hand-zone .player-identity {
    position: absolute;
    z-index: 4;
    left: 6px;
    bottom: 4px;
    flex-direction: row;
    width: auto;
    min-height: 0;
  }
  .player-identity img {
    width: clamp(56px, 4.5cqw, 112px);
    height: clamp(56px, 4.5cqw, 112px);
  }
  .hand-zone .hand-row { height: 100%; padding: 0 4px 0 clamp(126px, 11cqw, 220px); }
  .hand-melds { max-width: 22%; }
  .hand, .player-hand,
  .app-shell.large-tiles .hand,
  .app-shell.large-tiles .player-hand {
    display: flex !important;
    flex-wrap: nowrap !important;
    justify-content: center !important;
    align-items: flex-end;
    gap: 0 !important;
    min-width: 0;
    height: 100%;
    padding: 0 2px 4px;
    overflow: visible !important;
  }
  .hand-break { display: none !important; }
  .hand .tile-button,
  .player-hand .tile-button,
  .app-shell.large-tiles .hand .tile-button,
  .app-shell.large-tiles .player-hand .tile-button {
    flex: 0 0 clamp(60px, 5.2cqw, 78px) !important;
    width: clamp(60px, 5.2cqw, 78px) !important;
    min-width: 60px !important;
    max-width: 78px !important;
    height: clamp(84px, 7.28cqw, 109px) !important;
    min-height: 84px !important;
    margin-left: clamp(-9px, -.45cqw, -5px) !important;
    aspect-ratio: auto;
  }
  .hand .tile-button:first-child { margin-left: 0 !important; }
}

@media (min-width: 1680px) and (min-height: 900px) {
  #table {
    grid-template-columns: minmax(300px, 1.2fr) minmax(760px, 2fr) minmax(300px, 1.2fr);
  }
}

/* W12：窄手機直式把中央空間交給牌河；手牌尺寸與 8＋9 換列維持不變。 */
@media (orientation: portrait) and (max-width: 480px) {
  .table-center .rivers-board { padding: 8px 6px; }
  .rivers-board .tile,
  .river-chrono-tiles .tile {
    width: 40px !important;
    height: 54px !important;
    font-size: 15px !important;
  }
  .river-chrono-tiles { gap: 5px !important; max-width: 100%; }
}

@media (prefers-reduced-motion: reduce) {
  .opponent.is-reacting .standee { animation: none; }
}

/* 教學：選擇題長在教練泡泡裡；點牌步驟的手牌高亮 */
.coach-bubble .coach-text { margin: 0; }
.coach-bubble .quiz-question { margin: 8px 0 6px; font-weight: 700; }
.coach-bubble .quiz-options { display: flex; flex-wrap: wrap; gap: 6px; }
.coach-bubble .quiz-option {
  flex: 1 1 auto;
  min-width: 0;
  min-height: 40px;
  padding: 8px 12px;
  border-radius: 10px;
  border: 1px solid rgba(33, 31, 26, 0.25);
  background: #fffdf6;
  color: #211f1a;
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.coach-bubble .quiz-option:hover:not(:disabled) { background: #fff3cf; }
.coach-bubble .quiz-option:disabled { cursor: default; opacity: 0.75; }
.coach-bubble .quiz-option.is-right { background: #cdeacb; border-color: #4f8b4a; opacity: 1; font-weight: 700; }
.tile-button.tappable { cursor: pointer; opacity: 1; }
.tile-button.tapped { outline: 3px solid #f0b429; outline-offset: -3px; }
@media (prefers-reduced-motion: no-preference) {
  .tile-button.tapped { transition: outline-color 120ms ease; }
}
.flower-row .tile { opacity: 0.95; }

/* 大廳的致敬行：小字、不搶戲 */
.tribute {
  margin: 4px 0 0;
  font-size: 12px;
  letter-spacing: 0.04em;
  opacity: 0.6;
}

/* 玩家身份與旁白伯：字幕使用獨立一列，不蓋住手牌與出牌按鈕。 */
.identity-dialog { width: min(420px, calc(100% - 32px)); max-height: calc(100dvh - 32px); overflow-y: auto; border: 1px solid var(--gold); border-radius: 20px; padding: 24px; background: var(--felt-deep); color: var(--cream); }
.identity-dialog::backdrop { background: #000a; }
.identity-options { display: grid; gap: 10px; margin: 20px 0; }
.identity-options button { min-height: 48px; }
.identity-options [aria-pressed="true"] { background: #66522d; border-color: var(--gold); }
#identity-note { color: var(--muted); font-size: 13px; }
.player-story { display: block; font-size: 10px; font-weight: normal; color: var(--gold); line-height: 1.3; }
.narrator-caption { color: var(--cream); background: #173b33; border-left: 3px solid var(--gold); padding: 5px 8px; font-size: 12px; line-height: 1.5; text-align: center; }
.narrator-result { color: var(--gold); }

.table-header { display: grid; grid-template-columns: auto minmax(0, 1fr) auto auto; }
.table-header .narrator-caption { grid-column: 1 / -1; min-height: 28px; }
.table-header .narrator-caption[hidden] { display: block !important; visibility: hidden; }
.settings-panel:not([open]) > .settings-card { display: none; }
@media (min-width: 1280px) and (min-height: 700px) { #table { grid-template-rows: 86px minmax(142px, 21vh) minmax(222px, 1fr) auto minmax(132px, 18vh); } }
@media (orientation: portrait) {
  .rotate-hint { top: 50%; bottom: auto; transform: translate(-50%, -50%); }
}
@media (orientation: landscape) { .rotate-hint { display: none; } }

@media (orientation: portrait) and (max-width: 700px) { .hand-zone { position: relative; } }

.select-seat .seat-story { display: block; color: var(--gold); font-size: 10px; white-space: normal; }

/* 花牌獨立放在手牌上緣，避免多花時擠掉第十七張手牌。 */
@media (orientation: landscape) {
  .hand-melds { position: static; overflow: visible; }
  .hand-zone .hand-row { overflow: visible; }
  .hand-melds:not(:has(.meld-row)) { width: 0; min-width: 0; flex: 0 0 0; padding: 0; margin: 0; }
  .hand-melds .flower-row { position: absolute; bottom: calc(100% + 2px); left: 210px; flex-wrap: nowrap; gap: 2px; }
  .hand-melds .flower-row .tile { width: 22px !important; height: 28px !important; font-size: 10px !important; }
}

/* 短橫式由單一 Grid 分配高度；放不下時捲動牌桌，不縮小可點的手牌。 */
@media (orientation: landscape) and (max-height: 500px) {
  #table {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: 44px 44px minmax(60px, 1fr) auto 64px;
    grid-template-areas: "header" "opponents" "center" "actions" "hand";
    gap: 1px;
    height: 100dvh;
    min-height: 0;
    padding: 2px max(6px, env(safe-area-inset-right)) max(2px, env(safe-area-inset-bottom)) max(6px, env(safe-area-inset-left));
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior: contain;
  }
  .table-header { grid-area: header; position: relative; inset: auto; grid-template-columns: auto auto minmax(0, 1fr) auto auto; gap: 6px; min-height: 0; }
  .table-header .table-hud { grid-column: 2; grid-row: 1; width: auto; min-width: max-content; margin-inline: 4px; max-width: none; flex-wrap: nowrap; }
  .table-header .settings-panel { grid-column: 4; grid-row: 1; }
  .table-header .exit-mode-button { grid-column: 5; grid-row: 1; }
  .table-header .narrator-caption { grid-column: 3; grid-row: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin: 0; }
  .opponents { grid-area: opponents; position: relative; inset: auto; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 4px; height: 44px; min-height: 0; pointer-events: auto; }
  .opponents .opponent { position: relative; inset: auto; top: auto; left: auto; right: auto; width: 100%; max-width: none; height: 44px; min-height: 0; max-height: none; display: grid; grid-template-columns: 44px minmax(0, 1fr); align-items: center; gap: 4px; overflow: hidden; transform: none; }
  #table .opponents .opponent { top: 0; left: auto; right: auto; }
  .opponents .opponent[data-seat="3"] { grid-column: 1; grid-row: 1; }
  .opponents .opponent[data-seat="2"] { grid-column: 2; grid-row: 1; }
  .opponents .opponent[data-seat="1"] { grid-column: 3; grid-row: 1; }
  .opponents .avatar-wrap { position: relative; inset: auto; grid-column: 1; grid-row: 1; width: 44px; height: 44px; }
  .opponents .opponent .avatar-button { width: 44px !important; height: 44px !important; }
  .opponents .opponent-main { grid-column: 2; grid-row: 1; width: auto; min-width: 0; margin: 0; text-align: left; overflow: hidden; }
  .opponents .opponent-name { justify-content: flex-start; white-space: nowrap; }
  .opponents .opponent .meld-row,
  .opponents .opponent .flower-row { flex-wrap: nowrap; max-width: 100%; overflow-x: auto; overflow-y: hidden; justify-content: flex-start; }
  .opponents .opponent .meld-row { margin: 0; padding: 0; }
  .opponents .opponent .flower-row .tile { width: 20px; height: 26px; flex-shrink: 0; }
  .table-center { grid-area: center; position: relative; inset: auto; width: 100%; min-height: 60px; padding: 0; overflow: hidden; }
  .table-center .rivers-board { height: 100%; min-height: 0; padding: 5px 8px; display: block; overflow-y: auto; overscroll-behavior: contain; }
  .river-chrono { min-height: 100%; justify-content: flex-start; }
  .river-chrono-tiles { align-content: flex-start; max-width: 100%; flex-shrink: 0; }
  .actions { grid-area: actions; position: relative; inset: auto; transform: none; width: max-content; max-width: 100%; min-height: 44px; margin: 0 auto; padding: 0; justify-content: flex-start; flex-wrap: nowrap; gap: 4px; overflow-x: auto; }
  .actions:not(:has(button:not([hidden]))) { display: none; }
  .actions .action-button, .actions .action-button.win { height: 44px; min-height: 44px; font-size: 16px; }
  .hand-zone { grid-area: hand; position: relative; inset: auto; width: 100%; height: 64px; min-height: 64px; padding: 0; margin: 0; }
  /* 玩家頭像佔固定通道；副露不能從頭像下方開始排。 */
  #table .hand-zone .player-identity { left: 6px; bottom: 0; width: 64px; min-height: 0; flex-direction: column; gap: 0; padding: 0; font-size: 14px; text-align: center; }
  #table .hand-zone .player-identity img { width: 56px; height: 56px; border-radius: 14px; }
  #table .hand-zone .player-identity > strong { position: absolute; left: 50%; bottom: 2px; max-width: 58px; padding: 1px 4px; overflow: hidden; border-radius: 999px; background: rgba(5, 29, 24, .84); text-overflow: ellipsis; transform: translateX(-50%); white-space: nowrap; }
  #table .hand-zone .hand-row { height: 100%; padding-left: 80px !important; padding-right: 0 !important; gap: 2px; }
  .hand, .player-hand { gap: 0 !important; padding: 0 0 2px !important; }
  #hand { container-type: inline-size; }
  #table #hand .tile-button {
    flex: 0 0 44px !important; width: 44px !important; min-width: 44px !important; max-width: 44px !important; height: 60px !important; min-height: 60px !important; margin-left: -1px !important;
  }
  /* 依目前手牌張數及實際牌列寬度計算；空間足夠時牌面不重疊。 */
  #table #hand .tile-button:not(:first-child) { margin-left: clamp(-18px, calc(var(--hand-fit-share) - var(--hand-fit-cost)), 0px) !important; }
  #table #hand .tile-button:first-child { margin-left: 0 !important; }
  #table #hand .tile-button.drawn { margin-left: 2px !important; }
  .hand-melds { gap: 1px; max-width: none; flex-wrap: nowrap; }
  .hand-melds .meld-row { flex-wrap: nowrap; }
  #table:has(.hand-melds > .flower-row) { grid-template-rows: 44px 44px minmax(60px, 1fr) auto 98px; }
  #table:has(.hand-melds > .flower-row) .hand-zone { height: 98px; min-height: 98px; }
  .hand-melds .flower-row { top: 0; bottom: auto; left: 52px; }
  .hand-melds:has(> .flower-row) + .hand { align-self: end; height: 64px; }
  .app-shell.compact-table #table { gap: 0; }
  .app-shell.compact-table .opponent-name span { display: none; }
}

@media (orientation: landscape) and (max-height: 500px) and (max-width: 799px) {
  .hand-melds .meld-row { gap: 1px; padding: 2px 3px; }
  .hand-melds .tile { width: 28px; height: 40px; }
}

@media (orientation: landscape) and (max-height: 280px) {
  #table:has(#actions button:not([hidden])) .table-header::after,
  #table:has(.hand-melds > .flower-row) .table-header::after {
    content: var(--locale-scroll-hand, "↓ Scroll to hand");
    grid-column: 3;
    grid-row: 1;
    align-self: center;
    color: #ffe399;
    font-size: 12px;
    font-weight: 800;
    text-align: center;
    white-space: nowrap;
  }
}

/* 結算攤牌：桌機並排，手機逐家往下看；動作鈕固定在底部。 */
.result-dialog { width: min(calc(100% - 24px), 1080px); }
.result-players { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; margin: 14px 0; text-align: left; }
.result-player { min-width: 0; padding: 12px; border: 1px solid #77978966; border-radius: 12px; background: #082c25; }
.result-player.is-winner { border-color: #f2cf75; background: #284c37; }
.result-player.is-discarder { border-color: #eaa396; }
.result-player header { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.result-avatar { width: 40px; height: 40px; object-fit: cover; border-radius: 50%; background: #fff7d9; }
.result-player small { display: block; color: #c1d2c9; font-size: 11px; }
.result-status { border-radius: 6px; padding: 4px 7px; background: #ffffff15; font-size: 13px; white-space: nowrap; }
.is-winner .result-status { background: #f2cf75; color: #342800; }
.is-discarder .result-status { background: #913c36; color: white; }
.result-delta { margin-left: auto; text-align: right; font-size: 23px; white-space: nowrap; }
.result-delta.positive { color: #ffe399; }
.result-delta.negative { color: #ffb7a7; }
.result-hand { display: flex; flex-wrap: wrap; gap: 3px; align-items: flex-start; }
.result-player .tile { width: 36px; height: 50px; min-width: 0; flex-shrink: 0; font-size: 13px; }
.result-winning { margin-left: 5px; text-align: center; }
.result-winning > .tile { border: 2px solid #f0c34c; }
.result-winning small { color: #ffe399; }
.result-exposed { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 8px; }
.result-meld > small { margin-bottom: 3px; }
.result-exposed .meld-row, .result-exposed .flower-row { display: flex; flex-wrap: wrap; gap: 2px; padding: 0; margin: 0; background: none; }
.result-scoring { max-width: 640px; margin: 10px auto; padding: 8px 12px; border: 1px solid #e7b95b66; border-radius: 10px; text-align: left; }
.result-scoring summary { cursor: pointer; color: #ffe399; }
.result-scoring .yaku-list { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 20px; margin: 6px 0; }
@media (max-width: 600px) {
 .result-players { grid-template-columns: minmax(0, 1fr); gap: 10px; }
 .result-scroll { padding: 14px 10px 8px; }
 .result-player { padding: 10px; }
 .result-player .tile { width: 32px; height: 45px; }
 .result-delta { font-size: 20px; }
 .result-scoring .yaku-list { gap: 0 12px; font-size: 13px; }
}
@media (max-height: 500px) and (orientation: landscape) {
 .result-scroll > .narrator-result { display: none; }
 .result-scoring { margin: 5px auto; padding: 5px 10px; }
 .result-players { margin: 7px 0; gap: 8px; }
 .result-player { padding: 8px; }
 .result-player header { margin-bottom: 6px; }
 .result-avatar { width: 30px; height: 30px; }
 .result-player .tile { width: 30px; height: 42px; }
 .result-delta { font-size: 19px; }
 .result-dialog .dialog-actions { padding: 6px 18px; }
 .result-dialog .dialog-button { min-height: 44px; padding: 8px 12px; }
}

/* 莊家、吃碰來源與各家出牌辨識。 */
.opponent.is-dealer { border-color: #e9be65; }
.dealer-label { display: inline-grid; place-items: center; width: 28px; height: 28px; flex: 0 0 28px; border-radius: 6px; background: #f2bf55; color: #302407; font-size: 20px; font-weight: 900; }
.opponents .avatar-wrap .dealer-badge { min-width: 34px; min-height: 34px; font-size: 23px; }
.meld-row .tile.claimed-meld-tile { border-bottom: 4px solid #d58c16; box-shadow: inset 0 0 0 1px #d58c16; }
.opponents .opponent-main > .meld-row,
.opponents .opponent-main > .flower-row { position: static; clear: both; transform: none; margin: 4px 0 0; }
@media (min-width: 1000px) and (min-height: 501px) {
 .opponents .opponent-main { display: flex; flex-direction: column; align-items: stretch; }
 .opponents .opponent-main > .meld-row { display: flex; flex-wrap: wrap; max-height: none; overflow: visible; gap: 5px; }
 .opponents .opponent-main > .meld-row > .meld-row { display: flex; flex: 0 0 auto; }
 .opponents .opponent-main > .meld-row::after { content: none; }
 .opponents .opponent-main > .flower-row { display: flex; flex-wrap: wrap; gap: 2px; }
 .opponents .opponent-main > .flower-row .tile { width: 20px; height: 27px; flex: 0 0 20px; }
}
@media (max-width: 600px), (max-height: 500px) {
 .dealer-label { display: none; }
 .opponents .avatar-wrap .dealer-badge { min-width: 26px; min-height: 26px; font-size: 18px; padding: 1px 4px; }
 .opponents .action-banner { min-width: 66px; padding: 5px 7px; font-size: 15px; white-space: nowrap; }
}
@media (prefers-reduced-motion: no-preference) {
 .opponent.is-reacting .avatar-button { animation: discard-avatar 850ms ease-out both; }
 @keyframes discard-avatar { 0%,100% { translate: 0 0; } 30% { translate: 0 5px; box-shadow: 0 0 0 3px #f2bf55; } }
}
@media (max-height: 500px) and (orientation: landscape) {
 .opponents .opponent-main > .meld-row,
 .opponents .opponent-main > .flower-row { margin: 0; }
}

/* 重繪沿用事件時間，避免泡泡、思考狀態更新讓同一次出牌反覆閃爍。 */
.opponent.is-reacting .action-banner,
.opponent.is-reacting .avatar-button,
.opponent.is-reacting .standee { animation-delay: var(--action-elapsed, 0ms); }
/* 出牌提示覆在頭像中央，不向下伸入牌池或副露區。 */
.opponents .action-banner {
 top: 50%; bottom: auto; left: 50%; min-width: 0; width: max-content;
 padding: 4px 6px; font-size: 17px; white-space: nowrap;
 transform: translate(-50%, -50%); animation-name: avatar-banner-life;
}
@keyframes avatar-banner-life {
 0% { opacity: 0; transform: translate(-50%, -50%) scale(.85); }
 14%, 72% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
 100% { opacity: 0; transform: translate(-50%, -50%) scale(.94); }
}
@media (max-width: 600px), (max-height: 500px) {
 .opponents .action-banner { font-size: 14px; padding: 3px 4px; }
}

/* 選角以四位大圖為主，未入選角色收在側邊縮圖列。 */
.table-mode-switch { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; width: min(100%, 650px); margin: 8px auto 0; }
.table-mode-switch button { display: grid; gap: 2px; min-height: 56px; padding: 7px 10px; border: 1px solid #b59a60; border-radius: 12px; background: #102f29; color: #f2e8d3; cursor: pointer; }
.table-mode-switch button[aria-pressed="true"] { border-color: #ffe5a2; background: #dca948; color: #1c241d; box-shadow: 0 0 0 2px #ffe4a955; animation: selected-table-float 2.8s ease-in-out infinite; }
.table-mode-switch strong { font-size: clamp(12px, 1.5vw, 16px); }
.table-mode-switch small { font-size: clamp(10px, 1.1vw, 12px); line-height: 1.2; }
@media (max-width: 520px) {
  .table-mode-switch { gap: 5px; }
  .table-mode-switch button { min-height: 52px; padding: 6px 4px; }
  .table-mode-switch strong { font-size: 12px; }
  .table-mode-switch small { font-size: 9px; }
}
@keyframes selected-table-float { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-3px); } }
@media (prefers-reduced-motion: reduce) { .table-mode-switch button[aria-pressed="true"] { animation: none; } }
.resume-solo { min-height: 44px; padding: 8px 16px; border: 1px solid #ffe5a2; border-radius: 10px; background: #315d4c; color: #fff1c3; font-weight: 800; cursor: pointer; }
.resume-solo[hidden] { display: none; }
.select-seat .seat-diff { color: #ffdc8a; font-weight: 800; }
.select-card .tier-mini { display: block; color: #e8c980; font-size: 10px; }
.select-screen { gap: 10px; }
.select-stage {
  display: grid; grid-template-columns: minmax(0, 1fr) 136px; gap: 12px;
  width: min(100%, 1180px); min-height: 0; flex: 1 1 auto; align-items: stretch;
}
.select-seats {
  grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; width: 100%; margin: 0;
}
.select-seat {
  grid-template-rows: minmax(0, 1fr) auto; gap: 5px; min-width: 0; min-height: 290px;
  padding: 9px 7px; overflow: hidden; border-color: rgba(231,185,91,.45);
  background: linear-gradient(160deg, rgba(6,31,27,.88), rgba(29,76,61,.76));
}
.select-seat.is-active { border-color: var(--gold); box-shadow: inset 0 0 28px #e7b95b18, 0 0 0 2px #e7b95b35; }
.select-seat-main {
  grid-template-rows: auto minmax(0,1fr) auto auto; align-content: stretch; gap: 3px; min-width: 0; min-height: 0;
}
.select-seat .seat-label { z-index: 1; }
.select-seat img.select-fullbody {
  width: 100%; height: 100%; min-width: 0; min-height: 170px; max-height: 52dvh;
  border-radius: 0; object-fit: contain; object-position: center bottom; background: transparent;
}
.select-seat-main:disabled { cursor: default; }
.select-seat-shuffle { width: 100%; margin: 0; }
.select-grid {
  display: flex; flex-direction: column; gap: 7px; width: 100%; max-height: none; overflow: auto;
  align-items: stretch; padding: 3px; border: 1px solid #e7b95b55; border-radius: 14px; background: #061c18a8;
}
.select-card {
  grid-template-columns: 52px minmax(0, 1fr); gap: 6px; min-height: 64px; padding: 5px;
  border-radius: 10px; text-align: center;
}
.select-card img { width: 50px; height: 50px; min-width: 0; min-height: 0; border-radius: 8px; }
.select-card strong { font-size: 11px; overflow-wrap: anywhere; }
.select-actions { flex: 0 0 auto; margin: 0; }

/* 胡牌結算以勝方角色與輸贏資訊帶頭，四家牌型仍完整保留在下方。 */
.result-spotlight {
  position: relative; display: grid; grid-template-columns: minmax(140px, 27%) minmax(0, 1fr);
  align-items: end; min-height: 210px; margin: -22px -22px 14px; overflow: hidden;
  border-bottom: 1px solid #e7b95b88;
  background: radial-gradient(ellipse at 74% 38%, #326e58 0, #17483c 46%, #102d29 100%);
  text-align: left;
}
.result-spotlight::after { content: ""; position: absolute; inset: 0; pointer-events: none; background: linear-gradient(90deg, transparent 20%, #061c1870 100%); }
.result-hero { position: relative; z-index: 1; align-self: end; justify-self: center; width: 100%; height: 220px; object-fit: contain; object-position: center bottom; }
.result-hero-copy { position: relative; z-index: 1; align-self: center; min-width: 0; padding: 20px 18px 20px 8px; }
.result-hero-copy .eyebrow { margin: 0 0 7px; }
.result-body .result-hero-copy h2 { margin: 0 0 8px; color: #ffe399; font-size: clamp(25px, 4vw, 42px); }
.result-hero-copy .result-outcome { margin: 0; color: #fff8df; font-size: clamp(14px, 2vw, 20px); line-height: 1.5; }
/* 牌桌設定改為可捲動的置中面板，避免壓住右側角色立繪。 */
#table:has(.settings-panel[open])::before {
  content: "";
  position: fixed;
  z-index: 79;
  inset: 0;
  background: rgba(1, 16, 13, .48);
  pointer-events: none;
}
#table:has(.settings-panel[open]) > .table-header { z-index: 81; }
#table:has(.settings-panel[open]) .standee { visibility: hidden; }
#app:has(#table .settings-panel[open]) .toast { visibility: hidden; }
.settings-panel[open] > .settings-card {
  position: fixed;
  z-index: 80;
  top: 50%;
  right: auto;
  left: 50%;
  width: min(340px, calc(100vw - 24px));
  max-height: calc(100dvh - 24px);
  gap: 6px;
  padding: 10px 12px;
  font-size: 12px;
  overflow-y: auto;
  overscroll-behavior: contain;
  transform: translate(-50%, -50%);
}

/* 單機覆盤：寬版摘要、關鍵決定與當時公開牌況。 */
.result-dialog.review-wide { width: min(calc(100% - 24px), 920px); }
.review-shell { display: grid; gap: 16px; max-height: calc(100dvh - 28px); overflow-y: auto; overscroll-behavior: contain; padding: 22px; color: #f4f1e5; text-align: left; }
.review-shell h2 { margin: 0; color: #ffe399; font-size: clamp(24px, 4vw, 34px); }
.review-shell h3 { margin: 0; color: #ffe399; font-size: 18px; }
.review-shell p { margin: 4px 0; color: #d2dfda; }
.review-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.review-head .eyebrow { margin: 0 0 4px; color: #e7bd5d; }
.review-back-top { min-height: 44px; border: 1px solid #e6c46f; border-radius: 10px; padding: 8px 14px; color: #fff4d2; background: #315d4c; font: inherit; font-weight: 750; cursor: pointer; }
.review-archive-list { display: grid; gap: 8px; }
.review-archive-card { display: grid; grid-template-columns: minmax(0,1fr) minmax(110px,auto) auto; align-items: center; gap: 12px; min-height: 68px; border: 1px solid #55766a; border-radius: 12px; padding: 10px 14px; color: #f5f1df; background: #123b32; text-align: left; font: inherit; cursor: pointer; }
.review-archive-card:hover { border-color: #e7bd5d; background: #1d4e40; }
.review-archive-card-main { display: grid; gap: 2px; }
.review-archive-card small, .review-archive-outcome { color: #c6d5cc; }
.review-archive-card > span:last-child { color: #ffe399; font-size: 13px; font-weight: 800; }
.review-empty { border: 1px dashed #597b70; border-radius: 12px; padding: 18px; text-align: center; }
.review-actions { display: grid; grid-template-columns: repeat(auto-fit,minmax(min(100%,180px),1fr)); gap: 8px; }
.review-hand-picker { display: grid; grid-template-columns: auto minmax(0,1fr); align-items: center; gap: 12px; color: #e4eadf; font-weight: 750; }
.review-hand-picker select { min-height: 44px; border: 1px solid #779287; border-radius: 9px; padding: 8px 12px; color: #f5f1df; background: #123b32; font: inherit; }
.review-metrics { display: grid; grid-template-columns: repeat(3,minmax(0,1fr)); gap: 9px; }
.review-metrics > div { display: grid; align-content: center; gap: 3px; min-height: 78px; border: 1px solid #8b7545; border-radius: 13px; padding: 10px; background: linear-gradient(145deg,#254e41,#14382f); text-align: center; }
.review-metrics strong { color: #ffe399; font-size: clamp(20px,4vw,29px); line-height: 1.1; }
.review-metrics span { color: #d4e0d7; font-size: 12px; }
.review-section { display: grid; gap: 9px; border-top: 1px solid #45695c; padding-top: 13px; }
.review-muted { color: #afc5b8 !important; font-size: 13px; }
.review-moments, .review-decisions { display: grid; gap: 8px; }
.review-moment { display: grid; gap: 4px; border: 1px solid #bb8c43; border-radius: 11px; padding: 11px 13px; color: #fff4dc; background: #403722; text-align: left; font: inherit; cursor: pointer; }
.review-moment strong { color: #ffe399; }
.review-moment small { display: grid; gap: 2px; color: #e4dac2; }
.review-decision { display: grid; gap: 6px; border: 1px solid #496b60; border-left: 4px solid #648879; border-radius: 11px; padding: 11px 13px; background: #10372f; }
.review-decision.minor { border-left-color: #f1bb52; }
.review-decision.major { border-left-color: #f17b61; }
.review-decision-heading { display: flex; justify-content: space-between; gap: 10px; }
.review-decision-heading small { color: #aec5b8; }
.review-decision p { margin: 0; }
.review-cost { color: #ffd479 !important; font-weight: 800; }
.review-notes { display: grid; gap: 3px; margin: 0; padding-left: 20px; color: #e1e7dd; }
.review-step-button { justify-self: start; min-height: 40px; border: 1px solid #9a8652; border-radius: 9px; padding: 6px 12px; color: #ffe7ab; background: #274a3e; font: inherit; font-weight: 750; cursor: pointer; }
.review-luck-item { border-left: 3px solid #79b6a0; padding: 6px 10px; }
.review-luck-item.avoidable { border-left-color: #f0ab56; }
.review-luck-item.unlucky { border-left-color: #84bca4; }
.review-filter { display: flex; align-items: center; gap: 7px; color: #e9e4d4; white-space: nowrap; }
.review-filter input { width: 20px; height: 20px; accent-color: #edc762; }
.review-section-title { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.review-local-note { border-radius: 9px; padding: 9px 11px; background: #0c3029; font-size: 12px; }
.review-choice { display: grid; gap: 6px; border: 1px solid #b8904d; border-radius: 12px; padding: 13px; background: #263d34; }
.review-choice strong:first-child { color: #ffbd83; }
.review-choice strong:nth-child(2) { color: #ffe399; }
.review-public-rivers { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 8px; }
.review-river { min-width: 0; border: 1px solid #45695c; border-radius: 10px; padding: 9px; background: #0e3029; }
.review-river > strong { display: flex; justify-content: space-between; gap: 6px; color: #ffe399; }
.review-river > strong small { color: #b5c7bb; font-weight: 500; }
.review-river > div { display: flex; flex-wrap: wrap; gap: 3px; margin-top: 7px; }
.review-river .tile { transform: scale(.8); transform-origin: top left; margin-right: -5px; margin-bottom: -8px; }
.review-own-hand { display: grid; gap: 7px; }
.review-hand-tiles { display: flex; flex-wrap: wrap; align-items: flex-start; gap: 8px 4px; padding: 10px; border: 1px solid #9a8652; border-radius: 11px; background: #0a2b24; }
.review-hand-tile { display: grid; justify-items: center; gap: 3px; padding: 3px; border-radius: 7px; }
.review-hand-tile.chosen-tile { outline: 2px solid #ef8f60; }
.review-hand-tile.advised-tile { box-shadow: 0 0 0 2px #f4d77f; }
.review-hand-tile small { max-width: 54px; color: #ffe399; font-size: 9px; line-height: 1.1; text-align: center; }
@media (max-width: 600px) {
  .review-shell { gap: 12px; padding: 14px; }
  .review-archive-card { grid-template-columns: minmax(0,1fr) auto; }
  .review-archive-outcome { grid-column: 1; }
  .review-archive-card > span:last-child { grid-column: 2; grid-row: 1 / span 2; }
  .review-metrics { gap: 5px; }
  .review-metrics > div { min-height: 68px; padding: 7px 3px; }
  .review-metrics span { font-size: 10px; }
  .review-decision-heading { display: grid; gap: 2px; }
  .review-public-rivers { grid-template-columns: minmax(0,1fr); }
  .review-hand-picker { grid-template-columns: minmax(0,1fr); gap: 4px; }
  .review-section-title { align-items: flex-start; }
}
.settings-card input[type="checkbox"] { width: 16px; height: 16px; }
.settings-card input[type="range"] { height: 16px; }
.settings-card .tile-style-setting select,
.settings-card .music-track-setting select { min-height: 44px; }
.settings-card .settings-actions button { min-height: 44px; }
.settings-card .settings-leave { margin-top: 0; }

/* 將輪次狀態放到手牌上緣，讓玩家視線不用來回找提示。 */
.hand-heading:has(#hand-turn-cue) { display: flex !important; }
.hand-heading > #hand-turn-cue {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 32px;
  padding: 5px 14px;
  border: 1px solid rgba(255, 225, 139, .55);
  border-radius: 999px;
  color: #f7df9a;
  background: rgba(6, 37, 31, .94);
  font-size: 13px;
  font-weight: 800;
  letter-spacing: .02em;
  white-space: nowrap;
}
.hand-heading > #hand-turn-cue.is-mine {
  border-color: #fff0b5;
  color: #18372c;
  background: linear-gradient(180deg, #ffe9a1, #e5b84f);
  box-shadow: 0 0 0 2px rgba(255, 225, 139, .2), 0 0 18px rgba(255, 225, 139, .38);
}
@media (orientation: landscape) {
  /* 橫式牌列已占滿底部寬度；輪次提示固定留在頂部 HUD，避免蓋住可點的牌。 */
  .hand-heading:has(#hand-turn-cue) { display: none !important; }
  .table-hud .turn-status {
    min-height: 28px;
    padding: 4px 12px;
    border: 1px solid rgba(255, 225, 139, .7);
    border-radius: 999px;
    color: #fff0b5;
    background: rgba(6, 37, 31, .94);
    font-size: 13px;
    font-weight: 850;
  }
  .table-hud .turn-status.is-mine {
    color: #18372c;
    background: linear-gradient(180deg, #ffe9a1, #e5b84f);
  }
}
@media (max-width: 430px) and (orientation: portrait) {
  .hand-heading:has(#hand-turn-cue) { justify-content: flex-start; }
  .hand-heading > #hand-turn-cue { min-height: 30px; max-width: 100%; min-width: 0; flex: 0 1 auto; padding: 4px 10px; font-size: 12px; white-space: normal; overflow-wrap: normal; word-break: normal; line-height: 1.2; }
}
@media (prefers-reduced-motion: no-preference) {
  .hand-heading > #hand-turn-cue.is-mine { animation: hand-turn-glow 1.8s ease-in-out infinite; }
  @keyframes hand-turn-glow {
    0%, 100% { box-shadow: 0 0 0 2px rgba(255, 225, 139, .16), 0 0 12px rgba(255, 225, 139, .25); }
    50% { box-shadow: 0 0 0 3px rgba(255, 225, 139, .28), 0 0 22px rgba(255, 225, 139, .5); }
  }
}

/* 短版手機橫向把輪次提示留在頂部狀態列，避免壓住手牌。 */
@media (orientation: landscape) and (max-height: 520px) {
  .hand-heading:has(#hand-turn-cue) { display: none !important; }
  .table-hud .turn-status {
    min-height: 28px;
    padding: 4px 12px;
    border: 1px solid rgba(255, 225, 139, .7);
    border-radius: 999px;
    color: #fff0b5;
    background: rgba(6, 37, 31, .94);
    font-size: 13px;
    font-weight: 850;
  }
  .table-hud .turn-status.is-mine {
    color: #18372c;
    background: linear-gradient(180deg, #ffe9a1, #e5b84f);
  }
}

/* 桌面置中面板下移，避開對手角色的臉部立繪。 */
@media (min-width: 1200px) and (min-height: 700px) {
  .settings-panel[open] > .settings-card {
    top: calc(50% + clamp(60px, 8vh, 70px));
  }
}

/* 平板直式用獨立牌桌高度配置；避免沿用手機外距後把底部手牌推出畫面。 */
@media (orientation: portrait) and (min-width: 701px) and (max-width: 899px) {
  body { padding: 0; }
  .app-shell { min-height: 100dvh; border-radius: 0; }
  .screen { min-height: 0; }
  #table {
    width: 100%;
    height: 100dvh;
    max-height: 100dvh;
    min-height: 0;
    padding: max(12px, env(safe-area-inset-top)) 14px max(8px, env(safe-area-inset-bottom));
    grid-template-rows: auto minmax(112px, 10dvh) minmax(0, 1fr) auto auto auto auto minmax(206px, 25dvh);
    gap: 8px;
    overflow: hidden;
  }
  .table-header { flex-wrap: nowrap; gap: 8px; }
  .table-header h1 { font-size: 19px; }
  .table-hud { width: auto; max-width: none; gap: 5px; }
  .opponents { min-height: 112px; gap: 8px; }
  .opponents .opponent {
    display: grid;
    grid-template-columns: 48px minmax(0, 1fr);
    align-items: start;
    gap: 5px;
    min-height: 104px;
    padding: 8px 6px;
    text-align: left;
  }
  .opponents .opponent .avatar-button,
  .opponents .opponent:nth-child(1) .avatar-button { width: 44px !important; height: 44px !important; margin: 0; }
  .opponents .opponent-main { min-width: 0; text-align: left; }
  .opponents .opponent-name { display: block; margin: 0; }
  .opponents .opponent-name strong { display: block; overflow: hidden; font-size: 11px; text-overflow: ellipsis; white-space: nowrap; }
  .opponents .opponent-name span { font-size: 10px; }
  .opponents .opponent-main > .meld-row { max-height: 28px; overflow: hidden; }
  .table-center { min-height: 0; overflow: hidden; }
  .table-center .rivers-board { height: 100%; min-height: 0; padding: 10px; overflow: auto; }
  .rivers-board .tile, .river-chrono-tiles .tile { width: 30px !important; height: 40px !important; font-size: 12px !important; }
  .actions { min-height: 44px; gap: 6px; padding: 0; }
  .hand-zone {
    position: relative;
    display: grid;
    grid-template-rows: 36px minmax(0, 1fr);
    height: 100%;
    min-height: 0;
    overflow: visible;
  }
  .hand-heading { grid-row: 1; min-height: 32px; }
  .hand-zone .player-identity { position: absolute; left: 0; bottom: 4px; z-index: 4; }
  .hand-zone .player-identity img { width: 52px; height: 52px; }
  .hand-zone .hand-row { grid-row: 2; height: 100%; flex-direction: column; align-items: stretch; gap: 2px; overflow: visible; }
  .hand-melds { width: 100%; max-width: 100%; max-height: 36px; flex-wrap: nowrap; overflow-x: auto; }
  .hand, .player-hand {
    display: flex !important;
    flex: 1 1 auto;
    flex-wrap: wrap !important;
    align-content: end;
    justify-content: center !important;
    gap: 2px 0 !important;
    min-height: 0;
    height: 100%;
    padding: 0 4px 4px 54px;
    overflow: visible !important;
  }
  .hand-break { display: block !important; flex: 0 0 100%; height: 0; }
  .hand .tile-button, .player-hand .tile-button,
  .app-shell.large-tiles .hand .tile-button, .app-shell.large-tiles .player-hand .tile-button {
    flex: 0 0 clamp(52px, 7.6vw, 62px) !important;
    width: clamp(52px, 7.6vw, 62px) !important;
    min-width: 52px !important;
    max-width: 62px !important;
    min-height: 72px !important;
    height: clamp(72px, 10.2vw, 80px) !important;
    margin-left: -3px !important;
  }
}

/* 平板與大手機橫式：牌河退開對手區，手牌完整排在一列。 */
@media (orientation: landscape) and (min-width: 700px) and (max-width: 1199px) and (min-height: 501px) {
  .app-shell { --avatar-size: 60px; --avatar-size-opp: 64px; }
  .opponents .opponent { max-height: 126px; }
  .opponents .opponent .avatar-button,
  .opponents .opponent:nth-child(1) .avatar-button { width: 64px !important; height: 64px !important; }
  .table-center { top: 184px; }
  .hand-zone .hand .tile-button,
  .hand-zone .player-hand .tile-button,
  .app-shell.large-tiles .hand-zone .hand .tile-button,
  .app-shell.large-tiles .hand-zone .player-hand .tile-button {
    flex: 0 0 44px !important;
    width: 44px !important;
    min-width: 44px !important;
    max-width: 44px !important;
    min-height: 60px !important;
    height: 60px !important;
  }
  .hand-zone .hand .tile-button.drawn,
  .hand-zone .player-hand .tile-button.drawn { margin-left: 2px !important; }
  #table .hand-zone { left: 6px; right: 6px; width: auto !important; }
}

/* 700–899px 中等高度橫式用實際牌列寬度重疊，保留 44px 點擊區。 */
@media (orientation: landscape) and (min-width: 700px) and (max-width: 899px) and (min-height: 501px) {
  #hand { container-type: inline-size; gap: 0 !important; }
  .hand-zone .hand .tile-button,
  .hand-zone .player-hand .tile-button,
  .app-shell.large-tiles .hand-zone .hand .tile-button,
  .app-shell.large-tiles .hand-zone .player-hand .tile-button {
    flex: 0 0 44px !important;
    width: 44px !important;
    min-width: 44px !important;
    max-width: 44px !important;
    min-height: 60px !important;
    height: 60px !important;
  }
  #table #hand .tile-button:not(:first-child) { margin-left: clamp(-18px, calc(var(--hand-fit-share) - var(--hand-fit-cost)), 0px) !important; }
  #table #hand .tile-button:first-child { margin-left: 0 !important; }
  #table #hand .tile-button.drawn { margin-left: 2px !important; }
}

/* 大手機／桌面橫向：牌列以畫面中心定位，不再把頭像預留寬度加到整副牌的一側。 */
@media (orientation: landscape) and (min-width: 900px) {
  .hand-zone .hand-row { padding-left: 0 !important; padding-right: 0 !important; }
  .hand-zone .hand,
  .hand-zone .player-hand { justify-content: center !important; }
  .hand-zone .hand .tile-button,
  .hand-zone .player-hand .tile-button { margin-left: -2px !important; }
  .hand-zone .hand .tile-button:first-child,
  .hand-zone .player-hand .tile-button:first-child { margin-left: 0 !important; }
  .hand-zone .hand .tile-button.drawn,
  .hand-zone .player-hand .tile-button.drawn { margin-left: 2px !important; }
}

/* 1280px 以上縮窄牌面，讓置中的手牌避開左側頭像，也替瀏覽器右側工具列留空。 */
@media (orientation: landscape) and (min-width: 1200px) {
  .hand-zone .hand .tile-button,
  .hand-zone .player-hand .tile-button,
  .app-shell.large-tiles .hand-zone .hand .tile-button,
  .app-shell.large-tiles .hand-zone .player-hand .tile-button {
    flex: 0 0 clamp(54px, 4.4cqw, 60px) !important;
    width: clamp(54px, 4.4cqw, 60px) !important;
    min-width: 54px !important;
    max-width: 60px !important;
    height: clamp(72px, 6cqw, 82px) !important;
    min-height: 72px !important;
    margin-left: -2px !important;
  }
  .hand-zone .hand .tile-button:first-child,
  .hand-zone .player-hand .tile-button:first-child { margin-left: 0 !important; }
  .hand-zone .hand .tile-button.drawn,
  .hand-zone .player-hand .tile-button.drawn { margin-left: 2px !important; }
}

@media (max-width: 700px) and (orientation: portrait) {
  .select-panel .select-stage { max-height: none; }
  .select-stage { grid-template-columns: minmax(0, 1fr) 78px; grid-template-rows: minmax(0,1fr); gap: 6px; flex: 1 1 auto; max-height: 58dvh; }
  .select-seats { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 7px; }
  .select-seat { min-height: 0; padding: 4px; }
  .select-seat img.select-fullbody { min-height: 70px; max-height: 17dvh; }
  .select-seat .seat-diff { display: none; }
  .select-seat .seat-name { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .select-seat-shuffle { min-height: 34px; }
  .select-grid { flex-direction: column; max-height: none; overflow-x: hidden; overflow-y: auto; }
  .select-card { flex: 0 0 auto; grid-template-columns: minmax(0,1fr); justify-items: center; gap: 2px; min-height: 60px; padding: 3px 1px; }
  .select-card img { width: 38px; height: 38px; }
  .select-card strong { max-width: 72px; font-size: 9px; }
  .select-actions { width: min(100%, 480px); }
}
@media (max-height: 500px) and (orientation: landscape) {
  .select-panel .select-stage { display: grid; grid-template-columns: minmax(0, 1fr) 100px; grid-template-rows: minmax(0, 1fr); gap: 6px; height: min(61dvh, 246px); }
  .select-panel .select-seats { height: 100%; }
  .select-panel .select-seat { min-height: 0; height: 100%; }
  .select-panel .select-seat-main { min-height: 0; }
  .select-panel .select-grid { min-height: 0; max-height: 100%; overflow-y: auto; grid-template-columns: minmax(0, 1fr); }
  .select-panel .select-card { grid-template-columns: 34px minmax(0, 1fr); min-height: 42px; }
  .select-screen { padding-block: 6px; gap: 4px; }
  .select-screen > .eyebrow { margin: 0; }
  .select-screen > h1 { font-size: 22px; }
  .select-screen > .lead { font-size: 12px; line-height: 1.25; }
  .select-stage { grid-template-columns: minmax(0,1fr) 100px; gap: 6px; flex: 0 0 auto; height: min(61dvh, 246px); }
  .select-seats { gap: 5px; }
  .select-seat { height: 100%; min-height: 0; padding: 3px; }
  .select-seat img.select-fullbody { min-height: 75px; max-height: 30dvh; }
  .select-seat .seat-diff { display: none; }
  .select-grid { gap: 3px; }
  .select-card { grid-template-columns: 34px minmax(0,1fr); min-height: 42px; padding: 2px; }
  .select-card img { width: 32px; height: 32px; }
  .select-card strong { font-size: 10px; }
  .select-actions { max-width: 360px; }
  .select-actions button { min-height: 38px; }
  .result-spotlight { grid-template-columns: 120px minmax(0,1fr); min-height: 125px; margin: -10px -18px 8px; }
  .result-hero { height: 130px; }
  .result-hero-copy { padding: 8px 12px 8px 4px; }
  .result-hero-copy .eyebrow, .result-hero-copy .result-outcome { margin-block: 2px; }
  .result-body .result-hero-copy h2 { margin: 2px 0; font-size: 22px; }
}

/* 自己的花牌與副露固定在玩家區，避免看起來像浮在牌河中。 */
.hand-zone .player-identity { pointer-events: none; }
.hand-melds > .flower-row::before {
  content: var(--locale-my-flowers, "My flowers");
  flex: 0 0 100%;
  color: #ffe2a0;
  font-size: 11px;
  font-weight: 800;
  line-height: 1.2;
}

@media (orientation: landscape) {
  .hand-melds .flower-row {
    left: 68px;
    bottom: calc(100% + 3px);
    display: flex;
    flex-wrap: wrap;
    width: max-content;
    max-width: min(240px, calc(100vw - 84px));
    padding: 4px 6px;
    border: 1px solid rgba(231, 185, 91, .55);
    border-radius: 9px;
    background: rgba(5, 35, 29, .9);
    box-shadow: 0 3px 12px rgba(0, 0, 0, .25);
  }
}

@media (orientation: landscape) and (min-width: 1280px) and (min-height: 700px) {
  .hand-zone .player-identity {
    left: 12px;
    bottom: 4px;
    width: 100px;
    flex-direction: column;
    gap: 2px;
    text-align: center;
    font-size: 14px;
  }
  .hand-zone .player-identity img { width: 92px; height: 92px; }
  .hand-zone .hand-row {
    padding-inline: clamp(224px, 18vw, 270px) !important;
  }
  .hand-zone .hand .tile-button,
  .hand-zone .player-hand .tile-button,
  .app-shell.large-tiles .hand-zone .hand .tile-button,
  .app-shell.large-tiles .hand-zone .player-hand .tile-button {
    flex-basis: clamp(49px, 3.9vw, 60px) !important;
    width: clamp(49px, 3.9vw, 60px) !important;
    min-width: 49px !important;
    max-width: 60px !important;
  }
  .hand-melds .flower-row {
    left: 118px;
    bottom: 10px;
    width: 92px;
    max-width: 92px;
    gap: 2px;
  }
}

@media (orientation: landscape) and (max-height: 500px) {
  .hand-melds > .flower-row::before {
    flex-basis: auto;
    align-self: center;
    margin-right: 3px;
  }
}

@media (orientation: portrait) and (max-width: 480px) {
  .river-chrono { position: relative; }
  .river-chrono::before {
    content: var(--locale-brand-mark, "CC");
    position: absolute;
    top: 51%;
    left: 50%;
    display: grid;
    place-items: center;
    width: min(32vw, 118px);
    aspect-ratio: 1;
    border: 2px solid rgba(223, 190, 113, .13);
    border-radius: 50%;
    color: rgba(237, 213, 157, .15);
    font: 800 34px/1 serif;
    letter-spacing: .08em;
    transform: translate(-50%, -50%);
    pointer-events: none;
  }
  .hand-melds > .flower-row::before { flex-basis: auto; margin-right: 5px; }
  .hand .tile-button,
  .player-hand .tile-button,
  .app-shell.large-tiles .hand .tile-button,
  .app-shell.large-tiles .player-hand .tile-button,
  .hand .tile-button.drawn,
  .player-hand .tile-button.drawn {
    margin-left: clamp(-7px, calc((100vw - 420px) / 8), -3px);
  }
}

/* 直式三家以實際座位定位；DOM 順序仍供橫式的上、左、右排版使用。 */
@media (orientation: portrait) {
  .opponents .opponent[data-seat="3"] { grid-column: 1; grid-row: 1; }
  .opponents .opponent[data-seat="2"] { grid-column: 2; grid-row: 1; }
  .opponents .opponent[data-seat="1"] { grid-column: 3; grid-row: 1; }
}

@media (orientation: portrait) and (min-width: 481px) and (max-width: 899px) {
  /* 橫式立繪放進直式資訊卡會只剩巨大臉部特寫。 */
  .opponents .opponent .standee { display: none !important; }
}

@media (orientation: portrait) and (max-width: 700px) {
  /* 九張在上、八張在下；依可用寬度重疊，窄 Android 也不生出第三排。 */
  #hand { --tile-overlap: clamp(-16px, calc(12.5vw - 52.25px), -7px); }
  #hand .tile-button:not(:first-child) { margin-left: var(--tile-overlap) !important; }
  #hand .tile-button:first-child,
  #hand .hand-break + .tile-button { margin-left: 0 !important; }
  #hand .tile-button.drawn { margin-left: 2px !important; }

  .app-shell.compact-table #table { gap: 3px; padding-inline: 6px; }
  .app-shell.compact-table .opponents { gap: 3px; }
  .app-shell.compact-table .opponents .opponent { min-height: 50px; padding: 3px; grid-template-columns: 38px minmax(0, 1fr); }
  .app-shell.compact-table .opponents .opponent .avatar-button { width: 38px !important; height: 38px !important; }
  .app-shell.compact-table .opponents .opponent-name strong { font-size: 10px; }
  .app-shell.compact-table .rivers-board { padding: 5px; }
}

.settings-card .table-fit-setting { display: grid; gap: 4px; }
.settings-card .table-fit-setting select { width: 100%; min-height: 44px; border: 1px solid rgba(231,185,91,.45); border-radius: 8px; padding: 4px 8px; color: #f8f2df; background: #103b32; font: inherit; }
.settings-card .mouse-discard-setting { display: grid; gap: 4px; }
.settings-card .mouse-discard-setting select { width: 100%; min-height: 44px; border: 1px solid rgba(231,185,91,.45); border-radius: 8px; padding: 4px 8px; color: #f8f2df; background: #103b32; font: inherit; }
.settings-card .game-speed-setting { display: grid; gap: 4px; }
.settings-card .game-speed-setting select { width: 100%; min-height: 44px; border: 1px solid rgba(231,185,91,.45); border-radius: 8px; padding: 4px 8px; color: #f8f2df; background: #103b32; font: inherit; }
.settings-card #table-fullscreen-help { flex-basis: 100%; margin: 0; color: #ead8aa; font-size: 12px; line-height: 1.4; }

@media (orientation: portrait) and (max-width: 359px) {
  /* 窄 Android 的輪次提示已在頂部 HUD，手牌旁不再重複擠成直排文字。 */
  .hand-heading:has(#hand-turn-cue) { display: none !important; }
}

/* 短橫式為角標保留一行空間，頭像下移但仍維持原座位排列。 */
@media (orientation: landscape) and (max-height: 600px) {
  #table .opponents .opponent > .avatar-wrap { margin-top: 14px; }
}

/* 副露與頭像分開佔位；已碰的整組牌不可在大畫面被拆成兩列。 */
@media (orientation: landscape) {
  #table .hand-zone:has(.hand-melds .meld-row) .hand-row { justify-content: center; padding-left: 80px !important; padding-right: 0 !important; }
  #table .hand-zone:has(.hand-melds .meld-row) #hand { flex: 0 1 auto; width: auto; }
  #table .hand-melds { max-width: none; flex-wrap: nowrap; }
  #table .hand-melds .meld-row { flex-wrap: nowrap; }
}

@media (orientation: landscape) and (max-height: 500px),
       (orientation: landscape) and (min-width: 700px) and (max-width: 899px) and (min-height: 501px) {
  /* inline-size 容器的內在寬度是 0；以目前牌數指定收縮前寬度。 */
  #table .hand-zone:has(.hand-melds .meld-row) #hand { flex: 0 1 var(--hand-natural-width); width: var(--hand-natural-width); }
}

@media (orientation: landscape) and (min-width: 900px) and (max-height: 600px) {
  #table .hand-zone:not(:has(.hand-melds .meld-row)) .hand-row { padding-left: 0 !important; }
  #table #hand .tile-button:not(:first-child) { margin-left: 0 !important; }
  #table #hand .tile-button.drawn { margin-left: 2px !important; }
}

@media (orientation: landscape) and (min-width: 1024px) and (min-height: 501px) and (max-height: 600px) {
  #table .hand-zone .player-identity { left: 6px; bottom: 0; width: 64px; min-height: 0; flex-direction: column; gap: 0; padding: 0; font-size: 14px; text-align: center; }
  #table .hand-zone .player-identity img { width: 56px; height: 56px; border-radius: 14px; }
  #table .hand-zone .player-identity > strong { position: absolute; left: 50%; bottom: 2px; max-width: 58px; padding: 1px 4px; overflow: hidden; border-radius: 999px; background: rgba(5, 29, 24, .84); text-overflow: ellipsis; transform: translateX(-50%); white-space: nowrap; }
}

@media (orientation: landscape) and (min-width: 1024px) and (min-height: 601px) {
  #table .hand-zone:has(.hand-melds .meld-row) .hand-row { padding-left: 180px !important; padding-right: 0 !important; }
}

@media (orientation: landscape) and (min-width: 900px) and (min-height: 601px) {
  #table .hand-zone:has(.hand-melds .meld-row) #hand .tile-button:not(:first-child) { margin-left: 0 !important; }
  #table .hand-zone:has(.hand-melds .meld-row) #hand .tile-button.drawn { margin-left: 2px !important; }
}
/* 聽牌自動摸打：僅顯示自己的控制，不遮住手牌。 */
.ready-control{display:flex;align-items:center;gap:8px;flex-wrap:wrap;margin:6px 0;color:#f6dfa0;font-size:13px}
.ready-control button{min-height:44px;padding:8px 14px;border:1px solid #e1b954;border-radius:10px;background:#173d33;color:#ffedb5;font:inherit;cursor:pointer}
.ready-control button:disabled{opacity:.5;cursor:default}
.ready-control button:focus-visible{outline:3px solid #f4cf59;outline-offset:2px}
.ready-control span{flex:1;min-width:160px}
.actions .ready-control{width:100%;justify-content:center}
#ready-auto:empty{display:none}

/* EN/FR labels may take two lines; keep controls readable and comfortably tappable. */
#actions .action-button,
.dialog-actions .dialog-button,
.settings-actions button,
.campaign-actions button,
.select-actions button,
.lobby-actions button,
.room-actions button {
  height: auto;
  min-height: 44px;
  padding-block: 8px;
  white-space: normal;
  overflow-wrap: normal;
  word-break: normal;
  hyphens: none;
  line-height: 1.2;
}
#actions .action-button { flex: 0 1 auto; max-width: 100%; }
.dialog-actions .dialog-button { min-width: 0; }
@media (orientation:landscape) and (max-height:500px){
 .actions:has(#ready-auto:not(:empty)){overflow:visible;gap:6px}
 .actions:has(#ready-auto:not(:empty)) .action-button.win{position:static;inset:auto;min-width:52px;min-height:44px;padding:8px 12px;animation:none}
 .actions #ready-auto .ready-control{width:auto;margin:0}
}

/* 窄畫面保留三位對手的左右座位順序，副露在各自牌況列完整換行顯示。 */
@media (orientation: portrait) and (max-width: 700px) {
  #table { overflow-x: hidden; overflow-y: auto; }
  #table .opponents {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    align-items: start;
    gap: 4px;
    height: auto;
    min-height: 0;
    overflow: visible;
  }
  #table .opponents .opponent {
    position: relative;
    display: grid;
    grid-template-columns: 44px minmax(0, 1fr);
    grid-template-rows: auto auto auto;
    align-items: start;
    gap: 2px 4px;
    width: 100%;
    height: auto;
    min-height: 0;
    max-height: none;
    padding: 3px 4px;
    overflow: visible;
    text-align: left;
  }
  #table .opponents .opponent > .avatar-wrap {
    position: relative;
    inset: auto;
    grid-column: 1;
    grid-row: 1;
    width: 44px;
    height: 44px;
    transform: none;
  }
  #table .opponents .opponent .avatar-button,
  #table .opponents .opponent:nth-child(1) .avatar-button {
    width: 44px !important;
    height: 44px !important;
    border-radius: 12px !important;
  }
  #table .opponents .opponent-main { display: contents; position: static; overflow: visible; }
  #table .opponents .opponent-name {
    grid-column: 2;
    grid-row: 1;
    align-self: center;
    min-width: 0;
  }
  #table .opponents .opponent-main > .meld-row {
    display: flex;
    grid-column: 1 / -1;
    grid-row: 2;
    flex-wrap: wrap;
    align-items: flex-start;
    justify-content: flex-start;
    gap: 3px;
    width: 100%;
    min-height: 0;
    max-height: none;
    margin: 1px 0 0;
    padding: 0;
    overflow: visible;
    background: none;
  }
  #table .opponents .opponent-main > .meld-row > .meld-row {
    display: flex;
    flex: 0 0 auto;
    flex-wrap: nowrap;
    gap: 1px;
    width: max-content;
    max-width: none;
    min-height: 24px;
    margin: 0;
    padding: 0;
    overflow: visible;
  }
  #table .opponents .opponent-main > .meld-row > .meld-row .tile {
    flex: 0 0 16px;
    width: 16px;
    height: 22px;
    min-width: 16px;
    font-size: 6px;
  }
  #table .opponents .opponent-main > .flower-row {
    display: flex;
    grid-column: 1 / -1;
    grid-row: 3;
    flex-wrap: wrap;
    gap: 2px;
    min-height: 0;
    max-height: none;
    margin: 0;
    padding: 0;
    overflow: visible;
  }
  #table .opponents .opponent-main > .flower-row .tile {
    flex: 0 0 18px;
    width: 18px;
    height: 24px;
    font-size: 7px;
  }
  #table .opponents .opponent-main > .meld-row::after { content: none !important; }
}

/* 將公開動作提示固定在頭像右上角，與莊家左上角標記分開。 */
.opponents .avatar-wrap > .action-banner {
  top: -9px;
  right: -10px;
  bottom: auto;
  left: auto;
  width: max-content;
  min-width: 0;
  max-width: min(150px, calc(100vw - 16px));
  padding: 0 2px;
  border-width: 1px;
  border-radius: 8px;
  font-size: 10px;
  line-height: 1;
  white-space: nowrap;
  transform: scale(1);
  transform-origin: top right;
  animation-name: action-banner-corner-life;
}
@keyframes action-banner-corner-life {
  0% { opacity: 0; transform: scale(.82); }
  14%, 72% { opacity: 1; transform: scale(1); }
  100% { opacity: 0; transform: scale(.94); }
}
.opponents .avatar-wrap > .dealer-badge {
  top: -9px;
  right: auto;
  left: -10px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1px;
  min-width: 0;
  min-height: 14px;
  padding: 0 2px;
  border-width: 1px;
  font-size: 11px;
  transform: none;
  transform-origin: top left;
}
.opponents .opponent-name > .dealer-label { display: none !important; }
.opponents .avatar-wrap > .dealer-badge small {
  display: inline;
  margin: 0 0 0 1px;
  font-size: 7px;
}
.player-identity .player-avatar-wrap > .dealer-badge {
  top: -14px;
  right: auto;
  left: -9px;
  transform: none;
}
@media (prefers-reduced-motion: reduce) {
  .opponents .avatar-wrap > .action-banner,
  .opponents .standee-corners > .action-banner { animation: none !important; }
}

/* 桌機角標錨定可見立繪；手機與平板仍錨定 44px 頭像。 */
.standee-corners { display: none; }
@media (min-width: 1280px) and (min-height: 700px) {
  .opponents .standee { overflow: visible; }
  .opponents .standee-corners {
    position: absolute;
    z-index: 12;
    inset: 0;
    display: block;
    pointer-events: none;
    filter: none;
  }
  .opponents .standee-corners > .dealer-badge {
    top: -12px;
    left: -4px;
    right: auto;
    min-width: 0;
    min-height: 17px;
    padding: 1px 4px;
    border-width: 1px;
    font-size: 11px;
    transform: none;
  }
  .opponents .standee-corners > .dealer-badge { display: flex; align-items: center; justify-content: center; gap: 2px; }
  .opponents .standee-corners > .dealer-badge small { display: inline; margin: 0; font-size: 8px; }
  .opponents .standee-corners > .action-banner {
    top: -12px;
    right: -4px;
    bottom: auto;
    left: auto;
    width: max-content;
    min-width: 0;
    max-width: min(150px, calc(100vw - 16px));
    padding: 2px 5px;
    border-width: 1px;
    border-radius: 8px;
    font-size: 13px;
    line-height: 1;
    white-space: nowrap;
    transform: scale(1);
    transform-origin: top right;
    animation-name: action-banner-corner-life;
  }
  .opponents .avatar-wrap > .dealer-badge,
  .opponents .avatar-wrap > .action-banner { display: none !important; }
  .opponents .opponent-name > .dealer-label { display: none !important; }
}
@media (orientation: landscape) and (min-height: 501px) and (max-height: 600px) and (max-width: 1279px) {
  #table .opponents .opponent {
    display: grid;
    grid-template-columns: 44px minmax(0, 1fr);
    grid-template-rows: auto auto auto;
    align-items: start;
    gap: 2px 4px;
    width: 28%;
    min-height: 0;
    max-height: none;
    overflow: visible;
  }
  #table .opponents .opponent:nth-child(1) {
    top: 0;
    left: 50%;
    width: 36%;
    max-width: 280px;
    transform: translateX(-50%);
  }
  #table .opponents .opponent:nth-child(2) {
    top: 8px;
    left: 0;
    max-width: 240px;
    align-items: start;
  }
  #table .opponents .opponent:nth-child(3) {
    top: 8px;
    right: 0;
    left: auto;
    max-width: 240px;
    align-items: start;
  }
  #table .opponents .opponent > .avatar-wrap {
    position: relative;
    inset: auto;
    grid-column: 1;
    grid-row: 1;
    width: 44px;
    height: 44px;
    transform: none;
  }
  #table .opponents .opponent .avatar-button,
  #table .opponents .opponent:nth-child(1) .avatar-button {
    width: 44px !important;
    height: 44px !important;
    border-radius: 12px !important;
  }
  #table .opponents .opponent-main { display: contents; position: static; overflow: visible; }
  #table .opponents .opponent-name { grid-column: 2; grid-row: 1; min-width: 0; }
  #table .opponents .opponent-main > .meld-row {
    display: flex;
    grid-column: 1 / -1;
    grid-row: 2;
    flex-wrap: wrap;
    align-content: flex-start;
    gap: 2px;
    width: 100%;
    max-height: none;
    margin: 1px 0 0;
    padding: 0;
    overflow: visible;
  }
  #table .opponents .opponent-main > .meld-row > .meld-row {
    display: flex;
    flex: 0 0 auto;
    flex-wrap: nowrap;
    gap: 1px;
    width: max-content;
    max-width: none;
    min-height: 21px;
    margin: 0;
    padding: 0;
    overflow: visible;
  }
  #table .opponents .opponent-main > .meld-row > .meld-row .tile {
    flex: 0 0 15px;
    width: 15px;
    height: 21px;
    min-width: 15px;
    font-size: 6px;
  }
  #table .opponents .opponent-main > .flower-row {
    display: flex;
    grid-column: 1 / -1;
    grid-row: 3;
    flex-wrap: wrap;
    gap: 1px;
    max-height: none;
    margin: 0;
    padding: 0;
    overflow: visible;
  }
  #table .opponents .opponent-main > .flower-row .tile { flex: 0 0 18px; width: 18px; height: 24px; font-size: 7px; }
  #table .opponents .opponent-main > .meld-row::after { content: none !important; }
}

@media (min-width: 481px) and (max-width: 899px) and (orientation: portrait) and (min-height: 700px) {
  #table .opponents .opponent-main > .meld-row {
    max-height: none;
    overflow: visible;
  }
}

@media (orientation: landscape) and (max-height: 500px) {
  #table { grid-template-rows: 44px minmax(min-content, auto) minmax(60px, 1fr) auto 64px !important; }
  #table:has(.hand-melds > .flower-row) {
    grid-template-rows: 44px minmax(min-content, auto) minmax(60px, 1fr) auto 98px !important;
  }
  #table:has(.hand-melds > .flower-row) .hand-zone { height: 98px; min-height: 98px; }
  #table .opponents {
    height: auto !important;
    min-height: 0;
    align-items: start;
    overflow: visible;
  }
  #table .opponents .opponent {
    height: auto;
    min-height: 0;
    max-height: none;
    padding: 2px;
    overflow: visible;
    align-content: start;
    grid-template-columns: 44px minmax(0, 1fr);
    grid-template-rows: auto auto auto;
    gap: 1px 3px;
  }
  #table .opponents .opponent > .avatar-wrap {
    position: relative;
    inset: auto;
    grid-column: 1;
    grid-row: 1;
    width: 44px;
    height: 44px;
    transform: none;
  }
  #table .opponents .opponent .avatar-button,
  #table .opponents .opponent:nth-child(1) .avatar-button {
    width: 44px !important;
    height: 44px !important;
    border-radius: 12px !important;
  }
  #table .opponents .opponent-main { display: contents; position: static; overflow: visible; }
  #table .opponents .opponent-name { grid-column: 2; grid-row: 1; min-width: 0; }
  #table .opponents .opponent-main > .meld-row {
    display: flex;
    grid-column: 1 / -1;
    grid-row: 2;
    flex-wrap: wrap;
    justify-content: flex-start;
    align-content: flex-start;
    gap: 2px;
    width: 100%;
    max-height: none;
    margin: 1px 0 0;
    padding: 0;
    overflow: visible;
  }
  #table .opponents .opponent-main > .meld-row > .meld-row {
    display: flex;
    flex: 0 0 auto;
    flex-wrap: nowrap;
    gap: 1px;
    width: max-content;
    max-width: none;
    min-height: 21px;
    margin: 0;
    padding: 0;
    overflow: visible;
  }
  #table .opponents .opponent-main > .meld-row > .meld-row .tile {
    flex: 0 0 18px;
    width: 18px;
    height: 24px;
    min-width: 18px;
    font-size: 7px;
  }
  #table .opponents .opponent-main > .flower-row {
    display: flex;
    grid-column: 1 / -1;
    grid-row: 3;
    flex-wrap: wrap;
    gap: 1px;
    max-height: none;
    margin: 0;
    padding: 0;
    overflow: visible;
  }
  #table .opponents .opponent-main > .flower-row .tile { flex: 0 0 18px; width: 18px; height: 24px; font-size: 7px; }
  #table .opponents .opponent-main > .meld-row::after { content: none !important; }
}

/* Apply image clipping to every visible standee breakpoint. The badges stay outside this layer. */
#table .opponents .standee {
  overflow: visible;
  isolation: isolate;
}
#table .opponents .standee-visual {
  position: absolute;
  z-index: 0;
  inset: 0;
  overflow: hidden;
  border-radius: inherit;
  pointer-events: none;
}
#table .opponents .standee-visual > .standee-body {
  display: block;
  width: 100%;
  height: 100%;
  max-width: 100%;
  max-height: 100%;
}
#table .opponents .standee-visual > .standee-expression { z-index: 2; }
#table .opponents .standee-corners {
  position: absolute;
  z-index: 12;
  inset: 0;
  overflow: visible;
  pointer-events: none;
}
