:root {
  color-scheme: dark;
  --ink: #11130f;
  --surface: #1a1d18;
  --surface-raised: #22271f;
  --line: #353c30;
  --text: #f3f5ed;
  --muted: #b4bbad;
  --lime: #c8f560;
  --lime-ink: #17210a;
  --danger: #f1a89d;
  --radius: 14px;
  --page-gutter: clamp(14px, 4vw, 20px);
  --nav-height: 60px;
  --nav-offset: max(10px, env(safe-area-inset-bottom));
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

html {
  background: var(--ink);
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  scroll-padding-bottom: calc(var(--nav-height) + var(--nav-offset) + 20px);
}

html, body { min-height: 100%; }

body {
  margin: 0;
  min-width: 320px;
  overflow-x: hidden;
  overscroll-behavior-y: contain;
  background: var(--ink);
  color: var(--text);
  font-size: 16px;
  line-height: 1.45;
  -webkit-tap-highlight-color: transparent;
}

button, input, select, textarea { font: inherit; }

button, input, select, textarea, summary { min-height: 44px; }

button, summary, label, input, select { touch-action: manipulation; }

button { cursor: pointer; }

button:disabled { cursor: not-allowed; opacity: .62; }

button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, summary:focus-visible, a:focus-visible {
  outline: 3px solid var(--lime);
  outline-offset: 3px;
}

[hidden] { display: none !important; }

.app-shell {
  width: min(100%, 560px);
  min-height: 100dvh;
  margin: 0 auto;
  padding:
    max(8px, env(safe-area-inset-top))
    max(var(--page-gutter), env(safe-area-inset-right))
    calc(var(--nav-height) + var(--nav-offset) + 24px)
    max(var(--page-gutter), env(safe-area-inset-left));
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 52px;
  gap: 12px;
}

.brand {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  padding-block: 9px;
  gap: 8px;
  color: var(--text);
  font-size: 1.1rem;
  font-weight: 800;
  letter-spacing: .12em;
  text-decoration: none;
}

.brand-mark {
  width: 9px;
  height: 9px;
  border-radius: 999px;
  background: var(--lime);
}

.connection-status, .eyebrow, .field-help, .profile-label {
  margin: 0;
  color: var(--muted);
  font-size: .75rem;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
}

.connection-status.is-offline { color: var(--danger); }

.feedback {
  position: sticky;
  top: 8px;
  z-index: 3;
  margin: 8px 0;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-raised);
  color: var(--text);
}

.feedback.is-error { border-color: var(--danger); color: var(--danger); }
.feedback.is-success { border-color: var(--lime); }

.auth-view { padding-top: clamp(28px, 8vh, 78px); }

.auth-intro { max-width: 28rem; margin-bottom: 28px; }

h1, h2, p { overflow-wrap: anywhere; }

h1, h2 { margin: 0; line-height: 1.05; letter-spacing: -.035em; }
h1 { font-size: clamp(2rem, 8.5vw, 2.4rem); }
h2 { font-size: 1.25rem; }

.auth-intro h1 { margin-top: 8px; }
.auth-intro > p:last-child { margin: 16px 0 0; color: var(--muted); }

.panel, .mission-card, .today-card, .empty-state, .error-state, .loading-state {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.panel { padding: clamp(14px, 4vw, 18px); }

.form-stack { display: grid; gap: 12px; }

.form-stack label {
  display: grid;
  gap: 6px;
  color: var(--text);
  font-size: .9rem;
  font-weight: 700;
}

input, select, textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 10px 12px;
  background: var(--ink);
  color: var(--text);
}

input:not([type="file"]):not([type="range"]):not([type="checkbox"]), select { border-radius: 999px; }
textarea { resize: vertical; line-height: 1.45; }
input[type="range"] { min-height: 44px; padding: 0; border: 0; accent-color: var(--lime); }

input::placeholder { color: var(--muted); opacity: 1; }

.field-help { letter-spacing: 0; text-transform: none; }

.form-error { margin: 0; color: var(--danger); font-size: .9rem; }

