:root {
  color-scheme: light dark;
  --bg: #0f1419;
  --surface: #1a222d;
  --text: #f4f7fb;
  --muted: #9aa7b8;
  --accent: #4ade80;
  --border: #2a3441;
  --danger: #f87171;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  padding-bottom: calc(1rem + env(safe-area-inset-bottom, 0px));
}

.build-meta {
  width: 100%;
  text-align: center;
  color: var(--muted);
  font-size: 0.75rem;
  margin: 0.25rem 0 0.75rem;
}

.container {
  width: 100%;
  max-width: 480px;
  margin: 0 auto;
  padding: 1.25rem;
  padding-left: calc(1.25rem + env(safe-area-inset-left, 0px));
  padding-right: calc(1.25rem + env(safe-area-inset-right, 0px));
  padding-bottom: calc(1.25rem + env(safe-area-inset-bottom, 0px));
}

.hero .eyebrow {
  margin: 0 0 0.5rem;
  color: var(--accent);
  font-size: 0.875rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.hero h1 {
  margin: 0 0 0.75rem;
  font-size: 2.25rem;
  line-height: 1.1;
}

.lead {
  margin: 0;
  color: var(--muted);
  font-size: 1.05rem;
}

.status-card,
.next-steps {
  margin-top: 1.5rem;
  padding: 1rem;
  border: 1px solid var(--border);
  border-radius: 1rem;
  background: var(--surface);
}

.status-card h2,
.next-steps h2 {
  margin: 0 0 0.75rem;
  font-size: 1rem;
}

.status-pill {
  display: inline-block;
  margin: 0;
  padding: 0.5rem 0.875rem;
  border-radius: 999px;
  background: #243041;
  font-weight: 600;
}

.status-pill.ok {
  color: var(--accent);
}

.status-pill.error {
  color: var(--danger);
}

.next-steps ul {
  margin: 0;
  padding-left: 1.25rem;
  color: var(--muted);
}

.next-steps li + li {
  margin-top: 0.35rem;
}

.next-steps li.done {
  color: var(--accent);
}

.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
}

.page-header h1 {
  margin: 0.25rem 0 0;
  font-size: 1.75rem;
  line-height: 1.1;
}

.scan-page-header {
  align-items: center;
}

.scan-page-header h1 {
  margin-top: 0;
}

.quick-actions {
  margin-top: 1.5rem;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 0.65rem 1rem;
  border: 1px solid var(--border);
  border-radius: 0.75rem;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
}

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #052e16;
}

.btn-secondary {
  background: #243041;
}

.btn-danger {
  background: #3f1d1d;
  border-color: #7f1d1d;
  color: #fecaca;
}

.btn-block {
  width: 100%;
}

.search-bar {
  margin-bottom: 1rem;
}

.search-bar input {
  width: 100%;
  min-height: 44px;
  padding: 0.75rem 1rem;
  border: 1px solid var(--border);
  border-radius: 0.75rem;
  background: var(--surface);
  color: var(--text);
  font: inherit;
}

.food-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.food-card,
.empty-state {
  padding: 1rem;
  border: 1px solid var(--border);
  border-radius: 1rem;
  background: var(--surface);
}

.food-card + .food-card,
.food-list .empty-state {
  margin-top: 0.75rem;
}

.food-card-top {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  align-items: flex-start;
}

.food-card h2 {
  margin: 0;
  font-size: 1.1rem;
}

.food-brand,
.food-meta {
  margin: 0.25rem 0 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.food-macros {
  margin: 0.75rem 0 0;
  font-size: 0.95rem;
}

.food-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.875rem;
}

.food-actions form {
  margin: 0;
}

.badge {
  display: inline-block;
  padding: 0.25rem 0.625rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 700;
  white-space: nowrap;
}

.badge-verified {
  background: #14532d;
  color: #bbf7d0;
}

.badge-unverified {
  background: #3f3f46;
  color: #e4e4e7;
}

