:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-alt: #f9fafb;
  --border: #e2e5ea;
  --text: #1c1f26;
  --text-muted: #6b7280;
  --accent: #2f6fed;
  --accent-hover: #2559c7;
  --danger: #d64545;
  --danger-hover: #b53838;
  --success: #1e8e5a;
  /* Zebra row striping in the market table -- deliberately `--bg` (the page
     background peeking through the card), not `--surface-alt` (already used
     for hover), so the two effects stay visually distinct. `var()` inside a
     custom property resolves lazily at used-value time, so this correctly
     picks up the dark-mode `--bg` below without its own override. */
  --row-alt: var(--bg);
  --radius: 8px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 1px 3px rgba(16, 24, 40, 0.08);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14161a;
    --surface: #1c1f26;
    --surface-alt: #23262e;
    --border: #333844;
    --text: #e6e8eb;
    --text-muted: #9aa0ab;
    --accent: #5b8dff;
    --accent-hover: #7ba0ff;
    --danger: #ef6b6b;
    --danger-hover: #f28a8a;
    --success: #4fbf8b;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 1px 3px rgba(0, 0, 0, 0.5);
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 14px;
}

h1, h2, h3 { margin: 0 0 0.5em; font-weight: 600; }

hr { border: none; border-top: 1px solid var(--border); margin: 12px 0; }

button {
  font: inherit;
  cursor: pointer;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: 6px;
  padding: 6px 10px;
}
button:hover:not(:disabled) { background: var(--surface-alt); }
button:disabled { opacity: 0.5; cursor: not-allowed; }

input[type="text"], input[type="password"] {
  font: inherit;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 5px 8px;
  background: var(--surface);
  color: var(--text);
}
input:disabled { opacity: 0.5; }

/* ---------- Login / sport-picker screens ---------- */

.screen { min-height: 100vh; }

/* :not([hidden]) -- an ID/class selector unconditionally setting `display`
   would outrank the browser's default `[hidden] { display: none }` rule and
   keep the screen visible even after JS sets `el.hidden = true`. */
.screen-centered:not([hidden]) {
  display: flex;
  align-items: center;
  justify-content: center;
}

.login-form, .sport-picker {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 32px;
  width: 320px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.login-form .subtitle, .sport-picker .subtitle { color: var(--text-muted); margin: -8px 0 8px; }

.login-form label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 13px;
  color: var(--text-muted);
}

.login-form button, .sport-picker > button:not(.link-btn) {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
  padding: 8px 10px;
  margin-top: 4px;
}
.login-form button:hover, .sport-picker > button:not(.link-btn):hover { background: var(--accent-hover); }

.error { color: var(--danger); font-size: 13px; margin: 0; }

.sport-list { display: flex; flex-direction: column; gap: 6px; }

.sport-option {
  display: flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 10px;
  cursor: pointer;
}
.sport-option:has(input:checked) { border-color: var(--accent); background: var(--surface-alt); }
.sport-option input { margin: 0; }

.sport-picker .link-btn { align-self: center; margin-top: 4px; }

/* ---------- App shell ---------- */

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.header-left { display: flex; align-items: center; gap: 10px; }

/* margin-top nudge: flexbox `align-items: center` centers the h1's line
   box (which includes font leading above/below the glyphs), not the
   visual center of its letters -- an SVG with a true geometric center
   ends up sitting slightly below where the text visually reads as
   centered. Hand-tuned offset, not derived from any metric. */
.app-logo { height: 24px; width: auto; flex-shrink: 0; display: block; margin-top: -5px; }

.header-left h1 { line-height: 1; }

.header-right { display: flex; align-items: center; gap: 12px; color: var(--text-muted); }

.header-divider { width: 1px; height: 16px; background: var(--border); }

.sport-badge {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  color: var(--accent);
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 3px 10px;
}

.link-btn {
  background: none;
  border: none;
  color: var(--accent);
  padding: 0;
}
.link-btn:hover { text-decoration: underline; background: none; }

.main-row {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 12px;
}

