@import url('https://fonts.googleapis.com/css2?family=Geist:wght@400;500;600;700;800&display=swap');

:root {
  color-scheme: light;
  --cream: #0b0d12;
  --paper: #141820;
  --ink: #f1f3f7;
  --green: #40532a;
  --lime: #c9fa71;
  --line: #303745;
  --muted: #aab4c4;
  font-family: Geist, system-ui, sans-serif;
  color: var(--ink);
  background: var(--cream);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html { scroll-padding-top: calc(70px + env(safe-area-inset-top, 0px)); }
body { margin: 0; isolation: isolate; min-height: 100vh; }
main {
  max-width: 900px;
  margin: 0 auto;
  padding: max(16px, env(safe-area-inset-top)) 16px max(20px, env(safe-area-inset-bottom));
}

.hero {
  position: relative;
  isolation: isolate;
  display: flex;
  align-items: center;
  min-height: 190px;
  overflow: hidden;
  border-radius: 24px;
  padding: clamp(20px, 5vw, 48px);
  background: var(--green);
  color: var(--paper);
}

h1, h2, h3, p { margin: 0; }
h1 {
  position: relative;
  z-index: 1;
  font-size: clamp(40px, 9vw, 86px);
  font-weight: 800;
  line-height: .95;
  letter-spacing: -.075em;
}

.barcode-art {
  position: absolute;
  right: 2%;
  width: clamp(92px, 26vw, 238px);
  aspect-ratio: 1;
  transform: rotate(-13deg);
  border-radius: 32% 44% 32% 44%;
  background: var(--lime);
  display: grid;
  place-items: center;
}

.barcode-art span {
  width: 62%;
  height: 39%;
  background: repeating-linear-gradient(
    90deg,
    var(--ink) 0 3%, transparent 3% 6%,
    var(--ink) 6% 8%, transparent 8% 10%,
    var(--ink) 10% 15%, transparent 15% 19%
  );
}

.panels {
  display: grid;
  align-items: start;
  gap: 12px;
  margin: 12px 0 16px;
}

section {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 22px;
  padding: clamp(16px, 4vw, 24px);
  background: var(--paper);
}

h2 {
  margin-bottom: 14px;
  font-size: clamp(22px, 5vw, 28px);
  letter-spacing: -.045em;
}

h3 { overflow-wrap: anywhere; }
label {
  display: block;
  margin-bottom: 5px;
  font-size: 14px;
  font-weight: 650;
}

.row { display: flex; align-items: center; gap: 8px; }
input, button {
  min-height: 46px;
  border-radius: 12px;
  padding: 10px 12px;
  font: inherit;
}

input {
  min-width: 0;
  width: 0;
  flex: 1;
  border: 1px solid #495569;
  color: var(--ink);
  background: #0e1118;
}

button {
  border: 1px solid transparent;
  background: var(--green);
  color: #fff;
  font-weight: 700;
  cursor: pointer;
}

button:disabled { opacity: .46; cursor: default; }
:focus-visible { outline: 3px solid #c9fa71; outline-offset: 3px; }

#scan {
  width: 100%;
  margin-top: 9px;
  background: var(--lime);
  color: var(--ink);
}

#camera[hidden] { display: none !important; }
#camera {
  position: fixed;
  inset: 0;
  z-index: 10000;
  margin: 0;
  width: 100%;
  height: 100%;
  height: 100dvh;
  background: #090709;
  isolation: isolate;
}
body.camera-open { overflow: hidden; }
#preview {
  display: block;
  width: 100%;
  height: 100%;
  max-height: none;
  margin: 0;
  border-radius: 0;
  object-fit: cover;
  background: var(--ink);
}
#camera .camera-hint {
  position: absolute;
  top: calc(env(safe-area-inset-top, 0px) + 20px);
  left: 16px;
  right: 16px;
  margin: 0;
  padding: 12px 16px;
  border-radius: 16px;
  background: #151015cc;
  color: #fff;
  text-align: center;
  font-size: 16px;
}
#camera #stop {
  position: absolute;
  bottom: calc(env(safe-area-inset-bottom, 0px) + 20px);
  left: 16px;
  right: 16px;
  width: calc(100% - 32px);
  min-height: 48px;
  background: #ffad73;
  color: #211821;
}

#status:not(:empty) {
  margin-top: 12px;
  color: var(--muted);
}

#custom, #portion {
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

