/* ============================================================
   PuppySolitaire — v0 "premium park" look
   Layer cake: scene plate → card stage → character → HUD.
   The scene layer is a gradient placeholder until the art pass.
   ============================================================ */

:root {
  /* set by layout() in game.js; these are fallbacks */
  --card-w: 92px;
  --card-h: 133px;
  --gap: 10px;

  --felt-hi: #4a9d68;
  --felt-lo: #1c5636;
  --ink: #22301f;
  --red: #c9333e;
  --black: #2e2e38;
  --card-face: #fffdf5;
  --back-hi: #ef7f50;
  --back-lo: #c34a2c;
  --chip-bg: rgba(16, 38, 26, 0.45);
  --chip-border: rgba(255, 255, 255, 0.18);
  --radius: calc(var(--card-w) * 0.1);
}

* { margin: 0; padding: 0; box-sizing: border-box; }

[hidden] { display: none !important; }

html, body { height: 100%; }

body {
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  color: #fff;
  overflow-x: hidden;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
  background: var(--felt-lo);
}

/* ---------- scene layer (future 16:9 art plate drops in here) ---------- */
#scene-layer {
  position: fixed;
  inset: 0;
  z-index: 0;
  background:
    radial-gradient(120vmax 70vmax at 50% -20vmax, var(--felt-hi), transparent 60%),
    radial-gradient(90vmax 60vmax at 50% 115%, rgba(0, 0, 0, 0.45), transparent 55%),
    linear-gradient(180deg, #2c7a4d 0%, var(--felt-lo) 70%);
}
/* ambient motif — giant faint emoji signatures per location */
#scene-motif span {
  position: absolute;
  font-size: 24vmin;
  opacity: 0.07;
  filter: saturate(0.5);
  user-select: none;
}
#scene-motif .m1 { top: 5%; left: 2%; transform: rotate(-12deg); }
#scene-motif .m2 { top: 34%; right: 3%; transform: rotate(10deg); font-size: 17vmin; }
#scene-motif .m3 { bottom: 8%; left: 20%; transform: rotate(6deg); font-size: 13vmin; }

#scene-layer::after {
  /* soft sun patch on the "grass" */
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(60vmax 30vmax at 70% 10%, rgba(255, 244, 200, 0.10), transparent 60%);
}

/* ---------- HUD ---------- */
#hud {
  position: relative;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: max(10px, env(safe-area-inset-top)) 14px 8px;
  flex-wrap: wrap;
}

#brand {
  font-size: 22px;
  font-weight: 600;
  letter-spacing: 0.2px;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.35);
  display: flex;
  align-items: center;
  gap: 7px;
}
#brand b { font-weight: 800; }
.brand-paw { filter: drop-shadow(0 2px 3px rgba(0,0,0,.3)); }

#hud-center {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: center;
}

#hud-season {
  background: linear-gradient(150deg, rgba(255, 182, 77, 0.28), rgba(240, 127, 46, 0.28));
  border: 1px solid rgba(255, 200, 120, 0.4);
  border-radius: 999px;
  padding: 6px 14px;
  font-size: 14px;
  font-weight: 700;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  white-space: nowrap;
}

#hud-stats {
  font-variant-numeric: tabular-nums;
  background: var(--chip-bg);
  border: 1px solid var(--chip-border);
  border-radius: 999px;
  padding: 6px 14px;
  font-size: 14px;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}
#hud-stats .dot { opacity: 0.5; margin: 0 6px; }

#hud-buttons { display: flex; gap: 8px; }

button {
  font: inherit;
  color: #fff;
  cursor: pointer;
  border: 1px solid var(--chip-border);
  background: rgba(255, 255, 255, 0.10);
  border-radius: 999px;
  padding: 7px 14px;
  font-size: 14px;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  transition: background 0.15s ease, transform 0.08s ease;
  touch-action: manipulation;
}
button:hover { background: rgba(255, 255, 255, 0.2); }
button:active { transform: scale(0.96); }

/* ---------- table ---------- */
#table {
  position: relative;
  z-index: 1;
  width: min(100%, calc(7 * var(--card-w) + 6 * var(--gap) + 24px));
  margin: 4px auto 40vh;   /* generous bottom room for long tableaus + Meatball */
  padding: 6px 12px;
}

#loc-banner {
  text-align: center;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 2.5px;
  text-transform: uppercase;
  opacity: 0.55;
  margin-bottom: 10px;
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.4);
}

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

.pile {
  position: relative;
  width: var(--card-w);
  min-height: var(--card-h);
  border-radius: var(--radius);
}
.pile:not(.tableau), .pile.tableau {
  background: rgba(0, 0, 0, 0.14);
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.12);
}
.pile-hint {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: calc(var(--card-w) * 0.38);
  color: rgba(255, 255, 255, 0.30);
  font-weight: 700;
}
#pile-stock { cursor: pointer; }

