/* ============================================================
   Pokey Pokey — clinical calm, but warm.
   Display: Space Grotesk · Body: Inter (tabular figures for data)
   ============================================================ */

:root {
  --bg:        #eef2f6;
  --bg-2:      #e6ecf2;
  --surface:   #ffffff;
  --ink:       #14202b;
  --muted:     #5c6b7a;
  --line:      #dde5ec;
  --accent:    #0f766e;
  --accent-ink:#ffffff;
  --accent-soft:#d6efec;

  --hot:    #e5484d;
  --warm:   #e8963a;
  --good:   #2f9e68;
  --unused: #b3c0cc;

  --up:   #d1544f;
  --down: #2f9e68;

  --sil:  #dbe4ec;

  --series-weight: var(--accent);
  --series-dose:   #7c6cf0;
  --series-hr:     #e5484d;

  --radius: 16px;
  --radius-sm: 11px;
  --shadow: 0 1px 2px rgba(20,32,43,.05), 0 12px 28px -16px rgba(20,32,43,.22);
  --shadow-sm: 0 1px 2px rgba(20,32,43,.06);

  --font-display: "Space Grotesk", ui-sans-serif, system-ui, sans-serif;
  --font-body: "Inter", ui-sans-serif, system-ui, -apple-system, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg:        #0e1519;
    --bg-2:      #0b1114;
    --surface:   #16212a;
    --ink:       #e6edf3;
    --muted:     #93a3b1;
    --line:      #26333d;
    --accent:    #2dd4bf;
    --accent-ink:#06231f;
    --accent-soft:#153230;
    --hot:    #f2555a;
    --warm:   #eaa04a;
    --good:   #3bb579;
    --unused: #3a4a56;
    --up:   #f2726d;
    --down: #3bb579;
    --sil:  #24313b;
    --series-dose: #9a8cff;
    --series-hr:   #f2555a;
    --shadow: 0 1px 2px rgba(0,0,0,.4), 0 14px 34px -18px rgba(0,0,0,.7);
    --shadow-sm: 0 1px 2px rgba(0,0,0,.4);
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font-body);
  color: var(--ink);
  background: var(--bg);
  line-height: 1.5;
  font-feature-settings: "cv05" 1;
  -webkit-font-smoothing: antialiased;
}
.tnum { font-variant-numeric: tabular-nums; }

