/* Sport tracker — phone-first dark UI.
   Sized for one-handed use: nothing tappable is under 48px. */

:root {
  --bg:        #0d0f14;
  --surface:   #161a22;
  --surface-2: #1e232d;
  --line:      #2a3140;
  --text:      #eef1f6;
  --muted:     #99a3b5;
  --accent:    #c2e04a;
  --accent-ink:#1a2000;
  --danger:    #f97362;
  --radius:    16px;
  --tabbar-h:  62px;
  /* 12px padding + 52px button + 14px padding. The docked bar, the body's
     bottom padding and the toast all measure from this, so they cannot
     drift into each other. */
  --action-bar-h: 78px;
}

@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg:        #f6f7fa;
    --surface:   #ffffff;
    --surface-2: #eef1f6;
    --line:      #dfe4ec;
    --text:      #131720;
    --muted:     #626d80;
    --accent:    #6b8f00;
    --accent-ink:#ffffff;
    --danger:    #d1442f;
  }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  /* Keep content clear of the tab bar and the iOS home indicator. */
  padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom, 0px));
  -webkit-tap-highlight-color: transparent;
}

/* Extra room on the log screen for the docked action bar. */
body:has(.action-bar) {
  padding-bottom: calc(var(--tabbar-h) + var(--action-bar-h) + 10px
                       + env(safe-area-inset-bottom, 0px));
}

.shell {
  max-width: 640px;
  margin: 0 auto;
  padding: 24px 18px 20px;
}

/* ---------- typography ---------- */

h1 { font-size: 1.6rem; margin: 0 0 6px; letter-spacing: -0.025em; font-weight: 660; }

.page-head { margin-bottom: 30px; }
.page-head .sub { margin: 0; }

/* Each step of the form gets the same generous rhythm. */
.step { margin-bottom: 26px; }
.step-label {
  display: block;
  font-size: 0.7rem; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.09em;
  color: var(--muted);
  margin-bottom: 11px;
}
h2 { font-size: 1.05rem; margin: 28px 0 12px; letter-spacing: -0.01em; }
.sub { color: var(--muted); font-size: 0.92rem; line-height: 1.5; margin: 0 0 20px; }

.greeting { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }
.greeting form { margin: 0; }
.linkish {
  background: none; border: 0; color: var(--muted);
  font-size: 0.85rem; cursor: pointer; padding: 8px; text-decoration: underline;
}

/* ---------- summary tiles ---------- */

.tiles { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.tile {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 15px 12px;
  text-align: center;
}
.tile .num { font-size: 1.35rem; font-weight: 650; letter-spacing: -0.02em; display: block; }
.tile .cap { color: var(--muted); font-size: 0.68rem; text-transform: uppercase;
             letter-spacing: 0.06em; margin-top: 4px; display: block; }
.tile.accent .num { color: var(--accent); }

/* ---------- sport picker ---------- */

.sport-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}
@media (min-width: 480px) {
  .sport-grid { grid-template-columns: repeat(auto-fill, minmax(112px, 1fr)); }
}
.sport {
  position: relative;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 7px;
  min-height: 84px;
  padding: 14px 8px;
  background: var(--surface);
  border: 1.5px solid var(--line);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 0.72rem; font-weight: 500;
  cursor: pointer;
  text-align: center;
  line-height: 1.2;
  transition: border-color .12s, background .12s, transform .08s;
}
.sport .emoji { font-size: 1.65rem; line-height: 1; }
.sport-name { font-size: 0.76rem; line-height: 1.25; }
.sport:active { transform: scale(0.97); }
.sport.is-selected {
  border-color: var(--sport-color, var(--accent));
  background: color-mix(in srgb, var(--sport-color, var(--accent)) 14%, var(--surface));
}

/* ---------- duration presets ---------- */

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.inline-chips { align-items: center; }


