:root {
  --bg: #111418;
  --card: #1b2027;
  --line: #2a313b;
  --text: #e8ecf1;
  --muted: #8a94a3;
  --accent: #4f9cf9;
  --good: #4ade80;
  --warn: #fbbf24;
  --bad: #f87171;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", sans-serif;
  padding: env(safe-area-inset-top) 16px calc(76px + env(safe-area-inset-bottom));
}
body.no-scroll { overflow: hidden; }
main { max-width: 560px; margin: 0 auto; padding-bottom: 24px; }
a { color: var(--accent); }
h1 { margin: 0; font-size: 22px; }
h2 { font-size: 22px; margin: 12px 0; }
h3 { font-size: 16px; margin: 0 0 8px; }
p { margin: 6px 0; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.good { color: var(--good); }
.bad { color: var(--bad); }

/* Header */
.top {
  max-width: 560px; margin: 0 auto; padding: 12px 0;
  display: flex; align-items: center; gap: 12px;
}
.top h1 { flex: 1; }
.icon-link { color: var(--muted); text-decoration: none; font-size: 22px; padding: 4px 8px; }
.sync { font-size: 12px; color: var(--warn); border: 1px solid var(--warn); border-radius: 999px; padding: 2px 8px; }

/* Bottom tabs */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: grid; grid-template-columns: repeat(6, 1fr);
  background: #0d1014; border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabs a {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 8px 0; font-size: 11px; color: var(--muted); text-decoration: none; min-height: 56px; justify-content: center;
}
.tabs a span { font-size: 18px; line-height: 1; }
.tabs a.active { color: var(--accent); }
.fab {
  position: fixed; right: 16px; bottom: calc(72px + env(safe-area-inset-bottom)); z-index: 11;
  border-radius: 999px; padding: 12px 20px; background: var(--accent); border-color: var(--accent); color: #fff;
  box-shadow: 0 4px 16px rgba(0,0,0,.4); font-weight: 600;
}

