/* 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: #f5f7f2;
  --bg-b: #dde4dc;
  --surface: #ffffff;
  --surface-2: #f2f5f0;
  --surface-3: #e7ece5;

  --felt-a: #cadfd0;
  --felt-b: #b2cdb9;

  --ink: #17211c;
  --ink-soft: #3d4a44;
  --muted: #66756d;

  --line: rgba(18, 42, 30, 0.13);
  --line-strong: rgba(18, 42, 30, 0.26);
  --slot-line: rgba(20, 62, 42, 0.3);
  --slot-fill: rgba(255, 255, 255, 0.22);

  --accent: #9d6f14;
  --accent-bright: #c68f1f;
  --accent-ink: #2b1d04;
  --good: #14855a;
  --bad: #bd3543;
  --info: #2f6fd0;

  --card-face: #ffffff;
  --card-edge: rgba(18, 30, 24, 0.16);
  --card-ink: #1a2430;
  --card-red: #c22f3d;
  --card-back-a: #2f7a66;
  --card-back-b: #17453b;
  --card-back-line: rgba(255, 255, 255, 0.22);

  --shadow-sm: 0 1px 2px rgba(12, 32, 22, 0.14);
  --shadow-card: 0 1px 2px rgba(12, 32, 22, 0.2), 0 5px 12px rgba(12, 32, 22, 0.12);
  --shadow-lift: 0 8px 18px rgba(12, 32, 22, 0.22), 0 18px 40px rgba(12, 32, 22, 0.16);
  --shadow-panel: 0 20px 50px rgba(12, 32, 22, 0.22);

  --radius: 16px;
  --radius-card: 8px;

  --display: "Avenir Next", "Segoe UI", system-ui, -apple-system, "Helvetica Neue", sans-serif;
  --body: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

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

    --bg-a: #131b20;
    --bg-b: #080c0f;
    --surface: #18222a;
    --surface-2: #1f2b34;
    --surface-3: #26343e;

    --felt-a: #163a30;
    --felt-b: #0b2320;

    --ink: #eaf1ee;
    --ink-soft: #c2d0ca;
    --muted: #8b9a94;

    --line: rgba(255, 255, 255, 0.09);
    --line-strong: rgba(255, 255, 255, 0.2);
    --slot-line: rgba(255, 255, 255, 0.17);
    --slot-fill: rgba(255, 255, 255, 0.03);

    --accent: #f0b849;
    --accent-bright: #ffd07a;
    --accent-ink: #241802;
    --good: #3fd39a;
    --bad: #ff6b7a;
    --info: #6fa8ff;

    --card-face: #f7f5ef;
    --card-edge: rgba(0, 0, 0, 0.45);
    --card-ink: #1b2430;
    --card-red: #cf3341;
    --card-back-a: #2c7f6a;
    --card-back-b: #103029;
    --card-back-line: rgba(255, 255, 255, 0.2);

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
    --shadow-card: 0 1px 2px rgba(0, 0, 0, 0.32), 0 4px 10px rgba(0, 0, 0, 0.26);
    --shadow-lift: 0 10px 22px rgba(0, 0, 0, 0.5), 0 22px 44px rgba(0, 0, 0, 0.42);
    --shadow-panel: 0 24px 60px rgba(0, 0, 0, 0.6);
  }
}

/* The in-app switch overrides the device preference in both directions. */
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg-a: #131b20;
  --bg-b: #080c0f;
  --surface: #18222a;
  --surface-2: #1f2b34;
  --surface-3: #26343e;
  --felt-a: #163a30;
  --felt-b: #0b2320;
  --ink: #eaf1ee;
  --ink-soft: #c2d0ca;
  --muted: #8b9a94;
  --line: rgba(255, 255, 255, 0.09);
  --line-strong: rgba(255, 255, 255, 0.2);
  --slot-line: rgba(255, 255, 255, 0.17);
  --slot-fill: rgba(255, 255, 255, 0.03);
  --accent: #f0b849;
  --accent-bright: #ffd07a;
  --accent-ink: #241802;
  --good: #3fd39a;
  --bad: #ff6b7a;
  --info: #6fa8ff;
  --card-face: #f7f5ef;
  --card-edge: rgba(0, 0, 0, 0.45);
  --card-ink: #1b2430;
  --card-red: #cf3341;
  --card-back-a: #2c7f6a;
  --card-back-b: #103029;
  --card-back-line: rgba(255, 255, 255, 0.2);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow-card: 0 1px 2px rgba(0, 0, 0, 0.32), 0 4px 10px rgba(0, 0, 0, 0.26);
  --shadow-lift: 0 10px 22px rgba(0, 0, 0, 0.5), 0 22px 44px rgba(0, 0, 0, 0.42);
  --shadow-panel: 0 24px 60px rgba(0, 0, 0, 0.6);
}

