
/* ============== Reset & base ============== */
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Inter, "Helvetica Neue", Arial, sans-serif;
  color: #f5f3ee;
  background: #0a4a29;
  min-height: 100dvh;
  overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  display: flex;
  flex-direction: column;
}
button { font: inherit; color: inherit; }
h1, h2, h3, p, ol, ul { margin: 0; }
ol, ul { padding-left: 1.2em; }

/* ============== Felt background ============== */
body::before {
  content: "";
  position: fixed; inset: 0;
  background:
    radial-gradient(ellipse at 50% 30%, rgba(255,255,255,0.07), transparent 60%),
    radial-gradient(ellipse at 50% 100%, rgba(0,0,0,0.35), transparent 70%),
    linear-gradient(180deg, #126a3d 0%, #0c5530 55%, #08401f 100%);
  z-index: -2;
}
body::after {
  content: "";
  position: fixed; inset: 0;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='160' height='160'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 0  0 0 0 0 0  0 0 0 0 0  0 0 0 0.05 0'/></filter><rect width='100%' height='100%' filter='url(%23n)'/></svg>");
  opacity: .55;
  pointer-events: none;
  z-index: -1;
  mix-blend-mode: overlay;
}

/* ============== Skip link ============== */
.skip {
  position: absolute; left: -9999px; top: 0;
  background: #fff; color: #000; padding: 8px 12px; border-radius: 6px;
}
.skip:focus { left: 8px; top: 8px; z-index: 100; }

/* ============== Top bar ============== */
.topbar {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 16px;
  padding: 14px 18px;
  background: linear-gradient(180deg, rgba(0,0,0,.18), rgba(0,0,0,0));
  backdrop-filter: blur(6px);
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand-mark { filter: drop-shadow(0 2px 4px rgba(0,0,0,.25)); }
.brand-name {
  font-family: "Playfair Display", Georgia, serif;
  font-weight: 700;
  font-size: clamp(20px, 2.5vw, 26px);
  letter-spacing: .5px;
  color: #fff8e7;
  text-shadow: 0 1px 2px rgba(0,0,0,.3);
}
.stats {
  display: flex; gap: 18px;
  justify-content: center;
}
.stat {
  display: flex; flex-direction: column; align-items: center;
  min-width: 64px;
  background: rgba(0,0,0,.22);
  border: 1px solid rgba(255,255,255,.08);
  border-radius: 12px;
  padding: 6px 12px;
  box-shadow: inset 0 1px 0 rgba(255,255,255,.06), 0 1px 3px rgba(0,0,0,.25);
}
.stat-label { font-size: 10px; letter-spacing: .14em; text-transform: uppercase; opacity: .72; }
.stat-value {
  font-variant-numeric: tabular-nums;
  font-weight: 700; font-size: 18px;
  color: #fff8e7;
}

.actions { display: flex; gap: 10px; }
.btn {
  display: inline-flex; align-items: center; gap: 8px;
  min-height: 44px; padding: 0 16px;
  border-radius: 999px;
  border: 1px solid rgba(255,255,255,.14);
  background: linear-gradient(180deg, rgba(255,255,255,.18), rgba(255,255,255,.06));
  color: #fff8e7;
  cursor: pointer;
  font-weight: 600; font-size: 15px;
  box-shadow:
    inset 0 1px 0 rgba(255,255,255,.18),
    0 2px 6px rgba(0,0,0,.25);
  transition: transform .12s ease, background .2s ease, box-shadow .2s ease;
}
.btn:hover { background: linear-gradient(180deg, rgba(255,255,255,.26), rgba(255,255,255,.10)); }
.btn:active { transform: translateY(1px) scale(.98); }
.btn:focus-visible { outline: 2px solid #ffd569; outline-offset: 2px; }
.btn.primary {
  background: linear-gradient(180deg, #ffcf5e, #f0a83a);
  color: #2b1900;
  border-color: rgba(0,0,0,.15);
}
.btn.icon-only { padding: 0; width: 44px; justify-content: center; }
#btn-sound .ic-sound-off { display: none; }
#btn-sound[aria-pressed="false"] .ic-sound-on { display: none; }
#btn-sound[aria-pressed="false"] .ic-sound-off { display: inline; opacity: .7; }

/* ============== Board layout ============== */
.board {
  position: relative;
  flex: 1 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px clamp(8px, 2vw, 18px) 16px;
}
.felt {
  position: relative;
  margin: 0 auto;
  /* --card-w-px is set by JS to fit viewport (width + height + tableau depth). */
  --card-w: var(--card-w-px, 84px);
  --card-h: calc(var(--card-w) * 1.42);
  --gap: calc(var(--card-w) * 0.12);
  --spread-up: calc(var(--card-w) * 0.32);
  --spread-down: calc(var(--card-w) * 0.15);
  --row-gap: calc(var(--card-w) * 0.20);
}

.row {
  display: grid;
  grid-template-columns: repeat(7, var(--card-w));
  gap: var(--gap);
  justify-content: center;
}
.top-row { margin-bottom: var(--row-gap); }

.pile-slot {
  width: var(--card-w);
  height: var(--card-h);
  display: flex; align-items: center; justify-content: center;
  position: relative;
  background: transparent;
  border: none;
}
.pile-slot::before {
  content: "";
  position: absolute;
  /* Inset the dashed outline so it has interior breathing room. */
  inset: calc(var(--card-w) * 0.05);
  border-radius: calc(var(--card-w) * 0.10);
  border: 2px dashed rgba(255,255,255,.20);
  background: rgba(0,0,0,.10);
  pointer-events: none;
  transition: border-color .22s ease, background .22s ease, box-shadow .22s ease;
}
.pile-slot > * { position: relative; z-index: 1; }
.pile-slot.is-target::before {
  border-color: #ffd569;
  background: rgba(255, 213, 105, .14);
  box-shadow: 0 0 0 3px rgba(255, 213, 105, .35), 0 0 26px rgba(255, 213, 105, .35);
}
.pile-slot.is-invalid::before {
  border-color: rgba(217, 48, 37, .8);
  background: rgba(217, 48, 37, .12);
}
.slot-icon {
  font-size: calc(var(--card-w) * .42);
  color: rgba(255,255,255,.18);
  font-family: "Apple Color Emoji", "Segoe UI Symbol", serif;
}
.slot-icon.red { color: rgba(255, 200, 200, .22); }

/* ============== Card layer (absolute positioned cards) ============== */
.card-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
}
.card {
  position: absolute;
  width: var(--card-w);
  height: var(--card-h);
  border-radius: calc(var(--card-w) * .12);
  background: #fefcf6;
  color: #1f1f1f;
  box-shadow:
    0 1px 0 rgba(255,255,255,.6) inset,
    0 1px 2px rgba(0,0,0,.18),
    0 6px 14px rgba(0,0,0,.22);
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
  pointer-events: auto;
  cursor: default;
  will-change: transform;
  transform: translate3d(var(--x, 0), var(--y, 0), 0);
  transition:
    transform .42s cubic-bezier(.22,.7,.2,1),
    box-shadow .25s ease;
  overflow: hidden;
}
.card.face-up { cursor: pointer; }
.card.dragging {
  transition: none;
  cursor: grabbing;
  box-shadow:
    0 1px 0 rgba(255,255,255,.6) inset,
    0 4px 8px rgba(0,0,0,.25),
    0 24px 50px rgba(0,0,0,.40);
  z-index: 9999 !important;
}
.card.lifted { transform: translate3d(var(--x, 0), calc(var(--y, 0) - 3px), 0); }
.card.hint {
  animation: hintPulse 1.1s ease-in-out infinite;
}
@keyframes hintPulse {
  0%, 100% { box-shadow: 0 1px 0 rgba(255,255,255,.6) inset, 0 1px 2px rgba(0,0,0,.18), 0 6px 14px rgba(0,0,0,.22), 0 0 0 0 rgba(255, 213, 105, 0); }
  50%      { box-shadow: 0 1px 0 rgba(255,255,255,.6) inset, 0 1px 2px rgba(0,0,0,.18), 0 6px 14px rgba(0,0,0,.22), 0 0 0 6px rgba(255, 213, 105, .55); }
}

/* Card face */
.card .corner {
  position: absolute;
  display: flex;
  flex-direction: column;
  align-items: center;
  line-height: .95;
  font-family: Georgia, "Times New Roman", serif;
  font-weight: 700;
}
.card .corner.tl { top: 4%; left: 6%; }
.card .corner.br { right: 6%; bottom: 4%; transform: rotate(180deg); transform-origin: center; }
.card .rank { font-size: calc(var(--card-w) * .26); }
.card .csuit { font-size: calc(var(--card-w) * .22); }
.card .center {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: calc(var(--card-w) * .55);
  font-family: "Apple Color Emoji", "Segoe UI Symbol", serif;
  opacity: .92;
  pointer-events: none;
}
.card.red { color: #c2241b; }
.card.black { color: #14141a; }

/* Card back */
.card.face-down { cursor: pointer; }
.card.face-down .face { display: none; }
.card.face-down .back {
  position: absolute; inset: 0;
  border-radius: inherit;
  background:
    repeating-linear-gradient(45deg, rgba(255,255,255,.06) 0 4px, rgba(255,255,255,0) 4px 8px),
    repeating-linear-gradient(-45deg, rgba(255,255,255,.05) 0 4px, rgba(255,255,255,0) 4px 8px),
    radial-gradient(ellipse at center, #1c4e8a, #0f2e57);
  border: 1px solid rgba(0,0,0,.25);
  box-shadow: inset 0 0 0 4px rgba(255,255,255,.10), inset 0 0 0 5px rgba(0,0,0,.25);
}
.card.face-down .back::after {
  content: "♠";
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  color: rgba(255,255,255,.18);
  font-size: calc(var(--card-w) * .55);
  font-family: "Apple Color Emoji", "Segoe UI Symbol", serif;
}

/* Stock empty refresh icon */
.pile-slot[data-pile="stock"] .slot-icon { color: rgba(255,255,255,.30); font-size: calc(var(--card-w) * .50); }

/* ============== Win overlay ============== */
.win-overlay {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: radial-gradient(ellipse at center, rgba(0,0,0,.55), rgba(0,0,0,.85));
  z-index: 1000;
  animation: fadeIn .4s ease;
}
.win-overlay[hidden] { display: none; }
.win-card {
  background: linear-gradient(180deg, #fffaf0, #f3e6c8);
  color: #2b1900;
  padding: 28px 32px;
  border-radius: 18px;
  text-align: center;
  box-shadow: 0 30px 80px rgba(0,0,0,.6);
  max-width: 420px; width: calc(100vw - 32px);
  animation: pop .5s cubic-bezier(.2,.85,.25,1.2);
}
.win-card h2 {
  font-family: Georgia, serif;
  font-size: 28px;
  margin-bottom: 8px;
}
.win-card p { margin-bottom: 18px; opacity: .8; }
@keyframes fadeIn { from { opacity: 0 } to { opacity: 1 } }
@keyframes pop { from { opacity: 0; transform: scale(.85) } to { opacity: 1; transform: scale(1) } }

/* ============== Ads + content ============== */
.ad {
  max-width: 1100px; margin: 14px auto 0;
  padding: 0 18px;
  min-height: 90px;
}
.adsbygoogle { background: rgba(0,0,0,.18); border-radius: 10px; }

.prose {
  max-width: 720px; margin: 28px auto 0;
  padding: 24px 22px;
  background: rgba(0,0,0,.22);
  border: 1px solid rgba(255,255,255,.08);
  border-radius: 16px;
  line-height: 1.6;
  color: #f1ecdf;
}
.prose h2 {
  font-family: Georgia, serif;
  font-size: 22px;
  margin-bottom: 10px;
  color: #fff8e7;
}
.prose h3 {
  font-family: Georgia, serif;
  font-size: 17px;
  margin: 18px 0 6px;
  color: #fff8e7;
}
.prose p, .prose li { font-size: 15px; }
.prose ol li, .prose ul li { margin: 4px 0; }

.foot {
  text-align: center; padding: 20px 16px 28px;
  font-size: 13px; opacity: .6;
}

/* ============== Mobile tuning ============== */
@media (max-width: 720px) {
  .topbar { grid-template-columns: 1fr 1fr; gap: 10px; padding: 10px; }
  .stats { grid-column: 1 / -1; order: 3; }
  .actions { justify-content: flex-end; }
  .btn { padding: 0 12px; min-height: 42px; font-size: 14px; }
  .btn span { display: inline; }
}
@media (max-width: 420px) {
  .btn span { display: none; }
  .btn { padding: 0; width: 42px; justify-content: center; }
  .stat { padding: 4px 8px; min-width: 56px; }
  .stat-value { font-size: 16px; }
  .brand-name { display: none; }
}

/* ============== Reduced motion ============== */
@media (prefers-reduced-motion: reduce) {
  .card { transition: none; }
  .card.hint { animation: none; box-shadow: 0 0 0 4px rgba(255,213,105,.7); }
  .win-overlay, .win-card { animation: none; }
}
