/* ============================================================
   One stylesheet for the whole site. Colours are tokens on :root, redefined
   for dark mode; each league's accent comes from body[data-sport].
   ============================================================ */

:root {
  --bg: #f4f6f9;
  --surface: #ffffff;
  --surface-2: #eef1f5;
  --line: #d9dee6;
  --text: #0f172a;
  --muted: #5b6475;
  --faint: #8a93a3;
  --accent: #0b5cad;
  --accent-2: #0ea5e9;
  --accent-ink: #ffffff;
  --good: #15803d;
  --bad: #b91c1c;
  --hl: #f59e0b;
  --shadow: 0 1px 2px rgba(15, 23, 42, .06), 0 4px 16px rgba(15, 23, 42, .06);
  --radius: 10px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  color-scheme: light;
}
body[data-sport="nhl"] { --accent: #0b5cad; --accent-2: #0ea5e9; }
body[data-sport="mlb"] { --accent: #b3122e; --accent-2: #1f5f3a; }
body[data-sport="nba"] { --accent: #d9480f; --accent-2: #1d4ed8; }

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0b1120; --surface: #131b2e; --surface-2: #1b2539; --line: #2a3650; --text: #e7ecf5; --muted: #a3adc2; --faint: #7c879e;
    --good: #4ade80; --bad: #f87171; --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 6px 20px rgba(0, 0, 0, .3); color-scheme: dark;
  }
  :root:not([data-theme="light"]) body[data-sport="nhl"] { --accent: #4ea1f5; --accent-2: #38bdf8; --accent-ink: #06121f; }
  :root:not([data-theme="light"]) body[data-sport="mlb"] { --accent: #f05268; --accent-2: #4ade80; --accent-ink: #1a0508; }
  :root:not([data-theme="light"]) body[data-sport="nba"] { --accent: #fb8a4c; --accent-2: #60a5fa; --accent-ink: #1a0a02; }
}
:root[data-theme="dark"] {
  --bg: #0b1120; --surface: #131b2e; --surface-2: #1b2539; --line: #2a3650; --text: #e7ecf5; --muted: #a3adc2; --faint: #7c879e;
  --good: #4ade80; --bad: #f87171; --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 6px 20px rgba(0, 0, 0, .3); color-scheme: dark;
}
:root[data-theme="dark"] body[data-sport="nhl"] { --accent: #4ea1f5; --accent-2: #38bdf8; --accent-ink: #06121f; }
:root[data-theme="dark"] body[data-sport="mlb"] { --accent: #f05268; --accent-2: #4ade80; --accent-ink: #1a0508; }
:root[data-theme="dark"] body[data-sport="nba"] { --accent: #fb8a4c; --accent-2: #60a5fa; --accent-ink: #1a0a02; }

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.5 var(--font); min-height: 100vh; display: flex; flex-direction: column; }
main { flex: 1; width: 100%; max-width: 1320px; margin: 0 auto; padding: 20px 16px 48px; outline: none; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { line-height: 1.2; margin: 0 0 .5em; letter-spacing: -.01em; }
h1 { font-size: 28px; } h2 { font-size: 20px; } h3 { font-size: 16px; }
p { margin: 0 0 .8em; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.skip { position: absolute; left: -999px; top: 8px; background: var(--surface); padding: 8px 12px; z-index: 100; }
.skip:focus { left: 8px; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
[hidden] { display: none !important; }

/* ---------- header and footer ---------- */
.top { background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 40; }
.top-in { max-width: 1320px; margin: 0 auto; padding: 10px 16px; display: flex; align-items: center; gap: 20px; flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 18px; color: var(--text); letter-spacing: -.02em; }
.brand:hover { text-decoration: none; }
.brand-mark { width: 26px; height: 26px; border-radius: 7px; background: linear-gradient(135deg, var(--accent), var(--accent-2)); box-shadow: inset 0 0 0 2px rgba(255, 255, 255, .25); }
.nav { display: flex; gap: 4px; flex-wrap: wrap; }
.nav a { color: var(--muted); padding: 6px 10px; border-radius: 8px; font-weight: 600; font-size: 14px; }
.nav a:hover, .nav a.on { color: var(--text); background: var(--surface-2); text-decoration: none; }
.top-tools { margin-left: auto; display: flex; gap: 8px; align-items: center; }
.search { position: relative; }
.search input { width: 220px; }
.search-results { position: absolute; right: 0; top: calc(100% + 6px); width: 320px; max-width: calc(100vw - 32px); background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 6px; z-index: 50; }
.search-results a { display: flex; justify-content: space-between; gap: 8px; padding: 8px 10px; border-radius: 6px; color: var(--text); }
.search-results a:hover, .search-results a.on { background: var(--surface-2); text-decoration: none; }
.foot { border-top: 1px solid var(--line); background: var(--surface); color: var(--muted); font-size: 13px; }
.foot-in { max-width: 1320px; margin: 0 auto; padding: 16px; display: flex; gap: 18px; flex-wrap: wrap; }
@media (max-width: 720px) {
  .top-in { gap: 10px; }
  .top-tools { margin-left: 0; width: 100%; }
  .search { flex: 1; } .search input { width: 100%; }
  .nav { order: 3; width: 100%; }
}

/* ---------- controls ---------- */
button, input, select, textarea { font: inherit; color: inherit; }
input[type="text"], input[type="search"], input[type="number"], select, textarea {
  background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px; min-height: 36px; max-width: 100%;
}
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); outline: none; box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 20%, transparent); }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid var(--line); background: var(--surface); border-radius: 8px; padding: 7px 12px; min-height: 36px; cursor: pointer; font-weight: 600; font-size: 14px; white-space: nowrap; }
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn:disabled { opacity: .45; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.small { min-height: 30px; padding: 4px 9px; font-size: 13px; }
.icon-btn { width: 36px; height: 36px; border-radius: 8px; border: 1px solid var(--line); background: var(--surface); cursor: pointer; display: inline-grid; place-items: center; }
.icon-btn:hover { background: var(--surface-2); }
#theme::before { content: "◐"; font-size: 18px; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.field { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); font-weight: 600; }
.field > input, .field > select { color: var(--text); font-weight: 400; }
.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chip { border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 5px 12px; font-size: 13px; cursor: pointer; color: var(--text); }
.chip:hover { border-color: var(--accent); color: var(--accent); }
.chip.on { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 14px; overflow-x: auto; }
.tabs button { border: 0; background: none; padding: 9px 12px; cursor: pointer; font-weight: 600; color: var(--muted); border-bottom: 2px solid transparent; white-space: nowrap; }
.tabs button.on { color: var(--text); border-bottom-color: var(--accent); }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; }
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.grid3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }
@media (max-width: 860px) { .grid2, .grid3 { grid-template-columns: 1fr; } }
.loading { color: var(--muted); padding: 24px; text-align: center; }
.error { color: var(--bad); padding: 12px; }

/* ---------- Ask ---------- */
.ask { display: flex; gap: 8px; align-items: stretch; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 6px; box-shadow: var(--shadow); }
.ask input { flex: 1; border: 0; background: transparent; min-height: 44px; font-size: 16px; padding: 0 10px; box-shadow: none !important; }
.ask .btn { min-height: 44px; }
.ask.busy { opacity: .7; }
.ask-log { display: flex; flex-direction: column; gap: 6px; margin: 10px 0 0; font-size: 14px; max-height: 180px; overflow: auto; }
.ask-log .you { align-self: flex-end; background: var(--accent); color: var(--accent-ink); padding: 6px 11px; border-radius: 12px 12px 2px 12px; max-width: 80%; }
.ask-log .it { align-self: flex-start; background: var(--surface-2); padding: 6px 11px; border-radius: 12px 12px 12px 2px; max-width: 90%; }
.ask-log .it.miss { color: var(--bad); }
.ask-log .read { font-size: 12px; color: var(--muted); }

/* ---------- home ---------- */
.hero { padding: 36px 0 20px; display: grid; gap: 18px; max-width: 820px; }
.hero h1 { font-size: clamp(30px, 5vw, 48px); letter-spacing: -.03em; }
.hero h1 em { font-style: normal; background: linear-gradient(90deg, var(--accent), var(--accent-2)); -webkit-background-clip: text; background-clip: text; color: transparent; }
.hero p { font-size: 18px; color: var(--muted); max-width: 640px; }
.features { margin-top: 28px; }
.features .card h3 { display: flex; gap: 8px; align-items: center; }
.demo { margin-top: 28px; }

/* ---------- dashboard maker ---------- */
.build-head { display: grid; gap: 12px; margin-bottom: 14px; }
.toolbar { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.toolbar .sep { width: 1px; height: 24px; background: var(--line); margin: 0 4px; }
.board-title { font-size: 22px; font-weight: 800; border: 1px dashed transparent; border-radius: 6px; padding: 2px 6px; margin-left: -6px; }
.board-title:hover { border-color: var(--line); }
.board-title:focus { border-color: var(--accent); outline: none; }
.board { --cols: 12; --row: 78px; display: grid; grid-template-columns: repeat(var(--cols), minmax(0, 1fr)); grid-auto-rows: var(--row); gap: 12px; padding: 12px; border-radius: 14px; background: var(--board-bg, transparent); min-height: 200px; }
.board.empty { display: grid; place-items: center; border: 2px dashed var(--line); color: var(--muted); text-align: center; grid-template-columns: 1fr; }
.widget { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); display: flex; flex-direction: column; min-width: 0; min-height: 0; position: relative; overflow: hidden; }
.widget.dragging { opacity: .4; }
.widget.drop-before { box-shadow: -4px 0 0 var(--accent), var(--shadow); }
.w-head { display: flex; align-items: center; gap: 6px; padding: 8px 8px 4px 12px; min-height: 36px; }
.w-title { font-weight: 700; font-size: 14px; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.w-tools { display: flex; gap: 2px; opacity: 0; transition: opacity .15s; }
.widget:hover .w-tools, .widget:focus-within .w-tools { opacity: 1; }
@media (hover: none) { .w-tools { opacity: 1; } }
.w-tools button { width: 28px; height: 28px; border: 0; background: transparent; border-radius: 6px; cursor: pointer; color: var(--muted); font-size: 15px; }
.w-tools button:hover { background: var(--surface-2); color: var(--text); }
.w-grip { cursor: grab; touch-action: none; }
.w-body { flex: 1; min-height: 0; padding: 4px 12px 10px; overflow: auto; position: relative; }
.w-body.chart { overflow: hidden; }
.w-resize { position: absolute; right: 2px; bottom: 2px; width: 16px; height: 16px; cursor: nwse-resize; touch-action: none; opacity: .5; background: linear-gradient(135deg, transparent 50%, var(--faint) 50%, var(--faint) 60%, transparent 60%, transparent 70%, var(--faint) 70%, var(--faint) 80%, transparent 80%); }
.widget.answer { background: color-mix(in srgb, var(--accent) 8%, var(--surface)); border-color: color-mix(in srgb, var(--accent) 35%, var(--line)); }
.answer-text { font-size: 16px; line-height: 1.45; }
.note-text { white-space: pre-wrap; }
@media (max-width: 720px) {
  .board { --cols: 1; grid-auto-rows: auto; }
  .widget { grid-column: 1 / -1 !important; grid-row: auto !important; min-height: 280px; }
  .widget.tiles-w, .widget.answer { min-height: 0; }
  .w-resize { display: none; }
}
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 10px; height: 100%; align-content: center; }
.tile { background: var(--surface-2); border-radius: 8px; padding: 10px 12px; min-width: 0; }
.tile .k { font-size: 12px; color: var(--muted); font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tile .v { font-size: 26px; font-weight: 800; letter-spacing: -.02em; line-height: 1.15; }
.tile .r { font-size: 12px; color: var(--muted); }
.tile .r.best { color: var(--good); font-weight: 600; }
.drawer { position: fixed; inset: 0; background: rgba(2, 6, 23, .45); z-index: 60; display: flex; justify-content: flex-end; }
.drawer-in { width: min(460px, 100%); height: 100%; background: var(--surface); padding: 18px; overflow: auto; display: flex; flex-direction: column; gap: 14px; box-shadow: var(--shadow); }
.modal { position: fixed; inset: 0; background: rgba(2, 6, 23, .45); z-index: 70; display: grid; place-items: center; padding: 16px; }
.modal-in { background: var(--surface); border-radius: 14px; padding: 20px; width: min(560px, 100%); max-height: 90vh; overflow: auto; display: grid; gap: 14px; box-shadow: var(--shadow); }
.modal-in h2 { margin: 0; }
.picks { display: flex; gap: 6px; flex-wrap: wrap; }
.pick { display: inline-flex; gap: 6px; align-items: center; background: var(--surface-2); border-radius: 999px; padding: 3px 4px 3px 10px; font-size: 13px; }
.pick button { border: 0; background: none; cursor: pointer; color: var(--muted); width: 22px; height: 22px; border-radius: 50%; }
.pick button:hover { background: var(--line); }
.add-list { display: grid; gap: 8px; }
.add-list button { text-align: left; border: 1px solid var(--line); background: var(--surface); border-radius: 10px; padding: 10px 12px; cursor: pointer; }
.add-list button:hover { border-color: var(--accent); }
.add-list b { display: block; }
.add-list span { font-size: 13px; color: var(--muted); }
.toasts { position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%); display: grid; gap: 8px; z-index: 90; }
.toast { background: var(--text); color: var(--bg); padding: 9px 14px; border-radius: 10px; font-size: 14px; box-shadow: var(--shadow); animation: toast-in .2s ease-out; }
@keyframes toast-in { from { transform: translateY(8px); opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .toast { animation: none; } }

/* ---------- tables ---------- */
.tbl-wrap { overflow: auto; max-width: 100%; }
table.tbl { border-collapse: collapse; width: 100%; font-size: 13px; font-variant-numeric: tabular-nums; }
.tbl th, .tbl td { padding: 6px 8px; border-bottom: 1px solid var(--line); text-align: right; white-space: nowrap; }
.tbl th { position: sticky; top: 0; background: var(--surface); color: var(--muted); font-weight: 700; font-size: 12px; cursor: pointer; user-select: none; z-index: 1; }
.tbl th:hover { color: var(--text); }
.tbl th.sorted { color: var(--accent); }
.tbl th.sorted::after { content: " ▾"; }
.tbl th.sorted.asc::after { content: " ▴"; }
.tbl td.l, .tbl th.l { text-align: left; }
.tbl tr:hover td { background: var(--surface-2); }
.tbl tr.hl td { background: color-mix(in srgb, var(--hl) 14%, transparent); }
.tbl .rk { color: var(--faint); width: 1%; }
.team-dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 6px; vertical-align: 0; }

/* ---------- charts ---------- */
.chart-box { width: 100%; height: 100%; position: relative; }
.chart-box svg { display: block; width: 100%; height: 100%; overflow: visible; }
.chart-tip { position: absolute; pointer-events: none; background: var(--text); color: var(--bg); font-size: 12px; padding: 6px 9px; border-radius: 7px; white-space: nowrap; z-index: 5; transform: translate(-50%, calc(-100% - 10px)); }
.legend { display: flex; gap: 12px; flex-wrap: wrap; font-size: 12px; color: var(--muted); padding: 2px 0 4px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }

/* ---------- pages ---------- */
.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; flex-wrap: wrap; margin-bottom: 16px; }
.page-head h1 { margin: 0; }
.team-head { display: flex; gap: 16px; align-items: center; }
.team-badge { width: 56px; height: 56px; border-radius: 14px; display: grid; place-items: center; color: #fff; font-weight: 900; font-size: 17px; letter-spacing: .02em; }
.team-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 10px; }
.team-grid a { display: flex; gap: 10px; align-items: center; padding: 10px; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; color: var(--text); }
.team-grid a:hover { border-color: var(--accent); text-decoration: none; }
.team-grid .team-badge { width: 36px; height: 36px; font-size: 11px; border-radius: 9px; }
.section { margin-top: 24px; }
.prose { max-width: 760px; }
.prose li { margin-bottom: 6px; }

/* ---------- graphics maker ---------- */
.gfx { display: grid; grid-template-columns: 360px minmax(0, 1fr); gap: 18px; align-items: start; }
.gfx-side { display: grid; gap: 14px; position: sticky; top: 76px; max-height: calc(100vh - 90px); overflow: auto; padding-right: 4px; }
.gfx-stage { background: var(--surface-2); border-radius: 14px; padding: 16px; display: grid; place-items: center; min-height: 300px; }
.gfx-stage svg { width: 100%; height: auto; max-height: 78vh; border-radius: 8px; box-shadow: var(--shadow); }
.subject { border: 1px solid var(--line); border-radius: 10px; padding: 10px; display: grid; gap: 8px; background: var(--surface); }
.subject-top { display: flex; justify-content: space-between; gap: 8px; align-items: center; font-weight: 700; }
@media (max-width: 960px) { .gfx { grid-template-columns: 1fr; } .gfx-side { position: static; max-height: none; } }
