/* Raise the Sum identity. Layout and operation semantics live in style.css. */
.game-loading main,.game-loading .site-links{visibility:hidden}
#game-loading-message{position:absolute;top:120px;left:24px;right:24px;text-align:center;color:var(--ink);font-size:16px}
.javascript-note{position:absolute;top:120px;left:24px;right:24px;text-align:center}
@font-face {
  font-family: 'Bricolage Grotesque';
  src: url('/assets/v/brand/bricolage-latin.b94352d949.woff') format('woff');
  font-weight: 200 800;
  font-style: normal;
  font-display: swap;
}
:root {
  --brand-heading: 'Bricolage Grotesque', 'DM Sans', sans-serif;
  --brand-tint: #edf1fd;
  -webkit-tap-highlight-color: transparent;
}
/* Pointer presses stay clean; keyboard navigation retains its focus ring. */
:is(button, a, summary):focus:not(:focus-visible) { outline: none; }
h2, .empty-table h3, .round-result h3 {
  font-family: var(--brand-heading);
  font-weight: 750;
}
.masthead { border-bottom-color: transparent; }
.brand-group { display: flex; align-items: center; gap: 20px; }
.brand-group .edition { white-space: nowrap; }
.edition { color: var(--ink); letter-spacing: 1.5px; }
.game-board {
  border-color: #d5dbce;
  box-shadow: 0 3px 0 #252c2909;
}
.scorebar {
  background: #fdfbf5;
  border-bottom-color: #dcded4;
  box-shadow: inset 0 3px var(--blue);
}
.avatar.you { background: var(--blue); border-color: var(--blue); color: white; }
.avatar.bot { background: var(--ink); border-color: var(--ink); color: var(--paper); }
.match-size-button { color: var(--blue); }
.points i.filled { background: var(--blue); border-color: var(--blue); }
.multiplayer-scorebar .seat-current { background: var(--brand-tint); }
.round-indicator>span { color: var(--ink); }

/* The same upright mark appears on every hidden card and the shared deck. */
.deck-card, .opponent-cards .mini-back {
  background: var(--ink) url('/assets/v/brand/mark-cream.d6d590b62c.svg') center / 64% auto no-repeat;
  border-color: var(--paper);
}
.deck-card { position: relative; }
.deck-card::before, .opponent-cards .mini-back::before {
  content: '';
  position: absolute;
  inset: 3px;
  border: 1px solid #f6f3eb40;
  border-radius: 3px;
  pointer-events: none;
}
.opponent-cards .mini-back::after { content: none; }
.empty-table .table-mark img { display: block; margin: auto; opacity: .5; }
.round-result .result-symbol img { display: block; margin: auto; }
.round-result h3 { font-weight: 800; }

