:root {
  --background: #f3f4f6;
  --surface: #ffffff;
  --text: #111827;
  --muted: #6b7280;
  --border: #e5e7eb;
  --accent: #4f46e5;
  --accent-soft: #e0e7ff;
  --success: #15803d;
  --success-soft: #dcfce7;
  --danger: #b91c1c;
  --radius: 14px;
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --series-3: #1baf7a;
  --series-4: #eda100;
  --series-5: #e87ba4;
  --series-6: #008300;
  --series-7: #4a3aa7;
  --series-8: #e34948;
  --series-other: #898781;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --background: #0b0f17;
    --surface: #161b26;
    --text: #f3f4f6;
    --muted: #9ca3af;
    --border: #273042;
    --accent: #818cf8;
    --accent-soft: #272d55;
    --success: #4ade80;
    --success-soft: #14321f;
    --danger: #f87171;
    --series-1: #3987e5;
    --series-2: #d95926;
    --series-3: #199e70;
    --series-4: #c98500;
    --series-5: #d55181;
    --series-6: #008300;
    --series-7: #9085e9;
    --series-8: #e66767;
    --grid: #273042;
    --axis: #3a4458;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--background);
  color: var(--text);
  padding-bottom: env(safe-area-inset-bottom);
}

.topbar { padding: 14px 16px; font-weight: 700; display: flex; justify-content: space-between; max-width: 584px; margin: 0 auto; }
.topbar nav { display: flex; gap: 14px; }
.topbar nav a { font-weight: 500; color: var(--muted); }
.topbar #whoami:empty { display: none; }
.topbar a { color: inherit; text-decoration: none; }

main { max-width: 560px; margin: 0 auto; padding: 0 12px 40px; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
}

h1 { font-size: 1.35rem; margin: 4px 0 8px; }
h2 { font-size: 1.05rem; margin: 0 0 10px; }
a { color: var(--accent); }

.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.center { text-align: center; }
.error { color: var(--danger); min-height: 1em; margin: 6px 0; }
.error:empty { display: none; }
.details { color: var(--muted); white-space: pre-wrap; margin-top: 0; }

.row { display: flex; gap: 8px; align-items: center; }
.grow { flex: 1; min-width: 0; }
.stack { display: grid; gap: 8px; }
.stack p { margin: 0; }

.field { display: block; margin-bottom: 14px; }
.field > span { display: block; font-size: 0.9rem; font-weight: 600; margin-bottom: 4px; }
.field em { font-weight: 400; color: var(--muted); }
.field.budget { width: 110px; }

input, textarea, select {
  width: 100%;
  font: inherit;
  color: inherit;
  background: var(--background);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
}
textarea { resize: vertical; }

button { font: inherit; cursor: pointer; border-radius: 10px; border: none; }
button:disabled { opacity: 0.4; cursor: default; }
.primary { background: var(--accent); color: white; padding: 11px 18px; font-weight: 600; }
.secondary { background: var(--accent-soft); color: var(--accent); padding: 9px 14px; font-weight: 600; }
.link { background: none; color: var(--accent); padding: 6px; }
.danger { color: var(--danger); }
.wide { width: 100%; }
.row > button { flex: none; }

.outcome-input { display: flex; gap: 4px; margin-bottom: 6px; }
.outcome-input .link { color: var(--muted); }

.game-list { margin: 0; padding-inline-start: 18px; }
.game-list li { margin: 4px 0; }

.status {
  display: inline-block;
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
}
.status-resolved { background: var(--success-soft); color: var(--success); }
.status-closed, .status-voided { background: var(--border); color: var(--muted); }

.outcomes { list-style: none; margin: 12px 0; padding: 0; }
.outcome {
  position: relative;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  margin-bottom: 8px;
  overflow: hidden;
}
.outcome-bar {
  position: absolute;
  inset-block: 0;
  inset-inline-start: 0;
  background: var(--accent-soft);
  transition: width 0.4s ease;
  z-index: 0;
}
.outcome > :not(.outcome-bar) { position: relative; z-index: 1; }
.outcome-body { flex: 1; min-width: 0; }
.outcome-label { font-weight: 600; overflow-wrap: anywhere; }
.outcome-probability { font-weight: 700; font-variant-numeric: tabular-nums; font-size: 1.1rem; }
.outcome .trade { background: var(--accent); color: white; padding: 7px 12px; font-weight: 600; }
.outcome.winner { border-color: var(--success); }
.outcome.winner .outcome-bar { background: var(--success-soft); }
.outcome.loser { opacity: 0.55; }

/* Explicit minimums, because browsers size table columns differently (Firefox would
   squeeze the stock column to a sliver and wrap the headers). Number columns shrink
   to fit their content and never wrap. The stock column takes the remaining width. */
