/* NutriScan front end.
   Brand system of tamaradinneen.com. British English throughout.
   Prussian-deep page with gold promoted from seasoning to structural accent:
   gold now carries hairlines, rules, card borders, small caps labels and the
   plate-total hero number. Ivory is the primary text; ivory at 0.75 opacity is
   secondary. No gold fills or gradients; square corners; hairline geometry. */

/* ---- Self-hosted fonts (OFL 1.1, see fonts/README). Relative URLs so the
   assets resolve under the /fooddetection reverse-proxy subpath as well as at
   the Modal root. ---- */
@font-face {
  font-family: "Fraunces Variable";
  font-style: normal;
  font-display: swap;
  font-weight: 100 900;
  src: url("./fonts/fraunces-variable.woff2") format("woff2-variations");
}
@font-face {
  font-family: "Quicksand Variable";
  font-style: normal;
  font-display: swap;
  font-weight: 300 700;
  src: url("./fonts/quicksand-variable.woff2") format("woff2-variations");
}

/* ---- Design tokens (defined once, never scattered as raw hex) ---- */
:root {
  --prussian: #003152;
  --prussian-deep: #000d16;
  --ivory: #FAF7F0;
  --gold: #C2A96A;
  --gold-deep: #9C7E3B;
  --charcoal: #2A2A2A;

  --serif: "Fraunces Variable", Georgia, "Times New Roman", serif;
  --label: "Quicksand Variable", system-ui, sans-serif;

  /* Secondary text is ivory dimmed; muted is dimmer still. */
  --ivory-secondary: rgba(250, 247, 240, 0.75);
  --ivory-muted: rgba(250, 247, 240, 0.62);
  /* Structural gold hairline / card border. */
  --gold-line: rgba(194, 169, 106, 0.35);
  --gold-wash: rgba(194, 169, 106, 0.12);
  --row-line: rgba(250, 247, 240, 0.12);

  --measure: 64rem;
  --hairline: 1px;
}

*,
*::before,
*::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--prussian-deep);
  color: var(--ivory);
  font-family: var(--serif);
  font-weight: 400;
  font-size: 1.0625rem;
  line-height: 1.55;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
}

.wrap {
  width: 100%;
  max-width: var(--measure);
  margin-inline: auto;
  padding-inline: 1.5rem;
}

/* ---- Small uppercase labels: Quicksand 600, gold ---- */
.eyebrow,
.label {
  font-family: var(--label);
  text-transform: uppercase;
  letter-spacing: 0.18em;
  font-weight: 600;
  font-size: 0.78rem;
  line-height: 1.3;
  color: var(--gold);
  margin: 0;
}

/* ---- Header: prussian-deep, ivory text, gold hairline beneath ---- */
.site-header {
  background: var(--prussian-deep);
  color: var(--ivory);
  border-bottom: var(--hairline) solid var(--gold-line);
  padding-block: 2.75rem 2.25rem;
}
.display {
  font-family: var(--serif);
  font-weight: 600;
  font-size: clamp(2.6rem, 7vw, 4.25rem);
  line-height: 1.02;
  letter-spacing: -0.01em;
  margin: 0.5rem 0 0.5rem;
  color: var(--ivory);
}
.lede {
  margin: 0;
  max-width: 34rem;
  font-size: 1.05rem;
  color: var(--ivory-secondary);
}

/* ---- Offline banner ---- */
.offline-banner {
  background: var(--prussian);
  color: var(--ivory);
  font-family: var(--label);
  text-transform: uppercase;
  letter-spacing: 0.14em;
  font-weight: 600;
  font-size: 0.74rem;
  text-align: center;
  padding: 0.6rem 1rem;
}
.offline-banner[hidden] { display: none; }

/* ---- Capture panel ---- */
main { padding-block: 2.5rem 3.5rem; }

.capture {
  border: var(--hairline) solid var(--gold-line);
  padding: 2rem 1.9rem 2.1rem;
}
.capture-heading { margin: 0 0 1.25rem; }

.capture-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
}

/* ---- Buttons: Fraunces 600, square, 1px border, 0.2s ease ---- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-family: var(--serif);
  font-weight: 600;
  font-size: 1rem;
  line-height: 1.1;
  padding: 1rem 1.9rem;
  border: var(--hairline) solid var(--gold);
  border-radius: 0;
  cursor: pointer;
  transition: background-color 0.2s ease, color 0.2s ease, opacity 0.2s ease;
}
/* Primary (Take a photo): transparent, ivory text, gold border. */
.btn-primary {
  background: transparent;
  color: var(--ivory);
  border-color: var(--gold);
}
.btn-primary:hover { background: var(--gold-wash); }
/* Secondary (Choose a photo): ivory field, prussian text. */
.btn-secondary {
  background: var(--ivory);
  color: var(--prussian);
  border-color: var(--ivory);
}
.btn-secondary:hover { opacity: 0.9; }
.btn:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
}
.btn input { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }

