/* Solitaire Collection — a card room that works by day or by night.
   ------------------------------------------------------------------
   Every colour is a token. The light palette is the default, the dark
   palette is redefined under prefers-color-scheme, and both are redefined
   again under [data-theme] so the in-app switch always wins. Components
   only ever reference tokens, never raw colours.                        */

:root {
  color-scheme: light;

  --bg-a: #74401f;
  --bg-b: #3b2115;
  --surface: #f5ecd8;
  --surface-2: #e3d4b7;
  --surface-3: #d4bf98;

  --felt-a: #1c6946;
  --felt-b: #10432f;

  --ink: #252a28;
  --ink-soft: #454b47;
  --muted: #6c6a60;

  --line: rgba(59, 33, 21, 0.2);
  --line-strong: rgba(59, 33, 21, 0.44);
  --slot-line: rgba(248, 232, 198, 0.58);
  --slot-fill: rgba(255, 246, 220, 0.07);

  --accent: #d3aa53;
  --accent-bright: #e7ca86;
  --accent-text: #765612;
  --accent-ink: #281906;
  --primary: #1d568d;
  --primary-bright: #3475ad;
  --primary-ink: #fffaf0;
  --good: #286f4e;
  --bad: #a83e3b;
  --info: #1d568d;

  --card-face: #f5ecd8;
  --card-edge: rgba(58, 37, 21, 0.3);
  --card-ink: #252a28;
  --card-red: #a83e3b;
  --card-back-a: #2f6fa8;
  --card-back-b: #1d568d;
  --card-back-line: rgba(248, 232, 198, 0.55);

  --wood-edge: #3b2115;
  --wood-highlight: rgba(233, 199, 145, 0.34);
  --paper-glow: rgba(255, 255, 255, 0.46);

  --shadow-sm: 0 1px 2px rgba(45, 25, 12, 0.2);
  --shadow-card: 0 1px 2px rgba(35, 22, 12, 0.24), 0 5px 12px rgba(35, 22, 12, 0.15);
  --shadow-lift: 0 8px 18px rgba(35, 22, 12, 0.28), 0 18px 40px rgba(35, 22, 12, 0.2);
  --shadow-panel: 0 20px 50px rgba(25, 14, 8, 0.38);

  --radius: 14px;
  --radius-card: 7px;

  --display: Georgia, "Times New Roman", Times, serif;
  --body: Tahoma, "Segoe UI", system-ui, -apple-system, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;

    --bg-a: #3b2115;
    --bg-b: #130a07;
    --surface: #2a231d;
    --surface-2: #372d25;
    --surface-3: #47392c;

    --felt-a: #1c6946;
    --felt-b: #10432f;

    --ink: #f4ead8;
    --ink-soft: #dccdb8;
    --muted: #b2a18a;

    --line: rgba(238, 210, 164, 0.13);
    --line-strong: rgba(238, 210, 164, 0.3);
    --slot-line: rgba(248, 232, 198, 0.42);
    --slot-fill: rgba(255, 246, 220, 0.045);

    --accent: #d3aa53;
    --accent-bright: #f0cf8b;
    --accent-text: #e5c477;
    --accent-ink: #2a1a07;
    --primary: #286aa4;
    --primary-bright: #3b7db6;
    --primary-ink: #fffaf0;
    --good: #69c796;
    --bad: #ef6b72;
    --info: #78a9df;

    --card-face: #f5ecd8;
    --card-edge: rgba(0, 0, 0, 0.5);
    --card-ink: #252a28;
    --card-red: #a83e3b;
    --card-back-a: #2f6fa8;
    --card-back-b: #1d568d;
    --card-back-line: rgba(248, 232, 198, 0.5);

    --wood-edge: #170d08;
    --wood-highlight: rgba(226, 183, 118, 0.2);
    --paper-glow: rgba(255, 238, 204, 0.05);

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.46);
    --shadow-card: 0 1px 2px rgba(0, 0, 0, 0.38), 0 4px 10px rgba(0, 0, 0, 0.3);
    --shadow-lift: 0 10px 22px rgba(0, 0, 0, 0.56), 0 22px 44px rgba(0, 0, 0, 0.46);
    --shadow-panel: 0 24px 60px rgba(0, 0, 0, 0.68);
  }
}