/* Cards and layout */
.card { background: var(--card); border-radius: 12px; padding: 14px 16px; margin: 12px 0; }
.card.banner { border: 1px solid var(--warn); }
.stack { display: flex; flex-direction: column; gap: 10px; }
.stack > .card { margin: 0; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 6px 0; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.grid3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; }
.actions { display: flex; gap: 8px; align-items: center; }
.actions.wrap { flex-wrap: wrap; }
.plain { list-style: none; margin: 0; padding: 0; }
.pill { font-size: 12px; background: var(--accent); color: #fff; border-radius: 999px; padding: 2px 8px; }
.back { display: inline-block; margin-top: 8px; text-decoration: none; }
details.subtle > summary { color: var(--muted); cursor: pointer; padding: 8px 0; }

/* Forms */
.field { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
input, select, textarea {
  font: inherit; font-size: 16px; color: var(--text); background: #12161b;
  border: 1px solid var(--line); border-radius: 10px; padding: 10px; min-height: 44px; width: 100%;
}
textarea { resize: vertical; }
input[type="checkbox"] { width: auto; min-height: 0; }
button, .button {
  font: inherit; border-radius: 10px; border: 1px solid var(--line); background: var(--card); color: var(--text);
  padding: 10px 16px; min-height: 44px; display: inline-flex; align-items: center; justify-content: center;
  text-decoration: none; cursor: pointer;
}
button.primary, .button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.danger { color: var(--bad); }
button.ghost { background: transparent; border-color: transparent; color: var(--muted); }
button.small, .button.small { padding: 6px 12px; min-height: 36px; font-size: 14px; }
button.done { color: var(--good); }
button.selected { background: var(--accent); border-color: var(--accent); color: #fff; }
button:disabled { opacity: .5; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); border-radius: 999px; padding: 6px 10px; color: var(--text); font-size: 14px; }
.scale { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; }

/* Workout logger */
.exercise .last { margin: 4px 0; }
.sets { margin: 6px 0; padding-left: 22px; }
.sets li { display: flex; justify-content: space-between; align-items: center; }
.sets li.warmup { color: var(--muted); }
.set-entry { display: grid; grid-template-columns: 1fr auto 1fr 0.8fr auto auto; gap: 6px; align-items: center; }
.set-entry input { padding: 8px; text-align: center; }
.warm { display: flex; align-items: center; gap: 2px; font-size: 13px; color: var(--muted); }
.rest-timer {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(72px + env(safe-area-inset-bottom)); z-index: 12;
  background: #0d1014; border: 1px solid var(--accent); border-radius: 999px; padding: 10px 20px; font-variant-numeric: tabular-nums;
}
.rest-timer.done { border-color: var(--good); color: var(--good); }

/* Plan */
.schedule { list-style: none; margin: 0; padding: 0; }
.schedule li { display: grid; grid-template-columns: 100px 1fr auto auto; gap: 8px; align-items: center; padding: 6px 0; border-bottom: 1px solid var(--line); }
.schedule li.done { color: var(--muted); }
.schedule .date { color: var(--muted); font-size: 14px; }
.plan-ex { border-bottom: 1px solid var(--line); padding: 6px 0; }
.cycle { margin: 0; padding-left: 22px; }
.cycle li { display: flex; justify-content: space-between; align-items: center; min-height: 40px; }
.cycle li.next { font-weight: 600; }
p.pill { display: inline-block; }
.targets { display: grid; grid-template-columns: 1fr auto 1fr auto 1fr auto 0.8fr auto 1fr; gap: 4px; align-items: center; font-size: 12px; color: var(--muted); }
.targets input { padding: 6px 2px; min-height: 36px; text-align: center; font-size: 15px; }

/* Supplements */
.supp.low { border: 1px solid var(--warn); }
.thumb { width: 48px; height: 48px; object-fit: contain; border-radius: 8px; background: #fff; }

/* Picker */
.pick-list { display: flex; flex-direction: column; gap: 4px; max-height: 50vh; overflow-y: auto; }
.pick-item { flex-direction: column; align-items: flex-start; text-align: left; }
.pick-item.new { color: var(--accent); }

/* Stats */
.chart { width: 100%; height: auto; display: block; }
.chart-line { fill: none; stroke: var(--accent); stroke-width: 2.5; }
.chart-raw { fill: none; stroke: var(--muted); stroke-width: 1; opacity: .6; }
.chart-label, .chart-empty { fill: var(--muted); font-size: 11px; }
.bars { display: flex; flex-direction: column; gap: 4px; }
.bar-row { display: grid; grid-template-columns: 90px 1fr 32px; gap: 8px; align-items: center; font-size: 13px; }
.bar { height: 8px; background: var(--line); border-radius: 4px; overflow: hidden; }
.bar > span { display: block; height: 100%; background: var(--accent); }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table th, .table td { text-align: left; padding: 6px 4px; border-bottom: 1px solid var(--line); }
.table th { color: var(--muted); font-weight: 500; }

/* Backups */
.backup-row { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 8px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.pill.subtle { background: var(--line); color: var(--text); margin-left: 8px; }

/* Sheet + toast */
.sheet-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.55); z-index: 20; display: flex; align-items: flex-end; justify-content: center; }
.sheet {
  background: var(--bg); width: 100%; max-width: 560px; max-height: 90vh; overflow-y: auto;
  border-radius: 16px 16px 0 0; padding: 12px 16px calc(16px + env(safe-area-inset-bottom));
}
.sheet-head { display: flex; justify-content: space-between; align-items: center; }
.toast {
  position: fixed; left: 50%; top: calc(12px + env(safe-area-inset-top)); transform: translate(-50%, -150%); z-index: 30;
  background: #0d1014; border: 1px solid var(--line); border-radius: 10px; padding: 10px 16px; transition: transform .2s;
}
.toast.show { transform: translate(-50%, 0); }

/* Chat (API mode) */
.chat { display: flex; flex-direction: column; gap: 8px; }
.bubble { max-width: 85%; padding: 10px 12px; border-radius: 14px; white-space: pre-wrap; word-wrap: break-word; }
.bubble.user { align-self: flex-end; background: var(--accent); color: #fff; }
.bubble.assistant { align-self: flex-start; background: var(--card); }
.bubble.thinking { color: var(--muted); font-style: italic; }
.bubble.error { color: var(--bad); }
.cost { font-size: 11px; color: var(--muted); margin-top: 4px; text-align: right; }
.proposal { border: 1px solid var(--accent); }