.button, .text-button, .nav-button {
  border: 0;
  border-radius: 999px;
  font-weight: 800;
  transition: transform 160ms ease, background-color 160ms ease, color 160ms ease;
}

.button:active, .text-button:active, .nav-button:active { transform: scale(.98); }

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  padding: 10px 16px;
}

.button-primary { background: var(--lime); color: var(--lime-ink); }
.button-secondary { border: 1px solid var(--line); background: transparent; color: var(--text); }
.button-danger { border: 1px solid var(--danger); background: transparent; color: var(--danger); }
.button-icon { width: 44px; padding: 0; font-size: 1.5rem; }

.text-button { min-height: 44px; padding: 8px 4px; background: transparent; color: var(--lime); text-align: left; }

.app-view { padding-top: 18px; }
.screen { animation: enter 180ms ease-out both; }
.screen-heading { margin-bottom: 16px; }
.screen-heading h1 { margin-top: 7px; }
.screen-heading-row, .form-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.content-region { display: grid; gap: 12px; }
.today-date { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 10px; text-transform: capitalize; }
.today-date .text-button { flex: 0 0 auto; text-align: right; }

.today-summary { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 9px; }
.summary-stat { min-width: 0; padding: 14px; }
.summary-stat strong { display: block; color: var(--lime); font-size: 1.35rem; line-height: 1; }
.summary-stat span { display: block; margin-top: 7px; color: var(--muted); font-size: .76rem; }

