:root {
  --teal: #0b6e69;
  --teal-dark: #084f4c;
  --sky: #26c6da;
  --primary: #1e88e5;
  --primary-dark: #1565c0;
  --white: #fff;
  --bg: #e8f4f8;
  --card: #fff;
  --text: #1f2933;
  --muted: #6b7c8f;
  --input-bg: #eef6fa;
  --border: #d6e4ec;
  --gauge-blue: #42a5f5;
  --gauge-green: #43a047;
  --gauge-yellow: #f9a825;
  --gauge-orange: #fb8c00;
  --gauge-red: #e53935;
  --nav-active: #1e88e5;
  --nav-muted: #90a4ae;
  --shadow: 0 4px 20px rgba(15, 35, 52, 0.08);
  --radius: 20px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  min-height: 100%;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }

.boot-screen {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  background: var(--bg);
}
.boot-spinner {
  width: 42px;
  height: 42px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
.boot-title { font-size: 18px; font-weight: 700; color: var(--teal); margin: 0; }
@keyframes spin { to { transform: rotate(360deg); } }

.app {
  min-height: 100vh;
  max-width: 520px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  background: var(--bg);
}

.gradient-header {
  background: linear-gradient(135deg, #0b6e69, #0e7a74, #11867f, #14928a, #179e95, #1aa8a0);
  padding: 16px 16px 30px;
  color: var(--white);
}
.header-row {
  display: flex;
  align-items: center;
  gap: 12px;
}
.header-logo {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background: rgba(255,255,255,0.15);
  padding: 6px;
}
.header-welcome { font-size: 12px; opacity: 0.85; font-weight: 600; margin: 0; }
.header-name { font-size: 20px; font-weight: 800; margin: 0; }
.header-screen { font-size: 11px; opacity: 0.75; margin: 2px 0 0; font-weight: 600; }
.header-login {
  margin-left: auto;
  min-width: 44px;
  height: 44px;
  border: none;
  border-radius: 22px;
  background: rgba(255,255,255,0.2);
  color: #fff;
  font-weight: 700;
  font-size: 11px;
  cursor: pointer;
}

.welcome-screen { min-height: 100vh; display: flex; flex-direction: column; }
.welcome-top {
  flex: 0 0 42vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #0b6e69, #11867f, #1aa8a0);
  border-bottom-left-radius: 32px;
  border-bottom-right-radius: 32px;
}
.welcome-logo { width: 120px; height: 120px; margin-bottom: 16px; }
.welcome-heading { font-size: 30px; font-weight: 800; color: #fff; margin: 0; }
.welcome-card {
  margin: -20px 16px 16px;
  background: var(--card);
  border-radius: 28px;
  padding: 24px;
  box-shadow: var(--shadow);
  flex: 1;
}

.sheet {
  flex: 1;
  margin-top: -24px;
  border-top-left-radius: 28px;
  border-top-right-radius: 28px;
  background: var(--bg);
  overflow: auto;
  padding: 16px 16px calc(96px + var(--safe-bottom));
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 14px;
  box-shadow: var(--shadow);
}
.section-title {
  font-size: 13px;
  font-weight: 800;
  color: var(--teal-dark);
  letter-spacing: 0.08em;
  margin: 0 0 12px;
}
.sub-title {
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
  margin: 8px 0;
}
.hint { font-size: 13px; color: var(--muted); line-height: 1.5; margin: 0 0 10px; }
.error-text { color: #c62828; font-size: 13px; font-weight: 600; }

.field-label { font-size: 14px; font-weight: 600; margin-bottom: 8px; display: block; }
.input, .textarea, select.input {
  width: 100%;
  background: var(--input-bg);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 12px 16px;
  font-size: 16px;
  color: var(--text);
}
.textarea { min-height: 100px; resize: vertical; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: none;
  border-radius: 28px;
  padding: 14px 20px;
  font-size: 16px;
  font-weight: 800;
  cursor: pointer;
  width: 100%;
  margin-top: 10px;
}
.btn:disabled { opacity: 0.6; cursor: not-allowed; }
.btn-primary { background: var(--teal); color: #fff; }
.btn-blue { background: var(--primary); color: #fff; }
.btn-muted { background: #90a4ae; color: #fff; }
.btn-ghost {
  background: transparent;
  color: var(--muted);
  font-weight: 700;
  width: auto;
  margin-top: 8px;
}
.btn-sm {
  width: auto;
  padding: 8px 14px;
  font-size: 12px;
  border-radius: 999px;
  margin: 0;
}

.gender-row { display: flex; gap: 12px; margin-bottom: 16px; }
.gender-card {
  flex: 1;
  text-align: center;
  padding: 14px;
  border-radius: 20px;
  border: 2px solid var(--border);
  background: var(--input-bg);
  cursor: pointer;
}
.gender-card.on { border-color: var(--primary); background: #e3f2fd; }
.gender-emoji { font-size: 40px; display: block; }
.gender-text { font-size: 13px; color: var(--muted); font-weight: 600; margin-top: 6px; }
.gender-card.on .gender-text { color: var(--primary); }

.metric-row {
  display: flex;
  align-items: center;
  background: var(--input-bg);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 12px 16px;
  margin-bottom: 10px;
}
.metric-label { width: 72px; font-size: 12px; font-weight: 800; color: var(--muted); letter-spacing: 0.05em; }
.metric-input-wrap { flex: 1; display: flex; align-items: center; justify-content: flex-end; gap: 8px; }
.metric-input {
  width: 80px;
  text-align: right;
  border: none;
  background: transparent;
  font-size: 18px;
  font-weight: 700;
  color: var(--text);
}
.metric-unit { font-size: 13px; font-weight: 700; color: var(--primary); }
.height-hint { font-size: 12px; color: var(--muted); margin-bottom: 8px; }

.mini-bmi {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px;
  margin-bottom: 12px;
}
.mini-bmi-val { font-size: 28px; font-weight: 800; color: var(--teal); }

/* BMI gauge */
.gauge-card { text-align: center; }
.gauge-eyebrow { font-size: 11px; font-weight: 800; letter-spacing: 0.12em; color: var(--muted); }
.gauge-title { font-size: 22px; font-weight: 800; margin: 6px 0 16px; }
.gauge-track {
  display: flex;
  height: 14px;
  border-radius: 999px;
  overflow: hidden;
  margin-bottom: 8px;
}
.gauge-seg { height: 100%; }
.gauge-marks {
  display: flex;
  justify-content: space-between;
  font-size: 10px;
  color: var(--muted);
  font-weight: 700;
  margin-bottom: 16px;
}
.gauge-needle-wrap {
  position: relative;
  height: 90px;
  margin: 0 auto 8px;
  max-width: 280px;
}
.gauge-needle {
  position: absolute;
  left: 50%;
  bottom: 8px;
  width: 4px;
  height: 72px;
  transform-origin: bottom center;
  border-radius: 4px;
  margin-left: -2px;
  transition: transform 1s cubic-bezier(0.22, 1, 0.36, 1);
}
.gauge-dot {
  position: absolute;
  left: 50%;
  bottom: 0;
  width: 18px;
  height: 18px;
  margin-left: -9px;
  border-radius: 50%;
  border: 3px solid #fff;
  box-shadow: var(--shadow);
}
.gauge-bmi-num { font-size: 48px; font-weight: 800; line-height: 1; }
.gauge-bmi-label { font-size: 12px; font-weight: 700; color: var(--muted); }
.category-badge {
  display: inline-block;
  margin-top: 10px;
  padding: 8px 14px;
  border-radius: 999px;
  border: 2px solid;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.06em;
}
.progress-track {
  height: 8px;
  background: #e8eef2;
  border-radius: 999px;
  overflow: hidden;
  margin-top: 14px;
}
.progress-fill { height: 100%; border-radius: 999px; transition: width 0.4s ease; }

.metric-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 14px;
}
.metric-tile {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 14px;
}
.metric-tile.accent { background: var(--primary); color: #fff; grid-column: span 2; }
.metric-tile-label { font-size: 11px; font-weight: 800; color: var(--muted); letter-spacing: 0.06em; }
.metric-tile.accent .metric-tile-label { color: rgba(255,255,255,0.8); }
.metric-tile-value { font-size: 24px; font-weight: 800; margin-top: 4px; }
.metric-tile-unit { font-size: 12px; color: var(--muted); margin-top: 2px; }
.metric-tile.accent .metric-tile-unit { color: rgba(255,255,255,0.85); }

.delta-banner {
  background: #fff8e1;
  border: 1px solid #ffe082;
  border-radius: 14px;
  padding: 14px;
  margin-bottom: 14px;
}
.delta-text { font-weight: 800; margin: 0; }
.delta-sub { font-size: 12px; color: var(--muted); margin: 4px 0 0; }

.range-row {
  display: grid;
  grid-template-columns: 12px 1fr auto auto;
  gap: 10px;
  align-items: center;
  padding: 10px 8px;
  border-radius: 12px;
}
.range-row.live { background: #e8f5e9; }
.range-dot { width: 10px; height: 10px; border-radius: 50%; }
.range-label { font-size: 13px; font-weight: 600; }
.range-label.on { font-weight: 800; }
.range-val { font-size: 12px; color: var(--muted); }
.you-badge {
  font-size: 10px;
  font-weight: 800;
  color: var(--gauge-green);
  background: #fff;
  padding: 2px 6px;
  border-radius: 6px;
}

.journey-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 8px;
  border-bottom: 1px solid #f0f4f7;
  cursor: pointer;
}
.journey-row:hover { background: rgba(30,136,229,0.04); }
.journey-dot { width: 12px; height: 12px; border-radius: 50%; flex-shrink: 0; }
.journey-body { flex: 1; min-width: 0; }
.journey-date { font-weight: 700; font-size: 14px; }
.journey-meta { font-size: 12px; color: var(--muted); }
.journey-bmi { font-size: 18px; font-weight: 800; color: var(--primary); }
.sync-badge { font-size: 10px; color: var(--muted); text-align: right; }

.tab-bar {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: 0;
  width: 100%;
  max-width: 520px;
  display: flex;
  align-items: flex-end;
  justify-content: space-around;
  background: #fff;
  border-top: 1px solid var(--border);
  padding: 8px 6px calc(8px + var(--safe-bottom));
  z-index: 50;
}
.tab-btn {
  flex: 1;
  border: none;
  background: none;
  padding: 6px 4px;
  cursor: pointer;
  color: var(--nav-muted);
}
.tab-btn.on { color: var(--nav-active); }
.tab-icon { display: block; font-size: 18px; line-height: 1; }
.tab-text { display: block; font-size: 10px; font-weight: 700; margin-top: 2px; }
.fab {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: none;
  background: var(--primary);
  color: #fff;
  font-size: 28px;
  font-weight: 300;
  margin-top: -24px;
  box-shadow: 0 6px 16px rgba(30,136,229,0.35);
  cursor: pointer;
}

.library-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 4px; }
.plan-card {
  display: flex;
  gap: 12px;
  align-items: center;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 14px;
  margin-bottom: 10px;
  cursor: pointer;
}
.plan-card.error { border-color: #ffcdd2; }
.plan-card-icon {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background: #e3f2fd;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 800;
  color: var(--primary);
  flex-shrink: 0;
}
.plan-card-icon.video { background: #263238; color: #fff; }
.plan-card-body { flex: 1; min-width: 0; }
.plan-card-title { font-weight: 800; font-size: 15px; margin: 0 0 4px; }
.plan-card-meta { font-size: 12px; color: var(--muted); margin: 0; }
.plan-card-action {
  background: var(--primary);
  color: #fff;
  font-size: 11px;
  font-weight: 800;
  padding: 8px 12px;
  border-radius: 10px;
}
.plan-card-action.teal { background: var(--teal); }
.plan-card-action.disabled { opacity: 0.45; }

.follow-card { padding: 16px; margin-bottom: 12px; cursor: pointer; }
.follow-top { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.type-badge {
  font-size: 11px;
  font-weight: 800;
  padding: 4px 10px;
  border-radius: 999px;
  background: #e0f2f1;
  color: var(--teal);
}
.type-badge.project { background: #e3f2fd; color: var(--primary); }
.pct { font-size: 18px; font-weight: 800; color: var(--primary); }

.profile-hero {
  background: var(--teal);
  border-radius: 16px;
  padding: 18px;
  color: #fff;
  margin-bottom: 14px;
}
.profile-hero h2 { margin: 0; font-size: 22px; }
.stats-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 14px; }
.stat-box {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
}
.stat-n { font-size: 22px; font-weight: 800; color: var(--primary); }
.stat-l { font-size: 11px; color: var(--muted); font-weight: 600; }
.profile-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 0;
  border-bottom: 1px solid #f0f4f7;
  font-size: 13px;
}
.profile-row span:first-child { color: var(--muted); font-weight: 600; }
.profile-row span:last-child { font-weight: 600; text-align: right; }

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 100;
  padding: 0;
}
.modal-overlay.center { align-items: center; padding: 16px; }
.modal-sheet {
  background: #fff;
  width: 100%;
  max-width: 520px;
  max-height: 92vh;
  border-radius: 20px 20px 0 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.modal-sheet.rounded { border-radius: 20px; max-height: 85vh; }
.modal-header {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 14px 16px;
  background: var(--teal);
  color: #fff;
}
.modal-eyebrow { font-size: 11px; opacity: 0.75; font-weight: 700; letter-spacing: 0.08em; }
.modal-title { font-size: 18px; font-weight: 800; margin: 2px 0 0; }
.modal-close {
  border: none;
  background: none;
  color: #fff;
  font-size: 22px;
  cursor: pointer;
  padding: 4px;
  line-height: 1;
}
.modal-body { overflow: auto; padding: 16px; flex: 1; }
.modal-pad { padding: 16px 20px 24px; }

.task-row {
  display: flex;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid #f0f4f7;
  cursor: pointer;
}
.task-row.done { opacity: 0.85; }
.check {
  width: 26px;
  height: 26px;
  border: 2px solid var(--border);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-weight: 800;
  color: #fff;
  margin-top: 2px;
}
.check.on { background: var(--gauge-green); border-color: var(--gauge-green); }
.task-title { font-weight: 700; font-size: 15px; }
.task-title.done { text-decoration: line-through; color: var(--muted); }
.task-detail { font-size: 13px; color: var(--muted); margin-top: 4px; line-height: 1.4; }
.task-meta { font-size: 11px; color: var(--muted); margin-top: 4px; font-weight: 600; }

.media-viewer {
  position: fixed;
  inset: 0;
  background: #111;
  z-index: 120;
  display: flex;
  flex-direction: column;
}
.media-viewer header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: #1a1a1a;
  color: #fff;
}
.media-viewer header h3 { flex: 1; margin: 0; font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.media-frame { flex: 1; border: none; width: 100%; background: #222; }
.media-video { flex: 1; width: 100%; background: #000; }

.photo-row { display: flex; flex-wrap: wrap; gap: 8px; margin: 12px 0; }
.thumb { width: 64px; height: 64px; border-radius: 10px; object-fit: cover; }
.add-photo {
  width: 64px;
  height: 64px;
  border: 1px dashed var(--border);
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 700;
  color: var(--primary);
  cursor: pointer;
}

.lock-banner {
  margin-top: 12px;
  padding: 12px;
  background: #eceff1;
  border-radius: 12px;
  font-size: 12px;
  color: var(--muted);
  text-align: center;
}

.toast-root {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(80px + var(--safe-bottom));
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: min(420px, calc(100% - 32px));
  pointer-events: none;
}
.toast {
  background: #263238;
  color: #fff;
  padding: 12px 16px;
  border-radius: 12px;
  font-size: 14px;
  font-weight: 600;
  box-shadow: var(--shadow);
  animation: toast-in 0.25s ease;
}
@keyframes toast-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.empty { font-size: 13px; color: var(--muted); line-height: 1.5; }

@media (min-width: 521px) {
  .app, .tab-bar { box-shadow: 0 0 0 1px var(--border); }
}