.extras { margin-top: 4px; }
.extras-body { padding-top: 4px; }
.extras-body textarea { margin-top: 10px; }
.more-toggle {
  color: var(--muted); font-size: .82rem; cursor: pointer; padding: 10px 0;
  list-style: none; min-height: 44px; display: flex; align-items: center;
}
.more-toggle::-webkit-details-marker { display: none; }
.more-toggle::before { content: "+ "; }
details[open] .more-toggle::before { content: "− "; }
.chip {
  min-height: 48px; padding: 0 17px;
  background: var(--surface); color: var(--text);
  border: 1.5px solid var(--line); border-radius: 999px;
  font-size: 0.9rem; font-weight: 500; cursor: pointer;
  transition: border-color .12s, background .12s, transform .08s;
}
.chip:active { transform: scale(0.96); }
.chip.is-selected {
  background: var(--accent); color: var(--accent-ink);
  border-color: var(--accent); font-weight: 650;
}

/* ---------- form fields ---------- */

.field { margin-top: 18px; }
.field > label {
  display: block; color: var(--muted);
  font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.06em;
  margin-bottom: 8px;
}
input[type="text"], input[type="email"], input[type="password"],
input[type="number"], input[type="date"], input[type="color"], textarea {
  width: 100%;
  min-height: 50px;
  padding: 12px 14px;
  background: var(--surface);
  border: 1.5px solid var(--line);
  border-radius: 12px;
  color: var(--text);
  font: inherit;
}
input:focus, textarea:focus, .sport:focus-visible, .chip:focus-visible, button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
textarea { min-height: 76px; resize: vertical; }

/* Revealed by the Custom chip. Labelled, because a bare number field left
   the units ambiguous -- "75" could read as minutes, hours or anything. */
.custom-input { margin-top: 12px; }
.custom-input[hidden] { display: none; }
.custom-input > label {
  display: block; color: var(--muted);
  font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.06em;
  margin-bottom: 8px;
}
/* The date field is only a picker trigger; the "Other…" chip shows the value,
   so the input itself stays out of the layout entirely. */
input.date-input {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px; border: 0;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap;
}

.row { display: flex; gap: 10px; }
.row > * { flex: 1; }

/* Docked just above the tab bar so logging never requires scrolling. */
.action-bar {
  position: fixed;
  left: 0; right: 0;
  bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom, 0px));
  z-index: 15;
  padding: 12px 16px 14px;
  background: linear-gradient(to top,
    var(--bg) 62%, color-mix(in srgb, var(--bg) 0%, transparent));
  pointer-events: none;
}
.action-bar > * { pointer-events: auto; }
.action-bar .btn { max-width: 608px; margin: 0 auto; }

.btn {
  display: block; width: 100%;
  min-height: 52px;
  margin-top: 22px;
  background: var(--accent); color: var(--accent-ink);
  border: 0; border-radius: 14px;
  font-size: 1.05rem; font-weight: 650;
  cursor: pointer;
  transition: transform .08s, opacity .12s;
}
.btn:active { transform: scale(0.985); }
.btn[disabled] { opacity: .45; cursor: not-allowed; }
.btn.secondary {
  background: var(--surface); color: var(--text);
  border: 1.5px solid var(--line);
}
a.btn { text-align: center; line-height: 52px; text-decoration: none; }

/* ---------- recent list ---------- */

.entries { list-style: none; margin: 0; padding: 0; }
.entry {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 4px;
  border-bottom: 1px solid var(--line);
}
.entry:last-child { border-bottom: 0; }
.entry .dot {
  width: 38px; height: 38px; flex: none;
  display: grid; place-items: center;
  border-radius: 11px; font-size: 1.15rem;
  background: color-mix(in srgb, var(--sport-color, var(--accent)) 18%, transparent);
}
.entry .what { flex: 1; min-width: 0; }
.entry .what strong { font-weight: 600; display: block; }
.entry .what small { color: var(--muted); font-size: 0.8rem; }
.entry .dur { font-variant-numeric: tabular-nums; font-weight: 600; }
.entry .del {
  background: none; border: 0; color: var(--muted);
  font-size: 1.2rem; line-height: 1; cursor: pointer;
  padding: 10px; min-width: 44px; min-height: 44px;
}
.entry .del:hover { color: var(--danger); }
.entry .reorder {
  background: none; border: 0; color: var(--muted);
  font-size: 1.05rem; line-height: 1; cursor: pointer;
  min-width: 40px; min-height: 44px; padding: 10px 6px;
}
.entry .reorder:disabled { opacity: .22; cursor: default; }
.entry .reorder:not(:disabled):hover { color: var(--accent); }

