:root {
  --background: #f3f5ef;
  --surface: #ffffff;
  --text: #1e2b22;
  --muted: #5d6b61;
  --border: #d4dacd;
  --accent: #2f6b55;
  --accent-soft: #dcebe3;
  --on-accent: #ffffff;
  --error: #a13e3b;
  --on-target: #2e7d4f;
  --close: #8a6a00;
  --far: #c2570c;
  --font: system-ui, -apple-system, "Segoe UI", sans-serif;
  --text-scale: 1;
  color-scheme: light;
  /* Every size in rem grows or shrinks with the text size chosen in Settings. */
  font-size: calc(16px * var(--text-scale));
}

/* Dark mode, chosen in Settings (or following the phone when set to Automatic).
   app.js sets data-mode on the page to "light" or "dark". */
:root[data-mode="dark"] {
  --background: #141a16;
  --surface: #1e2620;
  --text: #e6ece6;
  --muted: #a3b0a6;
  --border: #344038;
  --accent: #6fbf9a;
  --accent-soft: #24382d;
  --on-accent: #10251b;
  --error: #e58a86;
  --on-target: #6fcf97;
  --close: #f2c94c;
  --far: #f2994a;
  color-scheme: dark;
}

/* Color themes. Green is the default above; each other color has a light and a dark version. */
:root[data-theme="ocean"] {
  --background: #eef4f8;
  --border: #c9d8e3;
  --accent: #1f5f8b;
  --accent-soft: #d6e7f3;
}

:root[data-theme="ocean"][data-mode="dark"] {
  --background: #11181e;
  --surface: #1a242d;
  --border: #2e3d4a;
  --accent: #6fb3e0;
  --accent-soft: #1f3445;
  --on-accent: #0c1f2c;
}

:root[data-theme="sunset"] {
  --background: #fbf1ea;
  --border: #ead2c2;
  --accent: #b5532a;
  --accent-soft: #f6dccd;
}

:root[data-theme="sunset"][data-mode="dark"] {
  --background: #1d1512;
  --surface: #2a1f1a;
  --border: #4a362c;
  --accent: #f0946a;
  --accent-soft: #3d2a20;
  --on-accent: #2a1208;
}

:root[data-theme="lavender"] {
  --background: #f4f0f8;
  --border: #dbd0e6;
  --accent: #6a4c93;
  --accent-soft: #e6dcf1;
}

:root[data-theme="lavender"][data-mode="dark"] {
  --background: #17131d;
  --surface: #221c2b;
  --border: #3d3349;
  --accent: #b89be0;
  --accent-soft: #33284a;
  --on-accent: #1d1030;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--background);
  color: var(--text);
  font-family: var(--font);
  font-size: 1.0625rem;
  line-height: 1.45;
}

/* A background picture sits behind everything, fixed in place while the page scrolls.
   A pseudo-element is used because iPhones ignore background-attachment: fixed. */
.has-picture body {
  background: transparent;
}

.has-picture body::before {
  position: fixed;
  z-index: -1;
  inset: 0;
  background: var(--background) var(--picture) center / cover no-repeat;
  content: "";
}

/* Text that normally sits straight on the background gets a backing so it stays readable. */
.has-picture .date,
.has-picture .settings-link {
  width: fit-content;
  padding: 4px 12px;
  border-radius: 999px;
  background: var(--surface);
}

.has-picture .settings-link {
  margin: 20px auto 0;
  padding: 12px 16px;
}

.app-header {
  position: sticky;
  z-index: 1;
  top: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  background: var(--accent);
  color: var(--on-accent);
}

.app-header h1 {
  margin: 0;
  font-size: 1.25rem;
}

.back-button {
  min-height: 44px;
  padding: 0 8px;
  border: none;
  background: none;
  color: inherit;
  font-size: 1rem;
  cursor: pointer;
}

main {
  max-width: 560px;
  margin: 0 auto;
  padding: 16px;
}

.card {
  margin-bottom: 16px;
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
}

.card h2 {
  margin: 0 0 8px;
  font-size: 1.15rem;
}

