:root {
  color-scheme: dark;
  --page: #0d0d0d;
  --surface: #1a1a19;
  --surface-2: #262625;
  --border: rgba(255, 255, 255, 0.1);
  --text: #f0efec;
  --text-2: #c3c2b7;
  --muted: #989690;
  --grid: #2c2c2a;
  --axis: #383835;
  --accent: #3987e5;
  --danger: #e66767;
  --tabs-height: 60px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }

html, body { margin: 0; background: var(--page); color: var(--text); }
body {
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overscroll-behavior-y: none;
}
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
h2 { font-size: 17px; font-weight: 600; margin: 0; }
p { margin: 0; }

main {
  max-width: 560px;
  margin: 0 auto;
  padding: calc(16px + env(safe-area-inset-top)) 16px calc(var(--tabs-height) + 24px + env(safe-area-inset-bottom));
}

/* Bottom tabs */
.tabs {
  position: fixed;
  inset: auto 0 0;
  display: flex;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
}
.tab {
  flex: 1;
  height: var(--tabs-height);
  background: none;
  border: 0;
  color: var(--muted);
  font-weight: 500;
}
.tab.on { color: var(--text); box-shadow: inset 0 2px 0 var(--accent); }

/* Buttons */
.btn {
  flex: 1;
  min-height: 48px;
  padding: 0 16px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  font-weight: 600;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: #0b0b0b; }
.btn.danger { color: var(--danger); }
.btn.ghost { background: none; border-color: transparent; color: var(--muted); font-weight: 500; }
.btn.small { flex: none; min-height: 44px; padding: 0 14px; font-size: 14px; }
.btn.wide { width: 100%; }
.row { display: flex; gap: 10px; }
.icon-btn {
  width: 44px;
  height: 44px;
  margin: -8px -8px -8px 0;
  background: none;
  border: 0;
  font-size: 28px;
  line-height: 1;
  color: var(--muted);
}
.link-btn {
  background: none;
  border: 0;
  min-height: 44px;
  padding: 0 8px;
  color: var(--text-2);
  font-size: 15px;
}

/* Text helpers */
.muted { color: var(--text-2); }
.note { color: var(--muted); font-size: 13px; }
.center { text-align: center; }
.error { color: var(--danger); font-size: 14px; }
.error:empty { display: none; }
.empty { color: var(--muted); text-align: center; padding: 28px 12px; }

/* Fast tab: idle */
.fast-idle {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  min-height: calc(100dvh - var(--tabs-height) - 56px);
}
.start-btn {
  width: min(68vw, 260px);
  aspect-ratio: 1;
  border-radius: 50%;
  border: 0;
  background: var(--accent);
  color: #0b0b0b;
  font-size: 24px;
  font-weight: 700;
  letter-spacing: 0.04em;
  margin-bottom: 12px;
}
.start-btn:active { transform: scale(0.98); }

/* Fast tab: running */
.fast-active { display: flex; flex-direction: column; align-items: center; gap: 6px; }
.ring-btn {
  position: relative;
  width: min(80vw, 300px, 36dvh);
  min-width: 230px;
  aspect-ratio: 1;
  padding: 0;
  background: none;
  border: 0;
  border-radius: 50%;
}
.ring { display: block; width: 100%; height: 100%; transform: rotate(-90deg); }
.ring-track, .ring-fill { fill: none; stroke-width: 10; }
.ring-track { stroke: var(--surface-2); }
.ring-fill { stroke: var(--accent); stroke-linecap: round; transition: stroke-dashoffset 0.6s linear; }
.ring-inner {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 0 28px;
  gap: 2px;
}
.ring-caption { color: var(--muted); font-size: 14px; }
.clock { font-size: 40px; font-weight: 600; line-height: 1.15; font-variant-numeric: tabular-nums; }
.now-stage { color: var(--text-2); font-weight: 500; }
.next-stage { color: var(--muted); font-size: 14px; text-align: center; }
.started {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 10px 14px;
  background: var(--surface);
  border-radius: 12px;
}
.started-time { font-weight: 500; }
.end-btn { flex: none; margin-top: 4px; min-height: 56px; }

/* Cards and stat tiles */
.card { background: var(--surface); border-radius: 12px; padding: 14px; display: grid; gap: 10px; }
.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.tiles.three { grid-template-columns: repeat(3, 1fr); margin-top: 12px; }
.tile { background: var(--surface); border-radius: 12px; padding: 12px 14px; min-width: 0; }
.tiles.three .tile { padding: 10px; }
.tile-label { color: var(--muted); font-size: 13px; line-height: 1.25; }
.tile-value { font-size: 24px; font-weight: 600; margin-top: 4px; }
.tiles.three .tile-value { font-size: 18px; }
.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 44px;
  margin: 18px 0 8px;
}

