:root {
  color-scheme: dark;
  --bg: var(--tg-theme-bg-color, #0b0f14);
  --surface: var(--tg-theme-secondary-bg-color, #131a22);
  --surface-strong: #18212b;
  --text: var(--tg-theme-text-color, #f5f7f9);
  --muted: var(--tg-theme-hint-color, #8b98a7);
  --accent: var(--tg-theme-button-color, #58d6a0);
  --accent-text: var(--tg-theme-button-text-color, #07130e);
  --link: var(--tg-theme-link-color, #74e7b7);
  --line: rgba(255, 255, 255, 0.08);
  --warning: #f4bd68;
  --danger: #ff887d;
  --radius-xl: 26px;
  --radius-lg: 20px;
  --radius-md: 16px;
  --shadow: 0 18px 60px rgba(0, 0, 0, 0.25);
}

* { box-sizing: border-box; }
html { background: var(--bg); scroll-behavior: smooth; }
body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  background:
    radial-gradient(circle at 95% -5%, rgba(88, 214, 160, 0.12), transparent 30rem),
    var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 16px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
button, input { font: inherit; }
button { color: inherit; }
button:focus-visible, input:focus-visible { outline: 3px solid rgba(88, 214, 160, 0.42); outline-offset: 3px; }

.app-shell { width: min(100%, 720px); min-height: 100vh; margin: 0 auto; position: relative; }
.app-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(16px + env(safe-area-inset-top)) 20px 12px;
}
.app-header h1 { margin: -2px 0 0; font-size: 25px; letter-spacing: -0.04em; }
.eyebrow { margin: 0; color: var(--accent); font-size: 10px; font-weight: 800; letter-spacing: 0.16em; }
.profile-mark {
  width: 42px; height: 42px; display: grid; place-items: center; border-radius: 14px;
  overflow: hidden; color: #07130e; background: #0b1114; font-weight: 900;
  box-shadow: 0 8px 24px rgba(88, 214, 160, 0.2);
}
.profile-mark img { display: block; width: 100%; height: 100%; object-fit: cover; }
.header-status { display: flex; align-items: center; gap: 10px; }
.connection-status { padding: 5px 8px; border: 1px solid var(--line); border-radius: 99px; color: var(--muted); font-size: 9px; font-weight: 750; }
.connection-status.connected { border-color: rgba(88,214,160,.22); color: var(--accent); }
.connection-status.error { border-color: rgba(255,136,125,.24); color: var(--danger); }
main { padding: 4px 16px calc(116px + env(safe-area-inset-bottom)); }
.tab-panel { animation: panel-in 0.3s ease; }
.tab-panel[hidden] { display: none; }
@keyframes panel-in { from { opacity: 0; transform: translateY(6px); } }

.sobriety-card {
  position: relative; isolation: isolate; overflow: hidden; min-height: 238px; padding: 22px;
  border: 1px solid rgba(117, 233, 185, 0.24); border-radius: var(--radius-xl);
  background:
    linear-gradient(145deg, rgba(88, 214, 160, 0.17), rgba(19, 26, 34, 0.96) 58%),
    var(--surface);
  box-shadow: var(--shadow);
}
.sobriety-card::after { content: ""; position: absolute; inset: 0; z-index: -1; background: linear-gradient(115deg, transparent 48%, rgba(255,255,255,.035)); }
.sobriety-topline { display: flex; align-items: center; gap: 9px; color: #c8f7e1; font-size: 13px; font-weight: 750; }
.status-dot { width: 9px; height: 9px; border: 2px solid rgba(88,214,160,.35); border-radius: 50%; background: var(--accent); box-shadow: 0 0 16px var(--accent); }
.status-pill { margin-left: auto; padding: 5px 9px; border: 1px solid rgba(88,214,160,.2); border-radius: 99px; background: rgba(88,214,160,.08); color: var(--accent); font-size: 10px; text-transform: uppercase; letter-spacing: .08em; }
.sobriety-counter { display: flex; align-items: flex-start; gap: 11px; margin: 28px 0 14px; }
.sobriety-counter span:not(.counter-divider) { display: flex; flex-direction: column; }
.sobriety-counter strong { font-size: clamp(50px, 17vw, 82px); line-height: .85; letter-spacing: -.075em; font-variant-numeric: tabular-nums; }
.sobriety-counter small { margin-top: 13px; color: var(--muted); font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .12em; }
.counter-divider { margin-top: -7px; color: rgba(255,255,255,.25); font-size: 48px; line-height: 1; }
.sobriety-card > p { margin: 0; color: var(--muted); font-size: 13px; }
.sobriety-glow { position: absolute; right: -55px; bottom: -80px; z-index: -1; width: 210px; height: 210px; border-radius: 50%; background: rgba(88,214,160,.14); filter: blur(24px); }

.section-heading { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; }
.section-heading h2, .page-intro h2 { margin: 5px 0 0; font-size: 24px; line-height: 1.08; letter-spacing: -.045em; }
.today-heading { margin: 31px 2px 16px; }
.compact-heading { margin: 30px 2px 14px; align-items: center; }
.day-chip, .goal-badge { padding: 7px 10px; border: 1px solid var(--line); border-radius: 99px; background: rgba(255,255,255,.035); color: var(--muted); font-size: 11px; font-weight: 700; }

.metric-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.metric-card { position: relative; overflow: hidden; min-height: 132px; padding: 16px; border: 1px solid var(--line); border-radius: var(--radius-lg); background: linear-gradient(145deg, rgba(255,255,255,.025), transparent), var(--surface); }
.metric-card p { margin: 0 0 14px; color: var(--muted); font-size: 12px; font-weight: 650; }
.metric-card strong { display: block; margin-bottom: 7px; font-size: 27px; line-height: 1; letter-spacing: -.045em; font-variant-numeric: tabular-nums; }
.metric-card strong small { color: var(--muted); font-size: 12px; letter-spacing: 0; }
.metric-note { color: var(--muted); font-size: 10px; }
.metric-icon { position: absolute; top: 13px; right: 14px; display: grid; place-items: center; width: 25px; height: 25px; border-radius: 9px; background: rgba(88,214,160,.1); color: var(--accent); font-size: 13px; font-weight: 900; }
.metric-weight { background: linear-gradient(150deg, rgba(88,214,160,.11), transparent 65%), var(--surface); }
.mini-progress { height: 4px; margin-top: 15px; overflow: hidden; border-radius: 99px; background: rgba(255,255,255,.07); }
.mini-progress span { display: block; width: 0; height: 100%; border-radius: inherit; background: var(--accent); transition: width .25s ease; }
.section-total { color: var(--accent); font-size: 14px; font-variant-numeric: tabular-nums; }
.demo-meal-note { margin: -5px 2px 10px; color: var(--muted); font-size: 10px; }

.meal-list { overflow: hidden; border: 1px solid var(--line); border-radius: var(--radius-lg); background: var(--surface); }
.meal-row { position: relative; display: flex; align-items: center; gap: 13px; min-height: 70px; padding: 10px 15px; cursor: pointer; border-bottom: 1px solid var(--line); transition: background .2s ease; }
.meal-row:last-child { border-bottom: 0; }
.meal-row:has(input:checked) { background: rgba(88,214,160,.055); }
.meal-row input { position: absolute; opacity: 0; pointer-events: none; }
.custom-check { flex: 0 0 auto; width: 24px; height: 24px; border: 1.5px solid #596573; border-radius: 8px; transition: .2s ease; }
.meal-row input:checked + .custom-check { border-color: var(--accent); background: var(--accent); box-shadow: inset 0 0 0 6px var(--accent); }
.meal-row input:checked + .custom-check::after { content: "✓"; display: grid; place-items: center; height: 100%; color: var(--accent-text); font-size: 15px; font-weight: 950; }
.meal-copy { min-width: 0; display: flex; flex: 1; flex-direction: column; }
.meal-copy strong { font-size: 14px; }
.meal-copy small { margin-top: 3px; color: var(--muted); font-size: 11px; }
.meal-kcal { color: #d9dfe4; font-size: 13px; font-weight: 800; font-variant-numeric: tabular-nums; }
.meal-kcal small { color: var(--muted); font-size: 9px; font-weight: 600; }

.workout-toggle-card { display: flex; align-items: center; gap: 13px; margin-top: 14px; padding: 16px; min-height: 84px; border: 1px solid rgba(88,214,160,.19); border-radius: var(--radius-lg); background: linear-gradient(120deg, rgba(88,214,160,.08), transparent), var(--surface); cursor: pointer; }
.workout-symbol { display: grid; flex: 0 0 auto; place-items: center; width: 45px; height: 45px; border-radius: 15px; background: var(--accent); color: var(--accent-text); font-size: 17px; font-weight: 950; }
.workout-copy { min-width: 0; display: flex; flex: 1; flex-direction: column; }
.workout-copy small { color: var(--accent); font-size: 8px; font-weight: 850; letter-spacing: .12em; }
.workout-copy strong { margin-top: 2px; font-size: 14px; }
.workout-copy span { overflow: hidden; color: var(--muted); font-size: 10px; text-overflow: ellipsis; white-space: nowrap; }
.workout-toggle-card input { position: absolute; opacity: 0; }
.workout-toggle-card:has(input:disabled) { cursor: default; opacity: .78; border-color: rgba(244,189,104,.18); }
.workout-toggle-card:has(input:disabled) .workout-symbol { background: var(--warning); color: #261b08; }
.switch { flex: 0 0 auto; position: relative; width: 46px; height: 28px; border-radius: 99px; background: #313b46; transition: .2s ease; }
.switch::after { content: ""; position: absolute; top: 4px; left: 4px; width: 20px; height: 20px; border-radius: 50%; background: #94a0ac; transition: .2s ease; }
.workout-toggle-card input:checked + .switch { background: var(--accent); }
.workout-toggle-card input:checked + .switch::after { transform: translateX(18px); background: var(--accent-text); }

.page-intro { padding: 16px 4px 21px; }
.page-intro h2 { margin-top: 8px; font-size: 31px; }
.page-intro > p:last-child { max-width: 540px; margin: 12px 0 0; color: var(--muted); font-size: 14px; }
.chart-card, .checkin-card, .weekly-review-card, .meal-rhythm-card, .week-card { border: 1px solid var(--line); border-radius: var(--radius-xl); background: var(--surface); }
.chart-card { overflow: hidden; padding: 20px 12px 15px; }
.chart-header { display: flex; align-items: center; justify-content: space-between; padding: 0 8px 10px; }
.chart-header > div:first-child { display: flex; flex-direction: column; }
.chart-header span { color: var(--muted); font-size: 11px; }
.chart-header strong { margin-top: 3px; font-size: 23px; letter-spacing: -.04em; }
.goal-badge { border-color: rgba(244,189,104,.18); color: var(--warning); }
#weight-chart { display: block; width: 100%; height: auto; min-height: 205px; overflow: visible; }
.chart-grid-line { stroke: rgba(255,255,255,.06); stroke-width: 1; }
.chart-grid-label, .chart-date-label { fill: var(--muted); font-family: inherit; font-size: 10px; }
.goal-line { stroke: var(--warning); stroke-width: 1.5; stroke-dasharray: 6 6; }
.goal-label { fill: var(--warning); font-family: inherit; font-size: 10px; }
.weight-area { fill: url(#none); fill: rgba(88,214,160,.08); }
.weight-path { fill: none; stroke: var(--accent); stroke-width: 4; stroke-linecap: round; stroke-linejoin: round; }
.chart-point { fill: var(--surface); stroke: var(--accent); stroke-width: 4; }
.chart-legend { display: flex; justify-content: center; gap: 20px; color: var(--muted); font-size: 10px; }
.chart-legend span { display: flex; align-items: center; gap: 6px; }
.chart-legend i { display: block; width: 14px; height: 2px; }
.legend-current { background: var(--accent); }
.legend-goal { border-top: 1px dashed var(--warning); }

.checkin-card { margin-top: 14px; padding: 19px; }
.checkin-card .compact-heading { margin: 0; }
.calendar-icon { display: grid; place-items: center; width: 39px; height: 39px; border-radius: 13px; background: rgba(88,214,160,.1); color: var(--accent); font-weight: 900; }
.supporting-text { margin: 10px 0 17px; color: var(--muted); font-size: 12px; }
#checkin-form { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.field { display: flex; flex-direction: column; gap: 7px; color: var(--muted); font-size: 11px; font-weight: 700; }
.field input { width: 100%; min-height: 50px; padding: 0 13px; border: 1px solid var(--line); border-radius: 13px; background: rgba(255,255,255,.035); color: var(--text); font-size: 17px; font-weight: 750; }
.primary-button { grid-column: 1 / -1; min-height: 52px; margin-top: 5px; border: 0; border-radius: 14px; background: var(--accent); color: var(--accent-text); font-weight: 850; cursor: pointer; }
.form-status { grid-column: 1 / -1; min-height: 0; margin: 0; color: var(--accent); font-size: 11px; text-align: center; }
.form-status:empty { display: none; }
.weekly-review-card { margin-top: 14px; padding: 19px; border-color: rgba(88,214,160,.18); background: linear-gradient(135deg, rgba(88,214,160,.07), transparent), var(--surface); }
.weekly-review-card .compact-heading { margin: 0 0 14px; }
.weekly-review-card > strong { display: block; font-size: 15px; line-height: 1.4; }
.weekly-review-card ul { margin: 12px 0; padding-left: 18px; color: var(--muted); font-size: 11px; }
.weekly-review-card li + li { margin-top: 5px; }
.weekly-review-card > p { margin: 12px 0; padding: 10px; border-radius: 12px; background: rgba(255,255,255,.035); color: #dce4e8; font-size: 11px; }
.weekly-review-card > small { color: var(--muted); font-size: 10px; }

.nutrition-hero { display: flex; align-items: center; gap: 20px; padding: 21px; border: 1px solid rgba(88,214,160,.2); border-radius: var(--radius-xl); background: linear-gradient(135deg, rgba(88,214,160,.12), transparent), var(--surface); }
.nutrition-ring { display: grid; flex: 0 0 auto; place-items: center; align-content: center; width: 112px; height: 112px; border: 8px solid rgba(88,214,160,.12); border-top-color: var(--accent); border-right-color: var(--accent); border-radius: 50%; }
.nutrition-ring strong { font-size: 25px; line-height: 1; letter-spacing: -.05em; }
.nutrition-ring span { margin-top: 4px; color: var(--muted); font-size: 9px; }
.recommendation-label { color: var(--accent); font-size: 9px; font-weight: 850; letter-spacing: .12em; text-transform: uppercase; }
.nutrition-hero h3 { margin: 5px 0 4px; font-size: 19px; letter-spacing: -.025em; }
.nutrition-hero p { margin: 0; color: var(--muted); font-size: 11px; }
.nutrition-stats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 10px; }
.nutrition-stats article { display: flex; min-height: 112px; padding: 15px; flex-direction: column; border: 1px solid var(--line); border-radius: var(--radius-lg); background: var(--surface); }
.nutrition-stats span, .nutrition-stats small { color: var(--muted); font-size: 10px; }
.nutrition-stats strong { margin: auto 0 4px; font-size: 17px; letter-spacing: -.02em; }
.meal-rhythm-card { margin-top: 14px; padding: 18px; }
.meal-rhythm-card .compact-heading { margin: 0 0 10px; }
.meal-timeline { margin: 0; padding: 0; list-style: none; }
.meal-timeline li { display: grid; grid-template-columns: 54px 1fr auto; align-items: center; min-height: 46px; border-bottom: 1px solid var(--line); font-size: 12px; }
.meal-timeline time { color: var(--muted); font-variant-numeric: tabular-nums; }
.meal-timeline strong { color: var(--muted); }
.total-line { display: flex; justify-content: space-between; margin: 15px 0 1px; font-size: 13px; }
.total-line span { color: var(--muted); }
.coming-soon-card { display: flex; align-items: center; gap: 15px; margin-top: 14px; padding: 18px; border: 1px dashed rgba(255,255,255,.14); border-radius: var(--radius-lg); background: rgba(255,255,255,.018); }
.camera-placeholder { display: grid; flex: 0 0 auto; place-items: center; width: 62px; height: 62px; border-radius: 18px; background: rgba(255,255,255,.05); color: var(--muted); font-size: 23px; }
.soon-badge { display: inline-block; padding: 3px 7px; border-radius: 99px; background: rgba(244,189,104,.12); color: var(--warning); font-size: 8px; font-weight: 900; letter-spacing: .1em; text-transform: uppercase; }
.coming-soon-card h3 { margin: 6px 0 3px; font-size: 15px; }
.coming-soon-card p { margin: 0; color: var(--muted); font-size: 10px; }

.week-card { margin-bottom: 11px; padding: 18px; }
.week-card header { display: flex; align-items: center; gap: 13px; }
.week-number { display: grid; place-items: center; width: 42px; height: 42px; border: 1px solid var(--line); border-radius: 14px; color: var(--muted); font-size: 12px; font-weight: 850; }
.week-card header div { min-width: 0; flex: 1; }
.week-card header small { color: var(--accent); font-size: 9px; font-weight: 850; text-transform: uppercase; letter-spacing: .1em; }
.week-card h3 { margin: 1px 0 0; font-size: 16px; }
.week-card > p { margin: 14px 0 0 55px; color: var(--muted); font-size: 12px; }
.current-week { border-color: rgba(88,214,160,.26); background: linear-gradient(130deg, rgba(88,214,160,.07), transparent), var(--surface); }
.current-week .week-number { border-color: var(--accent); background: var(--accent); color: var(--accent-text); }
.current-badge { padding: 5px 8px; border-radius: 99px; background: rgba(88,214,160,.1); color: var(--accent); font-size: 8px; font-weight: 850; text-transform: uppercase; }
.week-card ul { margin: 16px 0 0; padding: 0; list-style: none; }
.week-card li { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-top: 1px solid var(--line); }
.week-card li i { color: var(--accent); font-size: 12px; font-style: normal; font-weight: 900; }
.week-card li span { display: flex; flex-direction: column; color: var(--muted); font-size: 10px; }
.week-card li strong { color: var(--text); font-size: 12px; }
.schedule-title { margin: 29px 2px 14px; }
.schedule-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 9px; }
.schedule-grid article { display: flex; min-height: 102px; padding: 14px; flex-direction: column; border: 1px solid var(--line); border-radius: var(--radius-md); background: var(--surface); }
.schedule-grid span { color: var(--accent); font-size: 9px; font-weight: 850; text-transform: uppercase; letter-spacing: .09em; }
.schedule-grid strong { margin-top: auto; font-size: 14px; }
.schedule-grid small { color: var(--muted); font-size: 9px; }
.safety-card { display: flex; gap: 13px; margin-top: 16px; padding: 17px; border: 1px solid rgba(244,189,104,.22); border-radius: var(--radius-lg); background: rgba(244,189,104,.06); }
.safety-icon { display: grid; flex: 0 0 auto; place-items: center; width: 33px; height: 33px; border-radius: 11px; background: var(--warning); color: #261b08; font-weight: 950; }
.safety-card h3 { margin: 1px 0 4px; font-size: 14px; }
.safety-card p { margin: 0; color: #c6b897; font-size: 11px; }
.mvp-exclusion, .demo-caption { color: var(--muted); font-size: 10px; text-align: center; }
.mvp-exclusion { margin: 12px 8px 0; }
.reset-button { width: 100%; min-height: 50px; margin-top: 28px; border: 1px solid rgba(255,136,125,.2); border-radius: 14px; background: transparent; color: var(--danger); font-size: 12px; font-weight: 800; cursor: pointer; }
.demo-caption { margin: 7px 0 0; }

.bottom-nav { position: fixed; right: 0; bottom: 0; left: 0; z-index: 10; display: grid; grid-template-columns: repeat(4, 1fr); width: min(100%, 720px); min-height: calc(70px + env(safe-area-inset-bottom)); margin: 0 auto; padding: 6px 8px env(safe-area-inset-bottom); border-top: 1px solid var(--line); background: color-mix(in srgb, var(--bg) 91%, transparent); backdrop-filter: blur(22px); -webkit-backdrop-filter: blur(22px); }
.tab-button { display: flex; min-height: 58px; align-items: center; justify-content: center; flex-direction: column; gap: 3px; border: 0; border-radius: 15px; background: transparent; color: var(--muted); cursor: pointer; }
.tab-button span { display: grid; place-items: center; width: 26px; height: 26px; font-size: 17px; font-weight: 800; }
.tab-button small { font-size: 9px; font-weight: 700; }
.tab-button.active { color: var(--accent); }
.tab-button.active span { background: rgba(88,214,160,.11); border-radius: 9px; }

@media (min-width: 560px) {
  main { padding-inline: 24px; }
  .app-header { padding-inline: 28px; }
  .metric-grid { grid-template-columns: repeat(4, 1fr); }
  .metric-card { min-height: 142px; }
  .nutrition-stats { grid-template-columns: repeat(2, 1fr); }
  .schedule-grid { grid-template-columns: repeat(4, 1fr); }
}
@media (max-width: 370px) {
  main { padding-inline: 12px; }
  .app-header { padding-inline: 16px; }
  .sobriety-card { padding: 19px; }
  .nutrition-ring { width: 94px; height: 94px; }
  .nutrition-hero { gap: 13px; padding: 16px; }
  .nutrition-hero h3 { font-size: 16px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
