/* ─── Design tokens ─────────────────────────────────────────────────────────── */
:root {
  --bg:         #0f172a;
  --surface:    #1e293b;
  --surface-2:  #334155;
  --surface-3:  #475569;
  --text:       #f1f5f9;
  --text-muted: #94a3b8;
  --accent:     #3b82f6;
  --accent-dk:  #2563eb;
  --radius:     14px;
  --radius-sm:  10px;
  --gap:        12px;
  --pad:        18px;

  /* RAG */
  --green:      #16a34a;
  --green-bg:   #14532d;
  --green-text: #bbf7d0;
  --amber:      #d97706;
  --amber-bg:   #78350f;
  --amber-text: #fde68a;
  --red:        #dc2626;
  --red-bg:     #7f1d1d;
  --red-text:   #fecaca;
}

/* ─── Reset ─────────────────────────────────────────────────────────────────── */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

html { height: 100%; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  min-height: 100%;
  overscroll-behavior-y: none;
}

/* ─── Layout ─────────────────────────────────────────────────────────────────── */
#app {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100svh;
  display: flex;
  flex-direction: column;
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--surface);
  border-bottom: 1px solid var(--surface-2);
  padding: 14px var(--pad);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.app-header h1 {
  font-size: 1.15rem;
  font-weight: 800;
  letter-spacing: -0.4px;
}

.game-badge {
  background: var(--surface-2);
  color: var(--text-muted);
  font-size: 0.75rem;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: 999px;
}

.main-content {
  flex: 1;
  padding: var(--pad);
  display: flex;
  flex-direction: column;
  gap: var(--gap);
  padding-bottom: calc(var(--pad) + env(safe-area-inset-bottom));
}

/* ─── Panels ─────────────────────────────────────────────────────────────────── */
.panel {
  background: var(--surface);
  border-radius: var(--radius);
  padding: var(--pad);
}

.panel-label {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1.2px;
  color: var(--text-muted);
  margin-bottom: 10px;
}

.panel-hint {
  font-size: 0.95rem;
  color: var(--text-muted);
  margin-bottom: 14px;
}

/* ─── Counter ────────────────────────────────────────────────────────────────── */
.counter-row {
  display: flex;
  align-items: center;
  gap: 20px;
  margin-bottom: 18px;
}

.counter-btn {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: 2px solid var(--surface-2);
  background: var(--surface-2);
  color: var(--text);
  font-size: 1.6rem;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.12s, border-color 0.12s;
  user-select: none;
}

.counter-btn:active { background: var(--accent); border-color: var(--accent); }
.counter-btn:disabled { opacity: 0.35; cursor: not-allowed; }

.counter-value {
  font-size: 2.5rem;
  font-weight: 800;
  min-width: 44px;
  text-align: center;
  letter-spacing: -1px;
}

/* ─── Buttons ────────────────────────────────────────────────────────────────── */
.btn-primary, .btn-secondary {
  width: 100%;
  padding: 15px;
  border-radius: var(--radius-sm);
  border: none;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.12s, transform 0.08s;
  letter-spacing: 0.1px;
}

.btn-primary {
  background: var(--accent);
  color: #fff;
  margin-top: 14px;
}
.btn-primary:active { background: var(--accent-dk); transform: scale(0.98); }
.btn-primary:disabled { opacity: 0.45; cursor: not-allowed; }

.btn-secondary {
  background: var(--surface-2);
  color: var(--text);
}
.btn-secondary:active { background: var(--surface-3); }

/* ─── Card slots ─────────────────────────────────────────────────────────────── */
.cards-row {
  display: flex;
  gap: 10px;
  justify-content: center;
}

.card-slot {
  width: 74px;
  height: 106px;
  border-radius: 9px;
  border: 2px dashed var(--surface-3);
  background: var(--surface-2);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  position: relative;
  transition: transform 0.1s, border-color 0.12s;
  user-select: none;
}

.card-slot:active { transform: scale(0.94); }

.card-slot.filled {
  background: #fff;
  border: 2px solid #e2e8f0;
  color: #1e293b;
}