:root[data-theme="light"] {
  color-scheme: light;
  --bg-a: #f5f7f2;
  --bg-b: #dde4dc;
  --surface: #ffffff;
  --surface-2: #f2f5f0;
  --surface-3: #e7ece5;
  --felt-a: #cadfd0;
  --felt-b: #b2cdb9;
  --ink: #17211c;
  --ink-soft: #3d4a44;
  --muted: #66756d;
  --line: rgba(18, 42, 30, 0.13);
  --line-strong: rgba(18, 42, 30, 0.26);
  --slot-line: rgba(20, 62, 42, 0.3);
  --slot-fill: rgba(255, 255, 255, 0.22);
  --accent: #9d6f14;
  --accent-bright: #c68f1f;
  --accent-ink: #2b1d04;
  --good: #14855a;
  --bad: #bd3543;
  --info: #2f6fd0;
  --card-face: #ffffff;
  --card-edge: rgba(18, 30, 24, 0.16);
  --card-ink: #1a2430;
  --card-red: #c22f3d;
  --card-back-a: #2f7a66;
  --card-back-b: #17453b;
  --card-back-line: rgba(255, 255, 255, 0.22);
  --shadow-sm: 0 1px 2px rgba(12, 32, 22, 0.14);
  --shadow-card: 0 1px 2px rgba(12, 32, 22, 0.2), 0 5px 12px rgba(12, 32, 22, 0.12);
  --shadow-lift: 0 8px 18px rgba(12, 32, 22, 0.22), 0 18px 40px rgba(12, 32, 22, 0.16);
  --shadow-panel: 0 20px 50px rgba(12, 32, 22, 0.22);
}

* {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  font-family: var(--body);
  color: var(--ink);
  background: linear-gradient(170deg, 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: 12px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink-soft);
  cursor: pointer;
  transition: transform 0.16s, border-color 0.16s, color 0.16s;
  box-shadow: 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;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: 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(160deg, var(--accent-bright), var(--accent));
  border-color: transparent;
  color: var(--accent-ink);
  box-shadow: var(--shadow-sm);
}

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

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

.home {
  max-width: 880px;
  margin: 0 auto;
  padding: 26px 20px calc(40px + env(safe-area-inset-bottom));
}

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

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

.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(--accent);
  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: var(--radius);
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
  box-shadow: 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);
}

.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: 1px solid var(--line);
  background: var(--surface);
}

.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: 10px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  text-align: center;
  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);
}

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

.game-status {
  margin: 0;
  padding: 7px 16px 0;
  font-size: 11.5px;
  letter-spacing: 0.05em;
  color: var(--muted);
  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-radius: 18px;
  background:
    radial-gradient(120% 90% at 50% 0%, var(--felt-a) 0%, var(--felt-b) 100%);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08), inset 0 0 40px rgba(0, 0, 0, 0.14);
  -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: 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, var(--card-back-line) 0 2px, transparent 2px 7px),
    linear-gradient(150deg, var(--card-back-a), var(--card-back-b));
  border: 1px solid var(--card-edge);
}

.card-back span {
  position: absolute;
  inset: 8%;
  border-radius: 4px;
  border: 1px 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: 1px solid var(--line);
  background: var(--surface);
}

.dock-btn {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 7px 4px;
  border: 1px solid transparent;
  border-radius: 12px;
  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(160deg, var(--accent-bright), var(--accent));
  color: var(--accent-ink);
  font-weight: 700;
}

/* ---------------------------------------------------------------- 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: var(--surface);
  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) 78%, 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: 22px;
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: var(--shadow-panel);
  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 5px;
  font-family: var(--display);
  font-size: 23px;
  font-weight: 700;
  letter-spacing: -0.02em;
  text-align: center;
}

.result-title.win {
  color: var(--good);
}

.result-title.stuck {
  color: var(--bad);
}

.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: 14px;
  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;
  border-radius: 14px;
  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);
}

.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: 12px;
  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);
}

.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);
}

.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: 11px;
  background: var(--surface-2);
  border: 1px solid var(--line);
}

.seg-btn {
  padding: 6px 11px;
  border: none;
  border-radius: 8px;
  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 {
    padding: 20px 15px 34px;
  }

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

  .table-wrap {
    margin: 6px 6px;
    padding: 8px 8px 12px;
    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) {
  .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;
}
