:root {
  font:
    14px "DM Sans",
    system-ui,
    sans-serif;
  color-scheme: light;
  --ui-bg: #e7eee8;
  --ui-surface: #f6faf6;
  --ui-soft: #d6e3d8;
  --ui-text: #203c31;
  --ui-muted: #496253;
  --ui-line: #a7bdac;
  --felt: #205443;
  --felt-edge: #12392f;
  --accent: #346c50;
  --on-accent: #fff;
  --table-text: #eef5e9;
  --table-muted: #b7d4c2;
  --table-line: #aecbb766;
  --table-soft: #001a1626;
  --table-hover: #ffffff16;
  --notice-bg: #f7edcf;
  --notice-text: #3e3b25;
  --highlight: #e2cb7d;
  --highlight-soft: #fff9cf15;
  --legal: #d5dfac;
  --button-size: 40px;
  --board-gap: 8px;
  background: var(--felt-edge);
  color: var(--ui-text);
}
:root[data-theme="dark"] {
  color-scheme: dark;
}
:root[data-appearance="midnight"] {
  --ui-bg: #1a263a;
  --ui-surface: #26354b;
  --ui-soft: #31445e;
  --ui-text: #edf2fa;
  --ui-muted: #b2bfd2;
  --ui-line: #536883;
  --felt: #26354f;
  --felt-edge: #121d30;
  --accent: #bfd6ea;
  --on-accent: #192c42;
  --table-text: #e4edf8;
  --table-muted: #b6c8de;
  --table-line: #a6bbd466;
  --notice-bg: #dce7f1;
  --notice-text: #23384d;
}
:root[data-appearance="lagoon"] {
  --ui-bg: #e2eff0;
  --ui-surface: #f5fbfb;
  --ui-soft: #cfe3e4;
  --ui-text: #163c43;
  --ui-muted: #43666a;
  --ui-line: #a3bfc2;
  --felt: #1d5e63;
  --felt-edge: #103f46;
  --accent: #276b72;
  --table-text: #e6f5f2;
  --table-muted: #b4d8d4;
  --table-line: #b4d8d466;
  --notice-bg: #e3f1e9;
  --notice-text: #214e4e;
}
:root[data-appearance="plum"] {
  --ui-bg: #ede4ee;
  --ui-surface: #f8f2f7;
  --ui-soft: #e0cfe1;
  --ui-text: #402c46;
  --ui-muted: #684d6d;
  --ui-line: #bda6bf;
  --felt: #553f59;
  --felt-edge: #302438;
  --accent: #745473;
  --table-text: #f7edf4;
  --table-muted: #d6bfd2;
  --table-line: #d6bfd266;
  --notice-bg: #f1e5ee;
  --notice-text: #563a54;
}
:root[data-appearance="clay"] {
  --ui-bg: #efe3d8;
  --ui-surface: #fff8f0;
  --ui-soft: #e5cebd;
  --ui-text: #47342e;
  --ui-muted: #715344;
  --ui-line: #c9ab96;
  --felt: #805448;
  --felt-edge: #4a332f;
  --accent: #84553e;
  --table-text: #fff2df;
  --table-muted: #f0d8c4;
  --table-line: #e5c9b466;
  --notice-bg: #f5e6cc;
  --notice-text: #614332;
}
:root[data-appearance="parchment"] {
  --ui-bg: #f3eedf;
  --ui-surface: #fffdf6;
  --ui-soft: #e6ddc7;
  --ui-text: #354335;
  --ui-muted: #515b40;
  --ui-line: #b5b69c;
  --felt: #e5d9be;
  --felt-edge: #c6b58f;
  --accent: #50654f;
  --table-text: #3c493c;
  --table-muted: #596351;
  --table-line: #6b786177;
  --table-soft: #5a613d0b;
  --table-hover: #ffffff44;
  --notice-bg: #e4ead9;
  --notice-text: #3b4c38;
  --highlight: #4b654d;
  --highlight-soft: #335a3320;
  --legal: #4d6b4d;
}
* {
  box-sizing: border-box;
}
html,
body {
  overflow-anchor: none;
  overflow-x: clip;
  overscroll-behavior: none;
  touch-action: manipulation;
}
body {
  margin: 0;
  min-height: max(100dvh, var(--scroll-floor, 0px));
  background: radial-gradient(ellipse at 50% 0, var(--felt), var(--felt-edge));
  color: var(--ui-text);
}
[hidden] {
  display: none !important;
}
button {
  min-height: var(--button-size);
  padding: 6px 9px;
  border: 1px solid var(--ui-line);
  border-radius: 6px;
  background: var(--ui-surface);
  color: var(--ui-text);
  font:
    600 12px "DM Sans",
    sans-serif;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
button:hover:enabled {
  background: var(--ui-soft);
  border-color: var(--accent);
}
button:disabled {
  opacity: 0.45;
  cursor: default;
}
button:focus-visible,
a:focus-visible {
  outline: 3px solid var(--highlight);
  outline-offset: 3px;
}

/* One control rail. Secondary controls unfold over the table on small screens. */
.shell {
  padding: 0 max(4px, env(safe-area-inset-right))
    max(4px, env(safe-area-inset-bottom)) max(4px, env(safe-area-inset-left));
}
.game-controls {
  position: sticky;
  top: 0;
  z-index: 30;
  display: grid;
  grid-template-areas: "actions view more fullscreen" "stock stock stock stock";
  grid-template-columns: minmax(0, 1fr) auto auto auto;
  align-items: center;
  gap: 4px 6px;
  padding: 2px 0;
  background: var(--felt);
  color: var(--table-text);
  box-shadow: 0 -10px 0 10px var(--felt);
}
.brand {
  grid-area: brand;
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  margin: 0;
  white-space: nowrap;
}
.spider-mark {
  color: var(--table-text);
  font-size: 24px;
}
.actions {
  grid-area: actions;
  display: flex;
  align-items: center;
  gap: 4px;
  min-width: 0;
}
#view-menu {
  grid-area: view;
  justify-self: end;
}
#more-menu {
  grid-area: more;
}
.utility-actions {
  grid-area: fullscreen;
  display: flex;
  align-items: center;
}
.game-controls button {
  white-space: nowrap;
}
.actions button,
.menu-toggle,
.utility-actions button {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  min-height: var(--button-size);
  padding: 0 8px;
  border-color: transparent;
  background: transparent;
  color: inherit;
  font-size: 12px;
}
.actions button {
  width: var(--button-size);
  padding: 0;
  flex: none;
}
.actions button:hover:enabled,
.menu-toggle:hover:enabled,
.utility-actions button:hover:enabled,
.menu-toggle[aria-expanded="true"] {
  background: var(--table-hover);
  border-color: transparent;
}
.action-label,
.game-menu-label {
  display: none;
}
#more-toggle {
  width: var(--button-size);
  padding: 0;
  font-size: 25px;
  line-height: 1;
}
.utility-actions button {
  width: var(--button-size);
  padding: 0;
  flex: none;
}
.actions svg,
.utility-actions svg {
  display: block;
  width: 19px;
  height: 19px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}