.flash {
  margin: 0 0 1rem;
  padding: 0.75rem 1rem;
  border-radius: 0.75rem;
  font-weight: 600;
}

.flash-ok {
  background: #14532d;
  color: #bbf7d0;
}

.flash-error {
  background: #3f1d1d;
  color: #fecaca;
}

.food-form label,
.delete-form {
  display: block;
  margin-bottom: 0.875rem;
}

.food-form label {
  color: var(--muted);
  font-size: 0.875rem;
}

.food-form input,
.food-form textarea {
  display: block;
  width: 100%;
  margin-top: 0.35rem;
  min-height: 44px;
  padding: 0.75rem 1rem;
  border: 1px solid var(--border);
  border-radius: 0.75rem;
  background: #111821;
  color: var(--text);
  font: inherit;
}

.food-form textarea {
  min-height: 96px;
  resize: vertical;
}

.checkbox-row {
  display: flex !important;
  align-items: center;
  gap: 0.625rem;
  color: var(--text) !important;
}

.checkbox-row input {
  width: auto;
  min-height: auto;
  margin: 0;
}

.field-hint {
  margin: -0.5rem 0 0.875rem;
  color: var(--muted);
  font-size: 0.85rem;
}

.macro-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
  margin-bottom: 0.875rem;
}

.delete-form {
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
}

.empty-state p {
  margin: 0 0 0.875rem;
  color: var(--muted);
}

.recipe-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.recipe-card {
  padding: 1rem;
  border: 1px solid var(--border);
  border-radius: 1rem;
  background: var(--surface);
}

.recipe-card + .recipe-card,
.recipe-list .empty-state {
  margin-top: 0.75rem;
}

.recipe-card-top {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  align-items: flex-start;
}

.recipe-card h2 {
  margin: 0;
  font-size: 1.1rem;
}

.card-link {
  color: inherit;
  text-decoration: none;
}

