* { box-sizing: border-box; }
html { color-scheme: dark light; -webkit-text-size-adjust: 100%; }
input, select, textarea { font-size: 16px; } /* 16px stops iPhones zooming into a field */
body {
  margin: 0; background: var(--color-bg); color: var(--color-text);
  font: 400 16px/24px var(--font); -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility;
  -webkit-tap-highlight-color: transparent; overscroll-behavior-y: none;
}
main { max-width: 640px; margin: 0 auto; padding-block: 8px calc(96px + env(safe-area-inset-bottom, 0px)); padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px)); }
h1 { font-size: 30px; line-height: 36px; margin: 8px 0 16px; font-weight: 800; letter-spacing: -.02em; }
h2 { font-size: 19px; line-height: 26px; margin: 28px 0 10px; font-weight: 700; letter-spacing: -.01em; }
p { margin: 0 0 12px; }
.muted { color: var(--color-text-muted); }
.small { font-size: 14px; line-height: 20px; }
a { color: var(--color-accent); }
.num { font-variant-numeric: tabular-nums; }

/* brand bar and tab bar */
#brand { position: sticky; top: 0; z-index: 4; display: flex; align-items: center; gap: 10px; max-width: 640px; margin: 0 auto; padding: calc(10px + env(safe-area-inset-top, 0px)) max(16px, env(safe-area-inset-right, 0px)) 6px max(16px, env(safe-area-inset-left, 0px)); font-weight: 800; font-size: 18px; letter-spacing: -.01em; background: color-mix(in srgb, var(--color-bg) 88%, transparent); -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px); }
#brand[hidden] { display: none; }
#brand > span { flex: 1; }
#menu-btn { min-height: 44px; min-width: 44px; padding: 0; border-radius: 12px; background: transparent; border-color: transparent; color: var(--color-text); }
#menu-btn[hidden] { display: none; }
#menu-btn svg { width: 26px; height: 26px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }
#menu-btn[aria-expanded="true"] { background: var(--color-surface-raised); }
#menu { position: absolute; top: calc(100% - 2px); right: max(12px, env(safe-area-inset-right, 0px)); min-width: 220px; padding: 6px; background: var(--color-surface-raised); border: 1px solid var(--color-border); border-radius: var(--radius-lg); box-shadow: 0 14px 34px rgba(0,0,0,.35); font-size: 16px; font-weight: 600; letter-spacing: 0; }
#menu[hidden] { display: none; }
.menu-item { display: flex; align-items: center; gap: 12px; min-height: 48px; padding: 8px 12px; border-radius: var(--radius-md); color: var(--color-text); text-decoration: none; }
.menu-item:hover, .menu-item:focus-visible { background: var(--color-surface); }
.menu-ico svg { width: 22px; height: 22px; display: block; fill: none; stroke: var(--color-accent); stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
#brand img { border-radius: 8px; display: block; }
nav#tabs {
  position: fixed; left: 0; right: 0; bottom: 0; display: flex; justify-content: center; gap: 2px;
  background: color-mix(in srgb, var(--color-surface) 92%, transparent); -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px); border-top: 1px solid var(--color-border);
  padding: 6px max(8px, env(safe-area-inset-right, 0px)) calc(6px + env(safe-area-inset-bottom, 0px)) max(8px, env(safe-area-inset-left, 0px)); z-index: 5;
}
nav#tabs a { flex: 1; max-width: 120px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; padding: 6px 4px; min-height: 54px; border-radius: var(--radius-md); color: var(--color-text-muted); text-decoration: none; font-size: 12px; line-height: 16px; font-weight: 600; }
nav#tabs svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
nav#tabs a[aria-current="page"] { color: var(--color-text); background: var(--color-surface-raised); }
nav#tabs a[aria-current="page"] svg { stroke: var(--color-accent); }
nav#tabs a[hidden] { display: none; }
nav#tabs[hidden] { display: none; }

