:root {
  --felt-1: #1c6b45;
  --felt-2: #0f4a30;
  --ink: #16241c;
  --cream: #fff7e8;
  --accent: #ffb300;
  --accent-dark: #c98600;
  --red: #c62828;
  --black: #1a1a1a;

  --font-display: "Baloo 2", "Segoe UI", sans-serif;
  --font-body: "Poppins", "Segoe UI", sans-serif;

  --card-w: clamp(34px, 11.2vw, 96px);
  --card-h: calc(var(--card-w) * 1.4);
  --overlap-up: calc(var(--card-h) * 0.30);
  --overlap-down: calc(var(--card-h) * 0.13);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  font-family: var(--font-body);
  background: var(--felt-2);
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

.game-frame {
  position: relative;
  width: 100vw;
  height: calc(100vh - 48px);
  height: calc(100dvh - 48px);
  overflow: hidden;
}

html.ksz-fullscreen .game-frame {
  height: 100vh;
  height: 100dvh;
}

.play-area {
  position: relative;
  width: 100%;
  height: 100%;
  background:
    radial-gradient(ellipse at 50% 0%, var(--felt-1), var(--felt-2) 75%);
}

.hidden { display: none !important; }

/* ---------------- Screens ---------------- */
.screen {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  overflow-y: auto;
}

.start-content {
  max-width: 560px;
  text-align: center;
  color: var(--cream);
}

.brand-title {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: clamp(2.4rem, 8vw, 4rem);
  letter-spacing: 2px;
  color: var(--accent);
  text-shadow: 0 3px 0 rgba(0,0,0,0.35);
  margin: 0 0 18px;
}

.hint {
  font-size: 0.98rem;
  line-height: 1.6;
  color: rgba(255,247,232,0.9);
  margin: 0 0 28px;
}

.btnrow {
  display: flex;
  gap: 14px;
  justify-content: center;
  flex-wrap: wrap;
}

.btn-primary, .btn-secondary {
  font-family: var(--font-body);
  font-weight: 600;
  font-size: 1rem;
  padding: 14px 28px;
  border-radius: 999px;
  border: none;
  cursor: pointer;
  transition: transform 0.12s ease, filter 0.12s ease;
}

.btn-primary {
  background: var(--accent);
  color: #2b1a00;
  box-shadow: 0 4px 0 var(--accent-dark);
}

.btn-secondary {
  background: transparent;
  color: var(--cream);
  border: 2px solid rgba(255,247,232,0.6);
}

.btn-primary:active, .btn-secondary:active {
  transform: translateY(2px);
}

.btn-primary:hover, .btn-secondary:hover {
  filter: brightness(1.08);
}

/* ---------------- Panels (leaderboard / win) ---------------- */
.panel {
  background: rgba(15, 74, 48, 0.92);
  border: 2px solid rgba(255,255,255,0.15);
  border-radius: 20px;
  padding: 28px 32px;
  max-width: 480px;
  width: 100%;
  text-align: center;
  color: var(--cream);
  box-shadow: 0 12px 32px rgba(0,0,0,0.4);
}

.panel-title {
  font-family: var(--font-display);
  color: var(--accent);
  font-size: 1.8rem;
  margin: 0 0 18px;
}

.win-time {
  font-size: 1.05rem;
  margin: 0 0 20px;
}

.leaderboard-list {
  list-style: none;
  margin: 0 0 22px;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 40vh;
  overflow-y: auto;
}

.leaderboard-list li {
  display: grid;
  grid-template-columns: 2em 1fr auto auto;
  gap: 10px;
  align-items: center;
  background: rgba(255,255,255,0.06);
  border-radius: 10px;
  padding: 8px 12px;
  font-size: 0.92rem;
}

.lb-rank { color: var(--accent); font-weight: 700; text-align: left; }
.lb-name { text-align: left; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lb-score { font-weight: 600; }
.lb-time { color: rgba(255,247,232,0.7); }

.highscore-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin: 0 0 20px;
}

.highscore-form label {
  font-size: 0.9rem;
  text-align: left;
}

.highscore-form input {
  font-family: var(--font-body);
  font-size: 1rem;
  padding: 10px 14px;
  border-radius: 10px;
  border: 2px solid rgba(255,255,255,0.2);
  background: rgba(255,255,255,0.08);
  color: var(--cream);
}

.highscore-form input:focus {
  outline: none;
  border-color: var(--accent);
}

/* ---------------- Fullscreen button ---------------- */
.fullscreen-btn {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 50;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: none;
  background: rgba(0,0,0,0.35);
  color: var(--cream);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
.fullscreen-btn svg { width: 20px; height: 20px; }
.fullscreen-icon--exit { display: none; }
.fullscreen-btn.is-fullscreen .fullscreen-icon--enter { display: none; }
.fullscreen-btn.is-fullscreen .fullscreen-icon--exit { display: block; }

/* ---------------- HUD ---------------- */
.hud {
  position: absolute;
  top: 8px;
  left: 8px;
  right: 60px;
  display: flex;
  align-items: center;
  gap: 10px;
  z-index: 40;
}

.hud-pill {
  background: rgba(0,0,0,0.3);
  border-radius: 999px;
  padding: 6px 16px;
  display: flex;
  gap: 8px;
  align-items: baseline;
  color: var(--cream);
}

.hud-label { font-size: 0.72rem; opacity: 0.75; }
.hud-value { font-family: var(--font-display); font-weight: 700; font-size: 1rem; }

.hud-controls { margin-left: auto; display: flex; gap: 8px; }

.hud-icon-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: none;
  background: rgba(0,0,0,0.3);
  color: var(--cream);
  font-size: 1.1rem;
  cursor: pointer;
}
.hud-icon-btn:active { transform: translateY(1px); }

/* ---------------- Board ---------------- */
#screen-game { align-items: stretch; padding: 0; }

.board {
  width: 100%;
  height: 100%;
  padding: 56px 3vw 16px;
  display: flex;
  flex-direction: column;
  gap: clamp(12px, 3vh, 32px);
}

.board-row {
  display: flex;
  gap: clamp(6px, 1.6vw, 18px);
}

.board-row--top {
  justify-content: flex-start;
}

.board-row--top .spacer {
  flex: 1;
}

.board-row--tableau {
  flex: 1;
  justify-content: space-between;
}

.pile {
  position: relative;
  width: var(--card-w);
  height: var(--card-h);
  border-radius: 8px;
  border: 2px dashed rgba(255,255,255,0.25);
  flex-shrink: 0;
}

.pile.tableau {
  height: 100%;
  border-style: dashed;
}

.foundation::before {
  content: attr(data-suit-symbol);
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: calc(var(--card-w) * 0.5);
  color: rgba(255,255,255,0.18);
}

.card {
  position: absolute;
  left: 0;
  top: 0;
  width: var(--card-w);
  height: var(--card-h);
  border-radius: 8px;
  background-size: cover;
  background-position: center;
  box-shadow: 0 2px 4px rgba(0,0,0,0.35);
  transition: top 0.12s ease, left 0.12s ease;
}

.card.face-up[data-pile^="tableau"],
.card.face-up[data-pile="waste"],
.card.face-up[data-pile^="foundation"] {
  cursor: grab;
}

.card.dragging {
  cursor: grabbing;
  transition: none;
  box-shadow: 0 10px 22px rgba(0,0,0,0.5);
}

.card.ghost {
  position: fixed;
  z-index: 500;
  pointer-events: none;
  transition: none;
  box-shadow: 0 14px 26px rgba(0,0,0,0.55);
}

.stock {
  cursor: pointer;
}

.stock .card { cursor: pointer; }

.stock-empty-mark {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: rgba(255,255,255,0.3);
  font-size: calc(var(--card-w) * 0.4);
}

@media (max-width: 640px) {
  .board { padding: 60px 1.5vw 10px; }
  .board-row { gap: clamp(3px, 1.2vw, 18px); }
  .hint { font-size: 0.88rem; }
}