.recipe-description,
.recipe-meta,
.recipe-instructions,
.ingredient-meta,
.ingredient-note {
  margin: 0.25rem 0 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.recipe-macros {
  margin: 0.75rem 0 0.5rem;
  font-size: 0.95rem;
}

.recipe-card .btn {
  margin-top: 0.75rem;
}

.badge-neutral {
  background: #243041;
  color: var(--muted);
}

.macro-summary {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.macro-box {
  padding: 1rem;
  border: 1px solid var(--border);
  border-radius: 1rem;
  background: var(--surface);
}

.macro-box h2 {
  margin: 0 0 0.5rem;
  font-size: 0.875rem;
  color: var(--muted);
}

.macro-box p {
  margin: 0;
  font-size: 1.1rem;
  font-weight: 700;
}

.macro-detail {
  margin-top: 0.35rem !important;
  font-size: 0.85rem !important;
  font-weight: 500 !important;
  color: var(--muted) !important;
}

.detail-section {
  margin-top: 1.25rem;
  padding: 1rem;
  border: 1px solid var(--border);
  border-radius: 1rem;
  background: var(--surface);
}

.section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.875rem;
}

.section-header h2,
.detail-section > h2 {
  margin: 0 0 0.875rem;
  font-size: 1rem;
}

.section-header h2 {
  margin-bottom: 0;
}

.ingredient-list {
  list-style: none;
  margin: 0 0 1rem;
  padding: 0;
}

.ingredient-card {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  align-items: center;
  padding: 0.75rem 0;
  border-bottom: 1px solid var(--border);
}

.ingredient-card:last-child {
  border-bottom: none;
}

.inline-empty {
  padding: 0.5rem 0;
}

.recipe-form label,
.inline-form label {
  display: block;
  margin-bottom: 0.875rem;
  color: var(--muted);
  font-size: 0.875rem;
}

.recipe-form input,
.recipe-form textarea,
.inline-form input,
.inline-form select {
  display: block;
  width: 100%;
  margin-top: 0.35rem;
  min-height: 44px;
  padding: 0.75rem 1rem;
  border: 1px solid var(--border);
  border-radius: 0.75rem;
  background: #111821;
  color: var(--text);
  font: inherit;
}

.recipe-form textarea {
  min-height: 96px;
  resize: vertical;
}

.btn-small {
  min-height: 36px;
  padding: 0.4rem 0.75rem;
  font-size: 0.875rem;
}

.quick-actions .btn + .btn {
  margin-top: 0.5rem;
}

.date-picker {
  margin-bottom: 1rem;
}

.date-picker label {
  display: block;
  color: var(--muted);
  font-size: 0.875rem;
}

.date-picker input {
  display: block;
  width: 100%;
  margin-top: 0.35rem;
  min-height: 44px;
  padding: 0.75rem 1rem;
  border: 1px solid var(--border);
  border-radius: 0.75rem;
  background: var(--surface);
  color: var(--text);
  font: inherit;
}

.macro-box-wide {
  grid-column: 1 / -1;
}

.pick-list,
.meal-log-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.pick-list li + li,
.meal-log-card + .meal-log-card {
  margin-top: 0.5rem;
}

.pick-card {
  display: block;
  padding: 1rem;
  border: 1px solid var(--border);
  border-radius: 0.75rem;
  background: #111821;
  color: inherit;
  text-decoration: none;
}

.pick-card strong {
  display: block;
}

.pick-card span {
  display: block;
  margin-top: 0.25rem;
  color: var(--muted);
  font-size: 0.9rem;
}

.pick-meta {
  font-size: 0.85rem !important;
}

.meal-log-card {
  padding: 0.875rem 0;
  border-bottom: 1px solid var(--border);
}

.meal-log-card:last-child {
  border-bottom: none;
}

.meal-log-meta,
.meal-log-calculation {
  margin: 0.35rem 0 0;
  color: var(--muted);
  font-size: 0.85rem;
}

.meal-log-calculation {
  font-size: 0.8rem;
}

.meal-log-top .badge {
  margin-left: 0.35rem;
}

.macro-over {
  color: var(--danger);
}

.target-note {
  margin: 0 0 1rem;
  color: var(--muted);
  font-size: 0.9rem;
}

.target-note a {
  color: var(--accent);
}

.target-list {
  list-style: none;
  margin: 0 0 1rem;
  padding: 0;
}

.target-card {
  padding: 1rem;
  border: 1px solid var(--border);
  border-radius: 1rem;
  background: var(--surface);
}

.target-card + .target-card {
  margin-top: 0.75rem;
}

.bottom-nav {
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
  margin-top: 1.5rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
}

.weight-list {
  list-style: none;
  margin: 0 0 1rem;
  padding: 0;
}

.weight-card {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  align-items: center;
  padding: 1rem;
  border: 1px solid var(--border);
  border-radius: 1rem;
  background: var(--surface);
}

.weight-card + .weight-card {
  margin-top: 0.75rem;
}

.bottom-nav a {
  flex: 1;
  text-align: center;
  padding: 0.75rem 0.25rem;
  border-radius: 0.75rem;
  background: var(--surface);
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 600;
  text-decoration: none;
}

.page-error {
  margin-top: 2rem;
  text-align: center;
}

.page-error h1 {
  margin: 0 0 0.5rem;
  font-size: 2rem;
}

.empty-state.page-error .btn {
  margin-top: 1rem;
}

.scan-camera-wrap {
  margin: 1rem 0;
  position: relative;
}

html.scan-overlay-open,
html.scan-page-active {
  overflow: hidden;
}

html.scan-overlay-open body,
html.scan-page-active body {
  margin: 0;
  overflow: hidden;
}

html.scan-overlay-open .build-meta,
html.scan-page-active .build-meta {
  display: none;
}

.scan-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: #000;
}

.scan-page-fullscreen {
  margin: -1rem;
  min-height: calc(100dvh - 2rem);
}

