:root {
  --bg: #f4f5f7; --card: #fff; --card2: #eef0f3; --line: #e3e5ea;
  --text: #14161b; --muted: #6b7280; --accent: #f26a00; --accent-text: #fff;
  --accent-soft: rgba(242, 106, 0, .12); --danger: #e5484d; --shadow: 0 1px 2px rgba(0,0,0,.05), 0 4px 16px rgba(0,0,0,.04);
  --r: 16px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115; --card: #181b22; --card2: #222630; --line: #2a2f3a;
    --text: #eceef2; --muted: #8b93a3; --accent: #ff7a1a; --accent-text: #160a00;
    --accent-soft: rgba(255, 122, 26, .14); --danger: #ff5a5f; --shadow: none;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body { font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; overscroll-behavior-y: contain; }
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; padding: 0; }
svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }
[hidden] { display: none !important; }

main {
  max-width: 640px; margin: 0 auto;
  padding: calc(env(safe-area-inset-top) + 8px) 16px calc(env(safe-area-inset-bottom) + 110px);
}

/* Header */
.bar { display: flex; align-items: center; gap: 6px; min-height: 56px; position: sticky; top: 0; z-index: 5;
  background: var(--bg); margin: 0 -16px; padding: env(safe-area-inset-top) 12px 0 16px; }
.bar h1 { flex: 1; margin: 0; font-size: 26px; font-weight: 750; letter-spacing: -.02em; min-width: 0;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar h1.title { font-size: 20px; }
.icon { display: grid; place-items: center; width: 42px; height: 42px; border-radius: 12px; color: var(--text); }
.icon:active { background: var(--card2); }
.pill { display: flex; align-items: center; gap: 6px; height: 36px; padding: 0 14px 0 11px; border-radius: 999px;
  background: var(--accent-soft); color: var(--accent); font-weight: 650; }
.pill svg { width: 18px; height: 18px; }
.pill:active { filter: brightness(.9); }

.toolbar { display: flex; align-items: center; justify-content: space-between; margin: 4px 0 12px; color: var(--muted); font-size: 14px; }
.seg { display: flex; background: var(--card2); border-radius: 12px; padding: 3px; }
.seg button { display: grid; place-items: center; height: 32px; min-width: 44px; padding: 0 10px; border-radius: 9px;
  color: var(--muted); font-size: 13px; font-weight: 700; letter-spacing: .02em; }
.seg button svg { width: 18px; height: 18px; }
.seg button.on { background: var(--card); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.12); }

.section { font-size: 13px; font-weight: 650; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 22px 4px 8px; }
.section.accent { color: var(--accent); }
.section .sub { text-transform: none; letter-spacing: 0; font-weight: 500; opacity: .8; }

/* Exercise cards */
.card { display: block; width: 100%; text-align: left; background: var(--card); border-radius: var(--r); padding: 14px 16px;
  margin-bottom: 10px; box-shadow: var(--shadow); border: 1px solid transparent; transition: transform .1s; }
