/* Spit — real-time speed card game. Felt-table look, readable legal-move cues,
   fast and touch-friendly. Themed via [data-theme]. */

:root {
  --bg: #0b1a12;
  --felt-1: #16432c;
  --felt-2: #0f2e1e;
  --ink: #f3f7f1;
  --muted: rgba(243, 247, 241, 0.62);
  --card-bg: #fbfaf5;
  --card-red: #c8324b;
  --card-black: #232a2e;
  --card-back: linear-gradient(135deg, #2b6b47, #16432c);
  --accent: #ffd35c;
  --glow: rgba(255, 211, 92, 0.85);
  --panel: rgba(8, 20, 14, 0.55);
  --border: rgba(255, 255, 255, 0.12);
  --radius: 12px;
}

[data-theme="light"] {
  --bg: #e9efe7;
  --felt-1: #2f8a5a;
  --felt-2: #1f6b44;
  --ink: #14241a;
  --muted: rgba(20, 36, 26, 0.6);
  --panel: rgba(255, 255, 255, 0.55);
  --border: rgba(0, 0, 0, 0.12);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
}

body {
  background: radial-gradient(circle at 50% 25%, var(--felt-1), var(--felt-2) 60%, var(--bg));
  color: var(--ink);
  font-family: Inter, system-ui, -apple-system, sans-serif;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.game-shell {
  height: 100dvh;
  max-width: 720px;
  margin: 0 auto;
  padding: 10px clamp(10px, 3vw, 20px) 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* ---- top bar / hero ---- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.potato-home-link {
  color: var(--muted);
  text-decoration: none;
  font-weight: 650;
  font-size: 0.82rem;
}
.toolbar { display: flex; gap: 6px; }
.icon-button {
  background: var(--panel);
  border: 1px solid var(--border);
  color: var(--ink);
  width: 38px; height: 38px;
  border-radius: 10px;
  font-size: 1rem;
  cursor: pointer;
}
.icon-button:hover { filter: brightness(1.15); }

.hero {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.eyebrow {
  margin: 0;
  font-size: 0.66rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--muted);
}
#game-title {
  margin: 0;
  font-size: clamp(1.4rem, 5vw, 2rem);
  line-height: 1;
}
.hero > div:first-child { display: none; } /* spacer not needed; title group implicit */
.stats { display: flex; gap: 10px; }
.stat {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 5px 12px;
  text-align: center;
  min-width: 52px;
}
.stat-label {
  display: block;
  font-size: 0.6rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}
.stat-value { font-size: 1.15rem; }

/* ---- table layout ---- */
.table {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 8px;
  padding: 6px 0;
}

.player-row {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.row-label {
  font-size: 0.66rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
}
.opponent .row-label { order: -1; }

.hand {
  display: flex;
  align-items: center;
  gap: clamp(6px, 2vw, 12px);
}
.field {
  display: flex;
  gap: clamp(6px, 2vw, 12px);
  flex: 1;
}
.you .hand { flex-direction: row; }
.opponent .hand { flex-direction: row-reverse; }

/* ---- center piles ---- */
.center-row {
  position: relative;
  display: flex;
  justify-content: center;
  gap: clamp(16px, 6vw, 40px);
  padding: 6px 0;
}
.center-pile {
  border-radius: var(--radius);
}

/* ---- cards ---- */
.card {
  position: relative;
  aspect-ratio: 5 / 7;
  width: clamp(48px, 13.5vw, 78px);
  border-radius: var(--radius);
  background: var(--card-bg);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.35);
  flex: 0 0 auto;
  overflow: hidden;
  transition: transform 0.09s ease, box-shadow 0.12s ease;
}
.field .card { width: clamp(48px, 14vw, 80px); }
.center-pile .card { width: clamp(58px, 17vw, 92px); }

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

.card .corner {
  position: absolute;
  display: flex;
  flex-direction: column;
  align-items: center;
  font-weight: 800;
  font-size: clamp(0.7rem, 2.6vw, 1rem);
  line-height: 1;
}
.card .corner.tl { top: 5px; left: 6px; }
.card .corner.br { bottom: 5px; right: 6px; transform: rotate(180deg); }
.card .corner i { width: 0.7em; height: 0.7em; display: block; margin-top: 1px; }
.card .corner svg { width: 100%; height: 100%; fill: currentColor; }

.card .pip {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}
.card .pip svg { width: 42%; height: 42%; fill: currentColor; opacity: 0.92; }

.card.back {
  background: var(--card-back);
  border: 2px solid rgba(255, 255, 255, 0.25);
}
.card.back::after {
  content: "";
  position: absolute;
  inset: 6px;
  border-radius: 7px;
  background-image: repeating-linear-gradient(45deg, rgba(255,255,255,0.12) 0 6px, transparent 6px 12px);
}

.slot-empty {
  background: transparent;
  border: 2px dashed var(--border);
  box-shadow: none;
}

/* playable cue */
.card.playable {
  cursor: pointer;
  box-shadow: 0 0 0 3px var(--glow), 0 4px 14px rgba(0, 0, 0, 0.4);
  animation: pulse 1.1s ease-in-out infinite;
}
.card.playable:hover { transform: translateY(-5px); }
.card.playable:active { transform: translateY(-2px) scale(0.97); }
@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 3px var(--glow), 0 4px 14px rgba(0,0,0,0.4); }
  50% { box-shadow: 0 0 0 5px var(--glow), 0 4px 18px rgba(0,0,0,0.5); }
}