h1, h2, h3, .brand, .stat-value, .card-title {
  font-family: var(--font-display);
  letter-spacing: -0.01em;
}
h1 { font-size: 1.5rem; margin: 0; font-weight: 600; }
h2 { font-size: 1.05rem; margin: 0; font-weight: 600; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
.muted { color: var(--muted); }
small { font-size: .72em; color: var(--muted); font-weight: 500; }

/* ---------- Layout shells ---------- */
.wrap {
  max-width: 640px;
  margin: 0 auto;
  padding: 18px 16px calc(96px + env(safe-area-inset-bottom));
}
body.auth {
  display: grid;
  place-items: center;
  min-height: 100dvh;
  padding: 24px 16px;
  background:
    radial-gradient(1200px 500px at 50% -10%, var(--accent-soft), transparent 60%),
    var(--bg);
}

/* ---------- Top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px;
  padding-top: calc(12px + env(safe-area-inset-top));
  background: color-mix(in srgb, var(--bg) 86%, transparent);
  backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--line);
}
.brand {
  display: inline-flex; align-items: center; gap: 9px;
  font-size: 1.15rem; font-weight: 700; color: var(--ink);
}
.brand:hover { text-decoration: none; }
.brand-mark {
  width: 20px; height: 20px; border-radius: 7px;
  background: linear-gradient(145deg, var(--accent), color-mix(in srgb, var(--accent) 55%, #4f46e5));
  box-shadow: inset 0 0 0 3px color-mix(in srgb, var(--accent) 30%, transparent);
  position: relative;
}
.brand-mark::after {
  content: ""; position: absolute; inset: 6px 8px auto 8px; height: 3px;
  border-radius: 3px; background: rgba(255,255,255,.85);
}
.topbar-right { display: flex; align-items: center; gap: 12px; }
.who { font-size: .85rem; color: var(--muted); font-weight: 500; }
.icon-link { font-size: 1.15rem; color: var(--muted); line-height: 1; }

/* ---------- Cards & structure ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
  margin-bottom: 16px;
}
.card-title { margin-bottom: 4px; }
.stack { display: flex; flex-direction: column; gap: 14px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.page-head { margin: 6px 2px 18px; }
.page-head p { margin: 4px 0 0; }
.section-head {
  display: flex; align-items: baseline; justify-content: space-between;
  margin: 22px 2px 12px;
}
.link-sm { font-size: .85rem; font-weight: 500; }

/* ---------- Flash & reminders ---------- */
.flash {
  border-radius: var(--radius-sm);
  padding: 12px 14px; margin-bottom: 14px;
  font-size: .92rem; font-weight: 500;
  border: 1px solid transparent;
}
.flash-ok    { background: var(--accent-soft); color: color-mix(in srgb, var(--accent) 78%, var(--ink)); border-color: color-mix(in srgb, var(--accent) 30%, transparent); }
.flash-error { background: color-mix(in srgb, var(--hot) 14%, var(--surface)); color: var(--hot); border-color: color-mix(in srgb, var(--hot) 34%, transparent); }
.flash-warn  { background: color-mix(in srgb, var(--warm) 16%, var(--surface)); color: color-mix(in srgb, var(--warm) 80%, var(--ink)); }

.reminder {
  display: flex; align-items: center; gap: 12px;
  background: linear-gradient(180deg, var(--surface), var(--surface));
  border: 1px solid color-mix(in srgb, var(--accent) 34%, var(--line));
  border-left: 4px solid var(--accent);
  border-radius: var(--radius);
  padding: 14px 16px; margin-bottom: 16px;
  color: var(--ink); box-shadow: var(--shadow-sm);
}
.reminder:hover { text-decoration: none; border-color: var(--accent); }
.reminder strong { display: block; }
.reminder-dot {
  width: 10px; height: 10px; border-radius: 50%; background: var(--accent);
  flex: none; box-shadow: 0 0 0 4px var(--accent-soft);
  animation: pulse 2.4s ease-in-out infinite;
}
.reminder-go { margin-left: auto; font-weight: 600; color: var(--accent); white-space: nowrap; }
@keyframes pulse { 0%,100% { transform: scale(1); opacity: 1; } 50% { transform: scale(1.25); opacity: .7; } }

/* ---------- Stats ---------- */
.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 6px; }
.stat-grid .stat:first-child { grid-column: 1 / -1; }
.stat { padding: 15px 16px; margin: 0; display: flex; flex-direction: column; gap: 3px; }
.stat-label { font-size: .72rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 600; }
.stat-value { font-size: 1.35rem; font-weight: 600; }
.stat-value small { font-size: .6em; }
.stat-sub { font-size: .85rem; color: var(--muted); }
.stat-accent { background: linear-gradient(160deg, var(--accent-soft), var(--surface)); border-color: color-mix(in srgb, var(--accent) 26%, var(--line)); }
.stat-accent .stat-value { color: color-mix(in srgb, var(--accent) 75%, var(--ink)); }
.trend.up { color: var(--up); } .trend.down { color: var(--down); }

/* ---------- Feed lists ---------- */
.feed { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; }
.feed-item {
  display: flex; align-items: center; gap: 12px;
  background: var(--surface); border: 1px solid var(--line);
  padding: 13px 15px; box-shadow: var(--shadow-sm);
}
.feed-item:first-child { border-top-left-radius: var(--radius); border-top-right-radius: var(--radius); }
.feed-item:last-child  { border-bottom-left-radius: var(--radius); border-bottom-right-radius: var(--radius); }
.feed-item + .feed-item { border-top: none; }
.feed-mark { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); flex: none; }
.feed-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.feed-main strong { font-weight: 600; }
.feed-meta { font-size: .82rem; color: var(--muted); }
.feed-note { color: var(--muted); font-style: italic; }
.feed-ago { font-size: .8rem; color: var(--muted); white-space: nowrap; }