/* The in-app switch overrides the device preference in both directions. */
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg-a: #3b2115;
  --bg-b: #130a07;
  --surface: #2a231d;
  --surface-2: #372d25;
  --surface-3: #47392c;
  --felt-a: #1c6946;
  --felt-b: #10432f;
  --ink: #f4ead8;
  --ink-soft: #dccdb8;
  --muted: #b2a18a;
  --line: rgba(238, 210, 164, 0.13);
  --line-strong: rgba(238, 210, 164, 0.3);
  --slot-line: rgba(248, 232, 198, 0.42);
  --slot-fill: rgba(255, 246, 220, 0.045);
  --accent: #d3aa53;
  --accent-bright: #f0cf8b;
  --accent-text: #e5c477;
  --accent-ink: #2a1a07;
  --primary: #286aa4;
  --primary-bright: #3b7db6;
  --primary-ink: #fffaf0;
  --good: #69c796;
  --bad: #ef6b72;
  --info: #78a9df;
  --card-face: #f5ecd8;
  --card-edge: rgba(0, 0, 0, 0.5);
  --card-ink: #252a28;
  --card-red: #a83e3b;
  --card-back-a: #2f6fa8;
  --card-back-b: #1d568d;
  --card-back-line: rgba(248, 232, 198, 0.5);
  --wood-edge: #170d08;
  --wood-highlight: rgba(226, 183, 118, 0.2);
  --paper-glow: rgba(255, 238, 204, 0.05);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.46);
  --shadow-card: 0 1px 2px rgba(0, 0, 0, 0.38), 0 4px 10px rgba(0, 0, 0, 0.3);
  --shadow-lift: 0 10px 22px rgba(0, 0, 0, 0.56), 0 22px 44px rgba(0, 0, 0, 0.46);
  --shadow-panel: 0 24px 60px rgba(0, 0, 0, 0.68);
}

:root[data-theme="light"] {
  color-scheme: light;
  --bg-a: #74401f;
  --bg-b: #3b2115;
  --surface: #f5ecd8;
  --surface-2: #e3d4b7;
  --surface-3: #d4bf98;
  --felt-a: #1c6946;
  --felt-b: #10432f;
  --ink: #252a28;
  --ink-soft: #454b47;
  --muted: #6c6a60;
  --line: rgba(59, 33, 21, 0.2);
  --line-strong: rgba(59, 33, 21, 0.44);
  --slot-line: rgba(248, 232, 198, 0.58);
  --slot-fill: rgba(255, 246, 220, 0.07);
  --accent: #d3aa53;
  --accent-bright: #e7ca86;
  --accent-text: #765612;
  --accent-ink: #281906;
  --primary: #1d568d;
  --primary-bright: #3475ad;
  --primary-ink: #fffaf0;
  --good: #286f4e;
  --bad: #a83e3b;
  --info: #1d568d;
  --card-face: #f5ecd8;
  --card-edge: rgba(58, 37, 21, 0.3);
  --card-ink: #252a28;
  --card-red: #a83e3b;
  --card-back-a: #2f6fa8;
  --card-back-b: #1d568d;
  --card-back-line: rgba(248, 232, 198, 0.55);
  --wood-edge: #3b2115;
  --wood-highlight: rgba(233, 199, 145, 0.34);
  --paper-glow: rgba(255, 255, 255, 0.46);
  --shadow-sm: 0 1px 2px rgba(45, 25, 12, 0.2);
  --shadow-card: 0 1px 2px rgba(35, 22, 12, 0.24), 0 5px 12px rgba(35, 22, 12, 0.15);
  --shadow-lift: 0 8px 18px rgba(35, 22, 12, 0.28), 0 18px 40px rgba(35, 22, 12, 0.2);
  --shadow-panel: 0 20px 50px rgba(25, 14, 8, 0.38);
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  overscroll-behavior: none;
}

body {
  margin: 0;
  font-family: var(--body);
  color: var(--ink);
  background:
    radial-gradient(ellipse at 50% -20%, var(--wood-highlight) 0%, transparent 58%),
    repeating-linear-gradient(92deg, rgba(255, 255, 255, 0.025) 0 1px, transparent 1px 42px),
    linear-gradient(155deg, var(--bg-a) 0%, var(--bg-b) 100%);
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

/* While a game is open the page itself never scrolls — the felt is the only
   scroller — so there is nothing for pull-to-refresh to grab. */
body[data-screen="game"] {
  overflow: hidden;
  position: fixed;
  inset: 0;
  width: 100%;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

#fx {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 90;
}

.screen[hidden] {
  display: none;
}

/* --------------------------------------------------------------- buttons */

.icon-btn {
  width: 40px;
  height: 40px;
  flex: none;
  display: grid;
  place-items: center;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: linear-gradient(180deg, var(--surface), var(--surface-2));
  color: var(--ink-soft);
  cursor: pointer;
  transition: transform 0.16s, border-color 0.16s, color 0.16s;
  box-shadow: inset 0 1px 0 var(--paper-glow), var(--shadow-sm);
}

.icon-btn:hover {
  color: var(--ink);
  border-color: var(--line-strong);
  transform: translateY(-1px);
}

.icon-btn:focus-visible,
.btn:focus-visible,
.dock-btn:focus-visible,
.game-card:focus-visible,
.level-card:focus-visible,
.seg-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.icon-btn.ghost {
  background: transparent;
  box-shadow: none;
}

.icon-btn svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}