.card-slot.filled.red { color: #dc2626; }

.card-plus {
  font-size: 1.6rem;
  color: var(--surface-3);
  font-weight: 300;
}

/* Rank + suit inside filled card */
.c-rank-tl {
  position: absolute;
  top: 5px;
  left: 7px;
  font-size: 1rem;
  font-weight: 800;
  line-height: 1;
}

.c-suit-mid {
  font-size: 2.2rem;
  line-height: 1;
}

.c-rank-br {
  position: absolute;
  bottom: 5px;
  right: 7px;
  font-size: 1rem;
  font-weight: 800;
  line-height: 1;
  transform: rotate(180deg);
}

/* ─── Odds panel ─────────────────────────────────────────────────────────────── */
.odds-panel {
  border-radius: var(--radius);
  padding: 22px var(--pad) 18px;
  text-align: center;
  transition: background 0.3s;
}

/* RAG states */
.odds-panel.rag-green { background: var(--green-bg); color: var(--green-text); }
.odds-panel.rag-amber { background: var(--amber-bg); color: var(--amber-text); }
.odds-panel.rag-red   { background: var(--red-bg);   color: var(--red-text);   }
.odds-panel.rag-loading { background: var(--surface); color: var(--text-muted); }

.odds-pct {
  font-size: 4rem;
  font-weight: 900;
  line-height: 1;
  letter-spacing: -3px;
}

.odds-sub {
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 1.2px;
  opacity: 0.8;
  margin-top: 2px;
}

.odds-action {
  font-size: 1.6rem;
  font-weight: 800;
  margin-top: 12px;
  letter-spacing: -0.5px;
}

.odds-reason {
  font-size: 0.88rem;
  opacity: 0.85;
  margin-top: 4px;
}

.odds-tie {
  font-size: 0.78rem;
  opacity: 0.65;
  margin-top: 6px;
}

.odds-next {
  margin-top: 16px;
  padding: 13px 20px;
  width: 100%;
  border-radius: var(--radius-sm);
  border: 2px solid rgba(255,255,255,0.3);
  background: rgba(255,255,255,0.12);
  color: inherit;
  font-size: 0.95rem;
  font-weight: 700;
  cursor: pointer;
  letter-spacing: 0.2px;
  transition: background 0.12s;
}
.odds-next:active { background: rgba(255,255,255,0.22); }

/* Loading spinner */
.loading-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 10px 0 4px;
  font-size: 0.9rem;
}

.spinner {
  width: 20px;
  height: 20px;
  border: 3px solid rgba(255,255,255,0.2);
  border-top-color: currentColor;
  border-radius: 50%;
  animation: spin 0.75s linear infinite;
  flex-shrink: 0;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ─── Card picker overlay ────────────────────────────────────────────────────── */
.picker-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.65);
  z-index: 100;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.picker-sheet {
  background: var(--surface);
  border-radius: var(--radius) var(--radius) 0 0;
  padding: 12px var(--pad) calc(var(--pad) + env(safe-area-inset-bottom));
  width: 100%;
  max-width: 480px;
  animation: slideUp 0.22s cubic-bezier(.22,1,.36,1);
}

@keyframes slideUp {
  from { transform: translateY(110%); }
  to   { transform: translateY(0); }
}

.sheet-handle {
  width: 36px;
  height: 4px;
  background: var(--surface-3);
  border-radius: 2px;
  margin: 0 auto 14px;
}

.picker-title {
  font-size: 1rem;
  font-weight: 700;
  text-align: center;
  margin-bottom: 16px;
}

.step-label {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1.2px;
  color: var(--text-muted);
  margin-bottom: 10px;
}

/* Suit grid */
.suit-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}

.suit-btn {
  height: 68px;
  border-radius: var(--radius-sm);
  border: 2px solid var(--surface-2);
  background: var(--surface-2);
  font-size: 2.2rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.1s, border-color 0.12s, background 0.12s;
}

.suit-btn.black { color: #f1f5f9; }
.suit-btn.red   { color: #f87171; }
.suit-btn:active { transform: scale(0.93); background: var(--surface-3); }
.suit-btn:disabled { opacity: 0.25; cursor: not-allowed; transform: none; }

/* Rank grid */
.back-link {
  background: none;
  border: none;
  color: var(--accent);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  padding: 0 0 10px;
  display: block;
}

.rank-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 7px;
}

.rank-btn {
  height: 52px;
  border-radius: var(--radius-sm);
  border: 2px solid var(--surface-2);
  background: var(--surface-2);
  color: var(--text);
  font-size: 1.1rem;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.08s, background 0.1s;
}

.rank-btn:active { transform: scale(0.93); background: var(--accent); border-color: var(--accent); }
.rank-btn:disabled { opacity: 0.22; cursor: not-allowed; transform: none; }

/* ─── Players remaining (street counters) ────────────────────────────────────── */
.players-remaining {
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--surface-2);
}

.players-remaining-label {
  display: block;
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1.2px;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.counter-row-sm {
  gap: 14px;
  margin-bottom: 0;
}

.counter-row-sm .counter-btn {
  width: 36px;
  height: 36px;
  font-size: 1.3rem;
}

.counter-row-sm .counter-value {
  font-size: 1.8rem;
  min-width: 32px;
}

/* ─── Utility ─────────────────────────────────────────────────────────────────── */
.hidden { display: none !important; }
