/* ===== BASE STYLES ===== */
* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --card-w: 100px;
  --card-h: 140px;
  --card-r: 8px;
  --card-offset: 28px;
  --card-offset-down: 10px;
  --bg: #0a0e17;
  --text: #eee;
  --header-bg: rgba(0,0,0,0.6);
  --accent: #e11d48;
  --slot-border: rgba(255,255,255,0.15);
  --card-face: #fff;
  --card-shadow: 0 2px 8px rgba(0,0,0,0.35);
  --font-rank: 16px;
  --font-suit-sm: 14px;
  --font-center: 36px;
  --tl-top: 5px;
  --tl-left: 7px;
}

html, body { height: 100%; overflow-x: hidden; overflow-y: auto; }

body {
  font-family: 'Inter', sans-serif;
  background: var(--bg);
  color: var(--text);
  transition: background 0.4s, color 0.4s;
  -webkit-tap-highlight-color: transparent;
}

#root { display: flex; flex-direction: column; min-height: 100%; }

/* ===== HEADER ===== */
header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 12px 28px;
  background: var(--header-bg);
  backdrop-filter: blur(12px);
  box-shadow: 0 4px 20px rgba(0,0,0,0.4);
  z-index: 100;
  flex-shrink: 0;
  flex-wrap: wrap;
  gap: 8px;
}
header h1 { font-size: 22px; letter-spacing: 2px; text-transform: uppercase; white-space: nowrap; }
.header-controls { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

select, .btn {
  padding: 8px 16px;
  border-radius: 6px;
  border: 1px solid #444;
  background: #1a1a2e;
  color: #fff;
  font-size: 14px;
  cursor: pointer;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
  font-family: inherit;
}
select:hover, .btn:hover { border-color: #888; }
.btn-new { background: var(--accent); border-color: var(--accent); font-weight: 600; }
.btn-new:hover { background: #be123c; }
.btn-hint { background: #2563eb; border-color: #2563eb; font-weight: 600; }
.btn-hint:hover { background: #1d4ed8; }

/* ===== GAME BOARD ===== */
.board {
  flex: 1;
  display: flex; flex-direction: column;
  padding: 20px 24px 16px;
  gap: 16px;
  max-width: 1200px;
  margin: 0 auto; width: 100%;
}

.top-bar {
  display: flex; justify-content: space-between; align-items: center;
  min-height: 40px;
  flex-wrap: wrap;
  gap: 10px;
}
.stock-area { display: flex; gap: 12px; align-items: center; }
.info-bar { display: flex; gap: 24px; font-size: 15px; font-weight: 600; }
.info-bar span { opacity: 0.7; }
.completed-area { display: flex; gap: 5px; }

/* ===== SLOTS ===== */
.slot {
  width: var(--card-w);
  height: var(--card-h);
  border: 2px dashed var(--slot-border);
  border-radius: var(--card-r);
  background: rgba(255,255,255,0.03);
  flex-shrink: 0;
}

/* ===== TABLEAU ===== */
.tableau { display: flex; gap: 10px; justify-content: center; }
.pile { position: relative; width: var(--card-w); flex-shrink: 0; min-height: var(--card-h); }

/* ===== CARDS ===== */
.card {
  width: var(--card-w);
  height: var(--card-h);
  border-radius: var(--card-r);
  position: absolute; left: 0;
  display: flex; flex-direction: column;
  font-weight: 700;
  user-select: none;
  cursor: grab;
  box-shadow: var(--card-shadow);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.card:active { cursor: grabbing; }

/* Face-up */
.card.face {
  background: var(--card-face);
  border: 1px solid rgba(0,0,0,0.12);
}
.card.face.red   { color: #dc2626; }
.card.face.black { color: #1e293b; }

.card .tl {
  position: absolute; top: var(--tl-top); left: var(--tl-left);
  display: flex; flex-direction: column; align-items: center;
  font-size: var(--font-rank); line-height: 1.15;
}
.card .tl .suit-sm { font-size: var(--font-suit-sm); }
.card .br {
  position: absolute; bottom: var(--tl-top); right: var(--tl-left);
  display: flex; flex-direction: column; align-items: center;
  font-size: var(--font-rank); line-height: 1.15;
  transform: rotate(180deg);
}
.card .br .suit-sm { font-size: var(--font-suit-sm); }
.card .center-suit {
  position: absolute; top: 50%; left: 50%;
  transform: translate(-50%,-50%);
  font-size: var(--font-center); opacity: 0.45;
}

/* Face-down */
.card.back {
  background: #2a2a3e;
  background-size: cover;
  background-position: center;
  border: 1px solid rgba(255,255,255,0.08);
  cursor: default;
}

/* Selected (tap-to-move) */
.card.selected {
  outline: 3px solid #facc15;
  outline-offset: -1px;
  transform: translateY(-6px);
  box-shadow: 0 8px 20px rgba(250,204,21,0.4) !important;
  z-index: 8500 !important;
}

/* Dragging */
.card.dragging {
  opacity: 0.85;
  transform: scale(1.06) !important;
  box-shadow: 0 12px 30px rgba(0,0,0,0.5) !important;
  z-index: 9999 !important;
}

/* Stock deck clickable */
.stock-pile { cursor: pointer; position: relative; width: var(--card-w); height: var(--card-h); }
.stock-pile .card { cursor: pointer; }

/* Completed mini card */
.completed-card {
  width: 36px; height: 50px; border-radius: 4px;
  background: #22c55e; border: 1px solid #16a34a;
  display: flex; align-items: center; justify-content: center;
  font-size: 16px; color: #fff; font-weight: 800;
}

/* Drop highlight */
.pile.drop-highlight > .slot,
.pile.drop-highlight > .card:last-child {
  outline: 2px solid #22c55e;
  outline-offset: -2px;
}

/* Hint highlight */
@keyframes hintPulse {
  0%   { box-shadow: 0 0 0 0 rgba(37,99,235,0.7); }
  50%  { box-shadow: 0 0 16px 6px rgba(37,99,235,0.5); }
  100% { box-shadow: 0 0 0 0 rgba(37,99,235,0.0); }
}
.card.hint-src {
  outline: 3px solid #3b82f6;
  outline-offset: -1px;
  animation: hintPulse 1s ease-in-out 3;
  z-index: 8000 !important;
}
@keyframes hintPulseDst {
  0%   { box-shadow: 0 0 0 0 rgba(34,197,94,0.7); }
  50%  { box-shadow: 0 0 16px 6px rgba(34,197,94,0.5); }
  100% { box-shadow: 0 0 0 0 rgba(34,197,94,0.0); }
}
.card.hint-dst, .slot.hint-dst {
  outline: 3px solid #22c55e;
  outline-offset: -1px;
  animation: hintPulseDst 1s ease-in-out 3;
  z-index: 7999 !important;
}

/* Win overlay */
.win-overlay {
  position: fixed; inset: 0; z-index: 10000;
  background: rgba(0,0,0,0.85);
  display: flex; align-items: center; justify-content: center; flex-direction: column;
  gap: 20px;
  animation: fadeIn 0.5s ease;
  padding: 20px;
}
.win-overlay h2 { font-size: 48px; }
.win-overlay .emoji { font-size: 80px; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

/* Stock empty */
.stock-empty {
  width: var(--card-w); height: var(--card-h);
  border: 2px dashed var(--slot-border);
  border-radius: var(--card-r);
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; opacity: 0.4; text-align: center;
}

/* Toast */
.toast {
  position: fixed; bottom: 30px; left: 50%; transform: translateX(-50%);
  padding: 12px 28px; border-radius: 10px;
  font-size: 15px; font-weight: 600; z-index: 99999;
  box-shadow: 0 4px 20px rgba(0,0,0,0.4);
  animation: fadeIn 0.3s ease;
  transition: opacity 0.3s;
  max-width: 90vw; text-align: center;
}
.toast-error { background: #ef4444; color: #fff; }
.toast-hint  { background: #2563eb; color: #fff; }

/* ================================================================
   RESPONSIVE — TABLET (≤1024px)
   ================================================================ */
@media (max-width: 1024px) {
  :root {
    --card-w: 80px;
    --card-h: 112px;
    --card-r: 6px;
    --card-offset: 24px;
    --card-offset-down: 8px;
    --font-rank: 14px;
    --font-suit-sm: 12px;
    --font-center: 28px;
    --tl-top: 4px;
    --tl-left: 5px;
  }
  header { padding: 10px 16px; }
  header h1 { font-size: 18px; letter-spacing: 1px; }
  select, .btn { padding: 6px 12px; font-size: 12px; }
  .board { padding: 14px 12px 10px; gap: 12px; }
  .tableau { gap: 6px; }
  .info-bar { font-size: 13px; gap: 16px; }
  .completed-card { width: 28px; height: 40px; font-size: 13px; }
}

/* ================================================================
   RESPONSIVE — PHONE (≤600px)
   ================================================================ */
@media (max-width: 600px) {
  :root {
    --card-w: calc((100vw - 60px) / 10);
    --card-h: calc(var(--card-w) * 1.4);
    --card-r: 4px;
    --card-offset: 18px;
    --card-offset-down: 6px;
    --font-rank: 10px;
    --font-suit-sm: 8px;
    --font-center: 18px;
    --tl-top: 2px;
    --tl-left: 3px;
  }
  header {
    padding: 8px 10px;
    justify-content: center;
  }
  header h1 { font-size: 14px; letter-spacing: 1px; width: 100%; text-align: center; }
  .header-controls { justify-content: center; width: 100%; }
  select, .btn { padding: 5px 8px; font-size: 11px; }
  .board { padding: 8px 6px 6px; gap: 8px; }
  .tableau { gap: 4px; }
  .top-bar { gap: 6px; }
  .info-bar { font-size: 11px; gap: 10px; }
  .completed-card { width: 22px; height: 30px; font-size: 10px; border-radius: 2px; }
  .win-overlay h2 { font-size: 28px; }
  .win-overlay .emoji { font-size: 50px; }
  .toast { font-size: 12px; padding: 8px 16px; bottom: 16px; }
  .card .br { display: none; } /* hide bottom-right on small screens */
}

/* ================================================================
   RESPONSIVE — VERY SMALL PHONE (≤380px)
   ================================================================ */
@media (max-width: 380px) {
  :root {
    --card-w: calc((100vw - 40px) / 10);
    --card-offset: 14px;
    --card-offset-down: 5px;
    --font-rank: 8px;
    --font-suit-sm: 7px;
    --font-center: 14px;
  }
  header h1 { font-size: 12px; }
  .card .center-suit { display: none; }
}