@media (max-width: 768px) {
  html.scan-page-active main.container {
    position: fixed;
    inset: 0;
    max-width: none;
    width: 100%;
    height: 100dvh;
    padding: 0;
    margin: 0;
  }

  .scan-page-fullscreen {
    position: fixed;
    inset: 0;
    margin: 0;
    width: 100%;
    height: 100dvh;
    min-height: 100dvh;
  }

  .scan-page-error {
    position: absolute;
    top: max(0.75rem, env(safe-area-inset-top));
    left: 1rem;
    right: 1rem;
    z-index: 5;
  }
}

.scan-shell {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100%;
  min-height: 100dvh;
  background: #000;
  color: #fff;
}

.scan-shell-header {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 4;
  padding: max(0.75rem, env(safe-area-inset-top)) 0.75rem 0.5rem;
}

.scan-shell-close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.5rem;
  height: 2.5rem;
  border: 0;
  border-radius: 999px;
  background: rgb(0 0 0 / 42%);
  color: #fff;
  font-size: 1.35rem;
  line-height: 1;
}

.scan-shell-viewfinder {
  position: absolute;
  inset: 0;
  flex: none;
  overflow: hidden;
  background: #000;
}

.scan-shell-viewfinder #scan-reader,
.scan-shell-viewfinder .scan-reader-mobile {
  position: absolute;
  inset: 0;
  width: 100% !important;
  height: 100% !important;
  min-height: 0;
  max-height: none;
  aspect-ratio: auto;
  border: 0;
  border-radius: 0;
}

.scan-shell-viewfinder #scan-reader > div,
.scan-shell-viewfinder #scan-reader__dashboard > div {
  width: 100% !important;
  height: 100% !important;
}

.scan-shell-viewfinder #scan-reader video {
  position: absolute !important;
  inset: 0 !important;
  width: 100% !important;
  height: 100% !important;
  object-fit: cover !important;
  display: block !important;
}

.scan-shell-viewfinder #scan-reader__dashboard {
  width: 100% !important;
  height: 100% !important;
  border: none !important;
  padding: 0 !important;
  margin: 0 !important;
  background: transparent !important;
}

.scan-shell-viewfinder #scan-reader__dashboard_section_csr {
  border: none !important;
  box-shadow: none !important;
}

.scan-shell-viewfinder #scan-reader__header_message,
.scan-shell-viewfinder #scan-reader__dashboard_section_swaplink,
.scan-shell-viewfinder #scan-reader__dashboard_section_fsr {
  display: none !important;
}

.scan-shell-frame {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}

.scan-shell-frame-box {
  width: min(82vw, 360px);
  height: min(28vh, 180px);
  border: 3px solid rgb(255 255 255 / 92%);
  border-radius: 1.1rem;
  box-shadow: 0 0 0 9999px rgb(0 0 0 / 38%);
}

.scan-shell--label .scan-shell-frame-box {
  width: min(88vw, 380px);
  height: min(52vh, 340px);
}

.scan-shell-caption {
  margin: 1rem 0 0;
  padding: 0 1rem;
  color: #fff;
  font-size: 1rem;
  font-weight: 500;
  text-align: center;
  text-shadow: 0 1px 8px rgb(0 0 0 / 65%);
}

