:root {
  --bg: #0e0f12;
  --surface: #17191e;
  --surface-2: #1f232a;
  --surface-3: #2a2f38;
  --border: #2a2f38;
  --text: #f2f4f7;
  --text-2: #c3c9d2;
  --muted: #8b94a1;
  --accent: #c6f432;
  --accent-ink: #12160a;
  --accent-soft: rgba(198, 244, 50, 0.14);
  --chart: #c6f432;
  --grid: #262a31;
  --ok: #3ddc97;
  --warn: #ffb547;
  --danger: #ff5a5f;
  --gif-bg: #ffffff;
  --radius: 16px;
  --radius-sm: 10px;
  --tabbar-h: 64px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  color-scheme: dark;
}

:root[data-theme="light"] {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #eef0f3;
  --surface-3: #e2e5ea;
  --border: #e2e5ea;
  --text: #14171c;
  --text-2: #3b424d;
  --muted: #6b7380;
  --accent: #b5e41f;
  --accent-ink: #12160a;
  --accent-soft: rgba(110, 160, 0, 0.12);
  --chart: #4d7c0f;
  --grid: #e6e8ec;
  --ok: #138a5a;
  --warn: #b26a00;
  --danger: #d6343a;
  color-scheme: light;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }
:root[data-theme="light"] a { color: #4d7c0f; }
img { max-width: 100%; display: block; }
.num, .tabular { font-variant-numeric: tabular-nums; }

#view {
  max-width: 720px;
  margin: 0 auto;
  padding: calc(16px + var(--safe-t)) 16px calc(var(--tabbar-h) + 32px + var(--safe-b));
  outline: none;
  min-height: 100%;
}
body.has-rest #view { padding-bottom: calc(var(--tabbar-h) + 150px + var(--safe-b)); }

/* ---------- tab bar ---------- */
#tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: flex; justify-content: space-around;
  height: calc(var(--tabbar-h) + var(--safe-b));
  padding-bottom: var(--safe-b);
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border-top: 1px solid var(--border);
}
#tabbar a {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  color: var(--muted); text-decoration: none; font-size: 11px; font-weight: 600;
}
#tabbar a svg { width: 24px; height: 24px; }
#tabbar a.on { color: var(--text); }
#tabbar a.on svg { color: var(--accent); }
:root[data-theme="light"] #tabbar a.on svg { color: #4d7c0f; }