.portfolio { width: 100%; border-collapse: collapse; }
.portfolio th { font-size: 0.8rem; font-weight: 500; color: var(--muted); text-align: start; padding: 0 0 6px; white-space: nowrap; }
.portfolio td { padding: 7px 0; border-top: 1px solid var(--border); }
.portfolio .number { width: 1%; min-width: 4.5em; text-align: end; font-variant-numeric: tabular-nums; padding-inline-start: 14px; white-space: nowrap; }
.portfolio .stock-name { display: flex; align-items: center; min-width: 5em; }
.portfolio .stock-name span:last-child { min-width: 0; overflow-wrap: anywhere; }
.portfolio .stock-name .line-key { flex: none; }
@media (max-width: 380px) {
  .portfolio { font-size: 0.9rem; }
  .portfolio .number { padding-inline-start: 10px; }
}
.portfolio tfoot td { font-weight: 700; border-top: 2px solid var(--border); }
.portfolio tfoot .full-cash-out td { border-top: 1px solid var(--border); }
.table-scroll { overflow-x: auto; }
.table-scroll + p { margin: 10px 0 0; }

.standings { list-style: none; margin: 0; padding: 0; }
.standings li { display: flex; gap: 10px; padding: 7px 4px; border-bottom: 1px solid var(--border); }
.standings li:last-child { border-bottom: none; }
.standings li.me { font-weight: 700; }
.standings .rank { width: 1.5em; color: var(--muted); text-align: end; }
.standings .name { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.standings .worth { font-variant-numeric: tabular-nums; }
.tag { font-size: 0.7rem; font-weight: 600; color: var(--muted); border: 1px solid var(--border); border-radius: 6px; padding: 0 5px; }

.host-controls { display: grid; gap: 10px; justify-items: start; }
.host-controls .row { width: 100%; }

.activity { list-style: none; margin: 0; padding: 0; font-size: 0.9rem; }
.activity li { padding: 6px 0; border-bottom: 1px solid var(--border); overflow-wrap: anywhere; }
.activity li:last-child { border-bottom: none; }

.sheet {
  position: fixed;
  inset: 0;
  background: rgb(0 0 0 / 0.45);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 10;
}
.sheet[hidden] { display: none; }
.sheet-card {
  background: var(--surface);
  width: 100%;
  max-width: 560px;
  border-radius: var(--radius) var(--radius) 0 0;
  padding: 16px 16px calc(16px + env(safe-area-inset-bottom));
}
.sheet-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.tabs { display: flex; gap: 6px; margin-bottom: 14px; }
.tabs button { flex: 1; padding: 9px; background: var(--background); color: var(--text); font-weight: 600; }
.tabs button.active { background: var(--accent); color: white; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; margin: -6px 0 10px; }
.chips button { background: var(--background); color: var(--text); border: 1px solid var(--border); padding: 5px 12px; font-size: 0.85rem; }
.preview { min-height: 3em; font-size: 0.95rem; }
.sheet-card .primary { width: 100%; }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: var(--text);
  color: var(--surface);
  padding: 10px 16px;
  border-radius: 10px;
  z-index: 20;
}
.toast[hidden] { display: none; }

.line-key { display: inline-block; width: 12px; height: 3px; border-radius: 2px; vertical-align: middle; margin-inline-end: 7px; }

.chart { position: relative; margin: 4px 0 14px; touch-action: pan-y; user-select: none; -webkit-user-select: none; }
/* Time runs left to right even in right-to-left languages. */
.chart svg { display: block; overflow: visible; direction: ltr; }
.chart svg:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }
.chart-grid { stroke: var(--grid); stroke-width: 1; }
.chart-baseline { stroke: var(--axis); stroke-width: 1; }
.chart-axis { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart-line { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart-dot { stroke: var(--surface); stroke-width: 2; }
.chart-crosshair { stroke: var(--muted); stroke-width: 1; }
.chart-tooltip {
  position: absolute;
  top: 0;
  pointer-events: none;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 10px;
  font-size: 0.85rem;
  box-shadow: 0 4px 14px rgb(0 0 0 / 0.12);
  max-width: 220px;
  z-index: 2;
}
.chart-tooltip[hidden] { display: none; }
.chart-tooltip-time { color: var(--muted); font-size: 0.75rem; margin-bottom: 4px; }
.chart-tooltip-row { display: flex; align-items: center; gap: 6px; white-space: nowrap; }
.chart-tooltip-row .line-key { margin-inline-end: 0; flex: none; }
.chart-tooltip-row strong { font-variant-numeric: tabular-nums; min-width: 2.6em; }
.chart-tooltip-row span:last-child { overflow: hidden; text-overflow: ellipsis; }

h2.question { font-size: 1.25rem; margin: 6px 0 8px; }
.invite { border-color: var(--accent); }
.invite p { margin: 0 0 10px; }
.hint { background: var(--accent-soft); border-radius: 10px; padding: 10px 12px; font-size: 0.9rem; margin: 10px 0 0; }
.help ul, .help ol { padding-inline-start: 20px; }
.help li { margin-bottom: 8px; }
.help h2 { margin-top: 20px; }
.topbar #whoami { max-width: 35vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