#btnSound svg path:first-child {
  fill: currentColor;
  stroke: none;
}

.icon-btn.is-off {
  color: var(--muted);
}

.icon-btn.is-off .wave {
  opacity: 0.2;
}

.btn {
  padding: 11px 18px;
  min-height: 44px;
  border-radius: 7px;
  border: 1px solid var(--line);
  background: linear-gradient(180deg, var(--surface), var(--surface-2));
  color: var(--ink);
  font: 600 14px/1 var(--body);
  cursor: pointer;
  transition: transform 0.16s, background 0.16s, border-color 0.16s;
}

.btn:hover {
  transform: translateY(-1px);
  border-color: var(--line-strong);
}

.btn.primary {
  background: linear-gradient(180deg, var(--primary-bright), var(--primary));
  border-color: color-mix(in srgb, var(--primary) 72%, black);
  color: var(--primary-ink);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.24), var(--shadow-sm);
}

.btn.subtle {
  background: transparent;
  color: var(--muted);
  border-color: transparent;
}

/* ------------------------------------------------------------------ home */

.home {
  position: relative;
  width: calc(100% - 36px);
  max-width: 920px;
  min-height: calc(100% - 36px);
  margin: 18px auto;
  padding: 26px 20px calc(40px + env(safe-area-inset-bottom));
  overflow: hidden;
  border: 1px solid var(--line-strong);
  border-radius: 16px;
  background:
    linear-gradient(115deg, var(--paper-glow), transparent 38%),
    var(--surface);
  box-shadow: 0 0 0 4px var(--wood-edge), var(--shadow-panel), inset 0 1px 0 var(--paper-glow);
}

.home::after {
  content: "";
  position: absolute;
  inset: 0 24px auto;
  height: 2px;
  background: linear-gradient(90deg, transparent, var(--accent), transparent);
  opacity: 0.7;
  pointer-events: none;
}

.home-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.room-mark {
  display: block;
  margin: 0 0 7px;
  color: var(--accent-text);
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.2em;
  line-height: 1;
  text-transform: uppercase;
}

.room-mark::before {
  content: "◆";
  margin-right: 7px;
  font-size: 0.82em;
}

.head-titles .room-mark {
  margin-bottom: 2px;
  font-size: 7px;
  letter-spacing: 0.15em;
}

.wordmark .suits {
  display: flex;
  gap: 5px;
  font-size: 13px;
  margin-bottom: 7px;
}

.wordmark .suits i {
  font-style: normal;
  line-height: 1;
}

.wordmark .suits i:nth-child(1),
.wordmark .suits i:nth-child(4) {
  color: var(--ink-soft);
}

.wordmark .suits i:nth-child(2),
.wordmark .suits i:nth-child(3) {
  color: var(--card-red);
}

.wordmark h1 {
  margin: 0;
  font-family: var(--display);
  font-size: clamp(28px, 7vw, 44px);
  font-weight: 700;
  letter-spacing: -0.025em;
  line-height: 0.98;
}

.wordmark h1 span {
  display: block;
  font-weight: 400;
  font-size: 0.52em;
  letter-spacing: 0.26em;
  text-transform: uppercase;
  color: var(--info);
  margin-top: 8px;
}

.home-intro {
  margin: 22px 0 20px;
  max-width: 46ch;
  font-size: 15px;
  line-height: 1.6;
  color: var(--muted);
}

.game-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.game-card {
  display: flex;
  align-items: stretch;
  gap: 14px;
  padding: 16px;
  text-align: left;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: linear-gradient(145deg, var(--surface), var(--surface-2));
  color: var(--ink);
  cursor: pointer;
  box-shadow: inset 0 1px 0 var(--paper-glow), var(--shadow-card);
  transition: transform 0.2s cubic-bezier(.2, .8, .3, 1), box-shadow 0.2s, border-color 0.2s;
}

.game-card:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-lift);
  border-color: var(--line-strong);
}

.game-art {
  position: relative;
  flex: none;
  width: 62px;
}

.mini {
  position: absolute;
  top: calc(var(--i) * 9px);
  left: calc(var(--i) * 7px);
  width: 38px;
  height: 54px;
  border-radius: 6px;
  background: var(--card-face);
  border: 1px solid var(--card-edge);
  box-shadow: var(--shadow-sm);
  transform: rotate(calc((var(--i) - 1) * 7deg));
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
  font-family: var(--display);
  transition: transform 0.25s cubic-bezier(.2, .8, .3, 1);
}