/* ---------- headings ---------- */
.top { display: flex; align-items: center; gap: 12px; margin: 4px 0 18px; }
.top h1 { font-size: 26px; line-height: 1.15; margin: 0; flex: 1; letter-spacing: -0.02em; }
.top .sub { color: var(--muted); font-size: 14px; margin-top: 2px; }
.back {
  width: 40px; height: 40px; border-radius: 50%; border: 0; background: var(--surface-2);
  display: grid; place-items: center; cursor: pointer; flex: none;
}
.back svg { width: 22px; height: 22px; }
h2 { font-size: 17px; margin: 26px 0 10px; letter-spacing: -0.01em; }
h3 { font-size: 15px; margin: 0 0 4px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.center { text-align: center; }
.row { display: flex; align-items: center; gap: 10px; }
.row.wrap { flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.stack > * + * { margin-top: 10px; }
.hidden { display: none !important; }

/* ---------- cards ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px;
}
.card + .card { margin-top: 12px; }
.card.hero { background: linear-gradient(140deg, var(--surface-2), var(--surface)); }
.card.accent { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.card.accent .muted { color: rgba(18, 22, 10, 0.7); }
.card.tap { cursor: pointer; }
.card.tap:active { transform: scale(0.99); }

.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 12px; }
.stat b { display: block; font-size: 22px; font-variant-numeric: tabular-nums; letter-spacing: -0.02em; }
.stat span { font-size: 12px; color: var(--muted); }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 46px; padding: 0 18px; border-radius: 999px; border: 1px solid var(--border);
  background: var(--surface-2); font-weight: 650; cursor: pointer; text-decoration: none; color: var(--text);
  white-space: nowrap;
}
.btn svg { width: 18px; height: 18px; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--danger); }
.btn.block { width: 100%; }
.btn.sm { min-height: 36px; padding: 0 14px; font-size: 14px; }
.btn:disabled { opacity: 0.5; cursor: default; }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; }
.btn-row .btn { flex: 1; }
.icon-btn {
  width: 38px; height: 38px; border-radius: 50%; border: 0; background: transparent; color: var(--muted);
  display: inline-grid; place-items: center; cursor: pointer; flex: none;
}
.icon-btn svg { width: 20px; height: 20px; }
.icon-btn:active { background: var(--surface-2); }
.icon-btn.on { color: var(--accent); }

/* ---------- chips ---------- */
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 2px 16px 6px; margin: 0 -16px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; padding: 8px 14px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--border);
  font-size: 14px; font-weight: 600; cursor: pointer; color: var(--text-2); white-space: nowrap;
}
.chip.on { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.tag {
  display: inline-block; padding: 3px 9px; border-radius: 999px; background: var(--surface-2);
  font-size: 12px; font-weight: 600; color: var(--text-2);
}
.tag.accent { background: var(--accent-soft); color: var(--accent); }
:root[data-theme="light"] .tag.accent { color: #4d7c0f; }

/* ---------- forms ---------- */
label.field { display: block; }
label.field > span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; font-weight: 600; }
.input, select.input, textarea.input {
  width: 100%; min-height: 46px; padding: 10px 14px; border-radius: var(--radius-sm);
  background: var(--surface-2); border: 1px solid var(--border); outline: none;
}
textarea.input { min-height: 96px; resize: vertical; }
.input:focus { border-color: var(--accent); }
.search { position: relative; }
.search svg { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); width: 18px; height: 18px; color: var(--muted); }
.search .input { padding-left: 42px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.switch { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 44px; }
.switch input { width: 46px; height: 28px; appearance: none; background: var(--surface-3); border-radius: 999px; position: relative; cursor: pointer; flex: none; }
.switch input::after { content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: #fff; transition: transform .15s; }
.switch input:checked { background: var(--accent); }
.switch input:checked::after { transform: translateX(18px); }

/* ---------- exercise list ---------- */
.ex-list { display: flex; flex-direction: column; gap: 8px; }
.ex-item {
  display: flex; align-items: center; gap: 12px; padding: 8px; padding-right: 12px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm);
  cursor: pointer; text-align: left; width: 100%;
}
.ex-item.sel { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.ex-item .t { flex: 1; min-width: 0; }
.ex-item .t b { display: block; font-size: 15px; line-height: 1.25; }
.ex-item .t small { color: var(--muted); font-size: 12.5px; }
.thumb {
  width: 64px; height: 64px; border-radius: 10px; background: var(--gif-bg); flex: none; overflow: hidden;
  display: grid; place-items: center;
}
.thumb img { width: 100%; height: 100%; object-fit: contain; }
:root[data-theme="light"] .thumb { outline: 1px solid var(--border); outline-offset: -1px; }
.thumb.lg { width: 100%; height: auto; aspect-ratio: 1; max-width: 340px; margin: 0 auto; border-radius: var(--radius); }
.thumb.md { width: 84px; height: 84px; }
.thumb .ph { color: #9aa3af; font-size: 11px; text-align: center; padding: 6px; }
.check {
  width: 26px; height: 26px; border-radius: 50%; border: 2px solid var(--surface-3); flex: none;
  display: grid; place-items: center;
}
.ex-item.sel .check { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.check svg { width: 16px; height: 16px; }
.star { color: var(--warn); }

/* ---------- detail ---------- */
.detail-hero { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; }
.tips { margin: 0; padding: 0; list-style: none; }
.tips li { position: relative; padding: 8px 0 8px 30px; border-bottom: 1px solid var(--border); }
.tips li:last-child { border-bottom: 0; }
.tips li::before {
  content: ""; position: absolute; left: 4px; top: 13px; width: 14px; height: 14px; border-radius: 50%;
  background: var(--accent-soft); box-shadow: inset 0 0 0 4px var(--accent);
}
.tips.bad li::before { background: transparent; box-shadow: inset 0 0 0 2px var(--danger); }
.tips.bad li::after { content: ""; position: absolute; left: 9px; top: 19px; width: 6px; height: 2px; background: var(--danger); }
ol.steps { margin: 0; padding-left: 22px; }
ol.steps li { padding: 5px 0; }

/* ---------- plan edit / session ---------- */
.plan-ex { padding: 12px; }
.plan-ex .head { display: flex; gap: 12px; align-items: center; }
.plan-ex .fields { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-top: 10px; }
.plan-ex .fields label span { font-size: 11px; }
.plan-ex .fields .input { min-height: 40px; padding: 6px 8px; text-align: center; }
.mini-input { min-height: 40px !important; padding: 6px 10px !important; }

.sets { width: 100%; border-collapse: collapse; margin-top: 10px; }
.sets th { font-size: 11px; color: var(--muted); font-weight: 700; text-transform: uppercase; letter-spacing: .04em; padding: 4px 2px; text-align: center; }
.sets td { padding: 3px 2px; text-align: center; }
.sets td.n { width: 34px; font-weight: 700; color: var(--muted); }
.sets td.prev { color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; }
.sets input {
  width: 100%; max-width: 76px; min-height: 40px; text-align: center; border-radius: 8px;
  background: var(--surface-2); border: 1px solid var(--border); font-variant-numeric: tabular-nums; font-weight: 650;
}
.sets input:focus { outline: none; border-color: var(--accent); }
.sets tr.done td { background: var(--accent-soft); }
.sets tr.done td:first-child { border-radius: 8px 0 0 8px; }
.sets tr.done td:last-child { border-radius: 0 8px 8px 0; }
.set-check {
  width: 40px; height: 40px; border-radius: 10px; border: 0; background: var(--surface-2); color: var(--muted);
  display: inline-grid; place-items: center; cursor: pointer;
}
.set-check svg { width: 20px; height: 20px; }
tr.done .set-check { background: var(--accent); color: var(--accent-ink); }

.session-bar {
  position: sticky; top: 0; z-index: 10; margin: -16px -16px 14px; padding: calc(10px + var(--safe-t)) 16px 10px;
  background: color-mix(in srgb, var(--bg) 90%, transparent); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  display: flex; align-items: center; gap: 12px; border-bottom: 1px solid var(--border);
}
.clock { font-size: 22px; font-weight: 750; font-variant-numeric: tabular-nums; letter-spacing: -0.02em; }
.suggest { margin-top: 8px; font-size: 13px; padding: 7px 10px; border-radius: 8px; background: var(--accent-soft); color: var(--text); }

/* ---------- rest timer ---------- */
.rest {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--tabbar-h) + var(--safe-b) + 10px);
  width: min(688px, calc(100% - 24px)); z-index: 25;
  background: var(--surface-2); border: 1px solid var(--surface-3); border-radius: 20px; padding: 12px 14px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, .45);
}
.rest .bar { height: 6px; background: var(--surface-3); border-radius: 99px; overflow: hidden; margin-top: 10px; }
.rest .bar i { display: block; height: 100%; background: var(--accent); border-radius: 99px; transition: width .25s linear; }
.rest .time { font-size: 34px; font-weight: 800; font-variant-numeric: tabular-nums; letter-spacing: -0.03em; line-height: 1; }
.rest.done { border-color: var(--accent); }
.rest.done .time { color: var(--accent); }

/* ---------- recovery / bars ---------- */
.rec { display: grid; grid-template-columns: 96px 1fr 44px; gap: 10px; align-items: center; padding: 5px 0; font-size: 14px; }
.rec .track { height: 8px; background: var(--surface-2); border-radius: 99px; overflow: hidden; }
.rec .track i { display: block; height: 100%; border-radius: 99px; }
.rec .pct { text-align: right; font-variant-numeric: tabular-nums; color: var(--muted); font-size: 13px; }

.week { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; text-align: center; }
.week div { font-size: 11px; color: var(--muted); font-weight: 700; }
.week i {
  display: grid; place-items: center; margin: 6px auto 0; width: 32px; height: 32px; border-radius: 50%;
  background: var(--surface-2); font-style: normal; font-size: 13px; color: var(--text-2);
}
.week i.on { background: var(--accent); color: var(--accent-ink); }
.week i.today { box-shadow: inset 0 0 0 2px var(--accent); }

/* ---------- charts ---------- */
.chart { position: relative; }
.chart svg { width: 100%; height: auto; display: block; overflow: visible; }
.chart .tip {
  position: absolute; pointer-events: none; background: var(--surface-3); color: var(--text); border-radius: 8px;
  padding: 6px 9px; font-size: 12.5px; white-space: nowrap; transform: translate(-50%, -110%); opacity: 0; transition: opacity .12s;
  box-shadow: 0 6px 18px rgba(0, 0, 0, .3);
}
.chart .tip.on { opacity: 1; }
.chart .tip b { font-variant-numeric: tabular-nums; }

/* ---------- sheet / modal ---------- */
.sheet-wrap { position: fixed; inset: 0; z-index: 50; display: flex; align-items: flex-end; justify-content: center; }
.sheet-bg { position: absolute; inset: 0; background: rgba(0, 0, 0, .55); animation: fade .15s; }
.sheet {
  position: relative; width: min(720px, 100%); max-height: 88vh; overflow: auto;
  background: var(--surface); border-radius: 22px 22px 0 0; padding: 10px 16px calc(20px + var(--safe-b));
  animation: up .2s ease-out;
}
.sheet .grab { width: 40px; height: 5px; border-radius: 9px; background: var(--surface-3); margin: 0 auto 12px; }
.sheet h2 { margin-top: 4px; }
.menu-item {
  display: flex; align-items: center; gap: 12px; width: 100%; padding: 14px 6px; background: none; border: 0;
  border-bottom: 1px solid var(--border); text-align: left; cursor: pointer; font-size: 15px;
}
.menu-item:last-child { border-bottom: 0; }
.menu-item svg { width: 20px; height: 20px; color: var(--muted); }
.menu-item.danger { color: var(--danger); }
@keyframes up { from { transform: translateY(40px); opacity: 0; } }
@keyframes fade { from { opacity: 0; } }

#toast {
  position: fixed; left: 50%; top: calc(14px + var(--safe-t)); transform: translate(-50%, -30px); z-index: 60;
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 999px; font-weight: 650; font-size: 14px;
  opacity: 0; pointer-events: none; transition: all .2s; max-width: calc(100% - 32px); text-align: center;
}
#toast.on { opacity: 1; transform: translate(-50%, 0); }