.mission-list { display: grid; gap: 10px; }
.today-card, .mission-card { padding: 14px; }
.mission-card { display: grid; gap: 12px; }
.mission-row { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.mission-title { margin: 0; font-size: 1rem; }
.mission-meta { margin: 5px 0 0; color: var(--muted); font-size: .84rem; }
.xp-badge { flex: 0 0 auto; padding: 6px 9px; border-radius: 999px; background: #2e3921; color: var(--lime); font-size: .76rem; font-weight: 800; }
.mission-actions { display: flex; gap: 8px; }
.mission-actions .button { width: auto; min-width: 44px; padding: 8px 12px; }
.button-complete { background: var(--lime); color: var(--lime-ink); }
.button-undo { background: var(--surface-raised); color: var(--text); }
.button-compact { background: transparent; color: var(--text); border: 1px solid var(--line); }
.button-deactivate { background: transparent; color: var(--danger); border: 1px solid var(--danger); }

.is-mobility-locked .app-shell {
  padding-bottom: max(18px, env(safe-area-inset-bottom));
}

.is-mobility-locked .app-view { padding-top: 8px; }

.mobility-gate {
  display: grid;
  align-content: center;
  min-height: calc(100dvh - max(8px, env(safe-area-inset-top)) - 78px - max(18px, env(safe-area-inset-bottom)));
  gap: 16px;
  overflow: hidden;
  border-color: #53643d;
  background:
    radial-gradient(circle at 92% 4%, rgba(200, 245, 96, .13), transparent 34%),
    linear-gradient(160deg, #20251c, #171a15 68%);
}

.mobility-gate-lock {
  justify-self: start;
  padding: 6px 9px;
  border: 1px solid var(--lime);
  border-radius: 999px;
  color: var(--lime);
  font-size: .68rem;
  font-weight: 900;
  letter-spacing: .13em;
}

.mobility-gate h2 {
  max-width: 9ch;
  color: var(--text);
  font-size: clamp(2.8rem, 14vw, 4.6rem);
  letter-spacing: -.06em;
}

.mobility-gate-message {
  max-width: 31rem;
  margin: -4px 0 0;
  color: var(--muted);
  font-size: 1rem;
}

.mobility-gate-steps {
  display: grid;
  gap: 8px;
  margin: 0;
  padding-left: 1.35rem;
  color: var(--text);
  font-size: .9rem;
}

.mobility-proof-picker {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 52px;
  padding: 11px 16px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--ink);
  color: var(--lime);
  font-weight: 800;
  cursor: pointer;
  text-align: center;
}

.mobility-proof-picker:has(input:focus-visible) {
  outline: 3px solid var(--lime);
  outline-offset: 3px;
}

.mobility-proof-picker input {
  position: absolute;
  width: 1px;
  height: 1px;
  min-height: 1px;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
}

.mobility-proof-preview { display: grid; gap: 8px; }
.mobility-proof-preview img {
  width: 100%;
  max-height: 220px;
  border-radius: var(--radius);
  object-fit: cover;
  background: var(--ink);
}
.mobility-proof-preview p { margin: 0; color: var(--muted); font-size: .82rem; }
.mobility-proof-submit { min-height: 54px; }
.proof-confirmation { color: var(--lime); font-size: .82rem; font-weight: 800; }
.mobility-journal-status { padding: 10px 0; }

.empty-state, .error-state, .loading-state { padding: 22px 18px; }
.empty-state h2, .error-state h2, .loading-state h2 { font-size: 1.1rem; }
.empty-state p, .error-state p, .loading-state p { margin: 8px 0 0; color: var(--muted); }
.error-state { border-color: var(--danger); }
.error-state h2 { color: var(--danger); }
.loading-skeleton { height: 13px; margin-top: 14px; border-radius: 999px; background: #31382c; animation: pulse 1.2s ease-in-out infinite; }
.loading-skeleton.short { width: 57%; }

.form-grid, .journal-grid, .measurements-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.date-control { display: grid; width: 142px; gap: 4px; color: var(--muted); font-size: .72rem; font-weight: 700; text-transform: uppercase; }
.date-control input { min-height: 44px; padding: 7px 9px; color-scheme: dark; }
.form-stack output { float: right; color: var(--lime); font-weight: 800; }
.photo-field { display: grid; gap: 8px; }
.file-picker { position: relative; display: flex !important; align-items: center; justify-content: center; min-height: 48px; padding: 10px 14px; border: 1px solid var(--line); border-radius: 999px; background: var(--ink); color: var(--lime) !important; cursor: pointer; text-align: center; }
.file-picker input { position: absolute; width: 1px; height: 1px; min-height: 1px; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap; }
.photo-preview { display: grid; gap: 10px; }
.photo-preview img { width: 100%; max-height: 420px; border-radius: var(--radius); object-fit: cover; background: var(--surface-raised); }
.measurements-panel { border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface-raised); }
.measurements-panel summary { display: flex; align-items: center; padding: 10px 13px; cursor: pointer; color: var(--text); font-weight: 800; }
.measurements-grid { padding: 0 12px 12px; }
.measurements-grid label:last-child { grid-column: 1 / -1; }
.journal-history { margin-top: 12px; }
.history-panel { display: grid; gap: 14px; }
.history-panel h2, .weight-delta { margin: 6px 0 0; }
.weight-delta { color: var(--lime); font-size: .9rem; }
.history-list { display: grid; gap: 8px; }
.history-day { display: grid; grid-template-columns: 60px 1fr; gap: 3px 10px; width: 100%; min-height: 64px; padding: 10px; border: 1px solid var(--line); border-radius: 12px; background: var(--ink); color: var(--text); text-align: left; }
.history-day strong { grid-row: 1 / 5; color: var(--lime); text-transform: capitalize; }
.history-day span { color: var(--muted); font-size: .78rem; }
.weekdays-field { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin: 0; padding: 10px; border: 1px solid var(--line); border-radius: var(--radius); }
.weekdays-field legend { padding: 0 5px; color: var(--muted); font-size: .8rem; font-weight: 700; }
.weekdays-field label { display: flex; align-items: center; gap: 5px; min-height: 44px; }
.weekdays-field input { width: 20px; min-height: 20px; accent-color: var(--lime); }
.toggle-control { display: flex !important; align-items: center; gap: 10px; min-height: 44px; }
.toggle-control input { flex: 0 0 22px; width: 22px; min-height: 22px; accent-color: var(--lime); }
.form-note { margin: 0; color: var(--muted); font-size: .9rem; }
.shopping-total { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 14px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface-raised); }
.shopping-total strong { color: var(--lime); }
#shopping-form { margin-top: 12px; }
.food-search input { margin-top: 6px; }
.custom-food-panel { display: grid; gap: 10px; }
.custom-food-fields { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; padding: 12px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface-raised); }
.custom-food-fields > label:first-child, .custom-food-submit { grid-column: 1 / -1; }
.food-catalog { display: grid; gap: 20px; }
.food-category { display: grid; gap: 8px; }
.food-category h3 { margin: 0; color: var(--muted); font-size: .78rem; letter-spacing: .08em; text-transform: uppercase; }
.food-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 8px; }
.food-row {
  display: grid;
  grid-template-columns: 64px minmax(0, 1fr) 52px;
  align-items: center;
  gap: 10px;
  min-height: 82px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface-raised);
}
.food-row.is-selected { border-color: rgb(198 255 77 / .46); }
.food-image, .shopping-item-image { display: block; object-fit: cover; background: var(--ink); }
.food-image { width: 64px; height: 64px; border-radius: 11px; }
.food-copy { display: grid; min-width: 0; gap: 3px; }
.food-copy strong { min-width: 0; font-size: .95rem; line-height: 1.2; overflow-wrap: anywhere; }
.food-copy span { color: var(--muted); font-size: .72rem; font-weight: 600; line-height: 1.2; }
.food-remove { min-height: 44px; width: fit-content; padding: 8px 0; background: transparent; color: var(--danger); font-size: .78rem; text-align: left; }
.food-add {
  width: 48px;
  min-height: 48px;
  padding: 0;
  border-radius: 50%;
  background: var(--lime);
  color: var(--lime-ink);
  font-size: 1.9rem;
  font-weight: 700;
  line-height: 1;
}
.food-add:active { transform: scale(.96); }
.food-add:disabled { border: 1px solid var(--line); background: var(--ink); color: var(--lime); opacity: 1; }
.visually-hidden { position: absolute !important; width: 1px !important; height: 1px !important; overflow: hidden !important; clip: rect(0 0 0 0) !important; clip-path: inset(50%) !important; white-space: nowrap !important; }

