/* Triathlon Tracker app shell. Tokens from prototype v4 (accent darkened in light and lightened in dark so link text and the active nav tint reach WCAG AA 4.5:1). Served under style-src 'self': no inline styles anywhere. */

/* ---- design tokens ---- */
:root {
  color-scheme: light;
  --bg: #f4f4f1; --surface: #fcfcfb; --surface2: #f1f0ec;
  --ink: #0b0b0b; --ink2: #52514e; --ink3: #6c6b65;
  --line: #e2e1db; --grid: #ebeae6; --mid: #d6d5cf;
  --swim: #2a78d6; --bike: #1a8a4c; --run: #d4600a; --tri: #7a4fd0; --on-sp: #fff;
  --s4: #eda100; --s5: #e87ba4; --s7: #6250d6; --s8: #e34948;
  --good: #0f8a5f; --bad: #d23b3a;
  --accent: #1f66bd; --on-accent: #fff;
  --r: 16px; --tab-h: 60px; --nav-w: 236px; --hdr: 0px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0f0f0e; --surface: #1a1a19; --surface2: #232321;
    --ink: #f0efec; --ink2: #c3c2b7; --ink3: #a09f95;
    --line: #2f2f2c; --grid: #2a2a27; --mid: #4a4a45;
    --swim: #4b95ec; --bike: #34b06c; --run: #f08035; --tri: #9d85f0; --on-sp: #111;
    --s4: #c98500; --s5: #d55181; --s7: #9085e9; --s8: #e66767;
    --good: #3cc08f; --bad: #ee7473; --accent: #4b95ec; --on-accent: #0b0b0b;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0f0f0e; --surface: #1a1a19; --surface2: #232321;
  --ink: #f0efec; --ink2: #c3c2b7; --ink3: #a09f95;
  --line: #2f2f2c; --grid: #2a2a27; --mid: #4a4a45;
  --swim: #4b95ec; --bike: #34b06c; --run: #f08035; --tri: #9d85f0; --on-sp: #111;
  --s4: #c98500; --s5: #d55181; --s7: #9085e9; --s8: #e66767;
  --good: #3cc08f; --bad: #ee7473; --accent: #4b95ec; --on-accent: #0b0b0b;
}

/* ---- base ---- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-padding-top: 120px; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  padding-bottom: calc(var(--tab-h) + 28px + env(safe-area-inset-bottom));
  overflow-x: hidden;
}
button, input, select { font: inherit; color: inherit; }
a { color: inherit; text-decoration: none; }
h1, h2, h3, p { margin: 0; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.page:focus, .page h1:focus, #sheetTitle:focus { outline: none; }
.sr, .skip:not(:focus) { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip:focus { position: fixed; top: 8px; left: 8px; z-index: 100; background: var(--surface); color: var(--ink); padding: 10px 14px; border-radius: 10px; border: 2px solid var(--accent); }
.noscript { padding: 24px 16px; text-align: center; color: var(--ink2); }

/* ---- shell ---- */
.shell { min-height: 100vh; }
.topline {
  max-width: 1100px; margin: 0 auto; min-height: 48px; display: flex; align-items: center; justify-content: space-between;
  padding: max(env(safe-area-inset-top), 10px) max(16px, env(safe-area-inset-right)) 0 max(16px, env(safe-area-inset-left));
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 750; letter-spacing: -.01em; font-size: 16px; }
.brand i { width: 22px; height: 22px; border-radius: 7px; display: inline-block; background: conic-gradient(var(--swim) 0 33%, var(--bike) 0 66%, var(--run) 0); }
.topline .acts { display: flex; gap: 8px; }
.iconbtn {
  appearance: none; border: 1px solid var(--line); background: var(--surface); border-radius: 12px; width: 44px; height: 44px;
  display: grid; place-items: center; cursor: pointer; color: var(--ink2);
}
.iconbtn svg { width: 20px; height: 20px; }
.iconbtn.flat { border: 0; background: var(--surface2); }
.sportbar { position: sticky; top: 0; z-index: 30; background: color-mix(in srgb, var(--bg) 90%, transparent); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); }
.sportbar[hidden] { display: none; }
.sportbar .in { max-width: 1100px; margin: 0 auto; padding: 6px 16px 8px; display: grid; gap: 6px; }
.page { max-width: 1100px; margin: 0 auto; padding: 10px max(16px, env(safe-area-inset-right)) 8px max(16px, env(safe-area-inset-left)); }
.pagehead { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; margin: 6px 0 12px; }
.pagehead h1 { font-size: 26px; line-height: 1.1; letter-spacing: -.02em; }
.pagehead p { margin: 2px 0 0; color: var(--ink3); font-size: 13px; }
.grid { display: grid; grid-template-columns: minmax(0, 1fr); gap: 14px; }
.back { display: inline-flex; align-items: center; gap: 2px; min-height: 44px; margin-left: -4px; padding-right: 8px; color: var(--accent); font-weight: 650; font-size: 15px; }
.back svg { width: 22px; height: 22px; }
.idline { color: var(--ink2); font-size: 13px; overflow-wrap: anywhere; }
.idline code { background: var(--surface2); padding: 0 5px; border-radius: 5px; }