#fullscreen[aria-pressed="false"] .exit-fullscreen,
#fullscreen[aria-pressed="true"] .enter-fullscreen {
  display: none;
}
.toolbar-panel {
  position: absolute;
  top: calc(100% + 4px);
  right: 2px;
  width: max-content;
  min-width: 210px;
  max-width: calc(100vw - 16px);
  max-height: calc(100dvh - var(--controls-height, 40px) - 16px);
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 6px;
  border: 1px solid var(--ui-line);
  border-radius: 10px;
  background: var(--ui-surface);
  color: var(--ui-text);
  box-shadow: 0 8px 24px #001b1555;
}
.view-actions {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 2px;
}
.toolbar-panel button {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 8px;
  width: 100%;
  min-height: 40px;
  padding: 8px 10px;
  border: 0;
  background: transparent;
  color: var(--ui-text);
  font-size: 13px;
  text-align: left;
}
.toolbar-panel button:hover:enabled,
.toolbar-panel button[aria-pressed="true"] {
  background: var(--ui-soft);
}
.toolbar-panel button[aria-pressed="true"]::after {
  content: "✓";
  margin-left: auto;
}
#new,
#confirm-new {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--on-accent);
}
#compact,
#appearance {
  border-top: 1px solid var(--ui-line);
  border-radius: 0 0 6px 6px;
  margin-top: 5px;
}
#appearance {
  white-space: normal;
  flex-wrap: nowrap;
}
.appearance-swatch {
  width: 13px;
  height: 13px;
  flex: none;
  border-radius: 50%;
  background: var(--felt);
  box-shadow: inset 0 0 0 1px #0003;
}
#appearance-name {
  color: var(--ui-muted);
  margin-left: 4px;
}
.appearance-caption {
  min-width: 0;
}
.toolbar-panel span[aria-hidden] {
  width: 18px;
  font-size: 18px;
  text-align: center;
  line-height: 1;
}

