:root {
  --bg: #12161A;
  --panel: #191F25;
  --panel-raised: #1F262D;
  --line: #2A333B;
  --text: #EAEEF1;
  --text-muted: #8B96A0;
  --amber: #E8873A;
  --amber-dim: #5A4128;
  --green: #7CB88F;
  --green-dim: #33463C;

  /* per-routine accents */
  --c-preride: #5B8FA8;      /* steel blue */
  --c-preride-dim: #2E4652;
  --c-postride: #E8873A;     /* amber */
  --c-postride-dim: #5A4128;
  --c-prerun: #D6553C;       /* cinder red-orange */
  --c-prerun-dim: #522A20;
  --c-postrun: #3F9E8F;      /* teal */
  --c-postrun-dim: #1F433C;
  --c-flex: #9B7FD4;         /* violet */
  --c-flex-dim: #3A3155;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: 'Inter', sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}
button, input, select, textarea { font-family: inherit; }
button { transition: opacity .15s ease, background .15s ease; cursor: pointer; }
button:hover:not(:disabled) { opacity: .88; }
button:disabled { opacity: .35; cursor: not-allowed; }
a { color: inherit; }
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-thumb { background: var(--line); border-radius: 3px; }

.app {
  max-width: 480px;
  margin: 0 auto;
  padding: max(20px, env(safe-area-inset-top)) 18px calc(40px + env(safe-area-inset-bottom));
  min-height: 100%;
}

/* header */
.header {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  margin-bottom: 18px;
}
.header-eyebrow {
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  letter-spacing: .14em;
  color: var(--amber);
}
.header-title {
  font-family: 'Space Grotesk', sans-serif;
  font-size: 26px;
  font-weight: 700;
  margin-top: 2px;
}
.header-date {
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  color: var(--text-muted);
  text-align: right;
  max-width: 120px;
}

/* nav */
.nav {
  display: flex;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 4px;
  gap: 4px;
  margin-bottom: 20px;
}
.nav-btn {
  flex: 1;
  padding: 9px 4px;
  background: transparent;
  border: none;
  border-radius: 7px;
  color: var(--text-muted);
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  letter-spacing: .01em;
}
.nav-btn.active { background: var(--panel-raised); color: var(--text); }
.nav-btn:disabled { opacity: .3; cursor: not-allowed; }

.body { min-height: 400px; }

/* generic building blocks */
.section-title {
  font-family: 'JetBrains Mono', monospace;
  font-size: 12px;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin: 0 0 10px;
}
.section-divider { height: 1px; background: var(--line); margin: 22px 0; }
.empty-note { font-size: 13px; color: var(--text-muted); line-height: 1.5; }

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px 10px;
}

/* today: weekly dial */
.today-top {
  display: flex;
  gap: 14px;
  align-items: center;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 16px;
  margin-bottom: 22px;
}
.dial-wrap { position: relative; flex-shrink: 0; }
.dial-wrap svg { display: block; }
.dial-center {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  flex-direction: column;
}
.dial-big { font-family: 'JetBrains Mono', monospace; font-size: 24px; font-weight: 700; }
.dial-small { font-size: 11px; color: var(--text-muted); }
.today-top-text .stat-label { font-size: 12px; color: var(--text-muted); line-height: 1.4; margin-top: 2px; }
.today-top-text .stat-name {
  font-family: 'Space Grotesk', sans-serif;
  font-weight: 700;
  font-size: 15px;
}

/* routine start buttons grid */
.routine-btns {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 8px;
}
.routine-start-btn {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  text-align: left;
  background: var(--panel);
  border: 1px solid var(--line);
  border-left: 4px solid var(--rc, var(--amber));
  border-radius: 10px;
  padding: 12px 14px;
  color: var(--text);
}
.routine-start-btn .icon { width: 30px; height: 30px; flex-shrink: 0; color: var(--rc, var(--amber)); }
.routine-start-btn .icon svg { width: 100%; height: 100%; }
.routine-start-btn .rlabel { flex: 1; }
.routine-start-btn .rname { font-family: 'Space Grotesk', sans-serif; font-weight: 700; font-size: 14.5px; }
.routine-start-btn .rmeta { font-size: 11.5px; color: var(--text-muted); margin-top: 2px; }
.routine-start-btn .rarrow { color: var(--text-muted); font-size: 16px; }