/* ---- stock ---- */
.stock-wrap { display: flex; }
.stock { position: relative; }
.stock-count {
  position: absolute;
  bottom: -6px;
  right: -6px;
  background: var(--accent);
  color: #1a1a1a;
  font-weight: 800;
  font-size: 0.7rem;
  min-width: 20px;
  height: 20px;
  padding: 0 5px;
  border-radius: 999px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 1px 4px rgba(0,0,0,0.4);
}

/* ---- start overlay ---- */
.start-overlay {
  position: absolute;
  inset: -8px -10px;
  display: flex;
  align-items: center;
  justify-content: center;
  width: auto;
  padding: 0;
  background: rgba(6, 16, 11, 0.55);
  backdrop-filter: blur(2px);
  border-radius: var(--radius);
  border: 0;
  appearance: none;
  color: inherit;
  font: inherit;
  cursor: pointer;
  z-index: 5;
}
.start-overlay.hidden { display: none; }
.start-overlay:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 3px;
}
.start-card {
  text-align: center;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 16px 22px;
  max-width: 320px;
}
.start-card strong { display: block; font-size: 1.3rem; margin-bottom: 6px; }
.start-card span { font-size: 0.82rem; color: var(--muted); }

/* ---- status / actions ---- */
.game-status {
  margin: 0;
  text-align: center;
  font-size: 0.88rem;
  color: var(--muted);
  min-height: 1.2em;
}
.game-status.spit { color: var(--accent); font-weight: 700; }

.game-actions { display: flex; justify-content: center; }
.action-button {
  background: var(--panel);
  border: 1px solid var(--border);
  color: var(--ink);
  padding: 9px 18px;
  border-radius: 10px;
  font-weight: 650;
  font-size: 0.9rem;
  cursor: pointer;
}
.action-button:hover { filter: brightness(1.15); }
.action-button.primary { background: var(--accent); color: #1a1a1a; border-color: transparent; }

.cloud-status { margin: 0; text-align: center; font-size: 0.7rem; color: var(--muted); min-height: 0.9em; }

/* ---- result dialog ---- */
.result-dialog {
  border: none;
  background: transparent;
  padding: 0;
}
.result-dialog::backdrop { background: rgba(4, 10, 7, 0.6); backdrop-filter: blur(3px); }
.result-card {
  background: var(--felt-2);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 24px 28px;
  width: min(86vw, 360px);
  text-align: center;
  color: var(--ink);
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.5);
}
.result-kicker {
  margin: 0;
  font-size: 0.66rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--muted);
}
.result-card h2 { margin: 4px 0 6px; font-size: 1.5rem; }
.result-summary { margin: 0 0 16px; color: var(--muted); font-size: 0.9rem; }
.result-grid {
  display: flex;
  justify-content: center;
  gap: 22px;
  margin-bottom: 18px;
}
.result-grid strong { display: block; font-size: 1.5rem; }
.result-grid span { font-size: 0.66rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); }
.result-actions { display: flex; gap: 10px; justify-content: center; }

@media (max-width: 380px) {
  .stat { min-width: 44px; padding: 4px 8px; }
  .hero { flex-wrap: wrap; }
}

@media (max-width: 640px) {
  .game-shell {
    padding-bottom: calc(64px + env(safe-area-inset-bottom));
  }
}

@media (prefers-reduced-motion: reduce) {
  .card.playable { animation: none; }
  .card { transition: none; }
}