.choice {
  display: block;
  width: 100%;
  margin-top: 12px;
  padding: 14px 16px;
  border: 2px solid var(--accent);
  border-radius: 10px;
  background: var(--accent-soft);
  color: var(--text);
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.choice span {
  display: block;
  color: var(--muted);
  font-size: 0.95rem;
}

.date {
  margin: 0 0 12px;
  color: var(--muted);
}

.area-list {
  display: grid;
  gap: 12px;
}

.area-card {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  color: inherit;
  text-decoration: none;
}

.area-icon {
  font-size: 1.8rem;
}

.area-text {
  display: grid;
  flex: 1;
  gap: 4px;
}

.area-text span {
  color: var(--muted);
}

.chevron {
  color: var(--muted);
  font-size: 1.6rem;
}

.progress {
  height: 8px;
  overflow: hidden;
  border-radius: 4px;
  background: var(--accent-soft);
}

.progress-fill {
  height: 100%;
  background: var(--accent);
}

/* Goal colors: green on target, yellow close to it, orange far from it. */
.status-on-target,
.area-text .status-on-target {
  color: var(--on-target);
  font-weight: 600;
}

.status-close,
.area-text .status-close {
  color: var(--close);
  font-weight: 600;
}

.status-far,
.area-text .status-far {
  color: var(--far);
  font-weight: 600;
}

.progress-fill.status-on-target {
  background: var(--on-target);
}

.progress-fill.status-close {
  background: var(--close);
}

.progress-fill.status-far {
  background: var(--far);
}

.settings-link {
  display: block;
  margin-top: 20px;
  padding: 12px 0;
  color: var(--accent);
  text-align: center;
}

.summary {
  margin: 0 0 8px;
  font-weight: 600;
}

.empty,
.hint {
  color: var(--muted);
}

.hint {
  font-size: 0.9rem;
}

.record-list {
  margin: 12px 0 0;
  padding: 0;
  list-style: none;
}

/* Items line up at the top, so the picture and Delete stay beside the meal's name
   even when its "Nutrients" table is open below it. */
.record-list li {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 0;
  border-top: 1px solid var(--border);
}

label {
  display: block;
  margin: 12px 0 4px;
  font-weight: 600;
}

.field-label {
  margin: 16px 0 6px;
  font-weight: 600;
}

label.radio {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  margin: 0;
  font-weight: normal;
}

input,
select {
  width: 100%;
  min-height: 44px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--background);
  color: var(--text);
  font: inherit;
}

label.radio input {
  width: auto;
  min-height: 0;
}

.primary {
  width: 100%;
  min-height: 48px;
  margin-top: 16px;
  border: none;
  border-radius: 10px;
  background: var(--accent);
  color: var(--on-accent);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

.secondary {
  display: block;
  width: 100%;
  min-height: 48px;
  margin-top: 12px;
  padding: 12px;
  border: 2px solid var(--accent);
  border-radius: 10px;
  background: none;
  color: var(--accent);
  font: inherit;
  font-weight: 600;
  text-align: center;
  text-decoration: none;
  cursor: pointer;
}

.primary:disabled,
.secondary:disabled {
  opacity: 0.6;
  cursor: wait;
}

.card h2.section-heading {
  margin-top: 20px;
}

a {
  color: var(--accent);
}

.delete {
  min-height: 36px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: none;
  color: var(--error);
  font: inherit;
  font-size: 0.9rem;
  cursor: pointer;
}

.form-error {
  margin: 12px 0 0;
  color: var(--error);
}

.swatches {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(96px, 1fr));
  gap: 8px;
}

.swatch {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  min-height: 44px;
  margin: 0;
  padding: 10px 4px;
  border: 2px solid var(--border);
  border-radius: 10px;
  font-size: 0.9rem;
  font-weight: normal;
  text-align: center;
  overflow-wrap: anywhere;
  cursor: pointer;
}

.swatch input {
  position: absolute;
  width: auto;
  min-height: 0;
  opacity: 0;
}

.swatch-icon {
  font-size: 1.5rem;
  line-height: 32px;
}

.swatch-color {
  width: 32px;
  height: 32px;
  border: 2px solid var(--muted);
  border-radius: 50%;
}