/* ---------- charts ---------- */

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 14px;
}
.card h3 { margin: 0 0 14px; font-size: 0.95rem; font-weight: 600; }

.bars { display: flex; align-items: stretch; gap: 5px; height: 150px; }
/* Columns are buttons so the values are reachable by tap and by keyboard. */
.bars .col {
  flex: 1; display: flex; flex-direction: column;
  background: none; border: 0; padding: 0; margin: 0;
  cursor: pointer; font: inherit; color: inherit;
  border-radius: 6px;
}
.bars .col:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.bars .col .bar { transition: height .25s ease, background .12s, opacity .12s; }
/* Dim the rest so the tapped bar reads as selected. */
.bars.has-selection .col:not(.is-selected) .bar { opacity: .38; }
.bars .col.is-selected .bar { background: var(--accent); }
.bars .col.is-selected .bar.empty { background: var(--muted); }
.bars .col.is-selected .xlab { color: var(--text); font-weight: 600; }
/* The plot area flexes; the label strip is a fixed height, so every bar
   sits on the same baseline whether or not its column is labelled. */
.bars .plot { flex: 1; display: flex; align-items: flex-end; width: 100%; }
.bars .bar {
  display: block;
  width: 100%; border-radius: 5px 5px 2px 2px;
  background: var(--accent); min-height: 3px;
}
.bars .bar.empty { background: var(--line); min-height: 2px; }
.bars .xlab {
  display: block;
  height: 18px; line-height: 18px; flex: 0 0 18px;
  font-size: 0.6rem; color: var(--muted);
  white-space: nowrap; text-align: center;
}

.legend { display: flex; flex-direction: column; gap: 12px; }
.legend-row { display: grid; grid-template-columns: 26px 1fr auto; gap: 10px; align-items: center; }
.legend-row .name { font-size: 0.9rem; }
.legend-row .val { font-variant-numeric: tabular-nums; color: var(--muted); font-size: 0.85rem; }
.meter { grid-column: 1 / -1; height: 7px; background: var(--surface-2);
         border-radius: 99px; overflow: hidden; }
.meter > span { display: block; height: 100%; border-radius: 99px; }

.heat-scroll { overflow-x: auto; padding-bottom: 4px; }
.heat-body { display: flex; gap: 6px; min-width: min-content; }
.heat { display: flex; gap: 3px; min-width: min-content; }
.heat .wcol { display: flex; flex-direction: column; gap: 3px; }

/* Weekday gutter (Mon/Wed/Fri), aligned to the 13px cell + 3px gap rhythm. */
.heat-days { display: flex; flex-direction: column; gap: 3px; flex: none; }
.heat-days span {
  height: 13px; line-height: 13px;
  font-size: 0.58rem; color: var(--muted); text-align: right; width: 22px;
}
.heat-months {
  display: flex; gap: 3px; margin-left: 28px; margin-bottom: 4px;
  min-width: min-content;
}
.heat-months .m {
  font-size: 0.58rem; color: var(--muted);
  width: 13px; flex: none; white-space: nowrap; overflow: visible;
}
.heat .cell.today { box-shadow: 0 0 0 1.5px var(--text); }

/* Tap target readout: shows the value for the selected bar or day. */
.readout {
  display: flex; flex-direction: column; gap: 1px;
  min-height: 44px; justify-content: center;
  padding: 8px 12px; margin-bottom: 14px;
  background: var(--surface-2);
  border-radius: 10px;
}
.readout-title {
  font-size: 0.68rem; color: var(--muted);
  text-transform: uppercase; letter-spacing: 0.06em;
}
.readout-value { font-size: 0.98rem; font-weight: 600; }