.card:active { transform: scale(.985); }
.card.plan { border-color: var(--accent); background: linear-gradient(var(--accent-soft), var(--accent-soft)), var(--card); }
.card-top { display: flex; align-items: baseline; gap: 10px; }
.card .name { flex: 1; font-weight: 650; font-size: 17px; }
.card .when { color: var(--muted); font-size: 13px; white-space: nowrap; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.chips:empty { display: none; }
.chip { font-size: 14px; font-weight: 600; font-variant-numeric: tabular-nums; padding: 3px 10px; border-radius: 8px; background: var(--card2); }
.chip.todo { background: none; box-shadow: inset 0 0 0 1.5px var(--accent); color: var(--accent); }

.empty { text-align: center; color: var(--muted); padding: 60px 24px; }
.empty b { display: block; color: var(--text); font-size: 18px; margin-bottom: 6px; }

/* History rows */
.group { background: var(--card); border-radius: var(--r); overflow: hidden; box-shadow: var(--shadow); }
.swipe { position: relative; touch-action: pan-y; }
.swipe + .swipe .row { border-top: 1px solid var(--line); }
.swipe-del { position: absolute; inset: 0 0 0 auto; width: 104px; background: var(--danger); color: #fff; font-weight: 650; }
.row { position: relative; display: flex; align-items: center; gap: 14px; min-height: 58px; padding: 0 16px 0 12px;
  background: var(--card); transition: transform .22s cubic-bezier(.2,.8,.2,1); user-select: none; }
.swipe.open .row { transform: translateX(-104px); }
.swipe:not(.open):not(.drag) .swipe-del { visibility: hidden; }
.check { display: grid; place-items: center; width: 34px; height: 34px; border-radius: 50%; flex: none;
  box-shadow: inset 0 0 0 2px var(--line); color: var(--accent-text); }
.check svg { width: 18px; height: 18px; stroke-width: 3; }
.row.done .check { background: var(--accent); box-shadow: none; }
.row.todo .check { box-shadow: inset 0 0 0 2px var(--accent); }
.val { flex: 1; font-size: 20px; font-weight: 650; font-variant-numeric: tabular-nums; letter-spacing: -.01em; }
.val .x { color: var(--muted); font-weight: 400; margin: 0 4px; }
.hint { font-size: 13px; color: var(--accent); font-weight: 600; }
.row.stale { opacity: .5; }
.row.stale .hint { color: var(--muted); }
.more { display: block; width: 100%; margin-top: 16px; padding: 14px; border-radius: var(--r); background: var(--card2); color: var(--muted); font-weight: 600; }

.fab { position: fixed; right: max(18px, calc(50vw - 302px)); bottom: calc(env(safe-area-inset-bottom) + 20px); z-index: 20;
  display: grid; place-items: center; width: 60px; height: 60px; border-radius: 20px;
  background: var(--accent); color: var(--accent-text); box-shadow: 0 8px 24px rgba(242,106,0,.35); }
.fab svg { width: 28px; height: 28px; stroke-width: 2.5; }
.fab:active { transform: scale(.94); }

/* Bottom sheet */
.sheet-wrap { position: fixed; inset: 0; z-index: 60; }
.backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.45); opacity: 0; transition: opacity .2s; }
.sheet { position: absolute; left: 0; right: 0; bottom: 0; max-width: 640px; margin: 0 auto; max-height: 92vh; overflow-y: auto;
  background: var(--card); border-radius: 22px 22px 0 0; padding: 8px 18px calc(env(safe-area-inset-bottom) + 18px);
  transform: translateY(100%); transition: transform .25s cubic-bezier(.2,.8,.2,1); }
.sheet-wrap.show .backdrop { opacity: 1; }
.sheet-wrap.show .sheet { transform: none; }
.grab { width: 40px; height: 5px; border-radius: 3px; background: var(--line); margin: 0 auto 10px; }
.sheet h3 { margin: 4px 0 16px; font-size: 20px; letter-spacing: -.01em; }
.sheet h3 .sub { display: block; font-size: 14px; color: var(--muted); font-weight: 500; margin-top: 2px; }
.sheet p { color: var(--muted); font-size: 14px; margin: -8px 0 14px; }

.field { display: flex; align-items: center; gap: 12px; min-height: 56px; border-bottom: 1px solid var(--line); }
.field > span { flex: 1; color: var(--muted); }
.field input[type=date] { border: 0; background: var(--card2); border-radius: 10px; padding: 8px 12px; }
.text-input { width: 100%; border: 0; border-radius: 12px; background: var(--card2); padding: 14px; font-size: 17px; outline: none; }
.text-input:focus, textarea:focus { box-shadow: inset 0 0 0 2px var(--accent); }
textarea { width: 100%; border: 0; border-radius: 12px; background: var(--card2); padding: 12px; font-size: 14px;
  font-family: ui-monospace, Menlo, monospace; resize: vertical; outline: none; }

.stepper { display: flex; align-items: center; background: var(--card2); border-radius: 12px; }
.stepper button { width: 44px; height: 44px; font-size: 22px; color: var(--accent); }
.stepper input { width: 64px; text-align: center; border: 0; background: none; font-size: 20px; font-weight: 650;
  font-variant-numeric: tabular-nums; outline: none; }
.bw { height: 44px; padding: 0 12px; border-radius: 12px; background: var(--card2); color: var(--muted); font-weight: 700; }
.wfield { flex-wrap: wrap; padding: 8px 0 12px; }
.stepper.wide { width: 100%; }
.stepper.wide input { flex: 1; }
.stepper.wide button { width: 60px; font-weight: 700; letter-spacing: .08em; }
.bw.on { background: var(--accent-soft); color: var(--accent); }

