/* Cards */
.card { display: inline-block; aspect-ratio: 100 / 140; line-height: 0; filter: drop-shadow(0 3px 3px #0007); position: relative; flex: none; }
.card svg { width: 100%; height: 100%; font-family: Georgia, "Times New Roman", "DejaVu Serif", serif; user-select: none; }
.flying { position: fixed; left: 0; top: 0; z-index: 1500; pointer-events: none; filter: drop-shadow(0 14px 10px #0008); }

.game { --mini: 40px; --pile: 76px; height: 100dvh; display: grid; grid-template-rows: auto minmax(0, 1fr) auto; overflow: hidden; }
.topbar { display: flex; align-items: center; gap: 10px; padding: 6px 10px; background: #050c09cc; border-bottom: 1px solid #ffffff14; }
.round-label { display: flex; gap: 8px; align-items: center; white-space: nowrap; font-family: var(--serif); color: var(--gold-2); }
.opening-label { flex: 1; min-width: 0; font-size: .8rem; color: #e9b8a0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; text-align: center; }
.opening-label.yes { color: var(--ok); }
.icon-btn { min-width: 34px; height: 32px; display: inline-grid; place-items: center; border-radius: 8px; border: 1px solid var(--line); background: #13241c; color: var(--text); text-decoration: none; cursor: pointer; font: inherit; }
.icon-btn.text { padding: 0 10px; font-size: .82rem; }

/* The table: wooden rim around a felt surface */
.table-wrap { min-height: 0; padding: 8px 10px; display: flex; justify-content: center; }
.rim { width: min(1400px, 100%); height: 100%; padding: 14px; border-radius: 120px / 110px;
  background: repeating-linear-gradient(93deg, #0000 0 7px, #00000024 7px 9px, #ffffff0d 9px 13px), linear-gradient(180deg, #8a5529, #4d2b12 45%, #6d3f1c);
  box-shadow: inset 0 2px 2px #ffd9a055, inset 0 -3px 5px #000a, 0 18px 46px #000d; }
.felt { height: 100%; border-radius: 106px / 96px; overflow: auto; padding: 8px 14px;
  background: radial-gradient(ellipse at 50% 38%, #1f7049 0%, #114a31 52%, #07291b 100%);
  box-shadow: inset 0 0 36px #000b, 0 0 0 2px #dcb45e66;
  display: grid; gap: 6px 10px; grid-template-columns: minmax(0, 1fr) minmax(250px, 1.25fr) minmax(0, 1fr);
  grid-template-rows: minmax(min-content, 1fr) auto minmax(min-content, 1fr);
  grid-template-areas: ". top ." "left center right" ". bottom ."; position: relative; }
.zone { display: flex; flex-direction: column; align-items: center; gap: 6px; min-width: 0; }
.zone.top { grid-area: top; } .zone.left { grid-area: left; justify-content: center; } .zone.right { grid-area: right; justify-content: center; }
.zone.bottom { grid-area: bottom; flex-direction: column-reverse; justify-content: flex-start; grid-column: 1 / -1; }
.center { grid-area: center; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; }

.plate { display: flex; align-items: center; gap: 8px; padding: 5px 12px 5px 6px; border-radius: 40px; background: #04100ad9; border: 2px solid #ffffff1f; max-width: 100%; position: relative; }
.plate.active { border-color: var(--gold-2); animation: glow 1.5s ease-in-out infinite; }
@keyframes glow { 0%, 100% { box-shadow: 0 0 6px 1px #f3d58e88; } 50% { box-shadow: 0 0 22px 6px #f3d58ecc; } }
.plate.offline { opacity: .65; }
.portrait { position: relative; }
.portrait .avatar { width: 46px; height: 46px; }
.portrait .dot { position: absolute; right: -2px; bottom: 0; margin: 0; border: 2px solid #04100a; width: 13px; height: 13px; }
.plate-text { display: grid; line-height: 1.25; min-width: 0; }
.plate-text strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.score { font-size: .76rem; color: var(--gold-2); }
.meta { display: flex; gap: 6px; align-items: center; font-size: .72rem; color: var(--muted); flex-wrap: wrap; }
.count { display: inline-flex; align-items: center; gap: 4px; font-weight: 700; color: var(--text); }
.back-icon { display: inline-block; width: 10px; height: 14px; border-radius: 2px; background: #7d1f31; border: 1px solid #d9b35c; box-shadow: 3px 0 0 -1px #7d1f31, 4px 0 0 -1px #d9b35c; margin-right: 3px; }
.state.yes { color: var(--ok); }
.timer { color: var(--gold-2); font-weight: 700; }
.roles { position: absolute; top: -10px; right: -6px; display: flex; gap: 3px; }
.role { font-size: .62rem; font-weight: 700; padding: 1px 6px; border-radius: 9px; background: #e9e2cd; color: #1b1a12; white-space: nowrap; box-shadow: 0 2px 5px #0008; }
.role.dealer { background: var(--gold); }

.melds { display: flex; flex-wrap: wrap; justify-content: center; gap: 5px 9px; }
.meld { display: flex; padding: 3px 4px; border: 2px solid transparent; border-radius: 8px; background: #0000001f; cursor: default; }
.meld .card { width: var(--mini); }
.meld .card + .card { margin-left: calc(var(--mini) * -.5); }
.meld.target { border-color: var(--gold-2); background: #f3d58e26; cursor: pointer; animation: glow 1.2s infinite; }
.stands-for { position: absolute; bottom: 1px; left: 1px; right: 1px; background: #3d1452e8; color: #fff; border-radius: 3px; font: 700 9px/13px system-ui; text-align: center; }

.piles { display: flex; gap: 18px; align-items: flex-end; justify-content: center; }
.pile { background: none; border: 0; padding: 4px; color: var(--text); display: grid; justify-items: center; gap: 5px; position: relative; border-radius: 10px; font: inherit; }
.pile .card, .slot { width: var(--pile); }
.slot { aspect-ratio: 100 / 140; border: 2px dashed #ffffff40; border-radius: 8px; }
.deck > .card { filter: drop-shadow(2px 2px 0 #d9ceb0) drop-shadow(2px 2px 0 #5c1220) drop-shadow(3px 5px 5px #000a); }
.pile-label { font-size: .72rem; color: #d8e6da; white-space: nowrap; }
.pile.live { cursor: pointer; background: #f3d58e1c; box-shadow: 0 0 0 2px var(--gold-2), 0 0 18px #f3d58e66; }
.cut-area .card { transform: rotate(6deg); }
.closing-card { position: absolute; top: 12px; left: 16px; transform: rotate(14deg); }
.cut-panel { text-align: center; width: min(330px, 100%); }
.cut-panel:empty { display: none; }
.cut-panel p { margin: 2px 0 6px; font-size: .85rem; }
.cut-panel input { accent-color: var(--gold); background: none; border: 0; padding: 0; min-height: 30px; }
.cut-panel output { display: block; font-size: .8rem; margin-bottom: 5px; }
.deck-spread { display: flex; justify-content: center; position: relative; padding: 0 6px; }
.deck-spread .card { width: 30px; margin-left: -19px; }
.deck-spread .card:first-child { margin-left: 0; }
.cut-marker { position: absolute; top: -5px; bottom: -5px; width: 3px; background: var(--gold-2); box-shadow: 0 0 9px var(--gold-2); }

/* The player's own hand and controls */
.dock { padding: 2px 8px max(6px, env(safe-area-inset-bottom)); background: linear-gradient(180deg, transparent, #030806 35%); min-width: 0; }
.status-line { display: flex; justify-content: center; gap: 14px; flex-wrap: wrap; font-size: .86rem; min-height: 21px; }
.turn-text.mine { color: var(--gold-2); font-weight: 700; }
.value { padding: 0 10px; border-radius: 99px; background: #5a2b22; font-weight: 700; }
.value.enough { background: #1c6b43; }
.hand { position: relative; width: min(1100px, 100%); margin: 0 auto; touch-action: none; }
.card.in-hand { position: absolute; left: 0; top: 0; width: var(--card-w); cursor: grab; touch-action: none; user-select: none; -webkit-user-select: none; transition: transform .22s ease; }
.card.in-hand.selected svg > rect { stroke: #e8a91c; stroke-width: 5; }
.card.in-hand.ghost { outline: 3px dashed var(--gold-2); outline-offset: 1px; border-radius: 8px; }
.card.in-hand.fresh svg > rect { fill: #fff3c4; }
.card.in-hand.dragging { transition: none; z-index: 900 !important; cursor: grabbing; filter: drop-shadow(0 16px 12px #000a); }
.group-tag { position: absolute; z-index: 400; height: 18px; border-radius: 9px; padding: 0 8px; border: 0; background: #1c6b43; color: #fff; font: 700 11px/18px system-ui; white-space: nowrap; overflow: hidden; cursor: pointer; }
.group-tag.invalid { background: #8c3a30; }
.actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 5px; margin-top: 4px; }
.act { min-height: 36px; padding: 5px 13px; border-radius: 9px; border: 1px solid #7a6736; background: linear-gradient(180deg, #24402f, #152a1f); color: var(--text); font: 600 .84rem system-ui; cursor: pointer; }
.act.primary:not(:disabled) { background: linear-gradient(180deg, var(--gold-2), var(--gold)); color: #241a05; }
.act.hant:not(:disabled) { background: linear-gradient(180deg, #c8414d, #82202d); border-color: var(--gold-2); animation: glow 1.4s infinite; }
.act.on { box-shadow: 0 0 0 2px var(--gold-2); }
.act:disabled { opacity: .32; cursor: default; }
.tools { display: flex; justify-content: center; gap: 5px; margin-top: 5px; flex-wrap: wrap; }
.tool { background: transparent; border: 1px solid var(--line); border-radius: 8px; color: var(--muted); padding: 3px 11px; min-height: 28px; font: .78rem system-ui; cursor: pointer; }
.tool:disabled { opacity: .35; }

/* Summaries and HANT */
.round-detail { display: grid; gap: 8px; margin-bottom: 14px; }
.result-row { border: 1px solid var(--line); border-radius: 11px; padding: 9px 11px; }
.result-row.won { border-color: var(--gold); background: #dcb45e14; }
.result-head { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.points { margin-left: auto; font: 700 1.3rem var(--serif); color: var(--gold-2); }
.calc { margin: 5px 0 0; font-size: .82rem; color: var(--muted); }
.mini-hand { display: flex; flex-wrap: wrap; gap: 2px; margin: 5px 0; }
.mini-hand .card { width: 36px; }
.podium { list-style: none; padding: 0; display: flex; flex-wrap: wrap; gap: 9px; }
.podium li { flex: 1 1 190px; display: grid; justify-items: center; text-align: center; gap: 3px; border: 1px solid var(--line); border-radius: 12px; padding: 11px; }
.podium li.winner { border-color: var(--gold-2); box-shadow: 0 0 22px #f3d58e55; }
.hant-show { position: fixed; inset: 0; z-index: 1600; display: grid; place-content: center; text-align: center; background: radial-gradient(circle, #6b1520ee 0%, #12040699 70%); overflow: hidden; animation: fade 2.8s both; }
.hant-word { font: 900 clamp(2.6rem, 12vw, 7rem) var(--serif); color: var(--gold-2); text-shadow: 0 0 30px #f3d58e, 0 6px 0 #6d4a0d; letter-spacing: .06em; animation: slam .65s cubic-bezier(.2,1.6,.4,1) both; padding: 0 12px; }
.hant-name { font: 600 1.5rem var(--serif); }
.hant-show i { position: absolute; left: 50%; top: 50%; font-style: normal; font-size: 2rem; color: var(--gold-2); animation: burst 1.7s ease-out both; }
@keyframes slam { from { transform: scale(3); opacity: 0; } to { transform: scale(1); opacity: 1; } }
@keyframes burst { from { transform: translate(-50%, -50%) rotate(var(--a)) translateY(0); opacity: 1; } to { transform: translate(-50%, -50%) rotate(var(--a)) translateY(calc(var(--d) * -1.6)); opacity: 0; } }
@keyframes fade { 0% { opacity: 0; } 8%, 85% { opacity: 1; } 100% { opacity: 0; } }

/* Phones: opponents across the top, piles in the middle, own combinations below */
@media (max-width: 720px) {
  .game { --mini: 29px; --pile: 54px; }
  .topbar { gap: 5px; padding: 4px 6px; flex-wrap: wrap; }
  .opening-label { order: 5; flex-basis: 100%; font-size: .68rem; white-space: normal; line-height: 1.2; }
  .round-label { flex: 1; font-size: .85rem; }
  .table-wrap { padding: 3px; }
  .rim { padding: 6px; border-radius: 30px; }
  .felt { border-radius: 25px; padding: 12px 4px 6px; grid-template-columns: repeat(6, minmax(0, 1fr)); grid-template-rows: auto minmax(min-content, 1fr) auto; grid-template-areas: none; align-content: space-between; }
  .zone.left { grid-area: 1 / 1 / 2 / 3; justify-content: flex-start; }
  .zone.top { grid-area: 1 / 3 / 2 / 5; }
  .zone.right { grid-area: 1 / 5 / 2 / 7; justify-content: flex-start; }
  .center { grid-area: 2 / 1 / 3 / 7; }
  .zone.bottom { grid-area: 3 / 1 / 4 / 7; }
  .zone:not(.bottom) .plate { flex-direction: column; gap: 2px; border-radius: 14px; padding: 7px 4px 4px; text-align: center; width: 100%; }
  .zone:not(.bottom) .meta { justify-content: center; font-size: .64rem; }
  .zone:not(.bottom) .score { font-size: .66rem; }
  .zone:not(.bottom) .plate-text { width: 100%; font-size: .8rem; }
  .zone.bottom .plate { padding: 2px 10px 2px 3px; }
  .portrait .avatar { width: 32px; height: 32px; font-size: .9rem; }
  .role { font-size: .54rem; padding: 0 4px; }
  .roles { right: 0; top: -9px; }
  .piles { gap: 8px; }
  .pile-label { font-size: .64rem; }
  .actions { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 4px; }
  .act { padding: 3px 2px; min-height: 38px; font-size: .66rem; line-height: 1.1; overflow-wrap: anywhere; hyphens: auto; }
  .tools { gap: 3px; }
  .tool { padding: 2px 6px; font-size: .68rem; }
  .dock { padding-left: 4px; padding-right: 4px; }
  .status-line { font-size: .76rem; gap: 6px; }
}
/* Landscape phones: opponents at the sides, compact controls in single rows */
@media (max-height: 540px) and (orientation: landscape) {
  .game { --mini: 22px; --pile: 38px; }
  .topbar { padding: 2px 8px; flex-wrap: nowrap; }
  .icon-btn { height: 26px; }
  .opening-label { order: 0; flex-basis: auto; font-size: .66rem; white-space: nowrap; }
  .table-wrap { padding: 2px 6px; }
  .rim { padding: 4px; border-radius: 34px; }
  .felt { border-radius: 30px; padding: 8px 8px 2px; gap: 2px 6px; grid-template-columns: repeat(6, minmax(0, 1fr)); grid-template-rows: auto auto auto; grid-template-areas: none; align-content: space-between; }
  .zone { gap: 2px; }
  .zone.left { grid-area: 1 / 1 / 3 / 3; justify-content: flex-start; }
  .zone.right { grid-area: 1 / 5 / 3 / 7; justify-content: flex-start; }
  .zone.top { grid-area: 1 / 3 / 2 / 5; flex-direction: row; justify-content: center; flex-wrap: wrap; }
  .center { grid-area: 2 / 3 / 3 / 5; gap: 2px; }
  .zone.bottom { grid-area: 3 / 1 / 4 / 7; flex-direction: row; justify-content: center; }
  .plate { padding: 1px 8px 1px 3px; gap: 5px; }
  .portrait .avatar { width: 24px; height: 24px; font-size: .75rem; }
  .plate-text { font-size: .68rem; line-height: 1.15; }
  .plate .score, .plate .meta { font-size: .6rem; }
  .role { font-size: .5rem; padding: 0 4px; }
  .piles { gap: 10px; }
  .pile { padding: 2px; gap: 1px; }
  .pile-label { font-size: .54rem; }
  .cut-panel .deck-spread, .cut-panel output { display: none; }
  .actions, .tools { display: flex; flex-wrap: nowrap; overflow-x: auto; justify-content: safe center; gap: 3px; margin-top: 2px; }
  .act { min-height: 28px; flex: none; white-space: nowrap; font-size: .66rem; padding: 2px 8px; }
  .tool { min-height: 22px; flex: none; white-space: nowrap; font-size: .62rem; padding: 0 8px; }
  .status-line { font-size: .68rem; min-height: 15px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
  .hant-show { animation: none; }
}
