/* ── Tokens ─────────────────────────────────────────────────── */
:root {
  color-scheme: light;
  --plane:        #f9f9f7;
  --surface:      #fcfcfb;
  --ink:          #0b0b0b;
  --ink-2:        #52514e;
  --ink-muted:    #898781;
  --grid:         #e1e0d9;
  --axis:         #c3c2b7;
  --hairline:     rgba(11,11,11,0.10);
  --wash:         rgba(11,11,11,0.04);
  --series-1:     #2a78d6;
  --series-2:     #d4a000;
  --series-3:     #d4342a;
  --radius:       14px;
  --shadow:       0 1px 2px rgba(11,11,11,0.05), 0 8px 24px rgba(11,11,11,0.04);
  --dot-shadow:  0 3px 10px rgba(11,11,11,0.10);
  --critical:     #c62f2f;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --plane:      #0d0d0d;
    --surface:    #1a1a19;
    --ink:        #ffffff;
    --ink-2:      #c3c2b7;
    --ink-muted:  #898781;
    --grid:       #2c2c2a;
    --axis:       #383835;
    --hairline:   rgba(255,255,255,0.10);
    --wash:       rgba(255,255,255,0.06);
    --series-1:   #3987e5;
    --series-2:   #f0bc2e;
    --series-3:   #ef5a4d;
    --shadow:     0 1px 2px rgba(0,0,0,0.5), 0 8px 24px rgba(0,0,0,0.35);
    --dot-shadow:  0 3px 12px rgba(0,0,0,0.5);
    --critical:   #f0776b;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --plane:      #0d0d0d;
  --surface:    #1a1a19;
  --ink:        #ffffff;
  --ink-2:      #c3c2b7;
  --ink-muted:  #898781;
  --grid:       #2c2c2a;
  --axis:       #383835;
  --hairline:   rgba(255,255,255,0.10);
  --wash:       rgba(255,255,255,0.06);
  --series-1:   #3987e5;
  --series-2:   #f0bc2e;
  --series-3:   #ef5a4d;
  --shadow:     0 1px 2px rgba(0,0,0,0.5), 0 8px 24px rgba(0,0,0,0.35);
  --dot-shadow:  0 3px 12px rgba(0,0,0,0.5);
  --critical:   #f0776b;
}

* { box-sizing: border-box; }
/* An id selector below would otherwise outrank the UA's [hidden] rule and
   leave a hidden panel on screen. */
[hidden] { display: none !important; }
html, body { margin: 0; }
/* The whole app is one fixed-height column: top bar, a single scroll region,
   tab bar. The pad screen sizes itself to that region and so never scrolls;
   only the timeline does, and only inside <main>. */
body {
  background: var(--plane);
  color: var(--ink);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  height: 100vh;
  height: 100dvh;
  display: flex; flex-direction: column;
  overflow: hidden;
}
main {
  flex: 1 1 auto; min-height: 0; overflow-y: auto;
  width: 100%; max-width: 720px; margin: 0 auto;
  padding: 0 max(14px, env(safe-area-inset-left));
}

.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;
}

/* ── Top bar ────────────────────────────────────────────────── */
.topbar {
  flex: none; width: 100%; max-width: 720px; margin: 0 auto;
  padding: max(14px, env(safe-area-inset-top)) max(14px, env(safe-area-inset-left)) 10px;
  display: flex; align-items: center; justify-content: flex-end; gap: 12px;
}
.icon-btn {
  width: 40px; height: 40px; flex: none;
  display: grid; place-items: center;
  font-size: 1.125rem; line-height: 1;
  color: var(--ink-2); background: transparent;
  border: 1px solid var(--hairline); border-radius: 10px;
  cursor: pointer;
}
.icon-btn:hover:not(:disabled) { background: var(--wash); color: var(--ink); }
.icon-btn:disabled { opacity: .35; cursor: default; }
.topbar-actions { display: flex; gap: 8px; flex: none; }

/* ── Tap pad ────────────────────────────────────────────────── */
/* Three dots, since that is the name of the app. On any phone a third of the
   pad's height is smaller than its width, so height is the binding constraint:
   flex sizes the circles vertically, aspect-ratio derives the width, and they
   centre in whatever horizontal room is left over. */
