:root {
  color-scheme: dark;
  --page: #0d0d0d;
  --surface: #1a1a19;
  --surface-2: #212120;
  --ink: #ffffff;
  --ink-secondary: #c3c2b7;
  --ink-muted: #898781;
  --hairline: #2c2c2a;
  --border: rgba(255, 255, 255, 0.1);
  --good: #0ca30c;
  --good-glow: rgba(12, 163, 12, 0.18);
  --critical: #e66767;
  --critical-glow: rgba(230, 103, 103, 0.16);
  --accent: #4fd6e8;
  --accent-2: #7c5cff;
  --pending: #c98500;
  --pending-glow: rgba(201, 133, 0, 0.16);
  --radius: 16px;
  --radius-sm: 10px;
  font-size: 16px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  background: var(--page);
  color: var(--ink);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}

body {
  padding-bottom: calc(96px + env(safe-area-inset-bottom));
}

.app {
  max-width: 560px;
  margin: 0 auto;
  padding: 0 16px;
}

/* ---------- Hero ---------- */

.hero {
  padding: calc(20px + env(safe-area-inset-top)) 4px 8px;
  position: relative;
  /* Contains the scrub line's negative z-index to *this* stacking context —
     without it, position:relative alone doesn't create one, and z-index:-1
     escapes all the way to the document root, ending up behind the whole
     page instead of just behind this header's own text. */
  isolation: isolate;
}

.hero-top {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 18px;
}

.brand {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.14em;
  color: var(--ink-muted);
}

.live-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 8px 2px var(--accent);
}

.hero-figure {
  font-size: 44px;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.05;
}

.hero-figure.pos { color: var(--good); text-shadow: 0 0 18px var(--good-glow); }
.hero-figure.neg { color: var(--critical); text-shadow: 0 0 18px var(--critical-glow); }

.hero-sub {
  color: var(--ink-muted);
  font-size: 13px;
  margin-top: 2px;
}

.spark-wrap {
  position: relative;
  margin-top: 14px;
}

.sparkline {
  width: 100%;
  height: 56px;
  display: block;
  touch-action: none;
}

.scrub-dot-el {
  position: absolute;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--good);
  box-shadow: 0 0 6px 1px var(--good-glow);
  transform: translate(-50%, -50%);
  opacity: 0;
  transition: opacity 100ms ease;
  pointer-events: none;
  z-index: 2;
}
.scrub-dot-el.visible { opacity: 1; }

/* Spans the full hero height (top of header down to the chart's own bottom
   edge) so it visually runs behind the brand/PnL text above the chart —
   negative z-index drops it under the header's normal-flow content while
   staying above the header's own background. */
.scrub-line-el {
  position: absolute;
  top: 0;
  width: 0;
  border-left: 1.5px dotted var(--ink-secondary);
  opacity: 0;
  transition: opacity 100ms ease;
  pointer-events: none;
  z-index: -1;
}
.scrub-line-el.visible { opacity: 0.4; }

.spark-tooltip {
  position: absolute;
  top: 4px;
  right: 4px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 6px 10px;
  font-size: 12px;
  color: var(--ink-secondary);
  pointer-events: none;
}
.spark-tooltip strong { color: var(--ink); display: block; font-size: 13px; }


/* ---------- Stats row ---------- */

.stats-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin: 10px 0 18px;
}

.stat-tile {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
}

.stat-label {
  font-size: 11px;
  color: var(--ink-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.stat-value {
  font-size: 19px;
  font-weight: 700;
  margin-top: 4px;
  font-variant-numeric: tabular-nums;
}

.stat-value.pos { color: var(--good); }
.stat-value.neg { color: var(--critical); }
.stat-value.neutral { color: var(--ink); }
.stat-value.warn { color: var(--pending); }

/* ---------- Filter bar ---------- */

.filter-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}

.chips {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  scrollbar-width: none;
  flex: 1;
  padding-bottom: 2px;
}
.chips::-webkit-scrollbar { display: none; }

.chip {
  flex: 0 0 auto;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--ink-secondary);
  border-radius: 999px;
  padding: 7px 14px;
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
}

.chip.active {
  background: var(--accent-2);
  border-color: var(--accent-2);
  color: #fff;
}

.sort-wrap select {
  background: var(--surface);
  color: var(--ink);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 7px 8px;
  font-size: 12px;
  max-width: 108px;
}

.book-summary {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  margin-bottom: 14px;
  font-size: 13px;
  color: var(--ink-secondary);
}
.book-summary strong { color: var(--ink); font-size: 15px; }
.book-summary .val.pos { color: var(--good); }
.book-summary .val.neg { color: var(--critical); }

