:root {
  --bg: #0f172a; /* slate-900 */
  --panel: #111827; /* gray-900 */
  --border: #334155; /* slate-700 */
  --text: #e5e7eb; /* gray-200 */
  --muted: #94a3b8; /* slate-400 */
  --accent: #2563eb; /* blue-600 */
  --accent-2: #16a34a; /* green-600 */
  --danger: #dc2626; /* red-600 */
  --chip: #1f2937; /* gray-800 */
}

* {
  box-sizing: border-box;
}
html,
body {
  margin: 0;
  padding: 0;
}
body {
  font-family: system-ui, -apple-system, Segoe UI, Roboto, Ubuntu, Cantarell,
    "Helvetica Neue", Arial;
  background: var(--bg);
  color: var(--text);
  line-height: 1.4;
}

.top {
  text-align: center;
  padding: 24px 16px;
}
.top h1 {
  margin: 0;
  font-size: 28px;
}
.top p {
  color: var(--muted);
  margin-top: 6px;
}

.content {
  width: min(1100px, 92%);
  margin: 0 auto 48px;
  display: grid;
  gap: 16px;
}

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px;
}

.card.big {
  text-align: center;
}

.grid-2 {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 16px;
}

h2 {
  margin: 0 0 12px;
  font-size: 20px;
}
.muted {
  color: var(--muted);
}

.btn {
  display: inline-block;
  appearance: none;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 14px;
  border-radius: 8px;
  cursor: pointer;
  text-decoration: none;
}
.btn:hover {
  border-color: var(--text);
}
.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
}
.btn.primary:hover {
  filter: brightness(1.05);
}
.btn.danger {
  background: var(--danger);
  border-color: var(--danger);
}

.join-form {
  display: grid;
  gap: 8px;
  max-width: 420px;
}
.join-form input[type="text"],
.join-form input[type="number"] {
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #0b1220;
  color: var(--text);
}

.code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono",
    monospace;
  background: var(--chip);
  padding: 2px 6px;
  border-radius: 6px;
}

.ball {
  display: inline-block;
  min-width: 120px;
  padding: 16px 24px;
  border-radius: 50px;
  background: #111827;
  border: 2px solid var(--border);
  font-weight: 700;
  font-size: 28px;
}
.ball.large {
  font-size: 36px;
  min-width: 160px;
}
.ball.largest {
  font-size: 48px;
  min-width: 200px;
}

.called-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.chip {
  background: var(--chip);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 6px 12px;
  font-weight: 600;
}