.mini:first-child {
  background:
    repeating-linear-gradient(45deg, transparent 0 4px, var(--card-back-line) 4px 5px),
    linear-gradient(150deg, var(--card-back-a), var(--card-back-b));
  border: 2px solid var(--card-face);
  box-shadow: inset 0 0 0 2px var(--card-back-b), var(--shadow-sm);
}

.mini:first-child b,
.mini:first-child i {
  opacity: 0;
}

.game-card:hover .mini {
  transform: rotate(calc((var(--i) - 1) * 12deg)) translateY(calc(var(--i) * -2px));
}

.mini b {
  font-size: 14px;
  line-height: 1;
  color: var(--card-ink);
}

.mini i {
  font-style: normal;
  font-size: 13px;
  line-height: 1;
  color: var(--card-ink);
}

.mini.red b,
.mini.red i {
  color: var(--card-red);
}

.game-body {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}

.game-name {
  font-family: var(--display);
  font-size: 19px;
  font-weight: 700;
  letter-spacing: -0.015em;
}

.game-blurb {
  font-size: 13px;
  line-height: 1.45;
  color: var(--muted);
}

.game-stats {
  display: flex;
  gap: 14px;
  margin-top: auto;
  padding-top: 10px;
  font-variant-numeric: tabular-nums;
}

.game-stats>span {
  display: flex;
  flex-direction: column;
  font-size: 15px;
  font-weight: 700;
  font-family: var(--display);
}

.game-stats em {
  font-style: normal;
  font-size: 9.5px;
  font-weight: 500;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
}

.home-foot {
  margin-top: 26px;
  font-size: 12px;
  color: var(--muted);
  text-align: center;
}

/* ------------------------------------------------------------------ game */

.game {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
}

.game-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  padding-top: max(10px, env(safe-area-inset-top));
  border-bottom: 3px solid var(--wood-edge);
  background: linear-gradient(180deg, var(--surface), var(--surface-2));
  box-shadow: inset 0 1px 0 var(--paper-glow), 0 2px 8px rgba(32, 18, 9, 0.24);
}

.head-titles {
  min-width: 0;
  flex: 1;
}

.head-titles h2 {
  margin: 0;
  font-family: var(--display);
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -0.015em;
  white-space: nowrap;
}

.head-titles p {
  margin: 1px 0 0;
  font-size: 10.5px;
  letter-spacing: 0.06em;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.hud {
  display: flex;
  gap: 7px;
}

.hud-chip {
  padding: 4px 11px;
  border-radius: 7px;
  background: linear-gradient(180deg, var(--surface), var(--surface-2));
  border: 1px solid var(--line);
  text-align: center;
  box-shadow: inset 0 1px 0 var(--paper-glow);
  transition: border-color 0.2s, box-shadow 0.2s;
}

.hud-chip .label {
  display: block;
  font-size: 8.5px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--muted);
}

.hud-chip strong {
  font-family: var(--display);
  font-size: 16px;
  font-variant-numeric: tabular-nums;
}

.hud-chip.is-hot {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 24%, transparent);
}

.hud-chip.is-hot strong {
  color: var(--accent-text);
}

.head-actions {
  display: flex;
  gap: 7px;
}

.game-status {
  margin: 0;
  padding: 7px 16px 0;
  font-size: 11.5px;
  letter-spacing: 0.05em;
  color: rgba(255, 244, 218, 0.82);
  text-shadow: 0 1px 1px rgba(36, 18, 9, 0.62);
  text-align: center;
  min-height: 20px;
}

/* ----------------------------------------------------------------- table */

.table-wrap {
  position: relative;
  /* the felt is the table surface: it fills the space, and the board sits
     at the top of it so columns can grow downward without shifting */
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  /* the felt may be scrolled vertically, but a swipe here must never chain
     out to the page and trigger pull-to-refresh */
  touch-action: pan-y;
  overscroll-behavior: contain;
  /* contain the cards' stacking order so nothing can rise above a dialog */
  isolation: isolate;
  z-index: 0;
  padding: 10px 12px 16px;
  margin: 8px 10px;
  border: 3px solid var(--wood-edge);
  border-radius: 14px;
  background:
    repeating-linear-gradient(0deg, rgba(255, 255, 255, 0.012) 0 1px, transparent 1px 4px),
    repeating-linear-gradient(90deg, rgba(0, 0, 0, 0.012) 0 1px, transparent 1px 5px),
    radial-gradient(120% 90% at 50% 0%, var(--felt-a) 0%, var(--felt-b) 100%);
  box-shadow:
    0 1px 0 var(--wood-highlight),
    0 5px 14px rgba(28, 15, 8, 0.25),
    inset 0 1px 0 rgba(255, 255, 255, 0.09),
    inset 0 0 48px rgba(0, 0, 0, 0.2);
  -webkit-overflow-scrolling: touch;
}

