:root {
  color-scheme: dark;
  --surface: #141b45;
  --surface-deep: #141c46;
  --glass: rgb(12 18 52 / .62);
  --slot: rgb(10 16 48 / .5);
  --slot-line: rgb(190 202 255 / .42);
  --slot-mark: rgb(190 202 255 / .5);
  --panel: rgb(14 20 56 / .95);
  --on-scene: var(--text);
  --on-scene-target: var(--target);
  --scene-shadow: rgb(5 8 26 / .9);
  --line: #7f90cf;
  --text: #f2f6fb;
  --muted: #c3d3e6;
  --action: #f2bd4e;
  --on-action: #16243f;
  --target: #8fe3d2;
  --heading: Rockwell, "Roboto Slab", "Rockwell Nova", "Bookman Old Style", serif;
  font: 16px/1.5 "Avenir Next", Avenir, "Segoe UI", "Helvetica Neue", sans-serif;
  color: var(--text);
  background: var(--surface);
}
*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; height: 100dvh; display: flex; flex-direction: column; overflow: hidden; }
a { color: inherit; text-underline-offset: .22em; }
h1, h2, p, ul, ol { margin: 0; }
h1 { font: 700 1.4rem/1.2 var(--heading); }
h2 { font: 700 1.1rem/1.3 var(--heading); margin-bottom: .5rem; }
:focus-visible { outline: 3px solid var(--action); outline-offset: 2px; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }

.bar { display: flex; flex-wrap: wrap; align-items: center; gap: .4rem .7rem; padding: .45rem clamp(.5rem, 1.4vw, 1.2rem); background: var(--glass); border-bottom: 1px solid rgb(255 255 255 / .1); }
.bar form, .turn { display: flex; align-items: center; gap: .5rem; }
.game-record-bar, .current-game-number {
  display: flex; flex-wrap: wrap; align-items: center; gap: .25rem .5rem;
}
.game-record-bar {
  padding: .3rem clamp(.5rem, 1.4vw, 1.2rem); background: var(--glass);
  border-bottom: 1px solid rgb(255 255 255 / .1); font-size: .875rem;
}
.game-record-bar button { min-height: 2rem; padding: .15rem .5rem; }
#current-number {
  min-width: 4ch; max-width: 22ch; padding: .2rem .4rem; font: inherit;
  color: var(--text); background: var(--surface-deep); border: 1px solid var(--line); border-radius: .3rem;
}
#deal-timer {
  padding: .12rem .5rem; font-variant-numeric: tabular-nums;
  border: 1px solid var(--slot-line); border-radius: .3rem;
}
#number-notice:empty { display: none; }
#number-notice, #records-summary { color: var(--muted); }
.game-bests { color: var(--target); font-variant-numeric: tabular-nums; }
main { position: relative; flex: 1; min-height: 0; display: flex; }

