:root {
  color-scheme: light;
  --page: #f3f7f3;
  --surface: #fff;
  --ink: #142922;
  --secondary: #456052;
  --line: #cbdcd0;
  --accent: #07513d;
  --soft: #edf3ee;
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #101c17;
  --surface: #192b23;
  --ink: #edf7f0;
  --secondary: #bdcfc3;
  --line: #405a4e;
  --accent: #a7e4c8;
  --soft: #283e34;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; background: var(--page); color: var(--ink); font: 16px/1.45 system-ui, -apple-system, sans-serif; }
header { border-block-end: 1px solid var(--line); background: var(--surface); }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 4px; }
a:focus-visible, button:focus-visible, select:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
button, select { color: inherit; font: inherit; }
.page { max-width: 1050px; margin-inline: auto; padding-inline: clamp(10px, 3vw, 25px); }
.top { min-height: 64px; display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.top a { display: inline-flex; align-items: center; gap: 7px; min-height: 44px; font-size: 14px; font-weight: 720; }
.top .brand { color: var(--ink); font-size: 18px; }
.brand img { object-fit: contain; border-radius: 6px; }
main { padding-block: 18px 32px; }
.heading { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-block-end: 12px; }
h1 { margin: 0; font-size: clamp(27px, 4vw, 39px); line-height: 1.1; }
.heading label { display: flex; align-items: center; gap: 7px; color: var(--secondary); font-size: 13px; font-weight: 730; }
select, .actions button { min-height: 44px; padding: 4px 11px; border: 1px solid var(--line); border-radius: 7px; background: var(--soft); font-size: 13px; font-weight: 730; cursor: pointer; }
.layout { display: grid; grid-template-columns: minmax(0, 1fr) minmax(164px, 215px); gap: 14px; align-items: start; }
.game, .guide { min-width: 0; padding: clamp(8px, 1.4vw, 15px); border: 1px solid var(--line); border-radius: 13px; background: var(--surface); }
.table {
  --gap: clamp(3px, 1vw, 10px);
  --card-height: clamp(52px, 10vw, 100px);
  --peek: clamp(18px, 3vw, 27px);
  padding: clamp(6px, 1.4vw, 15px);
  border: 1px solid #294a3d;
  border-radius: 9px;
  color: #f5f3e9;
  background: radial-gradient(ellipse at 42% 2%, #245f4b, #153e34 78%);
}
.top-piles { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--gap); }
.pile-group h2 { display: flex; justify-content: space-between; gap: 3px; margin: 0 0 5px; font-size: clamp(11px, 2.7vw, 14px); line-height: 1.3; }
#progress { color: #d6efdf; white-space: nowrap; font-variant-numeric: tabular-nums; }
.piles { display: grid; gap: var(--gap); align-items: start; }
.four { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.eight { grid-template-columns: repeat(8, minmax(0, 1fr)); min-height: calc(var(--card-height) + 6 * var(--peek)); margin-block-start: clamp(12px, 2vw, 23px); }
.pile { position: relative; display: flex; min-width: 0; min-height: var(--card-height); flex-direction: column; padding: 0; border: 0; border-radius: 5px; background: transparent; color: inherit; text-align: start; touch-action: manipulation; -webkit-tap-highlight-color: transparent; cursor: pointer; }
.pile:focus-visible { outline-color: #f8d587; z-index: 1; }
.pile[data-selected] .card-face:last-child { box-shadow: inset 0 0 0 3px #b57712, 0 0 0 2px #ffe49c; }
.pile[data-target] .card-face:last-child, .pile[data-target] .slot { outline: 2px solid #b7f3bc; outline-offset: 1px; }
.card-face, .slot { width: 100%; height: var(--card-height); border-radius: 5px; }
.slot { display: grid; place-items: center; border: 1px dashed #80aa96; color: #cfebd7; background: #173b30; font-size: clamp(15px, 3.8vw, 28px); }
.card-face { position: relative; display: flex; align-items: flex-start; gap: clamp(1px, .28vw, 4px); flex-shrink: 0; padding: 1px clamp(1px, .5vw, 6px); border: 1px solid #c2cabb; background: #fffdf5; color: #192b24; font: 760 clamp(12px, 3.1vw, 20px)/1.2 system-ui, sans-serif; box-shadow: 0 2px 3px #092b21a0; }
.card-face[data-red] { color: #a32233; }
.card-face + .card-face { margin-top: calc(var(--peek) - var(--card-height)); }
.card-mark { position: absolute; inset: 33% 0 auto; text-align: center; font-size: clamp(16px, 4vw, 36px); line-height: 1; }
.card-face:not(:last-child) .card-mark { visibility: hidden; }
.status { min-height: 21px; margin: 9px 0; color: var(--secondary); font-size: 13px; font-weight: 680; }
.status[data-won] { color: var(--accent); }
.actions { display: flex; align-items: center; flex-wrap: wrap; gap: 7px; }
.actions button:disabled { opacity: .55; cursor: default; }
#moves { margin-inline-start: auto; color: var(--secondary); font-size: 13px; font-variant-numeric: tabular-nums; }
.guide h2 { margin: 0 0 7px; font-size: 16px; }
.guide ol { margin: 0; padding-inline-start: 19px; color: var(--secondary); font-size: 14px; }
.guide li + li { margin-block-start: 7px; }
@media (max-width: 690px) {
  main { padding-block-start: 12px; }
  .top { min-height: 56px; }
  .layout { grid-template-columns: 1fr; gap: 9px; }
}
.pile[data-hint] .card-face:last-child, .pile[data-hint] .slot { outline:3px solid #f3d17c; outline-offset:1px; }
.status[data-stuck] { color:#7a1520; background:#fde8ea; border:2px solid #c23a48; border-radius:10px; padding:10px 14px; font-size:1.05rem; font-weight:750; }
[data-theme="dark"] .status[data-stuck] { color:#ffd6db; background:#4a1c22; border-color:#ff8d9a; }
button[data-suggest]:not(:disabled) { outline:3px solid #f3d17c; outline-offset:2px; font-weight:750; }
#restart-dialog { background:var(--surface); color:var(--ink); border:1px solid var(--line); border-radius:12px; padding:16px; }
#restart-dialog::backdrop { background:#0c2620b0; }
/* Short landscape phones (e.g. 667×375): size cards by height, not width, so the free cells,
   foundations and every column fit the first screen, and keep the actions pinned at the bottom. */
@media (orientation: landscape) and (max-height: 500px) {
  body:has(.top-piles) .top { min-height: 44px; }
  body:has(.top-piles) .top .brand { font-size: 15px; }
  body:has(.top-piles) .heading { margin-block-end: 4px; }
  body:has(.top-piles) h1 { font-size: 18px; }
  body:has(.top-piles) .heading select { min-height: 32px; padding-block: 2px; }
  body:has(.top-piles) .layout { grid-template-columns: 1fr; gap: 6px; }
  body:has(.top-piles) .game { padding: 6px 8px; }
  body:has(.top-piles) .table { --card-height: min(12.5vh, 47px); --peek: min(4.2vh, 16px); }
  body:has(.top-piles) .pile-group h2 { margin-block-end: 2px; font-size: 11px; }
  body:has(.top-piles) .slot { font-size: 18px; }
  body:has(.top-piles) .card-face { font-size: 13px; }
  body:has(.top-piles) .card-mark { font-size: 18px; }
  body:has(.top-piles) .eight { margin-block-start: 5px; }
  body:has(.top-piles) .card-face:last-child { box-shadow: 0 2px 3px #092b21a0, 0 0 0 1px #f8d58766; }
  body:has(.top-piles) .status { margin: 4px 0; min-height: 0; }
  body:has(.top-piles) .actions { position: sticky; bottom: 0; z-index: 2; padding: 6px 0; background: var(--surface); }
}

/* First move: show which cards can move. Scoped to FreeCell (this file is shared with ~45 card pages). */
body:has(.top-piles) .table[data-first-move] #tableau .card-face:last-child { box-shadow: 0 0 0 2px #f2c45a, 0 0 12px #f2c45a99; }
