:root {
  --bg: #0b0d10;
  --panel: #151920;
  --panel2: #1c212a;
  --line: #2a313c;
  --text: #f3f5f8;
  --muted: #8d97a7;
  --hot: #ff5a1f;
  --hot-glow: rgba(255, 90, 31, 0.45);
  --ok: #22c55e;
  --bad: #ef4444;
  --warn: #facc15;
  --away: #3b82f6;
  --home: #a855f7;
  --live: #ef4444;
  --tile-h: 84px;
  color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); }
body {
  font: 15px/1.35 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none;
  touch-action: manipulation;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  overscroll-behavior: none;
}
input, select, textarea { -webkit-user-select: text; user-select: text; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.center { text-align: center; }
h1 { font-size: 28px; margin: 0 0 8px; }
h2 { font-size: 13px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); margin: 0 0 10px; }

#haptic { position: fixed; left: -100px; top: -100px; opacity: 0; pointer-events: none; }

/* ---- login ---- */
#login { padding: 48px 20px; max-width: 420px; margin: 0 auto; display: grid; gap: 12px; }
#login input { font-size: 18px; }

/* ---- controls ---- */
.btn {
  appearance: none; border: 1px solid var(--line); background: var(--panel2); color: var(--text);
  font: inherit; font-weight: 600; padding: 10px 14px; border-radius: 10px; min-height: 44px;
}
.btn:active { filter: brightness(1.3); }
.btn.primary { background: #2563eb; border-color: #2563eb; }
.btn.small { min-height: 34px; padding: 6px 10px; font-size: 13px; }
.btn.wide { width: 100%; margin-top: 10px; }
.btn.danger { background: #7f1d1d; border-color: #b91c1c; }
input, select {
  width: 100%; font: inherit; color: var(--text); background: var(--bg); border: 1px solid var(--line);
  border-radius: 8px; padding: 9px 10px; min-height: 40px;
}
label { display: grid; gap: 4px; font-size: 12px; color: var(--muted); }
label.check { display: flex; gap: 8px; align-items: center; font-size: 14px; color: var(--text); margin-top: 10px; }
label.check input { width: 20px; min-height: 20px; height: 20px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.row-between { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.row-between h2 { margin: 0; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 14px; margin: 10px 10px 0; }

/* ---- top bar ---- */
#bar { display: flex; gap: 10px; padding: 8px 10px; align-items: stretch; background: var(--bg); position: sticky; top: 0; z-index: 5; }
.master {
  flex: 0 0 132px; border-radius: 14px; border: 2px solid var(--line); background: var(--panel);
  color: var(--muted); display: grid; place-content: center; text-align: center; padding: 6px; touch-action: none;
  position: relative; overflow: hidden;
}
.master-label { font-size: 22px; font-weight: 900; letter-spacing: .06em; }
.master-hint { font-size: 10px; text-transform: uppercase; letter-spacing: .1em; }
.master.armed { border-color: var(--hot); background: #3a1407; color: #fff; box-shadow: 0 0 18px var(--hot-glow) inset; }
.master.armed .master-label { color: var(--hot); }
.master .fillbar { position: absolute; left: 0; bottom: 0; height: 4px; background: var(--hot); width: 0; }
.master.holding .fillbar { width: 100%; transition: width .6s linear; }
.stats { flex: 1; display: grid; gap: 6px; align-content: center; }
.row1, .row2 { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.badge { font-weight: 800; font-size: 12px; padding: 3px 8px; border-radius: 6px; letter-spacing: .08em; }
.badge.dry { background: #334155; color: #e2e8f0; }
.badge.live { background: var(--live); color: #fff; animation: pulse 1.2s infinite; }
.pill { font-size: 12px; background: var(--panel); border: 1px solid var(--line); border-radius: 999px; padding: 2px 8px; color: var(--muted); display: inline-flex; gap: 5px; align-items: center; }
.pill .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--bad); display: inline-block; }
.pill.up .dot { background: var(--ok); }
.pill.slow .dot { background: var(--warn); }
.pill.ws { color: var(--ok); border-color: #14532d; }
#bal { font-weight: 700; color: var(--text); }

#offline { background: var(--bad); color: #fff; font-weight: 800; text-align: center; padding: 6px; }

#tabs { display: flex; gap: 6px; padding: 0 10px 6px; }
#tabs button { flex: 1; background: transparent; border: 0; color: var(--muted); font-weight: 800; letter-spacing: .1em; padding: 8px; border-bottom: 2px solid transparent; font-size: 13px; }
#tabs button.on { color: var(--text); border-color: var(--text); }

/* ---- fire pad ---- */
#gameline { display: flex; justify-content: space-between; gap: 8px; padding: 2px 12px 8px; font-weight: 700; }
#gameline .tm { display: flex; gap: 6px; align-items: baseline; }
#gameline .px { color: var(--muted); font-weight: 600; font-size: 13px; }
#pad { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; padding: 0 8px; }
#pad .col { display: grid; gap: 8px; align-content: start; }
#pad .wide-row { grid-column: 1 / -1; display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.tile {
  position: relative; min-height: var(--tile-h); border-radius: 14px; padding: 8px 10px; background: var(--panel);
  border: 2px solid var(--line); color: var(--muted); touch-action: none; display: grid; align-content: space-between;
  overflow: hidden; text-align: left; font: inherit; width: 100%;
}
.tile .t-label { font-weight: 900; font-size: 16px; line-height: 1.1; color: inherit; text-transform: uppercase; letter-spacing: .01em; }
.tile .t-px { display: flex; justify-content: space-between; align-items: baseline; gap: 4px; }
.tile .t-ask { font-size: 22px; font-weight: 800; font-variant-numeric: tabular-nums; }
.tile .t-meta { font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; text-align: right; }
.tile.sent .t-meta, .tile.filled .t-meta, .tile.nofill .t-meta { color: #fff; font-weight: 800; font-size: 12px; }
.tile .t-key { position: absolute; top: 6px; right: 8px; font-size: 10px; color: var(--muted); border: 1px solid var(--line); border-radius: 4px; padding: 0 4px; }
.tile.away { border-left-color: var(--away); }
.tile.home { border-left-color: var(--home); }
.tile.armed { color: var(--text); border-color: var(--hot); background: #22120b; box-shadow: 0 0 0 1px var(--hot-glow), 0 0 16px var(--hot-glow); }
.tile.armed.away, .tile.armed.home { border-left-width: 6px; }
.master-safe .tile.armed { box-shadow: none; border-color: #6b3a24; background: #1b130f; }
.tile.sent { background: #3b3307; border-color: var(--warn); color: #fff; }
.tile.filled { background: #0b2e19; border-color: var(--ok); color: #fff; }
.tile.nofill { background: #2b1111; border-color: var(--bad); color: #fff; }
.tile.flash { animation: flash .25s ease-out; }
.tile.shake { animation: shake .25s; }
.tile .holdbar { position: absolute; left: 0; bottom: 0; height: 3px; background: var(--hot); width: 0; }
.tile.holding .holdbar { width: 100%; transition: width .5s linear; }
.colhead { display: flex; justify-content: space-between; font-weight: 800; padding: 0 4px; font-size: 13px; }
.colhead.away { color: var(--away); } .colhead.home { color: var(--home); }
#pad-actions { display: flex; gap: 8px; padding: 12px 8px; }
#pad-actions .btn { flex: 1; }

/* ---- setup ---- */
.trig { border: 1px solid var(--line); border-radius: 12px; padding: 10px; margin-top: 10px; background: var(--panel2); }
.trig-head { display: grid; grid-template-columns: 1fr 74px 64px; gap: 6px; }
.trig-head input, .trig-head select { min-height: 36px; padding: 6px 8px; }
.trig-actions { display: flex; gap: 6px; margin-top: 8px; flex-wrap: wrap; }
.leg { border-top: 1px dashed var(--line); margin-top: 8px; padding-top: 8px; display: grid; gap: 6px; }
.leg-title { font-size: 13px; color: var(--text); display: flex; justify-content: space-between; gap: 8px; }
.leg-title .q { color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.leg-grid { display: grid; grid-template-columns: 84px 1fr 1fr 34px; gap: 6px; align-items: end; }
.leg-grid input, .leg-grid select { min-height: 34px; padding: 5px 6px; font-size: 14px; }
.leg-grid label { font-size: 10px; }
.seg { display: flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; min-height: 34px; }
.seg button { flex: 1; background: var(--bg); color: var(--muted); border: 0; font-weight: 800; font-size: 12px; }
.seg button.on.yes { background: #14532d; color: #fff; } .seg button.on.no { background: #7f1d1d; color: #fff; }
.tag { font-size: 10px; background: #1e3a8a; color: #bfdbfe; border-radius: 4px; padding: 1px 5px; margin-left: 6px; }
.risk { font-size: 12px; color: var(--muted); margin-top: 6px; }
.risk.over { color: var(--bad); font-weight: 700; }

/* ---- market sheet ---- */
#sheet { position: fixed; inset: 0; background: var(--bg); z-index: 20; display: flex; flex-direction: column; padding-top: env(safe-area-inset-top); }
.sheet-head { display: flex; gap: 8px; padding: 10px; border-bottom: 1px solid var(--line); }
#mkt-list { overflow: auto; flex: 1; padding: 0 10px 40px; -webkit-overflow-scrolling: touch; }
.mgroup h3 { font-size: 12px; color: var(--muted); letter-spacing: .08em; text-transform: uppercase; margin: 16px 0 6px; }
.mrow { display: grid; grid-template-columns: 1fr auto auto; gap: 6px; align-items: center; padding: 7px 0; border-bottom: 1px solid #161a21; }
.mrow .mt { font-size: 14px; } .mrow .mt small { display: block; color: var(--muted); font-size: 11px; }
.mrow .btn { min-height: 36px; padding: 4px 10px; font-size: 13px; min-width: 70px; }
.mrow .yes { border-color: #166534; } .mrow .no { border-color: #991b1b; }
.mrow.closed { opacity: .45; }

/* ---- log ---- */
.fire-row { border-bottom: 1px solid var(--line); padding: 8px 0; font-size: 13px; }
.fire-row .fh { display: flex; justify-content: space-between; font-weight: 700; }
.fire-row .ok { color: var(--ok); } .fire-row .bad { color: var(--bad); }
.fire-row .legs { color: var(--muted); margin-top: 3px; }
.pos-row { display: grid; grid-template-columns: 1fr auto auto; gap: 8px; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--line); font-size: 13px; }

#toast {
  position: fixed; left: 50%; bottom: calc(18px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: #111827; border: 1px solid var(--line); padding: 10px 14px; border-radius: 12px; z-index: 30; font-weight: 600;
  max-width: 92vw; text-align: center;
}

@keyframes pulse { 50% { opacity: .55; } }
@keyframes flash { from { filter: brightness(2.2); } to { filter: none; } }
@keyframes shake { 25% { transform: translateX(-4px); } 75% { transform: translateX(4px); } }

/* ---- bet size chips ---- */
#stake-bar { display: flex; gap: 5px; align-items: center; padding: 0 8px 8px; }
#stake-bar .stake-label { font-size: 11px; font-weight: 800; letter-spacing: .1em; color: var(--muted); padding-right: 2px; }
#stake-bar .chip {
  flex: 1 1 auto; min-width: 0; min-height: 34px; border-radius: 999px; border: 1px solid var(--line); background: var(--panel);
  color: var(--text); font: inherit; font-weight: 800; font-size: 13px; padding: 4px 6px;
}
#stake-bar .chip.on { background: #f8fafc; color: #0b0d10; border-color: #f8fafc; }
.help p, .help li { font-size: 14px; line-height: 1.45; color: var(--text); -webkit-user-select: text; user-select: text; }
.help ol { padding-left: 20px; margin: 0; display: grid; gap: 6px; }
.small { font-size: 12px; margin: 8px 0 0; }
#tol-bar { display: flex; gap: 6px; margin-top: 8px; }
#tol-bar .chip { flex: 1; min-height: 38px; border-radius: 999px; border: 1px solid var(--line); background: var(--bg); color: var(--text); font: inherit; font-weight: 800; font-size: 13px; }
#tol-bar .chip.on { background: #f8fafc; color: #0b0d10; border-color: #f8fafc; }
.speed-row { font-size: 13px; padding: 6px 0; border-bottom: 1px solid var(--line); font-variant-numeric: tabular-nums; }
.speed-row b { font-size: 16px; color: var(--text); margin-right: 4px; }
