*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #0f0f1a;
  --surface: #1a1a2e;
  --surface2: #16213e;
  --accent: #f97316;
  --text: #eee;
  --muted: #888;
  --b: #4fc3f7;
  --i: #81c784;
  --n: #ffb74d;
  --g: #f06292;
  --o: #ce93d8;
  --called: #f97316;
  --free: #ffd700;
  --radius: 12px;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  min-height: 100vh;
}

.screen { display: none; }
.screen.active { display: block; }

.container {
  max-width: 480px;
  margin: 0 auto;
  padding: 24px 16px 60px;
}

h1 { font-size: 2rem; text-align: center; margin-bottom: 28px; }
h2 { font-size: 1.3rem; }
h3 { font-size: .8rem; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; margin-bottom: 10px; }

.card-section { margin-bottom: 22px; }
.section-label { display: block; font-size: .75rem; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin-bottom: 8px; }
.hint { font-size: .78rem; color: var(--muted); margin-top: 5px; }

/* Card type toggle */
.card-type-row { display: flex; gap: 8px; margin-top: 2px; }
.card-type-btn {
  flex: 1; background: var(--surface); border: 1px solid #333; border-radius: 8px;
  color: var(--text); padding: 10px; font-size: .95rem; font-weight: 600; cursor: pointer; transition: all .15s;
}
.card-type-btn:hover { border-color: var(--accent); }
.card-type-btn.active { background: var(--accent); border-color: var(--accent); }

/* Inputs */
input[type="password"], input[type="number"], input[type="text"] {
  width: 100%; background: var(--surface); border: 1px solid #333; border-radius: var(--radius);
  color: var(--text); padding: 12px 14px; font-size: 1rem; outline: none; transition: border-color .2s;
}
input:focus { border-color: var(--accent); }

/* Upload */
.upload-area {
  border: 2px dashed #333; border-radius: var(--radius); cursor: pointer;
  position: relative; overflow: hidden; min-height: 110px;
  display: flex; align-items: center; justify-content: center; transition: border-color .2s;
}
.upload-area:hover { border-color: var(--accent); }
.upload-area input[type="file"] { position: absolute; inset: 0; opacity: 0; cursor: pointer; width: 100%; height: 100%; z-index: 2; }
.upload-inner { text-align: center; padding: 20px; pointer-events: none; }
.upload-icon { font-size: 2rem; display: block; margin-bottom: 6px; }
#preview-img { width: 100%; max-height: 220px; object-fit: cover; border-radius: 10px; display: block; }
#preview-img.hidden { display: none; }

/* Pattern */
.pattern-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.pattern-btn {
  background: var(--surface); border: 1px solid #333; border-radius: 8px;
  color: var(--text); padding: 10px; font-size: .9rem; cursor: pointer; transition: all .15s;
}
.pattern-btn:hover { border-color: var(--accent); }
.pattern-btn.active { background: var(--accent); border-color: var(--accent); font-weight: 700; }

