/* ---------- tokens ---------- */
:root {
  color-scheme: light;
  --bg: #f4f3ef;
  --surface: #fcfcfb;
  --surface-2: #f0efec;
  --border: #e2e0da;
  --grid: #e9e7e2;
  --text: #0b0b0b;
  --text-2: #52514e;
  --muted: #6c6b66;
  --accent: #2563c4;
  --accent-ink: #ffffff;
  --accent-soft: #e3edfb;
  --pos: #0b7a2b;
  --neg: #c0302f;
  --danger: #c0302f;
  --ok-bg: #e5f4e8;
  --err-bg: #fbe8e7;
  /* chart series (validated) */
  --series-earned: #2a78d6;
  --series-lost: #e34948;
  --series-line: #2a78d6;
  --ord-all: #184f95;
  --ord-tried: #3987e5;
  --ord-none: #86b6ef;
  --shadow: 0 1px 2px rgb(0 0 0 / .05), 0 2px 8px rgb(0 0 0 / .04);
  --radius: 14px;
  --tabs-h: 64px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #121211;
    --surface: #1a1a19;
    --surface-2: #242422;
    --border: #33332f;
    --grid: #2b2b28;
    --text: #f0efec;
    --text-2: #c3c2b7;
    --muted: #9b9a92;
    --accent: #3987e5;
    --accent-ink: #ffffff;
    --accent-soft: #1d2f48;
    --pos: #4cc56a;
    --neg: #f07a79;
    --danger: #f07a79;
    --ok-bg: #16301d;
    --err-bg: #3a1b1b;
    --series-earned: #3987e5;
    --series-lost: #e66767;
    --series-line: #3987e5;
    --ord-all: #9ec5f4;
    --ord-tried: #3987e5;
    --ord-none: #184f95;
    --shadow: none;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #121211;
  --surface: #1a1a19;
  --surface-2: #242422;
  --border: #33332f;
  --grid: #2b2b28;
  --text: #f0efec;
  --text-2: #c3c2b7;
  --muted: #9b9a92;
  --accent: #3987e5;
  --accent-ink: #ffffff;
  --accent-soft: #1d2f48;
  --pos: #4cc56a;
  --neg: #f07a79;
  --danger: #f07a79;
  --ok-bg: #16301d;
  --err-bg: #3a1b1b;
  --series-earned: #3987e5;
  --series-lost: #e66767;
  --series-line: #3987e5;
  --ord-all: #9ec5f4;
  --ord-tried: #3987e5;
  --ord-none: #184f95;
  --shadow: none;
}

