:root {
  --bg: #f4f6f5;
  --surface: #ffffff;
  --text: #16201d;
  --muted: #6b756f;
  --accent: #0f6e56;
  --accent-soft: color-mix(in srgb, var(--accent) 14%, transparent);
  --border: #e4e8e6;
  --danger: #b3261e;
  --radius: 14px;
  --maxw: 560px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1413; --surface: #19211e; --text: #e8ece9; --muted: #97a39d;
    --border: #283330;
  }
}
* { box-sizing: border-box; }
[x-cloak] { display: none !important; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg); color: var(--text);
  -webkit-font-smoothing: antialiased; font-size: 16px; line-height: 1.5;
}
.loading { padding: 30vh 1rem; text-align: center; color: var(--muted); }

.shell { max-width: var(--maxw); margin: 0 auto; min-height: 100vh; padding-bottom: 76px; }
.content { padding: 0 1rem; }
h1 { font-size: 1.6rem; margin: 1rem 0 0.75rem; }
h2 { font-size: 1.1rem; margin: 0 0 0.5rem; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.row-between { display: flex; align-items: center; justify-content: space-between; }

.topbar {
  position: sticky; top: 0; z-index: 5; background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  padding: max(env(safe-area-inset-top), 0.6rem) 1rem 0.6rem;
}
.brand { font-weight: 700; color: var(--accent); letter-spacing: -0.02em; display: flex; align-items: center; gap: 6px; }
.logo-mark { width: 26px; height: 26px; color: var(--accent); flex: none; }
.logo-mark.big { width: 84px; height: 84px; }
.who { display: flex; align-items: center; gap: 7px; background: var(--bg); border: 0; border-radius: 999px; padding: 4px 12px 4px 4px; color: var(--text); font-size: 0.85rem; font-weight: 600; }
.avatar { display: inline-flex; align-items: center; justify-content: center; border-radius: 50%; background: var(--accent); color: #fff; font-weight: 700; overflow: hidden; }
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.avatar.sm { width: 28px; height: 28px; font-size: 0.8rem; }
.avatar.lg { width: 76px; height: 76px; font-size: 1.8rem; }

/* gate */
.gate { max-width: var(--maxw); margin: 0 auto; min-height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 0.5rem; padding: 1.5rem; text-align: center; }
.wordmark { font-size: 1.8rem; font-weight: 700; color: var(--accent); letter-spacing: -0.02em; }
.gate-cards { display: flex; gap: 1rem; margin-top: 1.5rem; flex-wrap: wrap; justify-content: center; }
.gate-card { display: flex; flex-direction: column; align-items: center; gap: 0.6rem; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.4rem 1.8rem; cursor: pointer; }
.gate-card:active { transform: scale(0.97); }
.gate-name { font-weight: 600; font-size: 1.1rem; color: var(--text); }

.install-hint {
  background: var(--accent-soft); color: var(--accent); font-size: 0.85rem;
  padding: 0.6rem 1rem; display: flex; gap: 0.5rem; align-items: center; justify-content: space-between;
}

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem; margin: 0.75rem 0; }
.card.empty { text-align: center; }
.today-card h2 { font-size: 1.4rem; margin: 0.25rem 0; }
.big-stat { font-size: 2.2rem; font-weight: 700; color: var(--accent); }
.big-stat .unit { font-size: 1rem; color: var(--muted); font-weight: 400; }

.btn { border: 0; border-radius: 10px; padding: 0.7rem 1rem; font-size: 1rem; font-weight: 600; cursor: pointer; background: var(--bg); color: var(--text); }
.btn.primary { background: var(--accent); color: #fff; }
.btn.outline { background: transparent; border: 1px solid var(--accent); color: var(--accent); width: 100%; margin: 0.35rem 0; }
.btn.ghost { background: var(--accent-soft); color: var(--accent); }
.btn.big { width: 100%; padding: 0.9rem; margin-top: 0.75rem; font-size: 1.05rem; }
.btn:disabled { opacity: 0.55; }
.link { background: none; border: 0; color: var(--accent); font-size: 0.9rem; cursor: pointer; padding: 4px; }
.btn.file { display: inline-block; text-align: center; }

.quick { display: flex; gap: 0.5rem; margin-top: 0.75rem; }
.quick .btn { flex: 1; }
.freq-row, .chips, .ex-actions { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.freq-row .btn { width: auto; flex: 1 1 auto; }

.progress-row { margin-top: 0.4rem; font-size: 0.9rem; color: var(--muted); }
.bar { height: 8px; background: var(--bg); border-radius: 999px; margin-top: 0.35rem; overflow: hidden; }
.bar-fill { height: 100%; background: var(--accent); }

label { display: block; font-size: 0.85rem; color: var(--muted); margin: 0.6rem 0 0; }
input, select { width: 100%; padding: 0.65rem; border: 1px solid var(--border); border-radius: 10px; background: var(--surface); color: var(--text); font-size: 1rem; margin-top: 0.25rem; }

.exercise .ex-name { font-weight: 600; font-size: 1.05rem; }
.sets { width: 100%; border-collapse: collapse; margin-top: 0.6rem; }
.sets th { text-align: left; font-size: 0.75rem; color: var(--muted); font-weight: 500; padding-bottom: 4px; }
.sets td { padding: 3px 4px 3px 0; }
.sets .cell { width: 100%; padding: 0.5rem; margin: 0; text-align: center; }
.sets .donerow .cell { background: var(--accent-soft); }
.check { width: 44px; height: 40px; border-radius: 10px; border: 1px solid var(--accent); background: transparent; color: var(--accent); font-size: 1.2rem; }
.check.on { background: var(--accent); color: #fff; }
.chip { border: 1px solid var(--border); background: var(--surface); color: var(--text); border-radius: 999px; padding: 0.4rem 0.7rem; font-size: 0.8rem; }
.chip.on { background: var(--accent); color: #fff; border-color: var(--accent); }
.notes { background: var(--accent-soft); padding: 0.6rem; border-radius: 10px; font-size: 0.9rem; margin-top: 0.5rem; }
.rest-banner { position: sticky; top: 56px; z-index: 4; background: var(--accent); color: #fff; padding: 0.5rem 1rem; border-radius: 10px; display: flex; gap: 0.5rem; align-items: center; }
.rest-banner .link { color: #fff; text-decoration: underline; }
.sticky-finish { position: sticky; bottom: 84px; }

.macros { display: flex; justify-content: space-around; text-align: center; }
.macro .mv { font-weight: 700; font-size: 1.2rem; }
.macro .ml { font-size: 0.75rem; color: var(--muted); }
.macro.hi .mv { color: var(--accent); }
.macro-inputs { display: grid; grid-template-columns: 1fr 1fr; gap: 0.5rem; }
.food-results { margin-top: 0.5rem; max-height: 320px; overflow-y: auto; border: 1px solid var(--border); border-radius: 10px; }
.food-row { display: flex; flex-direction: column; align-items: flex-start; gap: 1px; width: 100%; text-align: left; background: transparent; border: 0; border-bottom: 1px solid var(--border); padding: 0.6rem 0.7rem; color: var(--text); }
.food-row:last-child { border-bottom: 0; }
.food-row:active { background: var(--accent-soft); }
.food-name { font-weight: 600; }
.food-meta { font-size: 0.78rem; color: var(--muted); }
.ing-row { display: flex; flex-direction: column; gap: 0.35rem; padding: 0.5rem 0; border-bottom: 1px solid var(--border); }
.ing-top { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; }
.ing-name { font-size: 0.92rem; font-weight: 600; }
.ing-controls { display: flex; align-items: center; gap: 0.5rem; }
.ing-grams { display: flex; align-items: center; gap: 4px; color: var(--muted); font-size: 0.85rem; }
.ing-grams .cell { width: 64px; padding: 0.4rem; margin: 0; }
.cook-select { flex: 1; margin: 0; padding: 0.4rem; font-size: 0.85rem; }
.recipe-totals { display: flex; flex-direction: column; gap: 0.4rem; background: var(--accent-soft); border-radius: 10px; padding: 0.7rem; margin-top: 0.7rem; }

.line { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; padding: 0.5rem 0; border-bottom: 1px solid var(--border); }
.line:last-child { border-bottom: 0; }
.line-actions { display: flex; gap: 0.25rem; }
.badge { background: var(--accent-soft); color: var(--accent); border-radius: 999px; padding: 1px 8px; font-size: 0.72rem; margin-left: 4px; }

.coach-view { display: flex; flex-direction: column; }
.chat { display: flex; flex-direction: column; gap: 0.6rem; padding: 0.5rem 0; min-height: 40vh; }
.msg { display: flex; }
.msg.user { justify-content: flex-end; }
.bubble { max-width: 85%; padding: 0.6rem 0.8rem; border-radius: 14px; white-space: pre-wrap; }
.msg.user .bubble { background: var(--accent); color: #fff; border-bottom-right-radius: 4px; }
.msg.assistant .bubble { background: var(--surface); border: 1px solid var(--border); border-bottom-left-radius: 4px; }
.chat-input { display: flex; gap: 0.5rem; position: sticky; bottom: 80px; background: var(--bg); padding: 0.5rem 0; }
.chat-input input { margin: 0; }

.bottom {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 6;
  max-width: var(--maxw); margin: 0 auto;
  background: var(--surface); border-top: 1px solid var(--border);
  display: flex; justify-content: space-around;
  padding: 0.3rem 0 max(env(safe-area-inset-bottom), 0.3rem);
}
.bottom button { background: none; border: 0; color: var(--muted); font-size: 0.68rem; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 0.3rem 0.5rem; }
.bottom button span { font-size: 1.25rem; }
.bottom button.on { color: var(--accent); }

.toast {
  position: fixed; bottom: 90px; left: 50%; transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 0.6rem 1rem; border-radius: 999px;
  font-size: 0.85rem; z-index: 10; max-width: 90%; text-align: center;
}

/* segmented toggle (coach mode) */
.seg { display: flex; background: var(--bg); border-radius: 10px; padding: 3px; }
.seg button { flex: 1; border: 0; background: transparent; color: var(--muted); padding: 0.55rem; border-radius: 8px; font-weight: 600; }
.seg button.on { background: var(--accent); color: #fff; }

/* colour swatches */
.swatches { display: flex; gap: 0.6rem; flex-wrap: wrap; }
.swatch { width: 40px; height: 40px; border-radius: 50%; border: 2px solid transparent; cursor: pointer; }
.swatch.on { border-color: var(--text); box-shadow: 0 0 0 2px var(--surface) inset; }

/* tiles grid in More */
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0.6rem; }
.tile { display: flex; flex-direction: column; align-items: center; gap: 4px; background: var(--bg); border: 0; border-radius: 12px; padding: 1rem; color: var(--text); font-weight: 600; }
.tile span { font-size: 1.5rem; }

/* badges */
.badge-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0.6rem; }
.badge-card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 0.9rem; text-align: center; }
.badge-card.locked { opacity: 0.42; filter: grayscale(0.7); }
.badge-icon { font-size: 1.9rem; }
.badge-title { font-weight: 600; margin-top: 0.2rem; }

/* avatar row in profile */
.avatar-row { display: flex; align-items: center; gap: 1rem; margin: 0.4rem 0 0.2rem; }

/* location flag + suggested swap */
.loc-flag { background: color-mix(in srgb, var(--danger) 12%, transparent); color: var(--danger); font-size: 0.8rem; padding: 0.4rem 0.6rem; border-radius: 8px; margin: 0.5rem 0; }
.chip.suggest { border-color: var(--accent); color: var(--accent); font-weight: 600; }