/* Numerical faces remain Space Grotesk; white type identifies every card. */
.playing-card::before { opacity: .35; }
.card-value { font-weight: 600; }
.card-name { font-weight: 700; opacity: 1; }
.playing-card.zero { --card-color: var(--ink); background: var(--ink); }
.card-badge { font-family: var(--brand-heading); font-weight: 700; }
.card-badge.fresh { background: var(--paper); color: var(--blue); border-color: #3464df50; }

.play-builder { background: #fdfbf5; }
.move-previews .target-column { background: var(--brand-tint); }
.move-previews .target-column .eyebrow { color: #4e608d; }
.play-builder .your-preview { border-color: #cbd5ef; background: #fffefa; }
.play-builder .opponent-preview { background: #f0efe8; border-color: #e1e0d6; }
.primary {
  background: var(--blue);
  border-color: var(--blue);
  color: white;
  box-shadow: none;
  font-weight: 700;
  transition: background .15s;
}
.primary:hover:not(:disabled) { background: #2955c9; border-color: #2955c9; }
.primary:disabled { box-shadow: none; }
.secondary { color: var(--ink); border-color: #bfc4b9; }
.secondary:hover:not(:disabled) { background: #eeeee5; }
.icon-button { background: #fdfbf5; }
.icon-button:hover { border-color: var(--blue); color: var(--blue); }
.hand-header h2>span { background: #e9e6db; color: var(--ink); }

dialog {
  border-color: #d4d4c8;
  background: var(--paper);
  background-image: linear-gradient(to right, var(--blue) 25%, var(--green) 25% 50%, var(--red) 50% 75%, var(--yellow) 75%);
  background-size: 100% 5px;
  background-repeat: no-repeat;
}
dialog::backdrop { background: #252c297d; }
dialog h2 { font-weight: 800; letter-spacing: -1px; }
.welcome-logo { display: block; width: 158px; height: auto; margin: 0 0 24px; }
.player-count-picker label:has(input:checked) { background: var(--brand-tint); border-color: var(--blue); }
.player-count-picker input { accent-color: var(--blue); }
.tutorial-coach { border-color: #cbd5ef; background: var(--brand-tint); }
.tutorial-coach .eyebrow { color: var(--blue); }
.demo-reference h2 { font-weight: 800; }
.deck-total { background: var(--ink); color: var(--paper); }
.reference-menu { position: relative; color: var(--ink); flex-shrink: 0; }
.reference-menu summary {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 0 10px; list-style: none;
  font-size: 12px; font-weight: 700; border-radius: 8px;
}
.reference-menu summary::-webkit-details-marker { display: none; }
.reference-menu[open] summary, .reference-menu summary:hover { background: var(--brand-tint); color: var(--blue); }
.reference-menu nav {
  position: absolute; top: calc(100% + 6px); right: 0; z-index: 50;
  width: 220px; padding: 6px; background: var(--paper);
  border: 1px solid var(--line); border-radius: 12px;
  box-shadow: 0 10px 32px #252c2926;
}
.reference-menu nav button {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  width: 100%; min-height: 46px; padding: 12px; border: 0;
  border-radius: 7px; background: transparent; color: var(--ink);
  font-size: 12px; font-weight: 600; text-align: left;
}
.reference-menu nav button:hover { background: var(--brand-tint); color: var(--blue); }
.header-actions .hints-toggle { display: flex; align-items: center; justify-content: center; gap: 8px; flex-shrink: 0; min-width: 44px; min-height: 44px; padding: 0; border: 0; background: transparent; color: var(--ink); font-size: 14px; font-weight: 600; }
.hints-toggle:hover { color: var(--blue); }
.hints-switch { position: relative; flex: 0 0 36px; width: 36px; height: 22px; border-radius: 11px; background: #a0a79d; transition: background .15s; }
.hints-switch::after { content: ''; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%; background: white; box-shadow: 0 1px 3px #0002; transition: transform .15s; }
.hints-toggle[aria-checked="true"] .hints-switch { background: var(--blue); }
.hints-toggle[aria-checked="true"] .hints-switch::after { transform: translateX(14px); }
@media(prefers-reduced-motion:reduce) { .hints-switch,.hints-switch::after { transition: none; } }
#deck-dialog .deck-contents > div { padding: 14px 0; }
#deck-dialog .deck-contents strong { font-size: 14px; }
#deck-dialog .deck-contents small { font-size: 11px; line-height: 1.5; }
#deck-dialog .deck-contents dd { font-size: 24px; }
#deck-dialog .reference-symbol { width: 32px; height: 40px; font-size: 23px; flex-shrink: 0; }
@media(max-width:700px) {
  .reference-menu summary { font-size: 11px; gap: 5px; padding: 0 7px; }
  .reference-menu nav { right: 0; }
  #deck-dialog { padding: 20px; }
  #deck-dialog h2 { font-size: 27px; }
  #deck-dialog .deck-contents > div { padding: 10px 0; }
  #deck-dialog .deck-contents small { font-size: 10px; }
  .welcome-logo { width: 132px; margin-bottom: 18px; }
  .primary:disabled { box-shadow: none; }
  .deck-card::before { inset: 2px; border-radius: 2px; }
}
@media(prefers-reduced-motion:reduce) {
  .primary { transition: none; }
}

/* Readable labels and guidance; compact screens may scroll instead of shrinking text. */
:root{--muted:#5f695f}
.edition,.round-indicator>span,.round-indicator small,.turn-event,.table-owner,.deck-column small{font-size:12px;letter-spacing:.4px;line-height:1.5}
.player-score strong,.multiplayer-scorebar .player-score strong{font-size:14px}
.match-size-button,.seat-state,.multiplayer-scorebar .seat-state,.opponent-state,.multiplayer .opponent-state{font-size:12px}
.opponent-hand-header h2,.multiplayer .opponent-hand-header h2{font-size:14px;line-height:1.5}
.opponent-hand-header h2>span,.multiplayer .opponent-hand-header h2>span{font-size:12px;color:#5f695f}
.deck-column strong{font-size:15px}
.empty-table h3{font-size:16px}
.round-result p,.status-bar,.status-bar.win-status,.turn-event{font-size:14px;line-height:1.5}
.move-previews .target-column .eyebrow,.play-builder .your-preview .eyebrow,.play-builder .opponent-preview .eyebrow{font-size:12px;line-height:1.5;letter-spacing:.5px}
.move-previews .target-column #target-equation,.move-previews .target-column small{font-size:13px;line-height:1.6}
.play-builder .selection-help,.play-builder .opponent-preview .selection-help{font-size:14px;line-height:1.5;color:var(--muted)}
.play-builder .selection-help.invalid{color:#b24339}
.hand-header h2{font-size:18px}
.hand-header p,.hand-header .quiet,.play-actions button,.primary,.secondary{font-size:14px;line-height:1.5}
.hand .card-name{font-size:10px;letter-spacing:0;bottom:18px}
.hand .card-badge{font-size:10px;letter-spacing:0}
.hand-notice strong{font-size:16px}.hand-notice p{font-size:14px;line-height:1.5}
.tutorial-coach h2{font-size:21px}.tutorial-coach p{font-size:15px;line-height:1.6}
.tutorial-coach .eyebrow,.tutorial-heading .quiet{font-size:12px;line-height:1.5;letter-spacing:.5px}
.reference-menu summary,.reference-menu nav button{font-size:14px}
#rules-dialog p,#rules-dialog .rule-types p,dialog p,#new-dialog p{font-size:16px;line-height:1.6}
.rule-types strong,.rule-example,#deck-dialog .deck-contents strong,.player-count-picker legend,.player-count-picker b{font-size:16px}
.rule-example small,#deck-dialog .deck-contents small,.player-count-picker small{font-size:14px;line-height:1.5}
#new-dialog .match-setup-note,.match-setup-note{font-size:14px!important}
footer,.multiplayer footer,footer .quiet{font-size:12px;letter-spacing:.2px;color:var(--muted)}
@media(min-width:701px){
 .play-builder .opponent-preview{grid-template-columns:minmax(0,1fr)}
 .play-builder .opponent-preview .calculation{font-size:24px}
 .play-builder{grid-template-columns:minmax(0,1fr) 150px}
}
@media(max-width:700px){
 .masthead{height:60px}
 .scorebar:not(.multiplayer-scorebar) .round-indicator{grid-template-columns:1fr;gap:0}
 .scorebar:not(.multiplayer-scorebar) .match-size-button{grid-column:1;grid-row:3}
 .round-indicator>span,.round-indicator small{font-size:11px}
 .arena .deck-column{width:40px}.deck-column small{font-size:10px}
 .table-owner{font-size:11px}
 .move-previews{grid-template-columns:82px minmax(0,1fr)}
 .move-previews .target-column .eyebrow{font-size:11px;letter-spacing:0}
 .move-previews .target-column #target-equation,.move-previews .target-column small{font-size:12px}
 .play-builder .your-preview .eyebrow,.play-builder .opponent-preview .eyebrow{font-size:11px;letter-spacing:0}
 .play-builder .your-preview .calculation{font-size:22px}
 .play-builder .opponent-preview .calculation{font-size:20px}
 .hand,.tutorial-active .hand{display:grid;grid-template-columns:repeat(4,minmax(0,1fr));gap:16px 8px;max-width:440px}
 .hand .playing-card,.multiplayer .hand .playing-card,.tutorial-active .hand .playing-card{width:100%;max-width:none;height:auto;aspect-ratio:3/4}
 .hand .card-value{font-size:38px}
 .hand .card-corner{font-size:15px}
 .play-builder .play-actions{grid-template-columns:48px 1fr 1.2fr}
 .play-actions button{padding-inline:5px}
 .reference-menu summary{padding-inline:5px}
 .multiplayer .opponent-hand-header h2>span{display:block;margin:0}
}

/* A shared green table, then one clear workspace for your next move. */
.game-board {
  color: #fffdf4;
  background: radial-gradient(ellipse at 50% 100%, #315e50, #21483c);
  border: 1px solid #21483c;
  border-radius: 22px;
  box-shadow: inset 0 0 0 5px #ffffff06, 0 4px 0 #173d3120;
}
.game-board .scorebar { background: #142d272e; border-color: #fffdf41a; box-shadow: none; }
.game-board .round-indicator>span { color: #fffdf4; }
.game-board .round-indicator small,
.game-board .seat-state,
.game-board .deck-column small,
.game-board .table-owner { color: #c2d5c8; }
.game-board .match-size-button { color: #fffdf4; }
.game-board .avatar.bot { background: #fffdf417; border-color: #fffdf440; color: #fffdf4; }
.game-board .points i { border-color: #fffdf466; }
.game-board .points i.filled { background: #f1c64b; border-color: #f1c64b; }
.game-board .multiplayer-scorebar .seat-current { background: #ffffff14; }
.game-board .opponent-row { color: #fffdf4; }
.game-board .opponent-hand-header h2 { font-weight: 600; }
.game-board .opponent-hand-header h2>span { background: transparent; color: #c2d5c8; font-weight: 400; padding: 0; }
.game-board .opponent-seat.seat-current { background: #ffffff08; border-color: #fffdf430; }
.game-board .opponent-cards .mini-back { background-color: #193d32; border-color: #b7c9b9; box-shadow: 0 2px 3px #102c3540; }
.game-board .deck-card { background-color: #193d32; box-shadow: 3px 3px 0 #879d87, 6px 6px 0 #597562; }
.game-board .turn-event,.game-board .thinking { color: #e0eddf; }
.game-board .status-bar { color: #e0eddf; background: #142d2726; border-color: #fffdf416; }
.game-board .status-bar.attack-status { color: #ffe29b; }
.game-board .round-result p { color: #c2d5c8; }
.game-board .result-symbol img { filter: brightness(0) invert(1); opacity: .8; }
.empty-table h3 { font-size: 24px; letter-spacing: -.7px; margin: 0; }
.table-cards .playing-card { box-shadow: 0 3px 0 color-mix(in srgb,var(--card-color),black 25%), 0 7px 12px #102c3540; }
.table-owner { margin-top: 10px; }
.play-builder { border: 0; background: transparent; padding: 0; gap: 18px; }
.move-previews { gap: 22px; }
.move-previews .target-column { background: transparent; border-radius: 0; border-right: 1px solid #dcded4; padding: 8px 18px 8px 0; }
.move-previews .target-column .eyebrow { color: var(--muted); }
.move-previews .target-column>strong { font-family: var(--brand-heading); font-size: 64px; font-weight: 750; }
.move-previews .target-column small { font-size: 12px; }
.move-stack { gap: 0; align-content: center; }
.play-builder .your-preview { border: 0; border-radius: 0; padding: 10px 0; background: transparent; }
.play-builder .your-preview .eyebrow { color: var(--muted); font-size: 12px; margin-bottom: 6px; }
.play-builder .your-preview .calculation { font-size: clamp(28px,3.1vw,40px); line-height: 1.35; }
.play-builder .opponent-preview { display: flex; align-items: center; flex-wrap: wrap; gap: 4px 14px; margin: 0; padding: 8px 0; border: 0; border-radius: 0; background: transparent; }
.play-builder .opponent-preview .eyebrow { color: var(--muted); font-size: 11px; margin: 0; }
.play-builder .opponent-preview .calculation { font-size: 20px; line-height: 1.5; }
.play-builder .opponent-preview[data-attack="true"] .eyebrow { color: var(--ink); }
.math-term { background: transparent; }
/* Score to beat and both next moves use the card colors, even for neutral values. */
.move-previews .math-term { opacity:1; }
.move-previews .math-add { color:var(--blue); }
.move-previews .math-subtract { color:var(--red); }
.move-previews .math-multiply { color:var(--green); }
.move-previews .math-divide { color:var(--yellow); }
.play-builder .selection-help { margin-top: 4px; font-size: 13px; }
.play-builder .play-actions { gap: 8px; }
.play-actions #play-button { order: -1; min-height: 48px; font-size: 16px; }
.hand-section { border-top: 1px solid var(--line); margin-top: 14px; padding-top: 10px; }
.hand-header { margin-bottom: 8px; }
.hand .playing-card { border-radius: 10px; box-shadow: 0 4px 0 color-mix(in srgb,var(--card-color),black 22%), 0 8px 13px #252c291a; }
.hand .playing-card.selected { box-shadow: 0 0 0 3px var(--paper), 0 0 0 5px var(--ink), 0 9px 16px #252c2926; }
.hand .card-badge.picked { width: 24px; height: 24px; padding: 0; display: grid; place-items: center; border-radius: 50%; font-size: 15px; top: -9px; right: -5px; }
.discarding-hand .your-preview { border-left: 3px solid var(--red); padding-left: 12px; }
@media(min-width:701px) {
  .game-board .arena { min-height: 120px; }
  .play-builder { margin-top: 22px; grid-template-columns: minmax(0,1fr) 144px; }
  .play-builder .play-actions { flex-direction: column; }
  .hand .playing-card { width: clamp(80px,10dvh,104px); height: clamp(110px,13.8dvh,143px); }
}
@media(max-width:1000px) and (min-width:701px) {
  .move-previews { grid-template-columns: 112px minmax(0,1fr); gap: 16px; }
  .play-builder .your-preview .calculation { font-size: 28px; }
}
@media(max-width:700px) {
  .game-board { border-radius: 16px; }
  .game-board .scorebar { padding: 8px 12px; }
  .game-board .arena { min-height: 76px; padding: 8px 10px 12px; grid-template-columns: 40px minmax(0,1fr) 40px; }
  .table-cards .playing-card { width: 34px; height: 48px; }
  .table-cards:has(.playing-card:nth-child(4)) .playing-card+.playing-card { margin-left: 0; }
  .empty-table h3 { font-size: 20px; }
  .table-owner { margin-top: 6px; }
  .player-area { padding-top: 10px; }
  .move-previews { grid-template-columns: 76px minmax(0,1fr); gap: 12px; }
  .move-previews .target-column { padding: 6px 8px 6px 0; }
  .move-previews .target-column>strong { font-size: 42px; }
  .move-previews .target-column #target-equation { font-size: 11px; }
  .move-previews .target-column small { font-size: 11px; line-height: 1.4; }
  .play-builder .your-preview { padding: 6px 0; }
  .play-builder .your-preview .eyebrow { font-size: 11px; margin-bottom: 4px; }
  .play-builder .your-preview .calculation { font-size: clamp(20px,5.6vw,28px); line-height: 1.4; }
  .play-builder .opponent-preview { display: block; padding: 4px 0; }
  .play-builder .opponent-preview .eyebrow { font-size: 11px; }
  .play-builder .opponent-preview .calculation { font-size: 18px; }
  .play-builder .play-actions { gap: 8px; }
  .play-actions #play-button { order: 0; }
  .hand-section { margin-top: 8px; padding-top: 4px; }
  .hand { padding-top: 12px; }
  .hand .card-value { padding-bottom: 12px; }
}
@media(max-width:360px) {
  .game-board .arena { grid-template-columns: 30px minmax(0,1fr) 30px; gap: 4px; }
  .table-cards .playing-card { width: 30px; height: 43px; }
  .move-previews { grid-template-columns: 64px minmax(0,1fr); gap: 8px; }
  .play-builder .your-preview .calculation { font-size: 20px; }
  .play-builder .opponent-preview .calculation { font-size: 17px; }
}

/* Portraits identify each seat; only your portrait opens the picker. */
.game-board .scorebar .player-score .portrait-avatar {
  position: relative;
  display: block;
  flex: 0 0 56px;
  width: 56px;
  height: 56px;
  min-width: 0;
  padding: 0;
  border: 2px solid #fffdf4aa;
  border-radius: 50%;
  background: var(--paper);
  line-height: 1;
}
.portrait-avatar img { display: block; width: 100%; height: 100%; object-fit: cover; border-radius: 50%; }
button.portrait-avatar { transition: transform .15s, box-shadow .15s; }
button.portrait-avatar:hover:not(:disabled) { transform: translateY(-2px); box-shadow: 0 0 0 3px #fffdf433; }
.game-board button.portrait-avatar:focus-visible { outline-color: #f1c64b; outline-offset: 4px; }
.portrait-edit { position: absolute; right: -4px; bottom: -3px; display: grid; place-items: center; width: 20px; height: 20px; border-radius: 50%; background: var(--paper); color: var(--ink); border: 2px solid #21483c; font-size: 14px; }
#portrait-dialog { width: min(460px,calc(100% - 24px)); }
#portrait-dialog::backdrop { backdrop-filter: none; background: #142d2799; }
#portrait-dialog h2 { margin: 16px 0 24px; font-size: 30px; }
#portrait-dialog .eyebrow { font-size: 11px; letter-spacing: 1px; }
.portrait-options { display: grid; grid-template-columns: repeat(4,minmax(0,1fr)); gap: 16px; padding: 4px; }
.portrait-option { position: relative; width: 100%; aspect-ratio: 1; border: 3px solid transparent; border-radius: 50%; background: #e9e6dc; padding: 0; transition: transform .15s, border-color .15s; }
.portrait-option img { width: 100%; height: 100%; display: block; object-fit: cover; border-radius: 50%; }
.portrait-option:hover { transform: translateY(-3px); }
.portrait-option[aria-pressed="true"] { border-color: var(--blue); }
.portrait-option:focus-visible { outline: 2px solid var(--ink); outline-offset: 4px; }
.portrait-check { display: none; position: absolute; right: -3px; bottom: -3px; width: 24px; height: 24px; border-radius: 50%; background: var(--blue); color: white; font-size: 15px; place-items: center; }
.portrait-option[aria-pressed="true"] .portrait-check { display: grid; }
@media(max-width:900px) and (min-width:701px) {
  .game-board .multiplayer-scorebar .player-score .portrait-avatar { width: 44px; height: 44px; flex-basis: 44px; }
  .multiplayer-scorebar .player-score { gap: 6px; padding-inline: 2px; }
}
@media(max-width:700px) {
  .game-board .scorebar .player-score .portrait-avatar { width: 40px; height: 40px; flex-basis: 40px; }
  .scorebar:not(.multiplayer-scorebar) { padding-inline: 10px; gap: 6px; }
  .scorebar:not(.multiplayer-scorebar) .player-score { gap: 6px; }
  .scorebar:not(.multiplayer-scorebar) .player-score>b { font-size: 21px; margin: 0; }
  .portrait-edit { width: 17px; height: 17px; font-size: 12px; }
  .multiplayer-scorebar .player-score { display: grid; grid-template-columns: minmax(0,1fr) auto; gap: 3px; align-items: center; }
  .game-board .multiplayer-scorebar .player-score .portrait-avatar { grid-column: 1/-1; justify-self: center; width: 44px; height: 44px; }
  .multiplayer-scorebar .player-score .seat-info { min-width: 0; }
  .multiplayer-scorebar .player-score .points { gap: 3px; }
  .multiplayer-scorebar .player-score .points i { width: 4px; height: 4px; }
  .multiplayer-scorebar .seat-state { font-size: 11px; white-space: nowrap; }
  #portrait-dialog { padding: 20px; }
  #portrait-dialog h2 { font-size: 27px; }
  .portrait-options { gap: 14px 10px; }
  .portrait-check { width: 20px; height: 20px; font-size: 13px; }
}
@media(max-width:360px) {
  .scorebar:not(.multiplayer-scorebar) .player-score { gap: 4px; }
  .game-board .scorebar:not(.multiplayer-scorebar) .player-score .portrait-avatar { width: 34px; height: 34px; flex-basis: 34px; }
}
@media(prefers-reduced-motion:reduce) {
  button.portrait-avatar,.portrait-option { transition: none; }
}

/* Primary action first, with Pass directly below at every screen size. */
.play-builder .play-actions { display: flex; flex-direction: column; align-items: stretch; gap: 8px; }
.play-actions #play-button { order: 0; }
.spectating .play-builder .play-actions { display: none; }
@media(max-width:700px) { .hand .playing-card { scroll-margin-bottom: 128px; } }

/* The menu shares the circular controls in the game header. */
.reference-menu summary.icon-button { border-radius: 50%; padding: 0; }
.menu-icon { display: block; width: 20px; height: 20px; }
.header-actions .match-setup-button {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  flex-basis: auto;
  width: auto;
  padding: 0 14px;
  border-radius: 22px;
  border-color: #c2cdef;
  background: var(--brand-tint);
  color: var(--blue);
}
.new-match-label { font-size: 14px; font-weight: 700; white-space: nowrap; }
@media(max-width:700px) {
  .header-actions .match-setup-button { flex-basis: 44px; width: 44px; padding: 3px 0; gap: 1px; flex-direction: column; border-radius: 50%; }
  .match-setup-button .menu-icon { width: 18px; height: 18px; }
  .new-match-label { font-size: 10px; line-height: 12px; }
  .new-match-word { display: none; }
}
.match-player-count {
  position: absolute;
  right: -3px;
  top: -3px;
  display: grid;
  place-items: center;
  min-width: 20px;
  height: 20px;
  padding: 0 3px;
  border: 2px solid var(--paper);
  border-radius: 50%;
  background: var(--blue);
  color: white;
  font-size: 12px;
  font-weight: 700;
  line-height: 1;
}
.scorebar:not(.multiplayer-scorebar) .round-indicator { grid-template-columns: 1fr; column-gap: 0; }

/* Round history sits with the controls and opens without moving the table. */
.header-actions { position: relative; }
.history-menu { display: flex; align-items: center; }
#history-button[aria-expanded="true"] { background: var(--brand-tint); color: var(--blue); border-color: var(--blue); }
.header-actions .history-panel {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  z-index: 50;
  width: min(360px,calc(100vw - 24px));
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--paper);
  color: var(--ink);
  box-shadow: 0 10px 32px #252c2926;
}
.history-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 8px; }
.history-heading h2 { font-size: 20px; }
.history-close { display: grid; place-items: center; width: 36px; height: 36px; padding: 0; border: 0; border-radius: 50%; background: transparent; color: var(--muted); font-size: 24px; }
.history-close:hover { background: #e9e6db; color: var(--ink); }
.history-panel #history-list { margin: 0; padding: 0 4px; list-style: none; max-height: min(340px,55dvh); overflow-y: auto; overscroll-behavior: contain; font-size: 14px; line-height: 1.6; }
.history-panel li { padding: 10px 0; border-top: 1px solid var(--line); overflow-wrap: anywhere; }
.history-panel li:first-child { border-top: 0; padding-top: 2px; }
.history-panel #history-list:focus-visible { outline: 2px solid var(--blue); outline-offset: 3px; border-radius: 4px; }
@media(max-width:360px) {
  .masthead .brand-logo { width: 100px; }
}
.menu-control-label,.menu-preferences:empty { display: none; }
@media(max-width:700px) {
  .masthead { height:60px; min-height:60px; padding-block:8px; flex-wrap:nowrap; gap:12px; }
  .masthead .brand-logo { width:100px; max-height:38px; }
  .masthead .header-actions { width:auto; flex:0 0 auto; gap:8px; }
  .masthead .edition { display:none; }
  /* Hide preferences during startup until their existing nodes move into the menu. */
  .header-actions > :is(#hints-toggle,#music-button,#sound-button) { display:none; }
  .reference-menu nav { width:min(260px,calc(100vw - 32px)); max-height:calc(100dvh - 100px - env(safe-area-inset-top,0px)); overflow-y:auto; }
  .menu-preferences { border-top:1px solid var(--line); margin-top:6px; padding-top:6px; }
  .header-actions .menu-preferences button { display:flex; flex-direction:row; justify-content:space-between; width:100%; height:auto; min-height:46px; gap:16px; padding:12px; border:0; border-radius:7px; font-size:14px; line-height:1.4; background:transparent; color:var(--ink); }
  .menu-preferences .menu-control-label { display:block; }
  .menu-preferences .hints-switch { flex:0 0 36px; }
  .menu-preferences .sound-icon { width:22px; height:22px; margin-right:7px; }
  .header-actions .menu-preferences button:hover { background:var(--brand-tint); color:var(--blue); }
}

/* Use available height for a roomier table without crowding short screens. */
@media(min-width:701px) and (min-height:701px) {
  .game-shell { --game-room: clamp(0px,calc(12dvh - 84px),40px); }
  .multiplayer .game-shell { --game-room: clamp(0px,calc(12dvh - 102px),34px); }
  .game-board .scorebar { padding-block: calc(7px + var(--game-room) / 8); }
  .game-board .scorebar .player-score .portrait-avatar {
    width: calc(56px + var(--game-room) / 4);
    height: calc(56px + var(--game-room) / 4);
    flex-basis: calc(56px + var(--game-room) / 4);
  }
  .game-board .player-score>b { font-size: clamp(24px,3dvh,32px); }
  .game-board .opponent-row {
    margin-top: calc(10px + var(--game-room) / 3);
    margin-bottom: calc(5px + var(--game-room) / 4);
  }
  .opponent-hand-header { margin-bottom: calc(5px + var(--game-room) / 6); }
  .game-board .arena {
    min-height: calc(120px + var(--game-room));
    padding-block: calc(10px + var(--game-room) / 4);
  }
  .table-cards { gap: 8px; }
  .table-cards .playing-card {
    width: clamp(46px,calc(10dvh - 24px),82px);
    height: clamp(64px,calc(14dvh - 34px),115px);
  }
  .table-cards .card-value { font-size: clamp(30px,4.2dvh,44px); }
  .table-cards .card-corner { font-size: clamp(12px,1.7dvh,16px); }
  .player-area .play-builder { margin-top: calc(22px + var(--game-room) / 3); }
  .move-previews .target-column>strong { font-size: clamp(64px,8dvh,80px); }
  .play-builder .your-preview { padding-block: calc(10px + var(--game-room) / 6); }
  .hand-section {
    margin-top: calc(14px + var(--game-room) / 4);
    padding-top: calc(10px + var(--game-room) / 4);
  }
  .hand-header { margin-bottom: calc(8px + var(--game-room) / 4); }
  .hand { gap: clamp(10px,1.4dvh,16px); }
  .hand .playing-card {
    width: clamp(80px,calc(14dvh - 26px),120px);
    height: clamp(110px,calc(19.2dvh - 35px),165px);
  }
  .hand .card-value { font-size: clamp(45px,6.4dvh,68px); }
  .hand .card-corner { font-size: clamp(17px,2.2dvh,22px); }
}
@media(min-width:1001px) and (min-height:701px) {
  .play-builder .your-preview .calculation { font-size: clamp(36px,4.9dvh,48px); }
  .play-builder .opponent-preview .calculation { font-size: clamp(20px,2.5dvh,25px); }
  .play-builder { grid-template-columns: minmax(0,1fr) 160px; }
  .play-actions #play-button { min-height: clamp(48px,6dvh,58px); font-size: 17px; }
}
@media(min-width:900px) {
  .tutorial-active .hand { grid-template-columns: repeat(var(--hand-count,8),minmax(0,76px)); }
  .tutorial-active .hand .card-value { font-size: clamp(38px,5.6dvh,52px); }
  .tutorial-active .hand .card-corner { font-size: 17px; }
}
@media(min-width:1001px) {
  body:not(.tutorial-active) .hand[data-size="large"] .playing-card {
    width: min(clamp(80px,calc(14dvh - 26px),120px),calc((100% - (var(--hand-count) - 1) * clamp(10px,1.4dvh,16px)) / var(--hand-count)));
    height: auto;
    aspect-ratio: 8 / 11;
  }
}
@media(min-width:701px) and (max-width:900px) {
  .game-board .multiplayer-scorebar .player-score .portrait-avatar {
    width: 44px; height: 44px; flex-basis: 44px;
  }
}

/* Keep the play surface steady as turns, messages and hand sizes change. */
.game-shell {
  --stable-card-width: clamp(80px,calc(14svh - 26px),120px);
  --stable-card-height: calc(var(--stable-card-width) * 11 / 8);
  --stable-hand-gap: clamp(10px,1.4svh,16px);
}
.game-board .turn-event { display:block; min-height:24px; box-sizing:border-box; }
.game-board #status { display:block; min-height:32px; box-sizing:border-box; }
.game-board #status[hidden] { display:block!important; visibility:hidden; }
.game-board .arena { min-height:clamp(132px,17.6svh,188px); }
.round-result .result-symbol { display:none; }
.game-board .opponent-cards { min-height:clamp(39px,4.9svh,53px); flex-wrap:nowrap; }
.game-board .opponent-cards:empty { display:flex; }
.game-board .multiplayer-scorebar .seat-state { min-height:1.5em; }
.multiplayer .game-board .opponent-cards {
  display:grid;
  grid-template-columns:repeat(5,minmax(0,24px));
  grid-template-rows:repeat(2,34px);
  gap:4px;
  min-height:72px;
  align-content:start;
}
.multiplayer .opponent-cards .mini-back { width:100%; }
.play-builder .your-preview .eyebrow { min-height:1.5em; }
#preview-label[hidden] { display:block!important; visibility:hidden; }
.play-builder .your-preview .calculation { min-height:1.35em; }
.play-builder #selection-help { display:block; min-height:21px; line-height:21px; }
.play-builder #selection-help[hidden] { display:block!important; visibility:hidden; }
.play-builder #opponent-preview { min-height:54px; align-content:start; }
.play-builder #opponent-preview[hidden] { display:flex!important; visibility:hidden; }
body[data-phase="between"] .your-preview .calculation,
body[data-phase="finished"] .your-preview .calculation { font-size:26px; }
.play-builder .play-actions {
  display:grid;
  grid-template-columns:minmax(0,1fr);
  --primary-action-height:clamp(48px,6svh,58px);
  grid-template-rows:var(--primary-action-height) 44px;
  align-content:center;
}
.play-actions #play-button,.play-actions #next-button { grid-column:1; grid-row:1; height:var(--primary-action-height); min-height:0; }
.play-actions #pass-button { grid-column:1; grid-row:2; }
.spectating .play-builder .play-actions { display:grid; visibility:hidden; }
.hand-header { min-height:44px; }
.hand-heading { align-items:center; }
#hint-button { min-width:125px; }
#hint-button[hidden] { display:block!important; visibility:hidden; }
.hand-layout { container-type:inline-size; }
body:not(.tutorial-active) .hand {
  display:flex;
  flex-wrap:wrap;
  align-items:flex-start;
  align-content:flex-start;
  gap:var(--stable-hand-gap);
  min-height:calc(var(--stable-card-height) + 24px);
  padding-block:12px;
}
body:not(.tutorial-active) .game-shell .hand .playing-card {
  flex:0 0 auto;
  width:min(var(--stable-card-width),calc((100% - 9 * var(--stable-hand-gap)) / 10));
  max-width:none;
  height:auto;
  aspect-ratio:8 / 11;
}
@media(min-width:701px) and (max-width:1000px) {
  .play-builder #selection-help { min-height:42px; }
  .play-builder #opponent-preview { min-height:76px; }
  body:not(.tutorial-active) .hand { min-height:calc(2 * var(--stable-card-height) + var(--stable-hand-gap) + 24px); }
  body:not(.tutorial-active) .game-shell .hand .playing-card { width:min(var(--stable-card-width),calc((100% - 4 * var(--stable-hand-gap)) / 5)); }
}
@media(max-width:700px) {
  .game-shell { --stable-hand-gap:8px; }
  .game-board .arena { min-height:136px; }
  .game-board .turn-event { min-height:47px; }
  .game-board #status,.game-board #status[hidden] { display:none!important; }
  .game-board .opponent-cards { min-height:27px; }
  .multiplayer .game-board .opponent-cards { grid-template-columns:repeat(5,minmax(0,17px)); grid-template-rows:repeat(2,23px); gap:3px; min-height:49px; }
  .play-builder .your-preview .calculation { min-height:2.8em; }
  .play-builder #selection-help { min-height:42px; }
  .play-builder #opponent-preview { min-height:81px; }
  .play-builder #opponent-preview[hidden] { display:block!important; }
  .hand-heading { min-height:42px; }
  .hand-header { min-height:94px; align-content:start; }
  .hand-heading { flex-basis:100%; }
  .hand-header #hint-button { min-height:44px; }
  body:not(.tutorial-active) .hand {
    --stable-card-width:calc((min(440px,100cqw) - 32px) / 4);
    --stable-card-height:calc(var(--stable-card-width) * 4 / 3);
    display:grid;
    grid-template-columns:repeat(4,minmax(0,1fr));
    grid-auto-rows:var(--stable-card-height);
    gap:16px 8px;
    min-height:calc(3 * var(--stable-card-height) + 56px);
  }
  body:not(.tutorial-active) .game-shell .hand .playing-card { width:100%; height:var(--stable-card-height); aspect-ratio:3 / 4; }
}
@media(max-width:360px) {
  .play-builder .your-preview .calculation { min-height:4.2em; }
  .play-builder #opponent-preview { min-height:98px; }
}
/* Fixed minimum tracks absorb short messages and single/two-line formulas. */
.move-stack { --primary-track:130px; --reply-track:54px; grid-template-rows:minmax(var(--primary-track),auto) minmax(var(--reply-track),auto); align-content:start; }
.play-builder .your-preview .calculation { min-height:0; }
@media(min-width:701px) and (max-width:1000px) { .move-stack { --primary-track:130px; --reply-track:80px; } }
@media(max-width:700px) { .move-stack { --primary-track:160px; --reply-track:84px; } }
@media(max-width:360px) { .move-stack { --primary-track:180px; --reply-track:104px; } }

@media(min-width:701px) {
  .multiplayer .game-board .opponent-cards { display:flex; min-height:34px; }
  .multiplayer .opponent-cards .mini-back { flex:0 1 24px; width:24px; min-width:0; }
  .player-area .play-builder { margin-top:16px; }
  .play-builder .your-preview { padding-block:8px; }
  .hand-section { margin-top:10px; padding-top:8px; }
  .hand-header { margin-bottom:8px; }
}
/* Three-digit scores stay on one line; they must not grow the whole workspace. */
.move-previews .target-column>strong { white-space:nowrap; overflow-wrap:normal; font-size:clamp(40px,6svh,64px); }
@media(min-width:701px) { .game-board .arena { min-height:clamp(136px,calc(14svh + 25px),180px); padding-block:10px; } }
@media(max-width:700px) {
  .game-board .arena { min-height:120px; }
  .move-previews .target-column>strong { font-size:34px; }
  .move-stack { --primary-track:140px; --reply-track:84px; }
}
@media(max-width:360px) { .move-previews .target-column>strong { font-size:30px; } }
.play-builder #opponent-preview { min-height:0; }
@media(max-width:700px) {
  body[data-phase="between"] .your-preview .calculation,
  body[data-phase="finished"] .your-preview .calculation { font-size:20px; }
}

/* Maths modes stay with the match; new choices are applied when dealing. */
.hand-heading{display:flex;align-items:center;gap:9px;flex-wrap:wrap}
#new-dialog{width:min(540px,calc(100% - 24px))}
#new-dialog .player-count-picker{margin:16px 0;gap:7px}
#new-dialog .player-count-picker label{padding:10px 12px}
#new-dialog .game-mode-picker small{font-size:13px;line-height:1.4}
#new-dialog .match-setup-note{margin:8px 0}
#rules-mode-note{padding:12px 14px;background:var(--brand-tint);border-radius:8px}
.welcome-actions{flex-wrap:wrap}
@media(max-width:600px){.welcome-actions{flex-direction:column;align-items:stretch}.welcome-actions button{width:100%}}
#new-dialog .player-count-picker:not(.game-mode-picker){grid-template-columns:repeat(3,minmax(0,1fr))}
#new-dialog .player-count-picker:not(.game-mode-picker) label{flex-direction:column;align-items:flex-start;gap:7px;padding:10px}
#new-dialog .player-count-picker:not(.game-mode-picker) b{font-size:14px}
#new-dialog .player-count-picker:not(.game-mode-picker) small{font-size:12px}