/* activity list */
.activity-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 0;
  border-bottom: 1px solid var(--line);
}
.activity-row:last-child { border-bottom: none; }
.activity-dot { width: 8px; height: 8px; border-radius: 999px; flex-shrink: 0; }
.activity-title { font-size: 13.5px; font-weight: 600; }
.activity-sub { font-size: 11.5px; color: var(--text-muted); margin-top: 1px; }

/* buttons */
.btn-primary {
  width: 100%;
  background: var(--amber);
  color: #1A1206;
  border: none;
  border-radius: 10px;
  padding: 14px 18px;
  font-family: 'Space Grotesk', sans-serif;
  font-weight: 700;
  font-size: 15px;
}
.btn-secondary {
  width: 100%;
  background: transparent;
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 13px 18px;
  font-family: 'Space Grotesk', sans-serif;
  font-weight: 600;
  font-size: 14px;
}
.btn-icon {
  flex: 1;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px 10px;
  color: var(--text);
  font-size: 13px;
}
.btn-link {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 12.5px;
  text-decoration: underline;
}

/* routines list */
.routine-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-left: 4px solid var(--rc, var(--amber));
  border-radius: 12px;
  padding: 16px;
  margin-bottom: 14px;
}
.routine-card-head { display: flex; align-items: center; gap: 12px; margin-bottom: 10px; }
.routine-card-head .icon { width: 34px; height: 34px; flex-shrink: 0; color: var(--rc, var(--amber)); }
.routine-card-head .icon svg { width: 100%; height: 100%; }
.routine-card-title { font-family: 'Space Grotesk', sans-serif; font-weight: 700; font-size: 17px; }
.routine-card-meta { font-family: 'JetBrains Mono', monospace; font-size: 11px; color: var(--text-muted); margin-top: 2px; }
.routine-card-desc { font-size: 13px; color: var(--text-muted); line-height: 1.5; margin-bottom: 12px; }
.routine-steps-toggle { font-size: 12.5px; color: var(--text-muted); text-decoration: underline; background: none; border: none; padding: 0; margin-bottom: 10px; }
.step-list { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; }
.step-list-row { display: flex; align-items: center; gap: 10px; background: var(--panel-raised); border-radius: 9px; padding: 8px 11px; }
.step-list-name { font-size: 13px; font-weight: 600; }
.step-list-side { font-weight: 400; color: var(--text-muted); }
.step-list-time { font-family: 'JetBrains Mono', monospace; font-size: 11.5px; color: var(--text-muted); margin-left: auto; }

/* runner */
.runner-wrap { display: flex; flex-direction: column; align-items: center; text-align: center; padding-top: 4px; }
.runner-progress { font-family: 'JetBrains Mono', monospace; font-size: 12px; color: var(--text-muted); margin-bottom: 10px; }
.runner-pose { width: 96px; height: 96px; color: var(--rc, var(--amber)); margin-bottom: 6px; }
.runner-pose svg { width: 100%; height: 100%; }
.runner-time { font-family: 'JetBrains Mono', monospace; font-size: 42px; font-weight: 700; line-height: 1; }
.runner-name { font-family: 'Space Grotesk', sans-serif; font-size: 22px; font-weight: 700; margin-top: 16px; }
.runner-side { font-size: 13px; color: var(--rc, var(--amber)); margin-top: 4px; font-family: 'JetBrains Mono', monospace; }
.runner-cue { font-size: 13.5px; color: var(--text-muted); line-height: 1.5; margin-top: 14px; max-width: 340px; }
.runner-controls { display: flex; align-items: center; gap: 10px; margin-top: 26px; width: 100%; }
.runner-controls .btn-primary { flex: none; padding: 12px 28px; }

