:root {
  color-scheme: light dark;
  --bg: #f4f5f7; --card: #ffffff; --text: #16181d; --muted: #6b7280; --line: #e3e5ea;
  --accent: #2f6fed; --accent-text: #ffffff; --good: #1f9d55; --warn: #d97706; --bad: #dc2626;
  --tabbar: #ffffff; --input: #ffffff;
  --sat: env(safe-area-inset-top, 0px); --sab: env(safe-area-inset-bottom, 0px);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111318; --card: #1b1e26; --text: #eef0f4; --muted: #9aa1ad; --line: #2a2e38;
    --accent: #5b8cff; --good: #3fbf7f; --warn: #f5a524; --bad: #f26b6b; --tabbar: #15181f; --input: #12141a;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--text);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", Inter, system-ui, sans-serif;
  -webkit-text-size-adjust: 100%; -webkit-tap-highlight-color: transparent; }
body { min-height: 100dvh; display: flex; flex-direction: column; }
.topbar { position: sticky; top: 0; z-index: 5; display: flex; align-items: baseline; justify-content: space-between;
  padding: calc(var(--sat) + 12px) 16px 10px; background: var(--bg); }
.topbar h1 { margin: 0; font-size: 26px; font-weight: 700; letter-spacing: -0.01em; }
.status { font-size: 12px; color: var(--muted); background: none; border: 0; padding: 4px 0; }
.status.err { color: var(--bad); }
.view { flex: 1; padding: 0 12px calc(var(--sab) + 84px); max-width: 720px; width: 100%; margin: 0 auto; }
.tabs { position: fixed; bottom: 0; left: 0; right: 0; display: flex; background: var(--tabbar);
  border-top: 1px solid var(--line); padding-bottom: var(--sab); z-index: 5; }
.tabs button { flex: 1; background: none; border: 0; padding: 10px 0 8px; color: var(--muted); font-size: 12px; font-weight: 600; }
.tabs button.active { color: var(--accent); }

.card { background: var(--card); border-radius: 14px; padding: 14px; margin: 10px 0; box-shadow: 0 1px 2px rgba(0,0,0,.05); }
.card h2 { margin: 0 0 8px; font-size: 15px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.card h3 { margin: 0 0 6px; font-size: 17px; }
.row { display: flex; gap: 8px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.grow { flex: 1; }
.muted { color: var(--muted); font-size: 14px; }
.small { font-size: 13px; }
.big { font-size: 30px; font-weight: 700; letter-spacing: -0.02em; }
.stat { flex: 1; text-align: center; }
.stat .big { font-size: 24px; }
.stat .muted { font-size: 12px; }
.good { color: var(--good); } .bad { color: var(--bad); } .warn { color: var(--warn); }
.list { margin: 0; padding: 0; list-style: none; }
.list li { padding: 10px 0; border-top: 1px solid var(--line); }
.list li:first-child { border-top: 0; }
.tap { cursor: pointer; }

button, .btn { font: inherit; }
.btn { display: inline-block; border: 0; border-radius: 10px; padding: 10px 14px; background: var(--accent); color: var(--accent-text);
  font-weight: 600; cursor: pointer; }
.btn.secondary { background: var(--line); color: var(--text); }
.btn.danger { background: transparent; color: var(--bad); }
.btn.small { padding: 6px 10px; font-size: 13px; }
.btn.block { width: 100%; padding: 14px; font-size: 17px; }
.btn:disabled { opacity: .5; }
input, select, textarea { font: inherit; color: var(--text); background: var(--input); border: 1px solid var(--line);
  border-radius: 10px; padding: 10px 12px; width: 100%; min-width: 0; }
input[type=number] { text-align: right; }
textarea { min-height: 70px; resize: vertical; }
label.field { display: block; margin: 8px 0; }
label.field > span { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.inline-check { display: inline-flex; align-items: center; gap: 6px; padding: 8px 10px; border: 1px solid var(--line);
  border-radius: 999px; font-size: 13px; }
.inline-check input { width: auto; }

.progress { height: 8px; border-radius: 4px; background: var(--line); overflow: hidden; margin: 8px 0 4px; }
.progress > div { height: 100%; background: var(--accent); border-radius: 4px; transition: width .3s; }
.badge { display: inline-block; font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 999px;
  background: var(--line); color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }

.ex { border-top: 1px solid var(--line); padding: 12px 0; }
.ex:first-of-type { border-top: 0; }
.ex .name { font-weight: 700; display: flex; justify-content: space-between; align-items: center; }
.sets { display: grid; grid-template-columns: 34px 1fr 1fr 40px; gap: 6px; align-items: center; margin-top: 8px; }
.sets .hdr { font-size: 11px; color: var(--muted); text-transform: uppercase; text-align: center; }
.sets .n { text-align: center; color: var(--muted); font-size: 13px; }
.sets input { padding: 10px 8px; }
.sets .done { width: 34px; height: 34px; border-radius: 8px; border: 1px solid var(--line); background: var(--input);
  color: transparent; font-size: 18px; }
.sets .done.on { background: var(--good); border-color: var(--good); color: #fff; }
.hint { font-size: 12px; color: var(--muted); margin-top: 6px; }

.chart { width: 100%; height: auto; display: block; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .line { fill: none; stroke: var(--accent); stroke-width: 2; }
.chart .avg { fill: none; stroke: var(--good); stroke-width: 2; stroke-dasharray: 4 3; }
.chart .dot { fill: var(--accent); }
.chart text { fill: var(--muted); font-size: 10px; }

.chat { display: flex; flex-direction: column; gap: 10px; }
.msg { max-width: 92%; padding: 10px 12px; border-radius: 14px; white-space: pre-wrap; word-wrap: break-word; font-size: 15px; }
.msg.user { align-self: flex-end; background: var(--accent); color: var(--accent-text); border-bottom-right-radius: 4px; }
.msg.assistant { align-self: flex-start; background: var(--card); border-bottom-left-radius: 4px; }
.msg pre, .md pre { background: var(--bg); padding: 8px; border-radius: 8px; overflow-x: auto; font-size: 12px; }
.composer { position: sticky; bottom: calc(var(--sab) + 62px); background: var(--bg); padding: 8px 0; }
.md h1, .md h2, .md h3 { margin: 10px 0 4px; }
.md table { border-collapse: collapse; width: 100%; font-size: 13px; }
.md td, .md th { border-bottom: 1px solid var(--line); padding: 4px 6px; text-align: left; }
.toast { position: fixed; left: 50%; bottom: calc(var(--sab) + 76px); transform: translateX(-50%); background: var(--text);
  color: var(--bg); padding: 10px 16px; border-radius: 999px; font-size: 14px; z-index: 10; max-width: 90vw; }
details summary { cursor: pointer; color: var(--accent); font-weight: 600; }
.setup { max-width: 480px; margin: 0 auto; }
.setup ol { padding-left: 20px; color: var(--muted); font-size: 14px; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px; background: var(--line); padding: 1px 5px; border-radius: 5px; }
.pill { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 12px; background: var(--line); color: var(--muted); }
.pill.ok { color: var(--good); } .pill.err { color: var(--bad); }