/* Stock and completed runs share the header, with a second row in portrait. */
.table {
  position: relative;
  min-height: max(
    0px,
    calc(var(--scroll-floor, 0px) - var(--controls-height, 0px))
  );
  padding: 4px 2px 6px;
  color: var(--table-text);
}
.table-top {
  grid-area: stock;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}
.deal {
  grid-area: deal;
  justify-self: start;
}
.foundations {
  grid-area: foundations;
  justify-self: end;
}
.deal {
  display: flex;
  align-items: center;
  gap: 6px;
  min-height: 32px;
  padding: 0 6px;
  border-color: transparent;
  background: transparent;
  color: var(--table-text);
}
.deal:hover:enabled {
  background: var(--table-hover);
  border-color: var(--table-muted);
}
#deal-label {
  font-size: 12px;
  white-space: nowrap;
}
.stock-packs {
  display: flex;
  align-items: center;
  height: 24px;
  min-width: 34px;
  flex: none;
  padding-right: 2px;
}
.stock-packs i {
  display: block;
  width: 19px;
  height: 25px;
  margin-left: -14px;
  border-radius: 2px;
  background: url("./cards/back.svg?v=12") center/contain no-repeat;
  box-shadow: 1px 1px 2px #001e15aa;
}
.stock-packs i:first-child {
  margin-left: 0;
}
.foundations,
.completed {
  display: flex;
  align-items: center;
}
.foundations {
  gap: 8px;
}
.completed {
  gap: 4px;
}
.completed span {
  display: grid;
  place-items: center;
  width: 16px;
  height: 24px;
  border: 1px solid var(--table-line);
  border-radius: 3px;
  background: var(--table-soft);
  color: var(--table-muted);
  font-size: 14px;
}
.completed span.filled {
  background: #fffdf5;
  color: #15372b;
  border-color: #fffdf5;
}
.completed span.red {
  color: #a72e46;
}
.completed svg {
  width: 85%;
  height: 85%;
  fill: currentColor;
}
.completed span.receiving {
  outline: 2px solid var(--highlight);
  outline-offset: 2px;
}
#progress {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}
.stock-detail {
  display: none;
}
.table-scroll {
  position: relative;
  overflow: visible;
  padding: 0;
  min-width: 0;
}
.board {
  position: absolute;
  top: 0;
  left: 50%;
  display: grid;
  grid-template-columns: repeat(10, minmax(0, 1fr));
  gap: var(--board-gap);
  align-items: stretch;
  min-width: 0;
  --card-height: 140px;
  transform: translateX(-50%) scale(var(--table-zoom, 1));
  transform-origin: center top;
}
.column {
  position: relative;
  min-height: var(--card-height);
  border-radius: 5px;
}
.empty-column {
  width: 100%;
  height: var(--card-height);
  min-height: 0;
  padding: 0;
  background: var(--table-soft);
  border: 1px solid var(--table-line);
  border-radius: 5px;
  color: var(--table-muted);
  font-size: 21px;
  box-shadow: inset 0 1px 5px #001c1730;
}
.empty-column:hover:enabled {
  background: #ffffff0b;
}
.column.can-drop {
  outline: 2px dashed var(--legal);
  outline-offset: 1px;
}
.column.can-drop .card:last-child {
  box-shadow:
    inset 0 0 0 2px #57743c,
    0 1px 2px #00271caf;
}
.column.can-drop .empty-column {
  color: var(--table-text);
  border-color: var(--legal);
}
.column.hint-target,
.column.drop-target {
  outline: 2px solid var(--highlight);
  outline-offset: 2px;
  background: var(--highlight-soft);
}

