:root {
  --bg: #0f1115;
  --card: #181b22;
  --card-2: #20242e;
  --line: #2a2f3a;
  --text: #e8eaf0;
  --muted: #8b93a7;
  --accent: #5eead4;
  --gold: #fbbf24;
  --warn: #f59e0b;
  --radius: 16px;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg); color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  line-height: 1.5; min-height: 100vh; padding: 24px 16px 96px;
  display: flex; justify-content: center;
}
.wrap { width: 100%; max-width: 520px; }

header.app { text-align: center; margin-bottom: 20px; }
header.app .logo { font-size: 13px; letter-spacing: 3px; text-transform: uppercase; color: var(--accent); font-weight: 700; }
.tagline { font-size: clamp(20px, 6vw, 26px); margin: -10px 0 18px; letter-spacing: -0.5px; text-align: center; white-space: nowrap; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; margin-bottom: 16px; }
.card h2 { font-size: 18px; margin: 0 0 6px; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.muted-p { font-size: 13px; color: var(--muted); margin: 0 0 12px; }

/* Splash blurb */
.blurb p { margin: 0 0 12px; color: var(--muted); font-size: 15px; }
.blurb p strong { color: var(--text); }
.blurb .commit { margin-top: 4px; padding: 12px 14px; background: var(--card-2); border-radius: 12px; font-size: 14px; color: var(--text); border-left: 3px solid var(--accent); }
.toggle { background: none; border: none; color: var(--accent); cursor: pointer; font-size: 13px; padding: 8px 0 0; font-weight: 600; }

/* inputs / rows */
.idrow { display: flex; gap: 8px; margin-bottom: 4px; }
.idrow input, .idrow select { flex: 1; min-width: 0; background: var(--card-2); border: 1px solid var(--line); color: var(--text); border-radius: 10px; padding: 12px; font-size: 16px; }
.idrow button { flex-shrink: 0; background: var(--accent); color: #06241f; border: none; border-radius: 10px; padding: 0 18px; font-weight: 700; cursor: pointer; }
label.fld { display: block; font-size: 12px; color: var(--muted); margin: 0 0 6px; text-transform: uppercase; letter-spacing: .5px; }

.btn { display: block; width: 100%; border: none; border-radius: 12px; padding: 15px; font-size: 16px; font-weight: 700; cursor: pointer; margin-top: 8px; transition: transform .05s ease, opacity .15s ease; }
.btn:active { transform: scale(0.985); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: #06241f; }
.btn-secondary { background: var(--card-2); color: var(--text); border: 1px solid var(--line); }
.btn-row { display: flex; gap: 10px; }
.btn-row .btn { margin-top: 0; }
.hint { text-align: center; font-size: 12px; color: var(--muted); margin: 10px 0 0; }
.status { font-size: 13px; color: var(--muted); margin-top: 12px; text-align: center; }
.status.err { color: var(--warn); }
a.linkbtn { text-decoration: none; text-align: center; }

/* Streaks */
.streaks { display: flex; gap: 12px; margin-bottom: 16px; }
.streaks .card { flex: 1; margin-bottom: 0; text-align: center; padding: 18px 12px; }
.streaks .num { font-size: 40px; font-weight: 800; line-height: 1; }
.streaks .num.cur { color: var(--accent); }
.streaks .num.best { color: var(--gold); }
.streaks .label { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: 1px; margin-top: 6px; }
.flame { font-size: 18px; }

/* Today */
.today-head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 4px; }
.today-head h2 { font-size: 18px; margin: 0; }
.today-head .date { font-size: 13px; color: var(--muted); }
.done-badge { display: inline-flex; align-items: center; gap: 6px; background: rgba(94,234,212,0.12); color: var(--accent); border: 1px solid rgba(94,234,212,0.3); padding: 4px 10px; border-radius: 999px; font-size: 13px; font-weight: 600; }
.section-label { font-size: 11px; text-transform: uppercase; letter-spacing: 1px; color: var(--muted); margin: 16px 0 2px; font-weight: 700; }
.section-label.optional { color: var(--gold); }
.section-note { font-size: 12px; color: var(--muted); margin: 0 0 4px; }

.exercise { display: flex; align-items: center; gap: 12px; padding: 14px 0; border-bottom: 1px solid var(--line); }
.exercise:last-of-type { border-bottom: none; }
.exercise .icon { font-size: 26px; width: 34px; text-align: center; }
.exercise .info { flex: 1; min-width: 0; }
.exercise .name { font-weight: 600; }
.exercise .min { font-size: 12px; color: var(--muted); }
.exercise .logged-today { font-size: 12px; color: var(--accent); margin-top: 2px; }
.exercise input { width: 64px; background: var(--card-2); border: 1px solid var(--line); color: var(--text); border-radius: 10px; padding: 10px; font-size: 16px; text-align: center; -moz-appearance: textfield; }
.exercise input::-webkit-outer-spin-button, .exercise input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.exercise .unit { font-size: 12px; color: var(--muted); width: 30px; }

/* Totals / averages */
.totals h2 { font-size: 18px; margin: 0 0 14px; }
.totals h2 .sub { font-weight: 400; font-size: 12px; color: var(--muted); }
.grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.tot { background: var(--card-2); border-radius: 12px; padding: 14px 8px; text-align: center; }
.tot .v { font-size: 22px; font-weight: 800; }
.tot .k { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; margin-top: 4px; }
.tot.optional { outline: 1px solid rgba(251,191,36,0.25); }
.days { text-align: center; margin-top: 14px; font-size: 13px; color: var(--muted); }
.pb-streak { text-align: center; padding: 2px 0 14px; }
.pb-streak-v { display: block; font-size: 40px; font-weight: 800; color: var(--gold); line-height: 1; }
.pb-streak-k { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: 1px; }

/* Routine editor */
.callout { background: rgba(94,234,212,0.07); border: 1px solid rgba(94,234,212,0.25); border-radius: 12px; padding: 12px 14px; font-size: 13px; color: var(--text); margin-bottom: 14px; }
.callout strong { color: var(--accent); }
.re-row { display: flex; align-items: center; gap: 10px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.re-row:last-child { border-bottom: none; }
.re-icon { font-size: 20px; width: 26px; text-align: center; }
.re-label { flex: 1; font-weight: 600; min-width: 0; }
.re-min { width: 58px; background: var(--card-2); border: 1px solid var(--line); color: var(--text); border-radius: 8px; padding: 8px; text-align: center; font-size: 15px; -moz-appearance: textfield; }
.re-min::-webkit-outer-spin-button, .re-min::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.re-unit { font-size: 11px; color: var(--muted); width: 26px; }
.re-opt { font-size: 11px; border: 1px solid var(--line); background: var(--card-2); color: var(--muted); border-radius: 999px; padding: 5px 9px; cursor: pointer; white-space: nowrap; }
.re-opt.on { border-color: var(--gold); color: var(--gold); background: rgba(251,191,36,0.1); }
.re-rm { background: none; border: 1px solid var(--line); color: var(--muted); border-radius: 8px; padding: 6px 9px; cursor: pointer; }

/* Account / friend code */
.idbox { display: flex; align-items: center; gap: 8px; background: var(--card-2); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; }
.idbox code { flex: 1; min-width: 0; font-size: 22px; font-weight: 700; letter-spacing: 3px; overflow-wrap: anywhere; color: var(--accent); }
.idbox button { flex-shrink: 0; background: var(--accent); color: #06241f; border: none; border-radius: 8px; padding: 8px 14px; font-weight: 700; cursor: pointer; font-size: 13px; }

/* Friends */
.friend-item { display: flex; justify-content: space-between; align-items: center; padding: 11px 0; border-bottom: 1px solid var(--line); }
.friend-item:last-child { border-bottom: none; }
.friend-item .nm { font-weight: 600; }
.friend-item button.rm { background: none; border: 1px solid var(--line); color: var(--muted); border-radius: 8px; padding: 6px 12px; cursor: pointer; font-size: 12px; }

/* Leaderboard */
.lb-tabs { display: flex; gap: 6px; margin-bottom: 12px; }
.lb-tab { flex: 1; background: var(--card-2); border: 1px solid var(--line); color: var(--muted); border-radius: 10px; padding: 9px 4px; font-size: 12px; font-weight: 700; cursor: pointer; }
.lb-tab.active { background: var(--accent); color: #06241f; border-color: var(--accent); }
.lb-exsel { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
.exsel-btn { background: var(--card-2); border: 1px solid var(--line); color: var(--text); border-radius: 999px; padding: 6px 12px; font-size: 12px; cursor: pointer; }
.exsel-btn.active { background: rgba(94,234,212,0.15); border-color: var(--accent); color: var(--accent); }
.lb-row { background: var(--card-2); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; margin-bottom: 10px; }
.lb-row:last-child { margin-bottom: 0; }
.lb-row.me { border-color: var(--accent); }
.lb-row.todo { border-color: var(--warn); background: rgba(245,158,11,0.07); }
.lb-head { display: flex; align-items: center; gap: 10px; }
.lb-rank { font-weight: 800; color: var(--muted); min-width: 18px; }
.lb-name { flex: 1; font-weight: 700; overflow-wrap: anywhere; }
.lb-name .you { font-size: 10px; color: var(--accent); border: 1px solid var(--accent); border-radius: 999px; padding: 1px 7px; margin-left: 6px; vertical-align: middle; }
.lb-streak { font-weight: 800; color: var(--accent); white-space: nowrap; }
.lb-todo { font-size: 10px; font-weight: 700; color: var(--warn); border: 1px solid var(--warn); border-radius: 999px; padding: 1px 7px; white-space: nowrap; }
.lb-routine { margin-top: 8px; font-size: 15px; letter-spacing: 3px; }
.lb-metrics { margin-top: 10px; display: flex; flex-direction: column; gap: 5px; }
.lb-m { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); gap: 8px; }
.lb-m .lb-v { color: var(--text); text-align: right; }

footer { text-align: center; font-size: 12px; color: var(--muted); margin-top: 20px; }
footer button { background: none; border: none; color: var(--muted); text-decoration: underline; cursor: pointer; font-size: 12px; }

.card h2 .sub { font-weight: 400; font-size: 13px; color: var(--muted); margin-left: 6px; }

/* Badge activity feed */
.feed-row { display: flex; align-items: center; gap: 10px; padding: 9px 0; border: none; border-bottom: 1px solid var(--line); width: 100%; background: none; color: inherit; font: inherit; text-align: left; cursor: pointer; }
.feed-row:last-child { border-bottom: none; }
.feed-row:active { opacity: 0.6; }
.feed-icon { font-size: 22px; width: 28px; text-align: center; }
.feed-text { flex: 1; font-size: 14px; color: var(--muted); min-width: 0; }
.feed-text strong { color: var(--text); font-weight: 700; }
.feed-time { font-size: 11px; color: var(--muted); white-space: nowrap; }

/* Badge grid + cells */
.badge-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin: 4px 0 8px; }
.badge { background: var(--card-2); border: 1px solid var(--line); border-radius: 12px; padding: 14px 8px; text-align: center; cursor: pointer; color: var(--text); font: inherit; transition: transform .05s ease, border-color .15s ease; }
.badge:active { transform: scale(0.97); }
.badge:not(.locked) { border-color: rgba(251,191,36,0.45); }
.badge.locked { opacity: 0.4; filter: grayscale(1); }
.badge-ic { font-size: 30px; line-height: 1; }
.badge-nm { font-size: 11px; font-weight: 700; margin-top: 6px; }
.badge-cnt { font-size: 10px; color: var(--muted); margin-top: 3px; text-transform: uppercase; letter-spacing: .5px; }

/* Badge detail */
.badge-detail { text-align: center; padding: 12px 0 4px; }
.badge-detail.locked .bd-ic { filter: grayscale(1); opacity: 0.5; }
.bd-ic { font-size: 56px; line-height: 1; }
.bd-nm { font-size: 22px; margin: 10px 0 2px; }
.bd-grp { font-size: 11px; text-transform: uppercase; letter-spacing: 1px; color: var(--gold); font-weight: 700; }
.bd-desc { font-size: 14px; color: var(--muted); margin: 10px 0 0; }
.bd-prog { margin: 16px 0; }
.bd-prog-head { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.bd-bar { height: 8px; background: var(--card-2); border-radius: 999px; overflow: hidden; }
.bd-bar-fill { height: 100%; background: var(--accent); border-radius: 999px; transition: width .3s ease; }
.bd-who { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 4px; }
.who-chip { font-size: 12px; background: var(--card-2); border: 1px solid var(--line); border-radius: 999px; padding: 5px 11px; }
.who-chip.me { border-color: var(--accent); color: var(--accent); }

/* Self-update banner (shown when a new deploy is detected in the foreground) */
.update-banner { position: fixed; top: 0; left: 50%; transform: translateX(-50%); width: 100%; max-width: 520px; background: var(--gold); color: #2a1c00; border: none; padding: 12px; font-size: 14px; font-weight: 700; cursor: pointer; z-index: 60; box-shadow: 0 4px 18px rgba(0,0,0,0.45); }

/* Sticky bottom tab nav */
.tabbar { position: fixed; bottom: 0; left: 50%; transform: translateX(-50%); width: 100%; max-width: 520px; display: flex; gap: 2px; background: var(--card); border-top: 1px solid var(--line); padding: 6px 6px max(6px, env(safe-area-inset-bottom)); z-index: 40; box-shadow: 0 -8px 24px rgba(0,0,0,0.35); }
.tabbtn { flex: 1; background: none; border: none; color: var(--muted); cursor: pointer; padding: 7px 2px; display: flex; flex-direction: column; align-items: center; gap: 3px; border-radius: 10px; font: inherit; }
.tabbtn:active { background: var(--card-2); }
.tabbtn-ic { font-size: 21px; line-height: 1; filter: grayscale(1); opacity: 0.65; transition: opacity .15s ease; }
.tabbtn-lb { font-size: 10px; font-weight: 700; letter-spacing: .3px; }
.tabbtn.active { color: var(--accent); }
.tabbtn.active .tabbtn-ic { filter: none; opacity: 1; }

.toast { position: fixed; left: 50%; bottom: 84px; transform: translateX(-50%) translateY(20px); background: var(--accent); color: #06241f; padding: 12px 22px; border-radius: 999px; font-weight: 700; font-size: 14px; opacity: 0; pointer-events: none; transition: opacity .25s ease, transform .25s ease; box-shadow: 0 8px 30px rgba(0,0,0,0.4); z-index: 50; max-width: 90vw; text-align: center; }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
