/* Solitaire — Klondike, matches portal dark theme */
:root {
  --bg: #0f0f1a;
  --bg-2: #1a1a2e;
  --bg-3: #232342;
  --bg-4: #2a2a4a;
  --accent: #e94560;
  --accent-2: #ff6b6b;
  --gold: #ffd54a;
  --green: #4caf50;
  --green-2: #66bb6a;
  --text: #e8e8f0;
  --text-dim: #9999b3;
  --border: #2a2a4a;
  --shadow: 0 8px 30px rgba(0,0,0,0.45);
  --red: #e94560;
  --black: #1a1a2e;
  --card-w: 78px;
  --card-h: 110px;
  --card-radius: 9px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: contain;
}

.container { max-width: 1100px; margin: 0 auto; padding: 0 1rem; }

.header-row {
  display: flex; align-items: center; justify-content: space-between;
  gap: 1rem; flex-wrap: wrap;
}

.subtitle { color: var(--text-dim); font-size: 0.95rem; margin-top: 0.25rem; }

.back-link {
  color: var(--text); text-decoration: none; padding: 0.5rem 0.9rem;
  border-radius: 8px; background: var(--bg-2); border: 1px solid var(--border);
  font-size: 0.9rem; transition: all 0.15s ease;
}
.back-link:hover { background: var(--bg-3); border-color: var(--accent); color: var(--accent); }

.game-shell {
  background: var(--bg-2); border-radius: 16px; padding: 1.25rem;
  margin: 1.5rem 0; box-shadow: var(--shadow); border: 1px solid var(--border);
}

/* HUD */
.hud {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 0.75rem;
  margin-bottom: 1rem;
}
.hud-cell {
  background: var(--bg-3); border: 1px solid var(--border);
  border-radius: 10px; padding: 0.5rem 0.75rem; text-align: center;
}
.hud-label { color: var(--text-dim); font-size: 0.72rem; letter-spacing: 0.08em; text-transform: uppercase; }
.hud-value { color: var(--text); font-size: 1.4rem; font-weight: 700; margin-top: 0.1rem; }

/* Toolbar */
.toolbar {
  display: flex; flex-wrap: wrap; gap: 0.5rem;
  margin-bottom: 1rem; align-items: center;
}