/* ---------- cards ---------- */
.card {
  position: absolute;
  left: 0;
  width: var(--card-w);
  height: var(--card-h);
  border-radius: var(--radius);
  will-change: transform;
}

.card.face-up {
  background: var(--card-face);
  box-shadow:
    0 1px 1px rgba(0, 0, 0, 0.22),
    0 3px 8px rgba(0, 0, 0, 0.18),
    inset 0 0 0 1px rgba(0, 0, 0, 0.06);
  color: var(--black);
}
.card.face-up.red { color: var(--red); }
.card.face-up.grabbable { cursor: grab; }

.card .corner {
  position: absolute;
  display: flex;
  flex-direction: column;
  align-items: center;
  line-height: 1;
  font-weight: 800;
  font-size: calc(var(--card-w) * 0.21);
}
.card .corner .suit-small { font-size: calc(var(--card-w) * 0.19); margin-top: 1px; }
.card .corner.tl { top: calc(var(--card-w) * 0.07); left: calc(var(--card-w) * 0.08); }
.card .corner.br { bottom: calc(var(--card-w) * 0.07); right: calc(var(--card-w) * 0.08); transform: rotate(180deg); }

.card .center {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: calc(var(--card-w) * 0.46);
  opacity: 0.9;
}
.card .center.face-pup { font-size: calc(var(--card-w) * 0.52); }

.card.face-down {
  background: linear-gradient(150deg, var(--back-hi), var(--back-lo));
  box-shadow:
    0 1px 1px rgba(0, 0, 0, 0.25),
    0 3px 8px rgba(0, 0, 0, 0.2),
    inset 0 0 0 1px rgba(0, 0, 0, 0.12);
}
.card.face-down::before {
  content: "";
  position: absolute;
  inset: calc(var(--card-w) * 0.07);
  border: 2px dashed rgba(255, 255, 255, 0.45);
  border-radius: calc(var(--radius) * 0.7);
}
.card.face-down::after {
  content: var(--card-emblem, "🐾");
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: calc(var(--card-w) * 0.36);
  filter: grayscale(1) brightness(3);
  opacity: 0.85;
}

/* drag ghost */
#drag-ghost {
  position: fixed;
  z-index: 50;
  pointer-events: none;
  filter: drop-shadow(0 12px 16px rgba(0, 0, 0, 0.35));
}
#drag-ghost .card { transform: none !important; }

.card.drag-hidden { visibility: hidden; }

/* ---------- finish button ---------- */
#btn-finish {
  position: fixed;
  z-index: 10;
  left: 50%;
  bottom: 26px;
  transform: translateX(-50%);
  font-size: 18px;
  font-weight: 700;
  padding: 12px 26px;
  background: linear-gradient(150deg, #ffb64d, #f07f2e);
  border: none;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.35);
  animation: bounce-in 0.4s ease;
}
@keyframes bounce-in {
  0% { transform: translateX(-50%) scale(0.6); opacity: 0; }
  70% { transform: translateX(-50%) scale(1.08); }
  100% { transform: translateX(-50%) scale(1); opacity: 1; }
}

/* ---------- Meatball (character layer v0) ---------- */
#meatball {
  position: fixed;
  z-index: 20;
  left: 14px;
  bottom: max(14px, env(safe-area-inset-bottom));
  display: flex;
  align-items: flex-end;
  gap: 10px;
  pointer-events: none;
}
#meatball-face {
  width: 54px;
  height: 54px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 32px;
  background: rgba(255, 253, 245, 0.92);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3), inset 0 0 0 3px rgba(240, 127, 46, 0.65);
  pointer-events: auto;
  cursor: pointer;
}
#meatball-bubble {
  max-width: min(280px, 60vw);
  background: #fffdf5;
  color: var(--ink);
  border-radius: 14px 14px 14px 4px;
  padding: 9px 13px;
  font-size: 14px;
  line-height: 1.35;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
  animation: bubble-pop 0.22s ease;
  margin-bottom: 6px;
}
@keyframes bubble-pop {
  from { transform: scale(0.7) translateY(6px); opacity: 0; }
  to { transform: scale(1) translateY(0); opacity: 1; }
}