.scan-shell-status {
  position: absolute;
  left: 50%;
  bottom: calc(6.5rem + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 4;
  margin: 0;
  padding: 0.35rem 0.75rem;
  border-radius: 999px;
  background: rgb(0 0 0 / 55%);
  color: #fff;
  font-size: 0.85rem;
  white-space: nowrap;
}

.scan-shell-toolbar {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 4;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 1rem;
  padding: 1rem 1.5rem max(1.25rem, env(safe-area-inset-bottom));
  background: linear-gradient(transparent, rgb(0 0 0 / 78%));
}

.scan-shell-tool {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 3rem;
  height: 3rem;
  border-radius: 999px;
  background: rgb(255 255 255 / 14%);
  color: #fff;
  cursor: pointer;
}

.scan-shell-tool-icon {
  font-size: 1.2rem;
  line-height: 1;
}

.scan-shell-torch {
  justify-self: end;
}

.scan-shell-shutter {
  width: 4.6rem;
  height: 4.6rem;
  border: 4px solid #fff;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 0 0 4px rgb(255 255 255 / 22%);
  justify-self: center;
}

.scan-shell-shutter:active {
  transform: scale(0.96);
}

.scan-camera-wrap.scan-camera-live .scan-camera-hint {
  display: none;
}

.scan-camera-wrap #scan-reader video {
  width: 100% !important;
  height: 100% !important;
  object-fit: cover !important;
  display: block !important;
}

.scan-camera-wrap #scan-reader__dashboard {
  width: 100% !important;
  height: 100% !important;
  border: none !important;
  padding: 0 !important;
  margin: 0 !important;
}

.scan-camera-wrap #scan-reader__header_message {
  display: none !important;
}

.scan-reader {
  position: relative;
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 1rem;
  overflow: hidden;
  background: #000;
  aspect-ratio: 16 / 9;
  min-height: 180px;
  max-height: none;
}

.scan-reader[hidden] {
  display: none !important;
}

.scan-reader video,
.scan-video {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
  min-height: 0;
  background: #000;
}

.scan-guide {
  position: absolute;
  inset: 0;
  pointer-events: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
}

.scan-start-btn {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  z-index: 2;
  min-width: 11rem;
}

.scan-camera-hint {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  z-index: 2;
  margin: 0;
  padding: 0.5rem 0.75rem;
  border-radius: 0.5rem;
  background: rgb(0 0 0 / 55%);
  color: #fff;
  font-size: 0.9rem;
  text-align: center;
  pointer-events: none;
}

.scan-guide-box {
  width: 96%;
  height: 54%;
  max-height: 220px;
  border: 1.5px solid color-mix(in srgb, var(--accent) 82%, white 18%);
  border-radius: 0.5rem;
  box-shadow: 0 0 0 9999px rgb(0 0 0 / 18%);
}

.scan-guide-box-tall {
  height: 55%;
  max-height: 280px;
}

.scan-guide-text {
  margin: 0;
  padding: 0.2rem 0.5rem;
  border-radius: 0.5rem;
  background: rgb(0 0 0 / 42%);
  color: var(--text);
  font-size: 0.8rem;
}

.scan-file-btn {
  margin-bottom: 0.75rem;
  cursor: pointer;
  text-align: center;
}

.scan-manual-form {
  display: grid;
  gap: 0.75rem;
  margin-top: 1rem;
}

.scan-status {
  margin-top: 0.5rem;
}

.scan-actions {
  display: grid;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}

@media (max-width: 480px) {
  .container {
    padding: 1rem;
    padding-left: calc(1rem + env(safe-area-inset-left, 0px));
    padding-right: calc(1rem + env(safe-area-inset-right, 0px));
    padding-bottom: calc(1.5rem + env(safe-area-inset-bottom, 0px));
  }

  .page-header {
    flex-wrap: wrap;
    gap: 0.75rem;
  }

  .page-header h1 {
    font-size: 1.6rem;
  }

  .page-header .btn {
    margin-left: auto;
  }

  .food-card-top,
  .recipe-card-top,
  .section-header {
    flex-direction: column;
    align-items: flex-start;
  }

  .macro-grid,
  .macro-summary {
    grid-template-columns: 1fr;
  }

  .scan-reader {
    width: 100%;
    aspect-ratio: 16 / 9;
    min-height: 0;
    max-height: none;
  }

  .scan-guide-box {
    width: 94%;
    height: 50%;
  }

  .scan-manual-form {
    margin-bottom: calc(1.25rem + env(safe-area-inset-bottom, 0px));
  }
}

