@layer layout {
/* Play controls own their visual states across all viewport sizes.
   Felt = context, gold = selected/primary, mint = reaction, coral = error. */
:root {
  --control-surface: #14382d;
  --control-border: #577368;
  --control-text: #f3efdf;
  --control-muted: #bdcbbf;
  --control-gold: #ecd28e;
  --control-reaction: #99ddd0;
  --control-error: #ffb49e;
  --action-bar-height: 114px;
}

button { touch-action: manipulation; -webkit-tap-highlight-color: transparent; }
button:focus-visible { outline: 3px solid var(--control-gold); outline-offset: 3px; }
button:disabled { cursor: default; }

.game-toolbar { display: flex; min-height: 44px; align-items: center; gap: 12px; }
.game-brand { color: #f5e8c5; font-size: 18px; font-weight: 850; letter-spacing: -.04em; }
.round-label { color: var(--control-muted); font-size: 12px; }
.game-settings-toggle {
  position: static; display: block; min-width: 60px; min-height: 44px; margin-left: auto;
  border: 1px solid var(--control-border); border-radius: 8px; padding: 8px 14px;
  background: #102e24; color: var(--control-text); font-size: 13px; font-weight: 700;
}
.event-strip { display: grid; align-items: center; min-height: 36px; margin-top: -8px; }
#action-announcement { color: var(--control-muted); font-size: 13px; line-height: 1.4; text-align: center; overflow-wrap: anywhere; }
#action-announcement[data-kind="declaration"],
#action-announcement[data-kind="ting"] { color: var(--control-gold); font-weight: 750; }
#action-announcement[data-kind="interrupt"] { color: var(--control-reaction); font-weight: 750; }

.hand-panel { border-width: 1px; background: #0b281f; box-shadow: 0 4px 18px #0005; }
.hand-panel.my-turn { border-color: #d4b66d; box-shadow: inset 0 0 0 1px #d4b66d40, 0 4px 18px #0005; }
.hand-panel[data-flow-state="reaction"] { border-color: #78bdb0; }
.player-one-hand-title { position: static; min-height: 26px; flex-wrap: wrap; }
.hand-status { display: flex; min-height: 44px; align-items: center; justify-content: space-between; gap: 8px; color: var(--control-muted); }
#selection-count { min-width: 0; font-size: 13px; font-weight: 650; line-height: 1.4; overflow-wrap: anywhere; }
.hand-panel[data-selection-count]:not([data-selection-count="0"]) #selection-count { color: var(--control-gold); }
#move-warning:empty { display: none; }
.clear-selection { flex-shrink: 0; min-height: 44px; padding: 6px 10px; border: 0; border-radius: 6px; background: transparent; color: #e5d6ab; font-size: 12px; }
.clear-selection:disabled { opacity: .45; }
.hand .card { transition: transform 160ms ease-out, box-shadow 160ms ease-out, border-color 160ms ease-out; }
.hand .card[aria-pressed="true"] { border-color: var(--control-gold); box-shadow: 0 0 0 2px #ecd28e, 0 6px 12px #0006; }
.hand .card:focus-visible { outline-offset: 2px; }
.hand .card.reaction-candidate { border-color: var(--control-reaction); box-shadow: 0 0 0 2px #99ddd0, 0 4px 10px #0005; }

.seat-actions { position: relative; display: flex; flex: 0 0 auto; min-height: var(--action-bar-height); flex-direction: column; justify-content: flex-end; margin-top: auto; padding: 8px 0 2px; border-top: 1px solid #8fa58f40; }
.seat-hand .seat-actions:not(.is-active) { display: none; }
.seat-action-hint { min-height: 38px; margin: 0; padding: 0 4px; display: flex; align-items: center; justify-content: center; color: var(--control-muted); font-size: 13px; line-height: 1.45; text-align: center; overflow-wrap: anywhere; }
.seat-action-hint:empty { visibility: hidden; }
.seat-action-hint.error { color: var(--control-error); }
.seat-actions[data-action-state="reaction"] .seat-action-hint { padding-right: 44px; color: var(--control-reaction); }
.seat-actions[data-action-state="play"] .seat-action-hint { color: #e6dfc6; }
.seat-actions[data-action-state="blocked"] .seat-action-hint { color: var(--control-error); }
.action-countdown { position: absolute; top: 14px; right: 6px; color: var(--control-reaction); font-size: 16px; font-weight: 850; font-variant-numeric: tabular-nums; }
.reaction-meter { flex: 0 0 3px; height: 3px; margin: 5px 0 10px; overflow: hidden; border-radius: 2px; background: transparent; }
.reaction-meter[data-active="true"] { background: #99ddd024; }
.reaction-meter span { display: block; width: 100%; height: 100%; transform-origin: left; background: var(--control-reaction); transition: transform 180ms linear; }
.seat-action-buttons { display: flex; flex: 0 0 auto; min-height: 48px; align-items: stretch; justify-content: center; gap: 8px; }
.seat-action-buttons button {
  min-width: 0; min-height: 48px; max-width: 320px; flex: 1 1 0;
  border: 1px solid var(--control-border); border-radius: 9px; padding: 10px 12px;
  background: var(--control-surface); color: var(--control-text); font-size: 15px; font-weight: 750;
  line-height: 1.2; white-space: nowrap; box-shadow: 0 2px 0 #0003;
  transition: background-color 140ms ease, transform 100ms ease;
}
.seat-action-buttons button.primary { border-color: #edd797; background: var(--control-gold); color: #20352a; box-shadow: 0 2px 0 #8d763d; }
.seat-actions[data-action-state="play"] button.primary,
.seat-actions[data-action-state="blocked"] button.primary { flex-grow: 1.7; }
.seat-actions[data-action-state="reaction"] button.primary { border-color: #b7ebde; background: var(--control-reaction); color: #15372d; }
.seat-action-buttons button:disabled { opacity: 1; border-color: #3b5148; background: #1a3027; color: #93a197; box-shadow: none; }
.seat-action-buttons button:not(:disabled):active { transform: translateY(2px); box-shadow: none; }
.hand-panel.hand-empty[data-flow-state="ended"] .seat-actions { display: flex; }

.turn-label { display: flex; min-height: 38px; align-items: center; justify-content: center; margin: 7px 0 0; padding: 6px 8px; border-radius: 6px; background: #163c2d; color: #eff1df; font-size: 13px; font-weight: 650; line-height: 1.45; text-align: center; }
.turn-label[data-flow-state="play"], .turn-label[data-flow-state="declare"], .turn-label[data-flow-state="response"] { background: #34472f; color: #ffedb8; }
.turn-label[data-flow-state="reaction"] { background: #1b4b41; color: #c5f2e7; }
.reaction-label { font-variant-numeric: tabular-nums; }
.reaction-label:not(:empty) { padding: 3px 6px; border-radius: 4px; background: #245e50; color: #effff7; font-weight: 750; }
.inline-log li { display: list-item; -webkit-line-clamp: unset; white-space: normal; overflow-wrap: anywhere; text-overflow: clip; line-height: 1.35; }
.inline-log ol { overflow-y: auto; overscroll-behavior: contain; }
.inline-log { min-height: 80px; }
/* A first-use tip borrows the history slot instead of pushing actions down. */
.rule-tip { position: absolute; z-index: 3; right: 0; bottom: 0; left: 0; min-height: 48px; margin: 0; padding: 1px 8px; }
.rule-tip button { min-width: 44px; min-height: 44px; }
.table-layout:has(.rule-tip:not([hidden])) .inline-log { visibility: hidden; }

.mode-dialog, .settings-dialog, .rules-reference-dialog { border: 1px solid #87916c; border-radius: 14px; background: #102c23; box-shadow: 0 18px 60px #0009; }
dialog { max-height: calc(100dvh - 32px); overflow-y: auto; overscroll-behavior: contain; }
.mode-dialog h2 { font-size: clamp(21px, 5vw, 26px); letter-spacing: -.04em; }
.mode-option { min-height: 104px; border-radius: 9px; box-shadow: none; }
.mode-option.selected { border-color: #dfc582; background: #214b37; box-shadow: none; }
.mode-option:disabled { opacity: .55; }
.mode-start { margin-top: 10px; min-height: 48px; border: 1px solid #ecd28e; border-radius: 9px; background: #ecd28e; color: #20352a; box-shadow: 0 2px 0 #8d763d; }
.rules-reference-dialog { display: none; }
.rules-reference-dialog[open] { display: flex; flex-direction: column; }
.rules-reference-list { min-height: 0; flex: 1 1 auto; }
.rules-reference-dialog .settings-close { flex-shrink: 0; }
.rules-reference-dialog .panel-kicker { color: #bfceb9; }
.result-dialog { border: 1px solid #cbbd96; border-radius: 14px; background: #f4ecd7; color-scheme: light; }
.result-header { justify-content: center; text-align: center; }
.result-header h2 { margin-top: 5px; font-size: 26px; }
.result-summary { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 20px 0 14px; }
#result-change { font-size: clamp(38px, 8vw, 52px); font-weight: 850; letter-spacing: -.04em; font-variant-numeric: tabular-nums; line-height: 1; color: #344b3c; }
.result-dialog[data-outcome="win"] #result-change { color: #196649; }
.result-dialog[data-outcome="loss"] #result-change { color: #a73b30; }
#result-total { margin-top: 4px; font-size: 13px; color: #596554; }
.result-message { margin-top: 0; line-height: 1.6; text-align: center; font-weight: 500; }
.result-section { border-color: #bdb59580; }
.result-section > .panel-kicker { text-align: left; font-size: 12px; color: #665f48; }
.result-scores li { padding: 8px; border-radius: 6px; }
.result-scores .own-result { background: #e1e5ce; font-weight: 750; }
.result-actions { background: #f4ecd7; }
.result-actions button { width: 100%; min-height: 48px; border-radius: 8px; background: #245d45; color: #fffbed; }

@media (hover: hover) {
  .seat-action-buttons button.secondary:not(:disabled):hover { background: #244d3e; }
  .seat-action-buttons button.primary:not(:disabled):hover { filter: brightness(1.07); }
  .clear-selection:not(:disabled):hover { background: #f3dfb012; }
}
@media (min-width: 768px) {
  .app-shell { display: grid; grid-template-columns: 1fr; grid-template-rows: auto auto auto; align-content: start; gap: 6px; padding: 4px max(12px, env(safe-area-inset-right)) max(4px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left)); }
  .game-toolbar { grid-area: 1 / 1; }
  .event-strip { grid-area: 1 / 1; min-height: 0; margin: 0 80px 0 220px; pointer-events: none; }
  .board { grid-template-rows: 72px minmax(280px, auto); gap: 6px 12px; }
  .game-grid, .table-panel { min-height: 280px; }
  .table-panel { padding: 8px; }
  .table-layout { padding-top: 50px; }
  .table-state { row-gap: 0; }
  .table-cards { grid-template-rows: minmax(100px, 1fr); }
  .table-pile { min-height: 100px; }
  .table-meta { min-height: 28px; margin-top: 4px; padding-top: 4px; font-size: 12px; }
  #reaction-label { display: none; }
  .turn-label { min-height: 32px; margin-top: 4px; padding: 4px 6px; font-size: 12px; }
  .inline-log { min-height: 48px; flex-basis: 48px; height: 48px; }
  .inline-log > .panel-kicker { font-size: 11px; }
  .inline-log ol { margin-top: 2px; font-size: 12px; }
  .hand-panel { display: grid; grid-template-columns: auto minmax(0, 1fr); padding: 4px 10px; }
  .player-one-hand-title { grid-area: 1 / 1; min-height: 0; }
  .hand-status { grid-area: 1 / 2; min-height: 44px; justify-content: flex-end; }
  #hand { grid-area: 2 / 1 / 3 / 3; min-height: 150px; padding-top: 24px; padding-bottom: 14px; }
  #hand-seat-0-actions { grid-area: 3 / 1 / 4 / 3; }
  .seat-actions { min-height: 88px; padding-top: 3px; }
  .seat-action-hint { min-height: 28px; }
  .reaction-meter { margin: 2px 0 5px; }
  .seat-action-buttons, .seat-action-buttons button { min-height: 44px; }
  .seat-action-buttons button { padding-block: 8px; }
  .player.seat-1, .player.seat-3 { min-height: 160px; }
}
@media (max-width: 767px) {
  /* Reserve space for the hand and actions before expanding the table. */
  .app-shell { gap: 8px; padding-top: 8px; padding-bottom: max(8px, env(safe-area-inset-bottom)); }
  .game-toolbar { gap: 8px; }
  .game-brand { font-size: 16px; }
  .round-label { font-size: 11px; }
  .event-strip { min-height: 24px; margin-top: -4px; }
  #action-announcement { font-size: 12px; }
  .board { grid-template-rows: 80px minmax(312px, auto); gap: 6px; }
  .game-grid, .table-panel { min-height: 312px; }
  .table-panel { padding: 8px; }
  .table-layout { padding-top: 50px; }
  .table-cards { grid-template-rows: minmax(100px, 1fr); }
  .table-pile { min-height: 100px; }
  .table-meta { min-height: 28px; margin-top: 5px; padding-top: 5px; font-size: 12px; }
  #reaction-label { display: none; }
  .turn-label { min-height: 34px; margin-top: 5px; padding: 4px 6px; font-size: 12px; }
  .inline-log { min-height: 60px; flex-basis: 60px; height: 60px; }
  .inline-log > .panel-kicker { font-size: 11px; }
  .rule-tip { min-height: 60px; }
  .hand-panel { padding: 6px 10px; }
  .player-one-hand-title { min-height: 24px; }
  .hand { min-height: 134px; padding-top: 10px; padding-bottom: 22px; }
  .seat-actions { min-height: 104px; padding-top: 5px; }
  .reaction-meter { margin: 3px 0 7px; }
  .seat-action-buttons, .seat-action-buttons button { min-height: 46px; }
  .seat-action-buttons { gap: 6px; }
  .seat-action-buttons button { padding-inline: 6px; font-size: 14px; }
  .seat-action-hint { min-height: 34px; font-size: 12px; }
  .result-scores li { gap: 6px; font-size: 13px; }
}
@media (prefers-reduced-motion: reduce) {
  .hand .card, .seat-action-buttons button, .reaction-meter span, .mode-start { transition: none; }
}
html[data-reduced-motion="true"] .hand .card,
html[data-reduced-motion="true"] .seat-action-buttons button,
html[data-reduced-motion="true"] .reaction-meter span,
html[data-reduced-motion="true"] .mode-start { transition: none; }

}