/* ---------- rival (mirror of Meatball, bottom-right) ---------- */
#rival {
  position: fixed;
  z-index: 20;
  right: 14px;
  bottom: max(14px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: row-reverse;
  align-items: flex-end;
  gap: 10px;
  pointer-events: none;
}
#rival-face {
  width: 54px;
  height: 54px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 26px;
  background: rgba(255, 253, 245, 0.92);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3), inset 0 0 0 3px rgba(90, 90, 120, 0.5);
  pointer-events: auto;
  cursor: pointer;
}
#rival-bubble {
  max-width: min(280px, 60vw);
  background: #fffdf5;
  color: var(--ink);
  border-radius: 14px 14px 4px 14px;
  padding: 9px 13px;
  font-size: 14px;
  line-height: 1.35;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
  animation: bubble-pop 0.22s ease;
  margin-bottom: 6px;
}

/* ---------- overlays ---------- */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  background: rgba(10, 25, 16, 0.55);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  padding: 20px;
}
.panel {
  width: min(400px, 100%);
  background: #fffdf5;
  color: var(--ink);
  border-radius: 22px;
  padding: 24px 22px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.4);
  text-align: center;
}
.panel h2 { margin-bottom: 16px; font-size: 24px; }

.setting { margin: 14px 0; }
.setting-label { font-weight: 700; margin-bottom: 8px; }
.setting-note { font-size: 12px; opacity: 0.6; margin-top: 6px; }

.seg { display: flex; gap: 8px; justify-content: center; }
.seg-btn {
  flex: 1;
  max-width: 150px;
  background: #f0ece0;
  color: var(--ink);
  border: 2px solid transparent;
  border-radius: 14px;
  padding: 10px 8px;
  font-weight: 700;
  backdrop-filter: none;
}
.seg-btn small { display: block; font-weight: 500; opacity: 0.6; }
.seg-btn.active { border-color: #f07f2e; background: #ffe9d6; }

.wide-btn {
  width: 100%;
  background: #f0ece0;
  color: var(--ink);
  border: none;
  border-radius: 14px;
  padding: 12px;
  font-weight: 700;
  margin-top: 8px;
  backdrop-filter: none;
}
.wide-btn.primary { background: linear-gradient(150deg, #ffb64d, #f07f2e); color: #fff; }

.stats-line { font-size: 13px; opacity: 0.7; }
.credit { margin-top: 14px; font-size: 12px; opacity: 0.5; }

.season-host { font-size: 58px; line-height: 1.1; margin-bottom: 4px; }
#season-text { font-size: 14px; opacity: 0.75; margin-top: 4px; line-height: 1.5; }

#season-ladder {
  display: flex;
  justify-content: center;
  align-items: flex-end;
  gap: 3px;
  margin-bottom: 12px;
  padding: 8px 6px;
  background: #f4f0e4;
  border-radius: 12px;
}
.rung {
  font-size: 17px;
  line-height: 1;
  transition: transform 0.15s ease;
}
.rung.locked { filter: grayscale(1); opacity: 0.35; }
.rung.beaten { opacity: 0.85; }
.rung.beaten::after { content: "✓"; font-size: 9px; color: #2e8b57; font-weight: 800; display: block; text-align: center; }
.rung.current {
  font-size: 26px;
  transform: translateY(-2px);
  filter: drop-shadow(0 2px 4px rgba(240, 127, 46, 0.6));
}

.season-rules {
  font-size: 11.5px;
  opacity: 0.55;
  margin-top: 10px;
  line-height: 1.45;
}

.win-panel .win-dog { font-size: 64px; animation: dog-hop 0.7s ease infinite alternate; }
@keyframes dog-hop {
  from { transform: translateY(0) rotate(-4deg); }
  to { transform: translateY(-10px) rotate(4deg); }
}
.win-quip { font-style: italic; opacity: 0.75; margin-top: 8px; font-size: 14px; }
#win-stats { margin-top: 6px; font-weight: 600; }

/* confetti */
.confetti {
  position: fixed;
  z-index: 45;
  top: -40px;
  font-size: 22px;
  pointer-events: none;
  animation: confetti-fall linear forwards;
}
@keyframes confetti-fall {
  to { transform: translateY(110vh) rotate(720deg); opacity: 0.7; }
}

/* card flip pop */
@keyframes flip-pop {
  0% { transform: scaleX(0.15); }
  100% { transform: scaleX(1); }
}
.card.just-flipped { animation: flip-pop 0.18s ease-out; }

/* ---------- responsive ---------- */
@media (max-width: 560px) {
  #brand { font-size: 18px; }
  .btn-label { display: none; }
  #hud-stats { font-size: 12px; padding: 5px 11px; }
  #hud-season { font-size: 12px; padding: 5px 11px; }
  #hud { padding-bottom: 4px; }
  #meatball-face { width: 44px; height: 44px; font-size: 26px; }
  #rival-face { width: 44px; height: 44px; font-size: 20px; }
  #loc-banner { font-size: 11px; letter-spacing: 1.8px; }
  .card .corner { font-weight: 700; }
}