.btn {
  background: var(--bg-3); color: var(--text); border: 1px solid var(--border);
  padding: 0.55rem 1rem; border-radius: 8px; cursor: pointer;
  font-size: 0.92rem; font-weight: 600; transition: all 0.15s ease;
}
.btn:hover:not(:disabled) { background: var(--bg-4); border-color: var(--accent); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: white; }
.btn.primary:hover:not(:disabled) { background: var(--accent-2); border-color: var(--accent-2); }
.btn.danger { background: #c0392b; border-color: #c0392b; color: white; }
.btn.danger:hover { background: #d94e3f; border-color: #d94e3f; }

.draw-toggle {
  display: inline-flex; background: var(--bg-3); border: 1px solid var(--border);
  border-radius: 8px; padding: 3px; gap: 3px; margin-left: auto;
}
.toggle-btn {
  background: transparent; color: var(--text-dim); border: none;
  padding: 0.4rem 0.75rem; border-radius: 6px; cursor: pointer;
  font-size: 0.85rem; font-weight: 600; transition: all 0.15s ease;
}
.toggle-btn.active { background: var(--accent); color: white; }
.toggle-btn:hover:not(.active) { color: var(--text); }

/* Board */
.board {
  background: linear-gradient(135deg, #0c1d3e 0%, #0a1530 100%);
  border-radius: 12px; padding: 1rem; border: 1px solid var(--border);
  user-select: none; -webkit-user-select: none;
}

.top-row {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 0.6rem;
  margin-bottom: 1.25rem;
}

.slot, .column {
  width: 100%;
  aspect-ratio: 5 / 7;
  border-radius: var(--card-radius);
  position: relative;
}

.slot {
  background: rgba(255,255,255,0.04);
  border: 2px dashed rgba(255,255,255,0.1);
}
.slot.highlight-valid { border-color: var(--green); background: rgba(76,175,80,0.15); }
.slot.highlight-hint   { border-color: var(--gold); background: rgba(255,213,74,0.18); box-shadow: 0 0 14px rgba(255,213,74,0.4); }
.slot.highlight-empty  { border-style: solid; }

.slot .empty-label {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  color: rgba(255,255,255,0.18); font-size: 1.6rem; font-weight: 700;
}

.slot.foundation[data-fdn="0"] .empty-label::before { content: "♠"; color: rgba(180,180,200,0.25); }
.slot.foundation[data-fdn="1"] .empty-label::before { content: "♥"; color: rgba(233,69,96,0.30); }
.slot.foundation[data-fdn="2"] .empty-label::before { content: "♦"; color: rgba(233,69,96,0.30); }
.slot.foundation[data-fdn="3"] .empty-label::before { content: "♣"; color: rgba(180,180,200,0.25); }

.slot.foundation .empty-label::before {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 2.6rem;
}

.spacer { width: 100%; }

/* Tableau columns */
.tableau {
  display: grid; grid-template-columns: repeat(7, 1fr); gap: 0.6rem;
}

.column {
  background: rgba(255,255,255,0.03);
  border: 2px dashed rgba(255,255,255,0.08);
  position: relative;
  aspect-ratio: auto;
  min-height: calc(var(--card-h) * 1.4);
}
.column.highlight-valid { border-color: var(--green); background: rgba(76,175,80,0.10); }
.column.highlight-hint  { border-color: var(--gold); background: rgba(255,213,74,0.10); }

/* Cards */
.card {
  position: absolute;
  width: var(--card-w);
  height: var(--card-h);
  border-radius: var(--card-radius);
  background: linear-gradient(180deg, #fdfdfd 0%, #f0f0f5 100%);
  border: 1px solid #c0c0c8;
  box-shadow: 0 2px 4px rgba(0,0,0,0.35);
  display: flex; flex-direction: column;
  padding: 6px 8px;
  cursor: grab;
  font-family: 'Georgia', serif;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
  user-select: none; -webkit-user-select: none;
  touch-action: none;
}
.card:hover { box-shadow: 0 4px 10px rgba(0,0,0,0.5); transform: translateY(-1px); }
.card.dragging {
  cursor: grabbing; z-index: 9999;
  box-shadow: 0 12px 24px rgba(0,0,0,0.7);
  transform: rotate(-2deg);
}
.card.selected {
  outline: 3px solid var(--gold);
  outline-offset: 2px;
  box-shadow: 0 0 18px rgba(255,213,74,0.6), 0 4px 10px rgba(0,0,0,0.5);
}

.card .rank {
  font-size: 1.25rem;
  font-weight: 700;
  line-height: 1;
}
.card .suit {
  font-size: 1rem;
  line-height: 1;
}
.card .suit-large {
  position: absolute;
  bottom: 6px; right: 6px;
  font-size: 1.5rem;
}

.card.red { color: var(--red); }
.card.black { color: #222; }

.card.face-down {
  background: linear-gradient(135deg, #1e3a6e 0%, #0f2552 50%, #1e3a6e 100%);
  border: 1px solid #4a6ab0;
  cursor: grab;
  position: relative;
}
.card.face-down::before {
  content: '';
  position: absolute; inset: 5px;
  border: 2px solid rgba(255,255,255,0.18);
  border-radius: 5px;
  background-image:
    repeating-linear-gradient(45deg,
      rgba(255,255,255,0.05) 0,
      rgba(255,255,255,0.05) 4px,
      transparent 4px,
      transparent 8px),
    radial-gradient(circle at center, rgba(255,255,255,0.05), transparent 60%);
}
.card.face-down::after {
  content: '🂠';
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 2rem; opacity: 0.4; color: white;
}

/* Drag ghost */
.drag-ghost {
  position: fixed;
  pointer-events: none;
  z-index: 99999;
  display: flex; flex-direction: column;
  filter: drop-shadow(0 8px 20px rgba(0,0,0,0.6));
}

/* Status */
.status {
  margin-top: 1rem;
  text-align: center;
  color: var(--text-dim);
  font-size: 0.92rem;
  min-height: 1.4em;
}

/* Modals */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.7);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000;
  animation: fadeIn 0.2s ease;
}
.modal-backdrop.hidden { display: none; }
.modal {
  background: var(--bg-2);
  border-radius: 14px;
  padding: 1.5rem 1.75rem;
  max-width: 90vw;
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  animation: scaleIn 0.25s ease;
}
.modal-wide { width: min(560px, 90vw); }
.modal h2 {
  margin: 0 0 1rem 0;
  background: linear-gradient(135deg, var(--accent), var(--gold));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 1rem;
}
.modal-head h2 { margin: 0; }
.modal-close {
  background: transparent; border: none; color: var(--text-dim);
  font-size: 1.4rem; cursor: pointer; padding: 0.25rem 0.6rem;
  border-radius: 6px;
}
.modal-close:hover { color: var(--accent); background: var(--bg-3); }
.modal-actions {
  display: flex; gap: 0.5rem; justify-content: flex-end; margin-top: 1.25rem;
}

.win-stats {
  background: var(--bg-3); border-radius: 10px; padding: 1rem;
  display: grid; grid-template-columns: repeat(2, 1fr); gap: 0.5rem;
}
.win-stats div { font-size: 0.95rem; }
.win-stats strong { color: var(--gold); }

/* Stats grid */
.stats-grid {
  display: grid; grid-template-columns: repeat(2, 1fr); gap: 0.75rem;
}
.stats-card {
  background: var(--bg-3); border: 1px solid var(--border);
  border-radius: 10px; padding: 0.75rem;
}
.stats-card .lbl { color: var(--text-dim); font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.05em; }
.stats-card .val { color: var(--text); font-size: 1.4rem; font-weight: 700; margin-top: 0.2rem; }
.stats-card.full { grid-column: span 2; }

/* Toast */
.toast-container {
  position: fixed; top: 1rem; right: 1rem;
  display: flex; flex-direction: column; gap: 0.5rem;
  z-index: 1100;
  pointer-events: none;
}
.toast {
  background: var(--bg-2);
  border: 1px solid var(--accent);
  border-left: 4px solid var(--accent);
  color: var(--text);
  padding: 0.7rem 1rem;
  border-radius: 8px;
  font-size: 0.95rem;
  box-shadow: var(--shadow);
  animation: toastIn 0.35s cubic-bezier(0.16, 1, 0.3, 1) both;
  pointer-events: auto;
}
.toast.gold {
  border-color: var(--gold); border-left-color: var(--gold);
  box-shadow: 0 0 18px rgba(255,213,74,0.3);
}
.toast.hide { animation: toastOut 0.3s ease forwards; }

/* Confetti */
.confetti-container {
  position: fixed; inset: 0;
  pointer-events: none;
  z-index: 1200;
  overflow: hidden;
}
.confetti {
  position: absolute;
  top: -10px;
  width: 10px; height: 14px;
  opacity: 0.9;
  animation: confettiFall linear forwards;
}

/* Animations */
@keyframes fadeIn { from { opacity: 0 } to { opacity: 1 } }
@keyframes scaleIn { from { transform: scale(0.85); opacity: 0 } to { transform: scale(1); opacity: 1 } }
@keyframes toastIn {
  from { transform: translateX(120%); opacity: 0; }
  to   { transform: translateX(0); opacity: 1; }
}
@keyframes toastOut {
  to { transform: translateX(120%); opacity: 0; }
}
@keyframes confettiFall {
  to { transform: translateY(110vh) rotate(720deg); }
}

/* Responsive */
@media (max-width: 900px) {
  :root { --card-w: 50px; --card-h: 70px; }
  .top-row, .tableau { gap: 0.35rem; }
  .card { padding: 3px 4px; }
  .card .rank { font-size: 0.85rem; }
  .card .suit { font-size: 0.7rem; }
  .card .suit-large { font-size: 1rem; bottom: 2px; right: 3px; }
  .hud { grid-template-columns: repeat(2, 1fr); }
  .draw-toggle { margin-left: 0; }
  .toolbar { flex-direction: column; align-items: stretch; }
  .draw-toggle { align-self: flex-start; }
  .column { min-height: calc(var(--card-h) * 1.6); }
}

@media (max-width: 540px) {
  :root { --card-w: 38px; --card-h: 54px; }
  .top-row, .tableau { gap: 0.25rem; }
  .card .rank { font-size: 0.7rem; }
  .card .suit { font-size: 0.55rem; }
  .card .suit-large { font-size: 0.8rem; }
  .column { min-height: calc(var(--card-h) * 2); }
}