.empty { text-align: center; padding: 36px 16px; color: var(--muted); }
.empty svg { width: 44px; height: 44px; color: var(--surface-3); margin-bottom: 8px; }
.seg { display: flex; background: var(--surface-2); border-radius: 999px; padding: 4px; gap: 4px; margin-bottom: 14px; }
.seg button { flex: 1; border: 0; background: transparent; padding: 9px 6px; border-radius: 999px; font-weight: 650; font-size: 14px; color: var(--muted); cursor: pointer; }
.seg button.on { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgba(0, 0, 0, .2); }
.spinner { width: 22px; height: 22px; border-radius: 50%; border: 3px solid var(--surface-3); border-top-color: var(--accent); animation: spin .8s linear infinite; display: inline-block; vertical-align: middle; }
@keyframes spin { to { transform: rotate(360deg); } }
.ai-text { white-space: pre-wrap; }
.ai-text strong { color: var(--text); }
.logo { display: inline-flex; align-items: center; gap: 8px; font-weight: 800; font-size: 20px; letter-spacing: -0.03em; }
.logo i { width: 30px; height: 30px; border-radius: 9px; background: var(--accent); display: grid; place-items: center; color: var(--accent-ink); }
.logo i svg { width: 20px; height: 20px; }
hr.sep { border: 0; border-top: 1px solid var(--border); margin: 14px 0; }
.pr { display: inline-flex; align-items: center; gap: 4px; font-size: 11px; font-weight: 800; color: var(--accent-ink); background: var(--accent); padding: 2px 7px; border-radius: 99px; }

@media (min-width: 560px) {
  .stats { grid-template-columns: repeat(4, 1fr); }
}
@media (max-width: 380px) {
  .plan-ex .fields { grid-template-columns: repeat(2, 1fr); }
  .rec { grid-template-columns: 82px 1fr 40px; }
}