/* Legend that states the actual duration each shade represents. */
.heat-key {
  display: flex; flex-wrap: wrap; gap: 6px 14px;
  margin-top: 14px;
  font-size: 0.66rem; color: var(--muted);
}
.heat-key .key-item { display: flex; align-items: center; gap: 5px; }
.heat-key .cell {
  width: 11px; height: 11px; border-radius: 3px;
  background: var(--surface-2); flex: none;
}
.heat-key .cell.l1 { background: color-mix(in srgb, var(--accent) 28%, var(--surface-2)); }
.heat-key .cell.l2 { background: color-mix(in srgb, var(--accent) 50%, var(--surface-2)); }
.heat-key .cell.l3 { background: color-mix(in srgb, var(--accent) 74%, var(--surface-2)); }
.heat-key .cell.l4 { background: var(--accent); }
.heat-key .key-text { white-space: nowrap; }
.heat .cell {
  width: 13px; height: 13px; border-radius: 3px;
  background: var(--surface-2);
  border: 0; padding: 0; margin: 0;
  cursor: pointer; -webkit-appearance: none; appearance: none;
}
.heat .cell:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.heat .cell.is-selected { box-shadow: 0 0 0 2px var(--accent); }
.heat .cell.l1 { background: color-mix(in srgb, var(--accent) 28%, var(--surface-2)); }
.heat .cell.l2 { background: color-mix(in srgb, var(--accent) 50%, var(--surface-2)); }
.heat .cell.l3 { background: color-mix(in srgb, var(--accent) 74%, var(--surface-2)); }
.heat .cell.l4 { background: var(--accent); }
.heat .cell.future { opacity: .28; }

.range-tabs { display: flex; gap: 6px; margin-bottom: 16px; }
.range-tabs button {
  flex: 1; text-align: center; padding: 10px 4px;
  min-height: 44px; display: grid; place-items: center;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 10px; color: var(--muted);
  font: inherit; font-size: 0.85rem; cursor: pointer;
}
.range-tabs button.is-active { background: var(--accent); color: var(--accent-ink);
                               border-color: var(--accent); font-weight: 600; }