.finished-wrap { display: flex; flex-direction: column; align-items: center; text-align: center; padding-top: 50px; }
.finished-check {
  width: 64px; height: 64px; border-radius: 999px;
  background: var(--green-dim); color: var(--green);
  font-size: 30px; display: flex; align-items: center; justify-content: center;
  margin-bottom: 18px;
}
.finished-title { font-family: 'Space Grotesk', sans-serif; font-size: 22px; font-weight: 700; }
.finished-sub { font-size: 13.5px; color: var(--text-muted); margin-top: 8px; margin-bottom: 26px; }

/* calendar */
.cal-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.cal-nav-btn { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; width: 32px; height: 32px; color: var(--text); font-size: 16px; }
.cal-month-label { font-family: 'Space Grotesk', sans-serif; font-size: 16px; font-weight: 700; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.cal-dow { font-family: 'JetBrains Mono', monospace; font-size: 10px; color: var(--text-muted); text-align: center; padding-bottom: 4px; }
.cal-cell {
  aspect-ratio: 1;
  background: var(--panel); border: 1px solid var(--line); border-radius: 7px;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 3px; padding: 2px;
}
.cal-cell.today { border-color: var(--amber); }
.cal-cell-num { font-size: 11.5px; font-family: 'JetBrains Mono', monospace; }
.cal-cell-marks { display: flex; gap: 3px; flex-wrap: wrap; justify-content: center; height: 6px; }
.cal-dot { width: 5px; height: 5px; border-radius: 999px; }
.cal-legend { display: flex; flex-wrap: wrap; gap: 12px 18px; margin-top: 16px; }
.legend-item { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-muted); }

/* progress */
.stats-row { display: flex; gap: 10px; margin-bottom: 20px; flex-wrap: wrap; }
.stat-card-flat {
  flex: 1; min-width: 90px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  padding: 14px 10px; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 6px; min-height: 90px;
}
.stat-flat-value { font-family: 'JetBrains Mono', monospace; font-size: 24px; font-weight: 700; }
.stat-flat-unit { font-size: 12px; color: var(--text-muted); margin-left: 2px; }
.stat-label { font-size: 11px; color: var(--text-muted); text-align: center; line-height: 1.3; }

.bar-chart { display: flex; gap: 8px; height: 140px; align-items: flex-end; margin-bottom: 10px; }
.bar-col { flex: 1; display: flex; flex-direction: column; align-items: center; height: 100%; }
.bar-track { flex: 1; width: 60%; position: relative; display: flex; align-items: flex-end; background: var(--panel); border-radius: 5px; }
.bar-fill { width: 100%; border-radius: 5px; transition: height .4s ease; background: var(--amber); }
.bar-target-line { position: absolute; left: -3px; right: -3px; border-top: 1px dashed var(--text-muted); }
.bar-label { font-size: 9px; color: var(--text-muted); margin-top: 6px; font-family: 'JetBrains Mono', monospace; text-align: center; }
.bar-count { font-size: 11px; font-weight: 700; margin-top: 2px; }

.routine-totals { display: flex; flex-direction: column; gap: 8px; }
.routine-total-row { display: flex; align-items: center; gap: 10px; background: var(--panel); border: 1px solid var(--line); border-left: 4px solid var(--rc, var(--amber)); border-radius: 10px; padding: 10px 14px; }
.routine-total-name { flex: 1; font-size: 13.5px; font-weight: 600; }
.routine-total-count { font-family: 'JetBrains Mono', monospace; font-size: 15px; font-weight: 700; }

/* data tab */
.data-actions { display: flex; flex-direction: column; gap: 10px; }
.data-json {
  width: 100%;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--text-muted);
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  padding: 12px;
  min-height: 160px;
  resize: vertical;
}
.toast {
  position: fixed;
  bottom: calc(24px + env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  background: var(--panel-raised);
  border: 1px solid var(--line);
  color: var(--text);
  font-size: 13px;
  padding: 10px 18px;
  border-radius: 999px;
  z-index: 100;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s ease, transform .2s ease;
}
.toast.show { opacity: 1; }