.pad {
  flex: 1 1 auto; min-height: 0;
  display: flex; flex-direction: column; align-items: center; gap: 12px;
  padding: 4px 0 2px;
}
.tap {
  position: relative;
  flex: 1 1 0; min-height: 0;
  aspect-ratio: 1; max-width: 100%;
  border: 0; border-radius: 50%;
  color: #fff; cursor: pointer;
  font: inherit;
  box-shadow: var(--dot-shadow);
  transition: transform .07s ease, filter .12s ease;
  touch-action: manipulation;
  user-select: none;
}
.tap:active { transform: scale(.965); filter: brightness(1.08); }
.tap.is-hit { animation: pop .28s ease; }
@keyframes pop { 0% { transform: scale(.94) } 55% { transform: scale(1.03) } 100% { transform: scale(1) } }
@media (prefers-reduced-motion: reduce) {
  .tap, .tap.is-hit { transition: none; animation: none; }
  .drawer > summary::before { transition: none; }
}
.tap-1 { background: var(--series-1); }
.tap-2 { background: var(--series-2); }
.tap-3 { background: var(--series-3); }

/* The count sits beside its dot, in the empty space the circles leave. It no
   longer needs a pill: off the colour it is plain text on the page, which
   also retires the white-on-yellow contrast problem the pill was solving. */
.tap-count {
  position: absolute; top: 50%; left: calc(100% + 18px);
  transform: translateY(-50%);
  font-size: clamp(1.25rem, 5.5vw, 1.75rem); font-weight: 650;
  font-variant-numeric: tabular-nums; letter-spacing: -0.01em;
  color: var(--ink-2);
}

.last-line {
  flex: none;
  margin: 12px 2px;
  font-size: .8125rem; color: var(--ink-2);
  font-variant-numeric: tabular-nums;
  min-height: 1.2em;
}

/* ── Filters ────────────────────────────────────────────────── */
.filters { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }
.chip {
  font: inherit; font-size: .8125rem; font-weight: 500;
  padding: 7px 13px; border-radius: 999px; cursor: pointer;
  color: var(--ink-2); background: transparent;
  border: 1px solid var(--hairline);
}
.chip:hover { background: var(--wash); }
.chip.is-selected { color: var(--ink); border-color: transparent; background: var(--wash); font-weight: 600; }
.chip.is-selected::before { content: "✓ "; font-weight: 700; }

/* ── Cards ──────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: var(--radius);
  padding: 16px 14px 12px;
  margin-bottom: 14px;
}
/* Wraps, because the chart subtitle carries the count and the trend delta
   and would otherwise widen the whole page on a phone */
.card-head { display: flex; align-items: baseline; justify-content: space-between; gap: 2px 12px; flex-wrap: wrap; }
.card h2 { margin: 0; font-size: .9375rem; font-weight: 650; }
.card-sub { margin: 0; min-width: 0; font-size: .75rem; color: var(--ink-muted); font-variant-numeric: tabular-nums; }

/* ── Legend ─────────────────────────────────────────────────── */
.legend { display: flex; gap: 14px; flex-wrap: wrap; margin: 10px 0 4px; }
.legend-item { display: inline-flex; align-items: center; gap: 6px; font-size: .75rem; color: var(--ink-2); }
.key { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }
.key-1 { background: var(--series-1); }
.key-2 { background: var(--series-2); }
.key-3 { background: var(--series-3); }

/* ── Chart ──────────────────────────────────────────────────── */
.chart-wrap { position: relative; }
#chart { display: block; width: 100%; height: 272px; touch-action: pan-y; }
#chart text { font: 11px system-ui, -apple-system, sans-serif; fill: var(--ink-muted); }
#chart .y-label { font-variant-numeric: tabular-nums; }
#chart .lane-label { font-size: 10px; font-weight: 650; fill: var(--ink-2); letter-spacing: .01em; }
#chart .gridline { stroke: var(--grid); stroke-width: 1; }
#chart .baseline { stroke: var(--axis); stroke-width: 1; }

/* Rate curves: a wide soft copy behind the line for bloom, then the line.
   Deliberately unfilled — a wash under crossing curves reads as stacking.
   No SVG filters: they are slow to composite on phones and this redraws on
   every pointermove. */
#chart .bloom { fill: none; stroke-width: 9; stroke-linecap: round; stroke-linejoin: round; opacity: .13; }
#chart .line  { fill: none; stroke-width: 2.25; stroke-linecap: round; stroke-linejoin: round; }