.range-tabs button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- tab bar ---------- */

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: flex;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
.tab {
  flex: 1; min-height: var(--tabbar-h);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  color: var(--muted); text-decoration: none; font-size: 0.68rem;
}
.tab svg { width: 21px; height: 21px; fill: none; stroke: currentColor;
           stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.tab.is-active { color: var(--accent); }

/* ---------- settings menu ---------- */

/* The More tab is a menu, not a page: rare things (password) live one tap
   deeper so the sport ordering she actually uses is not buried under them. */
.menu { list-style: none; margin: 0; padding: 0; }
.menu-row {
  display: flex; align-items: center; gap: 14px;
  min-height: 64px; padding: 12px 4px;
  border-bottom: 1px solid var(--line);
  color: var(--text); text-decoration: none;
}
.menu li:last-child .menu-row { border-bottom: 0; }
.menu-icon {
  width: 38px; height: 38px; flex: none;
  display: grid; place-items: center;
  border-radius: 11px; font-size: 1.15rem;
  background: color-mix(in srgb, var(--accent) 18%, transparent);
}
.menu-text { flex: 1; min-width: 0; }
.menu-text strong { font-weight: 600; display: block; }
.menu-text small { color: var(--muted); font-size: 0.8rem; }
.menu-chevron { color: var(--muted); font-size: 1.5rem; line-height: 1; }
.menu-row:active { background: var(--surface); }

.back {
  display: inline-block; min-height: 44px; line-height: 44px;
  color: var(--muted); text-decoration: none; font-size: 0.9rem;
}
.back:active { color: var(--text); }

/* Wrappers around a single icon button, so the button keeps its own size. */
.inline-form { margin: 0; }
.field-flush { margin-top: 0; }
.field-grow { flex: 2; }
.field-icon { flex: 0 0 84px; }
.icon-input { text-align: center; font-size: 1.3rem; }

.entry.is-muted .dot, .entry.is-muted .what { opacity: .6; }
.btn-inline {
  min-height: 40px; padding: 0 14px;
  background: var(--surface); color: var(--text);
  border: 1.5px solid var(--line); border-radius: 999px;
  font: inherit; font-size: 0.85rem; cursor: pointer;
}

/* Tappable colour presets: the OS colour picker is slow on a phone. */
.swatches { display: flex; flex-wrap: wrap; gap: 10px; }
.swatch { cursor: pointer; }
.swatch input { position: absolute; opacity: 0; pointer-events: none; }
.swatch > span[aria-hidden] {
  display: block; width: 46px; height: 46px;
  border-radius: 999px; background: var(--swatch);
  border: 3px solid transparent;
  box-shadow: inset 0 0 0 1.5px rgba(0,0,0,.18);
}
.swatch input:checked + span[aria-hidden] {
  border-color: var(--text);
}
.swatch input:focus-visible + span[aria-hidden] {
  outline: 2px solid var(--accent); outline-offset: 2px;
}

.sr-only {
  position: absolute; width: 1px; height: 1px;
  padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* ---------- confirmation sheet ---------- */

/* Centred card. <dialog> centres itself in the top layer, so this only has to
   size it and paint it. */
.sheet {
  border: 0; padding: 0;
  background: transparent;
  width: calc(100% - 40px); max-width: 380px;
  max-height: none;
  color: var(--text);
}
.sheet::backdrop { background: rgba(0, 0, 0, .55); }
.sheet > form {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 24px 20px 20px;
}
.sheet h2 { margin: 0; font-size: 1.15rem; }
.sheet-note { color: var(--muted); font-size: 0.88rem; margin: 8px 0 0; }
.sheet-actions { display: flex; gap: 10px; margin-top: 22px; }
.sheet-actions .btn { margin-top: 0; flex: 1; }
.btn.danger {
  background: var(--danger); color: #fff; border: 0;
}
.sheet[open] { animation: sheet-in .16s ease-out; }
@keyframes sheet-in {
  from { transform: scale(.96); opacity: 0; }
  to   { transform: scale(1); opacity: 1; }
}

/* ---------- misc ---------- */

.explainer {
  color: var(--muted); font-size: 0.82rem; line-height: 1.5;
  margin: 12px 2px 0;
}
.explainer strong { color: var(--text); font-weight: 600; }
.chart-note { color: var(--muted); font-size: 0.72rem; line-height: 1.45; margin: 12px 0 0; }

.empty-state { text-align: center; color: var(--muted); padding: 32px 16px; }
.empty-state .big { font-size: 2.2rem; display: block; margin-bottom: 10px; }
.alert {
  background: color-mix(in srgb, var(--danger) 14%, var(--surface));
  border: 1px solid color-mix(in srgb, var(--danger) 40%, transparent);
  color: var(--text);
  padding: 12px 14px; border-radius: 12px; margin-bottom: 16px; font-size: 0.9rem;
}
.notice {
  background: color-mix(in srgb, var(--accent) 14%, var(--surface));
  border: 1px solid color-mix(in srgb, var(--accent) 40%, transparent);
  color: var(--text);
  padding: 12px 14px; border-radius: 12px; margin-bottom: 16px; font-size: 0.9rem;
}
.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom, 0px) + 16px);
  background: var(--accent); color: var(--accent-ink);
  padding: 12px 22px; border-radius: 999px; font-weight: 650;
  box-shadow: 0 8px 28px rgba(0,0,0,.35);
  z-index: 40; animation: pop 2.4s ease forwards;
}
/* On the log screen the toast must clear the docked button as well, or it
   lands on top of it -- and both being accent-coloured, it read as the
   button changing rather than as a confirmation. */
body:has(.action-bar) .toast {
  bottom: calc(var(--tabbar-h) + var(--action-bar-h)
               + env(safe-area-inset-bottom, 0px) + 14px);
}

@keyframes pop {
  0%   { opacity: 0; transform: translate(-50%, 10px); }
  12%  { opacity: 1; transform: translate(-50%, 0); }
  80%  { opacity: 1; }
  100% { opacity: 0; }
}

.centered { min-height: 78vh; display: flex; flex-direction: column; justify-content: center; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .001ms !important;
    transition-duration: .001ms !important;
  }
}