/* Card faces retain their established proportions; only the table is zoomed. */
.card {
  position: absolute;
  top: var(--top, 0px);
  left: 0;
  width: 100%;
  height: var(--card-height);
  min-height: 0;
  padding: 0;
  border: 0;
  border-radius: clamp(3px, calc(var(--card-width) * 0.045), 7px);
  background: #fffdf6;
  color: #182b2b;
  box-shadow:
    0 1px 2px #00271caf,
    0 3px 5px #001f1b33;
  overflow: hidden;
  user-select: none;
  touch-action: pan-y pinch-zoom;
  isolation: isolate;
  transition: box-shadow 0.1s;
}
.card:hover:enabled {
  background: #fffdf6;
  border: 0;
}
.card:disabled {
  opacity: 1;
}
.card.red {
  color: #a52c44;
}
.card-art {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  pointer-events: none;
}
.card.down {
  background: url("./cards/back.svg?v=12") center/100% 100% no-repeat;
  cursor: default;
}
.card.selected,
.card.hint-source {
  outline: 2px solid var(--highlight);
  outline-offset: 0;
  box-shadow:
    0 0 0 2px var(--highlight),
    0 4px 8px #001c1790;
}
.card.selected ~ .card {
  outline: 1px solid var(--highlight);
}
.card[data-movable="true"] {
  cursor: grab;
}
.card.drag-hidden {
  opacity: 0.16;
}
/* A readable rank and suit remain underneath any artwork still loading. */
.card-corner {
  display: flex;
  position: absolute;
  top: calc(var(--card-height) * 0.01);
  left: calc(var(--card-width) * 0.007);
  width: calc(var(--card-width) * 0.205);
  flex-direction: column;
  align-items: center;
  pointer-events: none;
}
.card-corner > span:first-child {
  display: block;
  width: 100%;
  height: calc(var(--card-width) * 0.233);
}
.card-corner > span + span {
  font:
    calc(var(--card-width) * 0.2)/1 Georgia,
    serif;
}
.card-rank {
  display: block;
  width: 100%;
  height: 100%;
}
:is(.board, .drag-ghost).compact .card:not(.down) {
  border: 1px solid #d2d8cc;
}
:is(.board, .drag-ghost).compact .card-art {
  display: none;
}
:is(.board, .drag-ghost).compact .card-corner {
  gap: 1px;
  top: 4px;
  left: 0;
  width: 100%;
  font:
    750 clamp(18px, calc(var(--card-width) * 0.54), 26px)/1 "DM Sans",
    sans-serif;
  letter-spacing: -1px;
}
:is(.board, .drag-ghost).compact .card-corner > span:first-child {
  height: clamp(24px, calc(var(--card-width) * 0.7), 32px);
}
:is(.board, .drag-ghost).compact .card-corner > span + span {
  font:
    clamp(22px, calc(var(--card-width) * 0.66), 30px)/1 Georgia,
    serif;
  letter-spacing: 0;
}
.board.compact .card.down {
  background-color: #203d46;
  background-image:
    repeating-linear-gradient(
      45deg,
      transparent 0,
      transparent 4px,
      #9db3ad60 4px,
      #9db3ad60 4.5px
    ),
    repeating-linear-gradient(
      -45deg,
      transparent 0,
      transparent 4px,
      #c4bd9b55 4px,
      #c4bd9b55 4.5px
    );
  background-size: auto;
  border: 1px solid #e6eadd;
  box-shadow:
    inset 0 0 0 2px #203d46,
    0 1px 2px #00271caf;
}
.drag-ghost {
  position: fixed;
  left: 0;
  top: 0;
  z-index: 10000;
  pointer-events: none;
  will-change: transform;
  filter: drop-shadow(0 9px 8px #00150f70);
}
.drag-ghost .card {
  cursor: grabbing;
}
.run-clearance {
  z-index: 9998;
  filter: none;
}
.run-clearance .card {
  outline: 2px solid #e9cd83;
  box-shadow: 0 0 8px #f5da9070;
  pointer-events: none;
}

/* Feedback never reserves card space or changes the fitted layout. */
.notice {
  position: fixed;
  z-index: 9999;
  left: 50%;
  bottom: max(12px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  width: max-content;
  max-width: min(480px, calc(100% - 24px));
  margin: 0;
  padding: 10px 14px;
  border: 1px solid var(--ui-line);
  border-radius: 8px;
  background: var(--notice-bg);
  color: var(--notice-text);
  box-shadow: 0 5px 24px #001d2840;
  font:
    600 12px/1.5 "DM Sans",
    sans-serif;
  text-align: center;
  pointer-events: none;
}
#message:empty {
  display: none;
}
#win {
  position: sticky;
  top: calc(var(--controls-height, 0px) + 8px);
  z-index: 21;
  padding: 16px 0;
  border-radius: 6px;
  background: var(--felt);
  text-align: center;
}
#win h2 {
  margin: 0 0 8px;
  font:
    700 27px Manrope,
    sans-serif;
}
#win button {
  background: var(--accent);
  color: var(--on-accent);
  border-color: var(--accent);
}
dialog {
  width: min(430px, calc(100% - 24px));
  max-height: calc(100dvh - 24px);
  overflow: auto;
  padding: 20px;
  border: 1px solid var(--ui-line);
  border-radius: 12px;
  background: var(--ui-surface);
  color: var(--ui-text);
  box-shadow: 0 20px 70px #00150d80;
  font:
    14px/1.65 "DM Sans",
    sans-serif;
}
dialog::backdrop {
  background: #001a13b5;
}
.dialog-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  font:
    700 20px Manrope,
    sans-serif;
}
#close {
  width: 32px;
  min-height: 32px;
  padding: 0;
  font-size: 24px;
}
#dialog-body ul {
  padding-left: 19px;
}
#dialog-body li {
  margin: 8px 0;
}
#dialog-body a {
  color: var(--ui-text);
}
.dialog-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 7px;
  margin-top: 16px;
}
.credits {
  font-size: 11px;
  color: var(--ui-muted);
}
.suit-picker {
  border: 0;
  padding: 0;
  margin: 12px 0;
}
.suit-picker legend {
  font-weight: 700;
  margin-bottom: 7px;
}
.suit-picker label {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 11px;
  margin: 5px 0;
  border: 1px solid var(--ui-line);
  border-radius: 7px;
  cursor: pointer;
}
.suit-picker label:has(input:checked) {
  background: var(--ui-soft);
  border-color: var(--accent);
}
.suit-picker input {
  accent-color: var(--accent);
  width: 17px;
  height: 17px;
  margin: 0;
  flex: none;
}
.suit-picker small {
  color: var(--ui-muted);
  margin-left: auto;
  text-align: right;
}
.suit-picker label > span {
  white-space: nowrap;
  flex: none;
}