.table {
  position: relative;
  width: 100%;
  touch-action: manipulation;
}

.slots,
.card-layer {
  position: absolute;
  inset: 0;
}

.card-layer {
  pointer-events: none;
}

.slot {
  position: absolute;
  top: 0;
  left: 0;
  border-radius: var(--radius-card);
  border: 1.5px dashed var(--slot-line);
  background: var(--slot-fill);
  transition: border-color 0.18s, box-shadow 0.18s, background 0.18s;
}

.slot::after {
  content: attr(data-label);
  position: absolute;
  inset: auto 0 6px;
  text-align: center;
  font-size: 8px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--slot-line);
  opacity: 0;
  transition: opacity 0.2s;
}

.slot.is-empty::after {
  opacity: 0.9;
}

.slot-stock {
  border-style: solid;
}

/* Spider's finished runs: no outline until something lands there. */
.slot.is-quiet.is-empty {
  border-color: transparent;
  background: transparent;
}

.slot.is-quiet.is-empty::after {
  content: none;
}

.slot.is-target {
  border-color: var(--accent);
  border-style: solid;
  background: color-mix(in srgb, var(--accent) 16%, transparent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent);
}

.slot.is-hint {
  border-color: var(--info);
  border-style: solid;
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--info) 30%, transparent);
  animation: pulse 0.9s ease-in-out infinite;
}

.slot.is-invalid {
  border-color: var(--bad);
  animation: nudge 0.4s ease;
}

@keyframes pulse {

  0%,
  100% {
    opacity: 0.55;
  }

  50% {
    opacity: 1;
  }
}

@keyframes nudge {

  0%,
  100% {
    transform: translate(var(--sx, 0), var(--sy, 0));
  }
}

/* ----------------------------------------------------------------- cards */

.card {
  position: absolute;
  top: 0;
  left: 0;
  width: var(--card-w);
  height: var(--card-h);
  perspective: 700px;
  pointer-events: auto;
  cursor: default;
  transition: transform 0.26s cubic-bezier(.2, .8, .3, 1);
  will-change: transform;
  /* a touch that starts on a card is ours: no scrolling, no pull-to-refresh,
     no text selection and no long-press callout */
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

.card.playable {
  cursor: grab;
}

.card.is-dragging {
  transition: none;
  cursor: grabbing;
}

.no-anim .card,
.no-anim .card-inner,
.no-anim .slot {
  transition: none !important;
}

.card-inner {
  position: relative;
  width: 100%;
  height: 100%;
  transform-style: preserve-3d;
  transition: transform 0.32s cubic-bezier(.3, .8, .3, 1);
}

.card.down .card-inner {
  transform: rotateY(180deg);
}

.card-face,
.card-back {
  position: absolute;
  inset: 0;
  border-radius: var(--radius-card);
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  box-shadow: var(--shadow-card);
  overflow: hidden;
}

.card-face {
  background:
    radial-gradient(circle at 25% 16%, rgba(255, 255, 255, 0.62), transparent 42%),
    var(--card-face);
  border: 1px solid var(--card-edge);
  color: var(--card-ink);
  display: flex;
  align-items: center;
  justify-content: center;
}

.card.red .card-face {
  color: var(--card-red);
}

.corner {
  position: absolute;
  display: flex;
  flex-direction: column;
  align-items: center;
  line-height: 0.95;
  font-family: var(--display);
  font-weight: 700;
}

.corner.tl {
  top: 4%;
  left: 5%;
}

.corner.br {
  bottom: 4%;
  right: 5%;
  transform: rotate(180deg);
}

.corner b {
  font-size: calc(var(--card-w) * 0.3);
  letter-spacing: -0.04em;
}

.corner i {
  font-style: normal;
  font-size: calc(var(--card-w) * 0.24);
}

.pip {
  font-size: calc(var(--card-w) * 0.62);
  line-height: 1;
  opacity: 0.9;
}

.court+.pip,
.card-face .court~.pip {
  font-size: calc(var(--card-w) * 0.3);
  opacity: 0.75;
}

.court {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -62%);
  font-family: var(--display);
  font-weight: 700;
  font-size: calc(var(--card-w) * 0.56);
  letter-spacing: -0.04em;
}

.card-face .court~.pip {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, 62%);
}

.card-back {
  transform: rotateY(180deg);
  background:
    repeating-linear-gradient(45deg, transparent 0 4px, var(--card-back-line) 4px 5px),
    repeating-linear-gradient(-45deg, transparent 0 5px, rgba(255, 255, 255, 0.1) 5px 6px),
    linear-gradient(150deg, var(--card-back-a), var(--card-back-b));
  border: 2px solid var(--card-face);
  box-shadow: inset 0 0 0 2px var(--card-back-b), var(--shadow-card);
}