.switch { display: flex; align-items: center; gap: 12px; min-height: 56px; }
.switch span { flex: 1; }
.switch input { appearance: none; width: 50px; height: 30px; border-radius: 15px; background: var(--line); position: relative; transition: background .2s; margin: 0; }
.switch input::after { content: ""; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%; background: #fff; transition: transform .2s; box-shadow: 0 1px 3px rgba(0,0,0,.3); }
.switch input:checked { background: var(--accent); }
.switch input:checked::after { transform: translateX(20px); }

.actions { display: flex; gap: 10px; margin-top: 18px; }
.primary, .secondary, .danger { flex: 1; height: 52px; border-radius: 14px; font-weight: 650; font-size: 16px; }
.primary { background: var(--accent); color: var(--accent-text); }
.secondary { background: var(--card2); }
.danger { background: none; color: var(--danger); box-shadow: inset 0 0 0 1.5px var(--danger); }
.danger.armed { background: var(--danger); color: #fff; }
.primary:active, .secondary:active, .danger:active { filter: brightness(.92); }
.menu-item { display: flex; align-items: center; gap: 14px; width: 100%; min-height: 54px; text-align: left; border-bottom: 1px solid var(--line); }
.menu-item:last-child { border: 0; }
.small { font-size: 13px; color: var(--muted); }

.preview { margin-top: 14px; }
.prow { padding: 10px 0; border-bottom: 1px solid var(--line); }
.prow .name { font-weight: 650; }
.prow .chips { margin-top: 6px; }
.badge { margin-left: 8px; font-size: 12px; font-weight: 700; color: var(--accent); background: var(--accent-soft); padding: 2px 8px; border-radius: 6px; }
details { margin-top: 10px; color: var(--muted); font-size: 13px; }
details pre { white-space: pre-wrap; font-size: 12px; }

/* Rest timer */
.timer-btn { position: fixed; left: max(18px, calc(50vw - 302px)); bottom: calc(env(safe-area-inset-bottom) + 26px); z-index: 20;
  display: flex; align-items: center; gap: 6px; height: 48px; padding: 0 14px; border-radius: 16px;
  background: var(--card); color: var(--text); box-shadow: 0 4px 18px rgba(0,0,0,.18); font-weight: 700; font-variant-numeric: tabular-nums; }
.timer-btn span:empty { display: none; }
.timer-btn.run { color: var(--accent); }
.timer-btn.over { background: var(--danger); color: #fff; }
.timer { position: fixed; left: 0; right: 0; bottom: 0; z-index: 50; max-width: 640px; margin: 0 auto;
  background: var(--card); border-radius: 24px 24px 0 0; box-shadow: 0 -8px 40px rgba(0,0,0,.3);
  padding: 10px 20px calc(env(safe-area-inset-bottom) + 18px); text-align: center; }
.t-close { position: absolute; right: 12px; top: 10px; width: 40px; height: 40px; display: grid; place-items: center; color: var(--muted); }
.t-time { font-size: 72px; font-weight: 750; letter-spacing: -.03em; font-variant-numeric: tabular-nums; line-height: 1.1; margin-top: 14px; }
.timer.over .t-time { color: var(--danger); }
.timer.run:not(.over) .t-time { color: var(--accent); }
.t-label { color: var(--muted); font-size: 14px; min-height: 20px; }
.t-row { display: flex; gap: 10px; margin-top: 16px; }
.t-step { width: 76px; height: 56px; border-radius: 16px; background: var(--card2); font-weight: 700; font-size: 17px; }
.t-main { flex: 1; height: 56px; border-radius: 16px; background: var(--accent); color: var(--accent-text); font-weight: 700; font-size: 18px; }
.t-stop { margin-top: 10px; height: 44px; width: 100%; border-radius: 14px; color: var(--muted); font-weight: 600; }

.toast { position: fixed; left: 50%; top: calc(env(safe-area-inset-top) + 12px); transform: translateX(-50%); z-index: 70;
  max-width: calc(100% - 32px); width: max-content; background: var(--text); color: var(--bg); padding: 12px 18px; border-radius: 14px;
  font-size: 15px; box-shadow: 0 8px 30px rgba(0,0,0,.25); }

/* Open timer panel: keep the add button and the end of the list above it. */
.timer-open .fab { bottom: calc(var(--timer-h) + 16px); }
.timer-open main { padding-bottom: calc(var(--timer-h) + 100px); }
