:root {
  --bg: var(--palette-bg, #eeeee6);
  --ink: var(--palette-ink, #263b36);
  --paper: var(--palette-paper, #f4f4eb);
  --wash: var(--palette-wash, #e2ead9);
  --line: var(--palette-line, #ccd4c8);
  --accent: var(--palette-accent, #355e4c);
  --muted: var(--palette-muted, #58655b);
  --table-panel: var(--gc-theme-panel, #17352a);
  --table-current: var(--gc-theme-current, #8eaa9e);
  --table-line: var(--gc-theme-panel-line, #8eaa9e);
  --table-finished: color-mix(in srgb, var(--table-panel) 83%, var(--wash));
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.4 system-ui, sans-serif;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; }
.large { font-size: 1.14em; }
h1, h2, p { margin-block: 0 .5em; }
a { color: inherit; }
button, select {
  min-block-size: 44px; padding: .4rem .65rem; border: 1px solid var(--line);
  border-radius: 8px; background: var(--paper); color: var(--ink); font: inherit;
}
button { cursor: pointer; }
button:disabled { opacity: .65; cursor: default; }
button:focus-visible, select:focus-visible, a:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.primary { background: var(--palette-primary-bg, var(--accent)); color: var(--palette-primary-ink, white); font-weight: 700; }
.masthead, main, .game-footer { width: min(100% - 20px, 760px); margin-inline: auto; }
.masthead {
  padding-block: 12px; display: grid; grid-template-columns: 1fr auto; gap: 8px;
  align-items: center; border-block-end: 1px solid var(--line);
}
.masthead h1 { margin: 0; display: flex; align-items: center; gap: 8px; font: 700 clamp(1.6rem, 5vw, 2.1rem)/1 Georgia, serif; }
.masthead h1 img { border-radius: 8px; }
.accessibility { display: flex; align-items: center; gap: 6px; justify-content: end; }
.accessibility label { white-space: nowrap; }
.selectors, .setup { grid-column: 1 / -1; display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 8px; }
.selectors select, .setup select { width: 100%; min-width: 0; }
main { padding-block: 10px; }
#game-area {
  inline-size: 100%;
  padding-inline: max(10px, calc((100% - 760px) / 2));
}
.game-toolbar, .game-tools, .new-buttons { display: flex; align-items: center; }
.game-toolbar { gap: 5px; justify-content: space-between; margin-block: 6px 8px; }
.game-tools { justify-content: end; gap: 4px; min-inline-size: 0; }
.game-toolbar button { flex: 0 1 auto; min-inline-size: 42px; font-weight: 650; }
.new-buttons #new { border-start-end-radius: 0; border-end-end-radius: 0; }
#variants { display: grid; place-items: center; min-inline-size: 32px; padding: 0 6px; background: var(--wash);
  border-inline-start: 0; border-start-start-radius: 0; border-end-start-radius: 0; }
#variants i { width: 9px; height: 9px; border: solid currentColor; border-width: 0 2px 2px 0; transform: translateY(-2px) rotate(45deg); }
.compact { display: none; }
@media (max-width: 650px) {
  .game-toolbar .wide, #game-picker-button .toolbar-label { display: none; }
  .compact { display: inline; font-size: 1.25rem; }
  .game-toolbar .game-tools button { min-inline-size: 0; padding-inline: 5px; flex: 0 1 44px; }
  .game-toolbar .game-tools { flex: 1; }
}
@media (max-width: 410px) { .masthead { grid-template-columns: minmax(0,1fr) auto; } #contrast { font-size: .8rem; padding-inline: .4rem; max-inline-size: 126px; overflow-wrap: anywhere; } }
.game { border: 1px solid var(--line); border-radius: 16px; background: var(--paper); padding: 8px; }
.felt {
  --seat-height: 114px;
  --pile-height: 124px;
  position: relative; padding: 8px; display: grid;
  grid-template-rows: var(--seat-height) calc(var(--pile-height) + 3.5rem) var(--seat-height);
  background: var(--wash); color: #fff; border-radius: 12px;
}
/* Classic felt and colors from Osiem Asów. Other solid tables use the shared wash. */
:root[data-theme="classic"] {
  --bg: #e7eee5; --paper: #f7f5eb; --ink: #182d20; --muted: #496151;
  --accent: #225e3b; --line: #acbeae; --wash: #deebdd;
}
:root[data-theme="classic"] .felt {
  background: radial-gradient(ellipse at 50% 38%, #287846, #125032 78%);
}
:root[data-theme="tropics"] {
  --bg: #e4edf0; --paper: #f3f4eb; --ink: #152f42; --muted: #38596b;
  --accent: #184e77; --line: #9eb6bf; --wash: #dcebef;
}
:root[data-theme="beach"] {
  --bg: #ebddc5; --paper: #f7f2e7; --ink: #12363f; --muted: #3e5b60;
  --accent: #07586a; --line: #9eaeb0; --wash: #e7eee8;
}
:root:is([data-scenery="garden"], [data-scenery="tropics"], [data-scenery="beach"], [data-scenery="orange-grove"], [data-scenery="copper"], [data-scenery="starry-sky"]) {
  & #game-area, & .theme-preview .felt { background: var(--gc-scene-display) center / cover no-repeat var(--bg); }
  & .game { background: transparent; border-color: #ffffff60; }
  & #game-area .felt { background: transparent; }
}
#opponents { display: flex; justify-content: center; gap: clamp(4px, 2vw, 12px); }
#table {
  grid-template-rows: calc(var(--seat-height) + 18px) calc(var(--pile-height) + 3.5rem) var(--seat-height);
}
#opponents {
  --north-seat-offset: 18px;
  --side-seat-offset: calc(var(--north-seat-offset) + clamp(10px, 3vw, 18px));
}
#opponents > .seat { block-size: var(--seat-height); translate: 0 var(--north-seat-offset); }
#opponents:has(> .seat:nth-child(2)) {
  gap: clamp(8px, 2.5vw, 24px);
}
/* Leave the middle seat vacant in a three-player game. */
#opponents:has(> .seat:nth-child(2):last-child)::before {
  content: "";
  flex: 1;
  min-inline-size: 0;
  max-inline-size: 8rem;
  order: 1;
}
#opponents:has(> .seat:nth-child(2):last-child) > .seat:last-child { order: 2; }
#opponents:has(> .seat:nth-child(2)) > .seat:is(:first-child, :last-child) {
  max-inline-size: min(7.5rem, 30%);
}
#opponents:has(> .seat:nth-child(2)) > .seat:first-child { translate: 6px var(--side-seat-offset); }
#opponents:has(> .seat:nth-child(2)) > .seat:last-child { translate: -6px var(--side-seat-offset); }
.seat {
  flex: 1; min-width: 0; max-width: 8rem;
  display: grid; grid-template: "avatar" 32px "caption" 20px "fan" 26px "move" 32px / minmax(0, 1fr);
  justify-items: center; align-items: center; gap: 1px;
  text-align: center; color: #fff; font-size: .81rem;
}
.seat-avatar {
  grid-area: avatar; position: relative; display: grid; place-items: center;
  inline-size: 32px; block-size: 32px; border-radius: 50%;
  border: 1px solid var(--table-line); background: var(--table-panel); color: #fff;
  font-size: .92rem; font-weight: 750; isolation: isolate;
}
.seat.current .seat-avatar { outline: 2px solid var(--table-current); outline-offset: 2px; }
.seat.pan-loser .seat-avatar { border-color: #f2a4ab; }
.seat-caption {
  grid-area: caption; padding-inline: 4px 1px; border-radius: 10px;
  background: var(--table-panel); color: var(--gc-theme-panel-ink, #fff);
}
.seat > .last-move { grid-area: move; }
.seat > .hand-fan, #your-fan { grid-area: fan; }
.your-seat { grid-template-areas: "move" "avatar" "caption" "fan"; grid-template-rows: 32px 32px 20px 26px; }
/* Fan overlap and bottom pivot follow the Kierki table hands. */
.hand-fan {
  --fan-width: 20px;
  --fan-height: 26px;
  display: flex; justify-content: center; align-items: center;
  min-block-size: var(--fan-height); padding-inline: 6px;
}
.hand-fan > :is(.playing-card, .mini-back) {
  box-sizing: border-box; flex: none;
  inline-size: var(--fan-width); min-inline-size: var(--fan-width);
  block-size: var(--fan-height); min-block-size: var(--fan-height);
  border-radius: 5px; transform: rotate(var(--angle)); transform-origin: center bottom;
}
.hand-fan > * + * { margin-inline-start: calc(var(--fan-step) - var(--fan-width)); }
.hand-fan .playing-card { justify-items: start; align-content: start; padding: 2px; font-size: .65rem; }
.mini-back {
  border: 1px solid var(--card-back-edge, var(--table-line));
  background: var(--card-back-bg, var(--table-panel));
}
.card-count {
  position: absolute; inset-block-end: -3px; inset-inline-start: calc(100% - 5px);
  min-inline-size: 18px; padding-inline: 3px; border-radius: 10px;
  border: 1px solid var(--table-line); background: var(--paper); color: var(--ink);
  font: 750 .68rem/1.4 system-ui, sans-serif; white-space: nowrap;
}
.your-seat { justify-self: center; inline-size: min(100%, 8rem); }
.center { display: grid; justify-items: center; align-content: start; gap: 6px; padding-block-start: 6px; }
.pile-panel {
  position: relative; display: grid; inline-size: min(100%, 385px); block-size: var(--pile-height);
  border: 1px solid var(--table-line); border-radius: 8px; background: var(--table-panel); color: #fff;
}
/* The playing surface is the central panel beneath the pile. */
#table .pile-panel {
  border: 1px solid var(--table-line);
  border-radius: 42% / 49%;
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
}
#table .pile-panel::before {
  content: "";
  position: absolute;
  inset: 7px;
  border: 1px solid var(--table-line);
  border-radius: inherit;
  opacity: .62;
  pointer-events: none;
}
:root:not([data-theme="contrast"]) #table .pile-panel {
  background-image: repeating-linear-gradient(45deg, #ffffff08 0 1px, transparent 1px 5px);
  border-color: color-mix(in srgb, var(--table-line) 65%, var(--table-panel));
  box-shadow:
    inset 0 1px 2px #ffffff45,
    inset 0 0 0 6px color-mix(in srgb, var(--table-panel) 78%, black),
    inset 0 0 9px 7px #0004,
    0 2px 3px #0003;
}
#pile {
  border-radius: inherit;
  display: grid; grid-template-rows: 1fr auto; align-items: center; justify-items: center; gap: 4px; padding: 5px 9px;
  border: 0; background: transparent; color: inherit; font-size: .78rem;
}
.pile-panel:has(#pile-preview:not([hidden])) #pile-cards { visibility: hidden; }
.pile-panel:has(#pile-preview:not([hidden])) #pile-caption { align-self: end; }
#pile-preview {
  position: absolute; inset: 2px 4px 22px; z-index: 1;
  display: flex; flex-wrap: wrap; justify-content: center; align-content: center;
  padding: 0 14px 26px 0; margin: 0; list-style: none; pointer-events: none;
}
#pile-preview li { flex: 0 0 21.8px; block-size: 23px; min-inline-size: 0; }
@media (max-width: 319px) {
  .felt { --pile-height: 147px; }
}
#pile.waiting .playing-card { opacity: .8; }
#status { margin: 0; max-block-size: 2.75rem; overflow: auto; padding: 4px 9px; background: var(--gc-theme-panel, var(--table-panel)); color: #fff; border-radius: 8px; font-size: .86rem; text-align: center; }
.controls { padding-block-start: 8px; overflow-anchor: none; }
.last-move { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 2px; min-block-size: 23px; font-size: .72rem; }
#table .last-move { align-content: center; align-self: stretch; inline-size: 100%; min-inline-size: 0; }
#table .taken-label { background: var(--table-panel); color: var(--gc-theme-panel-ink, #fff); border-radius: 6px; line-height: 1.18; inline-size: 100%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#table button.taken-label {
  min-block-size: 22px; padding: 0 2px;
  border: 1px solid var(--table-line); color: var(--gc-theme-panel-ink, #fff); background: var(--table-panel);
}
#taken-list { display: flex; flex-wrap: wrap; gap: 4px; margin: 0; padding: 0; list-style: none; }
.last-move .playing-card { min-inline-size: 19px; min-block-size: 20px; padding: 1px 2px; }
.shared-settings .pace-row { display: grid; grid-template-columns: minmax(0, 1fr) auto auto; gap: 6px; }
.shared-settings .pace-row select { min-inline-size: 0; max-inline-size: min(100%, 12rem); padding-inline: 4px; }
@media (max-width: 360px) {
  .shared-settings .pace-row { grid-template-columns: minmax(0, 1fr) auto; }
  .shared-settings .pace-row select { grid-row: 2; grid-column: 1 / -1; max-inline-size: 100%; }
}

.controls {
  --hand-width: clamp(36px, 10.7vw, 42px);
  --hand-height: calc(var(--hand-width) * 1.4);
  --step: clamp(0px, calc((100% - var(--hand-width) - 6px) / var(--gaps)), var(--hand-width));
}
#hand {
  display: flex; justify-content: center; align-items: flex-start;
  min-block-size: calc(var(--hand-height) + 14px);
  padding-block: 3px 11px;
}
.playing-card {
  min-inline-size: 36px; min-block-size: 49px; padding: 3px; display: inline-grid; place-items: center;
  border-radius: 6px; border: 1px solid #aab8a9; background: #fffbec; color: #142c22; font-weight: 750;
}
.playing-card.red { color: #a31b3b; }
#hand .playing-card {
  position: relative; flex: 0 0 var(--hand-width); min-inline-size: 0;
  block-size: var(--hand-height); justify-items: start; align-content: start;
  padding: 5px 0 0 4px; gap: 2px; border-radius: 7px; line-height: 1;
  transform: translateY(var(--drop)); box-shadow: 0 2px 4px #1a2d2440;
  background: linear-gradient(#fffdf7, #f4ecda);
}
#hand .playing-card + .playing-card { margin-inline-start: calc(var(--step) - var(--hand-width)); }
#hand .playing-card span:last-child { font-size: 1.12em; }
#hand .playing-card:enabled {
  border-color: var(--accent); box-shadow: 0 2px 4px #1a2d2440, inset 0 -3px var(--accent);
  touch-action: manipulation;
}
#hand .playing-card:disabled { background: #e8e3d9; color: #555c55; opacity: 1; }
#hand .playing-card.red:disabled { color: #804b54; }
#hand .playing-card:focus-visible { z-index: 1; }
#pile-caption:has(#pile-cue:not([hidden])) #pile-count { display: none; }
.pile-panel:has(#pile-preview:not([hidden]), #move-choices:not([hidden])) #pile-caption #pile-count { display: inline; }
.pile-panel:has(#pile-preview:not([hidden]), #move-choices:not([hidden])) #pile-caption #pile-cue { display: none; }
#pile-cue { font-weight: 750; }
.controls:has(#hand:not(.empty-hand)) {
  display: grid;
  grid-template-rows: 50px auto;
}
#quartet-shortcuts { position: relative; grid-row: 1; }
#hand { grid-row: 2; }
.quartet-shortcut {
  position: absolute;
  top: 0;
  left: calc(50% + var(--group-offset) * var(--step));
  translate: -50% 0;
  direction: ltr;
  white-space: nowrap;
  min-inline-size: 44px;
  padding: 2px 8px;
}
.quartet-shortcut::before, .quartet-shortcut::after {
  content: "";
  position: absolute;
  inset-inline-start: 50%;
  translate: -50% 0;
  pointer-events: none;
  clip-path: polygon(0 0, 100% 0, 50% 100%);
}
.quartet-shortcut::before {
  top: 100%;
  inline-size: 13px;
  block-size: 6px;
  background: var(--draw-edge);
}
.quartet-shortcut::after {
  top: calc(100% - 1px);
  inline-size: 11px;
  block-size: 6px;
  background: var(--draw-bubble);
}
@media (max-width: 400px) {
  .controls:has(#hand.dense-hand) { grid-template-rows: 100px auto; }
  #quartet-shortcuts.staggered .quartet-shortcut { top: calc(var(--group-row) * 50px); }
}
#hand.empty-hand { min-block-size: 0; padding: 0; }
@media (max-width: 480px) {
  #hand.dense-hand .playing-card { padding-inline-start: 2px; font-size: .78rem; }
  #hand.packed-hand .playing-card { padding-inline-start: 1px; font-size: .64rem; }
}
#move-choices {
  display: grid;
  position: absolute;
  top: 4px;
  left: calc(50% + var(--pile-half-width, 18px) + 6px);
  z-index: 2;
  inline-size: min(78px, calc(50% - var(--pile-half-width, 18px) - 10px));
}
:is(#move-choices, .quartet-shortcut) {
  --draw-bubble: color-mix(in srgb, var(--table-panel) 90%, white);
  --draw-edge: color-mix(in srgb, var(--table-line) 55%, var(--draw-bubble));
  color: var(--gc-theme-panel-ink, #fff);
  background: var(--draw-bubble);
  border: 1px solid var(--draw-edge);
  border-radius: 12px;
}
#move-choices::before, #move-choices::after {
  content: "";
  position: absolute;
  pointer-events: none;
  top: 50%;
  translate: 0 -50%;
  clip-path: polygon(0 50%, 100% 3%, 100% 97%);
}
#move-choices::before {
  left: -7px;
  inline-size: 7px;
  block-size: 15px;
  background: var(--draw-edge);
}
#move-choices::after {
  left: -5px;
  inline-size: 6px;
  block-size: 13px;
  background: var(--draw-bubble);
}
#move-choices button {
  min-inline-size: 0;
  border: 0;
  border-radius: 10px;
  padding: 2px 4px;
  background: transparent;
}
:is(#move-choices button, .quartet-shortcut) {
  min-block-size: 44px;
  cursor: pointer;
  color: var(--gc-theme-panel-ink, #fff);
  font-size: .74rem;
  font-weight: 700;
  line-height: 1.15;
  overflow-wrap: anywhere;
  touch-action: manipulation;
}
@media (pointer: fine) {
  #move-choices button { min-block-size: 36px; }
}
#move-choices button + button { box-shadow: 0 -1px var(--draw-edge); }
:is(#move-choices button, .quartet-shortcut):focus-visible { outline: 2px solid currentColor; outline-offset: -3px; }
:is(#move-choices button, .quartet-shortcut):active { background: color-mix(in srgb, var(--draw-bubble) 90%, black); }
:root[data-theme="contrast"] :is(#move-choices, .quartet-shortcut) { --draw-bubble: #111; --draw-edge: #fff; }
dialog { width: min(460px, calc(100% - 24px)); max-block-size: 88dvh; border: 1px solid var(--line); border-radius: 12px; background: var(--paper); color: var(--ink); padding: 16px; }
dialog::backdrop { background: #101e1bb0; }
.dialog-heading { display: flex; justify-content: space-between; gap: 8px; align-items: center; margin-block-end: 12px; }
.dialog-heading h2 { margin: 0; font-size: 1.3rem; }
.dialog-heading button { min-inline-size: 44px; font-size: 1.3rem; }
.setup { margin-block-end: 12px; }
#game-area.expanded { position: fixed; inset: 0; width: 100%; overflow: auto; z-index: 5; background: var(--bg); padding: max(8px, env(safe-area-inset-top)) max(8px, env(safe-area-inset-right)) max(8px, env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left)); }
.expanded > :is(.game, .game-toolbar) { max-width: 760px; margin-inline: auto; }
.expanded #my-progress { display: none; }
.game-footer { margin-block: 14px; }

.pile-panel, #pile * { -webkit-tap-highlight-color: transparent; }
#pile { -webkit-tap-highlight-color: transparent; touch-action: none; user-select: none; -webkit-touch-callout: none; }
#pile-cards { display: flex; --card-width: 36px; }
.table-card {
  inline-size: 36px; block-size: 49px; flex: none;
  justify-items: start; align-content: start; padding: 2px;
  font-size: .77rem; line-height: 11px;
}
#pile-cards .playing-card + .playing-card { margin-inline-start: calc(1px - var(--card-width)); }
.seat-caption { display: flex; max-inline-size: 100%; min-inline-size: 0; align-items: center; justify-content: center; gap: 2px 5px; }
.seat-caption strong { min-inline-size: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#move-history { padding: 8px; margin-block: 8px; border: 1px solid var(--line); border-radius: 8px; background: var(--paper); }
#move-history summary { cursor: pointer; font-weight: 700; }
#history-list { margin-block: 6px 0; padding: 0; list-style: none; }
#history-list li { display: flex; justify-content: space-between; align-items: center; gap: 6px; border-block-start: 1px solid var(--line); padding: 5px; }
#player-name-input {
  display: block; inline-size: 100%; min-block-size: 44px; margin-block: 4px 12px;
  color: inherit; background: var(--paper); border: 1px solid var(--line);
  border-radius: 6px; font: inherit; padding-inline: 8px;
}
.edit-name {
  position: relative; flex: none; inline-size: 23px; min-block-size: 22px;
  padding: 0; border: 0; background: transparent; color: inherit; line-height: 1;
}
.edit-name::after { content: ""; position: absolute; inset: -11px 0 0; }
.seat-caption { gap: 2px 3px; }

:root[data-theme="contrast"] {
  & #contrast[aria-pressed="true"] { background: #111; color: #fff; }
  & .felt { background: #fff; color: #111; box-shadow: inset 0 0 0 2px #111; }
  & .pile-panel, & #status { background: #111; color: #fff; border-color: #111; }
  & .seat.current .seat-avatar { outline-color: #111; }
  & .card-count { background: #fff; color: #111; border-color: #111; }
  & #table button.taken-label { border-color: currentColor; }
  & :is(#pile, .edit-name, #table button.taken-label):focus-visible {
    outline-color: currentColor;
    outline-offset: -2px;
  }
  & .mini-back { border-color: currentColor; }
  & .playing-card { background: #fff; border-color: #111; color: #111; }
  & .playing-card.red { color: #8c001a; }
  & #hand .playing-card { background: #fff; }
  & #hand .playing-card:disabled { background: #eaeaea; color: #555; }
  & #hand .playing-card:not(:disabled) { border-color: #111; box-shadow: inset 0 -3px #111; }
}

#match-result {
  margin-block-start: 8px; padding: 10px 12px;
  border: 1px solid var(--line); border-radius: 10px; background: var(--paper); color: var(--ink);
}
#match-result h3 { margin: 0 0 4px; font-size: 1rem; }
#match-result p { margin: 0; }
#match-result-winner, .pan-result { font-weight: 700; }
.card-count.pan-loser-label { background: #591d28; color: #fff; border-color: #f2a4ab; }
:root[data-theme="contrast"] .card-count.pan-loser-label { background: #111; color: #fff; border-color: #fff; }

@media (prefers-reduced-motion: no-preference) {
  .pan-loser-label {
    animation: pan-result-pulse 750ms ease-in-out 3;
  }
}
@keyframes pan-result-pulse {
  50% { transform: scale(1.12); box-shadow: 0 0 0 4px #f2a4ab50; }
}