.card-back span {
  position: absolute;
  inset: 8%;
  border-radius: 4px;
  border: 2px solid var(--card-back-line);
}

.card.is-selected .card-face {
  box-shadow: 0 0 0 2.5px var(--accent), var(--shadow-lift);
}

.card.is-target-card .card-face {
  box-shadow: 0 0 0 2.5px color-mix(in srgb, var(--accent) 70%, transparent), var(--shadow-card);
}

.card.is-hint-card .card-face {
  box-shadow: 0 0 0 3px var(--info), var(--shadow-lift);
}

.card.is-dragging .card-face,
.card.is-dragging .card-back {
  box-shadow: var(--shadow-lift);
}

/* --------------------------------------------------------------- floats */

.floats {
  position: absolute;
  inset: 10px 12px 16px;
  pointer-events: none;
  z-index: 60;
}

.float-text {
  position: absolute;
  transform: translate(-50%, -50%);
  font-family: var(--display);
  font-weight: 700;
  font-size: 15px;
  font-variant-numeric: tabular-nums;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.35);
  animation: float-up 1.3s cubic-bezier(.2, .9, .3, 1) forwards;
  white-space: nowrap;
}

.float-text.gain {
  color: var(--accent-bright);
}

.float-text.loss {
  color: var(--bad);
}

.float-text.combo {
  color: var(--good);
  font-size: 13px;
  animation-delay: 0.1s;
}

@keyframes float-up {
  0% {
    opacity: 0;
    transform: translate(-50%, -20%) scale(0.7);
  }

  20% {
    opacity: 1;
    transform: translate(-50%, -70%) scale(1.1);
  }

  100% {
    opacity: 0;
    transform: translate(-50%, -190%) scale(1);
  }
}

/* ------------------------------------------------------------------ dock */

.dock {
  display: flex;
  gap: 6px;
  padding: 8px 12px calc(10px + env(safe-area-inset-bottom));
  border-top: 3px solid var(--wood-edge);
  background: linear-gradient(180deg, var(--surface), var(--surface-2));
  box-shadow: inset 0 1px 0 var(--paper-glow), 0 -2px 8px rgba(32, 18, 9, 0.18);
}

.dock-btn {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 7px 4px;
  border: 1px solid transparent;
  min-height: 44px;
  border-radius: 7px;
  background: transparent;
  color: var(--ink-soft);
  font: 500 10.5px/1.2 var(--body);
  cursor: pointer;
  transition: background 0.16s, color 0.16s, transform 0.16s;
}

.dock-btn:hover:not(:disabled) {
  background: var(--surface-2);
  transform: translateY(-1px);
}

.dock-btn:disabled {
  opacity: 0.35;
  cursor: default;
}

.dock-btn[hidden] {
  display: none;
}

.dock-icon {
  font-size: 17px;
  line-height: 1;
}

.dock-btn.accent {
  background: linear-gradient(180deg, var(--primary-bright), var(--primary));
  color: var(--primary-ink);
  font-weight: 700;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.22), var(--shadow-sm);
}

/* ---------------------------------------------------------------- toasts */

.toasts {
  position: fixed;
  left: 50%;
  bottom: calc(84px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 150;
  display: flex;
  flex-direction: column;
  gap: 6px;
  align-items: center;
  pointer-events: none;
}

.toast {
  padding: 9px 16px;
  border-radius: 999px;
  background: linear-gradient(180deg, var(--surface), var(--surface-2));
  border: 1px solid var(--line-strong);
  box-shadow: var(--shadow-lift);
  font-size: 13px;
  font-weight: 600;
  animation: toast-in 0.24s cubic-bezier(.2, .9, .3, 1);
  transition: opacity 0.4s, transform 0.4s;
}

.toast.is-out {
  opacity: 0;
  transform: translateY(6px);
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
}

/* ---------------------------------------------------------------- modals */

.modal {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: grid;
  place-items: center;
  padding: 18px;
  background: color-mix(in srgb, var(--bg-b) 84%, transparent);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  opacity: 0;
  transition: opacity 0.2s;
  overflow-y: auto;
}

.modal[hidden] {
  display: none;
}

.modal.is-open {
  opacity: 1;
}

.modal-card {
  width: min(100%, 440px);
  max-height: calc(100vh - 36px);
  overflow-y: auto;
  padding: 24px;
  border-radius: 12px;
  background:
    linear-gradient(135deg, var(--paper-glow), transparent 42%),
    var(--surface);
  border: 1px solid var(--line-strong);
  box-shadow: 0 0 0 4px var(--wood-edge), var(--shadow-panel), inset 0 1px 0 var(--paper-glow);
  transform: translateY(14px) scale(0.98);
  transition: transform 0.26s cubic-bezier(.2, .9, .3, 1);
}

.modal.is-open .modal-card {
  transform: none;
}

.modal-title,
.result-title {
  margin: 0 0 14px;
  padding: 9px 12px;
  border: 1px solid var(--wood-edge);
  border-radius: 7px;
  background: linear-gradient(180deg, var(--felt-a), var(--felt-b));
  color: #f5ecd8;
  font-family: var(--display);
  font-size: 23px;
  font-weight: 700;
  letter-spacing: -0.02em;
  text-align: center;
  text-shadow: 0 1px 1px rgba(0, 0, 0, 0.38);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.12), var(--shadow-sm);
}