.shopping-result { display: grid; gap: 12px; }
.shopping-result h2 { font-size: 1.15rem; }
.shopping-list-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.shopping-list-actions { display: flex; align-items: center; gap: 10px; }
.shopping-list-actions .text-button { min-height: 44px; padding-inline: 2px; }
.shopping-check-list { display: grid; gap: 8px; }
.shopping-check-row { display: grid; grid-template-columns: minmax(0, 1fr) 44px; align-items: center; gap: 6px 10px; min-height: 68px; padding: 8px; border: 1px solid var(--line); border-radius: 14px; background: var(--surface-raised); }
.shopping-check-main { display: grid !important; grid-template-columns: 22px 48px minmax(0, 1fr); align-items: center; gap: 10px; min-width: 0; cursor: pointer; }
.shopping-check-main input { width: 22px; min-height: 22px; accent-color: var(--lime); }
.shopping-item-image { width: 48px; height: 48px; border-radius: 10px; }
.shopping-check-main span { display: grid; min-width: 0; gap: 1px; }
.shopping-check-main strong { overflow-wrap: anywhere; }
.shopping-check-main small { color: var(--muted); }
.shopping-item-remove { width: 44px; min-height: 44px; padding: 0; background: transparent; color: var(--muted); font-size: 1.45rem; }
.shopping-item-details { grid-column: 1 / -1; padding-left: 80px; }
.shopping-item-details summary { min-height: 44px; padding: 10px 0; color: var(--lime); font-size: .82rem; font-weight: 700; cursor: pointer; }
.shopping-item-fields { display: grid; grid-template-columns: minmax(0, 1fr) 110px; gap: 8px; padding: 2px 0 8px; }
.shopping-item-fields label { gap: 5px; color: var(--muted); font-size: .75rem; }
.shopping-item-fields input, .shopping-item-fields select { min-height: 44px; padding: 8px; }
.shopping-check-row.is-checked .shopping-item-image { opacity: .58; }
.shopping-check-row.is-checked .shopping-check-main strong { text-decoration: line-through; }