button, select { font: inherit; font-weight: 600; color: inherit; background: var(--surface-deep); border: 1px solid var(--line); border-radius: .35rem; min-height: 2.6rem; padding: .3rem .8rem; }
button { cursor: pointer; }
button:disabled { cursor: default; opacity: .5; }
#deal { background: var(--action); border-color: var(--action); color: var(--on-action); }
#moves { font-variant-numeric: tabular-nums; margin-inline-end: .4rem; }
/* Notices share the bar, so they never cover a card or change the table's size. */
.notices { flex: 1 1 0; min-width: 0; min-height: 2.6rem; display: flex; justify-content: center; align-items: center; gap: .8rem; }
#status, #prospects, #coop-state { min-width: 0; font-weight: 600; text-align: center; line-height: 1.25; overflow: hidden; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; }
#status:empty, #prospects:empty, #prospects:has(+ #status:not(:empty)) { display: none; }
#coop-state { display: block; color: var(--target); overflow-wrap: anywhere; }
#coop-turn:not(:empty) + #coop-partner::before { content: '·'; margin-inline: .25em; }
#prospects { color: var(--target); }
#solved { flex: none; }
#welcome { position: absolute; inset: 0; display: grid; place-items: center; text-align: center; font: 700 1.5rem/1.3 var(--heading); color: var(--on-scene); text-shadow: 0 2px 12px var(--scene-shadow); }
#finish { background: var(--action); border-color: var(--action); color: var(--on-action); padding-inline: 1.2rem; white-space: nowrap; animation: solved 1.6s ease-in-out infinite; }
@keyframes solved { 50% { box-shadow: 0 0 0 .5rem rgb(242 189 78 / .28); } }
@media (prefers-reduced-motion: reduce) { #finish { animation: none; } }

#game-choices { display: grid; gap: .5rem; min-width: 16rem; }
#game-choices button { display: flex; justify-content: space-between; align-items: center; }
.key { display: none; position: absolute; inset: auto 0 100%; text-align: center; font-size: .75rem; line-height: 1.4; color: var(--on-scene); text-shadow: 0 1px 4px var(--scene-shadow); pointer-events: none; }
.column > .key { top: auto; }
@media (hover: hover) and (pointer: fine) {
  html[data-shortcuts="on"] .key { display: block; }
}
@media (hover: none) and (pointer: coarse) { #shortcuts { display: none; } }
.target > .key { color: var(--on-scene-target); font-weight: 700; }
#table { --card: 60px; --gap: 6px; --fan: 24px; flex: 1; min-width: 0; overflow: hidden auto; padding: 1.5rem clamp(.35rem, 1.2vw, 1rem) .8rem; touch-action: pan-y; }
#table[data-game="klondike"] { --columns: 7; }
#table[data-game="spider"] { --columns: 10; }
#table[data-game="freecell"] { --columns: 8; }
.tops, .columns { display: grid; grid-template-columns: repeat(var(--columns), var(--card)); gap: var(--gap); justify-content: center; }
.tops { margin-bottom: 1.6rem; }
.homes { grid-column: 4 / -1; display: grid; grid-template-columns: repeat(4, var(--card)); gap: var(--gap); }
#table[data-game="spider"] .homes { grid-column: 3 / -1; grid-template-columns: repeat(8, var(--card)); }
/* FreeCell: four free cells on the left of the top row and the foundations on the right. */
.cells { grid-column: 1 / span 4; display: grid; grid-template-columns: repeat(4, var(--card)); gap: var(--gap); }
#table[data-game="freecell"] .homes { grid-column: 5 / -1; }
.pile { position: relative; min-width: 0; aspect-ratio: 5 / 7; border-radius: .5rem; }
.column { aspect-ratio: auto; min-height: 100%; }
.column > .card, .column > .spot, .waste > .spot { position: absolute; inset-inline: 0; }
.column > * { top: calc((var(--below-down, 0) * .4 + var(--below-up, 0)) * var(--fan)); }
.waste > .spot { left: calc(var(--below-up, 0) * 27%); }
#table[data-game="klondike"] .waste { z-index: 1; }

.spot { display: block; width: 100%; min-height: 0; padding: 0; border: 0; background: none; border-radius: 8% / 5.7%; position: relative; }
/* Other cards leave a swipe free to scroll the page. */
.movable { touch-action: none; }
.spot:disabled { opacity: 1; }
card-art > .card-dance { position: absolute; inset: 0; width: 100%; height: 100%; }
card-art.dancing > svg { visibility: hidden; }
.spot .card { box-shadow: 0 2px 5px rgb(4 8 28 / .45); }
.slot { aspect-ratio: 5 / 7; border: 2px solid var(--slot-line); background: var(--slot); color: var(--slot-mark); display: grid; place-items: center; container-type: inline-size; }
.slot > .suit-mark { width: 45cqi; height: 45cqi; fill: currentColor; }
.stock .caption { position: absolute; inset: auto 22% 8%; text-align: center; font-size: .8rem; line-height: 1.2; background: var(--surface-deep); color: var(--text); border-radius: .25rem; padding: .1rem; }
.stock.slot .caption { position: static; margin: 0; background: none; font-size: 1.4rem; }
.stock .spot { touch-action: manipulation; }
.stock .spot[aria-disabled="true"] { cursor: default; }
.chosen .card { outline: 3px solid var(--action); outline-offset: -3px; }
.can-move::after, .can-split::after, .target > .spot:last-of-type::after,
.could > .spot:last-of-type::after, .could-split > .spot:last-of-type::after {
  content: '';
  position: absolute;
  inset: -2px;
  border: 2px solid #a9fff0;
  border-radius: inherit;
  box-shadow: 0 0 0 2px #111a23, inset 0 0 0 1px #111a23;
  pointer-events: none;
}
.could > .spot:last-of-type::after { border-color: #ffe283; }
.can-split::after, .could-split > .spot:last-of-type::after { border-color: #f3f6f9; border-style: dashed; }
.over > .spot:last-of-type::after { border-color: #fff; box-shadow: 0 0 0 2px #111a23, 0 0 0 4px #a9fff0; }
.home > .spot, .cell > .spot { position: absolute; inset: 0; }
.replaying { pointer-events: none; }
/* A card on its way is not what a press meant: the press goes to the card beneath. */
.moving { z-index: 3; pointer-events: none; }
.pile:has(.moving) { z-index: 4; }
.lifted { opacity: .3; }
.ghost { position: fixed; inset: 0; z-index: 10; pointer-events: none; }
.ghost .card { box-shadow: 0 8px 18px rgb(10 22 45 / .45); }
#table:not([data-status="active"]) .spot { cursor: default; }

#panel { position: fixed; inset: 0 auto 0 0; width: min(27rem, 94vw); height: 100dvh; max-width: none; max-height: none; margin: 0; padding: 0; border: 0; border-inline-end: 1px solid var(--line); border-radius: 0; background: var(--panel); overflow-y: auto; }
#panel[open] { animation: panel .2s ease-out; }
@keyframes panel { from { transform: translateX(-100%); } }
@media (prefers-reduced-motion: reduce) { #panel[open] { animation: none; } }
.panel { display: grid; gap: 1.6rem; padding: 1rem 1.2rem 2rem; }
.panel-head { display: flex; justify-content: space-between; align-items: center; }
.panel-head h2 { margin: 0; font-size: 1.4rem; }
.options { display: grid; grid-template-columns: 1fr 1fr; gap: .5rem; align-items: center; }
.panel section > p, #rules p { color: var(--muted); margin-bottom: .5rem; }
.panel p:empty { display: none; }
.panel footer, .panel nav { display: flex; gap: 1rem; justify-content: space-between; }
.panel [aria-current="page"] { font-weight: 700; text-decoration: none; }
#deal-list { list-style: none; padding: .2rem; display: grid; gap: .35rem; max-height: 19rem; overflow-y: auto; }
#deal-list button { width: 100%; display: flex; flex-wrap: wrap; justify-content: space-between; gap: 0 .8rem; text-align: start; }
#deal-list button span:last-child { font-weight: 400; color: var(--muted); }
#deal-list button[aria-current="true"] { border-color: var(--action); }
#leaders { padding-inline-start: 1.5rem; font-variant-numeric: tabular-nums; }
#leaders:empty { display: none; }
#older { margin-top: .5rem; }

dialog { background: var(--surface-deep); color: inherit; border: 1px solid var(--line); border-radius: .6rem; padding: 1.4rem; max-width: 24rem; }
#designs { width: min(52rem, calc(100vw - 1.5rem)); max-width: none; }
.theme-preview { position: relative; display: flex; justify-content: center; align-items: center; gap: .4rem; width: 100%; height: 7.2rem; border-radius: .4rem; overflow: hidden; }
.theme-preview canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.theme-preview .card { position: relative; flex: none; width: 64px; box-shadow: 0 2px 6px rgb(0 0 0 / .5); }
.backdrop-preview { height: 5.2rem; }
.sound-mark { font-size: 1.6rem; line-height: 1; }
#own > summary { cursor: pointer; padding: .4rem 0 .8rem; font-weight: 700; }
dialog::backdrop { background: rgb(10 22 45 / .6); }
.choices { display: flex; gap: .5rem; justify-content: flex-end; margin-top: 1rem; }
.multiplayer-choices { display: grid; gap: .5rem; }
.multiplayer-choices button:not(:last-child) { display: grid; text-align: start; padding: .65rem .8rem; }
.multiplayer-choices button span { font-weight: 400; color: var(--muted); }
.multiplayer-choices button:last-child { justify-self: end; }
.listing-choice { display: flex; align-items: center; gap: .35rem; padding-block: .3rem; }
#open-games { background: var(--glass); border-bottom: 1px solid rgb(255 255 255 / .1); padding-inline: clamp(.5rem, 2vw, 1.2rem); }
#open-games summary { width: fit-content; padding-block: .35rem; cursor: pointer; font-weight: 600; }
.open-games-body { display: grid; gap: .35rem; padding-bottom: .5rem; }
.open-games-actions { display: flex; flex-wrap: wrap; gap: .35rem; }
.open-games-actions button, #rematch, #restart-race { min-height: 2rem; font-size: .875rem; }
#open-status, #rematch-status, #restart-status, #restart-dialog-status, #restart-seed-note { color: var(--muted); font-size: .875rem; }
#open-status:empty, #open-list:empty, #rematch-status:empty, #restart-status:empty, #restart-dialog-status:empty { display: none; }
#open-list { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(17rem, 100%), 1fr)); gap: .35rem;
  list-style: none; padding: .2rem; max-height: min(8rem, 20dvh); overflow: auto; }
#open-list button { display: flex; align-items: center; justify-content: space-between; gap: .55rem; width: 100%; text-align: start; }
#open-list button > span:first-child { overflow-wrap: anywhere; }
#open-list button > span:last-child { color: var(--target); }
#race-progress { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: .3rem 1rem; padding: .3rem .5rem;
  background: var(--glass); color: var(--on-scene); font-size: .875rem; overflow-wrap: anywhere; }
.race-counts, #race-score, #rematch-controls, #restart-controls { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: .15rem .75rem; }
.restart-choices { flex-wrap: wrap; }
#race-score { padding: .15rem .5rem; border: 1px solid var(--slot-line); border-radius: .35rem; }
#race-score > span:first-child { font-weight: 600; }
#race-progress strong { margin-inline-start: .25rem; font-variant-numeric: tabular-nums; }
#race-result { color: var(--on-scene-target); }
#race-result:empty { display: none; }
#invite-url { width: 100%; margin-block: .8rem .3rem; padding: .45rem; font: inherit; }
#invite-status, #share-status { color: var(--target); }
#deal-list li { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: .35rem; }
#deal-history, #seed-tool { width: min(32rem, calc(100vw - 1rem)); max-width: none; max-height: min(80dvh, 45rem); }
#game-records { width: min(60rem, calc(100vw - 1rem)); max-width: none; padding: clamp(.75rem, 3vw, 1.4rem); }
.records-nav { padding-block-end: .65rem; border-bottom: 1px solid var(--slot-line); }
.records-nav [aria-current="page"] { border-color: var(--target); color: var(--target); }
.records-controls { margin-block: .65rem 0; }
#records-summary:empty, #records-status:empty { display: none; }
#records-summary, #records-status, #records-older { margin-block-start: .75rem; }
.records-table-wrap { overflow-x: auto; margin-block-start: .5rem; }
#records-table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
#records-table :is(th, td) {
  padding: .45rem; text-align: start; border-bottom: 1px solid var(--slot-line); white-space: nowrap;
}
#records-table td button {
  background: none; border: 0; min-height: 2rem; padding: .05rem .25rem; max-width: 20ch;
  color: var(--target); text-decoration: underline; overflow: hidden; text-overflow: ellipsis;
}
#records-table td small { display: block; color: var(--muted); }
#records-table .record-resume { margin-inline-start: .25rem; }
.record-badges { display: flex; flex-wrap: wrap; gap: .2rem; }
.record-badges strong {
  padding: 0 .35rem; color: var(--action);
  border: 1px solid currentColor; border-radius: .3rem; font-size: .75rem;
}
.tool-heading, .tool-actions, .seed-line { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem; }
.tool-heading { justify-content: space-between; margin-bottom: .75rem; }
.tool-heading h2, .tool-section h3 { margin: 0; }
.tool-section { display: grid; gap: .35rem; margin-block: .75rem; }
.seed-line { flex-wrap: nowrap; }
.seed-line input { flex: 1; min-width: 0; }
#history-seed, #seed-entry { width: 100%; padding: .4rem; font: inherit; }
#records-number { max-width: 100%; padding: .4rem; font: inherit; }
#records-number-status:empty { display: none; }
#history-actions { max-height: 12rem; overflow: auto; padding-inline-start: 2rem; }
#history-seed-status, #seed-tool-note, #bot-search-details { color: var(--muted); }
#bot-result-actions { margin-top: .55rem; }
#bot-playback { display: flex; align-items: center; justify-content: center; gap: .65rem;
  padding: .25rem .5rem; background: var(--glass); color: var(--on-scene); }
#bot-playback button { min-height: 2rem; }

@media (max-width: 72rem) {
  .bar h1 { display: none; }
}
@media (max-width: 64rem) {
  /* Keeps the record bar to one row beside a short table. */
  .current-game-number label { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
}
/* Phones. app.js uses the same query to move the other controls into the menu. */
@media (max-width: 48rem), (max-height: 30rem) {
  .bar { gap: .45rem .5rem; padding: .4rem .5rem; }
  .bar form { order: 1; flex: 1 1 calc(100% - 6.5rem); min-width: 0; margin: 0; }
  /* iOS zooms into a smaller select. */
  #variant { flex: 1; min-width: 0; padding-inline: .45rem; font-size: 1rem; text-overflow: ellipsis; }
  .bar button { padding-inline: .65rem; font-size: .9rem; white-space: nowrap; }
  .turn { display: contents; }
  #progress { order: 2; display: flex; align-items: center; gap: .6rem; white-space: nowrap; }
  #progress > * { font-size: .875rem; }
  #progress > #moves { margin: 0; }
  #progress > #deal-timer { padding: 0; border: 0; color: var(--muted); }
  .notices { order: 3; flex: 1 1 0; gap: .5rem; justify-content: flex-start; }
  #status, #prospects, #coop-state { font-size: .85rem; line-height: 1.15; text-align: start; -webkit-line-clamp: 3; }
  #undo { order: 4; }
  #collect { order: 5; }
  /* A notice takes the place of the progress, and a partner's takes a row of its own. */
  .bar:has(#status:not(:empty), #solved:not([hidden])) #progress { display: none; }
  .bar:has(#status:not(:empty), #solved:not([hidden])) .notices { flex-basis: 5.5rem; }
  .notices:has(#solved:not([hidden])) #status { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
  .bar:has(#reconnect:not([hidden])) :is(#undo, #collect) { display: none; }
  .bar:has(#coop-state:not([hidden])) .notices { order: 6; flex-basis: 100%; min-height: 1.5rem; }
  .bar:has(#coop-state:not([hidden])) #progress { display: flex; flex: 1; }
  #race-progress, #bot-playback { padding-block: .15rem; }
  #game-records { padding: .85rem; }
}
@media (max-width: 30rem) {
  .bar:has(#prospects:not(:empty)) #deal-timer { display: none; }
}
@media (max-height: 30rem) {
  .bar { flex-wrap: nowrap; font-size: .875rem; padding-block: .25rem; }
  .bar:has(#coop-state:not([hidden])) { flex-wrap: wrap; }
  .bar :is(button, select) { min-height: 2.4rem; padding: .2rem .6rem; }
  .bar form { flex: 0 1 18rem; }
  .notices { min-height: 2.4rem; }
}
#panel-tools:empty { display: none; }
#panel-tools, #panel-tools .game-record-bar { display: grid; gap: .5rem; }
#panel-tools .game-record-bar { grid-template-columns: 1fr 1fr; padding: 0; background: none; border: 0; }
#panel-tools .game-record-bar button { min-height: 2.6rem; }
#panel-tools .current-game-number { grid-column: 1 / -1; }
#panel-tools #current-number { flex: 1; min-width: 0; min-height: 2.6rem; }
#panel-tools :is(.game-bests, #number-notice) { grid-column: 1 / -1; }
#panel-tools #open-games { padding: 0; background: none; border: 0; }

/* Table on a phone's side: stock and waste, columns, then foundations. */
#table[data-layout="side"] { display: grid; grid-template: auto auto 1fr / var(--card) auto auto; gap: .4rem var(--gap); justify-content: center; padding-block: .5rem .4rem; }
[data-layout="side"] .tops { display: contents; }
[data-layout="side"] .stock.pile { grid-area: 1 / 1; }
[data-layout="side"] .waste { grid-area: 2 / 1; align-self: start; }
[data-layout="side"] .waste > .spot { left: 0; top: calc(var(--below-up, 0) * var(--card) * .34); }
[data-layout="side"] .columns { grid-area: 1 / 2 / span 3; }
#table[data-layout="side"] .homes { grid-area: 1 / 3 / span 3; grid-template-columns: repeat(2, var(--card)); align-content: start; gap: .4rem var(--gap); }
#table[data-game="spider"][data-layout="side"] { grid-template: auto 1fr / var(--card) auto; }
#table[data-game="spider"][data-layout="side"] .columns { grid-area: 1 / 2 / span 2; }
#table[data-game="spider"][data-layout="side"] .homes { grid-area: 2 / 1; grid-template-columns: var(--card); grid-auto-rows: var(--home-step); gap: 0; }
[data-game="spider"][data-layout="side"] .home { align-self: start; }
/* FreeCell on its side: free cells two by two on the left, foundations two by two on the right. */
#table[data-game="freecell"][data-layout="side"] { grid-template: 1fr / auto auto auto; }
#table[data-game="freecell"][data-layout="side"] .cells { grid-area: 1 / 1; grid-template-columns: repeat(2, var(--card)); align-content: start; gap: .4rem var(--gap); }
#table[data-game="freecell"][data-layout="side"] .columns { grid-area: 1 / 2; }
#table[data-game="freecell"][data-layout="side"] .homes { grid-area: 1 / 3; }
@media (hover: hover) and (pointer: fine) {
  #table[data-layout="side"] { row-gap: 1.2rem; padding-top: 1.5rem; }
}
/* Without key labels the rows can sit closer. */
@media (hover: none) and (pointer: coarse) {
  #table { padding-top: .6rem; }
  .tops { margin-bottom: .7rem; }
}
