:root {
  --bg: #12211B;
  --surface: #1B3027;
  --surface-2: #223a2f;
  --line: #2B463A;
  --text: #EAE8E0;
  --muted: #9FB19B;
  --resin: #E6A93F;
  --resin-ink: #1A1206;
  --ring-empty: #2E4A3D;
  --danger: #E07A5F;
  --radius-lg: 20px;
  --radius-sm: 10px;
  --display: "Big Shoulders Display", "Arial Narrow", "Roboto Condensed", Impact, sans-serif;
  --body: "Atkinson Hyperlegible", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: dark;
  box-sizing: border-box;
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg: #E9EDE6;
    --surface: #F7F8F4;
    --surface-2: #EEF2EB;
    --line: #CCD5C8;
    --text: #16271F;
    --muted: #52665A;
    --resin: #B7761A;
    --resin-ink: #FFFFFF;
    --ring-empty: #D3DBCF;
    --danger: #B4462B;
    color-scheme: light;
  }
}
*, *::before, *::after { box-sizing: inherit; }
html { scroll-padding-top: env(safe-area-inset-top, 0px); -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--body);
  font-size: 1rem;
  line-height: 1.5;
  -webkit-tap-highlight-color: transparent;
}
button { font: inherit; color: inherit; cursor: pointer; }
input, select { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--resin); outline-offset: 2px; }
[hidden] { display: none !important; }

.app {
  max-width: 560px;
  margin: 0 auto;
  padding: 0 1rem calc(96px + env(safe-area-inset-bottom, 0px));
}

/* Top bar */
.topbar {
  display: flex; align-items: center; gap: .75rem;
  padding: 1rem 0 .5rem;
}
.brand { display: flex; align-items: center; gap: .5rem; font-family: var(--display); font-weight: 800; font-size: 1.5rem; letter-spacing: .01em; }
.brand-mark { width: 26px; height: 26px; color: var(--resin); }
.today-date { margin-left: auto; color: var(--muted); font-size: .9rem; }
.btn-install {
  margin-left: auto; border: 1px solid var(--resin); color: var(--resin); background: transparent;
  border-radius: 999px; padding: .35rem .8rem; font-size: .85rem; font-weight: 700;
}
.btn-install + .today-date { margin-left: 0; }

/* Session picker */
.sessions {
  display: flex; gap: .5rem; overflow-x: auto; scrollbar-width: none;
  margin: .25rem -1rem 0; padding: .25rem 1rem .75rem;
  scroll-snap-type: x proximity;
}
.sessions::-webkit-scrollbar { display: none; }
.chip {
  flex: 0 0 auto; scroll-snap-align: start;
  border: 1px solid var(--line); background: var(--surface);
  border-radius: 14px; padding: .55rem .8rem; text-align: left; min-width: 128px;
}
.chip b { display: block; font-size: .95rem; }
.chip small { color: var(--muted); font-size: .8rem; }
.chip.is-active { border-color: var(--resin); background: var(--surface-2); box-shadow: inset 0 0 0 1px var(--resin); }
.chip .suggest { color: var(--resin); }

/* Hero with growth rings */
.hero {
  display: grid; grid-template-columns: minmax(0, 1fr) 150px; gap: 1rem; align-items: center;
  padding: .5rem 0 1rem;
}
.hero h1 {
  font-family: var(--display); font-weight: 800; font-size: clamp(2.3rem, 11vw, 3.2rem);
  line-height: .95; margin: 0 0 .5rem; letter-spacing: .005em;
}
.hero p { margin: 0; color: var(--muted); max-width: 32ch; }
.hero .place { color: var(--text); font-weight: 700; }
.rings { width: 150px; height: 150px; }
.rings circle { fill: none; stroke-linecap: butt; transition: stroke .3s ease; }
.rings .seg-empty { stroke: var(--ring-empty); }
.rings .seg-done { stroke: var(--resin); }
.rings .seg-next { stroke: var(--muted); opacity: .55; }
.rings .pith { fill: var(--resin); stroke: none; }
.rings text { fill: var(--text); font-family: var(--display); font-weight: 800; }
.rings .sub { fill: var(--muted); font-family: var(--body); font-weight: 400; }
.rings-pop { animation: pop .45s ease; transform-origin: center; transform-box: fill-box; }
@keyframes pop { 0% { transform: scale(1); } 40% { transform: scale(1.04); } 100% { transform: scale(1); } }

