.game-flow [hidden] { display: none !important; }
.flow-setup, .flow-result {
  width: min(100%, 630px);
  margin-inline: auto;
  border: 1px solid #a49362;
  border-radius: 18px;
  padding: clamp(14px, 3vw, 26px);
  background: #153a2e;
  color: var(--room-ink);
}
.flow-setup h2, .flow-result h2 { margin: 0; font-size: clamp(22px, 4vw, 31px); }
.flow-setup p, .flow-result p { margin-block: 3px 12px; color: var(--room-soft); }
.flow-setup fieldset { border: 0; padding: 0; margin: 12px 0; min-width: 0; }
.flow-setup legend { font-size: 14px; font-weight: 750; margin-bottom: 5px; }
.flow-modes, .flow-actions { display: flex; flex-wrap: wrap; gap: 6px; align-items: stretch; }
.flow-choice { display: flex; align-items: center; gap: 10px; padding: 6px 10px; border: 1px solid #809b8580; border-radius: 8px; margin-block: 4px; cursor: pointer; }
.flow-choice:has(input:checked), .flow-computer { border-color: var(--gold); }
.flow-choice input { accent-color: var(--gold); }
.flow-choice small { display: block; color: var(--room-soft); }
.flow-computer, .game-flow :is(.flow-actions, .flow-modes, .flow-deal) :is(button,a) {
  display: inline-flex; min-height: 44px; align-items: center; justify-content: center;
  padding: 4px 12px; border: 1px solid #78907c; border-radius: 8px; background: #1c4839;
  color: var(--room-ink); font: inherit; font-size: 13px; font-weight: 700;
}
.game-flow :is(.flow-actions,.flow-modes) button:disabled { opacity: .55; cursor: default; }
.game-flow .flow-actions .flow-primary { background: var(--gold); color: #2e240f; border-color: var(--gold); flex-grow: 1; }
.flow-computer { border-color: var(--gold); }
.flow-deal { position: absolute; z-index: 2; inset: 35% 0 auto; display: grid; justify-items: center; gap: 7px; }
.flow-deal span[role="status"] { padding: 6px 13px; border-radius: 6px; background: #0b251c; color: var(--gold); font-weight: 800; }
.flow-flying { position: absolute; top: -32px; left: calc(50% - 13px); width: 26px; height: 32px; border: 1px solid var(--gold); border-radius: 4px; background: #2c654f; pointer-events: none; }
.game-flow .card-room { position: relative; }
.flow-result { margin-block: 6px; }
.flow-scores { display: grid; grid-template-columns: repeat(3,minmax(0,1fr)); gap: 6px; margin-bottom: 9px; }
.flow-score { min-width: 0; padding: 6px; border: 1px solid #809b8580; border-radius: 7px; }
.flow-score h3 { margin: 0; font-size: 13px; }
.flow-score strong { display: block; color: var(--gold); }
.flow-score .mini-cards { justify-content: start; }
.flow-score .mini-cards > span:not(.mini-card) { font-size: 12px; }
@media (orientation: landscape) and (max-height: 550px) {
  .flow-setup { padding: 8px 14px; }
  .flow-setup p, .flow-setup fieldset { margin-block: 4px; }
  .flow-choice { margin-block: 2px; padding-block: 3px; }
}

@media (orientation: landscape) and (min-width: 550px) and (max-height: 550px) {
  .flow-setup fieldset { display: grid; grid-template-columns: repeat(3,minmax(0,1fr)); gap: 6px; }
  .flow-choice { align-items: start; }
  .flow-choice input { margin-block-start: 4px; }
}

.flow-cut-options { display: grid; justify-items: center; gap: 8px; }
.flow-cut-options p { margin: 0; color: var(--room-ink); }
.flow-cut-options .flow-actions { justify-content: center; }
.game-flow .flow-cut-options button.flow-cut-card {
  flex-direction: column; gap: 5px; padding: 8px 12px; border-color: #78907c;
}

.game-flow .flow-cut-options button.flow-cut-card:hover,
.game-flow .flow-cut-options button.flow-cut-card:focus-visible { border-color: var(--gold); }
.flow-cut-stack {
  width: 44px; height: 24px; border-radius: 4px; border: 1px solid #bba575;
  background:
    linear-gradient(90deg, transparent calc(var(--cut-line) - 1px), var(--gold) calc(var(--cut-line) - 1px),
      var(--gold) calc(var(--cut-line) + 1px), transparent calc(var(--cut-line) + 1px)),
    repeating-linear-gradient(135deg, #1b493a 0 3px, #31664e 3px 6px);
}
.flow-shuffle { position: relative; width: 190px; height: 74px; }
.flow-packet { position:absolute; top:9px; left:72px; width:46px; height:60px; }
.flow-packet-left { --split:-59px; --turn:-19deg; }
.flow-packet-right { --split:59px; --turn:19deg; }
.flow-packet span {
  position:absolute; inset:0; transform: translateY(calc(var(--i) * -1.1px));
  border:1px solid #dabc83; border-radius:6px; box-shadow:0 2px 1px #0b251c;
  background:repeating-linear-gradient(135deg,#1b493a 0 3px,#235540 3px 6px);
}
@media (prefers-reduced-motion:no-preference) {
  .flow-packet { animation:flow-riffle 350ms ease-in-out both; }
  .flow-packet span { animation:flow-riffle-leaf 245ms ease-in-out both; animation-delay:calc(var(--i) * 12ms); }
}
@keyframes flow-riffle {
  31% { transform:translateX(var(--split)) rotate(var(--turn)); }
  73% { transform:translateX(calc(var(--split) * .22)) rotate(calc(var(--turn) * .35)); }
}
@keyframes flow-riffle-leaf {
  50% { transform:translateY(calc(var(--i) * -2.2px)) rotate(calc(var(--i) * 1.2deg)); }
}
@media (orientation: landscape) and (max-height: 550px) {
  .game-flow [data-predeal] .flow-deal { inset-block-start: 24%; }
}

.integrated-flow .flow-table { position: relative; }
.integrated-flow .flow-table[data-predeal] { min-height: min(460px,68dvh); }
.integrated-flow [data-dealing] :is(#actions,#player,#round-actions,#status) { visibility:hidden; }
/* Shuffle/cut screen: hide the previous hand's board, contract and last trick so nothing stale shows or overlaps the cut panel (Muse retest3, Bridge). */
.integrated-flow .flow-table[data-predeal] :is(.card-room,.table) > :not(.flow-deal) { visibility:hidden; }
.integrated-flow .flow-table[data-predeal] :is(.card-room,.table) { min-height:min(420px,62dvh); }
.integrated-flow #round-actions { justify-content:center; margin-block-start:7px; }
.integrated-flow .flow-deal { inset-block-start:25%; }
.integrated-flow .flow-scores { grid-template-columns:repeat(auto-fit,minmax(min(100%,125px),1fr)); }
.integrated-flow .flow-score :is(.tile,.hand-card) { width:25px; height:34px; }
.integrated-flow .flow-score .mini-cards { display:flex; flex-wrap:wrap; gap:3px; margin-top:4px; }
.integrated-flow .flow-score .hand-card { padding:2px; }
.integrated-flow .flow-score .card-corner { display:grid; gap:0; font-size:10px; line-height:1; }

.game-flow .flow-confirm {
  width:min(calc(100% - 24px),470px); padding:17px; border:1px solid #a49362; border-radius:14px;
  color:var(--room-ink); background:#153a2e;
}
.flow-confirm::backdrop { background:#051911cc; }
.flow-confirm h2 { margin:0 0 12px; font-size:clamp(16px,4vw,20px); }
.flow-confirm .flow-actions button { min-width:44px; }
.flow-optional-cut { display:flex; flex-wrap:wrap; gap:4px 7px; align-items:center; margin:4px 0 8px; font-size:13px; }
.flow-optional-cut input { accent-color:var(--gold); }
.flow-optional-cut small { color:var(--room-soft); }
.flow-formula { font-variant-numeric:tabular-nums; }
.flow-history { padding:4px 8px; border:1px solid #78907c80; border-radius:7px; color:var(--room-soft); font-size:12px; }
.flow-history summary { cursor:pointer; width:fit-content; font-weight:700; }
.flow-history ol { max-height:140px; overflow:auto; padding-inline-start:24px; margin:4px 0 0; }
.flow-terms, .integrated-flow .card-room > .flow-history, .integrated-flow .table > .flow-history { margin:5px auto; width:min(100%,560px); }
.flow-terms dl { display:grid; grid-template-columns:auto 1fr; gap:4px 9px; margin-block:6px; }
.flow-terms dt { color:var(--gold); font-weight:700; }
.flow-terms dd { margin:0; }
.flow-header-restart {
  position:absolute; inset-inline-end:14px; min-height:44px; padding:4px 10px; border:1px solid #78907c;
  border-radius:8px; color:var(--room-ink); background:#1c4839; font:700 12px system-ui,sans-serif;
}
.game-flow:has(#music) .flow-header-restart { display:none; }
.integrated-flow .flow-result > .flow-history { margin-block:8px; }
@media (orientation:landscape) and (max-height:480px) {
  .integrated-flow .flow-result { padding-block:10px; }
}
.live-table-tools { margin:8px auto; justify-content:center; width:min(100%,640px); }
.live-table-tools > .flow-history { flex:1; min-width:160px; padding:10px; }
.live-table-tools { align-items:flex-start; }
.integrated-flow #round-actions:not(:has(> :not([hidden]))) { display:none; }

/* Mahjong (pieces: tiles): the shuffle and deal show tiles, not playing-card backs (ChatGPT P2). */
body[data-pieces="tiles"] :is(.flow-packet span, .flow-flying) {
  border:1px solid #c9b98f; border-radius:5px;
  background:linear-gradient(180deg,#f7efd9 0 38%,#e6dcc0 38% 44%,#2f7a59 44%);
  box-shadow:0 2px 1px #0b251c;
}
body[data-pieces="tiles"] .flow-packet { width:34px; height:46px; }
body[data-pieces="tiles"] .flow-cut-stack { background:linear-gradient(180deg,#f7efd9 0 40%,#2f7a59 40%); }
/* A mode that isn't open yet should not look like a button (Muse #42). */
.game-flow .flow-modes button:disabled { background: transparent; border-style: dashed; box-shadow: none; opacity: .7; cursor: not-allowed; }

.flow-cards-label { display:block; margin-block:4px 2px; color:var(--room-soft); font-size:11px; }
/* Phones: back · title · restart as three real columns, so the floating Restart can't cover the title (seen on Mahjong at 390px). */
@media (max-width: 600px) {
  .game-flow header .top:has(.flow-header-restart:not([hidden])) {
    display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; gap: 6px;
  }
  .game-flow header .top:has(.flow-header-restart:not([hidden])) > :is(#back, .flow-header-restart) { position: static; inset: auto; }
  .game-flow header .top:has(.flow-header-restart:not([hidden])) > .game-title { justify-self: center; min-width: 0; overflow: hidden; }
  .game-flow header .top:has(.flow-header-restart:not([hidden])) > .game-title .brand { display: none; }
}
/* Flying cards pass behind the "Dealing" label and the Skip button instead of over them (Muse retro: all dealt tables). */
.flow-deal > :not(.flow-flying) { position: relative; z-index: 1; }
.flow-flying { z-index: 0; }