.result-title.win {
  color: #f5ecd8;
}

.result-title.stuck {
  background: linear-gradient(180deg, color-mix(in srgb, var(--bad) 84%, white), var(--bad));
  color: #fffaf0;
}

.modal-sub {
  margin: 0 0 18px;
  text-align: center;
  font-size: 13px;
  color: var(--muted);
}

.mini-head {
  margin: 18px 0 7px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--muted);
}

/* Extra axes offered beside the difficulty — Klondike and FreeCell's suits. */
.options {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.options[hidden] {
  display: none;
}

.option-row {
  padding: 13px 15px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--surface-2);
}

.option-head {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin-bottom: 9px;
}

.option-head strong {
  font-family: var(--display);
  font-size: 15px;
}

.option-head em {
  font-style: normal;
  font-size: 12px;
  color: var(--muted);
}

.segmented.wide {
  width: 100%;
  background: var(--surface);
}

.segmented.wide .seg-btn {
  flex: 1;
  padding: 8px 6px;
}

.option-note {
  margin: 8px 0 0;
  font-size: 12px;
  color: var(--muted);
  min-height: 15px;
}

.levels {
  display: flex;
  flex-direction: column;
  gap: 9px;
}

.level-card {
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 14px 16px;
  text-align: left;
  min-height: 44px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--ink);
  cursor: pointer;
  transition: transform 0.16s, border-color 0.16s, background 0.16s;
}

.level-card:hover {
  transform: translateY(-2px);
  border-color: var(--accent);
  background: var(--surface-3);
}

.level-name {
  font-family: var(--display);
  font-size: 16px;
  font-weight: 700;
}

.level-blurb {
  font-size: 12.5px;
  color: var(--muted);
}

.level-foot {
  display: flex;
  gap: 12px;
  margin-top: 5px;
}

.level-foot em {
  font-style: normal;
  font-size: 10px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--accent-text);
}

.level-foot em:last-child {
  color: var(--muted);
}

.stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.stat {
  display: flex;
  flex-direction: column;
  padding: 9px 10px;
  border-radius: 7px;
  background: var(--surface-2);
  border: 1px solid var(--line);
}

.stat span {
  font-size: 9px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
}

.stat strong {
  font-family: var(--display);
  font-size: 16px;
  font-variant-numeric: tabular-nums;
}

.breakdown {
  list-style: none;
  margin: 14px 0 0;
  padding: 0;
}

.breakdown li {
  display: flex;
  justify-content: space-between;
  padding: 6px 2px;
  font-size: 13px;
  border-bottom: 1px solid var(--line);
}

.breakdown li:last-child {
  border-bottom: none;
}

.breakdown b {
  color: var(--good);
  font-variant-numeric: tabular-nums;
}

.placement {
  margin: 12px 0 0;
  text-align: center;
  font-size: 13px;
  font-weight: 600;
  color: var(--accent-text);
}

.streak-line {
  margin: 6px 0 0;
  text-align: center;
  font-size: 12px;
  color: var(--muted);
}

/* ------------------------------------------------------------ statistics */

.stat-groups {
  display: flex;
  flex-direction: column;
  gap: 14px;
  margin-top: 18px;
}

.stat-group.is-empty {
  opacity: 0.55;
}

.stat-group-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  padding-bottom: 5px;
  border-bottom: 1px solid var(--line);
}

.stat-group-head h4 {
  margin: 0;
  font-family: var(--display);
  font-size: 15px;
}