/* ---------- base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  font-variant-numeric: tabular-nums;
  -webkit-tap-highlight-color: transparent;
}
h1, h2 { margin: 0; line-height: 1.2; }
h1 { font-size: 1.45rem; }
h2 { font-size: 1.1rem; }
h2 small { font-weight: 400; font-size: .8rem; }
p { margin: 0; }
a { color: var(--accent); }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.center { text-align: center; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.pos { color: var(--pos); }
.neg { color: var(--neg); }
[hidden] { display: none !important; }

main {
  max-width: 760px;
  margin: 0 auto;
  padding: 16px 16px calc(var(--tabs-h) + 24px + env(safe-area-inset-bottom));
}
main.main-auth { padding-bottom: 32px; }
.stack { display: grid; grid-template-columns: minmax(0, 1fr); gap: 16px; }

/* ---------- top bar & tabs ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 16px; padding-top: max(10px, env(safe-area-inset-top));
  background: color-mix(in srgb, var(--surface) 90%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 8px; color: var(--text); text-decoration: none; font-weight: 700; }
.total-badge {
  display: inline-flex; align-items: baseline; gap: 6px;
  padding: 4px 12px; border-radius: 999px;
  background: var(--surface-2); color: var(--text); text-decoration: none;
}
.total-badge strong { font-size: 1.1rem; }
.total-badge.neg strong { color: var(--neg); }
.total-label { font-size: .8rem; color: var(--muted); }

.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: grid; grid-template-columns: repeat(5, 1fr);
  height: calc(var(--tabs-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--surface); border-top: 1px solid var(--border);
}
.tabs a {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  color: var(--muted); text-decoration: none; font-size: .7rem;
}
.tabs a[aria-current="page"] { color: var(--accent); font-weight: 600; }
.tabs svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.tabs svg .fill { fill: currentColor; stroke: none; }

@media (min-width: 760px) {
  .topbar { padding-inline: max(16px, calc((100vw - 1000px) / 2)); }
  .tabs {
    position: sticky; top: 57px; bottom: auto; height: auto;
    display: flex; justify-content: center; gap: 4px; padding: 6px 16px;
    border-top: 0; border-bottom: 1px solid var(--border);
  }
  .tabs a { flex-direction: row; gap: 8px; font-size: .95rem; padding: 8px 14px; border-radius: 10px; }
  .tabs a[aria-current="page"] { background: var(--accent-soft); }
  .tabs svg { width: 20px; height: 20px; }
  main { padding-top: 24px; padding-bottom: 48px; }
}

/* ---------- cards & forms ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px; box-shadow: var(--shadow);
  display: grid; grid-template-columns: minmax(0, 1fr); gap: 14px; align-content: start;
}
.card.flush { padding: 0; gap: 0; overflow: hidden; }
.card-pad { padding: 16px 16px 10px; display: grid; gap: 8px; }
.form { display: grid; gap: 12px; }
.row { display: flex; flex-wrap: wrap; gap: 12px; }
.row > .field { flex: 1 1 140px; }
.row > .grow { flex: 3 1 220px; }
.field { display: grid; gap: 4px; margin: 0; padding: 0; border: 0; min-width: 0; }
.field > span, .field > legend, .segmented legend { font-size: .85rem; font-weight: 600; color: var(--text-2); padding: 0; }
input, select, button { font: inherit; color: inherit; }
input:not([type="radio"]):not([type="checkbox"]), select {
  width: 100%; min-width: 0; max-width: 100%; min-height: 46px; padding: 10px 12px;
  border: 1px solid var(--border); border-radius: 10px;
  background: var(--bg);
}
input:focus-visible, select:focus-visible, button:focus-visible, a:focus-visible, [tabindex]:focus-visible, summary:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}
.hint { font-size: .85rem; color: var(--muted); }
.alert { padding: 10px 12px; border-radius: 10px; font-size: .95rem; }
.alert.error { background: var(--err-bg); color: var(--danger); }
.alert.ok { background: var(--ok-bg); color: var(--pos); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 8px 16px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text);
  text-decoration: none; font-weight: 600; cursor: pointer;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.wide { width: 100%; }
.btn:active { transform: translateY(1px); }
.btn-icon {
  display: inline-flex; align-items: center; justify-content: center;
  width: 44px; height: 44px; border-radius: 10px; border: 0; background: transparent;
  color: var(--text-2); font-size: 1.6rem; line-height: 1; text-decoration: none; cursor: pointer;
}
.btn-icon:hover { background: var(--surface-2); }
.btn-icon svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.btn-icon.danger:hover { color: var(--danger); }
.btn-icon.disabled { opacity: .3; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }
.htmx-request button, .htmx-request .btn { opacity: .6; pointer-events: none; }

.more summary { cursor: pointer; color: var(--accent); font-size: .9rem; padding: 4px 0; }
.more[open] summary { margin-bottom: 6px; }

/* result picker: three big tap targets */
.segmented { border: 0; margin: 0; padding: 0; display: grid; gap: 6px; }
.seg-options { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.seg {
  position: relative; display: grid; justify-items: center; gap: 2px;
  padding: 10px 4px; border-radius: 12px; border: 1.5px solid var(--border); background: var(--bg);
  cursor: pointer; text-align: center;
}
.seg input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.seg-label { font-weight: 600; font-size: .95rem; }
.seg-pts { font-size: 1.25rem; font-weight: 700; color: var(--text-2); }
.seg:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.seg:has(input:checked) .seg-pts { color: var(--accent); }
.seg:has(input:focus-visible) { outline: 2px solid var(--accent); outline-offset: 2px; }

/* minutes stepper */
.stepper { display: grid; grid-template-columns: 52px 1fr 52px; gap: 8px; align-items: center; }
.step { min-height: 46px; font-size: 1.4rem; padding: 0; }
.stepper-value { position: relative; }
.stepper-value input { text-align: center; font-size: 1.2rem; font-weight: 700; padding-right: 44px !important; }
.stepper-value span { position: absolute; right: 12px; top: 50%; transform: translateY(-50%); color: var(--muted); pointer-events: none; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 4px; }
.chip {
  min-height: 36px; padding: 4px 14px; border-radius: 999px;
  border: 1px solid var(--border); background: var(--surface-2); cursor: pointer; font-size: .9rem;
}
.chip:hover { border-color: var(--accent); }

/* ---------- day ---------- */
.day-head { display: grid; gap: 12px; }
.day-nav { display: grid; grid-template-columns: 44px 1fr 44px; align-items: center; text-align: center; }
.day-title h1::first-letter { text-transform: uppercase; }
.day-title p { font-size: .9rem; }
.day-jump { display: flex; justify-content: center; }
.day-jump input { max-width: 200px; min-height: 40px !important; padding: 6px 10px !important; text-align: center; }
.score {
  display: grid; grid-template-columns: auto 1fr; gap: 16px; align-items: center;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow);
}
.hero { display: grid; }
.hero-label { font-size: .85rem; color: var(--muted); }
.hero-num { font-size: 3.2rem; font-weight: 800; line-height: 1; letter-spacing: -.02em; color: var(--text); }
.hero-num.neg { color: var(--neg); }
.day-sum { display: grid; gap: 4px; margin: 0; }
.day-sum div { display: flex; justify-content: space-between; gap: 8px; }
.day-sum dt { color: var(--muted); font-size: .9rem; }
.day-sum dd { margin: 0; font-weight: 600; }
.day-sum div:last-child { border-top: 1px solid var(--border); padding-top: 4px; }

