:root {
  --paper: #e9ece2;
  --card: #f6f7f1;
  --ink: #1c2315;
  --muted: #5b6450;
  --drab: #4a5a2c;
  --drab-soft: #d5dbc4;
  --coyote: #8a6d45;
  --line: rgba(28, 35, 21, 0.16);
  --belt: #d6ee3a;
  --belt-ink: #1c2315;
  --done: #4a5a2c;
  --fig: #1c2315;
  --fig-far: #9aa48a;
  --prop: #c9b48a;
  --ground: #9aa18e;
  --cond: "Avenir Next Condensed", "AvenirNextCondensed-Bold", "Arial Narrow", "Roboto Condensed", system-ui, sans-serif;
  --body: -apple-system, system-ui, "Segoe UI", Roboto, sans-serif;
  --tabbar: 58px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --paper: #14180f;
    --card: #1d2316;
    --ink: #e5e8da;
    --muted: #a4ab95;
    --drab: #a3b46f;
    --drab-soft: #2c3521;
    --coyote: #c4a476;
    --line: rgba(229, 232, 218, 0.14);
    --done: #a3b46f;
    --fig: #e5e8da;
    --fig-far: #6c7660;
    --prop: #6e5b3d;
    --ground: #4f5745;
    color-scheme: dark;
  }
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; height: 100%; }
body {
  margin: 0; min-height: 100%;
  background: var(--paper); color: var(--ink);
  font: 16px/1.45 var(--body);
  padding-top: env(safe-area-inset-top, 0px);
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}
button { font: inherit; color: inherit; cursor: pointer; }
:focus-visible { outline: 3px solid var(--drab); outline-offset: 2px; }
svg { display: block; }

.view {
  max-width: 640px; margin: 0 auto;
  padding: 18px 18px calc(var(--tabbar) + env(safe-area-inset-bottom, 0px) + 28px);
  outline: none;
}

h1, h2, h3 { font-family: var(--cond); font-weight: 800; margin: 0; letter-spacing: 0.005em; }
h1 { font-size: 2.1rem; line-height: 1.05; }
h2 { font-size: 1.45rem; line-height: 1.1; }
h3 { font-size: 1.12rem; line-height: 1.2; }
p { margin: 0; }
.muted { color: var(--muted); }
.small { font-size: 0.86rem; }

