:root {
  color-scheme: dark;
  --ink: #0d1728;
  --navy: #101f39;
  --line: #506987;
  --muted: #a9bed1;
  --text: #f6ecd3;
  --gold: #e9c77f;
  --ui-font: "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  --display-font: "Songti SC", "STSong", SimSun, serif;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; min-height: 100vh; color: var(--text); background: linear-gradient(160deg,#172946,var(--ink) 68%); font: 16px/1.5 var(--ui-font); }
button { color: inherit; font: inherit; cursor: pointer; }
button:disabled { cursor: default; opacity: .43; }
button:focus-visible, summary:focus-visible, .card-strip:focus-visible, .card-rail:focus-visible { outline: 2px solid #f4ce83; outline-offset: 3px; }
h1,h2,h3,p { margin: 0; }
.shell { max-width: 1320px; padding-inline: clamp(14px,4vw,54px); margin-inline: auto; }
.topbar { min-height: 80px; display: flex; align-items: center; justify-content: space-between; gap: 15px; }
.brand,.top-actions { display: flex; align-items: center; gap: 11px; }
.seal { width: 39px; height: 39px; display: grid; place-content: center; grid-auto-flow: column; gap: 2px; background: #783938; border: 1px solid #b88367; border-radius: 4px; font: 700 14px var(--display-font); }
.seal span:last-child { transform: translateY(4px); }
.brand-kicker { display: block; font-size: 11px; letter-spacing: .17em; color: #cfb684; }
.brand h1 { font: 750 33px/1.08 var(--display-font); letter-spacing: .045em; }
.table-switch { display: flex; gap: 2px; padding: 3px; border-radius: 7px; border: 1px solid #405776; background: #0c1728; }
.switch-button,.line-button,.gold-button,.sort-button { min-height: 35px; border-radius: 5px; padding: 5px 12px; white-space: nowrap; font-size: 14px; font-weight: 650; }
.switch-button { border: 0; background: transparent; color: var(--muted); min-height: 30px; }
.switch-button[aria-pressed=true] { color: #f6dfac; background: #283e5a; box-shadow: inset 0 0 0 1px #7590a64d; }
.line-button,.sort-button { border: 1px solid #597795; background: linear-gradient(#294663,#192d48); }
.line-button:hover:not(:disabled),.sort-button:hover:not(:disabled),.switch-button:hover { background: #3f5d7d; }
.gold-button { border: 1px solid #e4c781; color: #322112; background: linear-gradient(#f7d899,#cf9e54); }
.gold-button:hover:not(:disabled) { background: #ffe4ab; }

.workspace { padding-bottom: 24px; }
.game { min-width: 0; border: 1px solid #59728b; border-radius: 14px; overflow: hidden; background: #10233a; box-shadow: 0 22px 55px #070d1b91; }
.felt { position: relative; min-height: 363px; height: clamp(363px,50vh,490px); isolation: isolate; background: radial-gradient(ellipse at 50% 48%,#1d526b 1%,#183957 49%,#111f38 89%); }
.felt::before { content: ""; position: absolute; inset: 0; z-index: -1; pointer-events: none; background: repeating-linear-gradient(26deg,#c0d7e406 0 1px,transparent 1px 4px),repeating-linear-gradient(114deg,#020b171c 0 1px,transparent 1px 4px); }
.felt-border { position: absolute; inset: 8px; border: 1px solid #8cacc12e; border-radius: 8px; pointer-events: none; }
.table-meta { position: absolute; z-index: 2; top: 16px; left: 20px; right: 20px; display: flex; justify-content: space-between; gap: 10px; align-items: start; font-size: 13px; }
.round-display,.table-rotation { display: flex; align-items: center; gap: 8px; border: 1px solid #6687a666; border-radius: 4px; background: #10213bdc; color: #e7d8b5; padding: 4px 7px; white-space: nowrap; }
.stages { display: flex; gap: 3px; }
.stage { display: grid; place-content: center; padding: 0 5px; min-width: 20px; height: 20px; border-radius: 3px; color: #b6c9d8; background: #30506b8f; font: 700 13px var(--display-font); }
.stage.current { color: #2e291d; background: #e0c083; }
.stage.done { color: #e3cda0; }
.table-center { position: absolute; text-align: center; }
.center-mark { position: absolute; inset: 0; z-index: -1; display: grid; place-content: center; grid-auto-flow: column; gap: .12em; pointer-events: none; font: 850 clamp(35px,8vw,108px)/1 var(--display-font); color: #d8f1f617; }
.wall-count { color: #d7e4ef; font-size: 13px; white-space: nowrap; }
.wall-count strong { display: inline-block; color: #f9d18e; font-size: 20px; font-variant-numeric: tabular-nums; padding-inline: 2px; }
.center-content { min-width: 0; max-width: 100%; display: grid; justify-items: center; gap: 6px; }
.center-note { color: #f9dfaa; padding: 3px 7px; border-radius: 4px; background: #112a44dc; font-size: 13px; white-space: nowrap; }
.center-hint { color: #c6d9e5; font-size: 12px; }
.center-opening { display: grid; justify-items: center; gap: 5px; }
.center-opening strong,.end-title { color: #f6d799; font: 750 clamp(23px,4vw,37px) var(--display-font); }
.result-box { display: grid; justify-items: center; gap: 5px; min-width: 0; max-width: 100%; }
.result-groups { display: flex; flex-wrap: wrap; justify-content: center; gap: 3px; padding: 3px; max-height: 110px; overflow: auto; }
.result-total { color: #f7ead0; font-size: 14px; line-height: 1.1; }
.result-total strong { color: #ffdfa7; font-size: clamp(21px, 5vw, 30px); font-variant-numeric: tabular-nums; }
.result-stats { color: #f7ead0; font-size: 12px; }
.result-stats span { background: #102a44; border: 1px solid #7c98aa87; border-radius: 4px; padding: 1px 4px; white-space: nowrap; }
.result-stats strong { color: #ffdfa7; font-size: 14px; font-variant-numeric: tabular-nums; }
.result-end { color: #d4e3ed; font-size: 13px; }
.result-end strong { font-variant-numeric: tabular-nums; }
.result-fans { display: flex; flex-wrap: wrap; justify-content: center; gap: 4px; list-style: none; margin: 0; padding: 0; }
.result-fans li { margin: 0; padding: 1px 5px; border: 1px solid #9e865364; border-radius: 4px; background: #172e47; color: #f6e3b9; font-size: 11px; white-space: nowrap; }
.result-fans strong { color: #ffd78e; font-variant-numeric: tabular-nums; }

.seat { position: absolute; z-index: 1; width: clamp(114px,22%,225px); display: grid; gap: 5px; }
.seat.north { top: 17px; left: 50%; transform: translateX(-50%); width: clamp(114px,21%,215px); }
.seat.west,.seat.east { top: 33%; }
.seat.west { left: 20px; }
.seat.east { right: 20px; }
.seat-name,.player-identity { display: flex; align-items: center; gap: 6px; min-width: 0; border: 1px solid #95a5a2; border-radius: 5px; color: #22354b; background: linear-gradient(120deg,#f3ead3,#c4d4d0); padding: 5px 6px; box-shadow: inset 0 0 0 2px #e3e3d481,0 2px 4px #0a163484; }
.seat.active .seat-name { border-color: #ffce78; box-shadow: inset 0 0 0 1px #f1c879,0 0 13px #e7b85f43; }
.avatar { width: 33px; height: 33px; flex: 0 0 auto; display: grid; place-items: center; border-radius: 4px; border: 1px solid #b1cabb; color: #f8edc9; background: #316761; font: 750 17px var(--display-font); }
.seat[data-seat="2"] .avatar { background: #406c8c; }
.seat[data-seat="3"] .avatar { background: #805758; }
.hero-avatar { background: #835845; }
.identity-text { display: grid; min-width: 0; }
.identity-text strong,.identity-text h2 { font-size: 14px; white-space: nowrap; }
.hand-count,.player-tags { font-size: 11px; line-height: 1.3; color: #3d5365; white-space: nowrap; }
.seat-score { margin-left: auto; color: #664522; font-size: 13px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.role-pill { border-radius: 3px; color: #552c17; background: #e9c07a; padding: 1px 3px; font-size: 10px; font-weight: 750; line-height: 1.25; white-space: nowrap; }
.report-pill { background: #d1e0ac; }

.seat-history { width: 100%; min-width: 0; display: grid; grid-template-columns: minmax(0,1fr) 25px; gap: 2px 4px; padding: 3px; border: 1px solid #54738b99; border-radius: 5px; background: #0e2036b3; }
.past-flips { min-height: 63px; display: flex; align-items: flex-start; gap: 4px; }
.card-strip { min-width: 0; overflow-x: auto; overflow-y: hidden; overscroll-behavior-x: contain; scrollbar-width: none; }
.card-strip::-webkit-scrollbar { display: none; }
.card-rail { grid-column: 1/-1; width: 100%; min-width: 0; height: 11px; margin: 0; padding: 0; border: 0; appearance: none; background: transparent; cursor: ew-resize; touch-action: none; --rail-thumb: #a3bacd; }
.card-rail:focus-visible { outline-offset: 0; }
.card-rail:disabled { color: inherit; opacity: 1; cursor: default; --rail-thumb: #5b7389; }
.card-rail::-webkit-slider-runnable-track { height: 4px; border-radius: 3px; background: #304a62; }
.card-rail::-moz-range-track { height: 4px; border-radius: 3px; background: #304a62; }
.card-rail::-webkit-slider-thumb { width: var(--thumb-size, 100%); height: 6px; margin-top: -1px; border: 0; border-radius: 4px; appearance: none; background: var(--rail-thumb); }
.card-rail::-moz-range-thumb { width: var(--thumb-size, 100%); height: 6px; border: 0; border-radius: 4px; background: var(--rail-thumb); }
.latest-flip { display: grid; justify-items: center; min-height: 52px; padding-left: 3px; border-left: 1px solid #91a8ba61; }
.flip-card { display: grid; justify-items: center; gap: 3px; flex: 0 0 auto; }
.flip-number { font-size: 10px; line-height: 1; color: #bdd0df; white-space: nowrap; }
.latest-flip .flip-number { color: #f2ce8d; }
.latest-flip .tile { background: linear-gradient(#fcfaf0,#e6ede7); border-color: #e9c57d; }
.global-latest .latest-flip .tile { outline: 1px solid #ffdea0; box-shadow: 0 0 8px #fbcf79a6; }
.flip-placeholder { width: 19px; height: 56px; border: 1px dashed #819bad73; border-radius: 3px; }

.player-area { position: relative; display: grid; grid-template-columns: clamp(140px,20%,240px) minmax(0,1fr) max-content; grid-template-areas: "self control tools" "self hand tools"; gap: 4px 12px; align-items: start; padding: 13px 18px 16px; border-top: 1px solid #5c7a956e; background: linear-gradient(150deg,#182d47,#101f37 72%); }
.self-seat { grid-area: self; min-width: 0; display: grid; gap: 5px; }
.hand-meta { display: flex; align-items: center; gap: 5px; }
.hand-red,.timer { min-width: 0; border: 1px solid #8c764d; border-radius: 4px; background: #2b2c2b; padding: 1px 6px; color: #f3cb89; font-size: 12px; white-space: nowrap; }
.hand-red strong { font-size: 15px; font-variant-numeric: tabular-nums; }
.timer { border-color: #688299; color: #dbe9f2; background: #293c57; }
.control-bar { grid-area: control; display: flex; min-height: 40px; align-items: center; justify-content: space-between; gap: 6px; }
.status { min-width: 0; color: #f7d490; font-size: 15px; font-weight: 650; }
.status small { display: block; color: #c1d2e0; font-size: 12px; font-weight: 400; }
.moves { display: flex; justify-content: flex-end; gap: 5px; flex-wrap: wrap; }
.moves .gold-button,.moves .line-button { min-width: 49px; }
.utility-controls { grid-area: tools; display: grid; align-self: end; gap: 5px; }
.utility-controls button { min-height: 31px; }
.hand { grid-area: hand; min-width: 0; min-height: 103px; display: flex; align-items: center; flex-wrap: wrap; gap: 9px 7px; padding: 6px 3px 3px; touch-action: pan-y; }
.hand-group { display: inline-flex; align-items: center; flex-wrap: wrap; max-width: 100%; gap: 4px; }
.hand:not(.manual-order) .hand-group + .hand-group { border-left: 1px solid #9db2c355; padding-left: 4px; }
.tile { --tile-width: clamp(25px,3.8vw,43px); display: flex; flex-direction: column; justify-content: space-between; align-items: stretch; width: var(--tile-width); flex: 0 0 var(--tile-width); height: calc(var(--tile-width) * 3.12); padding: 4px 0; border: 1px solid #c3cbcc; border-radius: 5px; background: linear-gradient(138deg,#f7f8f1,#dfe9e7 82%); box-shadow: inset 0 0 0 2px #f3f6f2,0 3px 0 #748889,0 6px 9px #07101b8c; }
.tile.large { --tile-width: 49px; }
.tile.compact { --tile-width: 19px; height: 56px; padding: 1px 0; border-radius: 3px; box-shadow: inset 0 0 0 1px #f3f6f2,0 2px 0 #748889; }
.hand .tile { cursor: grab; user-select: none; touch-action: pan-y; }
.hand .tile.playable:hover,.hand .tile.selected { transform: translateY(-5px); outline: 2px solid #ebc271; }
.hand.is-dragging,.hand.is-dragging .tile { cursor: grabbing; }
.hand .drag-origin { opacity: .43; }
.hand .drop-before { box-shadow: -4px 0 #edc177,0 3px #8d7148; }
.hand .drop-after { box-shadow: 4px 0 #edc177,0 3px #8d7148; }

.table-details { display: grid; gap: 8px; margin-top: 10px; }
.panel { border: 1px solid #465f7d; border-radius: 7px; background: #15273f; }
.panel summary { cursor: pointer; color: #ecd4a4; padding: 7px 12px; font-size: 14px; }
.round-panel summary span { float: right; font-size: 12px; color: var(--muted); }
.round-details { display: grid; grid-template-columns: minmax(145px,1fr) 2fr; gap: 15px; padding: 4px 12px 12px; }
.score-row { display: flex; align-items: center; gap: 6px; border-top: 1px solid #3d5470; padding: 4px 0; font-size: 13px; }
.score-row .avatar { width: 22px; height: 22px; font-size: 12px; }
.score-row .tag { color: var(--gold); font-size: 11px; }
.score-row strong { margin-left: auto; color: #f2ddb3; font-variant-numeric: tabular-nums; }
.log { list-style: none; padding: 0; margin: 0; max-height: 162px; overflow-y: auto; scrollbar-width: thin; }
.log li { border-top: 1px solid #3d5470; padding: 4px 0; color: #c0d0e0; font-size: 13px; }
.log li:first-child { color: #f8d79d; }
.public-group { display: inline-flex; gap: 3px; flex: 0 0 auto; border: 1px solid #536f88; border-radius: 4px; padding: 2px 2px 4px; }
.sheet { color: var(--text); background: #172b46; border: 1px solid #7591aa; border-radius: 11px; width: min(540px,calc(100% - 26px)); max-height: 82vh; padding: 20px; box-shadow: 0 14px 70px #0008; }
.sheet::backdrop { background: #060d1bd4; }
.dialog-head,.dialog-actions { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 10px; }
.dialog-head h2 { font: 750 25px var(--display-font); }
.dialog-actions { justify-content: flex-end; margin: 14px 0 0; }
.rules-copy p,.reset-sheet p { color: #d9e2eb; font-size: 15px; }
.rules-copy h3 { color: var(--gold); font-size: 16px; margin-top: 10px; }
.rules-copy p+p { margin-top: 5px; }

@media (prefers-reduced-motion: no-preference) {
  .hand .tile { transition: transform .12s ease; }
}

.face-end { display: grid; grid-template-columns: 1fr 1fr; gap: 1px; margin-inline: 1px; height: 24%; flex: 0 0 24%; }
.face-end.bottom { transform: rotate(180deg); }
.pip-group { position: relative; min-width: 0; }
.pip { position: absolute; width: 38%; height: 32%; border-radius: 50%; background: #151c1c; transform: translate(-50%,-50%); }
.pip.red { background: #a92443; }
.pip-group[data-pip-count="1"] .pip,.pip-group[data-pip-count="2"] .pip { width: 49%; height: 36%; }
.pip-group[data-pip-count="3"] .pip { width: 61%; height: 31%; }
.pip-group[data-pip-count="5"] .pip { width: 35%; height: 28%; }
.pip-group[data-pip-count="6"] .pip { width: 34%; height: 35%; }
.tile.compact .face-end { gap: 0; margin-inline: 0; }

/* Portrait layout is the primary table on every screen. */
body { min-height: 100dvh; }
.shell { width: 100%; max-width: 500px; padding-inline: 9px; }
.topbar { min-height: 62px; padding-top: env(safe-area-inset-top); gap: 7px; }
.brand,.top-actions { gap: 6px; }
.brand h1 { font-size: 27px; }
.brand-kicker { font-size: 10px; letter-spacing: .1em; }
.seal { width: 31px; height: 31px; font-size: 12px; }
.table-switch { padding: 2px; }
.switch-button,.line-button,.gold-button,.sort-button { padding-inline: 10px; font-size: 14px; }
.topbar button { min-height: 39px; padding-inline: 8px; font-size: 13px; }
.workspace { padding-bottom: max(18px,env(safe-area-inset-bottom)); }
.game { border-radius: 16px; }
.felt { min-height: 290px; height: clamp(290px,40svh,365px); }
.table-meta { top: 10px; left: 12px; right: 12px; gap: 6px; font-size: 11px; }
.table-rotation { gap: 5px; padding-inline: 5px; }
.stage { min-width: 17px; height: 17px; font-size: 11px; padding-inline: 3px; }
.seat { width: 24%; }
.seat.north { width: 31%; top: 46px; }
.seat.east,.seat.west { top: 38%; }
.seat.east { right: 10px; }
.seat.west { left: 10px; }
.seat-name,.player-identity { gap: 4px; padding: 4px; flex-wrap: wrap; }
.identity-text strong,.identity-text h2 { font-size: 12px; }
.seat-score { font-size: 11px; }
.avatar { width: 24px; height: 24px; font-size: 13px; }
.hand-count,.player-tags { font-size: 10px; }
.center-content { gap: 4px; }
.center-note,.center-hint { font-size: 11px; }
.center-opening strong,.end-title { font-size: clamp(20px,6vw,31px); }
.past-flips { min-height: 56px; }
.latest-flip { min-height: 50px; }
.tile.compact,.flip-placeholder { height: 48px; }

.player-area { grid-template-columns: minmax(0,1fr) max-content; grid-template-areas: "self tools" "hand hand" "control control"; align-items: start; gap: 7px; padding: 8px 9px 9px; }
.self-seat { grid-template-columns: minmax(105px,1fr) minmax(56px,1fr); align-items: start; }
.hero-history { grid-column: 2; grid-row: 1/3; }
.hand-meta { grid-column: 1; }
.utility-controls { grid-auto-flow: row; align-self: stretch; gap: 4px; }
.utility-controls button { min-height: 34px; padding-inline: 7px; font-size: 12px; }
.hand { min-height: 69px; gap: 8px 4px; padding: 3px 2px 4px; }
.hand-group { gap: 3px; }
.hand:not(.manual-order) .hand-group + .hand-group { padding-left: 3px; }
.hand .tile { --tile-width: clamp(25px,7.1vw,34px); height: calc(var(--tile-width) * 2.9); touch-action: none; }
.control-bar { min-height: 58px; align-items: center; border-top: 1px solid #59789576; padding-top: 5px; }
.status { font-size: 13px; overflow-wrap: anywhere; }
.status small { font-size: 11px; }
.moves { flex: 0 0 auto; max-width: 65%; }
.moves .gold-button,.moves .line-button { min-height: 44px; min-width: 49px; }
.round-details { grid-template-columns: minmax(0,1fr) minmax(0,1.3fr); }
@media (hover: none) {
  .hand .tile.playable:not(.selected):hover { transform: none; outline: none; }
}
@media (max-width: 355px) {
  .shell { padding-inline: 5px; }
  .brand-kicker { display: none; }
  .topbar button { padding-inline: 6px; }
  .topbar { min-height: 56px; }
  .table-meta { left: 8px; right: 8px; }
  .seat.east { right: 8px; }
  .seat.west { left: 8px; }
  .seat-name { padding-inline: 3px; }
  .seat-name .avatar { width: 21px; height: 21px; }
  .seat-score { font-size: 10px; }
  .player-area { padding-inline: 7px; }
  .moves .line-button,.moves .gold-button { padding-inline: 7px; min-width: 43px; }
}

/* Older individual cards and exposed sets share one swipeable seat lane. */
.past-flips { padding-inline: 1px; }
.track-group { display: grid; justify-items: center; gap: 2px; flex: 0 0 auto; }
.track-group .public-group { gap: 2px; padding: 2px 3px 3px; background: #294454; border-color: #79978e; }
.track-group[data-group="steal"] .public-group { background: #434035; border-color: #8f7952; }
.track-group .tile.compact { --tile-width: 15px; height: 40px; }
.track-group-label { color: #cde2d3; font-size: 10px; line-height: 1; }
.track-group[data-group="steal"] .track-group-label { color: #efd18d; }
.track-empty { align-self: center; color: #a4b9ce; font-size: 10px; white-space: nowrap; padding-inline: 2px; }

/* Exposed sets sit above the player label; the separate timeline stays below it. */
.exposed-rack { display: grid; grid-template-columns: minmax(0,1fr); gap: 2px; min-width: 0; max-width: 100%; padding: 1px; }
.exposed-cards { display: flex; align-items: flex-end; gap: 4px; padding: 1px 0 2px; }
.exposed-cards:empty { padding: 0; }
.track-group { align-content: end; gap: 1px; border: 1px solid #668679; border-radius: 4px; padding: 1px 3px 2px; background: #243f51; }
.track-group[data-group="steal"] { background: #403d33; border-color: #8f7952; }
.meld-stack-row { display: flex; gap: 3px; align-items: end; }
.meld-stack { position: relative; display: inline-block; width: 18px; height: 13px; overflow: hidden; isolation: isolate; border-radius: 3px; }
.meld-stack[data-count="2"] { height: 25px; }
.meld-stack .tile.compact { position: absolute; inset: 0 auto auto 0; --tile-width: 18px; height: 48px; }
.meld-stack .tile.compact:nth-child(2) { top: 12px; }
.self-seat { grid-template-columns: minmax(76px,1fr) auto; grid-template-areas: "groups groups" "identity meta" "history history"; }
.hero-exposed { grid-area: groups; min-width: 0; min-height: 74px; display: grid; align-items: end; }
.player-identity { grid-area: identity; }
.hand-meta { grid-area: meta; flex-wrap: wrap; justify-content: flex-end; }
.hero-history { grid-area: history; }
.felt { --center-card-width: clamp(36px,9vw,46px); --center-card-height: calc(var(--center-card-width) * 2.55); }
.felt:has(.north) { min-height: max(395px,calc(320px + var(--center-card-height))); }
@media (max-width: 355px) {
  .hand-meta { max-width: 53px; gap: 3px; }
  .hand-red,.timer { padding-inline: 3px; }
}

.meld-stack[data-count="3"] { height: 37px; }
.meld-stack .tile.compact:nth-child(3) { top: 24px; }
.hand .tile.chi-match { background: linear-gradient(145deg,#f9fcf0,#dff1db 80%); border-color: #79cba8; box-shadow: inset 0 0 0 2px #9cdec1, 0 3px 0 #548c78, 0 0 8px #97eac66b; }
.hand .tile.chi-match.selected { outline-color: #f6d482; }
.player-identity { position: relative; }
.meld-effect { --spark: #addfcc; position: absolute; z-index: 5; top: -8px; right: 4px; pointer-events: none; min-width: 25px; padding: 1px 5px; color: #f2fcf1; background: #19483e; border: 1px solid var(--spark); border-radius: 5px; font: 750 15px/1.25 var(--display-font); text-align: center; }
.meld-effect-peng { --spark: #f2c878; background: #64451e; color: #fff0c6; }

.meld-stack[data-count="4"] { height: 49px; }
.meld-stack .tile.compact:nth-child(4) { top: 36px; }


/* Leave room for six matching groups while fitting twelve cards in one row. */
.player-cards { grid-area: hand; min-width: 0; container-type: inline-size; }
.hand { flex-wrap: nowrap; gap: 5px; height: clamp(70px,20cqw,102px); }
.hand-group { flex: 0 0 auto; flex-wrap: nowrap; max-width: none; gap: 3px; }
.hand:not(.manual-order) .hand-group + .hand-group { padding-left: 2px; }
.hand .tile { --tile-width: min(34px, calc((100cqw - 62px) / 12)); }
.hand .tile.playable:hover,.hand .tile.selected { transform: none; }
/* Cyan marks the replacement card. The gold ring follows the selection. */
.hand .tile.supplemented { position: relative; border-color: #2cabb9; }
.hand .tile.supplemented:not(.selected),
.hand .tile.supplemented.playable:not(.selected):hover { outline: 2px solid #6aedf0; outline-offset: 0; filter: drop-shadow(0 0 4px #56e1ecbb); }
.hand .tile.selected { outline: 2px solid #f4c96e; outline-offset: 1px; filter: drop-shadow(0 0 4px #f4c96ebb); }


.step-label { color: #adcce1; font-size: 11px; padding: 2px 8px; border: 1px solid #83a9c34d; border-radius: 9px; background: #173650a6; white-space: nowrap; }
.seat.east,.seat.west { top: calc(38% + 30px); }
.seat.north { top: 112px; }
.seat > .exposed-rack { position: absolute; inset-inline: 0; bottom: calc(100% + 3px); }
.seat-heading .seat-name { min-height: 36px; }
.table-center { inset: calc(50% - var(--center-card-height) / 2 - 30px) 29% 8px; display: grid; grid-template-rows: 25px minmax(0,1fr); gap: 5px; justify-content: stretch; align-items: start; }
.felt:has(.north) .table-center { top: 243px; }
.center-meta { display: flex; align-items: center; justify-content: center; gap: 5px; white-space: nowrap; }
.center-meta .step-label { padding: 2px 5px; }
.center-meta .wall-count { font-size: 11px; }
.center-meta .wall-count strong { min-width: 2.1ch; padding: 0; font-size: 22px; line-height: 1; }
.center-content { align-content: start; }
.center-note { white-space: normal; }
.center-action { display: grid; grid-template-columns: minmax(0,1fr); justify-items: center; gap: 6px; width: 100%; min-width: 0; }
.center-action-copy { display: grid; gap: 3px; justify-items: center; min-width: 0; max-width: 100%; text-align: center; overflow-wrap: anywhere; }
.center-action-copy .center-note { max-width: 100%; font-size: 12px; }
.center-action-copy .center-hint { padding-inline: 4px; }
.felt:has(.result-box) { height: auto; padding: clamp(60px,18vw,90px) 29% 14px; }
.felt:has(.north):has(.result-box) { padding-top: 243px; }
.felt:has(.result-box) .table-center { position: relative; inset: auto; grid-template-rows: 25px auto; }
.table-center .tile.large,.drawing-card { --tile-width: var(--center-card-width); width: var(--tile-width); height: var(--center-card-height); }
.drawing-card { border-radius: 4px; border: 1px solid #7c9fb6; background: repeating-linear-gradient(45deg,#24475d 0 3px,#355d72 3px 5px); box-shadow: 0 3px 0 #172939; }
.hand .tile.kan-match:not(.chi-match) { box-shadow: inset 0 0 0 2px #91b5d2,0 3px 0 #577990; }
.hand .tile.wait-match { background: linear-gradient(145deg,#fffae5,#e7ddbc 80%); border-color: #eac87d; box-shadow: inset 0 0 0 2px #e2c27a,0 3px 0 #9d783b; }
.meld-stack .tile.tile-back { background: repeating-linear-gradient(45deg,#24475d 0 3px,#355d72 3px 5px); border-color: #a1bbc7; box-shadow: inset 0 0 0 1px #1d394e; }
.revealed-hands { grid-area: hand; min-width: 0; padding: 7px 0; }
.revealed-hands h2 { margin: 0 0 6px; color: #f4d6a1; font-size: 15px; }
.revealed-seat { padding: 6px 7px; border-top: 1px solid #5c7a9559; }
.revealed-name { display: flex; align-items: center; gap: 7px; font-size: 14px; }
.revealed-name span { padding: 1px 5px; border-radius: 3px; background: #e9bb70; color: #392610; font-size: 12px; font-weight: 700; }
.revealed-cards { display: flex; gap: 3px; min-width: 0; overflow-x: auto; padding-block: 4px; }
.revealed-cards .tile.compact { --tile-width: 20px; height: 57px; }
.tile.winning-tile { position: relative; border-color: #f2bb55; background: #fff5da; outline: 1px solid #f2bb55; box-shadow: inset 0 0 0 1px #fff0c1, 0 2px 0 #aa7739; }
.winning-stamp { position: absolute; top: 50%; left: 50%; transform: translate(-50%,-50%); border-radius: 3px; padding: 0 2px; background: #8d5822; color: #fff4d9; font-size: 10px; font-weight: 700; line-height: 14px; white-space: nowrap; }
.meld-effect-kan { --spark: #b7d5f5; background: #234b71; color: #f0f7ff; }
.control-bar { display: grid; grid-template-columns: minmax(0,1fr); align-items: stretch; justify-content: stretch; gap: 4px; container-type: inline-size; padding-top: 4px; }
.control-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; min-height: 38px; }
.status { flex: 1; line-height: 1.3; }
.status small { min-height: 1.3em; }
.moves { display: grid; grid-template-columns: repeat(4,minmax(0,1fr)); gap: 4px; max-width: none; }
.game-move { min-width: 0; min-height: 42px; padding: 0 3px; border: 1px solid #e8c98c; border-radius: 7px; color: #342315; background: linear-gradient(#f7d898,#d5a559); box-shadow: inset 0 1px #ffecc5, inset 0 -2px #aa783b; font-size: 15px; font-weight: 750; }
.game-move:hover:not(:disabled) { background: #f9dfa9; }
.game-move:active:not(:disabled) { background: #ce9e5b; box-shadow: inset 0 1px 2px #654722; }
.game-move:disabled { opacity: 1; color: #94abc0; background: #152941; border-color: #3b5570; box-shadow: none; }
.move-extra { flex: 0 0 auto; min-height: 36px; padding-inline: 10px; font-size: 13px; }
.utility-controls { align-self: start; align-content: start; }
@container (min-width: 380px) {
  .moves { grid-template-columns: repeat(8,minmax(0,1fr)); }
}

.mode-bar { display: flex; flex-wrap: wrap; gap: .45rem; margin-block: .35rem .75rem; }
.mode-bar button { min-width: 0; min-height: 2.55rem; padding-inline: .65rem; white-space: nowrap; }
.mode-bar [aria-pressed="true"] { color: #2e2010; background: linear-gradient(#f6d99c, #d0a460); border-color: #f1d092; font-weight: 750; }
#install-app { margin-left: auto; }
.room-lobby { color: #e6edf3; padding-bottom: 2rem; }
.lobby-heading, .lobby-section-head, .room-row, .active-room-bar { display: flex; justify-content: space-between; align-items: center; gap: .65rem; }
.lobby-heading { margin: .5rem 0 1rem; }
.lobby-heading h2 { font-size: clamp(1.35rem, 5vw, 1.85rem); }
.lobby-heading h2, .lobby-section-head h3, .lobby-panel h3 { color: #f4d492; margin: 0; }
.lobby-heading span, .lobby-section-head span, .waiting-hint, .rooms-empty { color: #b8ccdf; }
.lobby-panel { background: #172b41; border: 1px solid #3e5872; border-radius: 1rem; padding: 1rem; margin: 0 0 .7rem; }
.lobby-form { display: grid; gap: .75rem; margin-top: .8rem; }
.lobby-form label, .lobby-join label, #waiting-link label { display: grid; gap: .35rem; min-width: 0; font-size: .9rem; }
.lobby-form :is(input, select), .lobby-join input, #invite-url { width: 100%; min-height: 2.6rem; padding: .42rem .65rem; border: 1px solid #55718d; background: #102035; color: #f2f7fc; border-radius: .45rem; font: inherit; font-size: 1rem; }
.lobby-form input::placeholder, .lobby-join input::placeholder { color: #a9bfd2; }
.lobby-buttons { display: flex; flex-wrap: wrap; gap: .5rem; }
.lobby-form > .gold-button { justify-self: start; }
.lobby-join { display: grid; grid-template-columns: minmax(0,1fr) auto; gap: .5rem; align-items: end; margin-top: .65rem; }
.room-list { display: grid; gap: .4rem; margin-top: .7rem; }
.room-row { text-align: start; color: #eff5fb; border: 1px solid #466581; background: #203a55; border-radius: .5rem; padding: .6rem .65rem; min-height: 2.65rem; font: inherit; }
.room-row strong { overflow-wrap: anywhere; }
.room-row span { color: #c3d4e4; white-space: nowrap; font-size: .82rem; }
.create-room summary { color: #f4d492; font-weight: 720; cursor: pointer; }
.waiting-members { display: grid; gap: .35rem; list-style: none; padding: 0; }
.waiting-members li { background: #223c57; border-radius: .4rem; padding: .52rem .7rem; }
.room-message, #join-error { background: #253e57; padding: .65rem .8rem; border-radius: .45rem; color: #ffe1a5; }
.active-room-bar { margin-bottom: .45rem; padding: .28rem .5rem; border: 1px solid #3e5872; border-radius: .5rem; font-size: .78rem; }
#active-room-label { overflow-wrap: anywhere; }
#room-game-status { color: #f5d194; }
.active-room-bar button { flex: 0 0 auto; min-height: 1.9rem; padding: .1rem .45rem; }

#music-toggle { margin-left: auto; }
#music-toggle[aria-pressed="true"] { background: #29465d; color: #f7dd9f; border-color: #927f57; }
.install-help { display: grid; gap: .35rem; margin-bottom: .65rem; }
.hu-celebration {
  position: absolute;
  inset: 0;
  z-index: 6;
  pointer-events: none;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: .4rem;
  isolation: isolate;
  color: #ffdda0;
  text-align: center;
  animation: hu-entry 2s both;
}
.hu-halo {
  position: absolute;
  z-index: -1;
  top: 50%;
  left: 50%;
  width: min(80%, 23rem);
  aspect-ratio: 1.35;
  transform: translate(-50%, -50%);
  background: radial-gradient(ellipse at center, #392212f5 0%, #58381fea 37%, #71491db2 56%, transparent 74%);
}
.hu-word {
  font: 900 clamp(3.15rem, 11vw, 7rem)/1.06 var(--display-font);
  letter-spacing: .12em;
  padding-inline-start: .12em;
  text-shadow: 0 0 .36em #f6a843, 0 .06em 0 #854915, 0 .12em .15em #35200c;
}
.hu-winner {
  max-width: min(75vw, 16rem);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: clamp(1.05rem, 4.4vw, 1.55rem);
  font-weight: 780;
  padding: .12em .72em;
  background: #351d14ed;
  border-radius: 1em;
  border: 1px solid #ffe0a675;
  color: #fff1cc;
}
.hu-seat {
  position: relative;
  z-index: 3;
  outline: 2px solid #fbd582;
  animation: hu-name-glow .65s ease-in-out 3 alternate both;
}
.hu-seat .identity-text :is(strong,h2) { color: #71370b; }
@keyframes hu-entry {
  0% { opacity: 0; transform: scale(.83); }
  13%, 89% { opacity: 1; transform: scale(1); }
  100% { opacity: 0; transform: scale(1.06); }
}
@keyframes hu-name-glow {
  from { box-shadow: inset 0 0 10px #f4bf6677, 0 0 4px #ffcb75; }
  to { box-shadow: inset 0 0 15px #f4bf66bc, 0 0 17px #ffcb75; }
}
@media (max-width: 375px) {
  .mode-bar { gap: .28rem; }
  .mode-bar button { padding-inline: .45rem; font-size: .78rem; }
}
@media (prefers-reduced-motion: reduce) {
  .hu-celebration,.hu-seat { animation: none; }
}

/* Keep the current table and its controls inside the visible viewport. */
body {
  min-height: 0;
  height: 100dvh;
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  overflow: hidden;
}
.topbar { min-height: calc(42px + env(safe-area-inset-top)); }
.brand h1 { font-size: 22px; }
.brand-kicker { font-size: 9px; }
.seal { width: 26px; height: 26px; }
.topbar button { min-height: 29px; }
.mode-bar { margin-block: 1px 5px; flex-wrap: nowrap; gap: 4px; }
.mode-bar button { min-height: 31px; padding: 2px clamp(3px, 1.4vw, 8px); font-size: 12px; flex: 0 1 auto; }
#music-toggle, #install-app { margin-left: 0; }
#effects-toggle { margin-left: auto; }
#effects-toggle[aria-pressed="true"] { background: #29465d; color: #f7dd9f; border-color: #927f57; }
.room-lobby { overflow-y: auto; min-height: 0; overscroll-behavior-y: contain; padding-bottom: max(12px, env(safe-area-inset-bottom)); }
.workspace {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  min-height: 0;
  padding-bottom: max(5px, env(safe-area-inset-bottom));
}
.active-room-bar { grid-row: 1; margin-bottom: 3px; padding-block: 1px; min-height: 24px; font-size: 11px; }
.active-room-bar button { min-height: 23px; }
.game {
  grid-row: 2;
  display: grid;
  grid-template-rows: minmax(115px, 1fr) auto;
  min-height: 0;
  border-radius: 11px;
  --history-card-h: clamp(21px, 4.7dvh, 41px);
  --history-card-w: clamp(10px, 2.7dvw, 17px);
  --meld-end: clamp(7px, 1.28dvh, 11px);
}
.felt, .felt:has(.north), .felt:has(.result-box), .felt:has(.north):has(.result-box) {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  gap: 3px;
  min-height: 0;
  height: auto;
  padding: 4px 6px 5px;
}
.felt-border { inset: 3px; }
.table-meta { position: static; min-width: 0; align-items: center; }
.round-display, .table-rotation { padding-block: 1px; }
.stage { height: 15px; }
.seats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 4px; align-items: end; min-height: 0; }
.seats[data-size="3"] { grid-template-columns: repeat(2, minmax(0, 1fr)); column-gap: 15%; }
.seat, .seat.north, .seat.east, .seat.west { position: static; inset: auto; transform: none; width: auto; min-width: 0; gap: 1px; }
.seat.east { grid-column: -2; grid-row: 1; }
.seat.west { grid-column: 1; grid-row: 1; }
.seat.north { grid-column: 2; grid-row: 1; }
.seat > .exposed-rack { position: static; inset: auto; }
.exposed-rack { min-height: 0; padding: 0; gap: 0; }
.exposed-cards { gap: 3px; padding: 0 0 1px; }
.exposed-rack:has(.exposed-cards:empty) { min-height: 0; }
.track-group { gap: 0; padding: 1px 2px; }
.track-group-label { font-size: 9px; }
.meld-stack { width: 15px; height: var(--meld-end); }
.meld-stack[data-count="2"] { height: calc(var(--meld-end) * 2); }
.meld-stack[data-count="3"] { height: calc(var(--meld-end) * 3); }
.meld-stack[data-count="4"] { height: calc(var(--meld-end) * 4); }
.meld-stack .tile.compact { --tile-width: 15px; height: calc(var(--meld-end) * 3.85); }
.meld-stack .tile.compact:nth-child(2) { top: var(--meld-end); }
.meld-stack .tile.compact:nth-child(3) { top: calc(var(--meld-end) * 2); }
.meld-stack .tile.compact:nth-child(4) { top: calc(var(--meld-end) * 3); }
.seat-heading .seat-name, .player-identity { min-height: 26px; gap: 3px; padding: 1px 3px; }
.seat-heading .identity-text { flex: 1 1 30px; }
.identity-text strong, .identity-text h2 { font-size: 12px; }
.hand-count, .player-tags { font-size: 9px; }
.seat-name .avatar, .player-identity .avatar { width: 18px; height: 18px; font-size: 11px; }
.seat-score { font-size: 10px; }
.role-pill { line-height: 1.2; font-size: 9px; }
.seat-history { grid-template-columns: minmax(0, 1fr) calc(var(--history-card-w) + 7px); gap: 0 2px; padding: 1px 2px 0; }
.past-flips, .latest-flip { min-height: var(--history-card-h); }
.latest-flip { padding-left: 1px; }
.seat-history .tile.compact, .seat-history .flip-placeholder { --tile-width: var(--history-card-w); height: var(--history-card-h); }
.seat-history .flip-placeholder { width: var(--history-card-w); }
.flip-card { gap: 1px; }
.flip-number { line-height: 1; font-size: 9px; }
.card-rail { height: 7px; }
.felt .table-center, .felt:has(.north) .table-center, .felt:has(.result-box) .table-center {
  position: relative;
  inset: auto;
  grid-template-rows: 18px minmax(0, 1fr);
  gap: 2px;
  min-height: 0;
  container-type: size;
}
.table-center {
  --center-card-height: clamp(28px, 48cqh, 105px);
  --center-card-width: calc(var(--center-card-height) / 2.55);
}
.center-meta { min-height: 0; }
.center-meta .step-label { line-height: 1.1; padding-block: 1px; }
.center-content { min-height: 0; align-content: safe center; height: 100%; overflow: auto; overscroll-behavior: contain; }
.center-action { gap: 3px; }
.center-action-copy { gap: 1px; }
.center-action-copy .center-note { font-size: 12px; padding-block: 1px; }
.center-hint { line-height: 1.1; }
.center-opening { gap: 2px; }
.end-title { font-size: clamp(17px, 5vw, 27px); line-height: 1.05; }
.result-box { gap: 2px; }
.result-stats span, .result-fans li { padding-block: 0; }
.result-fans { gap: 1px 3px; }
.result-fans { font-size: 11px; line-height: 1.16; }
.result-group-button { min-height: 20px; padding-block: 0; font-size: 11px; }
#groups-content { max-height: none; }
.player-area { padding: 3px 5px 4px; gap: 3px 5px; }
.self-seat { gap: 1px; }
.hero-exposed { min-height: 0; }
.hand-meta { max-width: none; align-self: center; }
.hand-red, .timer { padding: 0 3px; font-size: 10px; }
.hand-red strong { font-size: 13px; }
.utility-controls { gap: 2px; }
.utility-controls button { min-height: 24px; padding: 1px 5px; font-size: 11px; }
.hand { height: clamp(46px, 10.4dvh, 88px); min-height: 0; padding-block: 2px; }
.hand .tile { height: min(calc(var(--tile-width) * 2.9), calc(10.4dvh - 4px)); }
.revealed-hands { padding: 1px 0; }
.revealed-hands h2 { margin: 0 0 1px; font-size: 12px; }
.revealed-seat { display: grid; grid-template-columns: 65px minmax(0, 1fr); align-items: center; gap: 3px; padding: 1px 2px; }
.revealed-name { display: grid; gap: 0; font-size: 11px; line-height: 1.12; overflow-wrap: anywhere; }
.revealed-name span { padding: 0 2px; background: transparent; color: #f5d290; font-size: 9px; }
.revealed-cards { padding-block: 1px 2px; }
.revealed-cards .tile.compact { --tile-width: max(9px, var(--history-card-w)); height: clamp(22px, 4.3dvh, 37px); }
.control-bar { gap: 2px; min-height: 0; padding-top: 2px; }
.control-head { min-height: 25px; gap: 3px; }
.status { font-size: 12px; line-height: 1.12; }
.status small { min-height: 0; font-size: 10px; }
.status small:empty { display: none; }
.moves { grid-template-columns: repeat(8, minmax(0, 1fr)); gap: 3px; }
.game-move { min-height: 33px; font-size: 14px; }
.move-extra { min-height: 25px; padding-inline: 5px; font-size: 12px; }
.game[data-phase="result"] .moves, .game[data-phase="end"] .moves { display: none; }
#dealer-progress { margin: 6px 0; color: var(--muted); }

.dice-intro {
  position: absolute;
  inset: 0;
  z-index: 7;
  display: grid;
  align-content: center;
  justify-items: center;
  gap: 8px;
  padding: 6px 7px;
  background: radial-gradient(ellipse at 50% 60%, #1e5366, #12223b 82%);
  text-align: center;
}
.dice-intro h2 { color: #f7d691; font: 780 clamp(20px,5.8vw,31px)/1 var(--display-font); }
.dice-intro p { color: #f7d691; font-size: 13px; }
.dice-players { display: flex; justify-content: center; gap: 4px; width: min(100%, 380px); }
.dice-player {
  min-width: 0;
  flex: 1 1 0;
  display: grid;
  justify-items: center;
  align-content: start;
  gap: 3px;
  padding: 4px 1px;
  border: 1px solid #50728a;
  border-radius: 6px;
  background: #142d46;
  font-size: 12px;
}
.dice-player strong { min-width: 0; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dice-player small { white-space: normal; line-height: 1.1; color: #b9cfe2; }
.dice-dealer { border-color: #f1c97a; color: #ffda94; }
.dice-face {
  width: clamp(24px, 5.4dvh, 43px);
  aspect-ratio: 1;
  display: grid;
  grid-template: repeat(3, 1fr) / repeat(3, 1fr);
  gap: 1px;
  padding: 4px;
  border-radius: 5px;
  border: 1px solid #f3e1bb;
  background: #f2e4c5;
  box-shadow: 0 2px #b59b6d;
}
.dice-face i { place-self: center; width: 67%; aspect-ratio: 1; border-radius: 50%; background: #982c37; }
.dice-face.rolling { animation: toss-die .24s ease-in-out 3 alternate both; }
.dice-face.rolling i { grid-area: 2/2; }
.showing-dice .player-area { visibility: hidden; }
.showing-dice .table-center, .showing-dice .seats { visibility: hidden; }
@keyframes toss-die {
  from { transform: translateY(1px) rotate(-12deg); }
  to { transform: translateY(-5px) rotate(14deg); }
}
@media (prefers-reduced-motion: reduce) {
  .dice-face.rolling { animation: none; }
}
@media (max-height: 640px) {
  .topbar { min-height: calc(34px + env(safe-area-inset-top)); }
  .brand-kicker { display: none; }
  .brand h1 { font-size: 19px; }
  .mode-bar button { min-height: 27px; font-size: 11px; }
  .game { --history-card-h: clamp(19px, 4.2dvh, 26px); }
  .seat-heading .seat-name, .player-identity { min-height: 23px; }
  .seat-name .avatar { display: none; }
  .felt { padding-block: 2px; }
  .game-move { min-height: 30px; }
  .track-empty { font-size: 9px; }
}
@media (orientation: landscape) and (max-height: 540px) and (min-width: 560px) {
  .shell { max-width: 820px; }
  body { grid-template-columns: auto minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr); }
  .topbar { grid-area: 1 / 1; padding-right: 0; }
  .mode-bar { grid-area: 1 / 2; margin: 1px auto; justify-content: end; align-items: center; }
  .workspace, .room-lobby { grid-area: 2 / 1 / 3 / 3; }
  .game { grid-template-columns: minmax(0, 1fr) minmax(0, 1.02fr); grid-template-rows: minmax(0, 1fr); }
  .player-area { border-top: 0; border-left: 1px solid #5c7a956e; align-content: space-between; }
  .hand { height: 55px; }
  .hand .tile { height: min(calc(var(--tile-width) * 2.9), 49px); }
  .dice-face { width: 29px; }
}
.game { position: relative; }
.result-heading, .result-stats, .result-end { display: flex; align-items: center; justify-content: center; gap: 4px; flex-wrap: wrap; }
.result-group-button { min-height: 18px; }
@container (max-height: 112px) {
  .center-action { grid-template-columns: auto minmax(0, 1fr); align-items: center; width: fit-content; gap: 5px; }
  .table-center .center-action .tile.large, .table-center .drawing-card { --tile-width: 19px; height: clamp(23px, 55cqh, 52px); }
}

/* The settlement screen shows the score and all exposed hands together. */
.game:is([data-phase="result"], [data-phase="end"]) .seats,
.game:is([data-phase="result"], [data-phase="end"]) .self-seat { display: none; }
.game:is([data-phase="result"], [data-phase="end"]) .felt { grid-template-rows: auto minmax(0, 1fr); }
.game:is([data-phase="result"], [data-phase="end"]) .player-area {
  grid-template-areas: "hand hand" "control tools";
  grid-template-columns: minmax(0,1fr) auto;
}
.game:is([data-phase="result"], [data-phase="end"]) #sort-hand { display: none; }
.game:is([data-phase="result"], [data-phase="end"]) .result-box { gap: 4px; }
#revealed-seats { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 2px 4px; }
.revealed-seat { display: block; min-width: 0; }
.revealed-name { display: flex; gap: 3px; min-height: 19px; }
.revealed-name strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.revealed-name small { color: #f5d290; margin-left: auto; white-space: nowrap; }
.revealed-cards .tile.compact { --tile-width: clamp(8px, 2.6dvw, 15px); }
@media (max-height: 585px) and (orientation: portrait) {
  .self-seat {
    grid-template-columns: minmax(85px, .9fr) minmax(37px, 1fr) auto;
    grid-template-areas: "groups groups meta" "identity history history";
    align-items: center;
  }
  .game:not([data-phase="result"]):not([data-phase="end"]) .table-center {
    grid-template-columns: minmax(56px, 23%) minmax(0, 1fr);
    grid-template-rows: minmax(0, 1fr);
    align-items: center;
  }
  .game:not([data-phase="result"]):not([data-phase="end"]) .center-meta { flex-direction: column; gap: 1px; line-height: 1; }
  .hand-meta { justify-content: end; }
  .player-identity .avatar { display: none; }
}
@media (max-height: 585px) and (orientation: portrait) {
  .game { --meld-end: 6px; --history-card-h: 20px; }
  .seat-name, .player-identity { flex-wrap: nowrap; }
  .seat-name .identity-text, .player-identity .identity-text { line-height: 1.05; }
  .seat-name .hand-count, .player-identity .player-tags { line-height: 1.05; }
  .seat-name .hand-count { overflow: hidden; text-overflow: ellipsis; }
  .self-seat { grid-template-columns: minmax(107px, 1fr) minmax(24px, 1fr) auto; }
  .seat-name .role-pill, .player-identity .role-pill { padding-inline: 2px; }
  .seat-history .flip-number { font-size: 8px; }
  .felt .center-action-copy .center-note { font-size: 11px; line-height: 1.14; }
}

/* Give each part of the active table a row independent of the cards it contains. */
.game {
  --public-band: calc(4 * var(--meld-end) + 22px);
  --name-band: 31px;
  --history-band: calc(var(--history-card-h) + 20px);
  --seat-band: calc(var(--public-band) + var(--name-band) + var(--history-band) + 2px);
  --center-band: clamp(56px, 13.2dvh, 104px);
  --hand-band: clamp(48px, 10.4dvh, 84px);
  --wait-band: 41px;
  --status-band: 29px;
  --moves-band: 33px;
}
.game:not(:is([data-phase="result"], [data-phase="end"])) {
  align-self: start;
  grid-template-rows: auto auto;
}
.game:not(:is([data-phase="result"], [data-phase="end"])) .felt {
  grid-template-rows: 21px var(--seat-band) var(--center-band);
}
.game .table-meta { align-self: stretch; }
.game .table-rotation, .game .round-display { height: 21px; }
.seat, .seat.north, .seat.east, .seat.west {
  grid-template-rows: var(--public-band) var(--name-band) var(--history-band);
}
.seat .exposed-rack, .hero-exposed .exposed-rack {
  height: var(--public-band);
  grid-template-rows: minmax(0, 1fr) 7px;
}
.exposed-cards { align-items: end; min-height: 0; }
.exposed-cards .track-group { align-self: end; }
.seat-heading .seat-name, .player-identity {
  height: var(--name-band);
  min-height: 0;
  flex-wrap: nowrap;
}
.seat-name .identity-text, .player-identity .identity-text { line-height: 1.15; }
.seat-name .hand-count, .player-identity .player-tags {
  line-height: 1.15;
  overflow: hidden;
  text-overflow: ellipsis;
}
.seat-history {
  height: var(--history-band);
  min-height: 0;
  grid-template-rows: minmax(0, 1fr) 7px;
}
.game:not(:is([data-phase="result"], [data-phase="end"])) .table-center {
  grid-template-columns: minmax(42px, 22%) minmax(0, 1fr) minmax(20px, 15%);
  grid-template-rows: minmax(0, 1fr);
  gap: 0;
  align-items: center;
  --center-card-height: min(calc(var(--center-band) - 6px), 94px);
  --center-card-width: calc(var(--center-card-height) / 2.55);
}
.game:not(:is([data-phase="result"], [data-phase="end"])) .center-meta {
  grid-column: 1;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  line-height: 1;
}
.game:not(:is([data-phase="result"], [data-phase="end"])) .center-content { grid-column: 2; }
.game:not(:is([data-phase="result"], [data-phase="end"])) .center-action {
  width: fit-content;
  max-width: 100%;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: 6px;
}
.game:not(:is([data-phase="result"], [data-phase="end"])) .center-action .tile.large,
.game:not(:is([data-phase="result"], [data-phase="end"])) .drawing-card {
  --tile-width: var(--center-card-width);
  height: var(--center-card-height);
}
.center-opening strong { font-size: clamp(15px, 4.5vw, 23px); line-height: 1.08; }
.game:not(:is([data-phase="result"], [data-phase="end"])) .player-area {
  grid-template-areas: "self tools" "hand hand" "wait wait" "control control";
  grid-template-rows: auto var(--hand-band) var(--wait-band) auto;
  align-content: start;
}
.self-seat { grid-template-rows: var(--public-band) var(--name-band) var(--history-band); }
.hand { height: var(--hand-band); }
.hand .tile { height: min(calc(var(--tile-width) * 2.9), calc(var(--hand-band) - 5px)); }
.game:not(:is([data-phase="result"], [data-phase="end"])) .control-bar {
  grid-template-rows: var(--status-band) var(--moves-band);
}
.game:not(:is([data-phase="result"], [data-phase="end"])) .control-head { min-height: 0; }
.game:not(:is([data-phase="result"], [data-phase="end"])) .moves .game-move { min-height: 0; }
.status > span, .status > small {
  display: block;
  max-width: 100%;
  white-space: nowrap;
  overflow-x: auto;
  scrollbar-width: none;
}
.hand .tile.supplemented::after {
  content: "";
  position: absolute;
  inset: 1px;
  border: 1px solid #6aedf0;
  border-radius: 3px;
  box-shadow: inset 0 0 5px #50e7f0c4;
  pointer-events: none;
}
.wait-preview {
  grid-area: wait;
  display: grid;
  grid-template-columns: minmax(74px, 25%) minmax(0, 1fr);
  gap: 5px;
  align-items: center;
  grid-template-rows: minmax(0, 1fr);
  min-width: 0;
  height: var(--wait-band);
  padding: 1px 4px;
  overflow: hidden;
  border: 1px solid #486480;
  border-radius: 5px;
  background: #152941;
}
.game:is([data-phase="result"], [data-phase="end"]) .wait-preview { display: none; }
.wait-info { min-width: 0; font-size: 11px; line-height: 1.15; }
.wait-info h3 { display: inline; font-size: 11px; color: #f4cf89; }
.wait-info small { color: #c3d6e7; font-size: 10px; }
.wait-info small:empty { display: none; }
.wait-info #wait-context { display: inline-block; max-width: 100%; margin-left: 3px; white-space: nowrap; }
.wait-info #wait-context:empty { display: none; }
.wait-discards { overflow-x: auto; scrollbar-width: none; white-space: nowrap; color: #ebd7a7; font-size: 10px; line-height: 1.2; }
.wait-cards { display: flex; align-items: center; gap: 4px; min-width: 0; height: 100%; overflow-x: auto; overflow-y: hidden; overscroll-behavior-x: contain; scrollbar-width: thin; }
.wait-card {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 1px 4px;
  border: 1px solid #516f83;
  border-radius: 4px;
  background: #213a51;
}
.wait-card .tile.compact { --tile-width: 11px; height: clamp(21px, calc(var(--wait-band) - 10px), 29px); }
.wait-card-label { display: grid; white-space: nowrap; line-height: 1.1; font-size: 10px; color: #f3dfbb; }
.wait-card-label strong { color: #b9edf0; font-size: 9px; }
.wait-empty { opacity: .64; }
.wait-prompt { color: #aebfd0; font-size: 11px; }
.active-room-bar { height: 26px; overflow: hidden; }
#active-room-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#room-game-status { max-width: 42%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dice-face .die-dot { grid-area: 2 / 2; }

#hand-scores-title { font-size: 14px; margin-top: 10px; margin-bottom: 5px; }
.hand-score-history { overflow: auto; margin-bottom: 8px; }
.hand-score-history table { border-collapse: collapse; width: 100%; font-size: 11px; text-align: left; }
.hand-score-history :is(th, td) { vertical-align: top; padding: 5px 4px; border-bottom: 1px solid #3b526b; }
.hand-score-history thead th { color: #c0d4e5; }
.hand-score-history tbody th { color: #ebd299; }
.hand-score-history tbody th small { white-space: nowrap; }
.hand-score-history td small, .hand-score-history th small { display: block; color: #afc0d2; font-size: 10px; font-weight: 400; }
.hand-score-history .hand-score-number { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.hand-score-history td[data-positive="true"] { color: #b5edde; }
.score-log-details summary { cursor: pointer; font-size: 13px; color: #e9ce98; }
.score-log-details .log { margin: 5px 0; }

@media (max-height: 700px) and (orientation: portrait) {
  .game {
    --center-band: clamp(47px, 10.4dvh, 68px);
    --hand-band: clamp(45px, 9dvh, 63px);
    --name-band: 28px;
    --wait-band: 35px;
    --status-band: 26px;
    --moves-band: 30px;
  }
  .self-seat {
    grid-template-columns: minmax(107px, 1fr) minmax(24px, 1fr) auto;
    grid-template-areas: "groups groups meta" "identity history history";
    grid-template-rows: var(--public-band) var(--history-band);
    align-items: center;
  }
  .player-identity .avatar { display: none; }
}
@media (max-height: 585px) and (orientation: portrait) {
  .game { --meld-end: 5px; --history-card-h: 17px; --name-band: 25px; --center-band: 47px; }
}
@media (orientation: landscape) and (max-height: 540px) and (min-width: 560px) {
  .game { --hand-band: 47px; --wait-band: 34px; --status-band: 25px; --moves-band: 30px; }
  .game:not(:is([data-phase="result"], [data-phase="end"])) { grid-template-rows: auto; }
}
.game:not(:is([data-phase="result"], [data-phase="end"])) .center-mark {
  font-size: clamp(22px, calc(var(--center-band) * .68), 58px);
  overflow: hidden;
}

.audio-controls {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-left: auto;
}
#music-toggle, #effects-toggle { margin-left: 0; }
.dice-player .dice-face { display: grid; }
.dice-player > small { min-height: 1.1em; }
button.dice-player:disabled { opacity: 1; }
button.dice-player:enabled {
  border-color: #e9c77f;
  color: #ffe0a3;
  background: #24445a;
}
button.dice-player:enabled:hover { background: #2e5970; }
.hand .tile.supplemented { animation: refill-light 500ms ease-in-out 6 alternate; }
@keyframes refill-light {
  from { filter: drop-shadow(0 0 1px #6aedf0); }
  to { filter: drop-shadow(0 0 7px #6aedf0); }
}
.status {
  position: relative;
  isolation: isolate;
}
.status.remind-action {
  color: #fff5d4;
  animation: remind-player 1050ms ease-in-out infinite;
}
.status.remind-action::before,
.status.remind-action::after {
  content: "";
  pointer-events: none;
  position: absolute;
  z-index: -1;
  inset: -3px auto -3px -5px;
  width: min(100%, 236px);
}
.status.remind-action::before {
  background: radial-gradient(ellipse at 42% 50%, #c6771659 3%, #a759142e 47%, transparent 74%);
}
.status.remind-action::after {
  background: repeating-conic-gradient(from 7deg at 42% 50%, #ffd783 0deg 2deg, #fbbf5952 2deg 4deg, transparent 4deg 29deg);
  -webkit-mask-image: radial-gradient(ellipse at 42% 50%, transparent 32%, #000 60%, transparent 80%);
  mask-image: radial-gradient(ellipse at 42% 50%, transparent 32%, #000 60%, transparent 80%);
  transform-origin: 42% 50%;
  animation: reminder-rays 1050ms ease-out infinite;
}
.status > .status-sparks {
  position: absolute;
  z-index: -1;
  inset-block: 0;
  inset-inline-start: min(151px, 62%);
  width: 49px;
  overflow: visible;
  pointer-events: none;
  visibility: hidden;
  filter: drop-shadow(0 0 5px #ffbe51);
}
.status.remind-action > .status-sparks {
  visibility: visible;
  animation: reminder-rays 1050ms ease-out infinite;
}
.status-sparks::before,
.status-sparks::after {
  content: "";
  position: absolute;
  width: 16px;
  height: 16px;
  background: #ffdf8b;
  clip-path: polygon(50% 0, 57% 35%, 75% 25%, 65% 43%, 100% 50%, 65% 57%, 75% 75%, 57% 65%, 50% 100%, 43% 65%, 25% 75%, 35% 57%, 0 50%, 35% 43%, 25% 25%, 43% 35%);
}
.status-sparks::before { top: 0; left: 0; }
.status-sparks::after { bottom: 0; right: 0; width: 11px; height: 11px; }
@keyframes remind-player {
  0%, 100% { color: #fff9d9; text-shadow: 0 0 5px #ffe18d, 0 0 14px #ef9e35; }
  56% { color: #f7d490; text-shadow: 0 0 2px #e2a65c66; }
}
@keyframes reminder-rays {
  0% { opacity: .98; transform: scale(.91, .9); }
  37% { opacity: .68; transform: scale(1.07, 1.04); }
  77%, 100% { opacity: .35; transform: scale(1, .98); }
}
@media (prefers-reduced-motion: reduce) {
  .hand .tile.supplemented, .status.remind-action, .status.remind-action::after, .status.remind-action > .status-sparks { animation: none; }
  .status.remind-action { color: #fff4ce; text-shadow: 0 0 6px #f0c782; }
  .status.remind-action::after { opacity: .65; }
}