#custom label:not(:first-child) { margin-top: 10px; }
#density { margin: 4px 0 12px; color: var(--muted); }
output:not(:empty) { display: block; margin-top: 9px; font-weight: 700; }

.diary-panel { background: #181e29; border-color: #384355; }
.diary-panel h2 { margin-bottom: 6px; }
#total { font-size: clamp(20px, 5vw, 26px); font-weight: 750; letter-spacing: -.04em; }
#empty { margin-top: 8px; color: var(--muted); }
#entries { margin: 8px 0 0; padding: 0; list-style: none; }
#entries:empty { display: none; }
li { border-top: 1px solid #303745; padding: 10px 0; overflow-wrap: anywhere; }
small { color: var(--muted); }
a { color: var(--green); text-underline-offset: 3px; }

@media (min-width: 650px) {
  main { padding: 36px 22px; }
  .hero { min-height: 245px; }
  .barcode-art { right: 9%; }
  .panels { grid-template-columns: 1.2fr 1fr; gap: 16px; margin-top: 16px; }
}

.navigation {
  position: sticky;
  top: env(safe-area-inset-top, 0px);
  z-index: 10;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 4px;
  margin-bottom: 12px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--paper);
}

.navigation button[aria-pressed="false"] {
  color: var(--green);
  background: transparent;
}

.feed-hero { min-height: clamp(130px, 26vw, 220px); }
.feed-empty {
  margin-top: 12px;
  color: var(--muted);
}

.profile-identity { display: flex; align-items: center; gap: 14px; }
.profile-identity h2 { margin: 0; overflow-wrap: anywhere; }
#profile-avatar { width: 60px; height: 60px; border-radius: 50%; object-fit: cover; }
#profile-details { overflow-wrap: anywhere; }
#profile-details dd { margin: 0 0 10px; white-space: pre-wrap; }
#profile-details dt { font-size: 14px; font-weight: 700; }
#profile-form p, #profile-message:not(:empty) { margin-bottom: 12px; color: var(--muted); }
#profile-form label { margin-bottom: 10px; }
#profile-form input, #profile-form textarea {
  display: block; width: 100%; margin-top: 4px;
}
#profile-form textarea {
  padding: 10px 12px; border: 1px solid #495569; border-radius: 12px;
  font: inherit; background: #0e1118; color: var(--ink);
}
.profile-measurements { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }

#profile-name { flex: 1; min-width: 0; }
#profile-edit {
  min-height: 36px;
  padding: 6px 9px;
  border-color: var(--line);
  background: transparent;
  color: var(--green);
  font-size: 13px;
}

body::before {
  content: '';
  position: fixed;
  inset: 0;
  z-index: -1;
  background:
    linear-gradient(rgba(244, 237, 221, .76), rgba(244, 237, 221, .87)),
    url('food-background.jpg') center / cover no-repeat;
}

.hero {
  background:
    linear-gradient(90deg, rgba(25, 49, 33, .94), rgba(25, 49, 33, .52)),
    url('food-background.jpg') center 54% / cover no-repeat,
    var(--green);
}

.profile-settings {
  margin: 12px 0;
  padding: 10px 12px 0;
  border: 1px solid var(--line);
  border-radius: 12px;
}
.profile-settings legend { padding: 0 5px; font-weight: 700; }
.profile-settings select {
  display: block;
  width: 100%;
  min-height: 44px;
  margin-top: 4px;
  padding: 8px 10px;
  border: 1px solid #495569;
  border-radius: 12px;
  background: #0e1118;
  color: var(--ink);
  font: inherit;
}
.profile-estimate {
  margin: 12px 0;
  padding: 12px;
  border-radius: 12px;
  background: #181e29;
}
.profile-estimate.is-editing { display: none; }
.profile-estimate p + p { margin-top: 6px; }
.profile-estimate p:first-child { font-weight: 700; }
.profile-estimate p:last-child { font-size: 14px; }

#calorie-progress { margin: 12px 0; padding: 14px; border: 1px solid var(--line); border-radius: 12px; }
#calorie-summary, #calorie-dates { margin-top: 6px; color: var(--muted); font-size: 14px; }
#calorie-chart { display: block; width: 100%; height: auto; margin-top: 8px; }

:root {
  --cream: #0b0d12;
  --paper: #141820;
  --ink: #f1f3f7;
  --green: #344329;
  --lime: #c9fa71;
  --line: #303745;
}

body::before {
  background:
    linear-gradient(155deg, rgba(15, 81, 59, .89), rgba(10, 36, 28, .98)),
    url('food-background.jpg') center / cover no-repeat;
}