/* ---------- Today: day header + range card ---------- */
.dayhead { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; margin: 6px 0 14px; }
.daynum { font-family: var(--cond); font-weight: 800; line-height: 0.82; font-size: 5.6rem; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.daynum small { font-size: 1.6rem; color: var(--muted); letter-spacing: 0; margin-left: 4px; }
.dayhead .when { text-align: right; color: var(--muted); font-size: 0.9rem; padding-bottom: 6px; }

.range { display: grid; grid-template-columns: repeat(7, 1fr); gap: 5px; margin-bottom: 22px; }
.range button {
  aspect-ratio: 1; border: 1.5px solid var(--line); background: transparent; border-radius: 4px;
  font: 700 0.78rem/1 var(--cond); color: var(--muted); padding: 0; position: relative;
}
.range button.done { background: var(--done); border-color: var(--done); color: var(--paper); }
.range button.today { border-color: var(--ink); border-width: 2.5px; color: var(--ink); }
.range button.done.today { border-color: var(--ink); }
.range button.rest::after { content: ""; position: absolute; left: 50%; bottom: 4px; width: 4px; height: 4px; border-radius: 50%; background: currentColor; transform: translateX(-50%); opacity: .6; }

/* ---------- Session card ---------- */
.session { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 18px; }
.session-top { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; }
.mins { font-family: var(--cond); font-weight: 800; font-size: 1.45rem; white-space: nowrap; font-variant-numeric: tabular-nums; }
.mins span { font-size: 0.9rem; color: var(--muted); font-weight: 600; }
.session .focus { margin-top: 2px; color: var(--muted); }
.note { margin-top: 12px; padding: 10px 12px; border-left: 3px solid var(--coyote); background: color-mix(in srgb, var(--coyote) 9%, transparent); border-radius: 0 8px 8px 0; font-size: 0.92rem; }

.blocks { list-style: none; margin: 16px 0 0; padding: 0; counter-reset: blk; }
.blocks > li { counter-increment: blk; padding: 12px 0; border-top: 1px solid var(--line); }
.blocks > li > header { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 8px; }
.blocks > li > header h3::before { content: counter(blk) "  "; color: var(--muted); font-variant-numeric: tabular-nums; }
.blocks .detail { color: var(--muted); font-size: 0.85rem; }

.moves-row { display: flex; gap: 8px; overflow-x: auto; scroll-snap-type: x proximity; margin: 0 -18px; padding: 2px 18px 4px; scrollbar-width: none; }
.moves-row::-webkit-scrollbar { display: none; }
.chip { flex: 0 0 104px; scroll-snap-align: start; border: 1px solid var(--line); background: var(--paper); border-radius: 10px; padding: 6px 6px 8px; text-align: left; }
.chip .fx { width: 100%; height: auto; aspect-ratio: 3 / 2; }
.chip span { display: block; font-size: 0.76rem; line-height: 1.2; margin-top: 4px; }

.btn {
  display: flex; align-items: center; justify-content: center; gap: 8px; width: 100%;
  border: 0; border-radius: 12px; min-height: 54px; padding: 0 18px;
  font: 800 1.25rem/1 var(--cond); letter-spacing: 0.01em;
}
.btn-go { background: var(--belt); color: var(--belt-ink); margin-top: 16px; box-shadow: inset 0 -3px 0 rgba(0,0,0,.14); }
.btn-go:active { transform: translateY(1px); box-shadow: none; }
.btn-quiet { background: transparent; border: 1.5px solid var(--line); color: var(--ink); font-size: 1.05rem; min-height: 46px; }
.btn-row { display: flex; gap: 10px; margin-top: 10px; }

/* ---------- Programme list ---------- */
.week { margin-top: 22px; }
.week > header { display: flex; justify-content: space-between; align-items: baseline; border-bottom: 2px solid var(--ink); padding-bottom: 6px; }
.week > p { margin: 8px 0 4px; font-size: 0.9rem; color: var(--muted); }
.dayrow { display: grid; grid-template-columns: 44px 1fr auto; align-items: center; gap: 12px; width: 100%; background: none; border: 0; border-bottom: 1px solid var(--line); padding: 12px 0; text-align: left; }
.dayrow .n { font: 800 1.5rem/1 var(--cond); font-variant-numeric: tabular-nums; color: var(--muted); }
.dayrow.today .n { color: var(--ink); }
.dayrow .t { font-weight: 600; }
.dayrow .s { display: block; font-size: 0.82rem; color: var(--muted); font-weight: 400; }
.tick { width: 26px; height: 26px; border-radius: 50%; border: 1.5px solid var(--line); display: grid; place-items: center; }
.tick.on { background: var(--done); border-color: var(--done); color: var(--paper); }
.tick svg { width: 15px; height: 15px; stroke: currentColor; fill: none; stroke-width: 3; }

/* ---------- Exercise library ---------- */
.cat { margin-top: 24px; }
.cat h2 { margin-bottom: 10px; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 8px 10px 12px; text-align: left; }
.card .fx { width: 100%; height: auto; aspect-ratio: 3 / 2; }
.card b { display: block; font-family: var(--cond); font-size: 1.08rem; margin-top: 4px; }
.card span { display: block; font-size: 0.78rem; color: var(--muted); line-height: 1.3; }

/* Figure styling */
.fx-ground { stroke: var(--ground); stroke-width: 2; }
.fx-prop { fill: var(--prop); }
.fx-near, .fx-body { stroke: var(--fig); stroke-width: 6.5; fill: none; stroke-linecap: round; stroke-linejoin: round; }
.fx-far { stroke: var(--fig-far); stroke-width: 6.5; fill: none; stroke-linecap: round; stroke-linejoin: round; }
.fx-front .fx-far { stroke: var(--fig); }
.fx-head { fill: var(--fig); }

/* ---------- Sheet ---------- */
.sheet { position: fixed; inset: 0; z-index: 30; }
.sheet-scrim { position: absolute; inset: 0; background: rgba(10, 14, 6, 0.45); animation: fade .2s ease; }
.sheet-panel {
  position: absolute; left: 0; right: 0; bottom: 0; max-height: 92%; overflow-y: auto; -webkit-overflow-scrolling: touch;
  background: var(--paper); border-radius: 18px 18px 0 0;
  padding: 10px 18px calc(28px + env(safe-area-inset-bottom, 0px));
  max-width: 640px; margin: 0 auto; animation: rise .26s cubic-bezier(.2,.8,.2,1);
}
.sheet-grip { width: 40px; height: 5px; border-radius: 3px; background: var(--line); margin: 0 auto 8px; }
.sheet-x { position: absolute; right: 12px; top: 12px; }
@keyframes rise { from { transform: translateY(40px); opacity: 0; } }
@keyframes fade { from { opacity: 0; } }

.icon-btn { width: 40px; height: 40px; border-radius: 50%; border: 0; background: color-mix(in srgb, var(--ink) 8%, transparent); display: grid; place-items: center; }
.icon-btn svg { width: 20px; height: 20px; stroke: currentColor; fill: none; stroke-width: 2.2; stroke-linecap: round; }

.ex-hero { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 8px; margin: 34px 0 14px; }
.ex-hero .fx { width: 100%; height: auto; aspect-ratio: 3 / 2; }
.ex-meta { color: var(--muted); margin: 4px 0 14px; }
.cues { margin: 0 0 14px; padding-left: 0; list-style: none; counter-reset: c; }
.cues li { counter-increment: c; position: relative; padding: 0 0 8px 30px; }
.cues li::before { content: counter(c); position: absolute; left: 0; top: 1px; width: 21px; height: 21px; border-radius: 50%; background: var(--drab); color: var(--paper); font: 800 0.8rem/21px var(--cond); text-align: center; }
.scale { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 14px; }
.scale div { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 10px; font-size: 0.88rem; }
.scale b { display: block; font-family: var(--cond); font-size: 1rem; }
.video { display: flex; align-items: center; gap: 12px; text-decoration: none; color: var(--ink); background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; }
.video .play { flex: 0 0 38px; height: 38px; border-radius: 50%; background: #c4302b; display: grid; place-items: center; }
.video .play svg { width: 16px; height: 16px; fill: #fff; }
.video small { display: block; color: var(--muted); }

/* ---------- Progress ---------- */
.form { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 12px; }
.field { display: flex; flex-direction: column; gap: 4px; font-size: 0.85rem; color: var(--muted); }
.field input, .field select {
  font: 600 1.1rem var(--body); color: var(--ink); background: var(--card);
  border: 1.5px solid var(--line); border-radius: 10px; padding: 10px 12px; min-height: 46px; width: 100%;
  -webkit-appearance: none; appearance: none;
}
.field.wide { grid-column: 1 / -1; }
.log { margin-top: 14px; overflow-x: auto; }
.log table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; font-size: 0.9rem; }
.log th, .log td { text-align: right; padding: 8px 6px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.log th:first-child, .log td:first-child { text-align: left; }
.log th { font-weight: 600; color: var(--muted); font-size: 0.78rem; }
.delta { color: var(--drab); font-weight: 700; }
.section { margin-top: 28px; }
.toggle { display: flex; justify-content: space-between; align-items: center; padding: 12px 0; border-bottom: 1px solid var(--line); }
.switch { width: 52px; height: 32px; border-radius: 16px; border: 0; background: var(--line); position: relative; flex: 0 0 auto; }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 26px; height: 26px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.25); transition: transform .18s; }
.switch[aria-checked="true"] { background: var(--drab); }
.switch[aria-checked="true"]::after { transform: translateX(20px); }
.prose p + p { margin-top: 10px; }
.prose { font-size: 0.95rem; }

/* ---------- Tab bar ---------- */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: grid; grid-template-columns: repeat(4, 1fr);
  padding-bottom: env(safe-area-inset-bottom, 0px);
  background: color-mix(in srgb, var(--paper) 88%, transparent);
  -webkit-backdrop-filter: blur(16px); backdrop-filter: blur(16px);
  border-top: 1px solid var(--line);
}
.tabs button { height: var(--tabbar); border: 0; background: none; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; font-size: 0.68rem; color: var(--muted); }
.tabs svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.tabs button[aria-current="page"] { color: var(--ink); }
.tabs button[aria-current="page"] svg { stroke-width: 2.4; }