.status {
  margin: 1.25rem 0 0;
  min-height: 1.2em;
  font-size: 0.95rem;
  color: var(--ivory-secondary);
}
.status.is-error { color: var(--gold); }

/* ---- Results ---- */
.results:empty { display: none; }
.results { margin-top: 2.5rem; }

@media (prefers-reduced-motion: no-preference) {
  .results > * { animation: fade-in 320ms ease both; }
}
@keyframes fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

.overlay-figure { margin: 0 0 2rem; }
.overlay-figure img {
  display: block;
  width: 100%;
  height: auto;
  max-width: 100%;
  border: var(--hairline) solid var(--gold-line);
}

/* Section title with a short structural gold rule (3.5rem wide, 2px). */
.section-title {
  font-family: var(--serif);
  font-weight: 600;
  font-size: 1.35rem;
  color: var(--ivory);
  margin: 0 0 1.25rem;
  padding-bottom: 0.7rem;
}
.section-title::after {
  content: "";
  display: block;
  width: 3.5rem;
  height: 2px;
  background: var(--gold);
  margin-top: 0.7rem;
}

.cards {
  display: grid;
  gap: 1.25rem;
  grid-template-columns: repeat(auto-fill, minmax(16rem, 1fr));
}

/* Result card: 1px gold-line border on the prussian-deep field. */
.card {
  border: var(--hairline) solid var(--gold-line);
  padding: 1.5rem 1.5rem 1.7rem;
  background: transparent;
}
.card.is-unrecognised { border-color: rgba(250, 247, 240, 0.18); }

.card-name {
  font-family: var(--serif);
  font-weight: 600;
  font-size: 1.3rem;
  line-height: 1.15;
  margin: 0.15rem 0 0.35rem;
  color: var(--ivory);
}
.card-confidence { margin: 0 0 1rem; }

/* Per-item nutrition values: Fraunces, ivory. */
.card-kcal {
  font-family: var(--serif);
  font-weight: 600;
  font-size: 1.5rem;
  margin: 0.2rem 0 0.7rem;
  color: var(--ivory);
}
.macros {
  list-style: none;
  margin: 0 0 0.9rem;
  padding: 0;
  display: grid;
  gap: 0.25rem;
}
.macros li {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 1rem;
  border-bottom: var(--hairline) solid var(--row-line);
  padding-bottom: 0.3rem;
}
/* Nutrition labels: Quicksand caps, gold at 0.85. */
.macros .macro-label {
  font-family: var(--label);
  text-transform: uppercase;
  letter-spacing: 0.14em;
  font-weight: 600;
  font-size: 0.72rem;
  color: var(--gold);
  opacity: 0.85;
}
/* Nutrition values: Fraunces, ivory. */
.macros .macro-value {
  font-family: var(--serif);
  font-weight: 600;
  font-size: 0.98rem;
  color: var(--ivory);
}

.card-note,
.card-closest {
  margin: 0.4rem 0 0;
  font-size: 0.92rem;
  color: var(--ivory-secondary);
}
.card-footnote {
  margin: 0.75rem 0 0;
  font-size: 0.82rem;
  color: var(--ivory-muted);
}
.prediction-set {
  margin: 0.6rem 0 0;
  font-family: var(--label);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  font-size: 0.72rem;
  color: var(--gold);
  opacity: 0.85;
}

/* ---- Plate total: heaviest card, gold rule above, hero number in gold ---- */
.plate-total {
  margin-top: 2.5rem;
  border: var(--hairline) solid var(--gold-line);
  border-top: 2px solid var(--gold);
  padding: 1.8rem 1.7rem 1.9rem;
}
.plate-total-kcal {
  font-family: var(--serif);
  font-weight: 700;
  font-size: clamp(2.6rem, 8vw, 3.6rem);
  line-height: 1;
  color: var(--gold);
  margin: 0.35rem 0 0.85rem;
}
.plate-total .macros { max-width: 22rem; }
.plate-total-note {
  margin: 0.5rem 0 0;
  font-size: 0.9rem;
  color: var(--ivory-secondary);
}

.meta-line {
  margin: 2rem 0 0;
  font-family: var(--label);
  font-size: 0.74rem;
  letter-spacing: 0.04em;
  color: var(--ivory-muted);
  line-height: 1.6;
}