.profile-panel { display: grid; gap: 12px; }
.goals-panel { margin-top: 12px; }
.profile-value { margin: 0 0 8px; color: var(--lime); font-size: 1.1rem; font-weight: 800; }
.profile-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.profile-stat { display: grid; gap: 4px; padding: 12px 8px; border: 1px solid var(--line); border-radius: 10px; text-align: center; }
.profile-stat strong { color: var(--lime); font-size: 1.35rem; }
.profile-stat span { color: var(--muted); font-size: 0.72rem; line-height: 1.2; }
.profile-panel progress { width: 100%; height: 12px; accent-color: var(--lime); }
.install-panel { display: grid; gap: 10px; margin-top: 12px; }
.install-panel h2, .install-panel p { margin: 0; }
.install-panel p { color: var(--muted); line-height: 1.5; }
.install-panel strong { color: var(--text); }

.bottom-nav {
  position: fixed;
  right: max(10px, env(safe-area-inset-right));
  bottom: var(--nav-offset);
  left: max(10px, env(safe-area-inset-left));
  z-index: 5;
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  width: auto;
  max-width: 536px;
  min-height: var(--nav-height);
  margin: 0 auto;
  padding: 5px;
  border: 1px solid var(--line);
  border-radius: 22px;
  background: rgb(27 31 25 / .96);
  box-shadow: 0 12px 28px rgb(0 0 0 / .28);
  backdrop-filter: blur(18px) saturate(130%);
  -webkit-backdrop-filter: blur(18px) saturate(130%);
}

.nav-button {
  min-width: 0;
  min-height: 48px;
  overflow: hidden;
  padding: 4px 1px;
  border-radius: 16px;
  background: transparent;
  color: var(--muted);
  font-size: .7rem;
  line-height: 1.05;
  white-space: nowrap;
}
.nav-icon { display: block; margin-bottom: 4px; font-size: 1rem; line-height: 1; }
.nav-label { display: block; overflow: hidden; text-overflow: clip; }
.nav-button.is-active { background: var(--lime); color: var(--lime-ink); }

.noscript { margin: 0; padding: 16px; background: var(--surface); color: var(--text); }

@keyframes enter { from { opacity: 0; transform: translateY(5px); } to { opacity: 1; transform: translateY(0); } }
@keyframes pulse { 50% { opacity: .45; } }

@media (max-width: 430px) {
  .screen-heading-row { gap: 10px; }
  .today-summary { gap: 6px; }
  .summary-stat { min-height: 86px; padding: 12px 10px; }
  .summary-stat strong { font-size: 1.2rem; }
  .today-card, .mission-card { padding: 13px; }
  .journal-grid,
  .goals-panel .form-grid { grid-template-columns: 1fr; gap: 12px; }
  .profile-stats { gap: 6px; }
  .profile-stat { padding: 11px 6px; }
  .profile-stat span { font-size: .75rem; }
}

@media (max-width: 350px) {
  .nav-label {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    clip-path: inset(50%);
    white-space: nowrap;
  }
  .nav-icon { margin-bottom: 0; font-size: 1.15rem; }
  .today-date { align-items: flex-start; flex-direction: column; gap: 2px; }
  .food-row { grid-template-columns: 56px minmax(0, 1fr) 48px; gap: 8px; }
  .food-image { width: 56px; height: 56px; }
  .shopping-item-details { padding-left: 0; }
  .shopping-item-fields { grid-template-columns: minmax(0, 1fr) 100px; }
  .custom-food-fields { grid-template-columns: 1fr; }
  .custom-food-fields > label:first-child, .custom-food-submit { grid-column: auto; }
  .measurements-grid { grid-template-columns: 1fr; }
  .measurements-grid label:last-child { grid-column: auto; }
  .weekdays-field { grid-template-columns: repeat(2, 1fr); }
}

@media (min-width: 540px) {
  .app-shell {
    padding-right: max(24px, env(safe-area-inset-right));
    padding-left: max(24px, env(safe-area-inset-left));
  }
}

@media (orientation: landscape) and (max-height: 500px) {
  :root { --nav-height: 50px; }
  .bottom-nav { padding: 3px; }
  .nav-button { min-height: 44px; }
  .nav-label {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    clip-path: inset(50%);
    white-space: nowrap;
  }
  .nav-icon { margin-bottom: 0; }
}

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