/* Buttons */
.primary-btn {
  width: 100%; background: var(--accent); border: none; border-radius: var(--radius);
  color: #fff; font-size: 1.05rem; font-weight: 700; padding: 14px; cursor: pointer;
  transition: opacity .15s, transform .1s;
}
.primary-btn:disabled { opacity: .35; cursor: not-allowed; }
.primary-btn:not(:disabled):hover { opacity: .9; }
.primary-btn:not(:disabled):active { transform: scale(.98); }
.primary-btn.small { width: auto; padding: 12px 20px; }
.secondary-btn {
  background: var(--surface2); border: 1px solid #333; border-radius: var(--radius);
  color: var(--text); font-size: 1rem; padding: 12px 24px; cursor: pointer;
}
.link-btn { background: none; border: none; color: var(--accent); cursor: pointer; font-size: .9rem; text-decoration: underline; }
.icon-btn { background: var(--surface); border: 1px solid #333; border-radius: 8px; color: var(--text); font-size: 1.2rem; padding: 8px 14px; cursor: pointer; }
.btn-row { display: flex; gap: 12px; margin-top: 20px; }
.btn-row .secondary-btn { flex: 1; }
.btn-row .primary-btn { flex: 2; }
.manual-section { text-align: center; margin-top: 14px; }

/* Loading */
.progress-bar-wrap { background: #333; border-radius: 99px; height: 6px; margin-top: 10px; overflow: hidden; }
.progress-bar { background: var(--accent); height: 100%; width: 0%; border-radius: 99px; transition: width .4s ease; }
.spinner { width: 34px; height: 34px; border: 3px solid #333; border-top-color: var(--accent); border-radius: 50%; animation: spin .7s linear infinite; margin: 0 auto 10px; }
@keyframes spin { to { transform: rotate(360deg); } }

.error { background: #3b1a1a; border: 1px solid var(--accent); border-radius: var(--radius); color: #f88; padding: 12px; font-size: .9rem; }
.hidden { display: none !important; }

/* Layout Confirmation */
.layout-confirm {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--surface);
  border: 1px solid #333;
  border-radius: var(--radius);
  padding: 10px 14px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}
.layout-confirm-label { font-size: .8rem; color: var(--muted); }
.layout-adjust {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 1rem;
  font-weight: 700;
}
.layout-x { color: var(--muted); font-size: .9rem; }
.adj-btn {
  width: 28px; height: 28px;
  background: var(--surface2);
  border: 1px solid #444;
  border-radius: 6px;
  color: var(--text);
  font-size: 1.1rem;
  font-weight: 700;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  line-height: 1;
  transition: background .15s;
}
.adj-btn:hover { background: #2a2a4a; }

/* Picker actions */
.picker-actions {
  display: flex;
  gap: 8px;
  margin-bottom: 10px;
}
.secondary-btn.small {
  padding: 8px 16px;
  font-size: .85rem;
  flex: 1;
}

/* Pre-call */
.precall-section { margin-top: 20px; }
.precall-btns {
  display: flex;
  gap: 8px;
  margin-top: 8px;
  margin-bottom: 10px;
}
.precall-btn {
  flex: 1;
  background: var(--surface);
  border: 1px solid #333;
  border-radius: 8px;
  color: var(--text);
  padding: 10px;
  font-size: .9rem;
  font-weight: 600;
  cursor: pointer;
  transition: all .15s;
}
.precall-btn:hover { border-color: var(--accent); }
.precall-btn.active { background: var(--accent); border-color: var(--accent); }

.precall-label { font-size: .75rem; color: var(--muted); margin-bottom: 6px; text-transform: uppercase; letter-spacing: .06em; }
.precall-digits {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 6px;
  margin-bottom: 8px;
}
.digit-btn { flex: none; padding: 8px 4px; font-size: 1rem; }

/* Card Picker */
.card-picker-grid {
  display: grid;
  gap: 10px;
}
.picker-card {
  background: var(--surface);
  border: 2px solid #333;
  border-radius: var(--radius);
  padding: 16px 20px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 14px;
  transition: all .15s;
}
.picker-card:hover { border-color: #555; }
.picker-card.selected { border-color: var(--accent); background: rgba(233,69,96,.12); }
.picker-card-num {
  width: 36px; height: 36px; border-radius: 50%;
  background: var(--surface2); border: 2px solid #444;
  display: flex; align-items: center; justify-content: center;
  font-weight: 900; font-size: 1rem; flex-shrink: 0;
  transition: all .15s;
}
.picker-card.selected .picker-card-num { background: var(--accent); border-color: var(--accent); }
.picker-card-label { font-weight: 600; font-size: 1rem; }
.picker-card-hint { font-size: .75rem; color: var(--muted); margin-top: 2px; }
.picker-checkmark { margin-left: auto; font-size: 1.3rem; opacity: 0; transition: opacity .15s; }
.picker-card.selected .picker-checkmark { opacity: 1; }

/* Pre-dab modal */
.modal-overlay {
  position: fixed; inset: 0; z-index: 200;
  background: rgba(0,0,0,.75);
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
}
.modal-box {
  background: var(--surface);
  border: 1px solid #333;
  border-radius: var(--radius);
  padding: 28px 24px;
  width: 100%; max-width: 400px;
}
.modal-box h2 { margin-bottom: 8px; }
.modal-digit-btn {
  background: var(--surface2); border: 2px solid #333; border-radius: 8px;
  color: var(--text); font-size: 1rem; font-weight: 700; padding: 10px 4px;
  cursor: pointer; transition: all .15s;
}
.modal-digit-btn:hover { border-color: var(--called); }
.modal-digit-btn.selected { background: var(--called); border-color: var(--called); color: #000; }

/* Add game panel */
.add-game-panel {
  background: var(--surface2);
  border: 1px solid #333;
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 10px;
}
.game-precall-btn {
  flex: 1;
  background: var(--surface);
  border: 1px solid #333;
  border-radius: 8px;
  color: var(--text);
  padding: 8px;
  font-size: .85rem;
  font-weight: 600;
  cursor: pointer;
  transition: all .15s;
}
.game-precall-btn:hover { border-color: var(--called); }
.game-precall-btn.active { background: var(--called); border-color: var(--called); color: #000; }

/* Game pattern buttons + predab prompt use dab color */
.game-pattern-btn.active { background: var(--called) !important; border-color: var(--called) !important; color: #000 !important; }
.predab-prompt-btn.active { background: var(--called) !important; border-color: var(--called) !important; color: #000 !important; }

/* Session list on setup */
.session-game-item {
  display: flex; align-items: center; gap: 10px;
  background: var(--surface); border: 1px solid #333; border-radius: 10px;
  padding: 10px 14px; margin-bottom: 8px;
}
.session-game-item.ready { border-color: #2a4a2a; }
.session-game-item.error { border-color: #4a2a2a; }
.session-game-num {
  width: 30px; height: 30px; border-radius: 50%; background: var(--surface2);
  display: flex; align-items: center; justify-content: center;
  font-weight: 900; font-size: .9rem; flex-shrink: 0;
}
.session-game-item.ready .session-game-num { background: #1a3a1a; color: #4ade80; }
.session-game-info { flex: 1; }
.session-game-label { font-weight: 700; font-size: .95rem; }
.session-game-sub { font-size: .75rem; color: var(--muted); margin-top: 2px; }
.session-game-remove {
  background: none; border: none; color: var(--muted); font-size: 1.2rem;
  cursor: pointer; padding: 4px 8px; border-radius: 6px;
}
.session-game-remove:hover { color: var(--accent); }
.session-scanning { display: flex; align-items: center; gap: 8px; }
.session-spinner {
  width: 16px; height: 16px; border: 2px solid #333; border-top-color: var(--accent);
  border-radius: 50%; animation: spin .7s linear infinite; flex-shrink: 0;
}

/* Session nav in game */
.session-nav {
  display: flex; align-items: center; justify-content: space-between;
  background: var(--surface); border: 1px solid #333; border-radius: 10px;
  padding: 10px 14px; margin-bottom: 14px;
}
#session-counter { font-weight: 700; font-size: .95rem; color: var(--muted); }
.next-game-btn {
  background: var(--accent); border: none; border-radius: 8px;
  color: #fff; font-size: .9rem; font-weight: 700; padding: 8px 16px; cursor: pointer;
}
.next-game-btn:hover { opacity: .85; }

/* Game */
.game-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }

/* Dab color swatches */
.color-swatches { display: flex; gap: 12px; margin-top: 4px; }
.color-opt {
  width: 38px; height: 38px; border-radius: 50%;
  border: 3px solid transparent;
  cursor: pointer; transition: border-color .15s, transform .1s;
  flex-shrink: 0;
}
.color-opt:hover { transform: scale(1.12); }
.color-opt.selected { border-color: #fff; box-shadow: 0 0 0 2px rgba(255,255,255,.3); }

.win-banner {
  background: linear-gradient(135deg, #ffd700, #ff6b35);
  color: #000; text-align: center;
  padding: 14px; border-radius: var(--radius); margin-bottom: 14px;
  animation: pulse 1s ease-in-out infinite alternate;
}
#win-text { font-size: 1.8rem; font-weight: 900; }
.next-pattern-btn {
  margin-top: 10px;
  background: rgba(0,0,0,.2);
  border: 2px solid rgba(0,0,0,.3);
  border-radius: 8px;
  color: #000;
  font-size: 1rem;
  font-weight: 800;
  padding: 8px 18px;
  cursor: pointer;
  display: inline-block;
}
.next-pattern-btn:hover { background: rgba(0,0,0,.3); }
@keyframes pulse { from { transform: scale(1); } to { transform: scale(1.03); } }

/* Card Tabs */
.card-tabs { display: flex; gap: 6px; margin-bottom: 12px; overflow-x: auto; padding-bottom: 2px; }
.card-tab {
  flex-shrink: 0; background: var(--surface); border: 2px solid #333; border-radius: 8px;
  color: var(--muted); font-size: .85rem; font-weight: 700; padding: 6px 14px; cursor: pointer;
  transition: all .15s; position: relative;
}
.card-tab.active { background: var(--surface2); border-color: var(--accent); color: var(--text); }
.card-tab .win-dot { position: absolute; top: -4px; right: -4px; width: 10px; height: 10px; background: var(--free); border-radius: 50%; border: 2px solid var(--bg); }

/* Bingo Card */
.bingo-card-wrapper { background: var(--surface); border-radius: var(--radius); padding: 10px; margin-bottom: 18px; }
.bingo-header { display: grid; grid-template-columns: repeat(5, 1fr); gap: 4px; margin-bottom: 4px; }
.bingo-header div { text-align: center; font-size: 1.2rem; font-weight: 900; padding: 4px 0; }
.bingo-header div:nth-child(1){color:var(--b)} .bingo-header div:nth-child(2){color:var(--i)} .bingo-header div:nth-child(3){color:var(--n)} .bingo-header div:nth-child(4){color:var(--g)} .bingo-header div:nth-child(5){color:var(--o)}
.bingo-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 4px; }
.bingo-cell {
  aspect-ratio: 1; display: flex; align-items: center; justify-content: center;
  font-size: clamp(.8rem, 3.5vw, 1.1rem); font-weight: 700; border-radius: 8px;
  background: var(--surface2); border: 2px solid transparent; transition: all .2s; user-select: none;
}
.bingo-cell.col-b{border-color:#1e3a4a} .bingo-cell.col-i{border-color:#1e3a25} .bingo-cell.col-n{border-color:#3a2e1e} .bingo-cell.col-g{border-color:#3a1e2a} .bingo-cell.col-o{border-color:#2e1e3a}
.bingo-cell.free { background:#2a2700; border-color:var(--free); color:var(--free); font-size:.7rem; font-weight:900; }
.bingo-cell.dual { flex-direction: column; gap: 1px; padding: 2px; }
.dual-primary { font-size: clamp(.75rem, 3vw, 1rem); font-weight: 900; line-height: 1; }
.dual-secondary { font-size: clamp(.55rem, 2vw, .72rem); font-weight: 600; opacity: .75; line-height: 1; }
.bingo-cell.called { background:var(--called)!important; border-color:var(--called)!important; color:#fff!important; transform:scale(1.05); }
.bingo-cell.winning { background:var(--free)!important; border-color:var(--free)!important; color:#000!important; animation:pop .4s ease; }
@keyframes pop { 0%{transform:scale(1)} 50%{transform:scale(1.2)} 100%{transform:scale(1.05)} }

/* Caller / Numpad */
.caller-section { margin-bottom: 18px; }

.numpad-display-row {
  display: flex; align-items: center; gap: 10px;
  margin-bottom: 12px;
}
.numpad-display {
  flex: 1; text-align: center;
  font-size: 2rem; font-weight: 900;
  background: var(--surface); border: 1px solid #333; border-radius: var(--radius);
  padding: 12px; color: var(--text); letter-spacing: .05em;
}
.numpad-back {
  background: var(--surface); border: 1px solid #333; border-radius: var(--radius);
  color: var(--text); font-size: 1.4rem; padding: 12px 16px; cursor: pointer;
  transition: background .15s;
}
.numpad-back:hover { background: #2a2a3a; }

.numpad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}
.numpad-key {
  background: var(--surface);
  border: 1px solid #333; border-radius: var(--radius);
  color: var(--text); font-size: 1.4rem; font-weight: 700;
  padding: 16px; cursor: pointer;
  transition: background .1s, transform .08s;
  user-select: none;
}
.numpad-key:hover { background: #2a2a3a; }
.numpad-key:active { transform: scale(.93); background: #333; }
.numpad-call {
  background: var(--called); border: none; border-radius: var(--radius);
  color: #000; font-size: 1.1rem; font-weight: 900;
  padding: 16px; cursor: pointer;
  transition: opacity .15s, transform .08s;
}
.numpad-call:hover { opacity: .85; }
.numpad-call:active { transform: scale(.93); }
.called-history { display: flex; flex-wrap: wrap; gap: 6px; max-height: 90px; overflow-y: auto; }
.called-chip { background: var(--called); border-radius: 6px; color: #fff; font-size: .8rem; font-weight: 700; padding: 4px 8px; }

/* Ball Selector */
.ball-selector { margin-bottom: 20px; }
.columns-wrapper { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; }
.ball-column { display: flex; flex-direction: column; gap: 5px; align-items: center; }
.col-label { font-size: 1rem; font-weight: 900; margin-bottom: 2px; }
.b-col{color:var(--b)} .i-col{color:var(--i)} .n-col{color:var(--n)} .g-col{color:var(--g)} .o-col{color:var(--o)}
.ball {
  width: 100%; aspect-ratio: 1; border-radius: 50%; display: flex; align-items: center; justify-content: center;
  font-size: clamp(.6rem, 2.5vw, .82rem); font-weight: 700; cursor: pointer; border: 2px solid transparent;
  transition: all .15s; background: var(--surface2); color: var(--muted);
}
.ball:hover { transform: scale(1.1); }
.ball.b-ball{border-color:#1e3a4a;color:var(--b)} .ball.i-ball{border-color:#1e3a25;color:var(--i)} .ball.n-ball{border-color:#3a2e1e;color:var(--n)} .ball.g-ball{border-color:#3a1e2a;color:var(--g)} .ball.o-ball{border-color:#2e1e3a;color:var(--o)}
.ball.called { background:var(--called); border-color:var(--called); color:#fff; }
.ball.on-card { box-shadow: 0 0 0 2px currentColor; }

/* Manual Entry */
.bingo-header-row { display:grid; grid-template-columns:repeat(5,1fr); gap:6px; text-align:center; margin-bottom:6px; font-weight:900; font-size:1.2rem; }
.bingo-header-row div:nth-child(1){color:var(--b)} .bingo-header-row div:nth-child(2){color:var(--i)} .bingo-header-row div:nth-child(3){color:var(--n)} .bingo-header-row div:nth-child(4){color:var(--g)} .bingo-header-row div:nth-child(5){color:var(--o)}
#manual-inputs { display:grid; grid-template-columns:repeat(5,1fr); gap:6px; margin-bottom:4px; }
.manual-cell-input {
  width:100%; aspect-ratio:1; background:var(--surface); border:1px solid #333; border-radius:8px;
  color:var(--text); font-size:.9rem; font-weight:700; text-align:center; padding:0; outline:none;
}
.manual-cell-input:focus { border-color:var(--accent); }
.manual-cell-input.free-cell { background:#2a2700; border-color:var(--free); color:var(--free); font-size:.65rem; display:flex; align-items:center; justify-content:center; }