/* Readout nodes: where the three curves sit at the crosshair */
#chart .read-dot { stroke: var(--surface); stroke-width: 1.5; }
#chart .read-dot.is-active { stroke: var(--ink); stroke-width: 2; }
#chart .bin-dot { stroke: none; opacity: .9; }
#chart .band { fill: var(--wash); }

/* Event rail — every individual click, one row per button */
#chart .rail-bg { fill: var(--wash); }
#chart .rail-rule {
  stroke: var(--axis); stroke-width: 1; opacity: .55;
  stroke-dasharray: 1 4; stroke-linecap: round;
}
#chart .rail-tick { opacity: .8; }
#chart .rail-tick.is-active { opacity: 1; stroke: var(--surface); stroke-width: 1; }


.tooltip {
  position: absolute; z-index: 5; pointer-events: none;
  transform: translate(-50%, -100%);
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: 9px;
  box-shadow: var(--shadow);
  padding: 7px 10px;
  white-space: nowrap;
  font-size: .75rem; color: var(--ink-2);
}
.tooltip .tt-val { display: block; font-size: .875rem; font-weight: 650; color: var(--ink); font-variant-numeric: tabular-nums; }
.tooltip .tt-key { display: inline-block; width: 12px; height: 2px; vertical-align: middle; margin-right: 6px; border-radius: 1px; }
.tooltip .tt-row { display: block; font-variant-numeric: tabular-nums; }
.tooltip .tt-row.is-zero { color: var(--ink-muted); }
.tooltip .tt-row.is-strong { color: var(--ink); font-weight: 600; }
.tooltip .tt-sub { display: block; margin-bottom: 2px; font-size: .6875rem; color: var(--ink-muted); }

.empty { margin: 28px 0; text-align: center; font-size: .8125rem; color: var(--ink-muted); }

/* ── Actions ────────────────────────────────────────────────── */
.actions { display: flex; gap: 8px; flex-wrap: wrap; margin: 18px 0 0; }
.btn {
  font: inherit; font-size: .8125rem; font-weight: 500;
  padding: 9px 14px; border-radius: 10px; cursor: pointer;
  color: var(--ink-2); background: var(--surface);
  border: 1px solid var(--hairline);
}
.btn:hover { background: var(--wash); color: var(--ink); }

.footnote { margin: 18px 2px 0; font-size: .75rem; line-height: 1.5; color: var(--ink-muted); }
.footnote code { font-size: .95em; }

/* ── Toast ──────────────────────────────────────────────────── */
.toast {
  position: fixed; left: 50%; bottom: calc(22px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: var(--ink); color: var(--plane);
  font-size: .8125rem; font-weight: 500;
  padding: 9px 16px; border-radius: 999px;
  box-shadow: var(--shadow); z-index: 20;
}

.legend-item b { font-weight: 650; color: var(--ink); font-variant-numeric: tabular-nums; }

/* ── Collapsible data drawer ────────────────────────────────── */
.drawer { margin-top: 16px; border-top: 1px solid var(--hairline); }
.drawer > summary {
  display: flex; align-items: center; gap: 8px;
  padding: 12px 2px; cursor: pointer; list-style: none;
  font-size: .8125rem; font-weight: 550; color: var(--ink-2);
}
.drawer > summary::-webkit-details-marker { display: none; }
.drawer > summary::before {
  content: "›"; font-size: 1.05rem; line-height: 1;
  transition: transform .15s ease;
}
.drawer[open] > summary::before { transform: rotate(90deg); }
.drawer > summary:hover { color: var(--ink); }
.drawer .actions { margin-top: 2px; }

/* ── Panels & tab bar ───────────────────────────────────────── */
#panel-tap { height: 100%; display: flex; flex-direction: column; }
#panel-data { padding: 4px 0 18px; }

.tabbar {
  flex: none; z-index: 15;
  display: flex;
  padding: 6px max(14px, env(safe-area-inset-left)) calc(6px + env(safe-area-inset-bottom));
  gap: 6px;
  background: color-mix(in srgb, var(--plane) 88%, transparent);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--hairline);
}
@supports not (background: color-mix(in srgb, red 50%, transparent)) {
  .tabbar { background: var(--plane); }
}
.tabbtn {
  flex: 1 1 0; max-width: 340px; margin: 0 auto;
  display: flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 46px; padding: 0 14px;
  font: inherit; font-size: .875rem; font-weight: 550;
  color: var(--ink-muted); background: transparent;
  border: 0; border-radius: 11px; cursor: pointer;
  touch-action: manipulation;
}
.tabbtn-glyph { font-size: 1rem; line-height: 1; }
.tabbtn:hover { color: var(--ink-2); }
.tabbtn.is-active { color: var(--ink); background: var(--wash); font-weight: 650; }

