:root {
  color-scheme: dark;
  --ink: #f5f1e8;
  --muted: #a9bdb6;
  --felt: #173f34;
  --felt-dark: #0c2922;
  --gold: #ddb96b;
  --card-width: clamp(64px, 7.4vw, 104px);
  --card-height: calc(var(--card-width) * 1.42);
  --face-up-gap: clamp(44px, 5.7vw, 76px);
  --face-down-gap: clamp(20px, 2.2vw, 30px);
}

* { box-sizing: border-box; }

body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background:
    radial-gradient(circle at 50% -20%, rgba(82, 137, 112, .34), transparent 45%),
    linear-gradient(145deg, #12352c, #081f1b 74%);
}

button, input { font: inherit; }
button { color: inherit; }

.app-header {
  min-height: 74px;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 24px;
  padding: 12px clamp(16px, 3vw, 48px);
  border-bottom: 1px solid rgba(255,255,255,.1);
  background: rgba(5, 25, 21, .72);
  backdrop-filter: blur(18px);
}

.brand { display: flex; align-items: center; gap: 10px; }
.brand-mark { color: var(--gold); font-size: 34px; line-height: 1; }
.brand div { display: flex; flex-direction: column; line-height: 1.05; letter-spacing: .02em; }
.brand span:last-child { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .2em; }

.game-stats { display: flex; gap: clamp(20px, 4vw, 56px); }
.game-stats div { min-width: 52px; text-align: center; }
.game-stats span, .eyebrow { display: block; color: var(--muted); font-size: 10px; font-weight: 700; letter-spacing: .15em; text-transform: uppercase; }
.game-stats strong { font-size: 17px; font-variant-numeric: tabular-nums; }

