/* Trilogy - one stylesheet for every page. Colors are tokens; dark mode redefines them. */
:root {
  color-scheme: light;
  --bg: #f4f3ef;
  --surface: #ffffff;
  --surface-2: #f9f8f5;
  --ink: #15171c;
  --ink-2: #4a4e57;
  --muted: #747882;
  --line: #e2e0d9;
  --line-strong: #cfccc3;
  --brand: #c2410c;
  --brand-hover: #a3360a;
  --brand-ink: #ffffff;
  --brand-soft: #fcebe2;
  --bar: #14171c;
  --bar-ink: #f3f1ec;
  --swim: #2a78d6;
  --bike: #eb6834;
  --run: #1baf7a;
  --good: #0a7a32;
  --good-soft: #e3f4e8;
  --danger: #b42318;
  --danger-soft: #fdecea;
  --focus: #2a78d6;
  --grid: #e7e5df;
  --axis: #8a8d94;
  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 1px 2px rgba(20, 23, 28, .06), 0 4px 16px rgba(20, 23, 28, .05);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --display: "Barlow Condensed", system-ui, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0e1013;
    --surface: #171a1f;
    --surface-2: #1c2026;
    --ink: #eef0f2;
    --ink-2: #c3c7ce;
    --muted: #8c919a;
    --line: #2a2f37;
    --line-strong: #3a404a;
    --brand: #f07a3f;
    --brand-hover: #f59262;
    --brand-ink: #1b0c04;
    --brand-soft: #33200f;
    --bar: #0a0b0d;
    --swim: #3987e5;
    --bike: #d95926;
    --run: #199e70;
    --good: #3fbf6a;
    --good-soft: #13281a;
    --danger: #f2716a;
    --danger-soft: #34171a;
    --focus: #6aa7f0;
    --grid: #262a31;
    --axis: #8c919a;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0e1013; --surface: #171a1f; --surface-2: #1c2026; --ink: #eef0f2; --ink-2: #c3c7ce; --muted: #8c919a;
  --line: #2a2f37; --line-strong: #3a404a; --brand: #f07a3f; --brand-hover: #f59262; --brand-ink: #1b0c04;
  --brand-soft: #33200f; --bar: #0a0b0d; --swim: #3987e5; --bike: #d95926; --run: #199e70; --good: #3fbf6a;
  --good-soft: #13281a; --danger: #f2716a; --danger-soft: #34171a; --focus: #6aa7f0; --grid: #262a31; --axis: #8c919a;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4);
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; min-height: 100vh; display: flex; flex-direction: column;
  background: var(--bg); color: var(--ink); font: 16px/1.5 var(--font);
  overflow-x: hidden;
}
img, svg { max-width: 100%; }
a { color: var(--brand); text-underline-offset: 2px; }
a:hover { color: var(--brand-hover); }
h1, h2, h3 { font-family: var(--display); font-weight: 700; letter-spacing: .01em; line-height: 1.1; margin: 0 0 .4em; }
h1 { font-size: clamp(2rem, 5vw, 2.8rem); }
h2 { font-size: 1.55rem; }
h3 { font-size: 1.2rem; }
p { margin: 0 0 1em; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
[hidden] { display: none !important; }
.skip { position: absolute; left: -999px; top: 0; background: var(--surface); padding: 8px 12px; z-index: 100; }
.skip:focus { left: 8px; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.nowrap { white-space: nowrap; }

/* ---------- top bar ---------- */
.topbar { background: var(--bar); color: var(--bar-ink); position: sticky; top: 0; z-index: 40; }
.topbar-inner { max-width: 1200px; margin: 0 auto; padding: 10px 16px; display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.logo-link { display: flex; align-items: center; gap: 10px; text-decoration: none; color: inherit; margin-right: auto; }
.logo-link:hover { color: inherit; }
.logo-mark { width: 30px; height: 30px; flex: none; }
.logo-text { font-family: var(--display); font-size: 1.45rem; font-weight: 700; letter-spacing: .02em; white-space: nowrap; }
.site-nav, .public-nav { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; }
.site-nav a, .public-nav a:not(.btn), .link-button {
  color: var(--bar-ink); text-decoration: none; padding: 7px 10px; border-radius: 8px; font-size: .95rem;
  background: none; border: 0; font: inherit; cursor: pointer; opacity: .82;
}
.site-nav a:hover, .public-nav a:not(.btn):hover, .link-button:hover { opacity: 1; background: rgba(255, 255, 255, .08); color: var(--bar-ink); }
.site-nav a[aria-current="page"] { opacity: 1; background: rgba(235, 104, 52, .2); box-shadow: inset 0 -2px 0 #eb6834; }
.nav-sep { width: 1px; height: 22px; background: rgba(255, 255, 255, .18); margin: 0 6px; }
.menu-button {
  display: none; align-items: center; gap: 6px; background: rgba(255, 255, 255, .08); color: var(--bar-ink);
  border: 1px solid rgba(255, 255, 255, .18); border-radius: 9px; padding: 7px 12px; font: inherit; cursor: pointer;
}
.menu-button svg { width: 20px; height: 20px; stroke: currentColor; stroke-width: 2; fill: none; stroke-linecap: round; }
@media (max-width: 1060px) {
  .menu-button { display: inline-flex; }
  .site-nav { display: none; width: 100%; flex-direction: column; align-items: stretch; gap: 2px; padding: 6px 0 4px; }
  .site-nav.open { display: flex; }
  .site-nav a, .site-nav .link-button { padding: 11px 12px; text-align: left; font-size: 1rem; }
  .nav-sep { width: 100%; height: 1px; margin: 6px 0; }
}
.banner { padding: 10px 16px; text-align: center; font-size: .95rem; }
.demo-banner { background: var(--brand-soft); color: var(--ink); border-bottom: 1px solid var(--line); }
.waking-banner { background: #fff4d6; color: #4a3500; border-bottom: 1px solid #f0d78c; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .waking-banner { background: #3a2f0b; color: #ffe7a3; border-color: #5b4a12; } }
:root[data-theme="dark"] .waking-banner { background: #3a2f0b; color: #ffe7a3; border-color: #5b4a12; }

/* ---------- layout ---------- */
.main { flex: 1; width: 100%; max-width: 1200px; margin: 0 auto; padding: 24px 16px 48px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px 20px; flex-wrap: wrap; margin-bottom: 18px; }
.page-head h1 { margin: 0; }
.page-head p { margin: 4px 0 0; color: var(--ink-2); }
.page-head .actions { display: flex; gap: 8px; flex-wrap: wrap; }
.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
@media (max-width: 900px) { .grid-3, .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 640px) { .grid-2, .grid-3 { grid-template-columns: minmax(0, 1fr); } }
@media (max-width: 400px) { .grid-4 { grid-template-columns: minmax(0, 1fr); } }
.section { margin-top: 28px; }
.section > h2 { margin-bottom: 12px; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); min-width: 0; }
.card h2, .card h3 { margin-top: 0; }
.card-head { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; flex-wrap: wrap; margin-bottom: 10px; }
.card-head h2, .card-head h3 { margin: 0; }

/* stat tiles */
.stat { display: flex; flex-direction: column; gap: 2px; }
.stat .label { font-size: .8rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 600; }
.stat .value { font-family: var(--display); font-size: 2.2rem; font-weight: 700; line-height: 1.05; font-variant-numeric: tabular-nums; }
.stat .value small { font-size: 1rem; font-family: var(--font); font-weight: 500; color: var(--ink-2); margin-left: 4px; }
.stat .sub { font-size: .9rem; color: var(--ink-2); }
.delta-good { color: var(--good); font-weight: 600; }
.delta-bad { color: var(--danger); font-weight: 600; }
.sport-dot { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: 0; }
.sport-swim { background: var(--swim); } .sport-bike { background: var(--bike); } .sport-run { background: var(--run); }
.sport-strength, .sport-other { background: var(--muted); }
.stat-sport { border-top: 4px solid var(--line); }
.stat-sport.swim { border-top-color: var(--swim); } .stat-sport.bike { border-top-color: var(--bike); } .stat-sport.run { border-top-color: var(--run); }

.hero-countdown { background: var(--bar); color: var(--bar-ink); border-color: var(--bar); position: relative; overflow: hidden; }
.hero-countdown .label { color: rgba(243, 241, 236, .7); }
.hero-countdown .sub { color: rgba(243, 241, 236, .85); }
.hero-countdown::after {
  content: ""; position: absolute; right: -30px; bottom: -30px; width: 150px; height: 150px; opacity: .14;
  background: repeating-linear-gradient(0deg, #eb6834 0 18px, transparent 18px 24px);
  mask: linear-gradient(135deg, transparent 30%, #000 70%);
}

/* charts */
.chart-box { position: relative; height: 260px; }
.chart-box.short { height: 200px; }
.legend { display: flex; flex-wrap: wrap; gap: 4px 16px; font-size: .875rem; color: var(--ink-2); margin: 0 0 8px; padding: 0; list-style: none; }
.legend li { display: flex; align-items: center; }
.chart-note { font-size: .85rem; color: var(--muted); margin: 8px 0 0; }
details.table-view { margin-top: 8px; font-size: .9rem; }
details.table-view summary { cursor: pointer; color: var(--ink-2); }

/* buttons & forms */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; border-radius: 10px; border: 1px solid transparent;
  background: var(--brand); color: var(--brand-ink); font: 600 .95rem/1 var(--font); padding: 11px 16px; cursor: pointer;
  text-decoration: none; min-height: 42px;
}
.btn:hover { background: var(--brand-hover); color: var(--brand-ink); }
.btn:disabled { opacity: .6; cursor: progress; }
.btn-small { padding: 8px 12px; min-height: 36px; font-size: .9rem; }
.btn-ghost { background: transparent; color: var(--ink); border-color: var(--line-strong); }
.btn-ghost:hover { background: var(--surface-2); color: var(--ink); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: var(--danger); filter: brightness(1.1); color: #fff; }
.icon-btn { background: none; border: 1px solid transparent; color: var(--ink-2); border-radius: 8px; padding: 6px 9px; cursor: pointer; font: inherit; font-size: .875rem; }
.icon-btn:hover { background: var(--surface-2); border-color: var(--line); color: var(--ink); }

.form { display: grid; gap: 14px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px 14px; }
.form-grid .wide { grid-column: 1 / -1; }
@media (max-width: 520px) { .form-grid { grid-template-columns: minmax(0, 1fr); } }
.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.field label, .field .label { font-size: .875rem; font-weight: 600; color: var(--ink-2); }
.field .hint { font-size: .8rem; color: var(--muted); }
input, select, textarea {
  font: inherit; color: var(--ink); background: var(--surface); border: 1px solid var(--line-strong); border-radius: 9px;
  padding: 10px 11px; width: 100%; min-width: 0; min-height: 42px;
}
textarea { min-height: 84px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--focus); outline-offset: 0; border-color: var(--focus); }
.form-error { background: var(--danger-soft); color: var(--danger); border-radius: 9px; padding: 10px 12px; font-size: .95rem; }
.form-actions { display: flex; gap: 10px; flex-wrap: wrap; justify-content: flex-end; }
fieldset { border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 12px 14px 14px; margin: 0; min-width: 0; }
legend { font-weight: 700; padding: 0 6px; }

/* entry panel (dialog) */
dialog.panel {
  border: 0; padding: 0; border-radius: 16px; width: min(640px, calc(100vw - 24px)); max-height: calc(100vh - 32px);
  background: var(--surface); color: var(--ink); box-shadow: 0 20px 60px rgba(0, 0, 0, .35);
}
dialog.panel::backdrop { background: rgba(10, 12, 15, .55); }
.panel-head { display: flex; justify-content: space-between; align-items: center; padding: 16px 18px 10px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--surface); z-index: 1; }
.panel-head h2 { margin: 0; font-size: 1.5rem; }
.panel-body { padding: 16px 18px 20px; }

/* lists of records: a table on wide screens, stacked cards on phones */
.records { width: 100%; border-collapse: collapse; font-size: .95rem; }
.records th { text-align: left; font-size: .78rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 600; padding: 8px 10px; border-bottom: 1px solid var(--line); }
.records td { padding: 10px; border-bottom: 1px solid var(--line); vertical-align: top; font-variant-numeric: tabular-nums; }
.records tr:last-child td { border-bottom: 0; }
.records .num { text-align: right; }
.records .actions { text-align: right; white-space: nowrap; }
.records .title-cell strong { display: block; }
.tag { display: inline-block; font-size: .72rem; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; padding: 2px 7px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--line); color: var(--ink-2); }
.tag-sample { background: var(--brand-soft); border-color: transparent; color: var(--brand); }
.tag-done { background: var(--good-soft); color: var(--good); border-color: transparent; }
@media (max-width: 760px) {
  .records thead { display: none; }
  .records, .records tbody, .records tr, .records td { display: block; width: 100%; }
  .records tr { border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; margin-bottom: 10px; background: var(--surface); }
  .records td { border: 0; padding: 3px 0; display: flex; justify-content: space-between; gap: 12px; text-align: right; }
  .records td::before { content: attr(data-label); color: var(--muted); font-size: .85rem; text-align: left; flex: none; }
  .records td.title-cell { display: block; text-align: left; font-size: 1rem; padding-bottom: 6px; }
  .records td.title-cell::before { content: none; }
  .records td.actions { justify-content: flex-end; padding-top: 6px; }
  .records td.actions::before { content: none; }
  .records td:empty { display: none; }
}
.empty { text-align: center; padding: 28px 12px; color: var(--muted); }

/* split table (goals) */
.splits { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.splits th, .splits td { padding: 9px 8px; border-bottom: 1px solid var(--line); text-align: right; }
.splits th:first-child, .splits td:first-child { text-align: left; }
.splits thead th { font-size: .78rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.splits tfoot td { font-weight: 700; border-bottom: 0; }
@media (max-width: 480px) { .splits { font-size: .88rem; } .splits th, .splits td { padding: 8px 4px; } }

/* phases timeline */
.phases { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.phases li { border: 1px solid var(--line); border-left: 5px solid var(--line-strong); border-radius: 10px; padding: 10px 12px; background: var(--surface); }
.phases li.current { border-left-color: var(--brand); background: var(--brand-soft); }
.phases li.past { opacity: .7; }
.phase-top { display: flex; justify-content: space-between; gap: 8px; flex-wrap: wrap; align-items: baseline; }
.phase-top strong { font-size: 1.05rem; }
.phase-actions { display: flex; gap: 4px; justify-content: flex-end; margin-top: 4px; }

/* progress bar */
.progress { height: 8px; border-radius: 99px; background: var(--surface-2); border: 1px solid var(--line); overflow: hidden; }
.progress > span { display: block; height: 100%; background: var(--brand); border-radius: 99px; }

/* toasts */
.toasts { position: fixed; left: 50%; bottom: 18px; transform: translateX(-50%); display: grid; gap: 8px; z-index: 1000; width: min(460px, calc(100vw - 24px)); }
.toast { background: var(--bar); color: var(--bar-ink); border-radius: 12px; padding: 12px 14px; box-shadow: 0 10px 30px rgba(0, 0, 0, .3); display: flex; gap: 12px; align-items: center; justify-content: space-between; flex-wrap: wrap; font-size: .95rem; }
.toast.error { background: var(--danger); color: #fff; }
.toast .toast-actions { display: flex; gap: 8px; margin-left: auto; }
.toast .btn-ghost { color: var(--bar-ink); border-color: rgba(255, 255, 255, .3); }
.toast .btn-ghost:hover { background: rgba(255, 255, 255, .1); color: var(--bar-ink); }

/* public pages */
.hero { display: grid; grid-template-columns: 1.1fr .9fr; gap: 28px; align-items: center; padding: 18px 0 8px; }
.hero h1 { font-size: clamp(2.4rem, 6.5vw, 4rem); line-height: .98; }
.hero h1 em { font-style: normal; color: var(--brand); }
.hero .lead { font-size: 1.15rem; color: var(--ink-2); max-width: 36em; }
.hero-actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 8px; }
.hero-art { background: var(--bar); border-radius: 22px; padding: 22px; color: var(--bar-ink); box-shadow: var(--shadow); min-width: 0; }
.hero-art .mini-row { display: flex; justify-content: space-between; gap: 10px; padding: 10px 0; border-bottom: 1px solid rgba(255, 255, 255, .1); font-variant-numeric: tabular-nums; }
.hero-art .mini-row:last-child { border-bottom: 0; }
.hero-art .big { font-family: var(--display); font-size: 3rem; font-weight: 700; line-height: 1; }
@media (max-width: 820px) { .hero { grid-template-columns: minmax(0, 1fr); } }
.features { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; margin-top: 36px; }
@media (max-width: 900px) { .features { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 560px) { .features { grid-template-columns: minmax(0, 1fr); } }
.feature h3 { display: flex; align-items: center; gap: 8px; }
.feature p { color: var(--ink-2); margin: 0; }
.auth-box { max-width: 440px; margin: 20px auto; }
.demo-box { margin-top: 16px; border: 1px dashed var(--line-strong); border-radius: 12px; padding: 12px 14px; display: flex; gap: 10px; align-items: center; justify-content: space-between; flex-wrap: wrap; }
.prose { max-width: 720px; }
.prose h2 { margin-top: 1.4em; }

.footer { border-top: 1px solid var(--line); background: var(--surface); }
.footer-inner { max-width: 1200px; margin: 0 auto; padding: 16px; display: flex; justify-content: space-between; gap: 10px; flex-wrap: wrap; color: var(--muted); font-size: .9rem; }
.footer nav { display: flex; gap: 14px; }
.footer a { color: var(--ink-2); }

.key-reveal { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; background: var(--surface-2); border: 1px solid var(--line); border-radius: 9px; padding: 10px 12px; word-break: break-all; }
.drop { border: 2px dashed var(--line-strong); border-radius: 14px; padding: 18px; text-align: center; background: var(--surface-2); }
.drop.dragging { border-color: var(--brand); background: var(--brand-soft); }
.loading { color: var(--muted); padding: 20px 0; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.eyebrow { font-family: var(--display); font-weight: 700; font-size: 1.15rem; letter-spacing: .12em; text-transform: uppercase; color: var(--brand); margin: 0 0 6px; }
