:root {
  --bg: #f6f1e7;
  --surface: #fffdf8;
  --ink: #1d2420;
  --muted: #6b726d;
  --line: #e4dccb;
  --brand: #1f3a2e;
  --brand-ink: #f6f1e7;
  --accent: #e0912f;
  --good: #2f8a57;
  --bad: #c4513d;
  --radius: 16px;
  --shadow: 0 1px 2px rgba(0,0,0,.05), 0 4px 14px rgba(31,58,46,.07);
  --tabbar-h: 64px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121714;
    --surface: #1b221e;
    --ink: #eef0ea;
    --muted: #9aa39d;
    --line: #2b352f;
    --brand: #8fc7a6;
    --brand-ink: #10251a;
    --accent: #f0a648;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--ink);
  min-height: 100dvh;
  padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  -webkit-tap-highlight-color: transparent;
}
h1, h2, h3 { line-height: 1.2; margin: 0 0 .5rem; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
p { margin: 0 0 .75rem; }
a { color: inherit; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }

/* Top bar */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 8px; font-size: 1.05rem; }
.brand em { font-style: normal; color: var(--muted); font-size: .85rem; }
.dog-chip {
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  border-radius: 999px; padding: 6px 12px; font: inherit; font-size: .9rem;
  max-width: 50vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

main { padding: 16px; max-width: 720px; margin: 0 auto; outline: none; }

/* Tab bar */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: grid; grid-template-columns: repeat(5, 1fr);
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--surface); border-top: 1px solid var(--line);
}
.tabbar a {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; text-decoration: none; font-size: .72rem; color: var(--muted);
}
.tabbar a .ico { font-size: 1.25rem; filter: grayscale(1); opacity: .7; }
.tabbar a.active { color: var(--brand); font-weight: 600; }
.tabbar a.active .ico { filter: none; opacity: 1; }

/* Cards & lists */
.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 16px; margin-bottom: 12px;
  box-shadow: var(--shadow);
}
.list { list-style: none; margin: 0; padding: 0; }
.list-item {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 14px 16px; background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--radius);
  margin-bottom: 8px; text-decoration: none;
}
.list-item .grow { flex: 1; min-width: 0; }
.list-item .title { font-weight: 600; }
.chev { color: var(--muted); }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.spread { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }

.pill {
  display: inline-block; font-size: .72rem; padding: 2px 8px; border-radius: 999px;
  background: color-mix(in srgb, var(--brand) 12%, transparent); color: var(--brand);
  font-weight: 600; text-transform: capitalize;
}
.pill.l2 { background: color-mix(in srgb, var(--accent) 18%, transparent); color: var(--accent); }
.pill.l3 { background: color-mix(in srgb, var(--bad) 15%, transparent); color: var(--bad); }

.filters { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 8px; margin-bottom: 8px; }
.filters button { white-space: nowrap; }

/* Forms & buttons */
label { display: block; font-size: .85rem; color: var(--muted); margin: 10px 0 4px; }
input, select, textarea {
  width: 100%; font: inherit; color: var(--ink);
  background: var(--bg); border: 1px solid var(--line);
  border-radius: 12px; padding: 10px 12px;
}
textarea { min-height: 70px; resize: vertical; }
.btn {
  appearance: none; border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  font: inherit; font-weight: 600; padding: 10px 16px; border-radius: 12px; cursor: pointer;
  text-decoration: none; display: inline-flex; align-items: center; justify-content: center; gap: 6px;
}
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn.danger { color: var(--bad); }
.btn.block { width: 100%; }
.btn.sm { padding: 6px 12px; font-size: .875rem; }
.btn.on { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
.btn:active { transform: scale(.98); }

/* Train screen */
.clicker {
  display: block; width: 100%; aspect-ratio: 1.6 / 1; max-height: 34vh;
  border: none; border-radius: 28px; cursor: pointer;
  background: radial-gradient(circle at 50% 35%, color-mix(in srgb, var(--accent) 85%, white), var(--accent));
  color: #2a1a05; font-size: 1.6rem; font-weight: 800; letter-spacing: .04em;
  box-shadow: 0 8px 0 color-mix(in srgb, var(--accent) 60%, black), var(--shadow);
  transition: transform .05s, box-shadow .05s;
  user-select: none; -webkit-user-select: none; touch-action: manipulation;
}
.clicker.pressed { transform: translateY(6px); box-shadow: 0 2px 0 color-mix(in srgb, var(--accent) 60%, black); }
.clicker small { display: block; font-size: .8rem; font-weight: 600; opacity: .7; letter-spacing: 0; }

.timer { font-variant-numeric: tabular-nums; font-size: 2.6rem; font-weight: 700; text-align: center; }
.timer.done { color: var(--accent); }
.reps { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.rep-btn {
  border-radius: var(--radius); border: 2px solid; padding: 14px 8px; font: inherit;
  background: var(--surface); cursor: pointer; touch-action: manipulation;
}
.rep-btn .n { display: block; font-size: 2rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.rep-btn.good { border-color: var(--good); color: var(--good); }
.rep-btn.bad { border-color: var(--bad); color: var(--bad); }

/* Progress */
.bar { height: 8px; border-radius: 99px; background: var(--line); overflow: hidden; margin-top: 6px; }
.bar > span { display: block; height: 100%; background: var(--good); }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 12px; }
.stat { text-align: center; padding: 12px 6px; }
.stat .n { font-size: 1.6rem; font-weight: 800; display: block; }
.stat .l { font-size: .75rem; color: var(--muted); }

/* Command detail */
ol.steps { padding-left: 1.25rem; margin: 0; }
ol.steps li { margin-bottom: .5rem; }
ul.tips { padding-left: 1.1rem; margin: 0; }
ul.tips li { margin-bottom: .35rem; }

/* Plans */
.day { display: flex; gap: 12px; align-items: flex-start; }
.day input[type=checkbox] { width: 26px; height: 26px; flex: none; margin-top: 2px; accent-color: var(--good); }
.day.done .title { text-decoration: line-through; color: var(--muted); }
.progress-ring { font-weight: 700; color: var(--brand); }

.empty { text-align: center; padding: 32px 16px; }
.empty .big { font-size: 3rem; }

#toast {
  position: fixed; left: 50%; bottom: calc(var(--tabbar-h) + 16px + env(safe-area-inset-bottom));
  transform: translateX(-50%) translateY(20px); opacity: 0; pointer-events: none;
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 12px;
  font-size: .9rem; transition: opacity .2s, transform .2s; z-index: 20; max-width: 90vw;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* Recording */
.rec-live { animation: recpulse 1s ease-in-out infinite; }
@keyframes recpulse { 50% { background: color-mix(in srgb, var(--bad) 18%, var(--surface)); } }
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 36px; height: 36px; border-radius: 999px; text-decoration: none;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink); font-size: 1.1rem;
}
.cue-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.cue-row:last-child { border-bottom: none; }
.cue-row .title { flex: 1; min-width: 0; font-weight: 600; font-size: .95rem; }
.cue-row > .row, .cue-row > .btn { flex: none; }