.navigation {
  gap: 6px;
  padding: 6px;
  border-color: #303745;
  border-radius: 20px;
  background: linear-gradient(145deg, #1d2533, #121722);
  box-shadow: 0 8px 18px #00000070, inset 0 1px #ffffff26;
}

button,
#scan {
  border: 1px solid #d5ff8b;
  border-radius: 999px;
  background: linear-gradient(155deg, #dbff96, #acde50);
  color: #182308;
  box-shadow: 0 4px 0 #5c792e, 0 7px 13px #0b0d1230, inset 0 1px #edffbe;
  transition: transform .15s ease, box-shadow .15s ease;
}

.navigation button {
  min-width: 0;
  padding-inline: 4px;
  font-size: clamp(12px, 3.6vw, 16px);
  margin-bottom: 3px;
}

.navigation button[aria-pressed="false"],
#profile-edit {
  color: #f1f3f7;
  border-color: #3b4659;
  background: linear-gradient(150deg, #253042, #1a212e);
  box-shadow: 0 3px 0 #0b0d12, inset 0 1px #ffffff29;
}

button:enabled:active,
#scan:active,
#profile-edit:active,
.navigation button[aria-pressed="false"]:active {
  transform: translateY(2px);
  box-shadow: 0 1px 0 #182031, inset 0 1px #ffffff29;
}

button:focus-visible { outline: 3px solid #c9fa71; }

.hero {
  border: 1px solid #414d62;
  color: #f1f3f7;
  background:
    linear-gradient(105deg, #10151f 4%, #1a2432d9 48%, #18223360 100%),
    url('food-background.jpg') center 54% / cover no-repeat;
  box-shadow: 0 12px 25px #00000066, inset 0 1px #ffffff38;
}

.barcode-art {
  background: linear-gradient(145deg, #d8ff8c, #9fce46);
  box-shadow: 0 10px 22px #00000066, inset 0 1px #eaffb7;
}

section {
  background: linear-gradient(145deg, #191f2a, #141820);
  box-shadow: 0 8px 20px #0000003d, inset 0 1px #ffffff;
}

.diary-panel { background: linear-gradient(145deg, #1c2431, #161c26); }
main > div > small, main > div > small a { color: #aab4c4; }

@media (prefers-reduced-motion: reduce) {
  button, #scan { transition: none; }
}

.diary-date { margin-bottom: 12px; }
.diary-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.diary-actions button, #diary-today { font-size: 13px; min-height: 38px; padding: 6px 10px; }
.diary-actions input { min-width: 72px; }
#diary-message:not(:empty) { margin-bottom: 8px; font-size: 14px; }

.quick-panel { grid-column: 1 / -1; grid-row: 2; }
.quick-panel h3 { margin: 12px 0 8px; font-size: 17px; }
.quick-panel ul { margin: 0; padding: 0; list-style: none; }
#quick-message:not(:empty) { margin-bottom: 8px; font-size: 14px; }
@media (max-width: 649px) {
  .quick-panel { grid-row: auto; }
}

.quick-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.quick-heading h2 { margin: 0; }
.favorite-star { flex: none; width: 40px; min-height: 40px; padding: 0; font-size: 20px; }
#favorites-dialog {
  width: min(440px, calc(100% - 32px));
  max-height: 78vh;
  padding: 18px;
  overflow-y: auto;
  border: 1px solid var(--line);
  border-radius: 20px;
  color: var(--ink);
  background: var(--paper);
}
#favorites-dialog::backdrop { background: #080a10b3; }
#favorites-message:not(:empty) { margin-bottom: 8px; }

.diary-target { margin: 8px 0 14px; font-size: 14px; color: var(--muted); }
.diary-target progress { display: block; width: 100%; height: 12px; margin-top: 6px; accent-color: var(--green); }

.meal-picker { margin-top: 12px; padding: 12px 16px; border-radius: 16px; background: var(--paper); }
.meal-picker select, #favorites-meal {
  width: 100%; min-height: 44px; padding: 8px 10px; border: 1px solid #495569;
  border-radius: 12px; background: #0e1118; color: var(--ink); font: inherit;
}
#favorites-meal { margin-bottom: 8px; }
#entries .meal-group { padding-top: 12px; }
.meal-group h3 { margin-bottom: 8px; font-size: 16px; }
.meal-group ul { margin: 0; padding: 0; list-style: none; }

.backup-panel { margin-top: 18px; padding-top: 12px; border-top: 1px solid var(--line); }
#backup-message:not(:empty) { margin-top: 10px; font-size: 14px; }

.feed-posts { display: grid; grid-template-columns: minmax(0, 1fr); gap: 14px; margin-top: 14px; }
.feed-post {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: linear-gradient(145deg, #191f2a, #141820);
  box-shadow: 0 8px 20px #0000003d;
}
.feed-feature img { display: block; width: 100%; height: clamp(170px, 32vw, 275px); object-fit: cover; object-position: center 54%; }
.feed-post-body { padding: clamp(16px, 4vw, 24px); }
.feed-post h2 { margin-bottom: 8px; }
.feed-post p, .feed-post li { line-height: 1.55; }
.feed-post details { margin-top: 12px; }
.feed-post summary {
  width: fit-content;
  padding: 8px 13px;
  border: 1px solid #9abe58;
  border-radius: 999px;
  background: linear-gradient(155deg, #dbff96, #b4e35d);
  color: #182308;
  font-weight: 700;
  cursor: pointer;
}
.feed-post details p { margin-top: 10px; }
.feed-post ol, .feed-post ul { padding-left: 22px; }
.feed-post li { padding: 3px 0; border: 0; }
@media (min-width: 650px) {
  .feed-posts { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .feed-feature { grid-column: 1 / -1; }
}

#name-search, #custom-product, #nutrition-summary details, #nutrition-tools form { margin-block: 12px; }
#name-results { display: flex; flex-wrap: wrap; gap: 8px; margin-block: 8px; }
#nutrition-summary ul { padding-left: 0; list-style: none; }
#nutrition-summary details { padding: 10px; border: 1px solid var(--line); border-radius: 12px; }
#nutrition-progress { overflow-x: auto; margin-block: 12px; }
.nutrition-table { width: 100%; border-collapse: collapse; text-align: right; font-variant-numeric: tabular-nums; }
.nutrition-table th, .nutrition-table td { padding: 6px; border-bottom: 1px solid var(--line); }
.nutrition-bars { height: 42px; display: flex; align-items: end; gap: 3px; margin-bottom: 8px; }
.nutrition-bars span { flex: 1; background: var(--lime); border-radius: 2px 2px 0 0; }
#activity-include { width: auto; min-height: auto; }
input[type="date"], input[type="datetime-local"] { color-scheme: dark; }

.keyboard-done {
  position: fixed;
  right: max(12px, env(safe-area-inset-right));
  bottom: max(calc(var(--keyboard-inset, 0px) + 12px), env(safe-area-inset-bottom));
  min-width: 96px;
  min-height: 48px;
  z-index: 100;
}

@media (max-width: 649px), (any-pointer: coarse) {
  input:not([type="checkbox"]):not([type="file"]),
  #profile-form input, #profile-form textarea, textarea, select,
  .profile-settings select, .meal-picker select, #favorites-meal {
    min-height: 48px;
    min-width: 0;
    width: 100%;
    padding: 10px 12px;
    font-size: 16px;
    color-scheme: dark;
  }

  button, #scan, .diary-actions button, #diary-today {
    max-width: 100%;
    min-height: 38px;
    padding: 6px 9px;
    font-size: 14px;
    white-space: normal;
    overflow-wrap: anywhere;
    vertical-align: top;
    margin-bottom: 4px;
  }

  .navigation button {
    min-width: 0;
    padding-inline: 3px;
    font-size: clamp(12px, 3.8vw, 14px);
  }

  .favorite-star { width: 38px; padding: 0; font-size: 20px; }
  .keyboard-done { min-height: 44px; }
  .row, .profile-identity { flex-wrap: wrap; }
  .row > button { flex: 0 1 auto; }
  .diary-actions > button { min-width: 0; }

  #activity-include { width: 24px; height: 24px; vertical-align: middle; }
  #scan img, #scan svg, #open-favorites img, #open-favorites svg { width: 24px; height: 24px; }
  #nutrition-summary summary, .feed-post summary {
    min-height: 48px;
    padding-block: 12px;
    font-size: 16px;
  }
}

@media (max-width: 649px) {
  #search .row, #portion .row, #custom .row { flex-wrap: wrap; }
  #search .row > input, #portion .row > input, #custom .row > input { flex: 1 1 100%; }
  .navigation button { padding-inline: 4px; }
  .diary-actions { flex-wrap: wrap; }
}