.toolbar { display: flex; justify-content: flex-end; gap: 8px; }
button { border: 0; cursor: pointer; }
.icon-button, .text-button, .primary-button, .difficulty button, #random-seed {
  min-height: 38px;
  border: 1px solid rgba(255,255,255,.14);
  border-radius: 9px;
  padding: 0 14px;
  background: rgba(255,255,255,.07);
  transition: background .15s, border-color .15s, transform .15s;
}
.icon-button { width: 40px; padding: 0; font-size: 21px; }
.primary-button { border-color: #e4c476; color: #15251f; background: linear-gradient(#edcf87, #cfa653); font-weight: 750; }
button:hover:not(:disabled) { border-color: rgba(255,255,255,.34); transform: translateY(-1px); }
button:focus-visible, input:focus-visible { outline: 3px solid #f0cf7f; outline-offset: 3px; }
button:disabled { cursor: not-allowed; opacity: .35; }

main { padding: 22px clamp(12px, 3vw, 48px) 42px; }
.game-meta { max-width: 1500px; display: flex; align-items: center; justify-content: space-between; margin: 0 auto 16px; }
.game-meta strong { font-size: 14px; }
.difficulty { display: flex; padding: 3px; border-radius: 10px; background: rgba(0,0,0,.2); }
.difficulty button { min-height: 32px; border: 0; padding: 0 12px; background: transparent; color: var(--muted); }
.difficulty button[aria-pressed="true"] { color: var(--ink); background: rgba(255,255,255,.12); box-shadow: 0 1px 6px rgba(0,0,0,.3); }

.board-shell {
  max-width: 1500px;
  min-height: calc(100vh - 150px);
  margin: auto;
  overflow: hidden;
  border: 1px solid rgba(255,255,255,.11);
  border-radius: 18px;
  background:
    linear-gradient(rgba(255,255,255,.025) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,.018) 1px, transparent 1px),
    var(--felt);
  background-size: 22px 22px;
  box-shadow: 0 30px 80px rgba(0,0,0,.3), inset 0 0 80px rgba(0,0,0,.18);
}

.board-top { min-height: 148px; display: grid; grid-template-columns: 130px 1fr minmax(300px, auto); align-items: center; gap: 20px; padding: 18px 24px; border-bottom: 1px solid rgba(255,255,255,.08); }
.stock { display: flex; align-items: center; gap: 14px; padding: 8px; border-radius: 9px; background: transparent; color: var(--muted); font-size: 12px; }
.stock-stack, .card-back {
  background-color: #162c4b;
  background-image: repeating-linear-gradient(45deg, rgba(221,185,107,.38) 0 1px, transparent 1px 6px), repeating-linear-gradient(-45deg, rgba(221,185,107,.2) 0 1px, transparent 1px 6px);
  border: 3px solid #ede8dc;
  box-shadow: 3px 3px 0 #10223a, 6px 6px 0 rgba(237,232,220,.65), 0 8px 18px rgba(0,0,0,.3);
}
.stock-stack { width: 58px; height: 80px; border-radius: 6px; }
.message { color: #cad8d3; font-family: Georgia, serif; font-style: italic; text-align: center; }
.message.error { color: #ffb2a7; }
.foundations { display: flex; justify-content: flex-end; gap: 7px; min-height: 82px; }
.foundation { width: 55px; height: 78px; display: grid; place-items: center; border: 1px solid rgba(255,255,255,.22); border-radius: 6px; color: #17251f; background: #f7f3ea; font-size: 25px; box-shadow: 0 5px 12px rgba(0,0,0,.24); }
.foundation.empty { color: rgba(255,255,255,.12); background: rgba(0,0,0,.12); box-shadow: none; }

.tableau { min-width: 760px; display: grid; grid-template-columns: repeat(10, minmax(0, 1fr)); gap: clamp(5px, 1vw, 15px); padding: 22px 18px 300px; overflow-x: auto; }
.pile { position: relative; min-height: 180px; border-radius: 9px; }
.pile::before { content: ""; position: absolute; inset: 0 auto auto 0; width: 100%; max-width: var(--card-width); aspect-ratio: 1 / 1.42; border: 1px dashed rgba(255,255,255,.18); border-radius: 8px; }
.pile.valid::before { border: 2px solid var(--gold); background: rgba(221,185,107,.13); }

.card {
  position: absolute;
  top: calc(
    var(--face-up-before) * var(--face-up-gap) +
    var(--face-down-before) * var(--face-down-gap)
  );
  left: 0;
  width: 100%;
  max-width: var(--card-width);
  aspect-ratio: 1 / 1.42;
  padding: 7px;
  border: 1px solid #d4d0c6;
  border-radius: 8px;
  color: #19211e;
  background: linear-gradient(135deg, #fff, #eeeae0);
  box-shadow: 0 4px 8px rgba(0,0,0,.35);
  text-align: left;
  user-select: none;
  touch-action: manipulation;
  transition: transform .14s, box-shadow .14s, filter .14s;
}
.card:hover:not(.card-back) { transform: translateY(-3px); box-shadow: 0 7px 14px rgba(0,0,0,.4); }
.card.selected { transform: translateY(-7px); box-shadow: 0 0 0 3px var(--gold), 0 10px 20px rgba(0,0,0,.45); }
.card.hint { animation: hint-pulse .75s ease-in-out 2; }
.card.red { color: #a52d31; }
.card-back { padding: 0; font-size: 0; }
.rank { display: block; font-family: Georgia, serif; font-size: clamp(15px, 1.7vw, 23px); font-weight: 700; line-height: .9; }
.suit { font-size: clamp(14px, 1.55vw, 21px); }
.card-center { position: absolute; inset: 0; display: grid; place-items: center; font-size: clamp(24px, 3vw, 44px); opacity: .9; }
@keyframes hint-pulse { 50% { filter: brightness(1.25); box-shadow: 0 0 0 4px #f4d47e; } }

dialog { width: min(480px, calc(100% - 32px)); border: 1px solid rgba(255,255,255,.18); border-radius: 18px; padding: 0; color: var(--ink); background: #112d26; box-shadow: 0 30px 100px #000; }
dialog::backdrop { background: rgba(0,10,8,.75); backdrop-filter: blur(5px); }
dialog form { position: relative; display: grid; gap: 14px; padding: 34px; }
dialog h1 { margin: 0; font: 30px Georgia, serif; }
dialog p { margin: 0; color: var(--muted); font-size: 14px; }
dialog label { font-size: 13px; font-weight: 700; }
.dialog-close { position: absolute; top: 12px; right: 14px; padding: 6px; background: transparent; font-size: 24px; }
.seed-row { display: flex; gap: 8px; }
.seed-row input { min-width: 0; flex: 1; border: 1px solid rgba(255,255,255,.2); border-radius: 9px; padding: 10px 12px; color: var(--ink); background: rgba(0,0,0,.2); }
dialog .primary-button { margin-top: 8px; }

@media (max-width: 850px) {
  .app-header { grid-template-columns: 1fr auto; }
  .game-stats { grid-column: 1 / -1; grid-row: 2; justify-content: center; order: 3; }
  .toolbar .text-button { display: none; }
  .board-top { grid-template-columns: 100px 1fr; }
  .message { display: none; }
  .foundations { grid-column: 2; overflow: hidden; }
  .tableau { min-width: 720px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