@media (width < 1060px) {
  :root {
    --button-size: 36px;
    --board-gap: 5px;
  }
}
@media (width < 660px) {
  :root {
    --board-gap: 2px;
  }
  .table {
    padding-inline: 0;
  }
  .stock-packs i {
    height: 24px;
    width: 18px;
    margin-left: -14px;
  }
  .foundations {
    gap: 6px;
  }
  .completed {
    gap: 3px;
  }
  .completed span {
    width: 10px;
    height: 18px;
  }
  .completed span.filled {
    width: 14px;
    height: 22px;
  }
}
@media (width >= 560px) and (orientation: landscape) {
  .game-controls {
    grid-template-areas: "deal actions view more fullscreen foundations";
    grid-template-columns: auto auto minmax(0, 1fr) auto auto auto;
  }
  .table-top {
    display: contents;
  }
  .completed {
    gap: 3px;
  }
  .completed span,
  .completed span.filled {
    width: 12px;
    height: 18px;
  }
}
@media (width >= 1060px) {
  .game-controls {
    grid-template-areas: "deal actions view more fullscreen foundations";
    grid-template-columns: auto auto minmax(0, 1fr) auto auto auto;
    gap: 10px;
    padding: 3px 0;
  }
  .table-top {
    display: contents;
  }
  .toolbar-menu {
    position: relative;
  }
  .toolbar-panel {
    right: 0;
  }
  .actions button {
    width: auto;
    padding: 0 8px;
  }
  .action-label,
  .game-menu-label {
    display: inline;
  }
  .game-menu-icon {
    display: none;
  }
  #more-toggle {
    width: auto;
    padding: 0 9px;
    font-size: 12px;
  }
  .completed {
    gap: 4px;
  }
  .completed span,
  .completed span.filled {
    width: 16px;
    height: 24px;
  }
}
@media (width >= 1280px) {
  .game-controls {
    grid-template-areas: "brand deal actions view more fullscreen foundations";
    grid-template-columns: auto auto auto minmax(0, 1fr) auto auto auto;
  }
  .brand {
    position: static;
    display: flex;
    align-items: center;
    gap: 7px;
    width: auto;
    height: auto;
    overflow: visible;
    clip-path: none;
    font:
      750 18px Manrope,
      sans-serif;
    letter-spacing: -0.6px;
  }
}
@media (prefers-reduced-motion: reduce) {
  * {
    scroll-behavior: auto !important;
    transition: none !important;
  }
}