/* controls */
button, .btn {
  font: inherit; font-weight: 600; min-height: 44px; padding: 10px 18px; border-radius: var(--radius-md);
  border: 1px solid var(--color-border); background: var(--color-surface-raised); color: var(--color-text);
  cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; justify-content: center; gap: 8px;
}
button:active, .btn:active { opacity: .85; }
button:disabled { opacity: .4; cursor: default; }
.primary { background: var(--color-accent); color: var(--color-on-accent); border-color: transparent; box-shadow: 0 4px 14px color-mix(in srgb, var(--color-accent) 28%, transparent); }
.big { min-height: 56px; font-size: 18px; width: 100%; }
.ghost { background: transparent; border-color: var(--color-border); color: var(--color-accent); }
.danger { color: var(--color-danger); }
:focus-visible { outline: 2px solid var(--color-accent); outline-offset: 2px; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.row.spread { justify-content: space-between; }
.grow { flex: 1; min-width: 0; }
.stack > * + * { margin-top: 12px; }

label { display: block; font-size: 14px; font-weight: 500; margin-bottom: 4px; }
input, select, textarea {
  font: inherit; width: 100%; min-height: 48px; padding: 10px 14px; border-radius: var(--radius-md);
  border: 1px solid var(--color-border-input); background: var(--color-surface); color: var(--color-text);
}
textarea { min-height: 88px; }
input[type="checkbox"], input[type="radio"] { width: 24px; min-height: 24px; height: 24px; accent-color: var(--color-accent); }
.check { display: flex; align-items: center; gap: 10px; padding: 8px 0; font-size: 16px; font-weight: 400; margin: 0; }
.field { margin-bottom: 16px; }
.error { color: var(--color-danger); font-size: 14px; margin-top: 4px; }

/* cards and lists */
.card { background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius-lg); padding: 16px; box-shadow: var(--shadow-card); }
.card + .card { margin-top: 12px; }
a.card { display: block; color: inherit; text-decoration: none; }
.chip { display: inline-flex; align-items: center; min-height: 32px; padding: 2px 12px; border-radius: 999px; border: 1px solid var(--color-border); background: transparent; color: var(--color-text); font-size: 14px; font-weight: 500; }
.chip[aria-pressed="true"] { background: var(--color-accent); color: var(--color-on-accent); border-color: transparent; }
.chips { display: flex; gap: 8px; flex-wrap: wrap; margin: 12px 0; }
.dots { letter-spacing: 3px; color: var(--color-accent); white-space: nowrap; font-size: 12px; }
.dots .off { opacity: .22; }
.empty { text-align: center; padding: 32px 16px; color: var(--color-text-muted); }