/* ---------- Forms ---------- */
label { display: flex; flex-direction: column; gap: 6px; font-size: .85rem; font-weight: 600; color: var(--ink); }
input, select, textarea {
  font: inherit; color: var(--ink);
  background: var(--surface);
  border: 1.5px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 11px 12px; width: 100%;
  transition: border-color .15s, box-shadow .15s;
  font-weight: 500;
}
textarea { resize: vertical; min-height: 68px; line-height: 1.45; }
input::placeholder, textarea::placeholder { color: color-mix(in srgb, var(--muted) 75%, transparent); font-weight: 400; }
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent);
}
select { appearance: none; background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%); background-position: right 15px center, right 10px center; background-size: 5px 5px, 5px 5px; background-repeat: no-repeat; padding-right: 30px; }
.dose-row { display: grid; grid-template-columns: 1.4fr 1fr; gap: 10px; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  font: inherit; font-weight: 600; font-family: var(--font-body);
  padding: 12px 18px; border-radius: var(--radius-sm);
  border: 1.5px solid var(--line); background: var(--surface); color: var(--ink);
  cursor: pointer; transition: transform .06s, background .15s, border-color .15s;
}
.btn:hover { text-decoration: none; border-color: color-mix(in srgb, var(--ink) 20%, var(--line)); }
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { background: color-mix(in srgb, var(--accent) 88%, #000); border-color: transparent; }
.btn-ghost { background: transparent; }
.btn-block { width: 100%; }
.btn-icon {
  border: none; background: transparent; color: var(--muted);
  font-size: 1.4rem; line-height: 1; cursor: pointer; padding: 4px 8px; border-radius: 8px;
}
.btn-icon:hover { color: var(--hot); background: color-mix(in srgb, var(--hot) 12%, transparent); }
.inline-del { margin: 0; }
.hint { font-size: .85rem; color: var(--muted); margin: 12px 0 0; text-align: center; }

/* ---------- Auth ---------- */
.auth-card {
  width: 100%; max-width: 400px;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 22px; box-shadow: var(--shadow); padding: 30px 26px;
}
.auth-brand { display: flex; align-items: center; gap: 10px; font-family: var(--font-display); font-weight: 700; font-size: 1.2rem; margin-bottom: 20px; }
.auth-card h1 { font-size: 1.5rem; }
.auth-card p.muted { margin: 6px 0 20px; }
.auth-card .stack { margin-top: 4px; }
.auth-card .btn-primary { margin-top: 6px; width: 100%; }
.auth-alt { margin: 18px 0 0; text-align: center; font-size: .9rem; color: var(--muted); }

/* ---------- Bottom tab bar ---------- */
.tabbar {
  position: fixed; z-index: 30;
  left: 50%; transform: translateX(-50%);
  bottom: calc(10px + env(safe-area-inset-bottom));
  width: min(540px, calc(100% - 24px));
  display: flex; align-items: center; justify-content: space-between; gap: 4px;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: saturate(1.5) blur(14px);
  border: 1px solid var(--line);
  border-radius: 22px;
  box-shadow: var(--shadow);
  padding: 7px 8px;
}
.tab-group { flex: 1; display: flex; justify-content: space-around; gap: 2px; min-width: 0; }
.tab {
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  font-size: .68rem; font-weight: 600; color: var(--muted); padding: 6px 0;
  border-radius: 14px; flex: 1; min-width: 0;
}
.tab:hover { text-decoration: none; color: var(--ink); }
.tab svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.tab.is-active { color: var(--accent); }
.tab-primary {
  color: var(--accent-ink); position: relative; top: -14px; flex: 0 0 auto;
}
.tab-primary svg {
  width: 52px; height: 52px; padding: 14px;
  background: var(--accent); border-radius: 50%;
  box-shadow: 0 8px 18px -6px color-mix(in srgb, var(--accent) 70%, transparent);
  stroke-width: 2.4;
}
.tab-primary span { color: var(--muted); margin-top: -6px; }

/* ---------- Body map ---------- */
.bodymap-figures { display: flex; gap: 8px; justify-content: center; }
.bodyfig { margin: 0; flex: 1; max-width: 200px; text-align: center; }
.bodyfig figcaption { font-size: .72rem; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); font-weight: 600; margin-top: 2px; }
.body { width: 100%; height: auto; touch-action: manipulation; }
.body .sil { fill: var(--sil); }
.body .sil-limb { stroke: var(--sil); stroke-width: 17; stroke-linecap: round; }

.site { cursor: pointer; -webkit-tap-highlight-color: transparent; }
.site .site-halo { fill: transparent; transition: fill .15s; }
.site .site-dot { transition: r .12s, fill .15s; stroke: var(--surface); stroke-width: 1.5; }
.site.s-hot    .site-dot { fill: var(--hot); }
.site.s-warm   .site-dot { fill: var(--warm); }
.site.s-good   .site-dot { fill: var(--good); }
.site.s-unused .site-dot { fill: var(--unused); }
button.site { border: none; background: none; padding: 0; }
.site:hover .site-halo, .site:focus-visible .site-halo { fill: color-mix(in srgb, var(--accent) 22%, transparent); }
.site:focus-visible { outline: none; }
.site.is-selected .site-halo { fill: color-mix(in srgb, var(--accent) 30%, transparent); }
.site.is-selected .site-dot {
  r: 7.5; fill: var(--accent); stroke: var(--surface); stroke-width: 2;
  animation: sitepulse 1.6s ease-in-out infinite;
}
@keyframes sitepulse { 0%,100% { stroke-width: 2; } 50% { stroke-width: 4; } }

.legend { list-style: none; display: flex; flex-wrap: wrap; gap: 8px 16px; justify-content: center; padding: 4px 0 0; margin: 12px 0 0; font-size: .78rem; color: var(--muted); }
.legend li { display: inline-flex; align-items: center; gap: 6px; }
.legend .key { width: 11px; height: 11px; border-radius: 50%; }
.legend .key.s-hot { background: var(--hot); } .legend .key.s-warm { background: var(--warm); }
.legend .key.s-good { background: var(--good); } .legend .key.s-unused { background: var(--unused); }

.site-chosen { text-align: center; margin: 12px 0 0; font-size: .95rem; }
.site-chosen strong { color: var(--accent); }
.site-fallback { margin-top: 12px; }
.site-fallback summary { font-size: .85rem; color: var(--muted); cursor: pointer; text-align: center; }
.site-fallback select { margin-top: 10px; }

/* ---------- Weight chart ---------- */
.chart { width: 100%; height: auto; display: block; }
.chart-line { fill: none; stroke: var(--accent); stroke-width: 2.5; stroke-linecap: round; stroke-linejoin: round; }
.chart-area { fill: url(#wg); opacity: .9; stroke: none; }
.wg-top { stop-color: var(--accent); stop-opacity: .22; }
.wg-bot { stop-color: var(--accent); stop-opacity: 0; }
.chart-dot { fill: var(--accent); stroke: var(--surface); stroke-width: 2.5; }
.chart-lbl { fill: var(--muted); font-size: 9px; font-family: var(--font-body); font-weight: 600; }
.chart-empty { color: var(--muted); text-align: center; padding: 28px 10px; font-size: .9rem; }
.wt-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-top: 16px; padding-top: 16px; border-top: 1px solid var(--line); }
.wt-stats > div { display: flex; flex-direction: column; gap: 3px; }
.wt-stats strong { font-size: 1.1rem; font-family: var(--font-display); }
.wt-stats .down { color: var(--down); } .wt-stats .up { color: var(--up); }

/* ---------- Multi-series correlation chart ---------- */
.chart-multi .grid { stroke: var(--line); stroke-width: 1; }
.chart-multi .ser-line { fill: none; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
.chart-multi .ser-dot  { stroke: var(--surface); stroke-width: 1; }
.ser-weight .ser-line { stroke: var(--series-weight); } .ser-weight .ser-dot { fill: var(--series-weight); }
.ser-dose   .ser-line { stroke: var(--series-dose); }   .ser-dose   .ser-dot { fill: var(--series-dose); }
.ser-hr     .ser-line { stroke: var(--series-hr); }     .ser-hr     .ser-dot { fill: var(--series-hr); }
.ser[hidden] { display: none; }

.clegend { list-style: none; display: flex; flex-wrap: wrap; gap: 8px; margin: 14px 0 0; padding: 0; }
.clegend li { flex: 1 1 auto; }
.legend-toggle {
  display: flex; align-items: center; gap: 8px; width: 100%;
  background: var(--bg-2); border: 1.5px solid var(--line); border-radius: var(--radius-sm);
  padding: 8px 10px; cursor: pointer; font: inherit; color: var(--ink); text-align: left;
  transition: border-color .15s, opacity .15s;
}
.legend-toggle:hover { border-color: color-mix(in srgb, var(--ink) 20%, var(--line)); }
.clegend-key { width: 12px; height: 12px; border-radius: 3px; flex: none; }
.ser-weight .clegend-key { background: var(--series-weight); }
.ser-dose   .clegend-key { background: var(--series-dose); }
.ser-hr     .clegend-key { background: var(--series-hr); }
.clegend-name { font-weight: 600; font-size: .82rem; }
.clegend-val { margin-left: auto; font-size: .82rem; color: var(--muted); font-weight: 600; }
.legend-toggle.is-off { opacity: .45; }
.legend-toggle.is-off .clegend-key { background: var(--unused) !important; }
.legend-toggle.is-empty, .legend-toggle[disabled] { opacity: .5; cursor: default; }
.chart-foot { font-size: .78rem; margin: 12px 0 0; line-height: 1.45; }
.chart-card .chart-empty { padding: 40px 10px; }

/* ---------- Dashboard charts link ---------- */
.charts-link {
  display: flex; align-items: center; gap: 14px;
  padding: 15px 16px; margin-bottom: 16px; color: var(--ink);
}
.charts-link:hover { text-decoration: none; border-color: color-mix(in srgb, var(--accent) 40%, var(--line)); }
.charts-link svg {
  width: 30px; height: 30px; flex: none; padding: 6px;
  fill: none; stroke: var(--accent); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round;
  background: var(--accent-soft); border-radius: 10px;
}
.charts-link strong { font-family: var(--font-display); }
.charts-link .charts-go { margin-left: auto; color: var(--accent); font-weight: 700; font-size: 1.1rem; }

/* ---------- Mood picker (daily check-in) ---------- */
.mood-field { border: none; padding: 0; margin: 0; }
.mood-field legend { font-size: .85rem; font-weight: 600; color: var(--ink); padding: 0; margin-bottom: 6px; }
.mood-row { display: flex; flex-wrap: wrap; gap: 6px; }
.mood-opt { flex: 1 1 0; min-width: 56px; }
.mood-opt input { position: absolute; opacity: 0; width: 0; height: 0; }
.mood-opt span {
  display: block; text-align: center; padding: 9px 6px; font-size: .82rem; font-weight: 600;
  border: 1.5px solid var(--line); border-radius: var(--radius-sm); background: var(--surface);
  color: var(--muted); cursor: pointer; transition: border-color .15s, background .15s, color .15s;
}
.mood-opt input:checked + span { border-color: var(--accent); background: var(--accent-soft); color: color-mix(in srgb, var(--accent) 78%, var(--ink)); }
.mood-opt input:focus-visible + span { box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent); }

/* ---------- Usage bars ---------- */
.usage { list-style: none; margin: 10px 0 0; padding: 0; display: flex; flex-direction: column; gap: 9px; }
.usage li { display: grid; grid-template-columns: 130px 1fr 24px; align-items: center; gap: 10px; font-size: .82rem; }
.usage-label { color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.usage-bar { height: 8px; background: var(--bg-2); border-radius: 5px; overflow: hidden; }
.usage-bar span { display: block; height: 100%; background: linear-gradient(90deg, var(--accent), color-mix(in srgb, var(--accent) 60%, #4f46e5)); border-radius: 5px; }
.usage-count { text-align: right; font-weight: 600; }

/* ---------- Empty states ---------- */
.empty { text-align: center; padding: 28px 20px; }
.empty p { color: var(--muted); margin: 0 0 14px; }

/* ---------- Wider screens ---------- */
@media (min-width: 720px) {
  .wrap { padding-top: 24px; }
  .stat-grid { grid-template-columns: repeat(3, 1fr); }
  .stat-grid .stat:first-child { grid-column: auto; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