.swatch-color.rainbow {
  background: conic-gradient(#e53935, #fdd835, #43a047, #1e88e5, #8e24aa, #e53935);
}

.custom-color {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 12px;
}

.custom-color input {
  flex: none;
  width: 56px;
  height: 44px;
  padding: 2px;
  cursor: pointer;
}

.custom-color label {
  margin: 0;
}

.save-color {
  margin-top: 4px;
}

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

.saved-colors li {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}

.saved-color {
  display: flex;
  flex: 1;
  align-items: center;
  gap: 12px;
  min-height: 48px;
  padding: 6px 12px;
  border: 2px solid var(--border);
  border-radius: 10px;
  background: none;
  color: var(--text);
  font: inherit;
  text-align: left;
  overflow-wrap: anywhere;
  cursor: pointer;
}

.saved-color .swatch-color {
  flex: none;
}

.saved-color[aria-pressed="true"] {
  border-color: var(--accent);
  background: var(--accent-soft);
  font-weight: 600;
}

.swatch:has(input:checked) {
  border-color: var(--accent);
  background: var(--accent-soft);
  font-weight: 600;
}

.swatch:has(input:focus-visible) {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.picture-input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
}

.picture-input:focus-visible + .secondary {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.font-preview {
  margin: 8px 0 0;
}

.record-text {
  display: grid;
  flex: 1;
  gap: 2px;
  min-width: 0;
}

.meal-line {
  color: var(--muted);
  font-size: 0.9rem;
}

.meal-details summary {
  min-height: 32px;
  color: var(--accent);
  font-size: 0.9rem;
  cursor: pointer;
}

.ingredient-names {
  margin: 0 0 8px;
  padding-left: 20px;
}

.nutrient-table {
  width: 100%;
  margin-top: 8px;
  border-collapse: collapse;
  font-size: 0.95rem;
}

.nutrient-table th,
.nutrient-table td {
  padding: 6px 4px;
  border-top: 1px solid var(--border);
  text-align: left;
}

.nutrient-table thead th {
  border-top: none;
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 600;
}

.nutrient-table tbody th {
  font-weight: normal;
}

.nutrient-table td:not(:first-child) {
  text-align: right;
  white-space: nowrap;
}

.nutrient-table thead th:not(:first-child) {
  text-align: right;
}

.ingredients {
  margin: 16px 0 0;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
}

.ingredients legend {
  padding: 0 4px;
  font-weight: 600;
}

.ingredients .hint {
  margin-top: 0;
}

.ingredient-list,
.search-results {
  margin: 0;
  padding: 0;
  list-style: none;
}

.ingredient-list li {
  display: grid;
  gap: 6px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}

.ingredient-name {
  font-weight: 600;
  overflow-wrap: anywhere;
}

.amount-row,
.search-row {
  display: flex;
  gap: 8px;
}

.amount-row .ingredient-quantity {
  flex: 0 0 5.5em;
}

.amount-row .ingredient-unit {
  flex: 1;
  min-width: 0;
}

.search-row input {
  flex: 1;
  min-width: 0;
}

.search-row .secondary {
  width: auto;
  margin-top: 0;
  padding: 0 16px;
}

.search-result {
  width: 100%;
  min-height: 44px;
  margin-top: 6px;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.target-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 4px 0;
}

.target-row label {
  margin: 0;
  font-weight: normal;
}

.target-row input {
  flex: 0 0 7em;
  width: 7em;
}

.split-inputs {
  display: flex;
  gap: 12px;
}

.inline-label {
  display: flex;
  flex: 1;
  align-items: center;
  gap: 6px;
  margin: 0;
  font-weight: normal;
}

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

.target-reasons li {
  display: grid;
  gap: 2px;
  padding: 8px 0;
  border-top: 1px solid var(--border);
}

.target-reason-heading {
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

.target-reasons .hint {
  margin: 0;
}

h3.field-label {
  font-size: 1rem;
}

.quick-add {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}

.quick-add .secondary {
  flex: 1;
  margin-top: 0;
}

.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  margin: 0;
  padding: 10px 18px;
  border-radius: 20px;
  background: var(--text);
  color: var(--background);
  transform: translateX(-50%);
}

/* Meals decorations: a colored header card with the area's picture beside its heading,
   a picture per meal, and an accent edge on the cards below. Colors come from the theme,
   so every theme and dark mode match. */
.hero {
  border-color: transparent;
  background: linear-gradient(135deg, var(--accent-soft), var(--surface) 75%);
}

.hero h2 {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--accent);
  font-size: 1.3rem;
}

.hero-icon {
  font-size: 1.8rem;
  line-height: 1;
}

.record-icon {
  display: grid;
  flex: none;
  place-items: center;
  width: 2.5rem;
  height: 2.5rem;
  border-radius: 50%;
  background: var(--accent-soft);
  font-size: 1.3rem;
}

.nutrients-card,
.add-card {
  border-top: 4px solid var(--accent);
}

/* "Today's nutrients" opens and closes by tapping its heading; the arrow on the left
   points right when hidden and down when shown, like each meal's "Nutrients". */
.day-nutrients > summary {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  list-style: none;
  cursor: pointer;
}

.day-nutrients > summary::-webkit-details-marker {
  display: none;
}

.day-nutrients > summary h2 {
  margin: 0;
}

.day-nutrients > summary::before {
  content: "▶";
  display: inline-block;
  color: var(--accent);
  font-size: 0.8rem;
  transition: transform 0.2s;
}

.day-nutrients[open] > summary::before {
  transform: rotate(90deg);
}