/* ---- tab bar (phone) and side nav (desktop) ---- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 40; border-top: 1px solid var(--line);
  background: color-mix(in srgb, var(--surface) 92%, transparent); backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
  padding: 0 env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
.tabbar .in { display: grid; grid-template-columns: 1fr 1fr 84px 1fr 1fr; max-width: 560px; margin: 0 auto; height: var(--tab-h); align-items: center; }
.tabbar .brand, .navtheme { display: none; }
.tab {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  font-size: 11px; font-weight: 650; color: var(--ink3); min-height: var(--tab-h); height: 100%;
}
.tab svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.tab[aria-current="page"] { color: var(--accent); }
.tab[aria-current="page"] svg { stroke-width: 2.2; }
.logwrap { display: flex; justify-content: center; }
.logbtn {
  appearance: none; border: 4px solid var(--bg); background: var(--accent); color: var(--on-accent); width: 60px; height: 60px; border-radius: 50%;
  margin-top: -26px; display: grid; place-items: center; cursor: pointer; box-shadow: 0 6px 16px rgba(42, 120, 214, .4);
}
.logbtn svg { width: 28px; height: 28px; stroke: currentColor; stroke-width: 2.6; fill: none; stroke-linecap: round; }
.logbtn span { display: none; }

@media (min-width: 1024px) {
  body { padding-bottom: 40px; padding-left: var(--nav-w); }
  .tabbar { top: 0; right: auto; width: var(--nav-w); border-top: 0; border-right: 1px solid var(--line); background: var(--surface); padding: 20px 14px; backdrop-filter: none; -webkit-backdrop-filter: none; }
  .tabbar .in { display: flex; flex-direction: column; align-items: stretch; gap: 4px; height: 100%; max-width: none; margin: 0; }
  .tabbar .brand { display: flex; order: -2; padding: 4px 10px 18px; font-size: 18px; }
  .tab { flex-direction: row; justify-content: flex-start; gap: 12px; font-size: 15px; height: 46px; min-height: 46px; padding: 0 12px; border-radius: 12px; }
  .tab:hover { background: var(--surface2); }
  .tab[aria-current="page"] { background: color-mix(in srgb, var(--accent) 12%, transparent); }
  .logwrap { order: -1; margin-bottom: 10px; display: block; }
  .logbtn { width: 100%; height: 48px; border-radius: 14px; margin: 0; border: 0; display: flex; gap: 8px; align-items: center; justify-content: center; font-weight: 700; font-size: 15px; box-shadow: none; }
  .logbtn svg { width: 20px; height: 20px; }
  .logbtn span { display: inline; }
  .topline { display: none; }
  .page { padding-top: 20px; padding-left: 28px; padding-right: 28px; }
  .navtheme { display: flex; margin-top: auto; appearance: none; border: 0; background: none; cursor: pointer; width: 100%; text-align: left; }
  .grid { grid-template-columns: repeat(12, minmax(0, 1fr)); gap: 16px; }
  .w12 { grid-column: span 12; } .w8 { grid-column: span 8; } .w7 { grid-column: span 7; }
  .w6 { grid-column: span 6; } .w5 { grid-column: span 5; } .w4 { grid-column: span 4; }
  .sportbar .in { padding: 14px 28px 10px; }
}

/* ---- components ---- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 16px 14px 14px; min-width: 0; }
.card.flat { padding: 0; overflow: clip; }
.k { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 8px; font-size: 11px; letter-spacing: .06em; text-transform: uppercase; color: var(--ink3); font-weight: 700; }
.scope { font-weight: 600; letter-spacing: 0; text-transform: none; border: 1px solid var(--line); border-radius: 999px; padding: 1px 8px; font-size: 11px; white-space: nowrap; }
.note { font-size: 12px; color: var(--ink3); margin: 6px 0 0; }
.empty { padding: 26px 10px; text-align: center; color: var(--ink3); font-size: 14px; }
.empty b { display: block; color: var(--ink2); font-size: 15px; margin-bottom: 3px; }
.empty-ico { display: inline-grid; place-items: center; width: 44px; height: 44px; margin-bottom: 8px; border-radius: 14px; background: var(--surface2); color: var(--ink3); }
.empty-ico svg { width: 24px; height: 24px; }
.btn { appearance: none; border: 1px solid var(--line); background: var(--surface); border-radius: 12px; min-height: 44px; padding: 0 16px; font-weight: 650; cursor: pointer; }
.btn.pri { background: var(--accent); color: var(--on-accent); border-color: transparent; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { appearance: none; border: 1px solid var(--line); background: var(--surface); border-radius: 999px; min-height: 44px; padding: 0 14px; cursor: pointer; font-weight: 650; font-size: 14px; color: var(--ink2); white-space: nowrap; }
.chip[aria-pressed="true"] { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 2px; background: var(--surface2); border: 1px solid var(--line); border-radius: 12px; padding: 3px; }
.seg button { appearance: none; border: 0; background: none; min-height: 44px; border-radius: 9px; font-weight: 650; font-size: 14px; color: var(--ink2); cursor: pointer; }
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--ink); box-shadow: 0 1px 3px rgba(0, 0, 0, .14), 0 0 0 1px var(--line); }
.tiles { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.tiles.t2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.tile { border: 1px solid var(--line); border-radius: 12px; padding: 10px; background: var(--surface2); min-width: 0; }
.tile .n { font-size: 11px; color: var(--ink3); font-weight: 650; line-height: 1.25; }
.tile .v { font-size: 22px; font-weight: 720; font-variant-numeric: tabular-nums; letter-spacing: -.02em; line-height: 1.15; margin-top: 2px; }
.tile .s { font-size: 11.5px; color: var(--ink3); margin-top: 2px; line-height: 1.3; }
.sp { display: inline-grid; place-items: center; width: 30px; height: 30px; border-radius: 9px; color: var(--on-sp); flex: none; vertical-align: middle; }
.sp svg { width: 20px; height: 20px; }
.sp.swim { background: var(--swim); } .sp.bike { background: var(--bike); } .sp.run { background: var(--run); } .sp.tri { background: var(--tri); }
.ico { display: inline-block; width: 16px; height: 16px; vertical-align: -3px; }
.skeleton { display: block; border-radius: 8px; min-height: 14px; background: linear-gradient(90deg, var(--surface2) 25%, var(--grid) 50%, var(--surface2) 75%); background-size: 200% 100%; animation: shimmer 1.4s linear infinite; }
@keyframes shimmer { to { background-position: -200% 0; } }

/* ---- bottom sheet (phone) / centred dialog (desktop) ---- */
.backdrop { position: fixed; inset: 0; background: rgba(0, 0, 0, .45); z-index: 60; opacity: 0; visibility: hidden; transition: opacity .2s, visibility .2s; }
.backdrop.on { opacity: 1; visibility: visible; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 61; max-height: 94dvh; overflow: auto; background: var(--surface);
  border-radius: 22px 22px 0 0; border: 1px solid var(--line); border-bottom: 0; transform: translateY(105%); visibility: hidden;
  transition: transform .25s cubic-bezier(.2, .8, .2, 1), visibility .25s;
  padding: 6px 16px calc(18px + env(safe-area-inset-bottom));
}
.sheet.on { transform: none; visibility: visible; transition: transform .25s cubic-bezier(.2, .8, .2, 1), visibility 0s; }
.grab { width: 40px; height: 5px; border-radius: 3px; background: var(--mid); margin: 6px auto 8px; }
.sheet h2 { font-size: 20px; letter-spacing: -.01em; }
.sheethead { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; }
.toast {
  position: fixed; left: 50%; bottom: calc(var(--tab-h) + 24px + env(safe-area-inset-bottom)); transform: translate(-50%, 20px);
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-size: 14px; font-weight: 600;
  opacity: 0; pointer-events: none; transition: .2s; z-index: 80; max-width: calc(100vw - 32px); text-align: center;
}
.toast.on { opacity: 1; transform: translate(-50%, 0); }
@media (min-width: 1024px) {
  .sheet { top: 50%; bottom: auto; left: calc(50% + var(--nav-w) / 2); right: auto; width: 520px; transform: translate(-50%, -46%); opacity: 0; border-radius: 22px; border-bottom: 1px solid var(--line); max-height: 88vh; }
  .sheet.on { transform: translate(-50%, -50%); opacity: 1; }
  .grab { display: none; }
  .toast { bottom: 28px; left: calc(50% + var(--nav-w) / 2); }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; scroll-behavior: auto !important; }
}