/* Lists */
.list { list-style: none; margin: 12px 0 0; padding: 0; display: grid; gap: 1px; border-radius: 12px; overflow: hidden; }
.section-head + .list { margin-top: 0; }
.list-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  min-height: 56px;
  padding: 10px 14px;
  background: var(--surface);
  border: 0;
  text-align: left;
}
.row-title { font-weight: 500; }
.row-sub { color: var(--muted); font-size: 13px; }
.row-value { font-weight: 600; white-space: nowrap; font-variant-numeric: tabular-nums; }

/* Forms */
.field { display: grid; gap: 4px; min-width: 0; }
.field > span { color: var(--muted); font-size: 13px; }
.time-row { display: grid; grid-template-columns: 1fr auto 1fr; gap: 8px; align-items: center; margin-top: 4px; }
.time-colon { font-weight: 600; }
select { font-size: 18px; font-variant-numeric: tabular-nums; }
input[type="text"], input[type="date"], select {
  width: 100%;
  min-width: 0;
  min-height: 48px;
  padding: 0 10px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface-2);
}
.weight-inputs { display: grid; grid-template-columns: 1fr 1.5fr; gap: 8px; align-items: end; }
.weight-inputs .btn { grid-column: 1 / -1; }

/* Time range filter */
.segments { display: flex; gap: 6px; margin-top: 12px; }
.segment {
  flex: 1;
  min-height: 44px;
  background: none;
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text-2);
  font-size: 14px;
}
.segment.on { background: var(--surface-2); color: var(--text); font-weight: 600; }

/* Weight chart */
.chart-card { margin-top: 12px; padding-bottom: 8px; }
.chart-title { font-size: 14px; font-weight: 500; color: var(--text-2); }
.chart { position: relative; width: 100%; height: 220px; }
.chart svg { display: block; touch-action: pan-y; outline: none; }
.c-grid { stroke: var(--grid); stroke-width: 1; }
.c-axis { stroke: var(--axis); stroke-width: 1; }
.c-tick { fill: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.c-line { fill: none; stroke: var(--accent); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.c-point { fill: var(--accent); }
.c-end { fill: var(--accent); stroke: var(--surface); stroke-width: 2; }
.c-end-label { fill: var(--text); font-size: 13px; font-weight: 600; paint-order: stroke; stroke: var(--surface); stroke-width: 3px; }
.c-cross { stroke: var(--muted); stroke-width: 1; }
.c-tooltip {
  position: absolute;
  display: grid;
  padding: 4px 10px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 13px;
  white-space: nowrap;
  pointer-events: none;
}
.c-tooltip span { color: var(--text-2); font-size: 12px; }

.c-bar { fill: var(--accent); }
.c-bar.on { fill: #5598e7; }
.c-goal { stroke: var(--text-2); stroke-width: 1; }

/* Water */
.water-card { width: 100%; }
.fast-idle .water-card { margin-top: 12px; }
.fast-active .water-card { margin-top: 8px; }
.water-meter { display: grid; gap: 6px; }
.water-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.water-amount { font-size: 18px; font-weight: 600; }
.water-amount .muted { font-size: 14px; font-weight: 400; }
.meter { height: 8px; border-radius: 4px; background: var(--surface-2); overflow: hidden; }
.meter-fill { height: 100%; border-radius: 4px; background: var(--accent); }
.water-tiles { margin-top: 12px; }
.water-note { margin-top: 14px; }

/* Bottom sheet */
dialog {
  width: 100%;
  max-width: 560px;
  max-height: 90dvh;
  margin: auto auto 0;
  padding: 0;
  border: 0;
  border-radius: 18px 18px 0 0;
  background: var(--surface);
  color: var(--text);
}
dialog::backdrop { background: rgba(0, 0, 0, 0.6); }
.sheet-head {
  position: sticky;
  top: 0;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px;
  background: var(--surface);
}
.sheet-body { display: grid; gap: 12px; padding: 0 16px calc(20px + env(safe-area-inset-bottom)); }
.sheet-clock { font-size: 40px; font-weight: 600; text-align: center; font-variant-numeric: tabular-nums; }

/* Stage timeline */
.stages { list-style: none; margin: 4px 0 0; padding: 0; }
.stage {
  display: grid;
  grid-template-columns: 44px 1fr;
  gap: 8px;
  padding: 12px 10px 12px 0;
  border-top: 1px solid var(--grid);
}
.stage-hours { color: var(--muted); font-weight: 600; text-align: right; font-variant-numeric: tabular-nums; }
.stage-title { font-weight: 600; color: var(--text-2); }
.stage-status { color: var(--muted); font-size: 13px; }
.stage-text { color: var(--muted); font-size: 14px; margin-top: 4px; }
.stage.reached .stage-title { color: var(--text); }
.stage.reached .stage-hours { color: var(--text-2); }
.stage.reached .stage-text { color: var(--text-2); }
.stage.current { background: var(--surface-2); border-radius: 10px; border-top-color: transparent; box-shadow: inset 3px 0 0 var(--accent); }
.stage.current + .stage { border-top-color: transparent; }

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