/* ── Milestone nudge ────────────────────────────────────────
   A native <dialog>, so focus trapping, Escape and the top layer come from the
   browser rather than from hand-rolled JavaScript. */
.nudge {
  width: min(340px, calc(100vw - 40px));
  padding: 26px 22px 18px;
  border: 1px solid var(--hairline); border-radius: var(--radius);
  background: var(--surface); color: var(--ink);
  box-shadow: var(--shadow);
  text-align: center;
}
.nudge::backdrop { background: rgba(0,0,0,0.45); backdrop-filter: blur(3px); }
.nudge-title {
  margin: 0 0 8px; font-size: 1.25rem; font-weight: 680; letter-spacing: -0.02em;
}
.nudge-body { margin: 0 0 22px; font-size: .875rem; line-height: 1.5; color: var(--ink-2); }

/* The amounts sit on the app's own dots — same three colours, same shape */
/* Ko-fi picks the amount on its own page, so the dots are the mark here,
   not the controls — three buttons promising $1/$5/$10 would all land on the
   same picker. */
.nudge-mark { display: flex; justify-content: center; gap: 10px; margin-bottom: 20px; }
.nudge-mark i { width: 15px; height: 15px; border-radius: 50%; }
.nudge-mark i:nth-child(1) { background: var(--series-1); }
.nudge-mark i:nth-child(2) { background: var(--series-2); }
.nudge-mark i:nth-child(3) { background: var(--series-3); }

.nudge-give {
  display: block; margin: 0 0 20px; padding: 13px 22px;
  border-radius: 999px; text-decoration: none;
  background: var(--ink); color: var(--plane);
  font-size: .9375rem; font-weight: 650;
  transition: transform .08s ease, filter .12s ease;
}
.nudge-give:hover { transform: translateY(-1px); filter: brightness(1.1); }
.nudge-give:active { transform: translateY(0); }

.nudge-actions {
  display: flex; flex-wrap: wrap; justify-content: center; gap: 4px 18px;
  border-top: 1px solid var(--hairline); padding-top: 14px;
}
.nudge-link {
  font: inherit; font-size: .8125rem; color: var(--ink-muted);
  background: none; border: 0; padding: 6px 4px; cursor: pointer;
  text-decoration: underline; text-underline-offset: 3px;
}
.nudge-link:hover { color: var(--ink-2); }

@media (prefers-reduced-motion: reduce) {
  .nudge-give { transition: none; }
}

/* ── Destructive-action strip ───────────────────────────────
   Deleting the log is the one thing in this app that cannot be undone, so it
   takes two deliberate presses with the export offered in between. */
.danger {
  margin: 12px 0 2px;
  padding: 13px 14px;
  display: flex; flex-wrap: wrap; align-items: center; gap: 10px 14px;
  background: color-mix(in srgb, var(--critical) 11%, var(--plane));
  border: 1px solid color-mix(in srgb, var(--critical) 35%, transparent);
  border-radius: var(--radius);
}
@supports not (background: color-mix(in srgb, red 50%, blue)) {
  .danger { background: var(--wash); border-color: var(--critical); }
}
.danger-msg { margin: 0; flex: 1 1 15em; font-size: .8125rem; line-height: 1.45; color: var(--ink-2); }
.danger-msg b { color: var(--ink); font-weight: 650; }
.danger-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
/* Quiet trigger, loud confirm: the button that opens the warning must not look
   like the button that carries it out. */
.btn-warn { color: var(--critical); }
.btn-warn:hover:not(:disabled) { color: var(--critical); border-color: var(--critical); }
.btn:disabled { opacity: .4; cursor: default; }
.btn-danger {
  color: #fff; background: var(--critical); border-color: transparent; font-weight: 600;
}
.btn-danger:hover { color: #fff; background: var(--critical); filter: brightness(1.08); }
.danger-cancel {
  font: inherit; font-size: .8125rem; color: var(--ink-2);
  background: none; border: 0; padding: 8px 4px; cursor: pointer;
  text-decoration: underline; text-underline-offset: 3px;
}
.danger-cancel:hover { color: var(--ink); }