/* video */
.video { width: 100%; aspect-ratio: 16 / 9; background: var(--color-surface-raised); border-radius: var(--radius-lg); overflow: hidden; display: flex; align-items: center; justify-content: center; color: var(--color-text-muted); margin-bottom: 12px; }
.video video { width: 100%; height: 100%; object-fit: contain; background: #000; }

/* player */
.player-title { font-size: 28px; line-height: 34px; font-weight: 700; margin: 4px 0; }
.timer { font-size: 72px; line-height: 76px; font-weight: 700; text-align: center; margin: 24px 0; font-variant-numeric: tabular-nums; color: var(--color-accent); }
.progress { height: 6px; background: var(--color-border); border-radius: 3px; overflow: hidden; margin-bottom: 16px; }
.progress > div { height: 100%; background: var(--color-accent); }
.setrow { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.setrow input { font-size: 24px; min-height: 56px; text-align: center; font-variant-numeric: tabular-nums; }

/* calendar and bars */
.cal { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; text-align: center; }
.cal .dow { font-size: 12px; color: var(--color-text-muted); padding: 4px 0; }
.cal button { min-height: 44px; padding: 0; border-radius: var(--radius-sm); background: transparent; border-color: transparent; font-weight: 500; position: relative; }
.cal button[aria-pressed="true"] { background: var(--color-accent); color: var(--color-on-accent); }
.cal button.today { border-color: var(--color-accent); }
.cal button.has::after { content: ''; position: absolute; bottom: 5px; left: 50%; width: 6px; height: 6px; margin-left: -3px; border-radius: 50%; background: var(--color-accent); }
.cal button[aria-pressed="true"].has::after { background: var(--color-on-accent); }
.bars { display: flex; align-items: flex-end; gap: 6px; height: 96px; }
.bars div { flex: 1; background: var(--color-accent); border-radius: 4px 4px 0 0; min-height: 3px; }
.bars-labels { display: flex; gap: 6px; font-size: 12px; color: var(--color-text-muted); }
.bars-labels span { flex: 1; text-align: center; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 8px 4px; border-bottom: 1px solid var(--color-border); }
th { color: var(--color-text-muted); font-weight: 500; }

#toast { position: fixed; left: 16px; right: 16px; bottom: calc(84px + env(safe-area-inset-bottom)); max-width: 608px; margin: 0 auto; background: var(--color-surface-raised); border: 1px solid var(--color-border); padding: 12px 16px; border-radius: var(--radius-md); box-shadow: 0 12px 32px rgba(0,0,0,.5); opacity: 0; pointer-events: none; transition: opacity .2s; z-index: 10; }
#toast.show { opacity: 1; }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

.overlay { position: fixed; inset: 0; background: rgba(0,0,0,.6); display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 20; }
.modal { background: var(--color-surface-raised); border: 1px solid var(--color-border); border-radius: var(--radius-lg); padding: 20px; max-width: 420px; width: 100%; box-shadow: 0 12px 32px rgba(0,0,0,.5); }
textarea.code { font: 12px/16px ui-monospace, Menlo, monospace; min-height: 120px; }
.card.superset { border-left: 4px solid var(--color-accent); }
button.star { background: none; border: 0; font-size: 28px; line-height: 1; min-width: 44px; min-height: 44px; color: var(--color-accent); cursor: pointer; }

/* agenda */
.agenda-day { border-top: 1px solid var(--color-border); padding-top: .5rem; margin-top: .5rem; }
.agenda-day h2 { font-size: 1rem; margin: 0 0 .4rem; text-transform: capitalize; }
.agenda-day.is-today h2 { color: var(--color-accent); }
.agenda-day.drop { outline: 2px dashed var(--color-accent); outline-offset: 2px; }
.agenda-entry { cursor: grab; }
.agenda-entry[data-status="done"] { opacity: .65; }
.agenda-entry[data-status="missed"] strong::before { content: "! "; color: var(--color-danger); }
.agenda-move { max-width: 9.5rem; }

/* statistics */
.linechart { width: 100%; height: auto; color: var(--color-accent); display: block; margin: .5rem 0; }
.hbar { display: grid; grid-template-columns: 6.5rem 1fr 2rem; gap: .5rem; align-items: center; margin: .25rem 0; }
.hbar-track { background: var(--color-surface-raised); border: 1px solid var(--color-border); border-radius: 999px; height: .7rem; overflow: hidden; }
.hbar-track > div { background: var(--color-accent); height: 100%; }

/* offline banner */
#offline { position: sticky; top: 0; z-index: 20; padding: .5rem 1rem; background: var(--color-warning); color: var(--color-bg); font-size: .9rem; text-align: center; }
#offline[hidden] { display: none; }

/* community */
.post-body { white-space: pre-wrap; overflow-wrap: anywhere; margin: 8px 0; }
.comment { padding: 8px 0; border-top: 1px solid var(--color-border); overflow-wrap: anywhere; }
.comment.reply { margin-left: 20px; }
button.link { background: none; border: 0; padding: 4px 0; min-height: 32px; color: var(--color-accent); text-decoration: underline; font: inherit; cursor: pointer; }
a.mention { font-weight: 600; }

/* the person who made it */
.credit { text-align: center; color: var(--color-text-muted); font-size: 13px; margin: 32px 0 8px; }
.credit strong { color: var(--color-text); font-weight: 700; }
.logo-big { display: block; width: 72px; height: 72px; margin: 24px auto 8px; border-radius: 18px; box-shadow: var(--shadow-card); }

/* body weight */
.bw-hero { margin-bottom: 12px; }
.bw-big { font-size: 44px; line-height: 48px; font-weight: 800; letter-spacing: -.02em; margin: 2px 0 12px; }
.bw-stats { display: flex; gap: 20px; flex-wrap: wrap; }
.bw-stats strong { font-size: 18px; }
.bw-form { margin-bottom: 8px; }
.bw-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.bw-item { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 12px 16px; }
.bw-home { display: block; margin: 16px 0; }
.bw-home-kg { font-size: 26px; font-weight: 800; letter-spacing: -.01em; }
.chartbox { background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius-lg); padding: 12px 8px 4px; box-shadow: var(--shadow-card); }
.weightchart { width: 100%; height: auto; display: block; }
.weightchart .grid { stroke: var(--color-border); stroke-width: 1; }
.weightchart .axis { fill: var(--color-text-muted); font-size: 10px; }
.weightchart .raw { fill: none; stroke: var(--color-text-muted); stroke-width: 1; opacity: .5; }
.weightchart .dot { fill: var(--color-text-muted); }
.weightchart .trend { fill: none; stroke: var(--color-accent); stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; }
.weightchart .goal { stroke: var(--color-success); stroke-width: 1.5; stroke-dasharray: 5 4; }
.legend { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; padding: 0 8px; margin: 4px 0 8px; }
.legend .key { display: inline-block; width: 14px; height: 0; border-top: 3px solid var(--color-accent); border-radius: 2px; margin-left: 4px; }
.legend .key.dot { width: 6px; height: 6px; border: 0; border-radius: 50%; background: var(--color-text-muted); }
.legend .key.goal { border-top: 2px dashed var(--color-success); }
.cal { margin-bottom: 16px; }
.bw-item button { min-height: 40px; padding: 6px 12px; font-size: 15px; }

/* music dock: stays on screen above the tab bar while you move around */
#music-dock { position: fixed; left: 8px; right: 8px; bottom: calc(76px + env(safe-area-inset-bottom, 0px)); max-width: 624px; margin: 0 auto; z-index: 6; background: var(--color-surface-raised); border: 1px solid var(--color-border); border-radius: var(--radius-lg); box-shadow: 0 14px 34px rgba(0,0,0,.35); overflow: hidden; }
#music-dock[hidden] { display: none; }
.dock-bar { display: flex; align-items: center; gap: 6px; padding: 6px 8px 6px 14px; }
.dock-title { flex: 1; min-width: 0; font-weight: 700; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dock-btn { min-height: 40px; min-width: 40px; padding: 4px 10px; font-size: 14px; }
.dock-frame iframe { display: block; width: 100%; border: 0; background: var(--color-surface); }
#music-dock.collapsed .dock-frame { height: 1px; overflow: hidden; opacity: 0; pointer-events: none; }
.music-item { display: flex; flex-direction: column; gap: 10px; }
body.docked main { padding-bottom: calc(96px + 220px); }
html { scroll-padding-top: 64px; scroll-padding-bottom: 96px; }
body.no-tabs #music-dock { bottom: calc(10px + env(safe-area-inset-bottom, 0px)); }
body.docked.dock-collapsed main { padding-bottom: 170px; }

.badge-row { background: var(--color-surface); border: 1px solid var(--color-border); border-radius: 12px; padding: .6rem .8rem; display: grid; gap: .35rem; }
#new-badges { border-color: var(--color-accent); }

/* stat tiles: equal columns, centred, big numbers */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(4.4rem, 1fr)); gap: 14px 8px; text-align: center; }
.stats .num { display: block; font-size: 28px; line-height: 1.1; letter-spacing: -.02em; }
/* a heading with a button beside it sits on one baseline */
.row.spread:has(> h2) { align-items: flex-end; margin: 28px 0 10px; }
.row.spread > h2 { margin: 0; }
.favbox { margin: -6px 0 6px; }
.favbox .star { padding: 4px 8px; }
button.star[aria-pressed="true"] { color: #e0a100; }
#bg-hint, #bg-ok { margin: 16px 0 14px; text-align: center; }
/* workout: main action and tools sit at the bottom of the screen, where the thumb is */
.workout-root { display: flex; flex-direction: column; min-height: calc(100dvh - 24px - env(safe-area-inset-bottom, 0px)); }
.workout-root > p:empty { display: none; }
.workout-root > button.primary.big { margin-top: auto; }
.workout-root > .row, .workout-root > div.tools { margin-top: 12px; }
body.no-tabs:not(.docked) main { padding-bottom: calc(16px + env(safe-area-inset-bottom, 0px)); }
.idle { color: var(--color-danger, #b45309); font-weight: 600; }

.dots-step { display: flex; gap: 6px; justify-content: center; margin: 4px 0 8px; }
.dots-step span { width: 8px; height: 8px; border-radius: 99px; background: var(--color-border); }
.dots-step span.on { width: 22px; background: var(--color-accent); }
.welcome-row { display: flex; gap: 14px; align-items: flex-start; }
.welcome-ic { flex: none; width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; background: var(--color-accent); color: var(--color-on-accent, #ffc83d); font-size: 18px; }

/* challenges */
.ch-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; margin: 12px 0; }
.ch-day { min-height: 44px; padding: 0; border-radius: 12px; font-weight: 700; background: var(--color-surface); border: 1px solid var(--color-border); color: var(--color-text); }
.ch-day.done { background: var(--color-accent); color: var(--color-on-accent); border-color: transparent; }
.ch-day.today { outline: 2px solid var(--color-accent); outline-offset: 1px; }
.ch-day.sel { box-shadow: 0 0 0 3px color-mix(in srgb, var(--color-accent) 30%, transparent); }
.ch-row { display: grid; grid-template-columns: 4.2rem 1fr; gap: 6px 10px; align-items: center; }
.ch-row .ch-note { grid-column: 1 / -1; }
.spark { flex: none; stroke: var(--color-accent); fill: var(--color-accent); stroke-width: 2; }
.spark path { fill: none; }
.up { color: #15803d; font-weight: 600; }
.down { color: #b45309; font-weight: 600; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .up { color: #4ade80; } :root:not([data-theme="light"]) .down { color: #fbbf24; } }