/* ---------- Player ---------- */
.player {
  position: fixed; inset: 0; z-index: 40; overflow: hidden;
  background: #232b17; color: #eef0e4;
  display: flex; flex-direction: column;
  padding: calc(env(safe-area-inset-top, 0px) + 8px) 18px calc(env(safe-area-inset-bottom, 0px) + 14px);
  --fig: #eef0e4; --fig-far: #6f7b58; --prop: #6b5a3c; --ground: #4f5a3c;
}
.player.is-rest { background: #2d2a1f; }
.p-top { display: flex; align-items: center; justify-content: space-between; gap: 10px; min-height: 44px; }
.p-top .where { font-size: 0.9rem; color: #b9c0a6; text-align: center; flex: 1; }
.p-top .icon-btn { background: rgba(255,255,255,.1); color: #eef0e4; }
.p-bar { height: 4px; background: rgba(255,255,255,.12); border-radius: 2px; overflow: hidden; margin: 6px 0 0; }
.p-bar i { display: block; height: 100%; background: var(--belt); width: 0; transition: width .3s linear; }
.p-stage { flex: 1; display: flex; flex-direction: column; justify-content: center; min-height: 0; }
.p-fig { width: 100%; max-width: 460px; margin: 0 auto; }
.p-fig .fx { width: 100%; height: auto; aspect-ratio: 3 / 2; }
.p-label { text-align: center; margin-top: 4px; }
.p-label .kind { font: 800 1rem/1 var(--cond); color: var(--belt); letter-spacing: 0.02em; }
.player.is-rest .p-label .kind { color: #e9c77e; }
.p-label h2 { font-size: 2.1rem; margin-top: 6px; }
.p-label .sub { color: #b9c0a6; margin-top: 4px; font-size: 0.95rem; min-height: 1.4em; }
.p-clock { position: relative; width: min(42vw, 190px); aspect-ratio: 1; margin: 12px auto 0; }
.p-clock svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.p-clock circle { fill: none; stroke-width: 9; }
.p-clock .trk { stroke: rgba(255,255,255,.1); }
.p-clock .arc { stroke: var(--belt); stroke-linecap: round; transition: stroke-dashoffset .25s linear; }
.player.is-rest .p-clock .arc { stroke: #e9c77e; }
.p-clock .num { position: absolute; inset: 0; display: grid; place-items: center; font: 800 4.2rem/1 var(--cond); font-variant-numeric: tabular-nums; }
.p-next { text-align: center; color: #b9c0a6; font-size: 0.92rem; margin-top: 10px; min-height: 1.4em; }
.p-ctrl { display: grid; grid-template-columns: 1fr 1.4fr 1fr; gap: 12px; align-items: center; margin-top: 12px; }
.p-ctrl button { height: 60px; border-radius: 30px; border: 0; background: rgba(255,255,255,.1); color: #eef0e4; display: grid; place-items: center; }
.p-ctrl .main { background: var(--belt); color: var(--belt-ink); height: 68px; border-radius: 34px; }
.p-ctrl svg { width: 28px; height: 28px; fill: currentColor; }
.p-tips { margin: 10px auto 0; max-width: 460px; font-size: 0.88rem; color: #cfd5bd; text-align: center; min-height: 2.6em; }
.p-done { flex: 1; display: flex; flex-direction: column; justify-content: center; align-items: center; text-align: center; gap: 10px; }
.p-done .big { font: 800 5rem/0.9 var(--cond); color: var(--belt); }
.p-done .btn { max-width: 340px; }

@media (max-height: 700px) {
  .p-label h2 { font-size: 1.7rem; }
  .p-clock { width: min(34vw, 150px); }
  .p-clock .num { font-size: 3.3rem; }
  .p-tips { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