.entries { list-style: none; margin: 0; padding: 0; display: grid; }
.entry {
  display: grid; grid-template-columns: 48px 1fr auto; gap: 10px; align-items: center;
  padding: 10px 0; border-top: 1px solid var(--border);
}
.entry.editing { grid-template-columns: 1fr; padding: 14px 0; }
.entry-body { min-width: 0; }
.entry-title { font-weight: 600; overflow-wrap: anywhere; }
.entry-meta { font-size: .85rem; color: var(--muted); }
.entry-note { font-size: .85rem; color: var(--text-2); font-style: italic; overflow-wrap: anywhere; }
.entry-actions { display: flex; }
.entry-actions form { margin: 0; }
.pts {
  display: inline-flex; align-items: center; justify-content: center;
  height: 36px; border-radius: 10px; background: var(--surface-2);
  font-weight: 700; color: var(--text-2);
}
.pts.pos { color: var(--pos); }
.pts.neg { color: var(--neg); }
.empty { color: var(--muted); text-align: center; padding: 12px 0; }

/* ---------- auth ---------- */
.auth { max-width: 380px; margin: 8vh auto 0; display: grid; gap: 16px; justify-items: center; }
.auth .card { width: 100%; }

/* ---------- tiles ---------- */
.tiles { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
@media (min-width: 640px) { .tiles { grid-template-columns: repeat(4, 1fr); } }
.tile {
  display: grid; gap: 2px; align-content: start;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; box-shadow: var(--shadow);
}
.tile-label { font-size: .8rem; color: var(--muted); }
.tile-num { font-size: 1.5rem; font-weight: 700; }
.tile-sub { font-size: .8rem; color: var(--text-2); }
.hero-tile { display: grid; justify-items: center; gap: 4px; padding: 8px 0; text-align: center; }
.hero-tile .hero-num { font-size: 3.6rem; }

.month-nav { display: grid; grid-template-columns: 44px 1fr 44px; align-items: center; text-align: center; }
.month-nav h1::first-letter { text-transform: uppercase; }

/* period filter */
.filter { display: flex; gap: 4px; overflow-x: auto; padding: 4px; background: var(--surface-2); border-radius: 12px; scrollbar-width: none; }
.filter a {
  flex: 1 0 auto; text-align: center; padding: 8px 12px; border-radius: 9px;
  color: var(--text-2); text-decoration: none; font-size: .9rem; white-space: nowrap;
}
.filter a[aria-current="true"] { background: var(--surface); color: var(--text); font-weight: 600; box-shadow: var(--shadow); }

/* ---------- tables ---------- */
.table { width: 100%; border-collapse: collapse; font-size: .92rem; }
.table th, .table td { padding: 10px 12px; text-align: left; border-top: 1px solid var(--border); vertical-align: top; }
.table thead th { font-size: .78rem; font-weight: 600; color: var(--muted); border-top: 0; padding-top: 12px; }
.table tbody th { font-weight: 600; }
.table .num { text-align: right; white-space: nowrap; }
.table a { color: var(--text); text-decoration: none; }
.table tbody th a { text-decoration: underline; text-decoration-color: var(--border); text-underline-offset: 3px; }
.cell-sub { display: block; font-size: .75rem; color: var(--muted); font-weight: 400; }
.history tr.is-empty th a { color: var(--muted); }
@media (max-width: 420px) { .table th, .table td { padding: 9px 8px; } }

.table-view summary { cursor: pointer; color: var(--accent); font-size: .9rem; }
.table-view .table { margin-top: 8px; }

/* ---------- charts ---------- */
.chart { margin: 0; }
.chart figcaption { display: grid; gap: 6px; }
.legend { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 4px 16px; font-size: .85rem; color: var(--text-2); }
.legend li { display: inline-flex; align-items: center; gap: 6px; }
.swatch { width: 12px; height: 12px; border-radius: 3px; display: inline-block; }
.swatch-earned { background: var(--series-earned); }
.swatch-lost { background: var(--series-lost); }
.swatch-all { background: var(--ord-all); }
.swatch-tried { background: var(--ord-tried); }
.swatch-none { background: var(--ord-none); }

.plot {
  display: grid; grid-template-columns: 40px minmax(0, 1fr); grid-template-rows: 200px auto;
  column-gap: 8px; font-size: .75rem; color: var(--muted);
}
@media (min-width: 640px) { .plot { grid-template-rows: 240px auto; } }
.y-axis { position: relative; }
.y-axis span { position: absolute; right: 0; transform: translateY(-50%); }
.plot-area { position: relative; margin-right: 36px; }
.grid { position: absolute; left: 0; right: 0; height: 0; border-top: 1px solid var(--grid); }
.grid.zero { border-top-color: var(--muted); opacity: .6; }
.plot-area svg { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; }
.plot-area .line { fill: none; stroke: var(--series-line); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.plot-area .area { fill: var(--series-line); opacity: .1; }
.dot {
  position: absolute; width: 12px; height: 12px; margin: -6px 0 0 -6px; border-radius: 50%;
  background: var(--series-line); box-shadow: 0 0 0 2px var(--surface); pointer-events: none;
}
.end-label { position: absolute; left: 100%; margin-left: 8px; transform: translateY(-50%); font-weight: 700; color: var(--text); font-size: .85rem; }
.crosshair { position: absolute; top: 0; bottom: 0; width: 0; border-left: 1px solid var(--muted); pointer-events: none; }
.hit { position: absolute; inset: 0; touch-action: pan-y; cursor: crosshair; }
.x-axis { grid-column: 2; position: relative; height: 22px; margin-right: 36px; }
.x-axis span { position: absolute; top: 6px; transform: translateX(-50%); white-space: nowrap; }
.x-axis span:first-child { transform: none; }
.x-axis span:last-child:not(:first-child) { transform: translateX(-100%); }

.cols { position: absolute; inset: 0; display: flex; gap: 2px; }
.col { position: relative; flex: 1 1 0; min-width: 0; cursor: default; }
.col:hover, .col:focus-visible { background: color-mix(in srgb, var(--grid) 60%, transparent); border-radius: 4px; }
.bar { position: absolute; left: 50%; transform: translateX(-50%); width: min(24px, 70%); }
.bar.up { background: var(--series-earned); border-radius: 4px 4px 0 0; }
.bar.down { background: var(--series-lost); border-radius: 0 0 4px 4px; }
.cols-x { display: flex; gap: 2px; }
.cols-x span { position: static; flex: 1 1 0; min-width: 0; text-align: center; transform: none !important; overflow: visible; }

.foods .bar-col { width: 40%; vertical-align: middle; }
.segbar { display: flex; gap: 2px; height: 8px; border-radius: 999px; overflow: hidden; }
.segbar span:first-child { border-radius: 999px 0 0 999px; }
.segbar span:last-child { border-radius: 0 999px 999px 0; }
.segbar span:only-child { border-radius: 999px; }
.part-all { background: var(--ord-all); }
.part-tried { background: var(--ord-tried); }
.part-none { background: var(--ord-none); }

.tooltip {
  position: fixed; z-index: 50; pointer-events: none;
  max-width: 260px; padding: 6px 10px; border-radius: 8px;
  background: var(--text); color: var(--surface); font-size: .82rem; line-height: 1.35;
  box-shadow: 0 4px 14px rgb(0 0 0 / .18);
}

/* ---------- export ---------- */
.options { display: grid; gap: 8px; }
.option {
  display: grid; grid-template-columns: 22px 1fr; gap: 10px; align-items: start;
  padding: 12px; border: 1.5px solid var(--border); border-radius: 12px; cursor: pointer;
}
.option input { margin: 3px 0 0; width: 18px; height: 18px; accent-color: var(--accent); }
.option > span { display: grid; gap: 2px; }
.option:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }

@media (forced-colors: active) {
  .bar, .swatch, .segbar span, .dot { forced-color-adjust: none; }
}