/* ---------- Sections & list ---------- */

.section-title {
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--ink-muted);
  margin: 18px 2px 8px;
}

.bet-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.bet-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  display: flex;
  gap: 10px;
  align-items: center;
}

.bet-card.pending {
  border-color: rgba(201, 133, 0, 0.35);
  background: linear-gradient(0deg, var(--pending-glow), var(--pending-glow)), var(--surface);
}

.bet-main { flex: 1; min-width: 0; }

.bet-top-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 3px;
}

.bet-book {
  font-size: 12px;
  font-weight: 700;
  color: var(--accent);
}

.bet-date {
  font-size: 11px;
  color: var(--ink-muted);
}

.bet-desc {
  font-size: 14px;
  color: var(--ink-secondary);
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.bet-wager {
  font-size: 11px;
  color: var(--ink-muted);
  margin-top: 4px;
}

.bet-pnl {
  text-align: right;
  flex: 0 0 auto;
  font-weight: 700;
  font-size: 15px;
  font-variant-numeric: tabular-nums;
  min-width: 64px;
}

.bet-pnl.pos { color: var(--good); }
.bet-pnl.neg { color: var(--critical); }
.bet-pnl.pending-tag {
  color: var(--pending);
  font-size: 12px;
  font-weight: 700;
  border: 1px solid rgba(201, 133, 0, 0.4);
  border-radius: 999px;
  padding: 4px 10px;
}

.empty-state {
  color: var(--ink-muted);
  text-align: center;
  padding: 40px 10px;
  font-size: 14px;
}

/* ---------- FAB ---------- */

.fab {
  position: fixed;
  right: 20px;
  bottom: calc(24px + env(safe-area-inset-bottom));
  width: 58px;
  height: 58px;
  border-radius: 50%;
  border: none;
  background: linear-gradient(135deg, var(--accent-2), var(--accent));
  color: #fff;
  font-size: 30px;
  font-weight: 400;
  line-height: 1;
  box-shadow: 0 6px 24px rgba(124, 92, 255, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 20;
}
.fab:active { transform: scale(0.94); }

/* ---------- Sheets ---------- */

.sheet-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  z-index: 30;
}

.sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 31;
  background: var(--surface-2);
  border-top: 1px solid var(--border);
  border-radius: 20px 20px 0 0;
  padding: 10px 20px calc(24px + env(safe-area-inset-bottom));
  max-height: 88vh;
  overflow-y: auto;
  box-shadow: 0 -8px 40px rgba(0, 0, 0, 0.5);
}

.sheet-handle {
  width: 36px;
  height: 4px;
  background: var(--hairline);
  border-radius: 999px;
  margin: 6px auto 14px;
}

.sheet h3 {
  margin: 0 0 14px;
  font-size: 17px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 14px;
  font-size: 13px;
  color: var(--ink-secondary);
}

.field-row {
  display: flex;
  gap: 10px;
}
.field-row .field { flex: 1; }

.field input, .field textarea {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--ink);
  padding: 11px 12px;
  font-size: 15px;
  font-family: inherit;
  resize: none;
  width: 100%;
}

.field input:focus, .field textarea:focus {
  outline: none;
  border-color: var(--accent);
}

.money-input {
  display: flex;
  align-items: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0 12px;
}
.money-input span { color: var(--ink-muted); font-size: 15px; }
.money-input input {
  border: none;
  background: transparent;
  padding: 11px 4px 11px 6px;
}
.money-input input:focus { outline: none; border: none; }

.field-note {
  font-size: 12px;
  color: var(--ink-muted);
  margin: -4px 0 14px;
}

.detail-meta {
  font-size: 12px;
  color: var(--ink-muted);
  margin: -4px 0 14px;
}

.sheet-actions {
  display: flex;
  gap: 10px;
  margin-top: 6px;
}

.btn-primary, .btn-ghost, .btn-danger {
  flex: 1;
  padding: 13px 0;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  font-size: 15px;
  font-weight: 600;
  font-family: inherit;
}

.btn-primary {
  background: linear-gradient(135deg, var(--accent-2), var(--accent));
  border: none;
  color: #fff;
}

.btn-ghost {
  background: transparent;
  color: var(--ink-secondary);
}

.btn-danger {
  background: transparent;
  color: var(--critical);
  border-color: rgba(230, 103, 103, 0.3);
  flex: 0 0 auto;
  padding: 13px 18px;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(96px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--ink);
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 13px;
  z-index: 40;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
}
