:root {
  --bg: var(--palette-bg, #edeee4);
  --paper: var(--palette-paper, #f7f3e6);
  --ink: var(--palette-ink, #183a30);
  --line: var(--palette-line, #bccbc2);
  --accent: var(--palette-accent, #246448);
  --wash: var(--palette-wash, #e1eadd);
  --muted: var(--palette-muted, #51625a);
  --red-suit: #a21c38;
  --radius: 12px;
  --card-width: clamp(36px, 9.5vw, 55px);
  --card-height: calc(var(--card-width) * 1.4);
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.35 system-ui, sans-serif;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; }
body.large { font-size: 1.15rem; }
a { color: inherit; }
button, select { min-block-size: 44px; padding: .35em .65em; border: 1px solid var(--line); border-radius: 9px; background: var(--paper); color: var(--ink); font: inherit; }
button, summary { cursor: pointer; touch-action: manipulation; }
button:disabled { opacity: .58; cursor: default; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.primary { font-weight: 700; background: var(--accent); color: var(--palette-primary-ink, white); }
.masthead, main, .game-footer { width: min(100% - 20px, 720px); margin-inline: auto; }
.masthead { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 8px; padding-block: 10px; }
.masthead h1 { display: flex; gap: 7px; align-items: center; margin: 0; font: bold clamp(1.3rem, 5vw, 2rem)/1 Georgia, serif; white-space: nowrap; }
.accessibility, .selectors { display: flex; align-items: center; gap: 7px; }
.accessibility label { white-space: nowrap; }
.selectors { grid-column: 1 / -1; }
.selectors select { flex: 1; min-inline-size: 0; }
.game-toolbar, .game-tools { display: flex; align-items: center; gap: 5px; }
.game-toolbar { justify-content: space-between; margin-block: 7px; }
.game-toolbar > * { flex-shrink: 0; }
.game-toolbar button, .dialog-heading button { min-inline-size: 44px; }
.game-toolbar button { white-space: nowrap; }
.game-tools button { display: inline-flex; align-items: center; justify-content: center; gap: 5px; }
.short-label { display: none; }
.compact-toolbar :is(.wide-label, .toolbar-label) { display: none; }
.compact-toolbar .short-label { display: inline; font-size: 1.25rem; }
.game-toolbar.compact-toolbar button { inline-size: 44px; padding-inline: 0; }
@media (max-width: 680px) {
  .wide-label, .toolbar-label { display: none; }
  .short-label { display: inline; font-size: 1.25rem; }
  .game-toolbar button { inline-size: 44px; padding-inline: 0; }
}
@media (max-width: 350px) {
  .game-toolbar:has(.undo-redo-button:not([hidden])),
  .game-tools:has(.undo-redo-button:not([hidden])) { gap: 0; }
}
@media (max-width: 360px) {
  .masthead, main, .game-footer { width: calc(100% - 12px); }
  .masthead h1 img { inline-size: 27px; block-size: 27px; }
  .accessibility { gap: 3px; }
  #contrast { font-size: .79em; }
}
.table-shell, #score, #trick-history { border: 1px solid var(--line); border-radius: 15px; background: var(--paper); padding: 6px; }
.round-header { display: grid; grid-template-columns: 1fr auto; gap: 2px 6px; padding: 3px 4px 7px; }
#dealer, #trick-index { font-size: .9em; overflow-wrap: anywhere; }
#dealer { grid-column: 1; }
#trick-index { text-align: end; }
.table {
  position: relative; isolation: isolate; display: grid; grid-template: 1fr / 1fr;
  justify-items: center; align-items: center; block-size: clamp(290px, 71vw, 430px);
  border: 1px solid var(--line); border-radius: 14px; background: #184a37;
}
#table-action { position: absolute; inset: 0; z-index: 1; inline-size: 100%; background: transparent; border: 0; border-radius: inherit; }
#table-action:focus-visible { outline-color: var(--gc-theme-current, #edce7b); outline-offset: -5px; }
.seats { position: absolute; inset: 0; z-index: 2; pointer-events: none; direction: ltr; }
.seat { position: absolute; display: grid; gap: 3px; justify-items: center; width: min(29%, 160px); text-align: center; }
.seat[data-player="1"] { top: 8px; left: 5%; }
.seat[data-player="2"] { top: 8px; right: 5%; }
.seat[data-player="0"] { bottom: 36px; left: 50%; translate: -50%; }
.seat-avatar { position: relative; display: grid; place-items: center; inline-size: 48px; block-size: 48px; border: 1px solid var(--gc-theme-panel-line, #aac8b4); border-radius: 50%; pointer-events: auto; }
.seat.current .seat-avatar { outline: 2px solid var(--gc-theme-current, #edce7b); outline-offset: 2px; }
.seat .player-avatar-button { position: relative; min-block-size: 0; inline-size: 100%; block-size: 100%; padding: 0; border: 0; border-radius: 50%; background: transparent; color: inherit; font-weight: 750; }
.seat .player-avatar-button img { inline-size: 100%; block-size: 100%; border-radius: 50%; object-fit: cover; }
.seat .player-avatar-button > .player-avatar-portrait { object-fit: contain; }
.player-name, .quota, .table-prompt { border-radius: 7px; padding: 1px 5px; line-height: 1.2; }
.player-name { overflow: hidden; max-inline-size: 100%; text-overflow: ellipsis; white-space: nowrap; font-size: .8em; font-weight: 700; }
.quota { position: absolute; inset-inline-start: calc(50% + 20px); inset-block-start: 6px; min-inline-size: 42px; white-space: nowrap; font-size: .73rem; font-weight: 800; border: 1px solid var(--gc-theme-panel-line, #aac8b4); }
.hand-fan { display: flex; transform: translateX(8px); }
.mini-back { width: 20px; height: 28px; background: var(--card-back-pattern) var(--card-back-color); border: 1px solid var(--card-back-edge); border-radius: 4px; rotate: var(--tilt); transform-origin: center bottom; }
.mini-back + .mini-back { margin-inline-start: -16px; }
.felt { display: grid; place-items: center; inline-size: min(94%, 520px); block-size: 57%; margin-block-start: 7px; }
.table-prompt { align-self: end; grid-area: 1/1; margin: 0 5px 6px; text-align: center; font-size: clamp(.74rem, 3.1vw, .92rem); font-weight: 700; z-index: 0; }
.felt, .table-prompt { grid-area: 1/1; }
.trick { display: grid; direction: ltr; align-content: center; justify-content: center; grid-template: repeat(2, calc(var(--card-height) * .68)) / repeat(2, calc(var(--card-width) * .83)); pointer-events: none; }
.card { position: relative; display: grid; align-content: start; justify-items: start; inline-size: var(--card-width); block-size: var(--card-height); border: 1px solid #aeb6a8; border-radius: 6px; background: #fff9e9; color: #162f26; box-shadow: 0 2px 4px #0003; padding: 3px; font-size: clamp(.76rem, 3.3vw, 1rem); line-height: 1.02; }
.card span { font-size: 1.16em; }
.red { color: var(--red-suit); }
.trick .card[data-player="1"] { grid-area: 1/1; rotate: -13deg; }
.trick .card[data-player="2"] { grid-area: 1/2; rotate: 13deg; }
.trick .card[data-player="0"] { grid-area: 2/1/3/3; justify-self: center; rotate: 5deg; }
.trick .winning-card { z-index: 1; }
@media (orientation: portrait) {
  .felt { align-self: stretch; block-size: auto; margin-block: 74px 94px; }
  .felt:has(.trade-notice + .trade-notice, .trade-cards .card:nth-child(5)) { margin-block: 69px 38px; }
  .seat[data-player="0"] {
    bottom: 38px;
    width: min(80%, 300px);
    grid-template: repeat(2, 1fr) / minmax(0, 1fr) 48px minmax(0, 1fr);
    column-gap: 7px;
  }
  .seat[data-player="0"] .seat-avatar { grid-area: 1 / 2 / span 2; }
  .seat[data-player="0"] .player-name { grid-area: 1 / 3; align-self: end; justify-self: start; }
  .seat[data-player="0"] .quota { position: static; grid-area: 2 / 3; align-self: start; justify-self: start; }
  .trick { grid-template-rows: calc(var(--card-height) * .68) var(--card-height); }
}
.win-mark { position: absolute; bottom: 2px; right: 2px; display: grid; place-items: center; inline-size: 17px; block-size: 17px; border-radius: 50%; background: #f7db86; color: #25352a; }
.arriving { animation: lay-card .22s ease-out both; }
.arriving[data-player="1"] { --from-x: -46px; --from-y: -42px; }
.arriving[data-player="2"] { --from-x: 46px; --from-y: -42px; }
.arriving[data-player="0"] { --from-x: 0; --from-y: 40px; }
@keyframes lay-card { from { translate: var(--from-x) var(--from-y); opacity: .45; } }
@media (prefers-reduced-motion: reduce) { .arriving { animation: none; } }
#notices { z-index: 2; overflow: auto; max-block-size: 110px; max-inline-size: 81%; padding: 3px 5px; font-size: .82em; text-align: center; }
#notices:is(.kitty-reveal, .trade-reveal) { max-inline-size: 94%; max-block-size: none; overflow: visible; pointer-events: none; }
.notice { display: grid; gap: 3px; }
.notice + .notice { margin-block-start: 5px; padding-block-start: 4px; border-block-start: 1px solid currentColor; }
.kitty-cards, .trade-cards { justify-content: center; gap: 4px; direction: ltr; }
.kitty-cards { display: flex; }
.illustrated-face .face-corner { position: absolute; inset: 3px auto auto 3px; font-size: clamp(.55rem, calc(var(--card-width) * .23), .83rem); line-height: 1; }
.illustrated-face .face-opposite { inset: auto 3px 3px auto; rotate: 180deg; }
.face-artwork { position: absolute; inset: clamp(9px, calc(var(--card-width) * .29), 14px) 4px; }
.face-artwork img { display: block; inline-size: 100%; block-size: 100%; object-fit: contain; }
.face-pips { display: grid; grid-template: repeat(5, minmax(0, 1fr)) / repeat(3, minmax(0, 1fr)); place-items: center; }
.face-pips span { font-size: clamp(.35rem, calc(var(--card-width) * .17), .66rem); line-height: 1; }
.face-ace span { font-size: calc(var(--card-width) * .52); }
.trade-notice { line-height: 1.15; }
.trade-card-details { display: grid; grid-template-columns: auto minmax(0, 14ch); align-items: center; justify-content: center; gap: 4px 7px; }
.trade-card-details small { font-size: .83em; overflow-wrap: anywhere; }
.trade-cards { display: grid; grid-template-columns: repeat(min(4, var(--trade-count)), var(--card-width)); gap: 3px; }
.table:has(.trade-reveal:not([hidden])) .hand-fan,
.table:has(.trade-notice + .trade-notice, .trade-cards .card:nth-child(5)) .seat[data-player="0"] { visibility: hidden; }
.table:has(.trade-cards .card:nth-child(5), .trade-notice + .trade-notice) .seat .player-name { visibility: hidden; }
.hand-panel { padding: 6px 6px 9px; }
.actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; }
.actions:not(:empty) { margin-block-end: 6px; }
.suit-choice { min-inline-size: 44px; font-size: 1.36rem; line-height: 1.05; }
.hand { display: grid; direction: ltr; inline-size: min(100% - 4px, calc(var(--gaps) * (var(--card-width) - 7px) + var(--card-width))); margin-inline: auto; grid-template-columns: repeat(var(--gaps), minmax(0, 1fr)) var(--card-width); min-block-size: calc(var(--card-height) + 5px); align-content: center; }
.hand:has(> :only-child) { inline-size: var(--card-width); grid-template-columns: var(--card-width); }
.hand .card { min-block-size: 0; rotate: var(--tilt); translate: 0 var(--drop); transform-origin: center bottom; }
.hand .card:disabled { color: #53584f; background: #e6e3d8; opacity: 1; }
.hand .card.red:disabled { color: #704650; }
.hand .card:focus-visible { z-index: 1; outline-offset: -2px; }
.hand .card[aria-pressed="true"] { translate: 0 -3px; box-shadow: inset 3px 0 var(--accent), inset 0 2px var(--accent), 0 2px 4px #0003; }
.hand :is(.return-card, .received-card):disabled { background: var(--wash); color: var(--ink); box-shadow: inset 3px 0 var(--accent), inset 0 2px var(--accent), 0 2px 4px #0003; }
.hand :is(.return-card, .received-card).red:disabled { color: var(--red-suit); }
#score, #trick-history { margin-block: 5px; padding-inline: 9px; }
summary { font-weight: 700; }
#trick-history-list > details, .history-tricks > li { padding-block: 6px; border-block-start: 1px solid var(--line); }
#trick-history-list > details { margin-block-start: 6px; }
.history-tricks, .history-cards { list-style: none; margin: 0; padding: 0; }
.history-tricks { margin-block-start: 6px; }
.history-tricks p { margin: 0 0 4px; font-size: .85em; }
.history-cards { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 4px; }
.history-cards li { display: grid; justify-items: center; gap: 3px; min-inline-size: 0; text-align: center; font-size: .8em; }
.history-cards bdi { max-inline-size: 100%; overflow-wrap: anywhere; }
.history-cards .took-trick { font-weight: 750; }
.history-cards .card { inline-size: 32px; block-size: 44px; }
.history-cards .win-mark { inline-size: 13px; block-size: 13px; font-size: .72rem; }
table { inline-size: 100%; table-layout: fixed; border-collapse: collapse; font-size: .86em; }
th, td { padding: 5px 3px; text-align: end; overflow-wrap: anywhere; border-block-end: 1px solid var(--line); font-variant-numeric: tabular-nums; }
tr > :first-child { text-align: start; }
#metrics { display: grid; grid-template-columns: 1fr auto; gap: 8px; }
#metrics dd { margin: 0; font-weight: 700; }
dialog { max-inline-size: min(32rem, calc(100% - 24px)); inline-size: 100%; max-block-size: 90dvh; border: 1px solid var(--line); border-radius: 14px; background: var(--paper); color: var(--ink); padding: 14px; }
dialog::backdrop { background: #061a16a0; }
.dialog-heading { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-block-end: 10px; }
.dialog-heading h2 { margin: 0; }
#new-dialog .actions { justify-content: flex-end; }
.focus-game :is(.masthead, .game-footer, .game-install), .focus-game #my-progress { display: none; }
.focus-game main { padding-block-start: env(safe-area-inset-top); }
@media (orientation: portrait) {
  .focus-game .round-header { grid-template-columns: minmax(0, 1fr) auto; }
  .focus-game #dealer { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .focus-game .table {
    --reserved-height: 254px;
    block-size: clamp(255px, calc(100dvh - var(--reserved-height) - env(safe-area-inset-top) - env(safe-area-inset-bottom)), 470px);
  }
  .focus-game .table-shell:has(.actions:not(:empty)) .table { --reserved-height: 306px; }
}
@media (orientation: landscape) and (max-height: 500px) {
  .focus-game .game-toolbar { margin-block: 4px; }
  .focus-game .table-shell { display: grid; grid-template-columns: minmax(0, 1fr) clamp(195px, 36%, 240px); gap: 5px; }
  .focus-game .round-header { grid-column: 1 / -1; display: flex; flex-wrap: wrap; align-items: baseline; gap: 2px 9px; padding-block: 0 2px; }
  .focus-game .hand-panel { align-self: center; min-inline-size: 0; padding-inline: 3px; }
  .focus-game .actions { gap: 3px; }
  .focus-game .suit-choice { inline-size: 44px; padding-inline: 0; }
  .focus-game .hand { grid-template-columns: repeat(min(var(--gaps), 7), minmax(0, 1fr)) var(--card-width); row-gap: 6px; }
  .focus-game .hand .card { rotate: none; translate: none; }
  .focus-game .table { block-size: max(150px, calc(100dvh - 168px - env(safe-area-inset-top) - env(safe-area-inset-bottom))); }
  .focus-game .seat:not([data-player="0"]) { top: 5px; width: min(38%, 150px); grid-template: repeat(2, 1fr) / 48px minmax(0, 1fr); }
  .focus-game .seat:not([data-player="0"]) .seat-avatar { grid-row: 1 / span 2; }
  .focus-game .seat:not([data-player="0"]) .player-name { grid-row: 1; align-self: end; }
  .focus-game .seat:not([data-player="0"]) .quota { position: static; grid-row: 2; align-self: start; }
  .focus-game .seat[data-player="2"] { grid-template-columns: minmax(0, 1fr) 48px; }
  .focus-game .seat[data-player="2"] .seat-avatar { grid-column: 2; }
  .focus-game .seat[data-player="0"] { bottom: 26px; left: auto; right: 2%; width: min(21%, 110px); translate: none; }
  .focus-game .seats .hand-fan { display: none; }
  .focus-game .seat[data-player="0"] .quota { inset-inline: auto 0; inset-block-start: -3px; }
  .focus-game .felt { block-size: 67%; inline-size: 52%; }
  .focus-game .felt:has(.kitty-reveal:not([hidden]), .trade-reveal:not([hidden])) { inline-size: 57%; }
  .focus-game .felt:has(.trade-notice + .trade-notice, .trade-cards .card:nth-child(5)) { inline-size: 92%; margin-block-start: -8px; }
  .focus-game .table:has(.trade-notice + .trade-notice, .trade-cards .card:nth-child(5)) .seat { visibility: hidden; }
  .focus-game #notices.trade-reveal .trade-cards { grid-template-columns: repeat(var(--trade-count), var(--card-width)); }
  .focus-game #notices:has(.trade-notice + .trade-notice) { display: flex; align-items: start; gap: 5px; inline-size: 94%; }
  .focus-game .trade-notice { flex: var(--trade-count) 1 43px; min-inline-size: 0; grid-template-columns: minmax(0, 1fr); }
  .focus-game .trade-notice strong { font-size: .82em; }
  .focus-game .trade-reveal:has(.trade-notice + .trade-notice) .trade-notice bdi { display: block; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
  .focus-game .trade-notice + .trade-notice { margin: 0; padding: 0; border: 0; }
  .focus-game .trade-card-details { grid-template-columns: minmax(0, 1fr); }
  .focus-game { --card-width: clamp(27px, 5.2vw, 37px); --card-height: calc(var(--card-width) * 1.4); }
}