/* Toolbar */
.toolbar { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; margin-bottom: .75rem; }
.seg {
  display: inline-flex; border: 1px solid var(--line); border-radius: 999px; padding: 3px; background: var(--surface);
}
.seg button { border: 0; background: transparent; padding: .35rem .8rem; border-radius: 999px; font-size: .9rem; color: var(--muted); }
.seg button.is-on { background: var(--resin); color: var(--resin-ink); font-weight: 700; }
.btn-ghost {
  border: 1px solid var(--line); background: var(--surface); border-radius: 999px;
  padding: .45rem .9rem; font-size: .9rem; display: inline-flex; align-items: center; gap: .4rem;
}
.btn-ghost svg { width: 16px; height: 16px; stroke: currentColor; fill: none; stroke-width: 2; }
.btn-solid {
  border: 0; background: var(--resin); color: var(--resin-ink); border-radius: 999px;
  padding: .55rem 1.1rem; font-weight: 700;
}
.btn-block { display: block; width: 100%; padding: .9rem; font-size: 1.05rem; border-radius: 16px; }
.btn-danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 45%, var(--line)); }

/* Exercise list */
.list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: .6rem; }
.ex {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg);
  padding: .9rem .9rem .8rem;
}
.ex.is-complete { opacity: .72; }
.ex.is-complete .ex-name { text-decoration: line-through; text-decoration-color: var(--resin); text-decoration-thickness: 2px; }
.ex-head { display: flex; gap: .75rem; align-items: flex-start; }
.ex-main { flex: 1; min-width: 0; }
.ex-cat { color: var(--muted); font-size: .8rem; }
.ex-name { font-weight: 700; font-size: 1.08rem; line-height: 1.25; margin: .1rem 0 .15rem; }
.ex-dose { font-family: var(--display); font-weight: 600; font-size: 1.15rem; letter-spacing: .01em; }
.ex-tools { display: flex; gap: .25rem; }
.icon-btn {
  width: 38px; height: 38px; border-radius: 12px; border: 1px solid var(--line); background: transparent;
  display: grid; place-items: center;
}
.icon-btn svg { width: 18px; height: 18px; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.icon-btn[aria-expanded="true"] { background: var(--surface-2); border-color: var(--muted); }
.ex-how { margin: .6rem 0 0; color: var(--muted); font-size: .95rem; max-width: 60ch; }
.pips { display: flex; flex-wrap: wrap; gap: .45rem; margin-top: .75rem; }
.pip {
  min-width: 44px; height: 44px; padding: 0 .5rem; border-radius: 50%;
  border: 2px solid var(--ring-empty); background: transparent;
  font-family: var(--display); font-weight: 800; font-size: 1.05rem; color: var(--muted);
  transition: background .15s ease, border-color .15s ease, transform .1s ease;
}
.pip:active { transform: scale(.94); }
.pip.is-done { background: var(--resin); border-color: var(--resin); color: var(--resin-ink); }

.finish { margin-top: 1rem; }
.saved {
  border: 1px dashed var(--resin); border-radius: var(--radius-lg); padding: 1rem; margin-bottom: 1rem;
}
.saved h2 { font-family: var(--display); font-weight: 800; font-size: 1.6rem; margin: 0 0 .25rem; }
.saved p { margin: 0 0 .75rem; color: var(--muted); }

/* Timer */
.timer {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(72px + env(safe-area-inset-bottom, 0px));
  width: min(560px, calc(100% - 1.5rem));
  background: var(--surface-2); border: 1px solid var(--resin); border-radius: 18px;
  overflow: hidden; z-index: 20;
  box-shadow: 0 10px 30px -12px rgba(0, 0, 0, .55);
}
.timer-body { display: flex; align-items: center; gap: .75rem; padding: .7rem .9rem; }
.timer-label { color: var(--muted); font-size: .8rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.timer-time { font-family: var(--display); font-weight: 800; font-size: 2.1rem; line-height: 1; font-variant-numeric: tabular-nums; }
.timer-actions { margin-left: auto; display: flex; gap: .35rem; }
.timer-actions button { white-space: nowrap; }
.timer-actions .btn-ghost { padding: .45rem .6rem; font-size: .85rem; }
.timer-actions .btn-solid { padding: .45rem .8rem; font-size: .9rem; }
.timer-bar { height: 4px; background: var(--ring-empty); }
.timer-bar span { display: block; height: 100%; background: var(--resin); width: 0; transition: width .25s linear; }
.timer.is-over { border-color: var(--text); }

/* Tab bar */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: flex; justify-content: center; gap: 0;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
  padding: .35rem .5rem calc(.35rem + env(safe-area-inset-bottom, 0px));
}
.tab {
  flex: 1; max-width: 180px; border: 0; background: transparent; color: var(--muted);
  display: flex; flex-direction: column; align-items: center; gap: .15rem; font-size: .78rem; padding: .35rem 0;
}
.tab svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }
.tab svg .fill { fill: currentColor; stroke: none; }
.tab.is-active { color: var(--resin); font-weight: 700; }