.controls {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

/* === Win condition pattern previews === */
.win-conditions {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
}
.pattern-card {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px;
  position: relative;
  background: #0b1220;
}
.pattern-card.achieved {
  outline: 2px solid var(--accent-2);
}
.pattern-title {
  font-weight: 700;
  margin-bottom: 8px;
}
.previews-wrap {
  display: grid;
  gap: 8px;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
}
.preview-one {
  display: flex;
  justify-content: center;
}
.pattern-grid {
  display: grid;
  grid-template-columns: repeat(5, 16px);
  gap: 3px;
  padding: 6px;
  background: #0a0f1c;
  border-radius: 6px;
}
.pattern-grid .cell {
  width: 16px;
  height: 16px;
  border: 1px solid #21314e;
  border-radius: 4px;
  background: #0b1220;
}
.pattern-grid .cell.highlight {
  background: #16a34a; /* green spots */
  border-color: #15803d;
}
.achieved-badge {
  position: absolute;
  top: 10px;
  right: 10px;
  background: var(--accent-2);
  color: white;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
}

/* Toggle group for caller actions */
.win-controls {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

/* Simple modal for (re)configuring win conditions */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 50;
}
.modal .panel {
  width: min(720px, 92%);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
}
.modal.show {
  display: flex;
}
.pattern-pickers {
  display: grid;
  gap: 12px;
}
.pattern-picker {
  border: 1px dashed var(--border);
  border-radius: 8px;
  padding: 10px;
}
.pattern-picker .row {
  display: grid;
  gap: 8px;
  grid-template-columns: 1fr;
}
.pattern-picker .preview-slot {
  margin-top: 8px;
}

select.pattern-select,
select#win_count_select {
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #0b1220;
  color: var(--text);
  width: 100%;
}
/* === Called board layout (B I N G O with columns) === */
.called-board {
  display: grid;
  gap: 8px;
}
.called-row {
  display: grid;
  grid-template-columns: 32px 1fr;
  gap: 8px;
  align-items: start;
}
.called-letter {
  font-weight: 800;
  font-size: 20px;
  line-height: 1;
  padding-top: 4px;
}
.called-nums {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.called-nums .num {
  min-width: 34px;
  height: 28px;
  padding: 2px 0;
  border: 1px solid var(--border);
  border-radius: 6px;
  text-align: center;
  font-weight: 700;
  font-size: 14px;
  background: var(--chip);
  color: var(--muted);
}
.called-nums .num.hit {
  background: #0a1f12; /* dark green bg */
  border-color: #15803d;
  color: #22c55e; /* green text */
}
/* === Pattern previews: responsive sizing === */
.win-conditions {
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
}

.pattern-grid {
  --pattern-cell: 16px;
  display: grid;
  grid-template-columns: repeat(5, var(--pattern-cell));
  gap: 3px;
  padding: 6px;
  background: #0a0f1c;
  border-radius: 6px;
}
.pattern-grid .cell {
  width: var(--pattern-cell);
  height: var(--pattern-cell);
  border: 1px solid #21314e;
  border-radius: 4px;
  background: #0b1220;
}
.pattern-grid .cell.highlight {
  background: #16a34a;
  border-color: #15803d;
}

/* === Called board: compact, fluid tokens === */
.called-board {
  display: grid;
  gap: 8px;
}
.called-row {
  display: grid;
  grid-template-columns: 32px 1fr;
  gap: 8px;
  align-items: start;
}
.called-letter {
  font-weight: 800;
  font-size: 20px;
  line-height: 1;
  padding-top: 4px;
}
.called-nums {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.called-nums .num {
  min-width: clamp(24px, 6vw, 34px);
  height: clamp(22px, 5.5vw, 28px);
  padding: 2px 0;
  border: 1px solid var(--border);
  border-radius: 6px;
  text-align: center;
  font-weight: 700;
  font-size: clamp(12px, 3.5vw, 14px);
  background: var(--chip);
  color: var(--muted);
}
.called-nums .num.hit {
  background: #0a1f12;
  border-color: #15803d;
  color: #22c55e;
}

/* === Balls: fluid sizes for mobile === */
.ball {
  min-width: clamp(120px, 40vw, 200px);
  font-size: clamp(24px, 4.5vw, 28px);
}
.ball.large {
  font-size: clamp(28px, 6vw, 36px);
  min-width: clamp(140px, 44vw, 220px);
}
.ball.largest {
  font-size: clamp(32px, 8vw, 48px);
  min-width: clamp(160px, 50vw, 260px);
}

/* Mobile tweaks */
@media (max-width: 600px) {
  .content {
    width: 96%;
  }
  .called-row {
    grid-template-columns: 24px 1fr;
  }
  .called-letter {
    font-size: 18px;
  }
  .pattern-grid {
    --pattern-cell: 12px;
  }
}
@media (max-width: 380px) {
  .win-conditions {
    grid-template-columns: repeat(2, minmax(150px, 1fr));
  }
  .pattern-grid {
    --pattern-cell: 10px;
  }
}
/* ===== Mobile-first base ===== */
html,
body {
  -webkit-text-size-adjust: 100%;
}
body {
  font-size: 16px;
}
.top h1 {
  font-size: clamp(24px, 6.5vw, 32px);
}
.content {
  width: min(1100px, 96%);
}

/* Tap targets + no iOS zoom on inputs */
input,
select,
button {
  font-size: 16px;
}
.btn {
  min-height: 44px;
  padding: 12px 16px;
  font-weight: 700;
}
.join-form input[type="text"],
.join-form input[type="number"],
select.pattern-select,
select#win_count_select {
  min-height: 44px;
  font-size: 16px;
}

/* Show either hero (mobile) or full forms (desktop) */
.mobile-only {
  display: none;
}
.desktop-only {
  display: block;
}
@media (max-width: 720px) {
  .mobile-only {
    display: block;
  }
  .desktop-only {
    display: none !important;
  }
}

/* ===== Landing hero ===== */
.hero .hero-choices {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}
.hero-btn {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--panel);
  padding: 16px;
  text-align: left;
  font-weight: 800;
  display: flex;
  align-items: center;
  gap: 12px;
}
.hero-btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
}
.hero-btn .emoji {
  font-size: 22px;
  line-height: 1;
}
.hero .hero-forms {
  margin-top: 12px;
}
.hidden {
  display: none !important;
}

/* ===== Wizard / Stepper ===== */
.stepper {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin: 0 0 10px 0;
  padding: 0;
  list-style: none;
}
.stepper .step {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: #0b1220;
  color: var(--muted);
  font-weight: 700;
  font-size: 14px;
}
.stepper .step.active {
  color: var(--text);
  border-color: var(--text);
}
.stepper .badge {
  width: 22px;
  height: 22px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--chip);
  border: 1px solid var(--border);
  font-size: 12px;
  font-weight: 800;
}
.stepper .step.active .badge {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
}

.wizard-step {
  display: none;
}
.wizard-step.active {
  display: block;
}
.wizard-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 12px;
}

/* Pattern previews already responsive from previous update */
.win-conditions {
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
}

/* Make ball and called board sizes fluid (already added previously, kept for completeness) */
.ball {
  min-width: clamp(120px, 40vw, 200px);
  font-size: clamp(24px, 4.5vw, 28px);
}
.ball.large {
  font-size: clamp(28px, 6vw, 36px);
  min-width: clamp(140px, 44vw, 220px);
}
.ball.largest {
  font-size: clamp(32px, 8vw, 48px);
  min-width: clamp(160px, 50vw, 260px);
}

@media (max-width: 600px) {
  .content {
    width: 94%;
  }
}
.loading-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.35);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 100;
}
.loading-overlay.show {
  display: flex;
}
.spinner {
  width: 38px;
  height: 38px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}
@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}
/* === Last 5 balls strip === */
.last5 {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
}
.last-chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: clamp(44px, 14vw, 64px);
  height: clamp(36px, 11vw, 44px);
  padding: 0 10px;
  border-radius: 999px;
  font-weight: 800;
  border: 1px solid var(--border);
  background: #0b1220;
  color: var(--text);
  font-size: clamp(16px, 4.5vw, 18px);
}
.last-chip.latest {
  outline: 2px solid var(--accent);
}