.stat-group-head span {
  font-size: 12px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.board-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.board-list li {
  display: grid;
  grid-template-columns: 1fr auto auto auto;
  gap: 10px;
  align-items: baseline;
  padding: 6px 0;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}

.board-list li+li {
  border-top: 1px solid var(--line);
}

.board-list li.head {
  font-size: 9px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
  border-top: 0;
}

.board-list .tally,
.board-list .rate,
.board-list .best {
  min-width: 46px;
  text-align: right;
}

.board-list .board em {
  margin-left: 6px;
  padding: 1px 6px;
  border-radius: 6px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  font-style: normal;
  font-size: 10px;
  color: var(--muted);
}

.btn.danger {
  color: var(--bad);
}

.home-foot #btnStats {
  margin-bottom: 6px;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.score-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.score-list li {
  display: grid;
  grid-template-columns: 20px 1fr auto;
  gap: 8px;
  align-items: center;
  padding: 6px 2px;
  font-size: 13px;
  border-bottom: 1px solid var(--line);
}

.score-list li:last-child {
  border-bottom: none;
}

.score-list .pos {
  font-family: var(--display);
  font-weight: 700;
  color: var(--accent-text);
}

.score-list .pts {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.score-list .meta {
  font-size: 11px;
  color: var(--muted);
}

.score-list .empty {
  grid-template-columns: 1fr;
  color: var(--muted);
}

.modal-actions {
  display: flex;
  gap: 8px;
  justify-content: center;
  flex-wrap: wrap;
  margin-top: 20px;
}

.prose p {
  font-size: 13.5px;
  line-height: 1.65;
  color: var(--ink-soft);
}

.prose strong {
  color: var(--ink);
}

.prose.scoring {
  margin-top: 4px;
  padding-top: 4px;
  border-top: 1px solid var(--line);
}

/* -------------------------------------------------------------- settings */

.setting {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 12px 2px;
  border-bottom: 1px solid var(--line);
}

.setting-text strong,
.switch-text strong {
  display: block;
  font-size: 14px;
}

.setting-text em,
.switch-text em {
  font-style: normal;
  font-size: 11.5px;
  color: var(--muted);
}

.segmented {
  display: flex;
  flex: none;
  padding: 3px;
  border-radius: 8px;
  background: var(--surface-2);
  border: 1px solid var(--line);
}

.seg-btn {
  padding: 6px 11px;
  border: none;
  min-height: 32px;
  border-radius: 5px;
  background: transparent;
  color: var(--muted);
  font: 600 12px/1 var(--body);
  cursor: pointer;
  transition: background 0.16s, color 0.16s;
}

.seg-btn.is-on {
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow-sm);
}

.switch {
  display: flex;
  align-items: center;
  gap: 13px;
  padding: 12px 2px;
  cursor: pointer;
  border-bottom: 1px solid var(--line);
}

.switch input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.switch .track {
  position: relative;
  flex: none;
  width: 44px;
  height: 26px;
  border-radius: 999px;
  background: var(--surface-3);
  border: 1px solid var(--line);
  transition: background 0.22s;
}

.switch .track::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--muted);
  transition: transform 0.22s, background 0.22s;
}

.switch input:checked+.track {
  background: linear-gradient(160deg, var(--accent-bright), var(--accent));
  border-color: transparent;
}

.switch input:checked+.track::after {
  transform: translateX(18px);
  background: var(--card-face);
}

.switch input:focus-visible+.track {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ------------------------------------------------------------ responsive */

@media (max-width: 640px) {
  .game-grid {
    grid-template-columns: 1fr;
  }

  .home {
    width: 100%;
    min-height: 100%;
    margin: 0;
    padding: 20px 15px 34px;
    border: 0;
    border-radius: 0;
    box-shadow: none;
  }

  .home-intro {
    margin: 16px 0 16px;
    font-size: 14px;
  }

  .table-wrap {
    margin: 6px 6px;
    padding: 8px 8px 12px;
    border-width: 2px;
    border-radius: 14px;
  }

  .floats {
    inset: 8px 8px 12px;
  }

  .game-head {
    flex-wrap: wrap;
    gap: 8px;
    padding: 8px 10px;
  }

  .head-titles {
    order: 1;
    flex: 1;
  }

  .head-actions {
    order: 2;
  }

  .hud {
    order: 3;
    width: 100%;
    justify-content: space-between;
  }

  .hud-chip {
    flex: 1;
  }

  .game-status {
    padding: 5px 12px 0;
    min-height: 17px;
    font-size: 11px;
  }

  .modal-card {
    padding: 20px 17px;
  }

  .stats {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 380px) {
  .dock-btn {
    font-size: 9.5px;
  }

  .dock-icon {
    font-size: 15px;
  }
}

/* Landscape phones: reclaim vertical space for the table. */
@media (max-height: 520px) and (orientation: landscape) {
  .head-titles .room-mark,
  .game-status {
    display: none;
  }

  .dock {
    padding: 5px 10px calc(6px + env(safe-area-inset-bottom));
  }

  .dock-btn {
    flex-direction: row;
    gap: 6px;
  }

  .table-wrap {
    margin: 4px 6px;
  }
}

@media (prefers-reduced-motion: reduce) {

  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

.version-line {
  margin: 14px 0 0;
  text-align: center;
  font-size: 11.5px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
