:root {
  color-scheme: dark;
  --bg: #090a0d;
  --card: #17191f;
  --card-2: #1d2028;
  --line: #2b2e37;
  --text: #f7f7f8;
  --muted: #989aa6;
  --green: #63e08b;
  --green-deep: #277c49;
  --coral: #ff7b7b;
  --blue: #6689ff;
  --purple: #a78bfa;
  --safe-top: max(20px, env(safe-area-inset-top));
  --safe-bottom: max(16px, env(safe-area-inset-bottom));
  font-family: ui-rounded, "SF Pro Rounded", "SF Pro Display", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-synthesis: none;
}

* { box-sizing: border-box; }
html { background: var(--bg); }
body { margin: 0; background: var(--bg); color: var(--text); min-height: 100vh; }
button, input { font: inherit; }
button { -webkit-tap-highlight-color: transparent; }
button:focus-visible, input:focus-visible { outline: 2px solid var(--green); outline-offset: 2px; }

.app-shell { width: min(100%, 680px); margin: 0 auto; min-height: 100vh; padding-bottom: calc(112px + var(--safe-bottom)); }
.topbar { display: flex; justify-content: space-between; align-items: center; gap: 16px; padding: calc(var(--safe-top) + 12px) 20px 20px; position: relative; }
.brand { font-size: 27px; font-weight: 800; letter-spacing: -1.2px; }
.brand span { font-size: 23px; }
.topbar p, .page-title p { margin: 4px 0 0; color: var(--muted); font-size: 14px; }
.topbar .cloud-status { font-size: 11px; color: var(--green); }
.topbar .cloud-status.offline, .topbar .cloud-status.error { color: var(--coral); }
.topbar .cloud-status.pending { color: #f5c66b; }
.goal-pill { border: 1px solid color-mix(in srgb, var(--green) 35%, transparent); background: color-mix(in srgb, var(--green) 10%, var(--card)); color: var(--green); min-width: 70px; border-radius: 20px; padding: 8px 12px; display: grid; cursor: pointer; }
.goal-pill span { font-weight: 800; font-size: 19px; line-height: 1; }
.goal-pill small { color: var(--muted); margin-top: 4px; }

main { padding: 0 16px; }
.view { display: none; animation: view-in .26s ease both; }
.view.active { display: block; }
@keyframes view-in { from { opacity: 0; transform: translateY(5px); } }
.card { background: linear-gradient(145deg, #1a1c23, #15171c); border: 1px solid var(--line); border-radius: 24px; box-shadow: 0 12px 36px rgba(0, 0, 0, .16); }
.eyebrow { color: var(--muted); font-size: 11px; font-weight: 800; letter-spacing: 1.4px; margin: 0 0 7px; }
h1, h2, p { overflow-wrap: anywhere; }
h1, h2 { letter-spacing: -.04em; }

.hero-card { padding: 22px; display: flex; align-items: center; justify-content: space-between; min-height: 172px; overflow: hidden; position: relative; }
.hero-card::after { content: ""; position: absolute; width: 180px; height: 180px; right: -60px; top: -80px; border-radius: 50%; background: color-mix(in srgb, var(--green) 9%, transparent); filter: blur(4px); }
.hero-copy { position: relative; z-index: 1; max-width: 62%; }
.hero-copy h1 { font-size: clamp(42px, 13vw, 64px); margin: 0; color: var(--green); font-variant-numeric: tabular-nums; line-height: .96; }
.hero-copy h1.surplus { color: var(--coral); }
.hero-copy h1 small { font-size: 17px; color: var(--muted); font-weight: 650; letter-spacing: 0; }
.hero-copy > p:last-child { color: var(--muted); font-size: 13px; line-height: 1.45; margin: 12px 0 0; }
.deficit-ring { --progress: 0deg; width: 102px; height: 102px; flex: 0 0 102px; border-radius: 50%; background: conic-gradient(var(--green) var(--progress), #282b34 0); display: grid; place-items: center; position: relative; z-index: 1; }
.deficit-ring::after { content: ""; position: absolute; inset: 8px; background: #17191f; border-radius: 50%; }
.deficit-ring div { position: relative; z-index: 1; text-align: center; display: grid; }
.deficit-ring strong { font-size: 22px; font-variant-numeric: tabular-nums; }
.deficit-ring small { color: var(--muted); font-size: 10px; }

.metric-grid, .stat-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin: 12px 0 26px; }
.metric-card { padding: 15px; min-height: 108px; display: grid; grid-template-columns: 32px 1fr; grid-template-rows: 1fr auto; column-gap: 9px; align-items: center; }
.metric-icon { width: 30px; height: 30px; border-radius: 10px; display: grid; place-items: center; font-weight: 850; background: color-mix(in srgb, var(--blue) 16%, transparent); color: var(--blue); }
.metric-icon.green { color: var(--green); background: color-mix(in srgb, var(--green) 14%, transparent); }
.metric-icon.coral { color: var(--coral); background: color-mix(in srgb, var(--coral) 14%, transparent); }
.metric-icon.purple { color: var(--purple); background: color-mix(in srgb, var(--purple) 14%, transparent); }
.metric-card strong { font-size: 21px; letter-spacing: -.04em; }
.metric-card small { color: var(--muted); grid-column: 1 / -1; font-size: 11px; }

.section-heading, .card-heading { display: flex; align-items: end; justify-content: space-between; gap: 12px; }
.section-heading { margin: 0 4px 12px; }
.section-heading h2, .card-heading h2 { font-size: 20px; margin: 0; }
.info-button { width: 32px; height: 32px; border-radius: 50%; border: 1px solid var(--line); color: var(--muted); background: var(--card); font-weight: 800; }
.projection-list { display: grid; gap: 10px; }
.projection-card { padding: 16px; display: grid; grid-template-columns: 58px 1fr; gap: 13px; align-items: center; }
.target-badge { width: 58px; height: 58px; display: grid; place-items: center; border-radius: 18px; background: color-mix(in srgb, var(--green) 13%, transparent); color: var(--green); font-size: 21px; font-weight: 850; }
.projection-copy { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.projection-copy > div { display: grid; gap: 2px; }
.projection-copy small { color: var(--muted); font-size: 9px; font-weight: 750; letter-spacing: .5px; }
.projection-copy strong { font-size: 14px; line-height: 1.2; }
.projection-copy span { color: var(--muted); font-size: 11px; }
.projection-meta { grid-column: 1 / -1; border-top: 1px solid var(--line); padding-top: 10px; color: var(--muted); font-size: 11px; }

.weekly-card, .chart-card, .calendar-card, .workout-card, .insight-card, .integration-card, .danger-zone { margin-top: 12px; padding: 19px; }
.card-heading strong { color: var(--green); font-size: 13px; }
.bar-chart { height: 178px; display: grid; grid-template-columns: repeat(7, 1fr); gap: 7px; margin-top: 20px; }
.bar-column { display: grid; grid-template-rows: 20px 1fr 17px; gap: 4px; text-align: center; min-width: 0; }
.bar-column strong { font-size: 9px; color: var(--muted); font-variant-numeric: tabular-nums; }
.bar-column small { color: var(--muted); font-size: 10px; text-transform: uppercase; }
.bar-track { background: #22252d; border-radius: 9px; position: relative; display: flex; align-items: end; overflow: hidden; }
.bar-track i { display: block; width: 100%; border-radius: 8px; min-height: 4px; transition: height .5s ease; }
.bar-track .deficit { background: linear-gradient(var(--green), #3aa765); }
.bar-track .surplus { background: linear-gradient(var(--coral), #b94d58); }
.bar-track .missing { background: #353842; }
.weekly-foot { margin-top: 14px; padding-top: 13px; border-top: 1px solid var(--line); display: flex; justify-content: space-between; color: var(--muted); font-size: 11px; }
.insight-card { display: flex; gap: 14px; margin-bottom: 12px; }
.insight-icon { width: 42px; height: 42px; flex: 0 0 42px; border-radius: 14px; display: grid; place-items: center; color: var(--green); background: color-mix(in srgb, var(--green) 13%, transparent); font-size: 21px; }
.insight-card h2 { margin: 0; font-size: 18px; }
.insight-card p:last-child { color: var(--muted); font-size: 13px; line-height: 1.5; margin: 6px 0 0; }

.page-title { padding: 16px 4px 18px; }
.page-title h1 { margin: 0; font-size: 38px; }
.page-title > p:last-child { margin-top: 6px; font-size: 14px; color: var(--muted); }
.stat-grid { margin-top: 0; }
.chart-card svg { width: 100%; height: auto; margin-top: 12px; overflow: visible; }
.chart-grid { stroke: #30333c; stroke-width: 1; }
.weight-raw { fill: none; stroke: #4a4e5a; stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; }
.weight-average { fill: none; stroke: var(--green); stroke-width: 5; stroke-linecap: round; stroke-linejoin: round; }
.last-point { fill: var(--green); stroke: #d7ffe2; stroke-width: 3; }
.chart-label, .empty-chart { fill: var(--muted); font-size: 17px; }
.heatmap { display: grid; grid-template-columns: repeat(7, 1fr); gap: 8px; margin: 22px 0 12px; }
.heatmap i { aspect-ratio: 1; border-radius: 7px; background: #292c34; }
.heatmap .level-1 { background: #5c5142; }
.heatmap .level-2 { background: #397050; }
.heatmap .level-3 { background: var(--green); box-shadow: 0 0 12px color-mix(in srgb, var(--green) 20%, transparent); }
.legend { display: flex; justify-content: space-between; color: var(--muted); font-size: 10px; }
.legend span { display: flex; align-items: center; gap: 5px; }
.legend i { width: 8px; height: 8px; border-radius: 3px; background: #292c34; }
.legend i.good { background: var(--green); }
.workout-list { margin-top: 15px; display: grid; }
.workout-row { display: flex; gap: 12px; align-items: center; padding: 12px 0; border-top: 1px solid var(--line); }
.workout-row > span { font-size: 20px; }
.workout-row div { display: grid; gap: 3px; }
.workout-row small, .empty-state { color: var(--muted); }
.empty-state { font-size: 13px; }

.log-form, #settings-form { display: grid; gap: 12px; }
.form-card { padding: 19px; display: grid; gap: 15px; }
.form-card h2, .integration-card h2, .danger-zone h2 { margin: 0; font-size: 19px; }
.field-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
label { display: grid; gap: 7px; color: var(--muted); font-size: 12px; font-weight: 650; }
input { width: 100%; color: var(--text); background: #101216; border: 1px solid var(--line); border-radius: 14px; padding: 13px 12px; font-size: 16px; min-height: 48px; }
input::placeholder { color: #555862; }
.form-help { color: var(--muted); font-size: 12px; line-height: 1.5; margin: 0; }
.primary-button, .secondary-button { min-height: 52px; border: 0; border-radius: 18px; font-weight: 800; cursor: pointer; }
.primary-button { background: var(--green); color: #07120a; padding: 14px 18px; }
.secondary-button { background: var(--card-2); border: 1px solid var(--line); color: var(--text); padding: 12px 15px; }
.text-button { background: transparent; border: 0; color: var(--muted); min-height: 42px; font-weight: 700; }
.text-button.danger { color: var(--coral); }
.hidden { display: none !important; }
.integration-card { display: grid; gap: 14px; }
.integration-heading { display: flex; gap: 12px; align-items: center; }
.integration-heading > span { width: 42px; height: 42px; border-radius: 13px; display: grid; place-items: center; background: var(--card-2); font-size: 20px; }
.integration-heading p, .danger-zone p { color: var(--muted); font-size: 12px; margin: 3px 0 0; }
.button-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.sync-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; color: var(--muted); font-size: 12px; }
.sync-row strong { color: var(--green); font-size: 11px; white-space: nowrap; }
.file-button { display: grid; place-items: center; }
.file-button input { display: none; }
.danger-zone { margin-bottom: 20px; }

.quick-add { position: fixed; right: max(22px, calc((100vw - 650px) / 2)); bottom: calc(83px + var(--safe-bottom)); z-index: 10; min-height: 49px; border-radius: 28px; border: 0; background: var(--green); color: #08110a; padding: 0 19px; font-size: 14px; font-weight: 850; box-shadow: 0 9px 28px rgba(33, 150, 79, .32); }
.quick-add span { font-size: 23px; vertical-align: -2px; margin-right: 3px; }
.tabbar { position: fixed; z-index: 9; left: 50%; transform: translateX(-50%); bottom: calc(8px + env(safe-area-inset-bottom)); width: min(calc(100% - 24px), 650px); min-height: 72px; border: 1px solid #383b45; background: rgba(30, 32, 39, .92); backdrop-filter: blur(22px) saturate(1.3); border-radius: 30px; padding: 6px; display: grid; grid-template-columns: repeat(4, 1fr); box-shadow: 0 14px 35px rgba(0, 0, 0, .4); }
.tabbar button { border: 0; border-radius: 25px; color: #c6c8ce; background: transparent; display: grid; place-items: center; align-content: center; gap: 2px; font-size: 10px; font-weight: 700; }
.tabbar button span { font-size: 22px; line-height: 1; }
.tabbar button.active { background: #444750; color: var(--green); }

dialog { color: var(--text); background: #17191f; border: 1px solid var(--line); box-shadow: 0 30px 90px #000; }
dialog::backdrop { background: rgba(0, 0, 0, .7); backdrop-filter: blur(5px); }
.sheet { width: min(calc(100% - 20px), 640px); max-height: min(88vh, 850px); border-radius: 30px; padding: 22px; margin: auto auto max(10px, env(safe-area-inset-bottom)); overflow-y: auto; }
.sheet[open] { animation: sheet-in .26s ease both; }
@keyframes sheet-in { from { transform: translateY(30px); opacity: 0; } }
.sheet-handle { width: 38px; height: 5px; border-radius: 5px; background: #52555f; margin: -10px auto 22px; }
.sheet h1 { margin: 0 0 8px; font-size: 30px; }
.sheet > p, .sheet form > p { color: var(--muted); line-height: 1.5; font-size: 14px; }
.sheet .primary-button { width: 100%; margin-top: 18px; }
.onboarding-sheet form { display: grid; }
.onboarding-sheet .text-button { margin-top: 5px; }
.auth-sheet { margin: auto; }
.auth-sheet form { display: grid; gap: 13px; }
.auth-sheet .primary-button { margin-top: 4px; }
.auth-sheet .secondary-button { width: 100%; }
.auth-message { min-height: 18px; margin: 0 !important; color: var(--coral) !important; font-size: 12px !important; }
.install-steps { padding-left: 23px; color: var(--muted); line-height: 1.6; }
.install-steps li { margin-bottom: 8px; padding-left: 5px; }
.toast { position: fixed; left: 50%; bottom: calc(98px + var(--safe-bottom)); transform: translate(-50%, 20px); z-index: 30; background: #f1f3f2; color: #111; border-radius: 18px; padding: 12px 17px; font-size: 13px; font-weight: 750; opacity: 0; pointer-events: none; transition: .22s ease; max-width: calc(100% - 32px); text-align: center; box-shadow: 0 12px 35px rgba(0,0,0,.35); }
.toast.visible { opacity: 1; transform: translate(-50%, 0); }

@media (min-width: 560px) {
  main { padding: 0 20px; }
  .metric-grid, .stat-grid { grid-template-columns: repeat(4, 1fr); }
  .metric-card { min-height: 118px; grid-template-columns: 1fr; grid-template-rows: 32px auto auto; }
  .metric-card small { grid-column: auto; }
  .projection-card { grid-template-columns: 70px 1fr auto; }
  .projection-meta { grid-column: auto; border: 0; border-left: 1px solid var(--line); padding: 0 0 0 14px; max-width: 130px; }
}

@media (max-width: 370px) {
  .hero-card { padding: 18px; }
  .hero-copy h1 { font-size: 39px; }
  .deficit-ring { width: 88px; height: 88px; flex-basis: 88px; }
  .field-grid { grid-template-columns: 1fr; }
  .projection-copy { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