/* Section headings */
.h2 { font-family: var(--display); font-weight: 800; font-size: 1.9rem; line-height: 1; margin: 1rem 0 .75rem; }
.h3 { font-weight: 700; font-size: 1.05rem; margin: 1.5rem 0 .5rem; }
.note { color: var(--muted); font-size: .92rem; margin: 0 0 .75rem; max-width: 60ch; }

/* Library */
.search {
  width: 100%; border: 1px solid var(--line); background: var(--surface); border-radius: 14px;
  padding: .7rem .9rem; margin-bottom: .6rem;
}
.filters { display: flex; gap: .4rem; overflow-x: auto; scrollbar-width: none; margin: 0 -1rem .75rem; padding: 0 1rem; }
.filters::-webkit-scrollbar { display: none; }
.filter {
  flex: 0 0 auto; border: 1px solid var(--line); background: transparent; border-radius: 999px;
  padding: .35rem .75rem; font-size: .88rem; color: var(--muted);
}
.filter.is-on { border-color: var(--resin); color: var(--text); background: var(--surface-2); }
.lib-meta { color: var(--muted); font-size: .85rem; margin-top: .15rem; }
.switch { display: flex; align-items: center; gap: .6rem; margin-top: .6rem; font-size: .9rem; color: var(--muted); }
.switch input { width: 20px; height: 20px; accent-color: var(--resin); }

/* Progress */
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: .5rem; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: .75rem; }
.stat b { display: block; font-family: var(--display); font-weight: 800; font-size: 2rem; line-height: 1; }
.stat span { color: var(--muted); font-size: .82rem; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg); padding: 1rem; }
.weight-row { display: flex; gap: .5rem; align-items: stretch; }
.weight-row input {
  flex: 1; min-width: 0; border: 1px solid var(--line); background: var(--bg); border-radius: 12px; padding: .6rem .8rem;
}
.weight-now { display: flex; align-items: baseline; gap: .5rem; margin-bottom: .5rem; flex-wrap: wrap; }
.weight-now b { font-family: var(--display); font-weight: 800; font-size: 2.4rem; line-height: 1; }
.weight-now span { color: var(--muted); }
.spark { width: 100%; height: 110px; display: block; margin: .5rem 0 .75rem; }
.spark .line { fill: none; stroke: var(--resin); stroke-width: 2.5; stroke-linejoin: round; stroke-linecap: round; }
.spark .goal { stroke: var(--muted); stroke-dasharray: 4 5; stroke-width: 1.5; }
.spark .dot { fill: var(--resin); }
.spark text { fill: var(--muted); font-size: 11px; font-family: var(--body); }
.hist { list-style: none; margin: 0; padding: 0; }
.hist li { display: flex; gap: .75rem; align-items: center; padding: .7rem 0; border-bottom: 1px solid var(--line); }
.hist li:last-child { border-bottom: 0; }
.hist .when { color: var(--muted); font-size: .85rem; width: 4.5rem; flex: 0 0 auto; }
.hist .what { flex: 1; min-width: 0; }
.hist .what b { display: block; }
.hist .what span { color: var(--muted); font-size: .85rem; }
.hist .del { width: 32px; height: 32px; }
.field { display: flex; flex-direction: column; gap: .35rem; margin-bottom: .9rem; }
.field label { font-weight: 700; font-size: .95rem; }
.field select { border: 1px solid var(--line); background: var(--bg); border-radius: 12px; padding: .6rem .8rem; }
.row-actions { display: flex; gap: .5rem; flex-wrap: wrap; }
.empty { color: var(--muted); padding: .5rem 0; }

/* Toast */
.toast {
  position: fixed; left: 50%; top: calc(12px + env(safe-area-inset-top, 0px)); transform: translate(-50%, -150%);
  background: var(--text); color: var(--bg); padding: .6rem 1.1rem; border-radius: 16px; font-weight: 700; font-size: .9rem; text-align: center;
  transition: transform .25s ease, visibility 0s linear .25s; z-index: 40; pointer-events: none; max-width: calc(100% - 2rem);
  visibility: hidden;
}
.toast.is-on { transform: translate(-50%, 0); visibility: visible; transition: transform .25s ease; }

@media (max-width: 380px) {
  .hero { grid-template-columns: minmax(0, 1fr) 118px; }
  .rings { width: 118px; height: 118px; }
  .timer-actions .btn-ghost:first-child { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
}