.empty-note {
  margin: 1.5rem 0 0;
  font-size: 1.05rem;
  color: var(--ivory-secondary);
}

/* ---- Footer: prussian band, ivory text, gold hairline above ---- */
.site-footer {
  background: var(--prussian);
  color: var(--ivory);
  border-top: var(--hairline) solid var(--gold-line);
  padding-block: 2rem 2.5rem;
  margin-top: 3rem;
}
.site-footer p {
  margin: 0 0 0.6rem;
  font-size: 0.85rem;
  line-height: 1.5;
  color: var(--ivory-secondary);
  max-width: 46rem;
}
.site-footer p:last-child { margin-bottom: 0; }

/* ---- Header layout with the Juniper mascot ---- */
.site-header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1.5rem;
}
.site-header-text { min-width: 0; }

/* ---- Juniper mascot: gold hairline berry on the sprig, theatrical only ----
   Four states via data-state: idle, scanning, result, unsure. Presentation is
   all in CSS (SVG presentation attributes cannot read CSS custom properties). */
.juniper {
  flex: none;
  width: 84px;
  height: 84px;
  overflow: visible;
}
@media (max-width: 34rem) { .juniper { width: 62px; height: 62px; } }

.juniper-sprig { fill: none; stroke: var(--gold); stroke-width: 2; stroke-linecap: round; }
.juniper-body {
  fill: var(--gold-wash);
  stroke: var(--gold);
  stroke-width: 2;
  transform-origin: 48px 56px;
}
.juniper-eyes { fill: var(--ivory); }
.juniper-mouths path {
  fill: none;
  stroke: var(--ivory);
  stroke-width: 2.4;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.juniper-scan-line { stroke: var(--gold); stroke-width: 1.6; opacity: 0; }
.juniper-spark { fill: var(--gold); opacity: 0; transform-origin: 74px 36px; }

/* Mouth shown per state. */
.juniper .m-idle,
.juniper .m-scan,
.juniper .m-result,
.juniper .m-unsure { display: none; }
.juniper[data-state="idle"] .m-idle { display: block; }
.juniper[data-state="scanning"] .m-scan { display: block; }
.juniper[data-state="result"] .m-result { display: block; }
.juniper[data-state="unsure"] .m-unsure { display: block; }

/* State accents (static; animated only when motion is allowed). */
.juniper[data-state="scanning"] .juniper-scan-line { opacity: 0.9; }
.juniper[data-state="result"] .juniper-spark { opacity: 1; }

@media (prefers-reduced-motion: no-preference) {
  .juniper[data-state="idle"] .juniper-body { animation: juniper-breathe 3.6s ease-in-out infinite; }
  .juniper[data-state="scanning"] .juniper-scan-line { animation: juniper-sweep 1.1s ease-in-out infinite; }
  .juniper[data-state="scanning"] .juniper-body { animation: juniper-pulse 1.1s ease-in-out infinite; }
  .juniper[data-state="result"] .juniper-spark { animation: juniper-pop 480ms ease both; }
}
@keyframes juniper-sweep {
  0% { transform: translateY(-22px); }
  50% { transform: translateY(22px); }
  100% { transform: translateY(-22px); }
}
@keyframes juniper-pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.72; } }
@keyframes juniper-breathe { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.03); } }
@keyframes juniper-pop {
  0% { opacity: 0; transform: scale(0.4); }
  60% { opacity: 1; transform: scale(1.15); }
  100% { opacity: 1; transform: scale(1); }
}

/* ---- Unsure card: same quiet border as an unrecognised item ---- */
.card.is-unsure { border-color: rgba(250, 247, 240, 0.18); }

/* ---- About panel: collapsible, gold-hairline framed ---- */
.about {
  margin-top: 2.5rem;
  border: var(--hairline) solid var(--gold-line);
}
.about > summary {
  font-family: var(--label);
  text-transform: uppercase;
  letter-spacing: 0.16em;
  font-weight: 600;
  font-size: 0.76rem;
  color: var(--gold);
  cursor: pointer;
  padding: 1rem 1.4rem;
  list-style: none;
}
.about > summary::-webkit-details-marker { display: none; }
.about[open] > summary { border-bottom: var(--hairline) solid var(--gold-line); }
.about-body { padding: 1.2rem 1.4rem 1.4rem; }
.about-body p {
  margin: 0 0 0.8rem;
  font-size: 0.92rem;
  line-height: 1.55;
  color: var(--ivory-secondary);
  max-width: 44rem;
}
.about-body p:last-child { margin-bottom: 0; }
.about-body .about-model { color: var(--ivory); }