.market-tabs {
  flex: 1 1 auto;
  min-width: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.control-panel {
  flex: 0 0 280px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px;
}

.config-forms {
  margin: 0 12px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.config-panel-content {
  padding: 14px;
  display: flex;
  flex-wrap: wrap;
  gap: 24px;
}

.section-label { color: var(--text-muted); font-size: 13px; }

/* ---------- Tabs ---------- */

.tab-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 2px;
  padding: 8px 8px 0;
  border-bottom: 1px solid var(--border);
}
.tab-bar--inner { background: var(--surface-alt); padding-top: 6px; }

.tab-btn {
  border: 1px solid transparent;
  border-bottom: none;
  background: transparent;
  border-radius: 6px 6px 0 0;
  padding: 6px 12px;
  color: var(--text-muted);
}
.tab-btn.active {
  background: var(--surface);
  border-color: var(--border);
  color: var(--text);
  font-weight: 600;
}
.tab-btn--inner.active { background: var(--surface-alt); }

/* ---------- Market rows ---------- */

.market-content {
  padding: 10px;
  max-height: 64vh;
  overflow-y: auto;
}

.market-row {
  display: grid;
  grid-template-columns: minmax(0, 2.4fr) repeat(5, minmax(0, 0.9fr)) 32px;
  align-items: stretch;
  gap: 6px;
  padding: 3px 4px;
  border-radius: 4px;
}
.market-row:hover { background: var(--surface-alt); }

/* Every cell is its own flex row so it stretches to fill the grid cell
   height while still centering its content vertically; horizontal alignment
   is per cell-type below (price-cell/check-cell right/center, everything
   else defaults to flex-start, i.e. left). */
.market-row > * {
  display: flex;
  align-items: center;
  min-width: 0;
}

/* Zebra row striping -- alternates across selection rows only (rowIndex is
   tracked in JS, not via nth-child: market-name-row divs interleaved between
   markets would otherwise throw off a pure-CSS nth-child count). */
.market-row.row-alt { background: var(--row-alt); }
.market-row.row-alt:hover { background: var(--surface-alt); }

.market-row--header {
  font-weight: 600;
  font-size: 12px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.02em;
  position: sticky;
  top: 0;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding-bottom: 6px;
}

/* Same alignment as the values they head -- price-cell is shared by header
   and data cells so a column's header and its values always match. */
/* justify-content, not text-align -- these cells are flex containers (see
   `.market-row > *` above), so text-align has no effect on where their
   single text-node/checkbox child sits. */
.price-cell { justify-content: flex-end; font-variant-numeric: tabular-nums; }
.check-cell { justify-content: center; }

.market-name-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
  padding: 4px;
  font-weight: 600;
  color: var(--text-muted);
}

.weight-label { color: var(--text-muted); font-weight: 400; }

.weight-input { width: 56px; text-align: right; }

.loading { color: var(--text-muted); padding: 12px; }

/* ---------- Control / config forms ---------- */

.config-row {
  display: grid;
  grid-template-columns: 1fr 24px 72px 24px minmax(0, 2fr);
  align-items: center;
  gap: 6px;
  padding: 3px 0;
}
.config-row--header {
  font-weight: 600;
  font-size: 12px;
  color: var(--text-muted);
  text-transform: uppercase;
}

.stepper-btn { width: 24px; padding: 2px 0; text-align: center; }

.config-input { width: 100%; text-align: right; }

.config-desc { color: var(--text-muted); font-size: 12px; }

.config-form { min-width: 320px; flex: 1 1 360px; }

/* ---------- Bet slip ---------- */

.bet-slip h3 { margin-bottom: 8px; }

.bet-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin: 6px 0;
}
.bet-row label { display: flex; align-items: center; gap: 8px; width: 100%; justify-content: space-between; color: var(--text-muted); }
#stake-input { width: 90px; text-align: right; }
#odds-display { font-variant-numeric: tabular-nums; color: var(--text); }

#bet-btn {
  width: 100%;
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}
#bet-btn:hover:not(:disabled) { background: var(--accent-hover); }

/* ---------- Action buttons ---------- */

.action-buttons { display: flex; flex-direction: column; gap: 8px; }
.action-buttons button { background: var(--accent); color: #fff; border-color: var(--accent); }
.action-buttons button:hover:not(:disabled) { background: var(--accent-hover); }

.danger-btn { width: 100%; color: var(--danger); border-color: var(--danger); background: transparent; }
.danger-btn:hover:not(:disabled) { background: var(--danger); color: #fff; }

#status-text { margin: 4px 0 0; }
