:root {
  --bg: #f5f4ee;
  --ink: #172122;
  --muted: #5f6d6f;
  --line: #d7ddd6;
  --good: #1e7a53;
  --mixed: #ab7a0c;
  --bad: #a5392c;
  --teal: #0f8b8d;
  --radius: 18px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: Manrope, "Segoe UI", sans-serif;
  color: var(--ink);
  background: radial-gradient(circle at 15% 20%, #fff7dc 0%, transparent 44%),
    radial-gradient(circle at 80% 0%, #d9f2ef 0%, transparent 35%), var(--bg);
  position: relative;
  overflow-x: hidden;
}

h1,
h2,
h3 {
  font-family: Outfit, Manrope, sans-serif;
  margin: 0;
}

.ambient {
  position: fixed;
  border-radius: 999px;
  pointer-events: none;
  z-index: 0;
}

.ambient-one {
  width: 280px;
  height: 280px;
  background: #ffcb6e42;
  top: -70px;
  right: -60px;
}

.ambient-two {
  width: 320px;
  height: 320px;
  background: #4db6ac29;
  bottom: -140px;
  left: -80px;
}

.app-shell {
  position: relative;
  z-index: 1;
  max-width: 860px;
  margin: 28px auto 64px;
  padding: 0 16px;
  display: grid;
  gap: 16px;
}

.card {
  background: linear-gradient(155deg, #fffefa 0%, #fffcf1 100%);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: 0 11px 24px #11111110;
}

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

.top-title {
  font-size: clamp(1.5rem, 2.8vw, 1.9rem);
}

.eyebrow {
  margin: 0;
  color: #0e6f70;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  font-size: 0.72rem;
}

.page-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.nav-btn {
  border: 1px solid #b8c5bc;
  background: #fff;
  border-radius: 999px;
  padding: 9px 13px;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}

.nav-btn.is-active {
  background: #ecf5f4;
  border-color: #0f8b8d;
  color: #125f62;
}

.page-section {
  display: grid;
  gap: 16px;
}

.hero h2 {
  margin-top: 6px;
  font-size: clamp(1.45rem, 2.9vw, 2rem);
  line-height: 1.15;
}

.subtext {
  margin: 10px 0 0;
  color: var(--muted);
  max-width: 70ch;
}

.analyze-form,
.auth-form {
  display: grid;
  gap: 12px;
}

.input-label {
  font-weight: 700;
  font-size: 0.95rem;
}

.input-label.optional::after {
  content: " (optional)";
  color: var(--muted);
  font-weight: 500;
}

.photo-input {
  border: 1px dashed #8ca8aa;
  border-radius: 14px;
  background: #f7fffe;
  padding: 10px;
}

.preview-wrap {
  min-height: 180px;
  border: 1px solid #d5dbd3;
  border-radius: 14px;
  background: #f6f7f1;
  display: grid;
  place-items: center;
  overflow: hidden;
}

.preview-placeholder {
  color: var(--muted);
  margin: 0;
}

.photo-preview {
  width: 100%;
  max-height: 320px;
  object-fit: cover;
}

textarea,
input.auth-input {
  border: 1px solid #cad2cb;
  border-radius: 12px;
  padding: 10px 12px;
  font: inherit;
  background: #fffffc;
}

.share-input {
  flex: 1;
  min-width: 220px;
}

textarea:focus,
.auth-input:focus,
.photo-input:focus,
.analyze-btn:focus,
.action-btn:focus,
.refresh-btn:focus,
.nav-btn:focus {
  outline: 2px solid #3aa0a1;
  outline-offset: 2px;
}

.analyze-btn {
  border: 0;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--teal), #0da099);
  color: #fff;
  font-weight: 800;
  font-size: 1rem;
  padding: 12px 18px;
  cursor: pointer;
}

.analyze-btn:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

.status-text {
  margin: 0;
  min-height: 1.2rem;
  color: #355355;
  font-size: 0.95rem;
}

.auth-subtext {
  margin: 6px 0 12px;
  color: var(--muted);
}

.auth-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.auth-user {
  margin: 8px 0 14px;
  color: #2b4041;
  font-weight: 700;
}

.results-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 10px;
}

.result-guidance {
  margin: 0;
  color: #2c4a4c;
  text-align: right;
  font-weight: 600;
}

.food-description {
  margin: 8px 0 0;
  color: #2e4a4c;
  font-weight: 700;
}

.score-grid {
  margin-top: 12px;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.score-card {
  border: 1px solid #d9dfd7;
  border-radius: 14px;
  padding: 14px;
  background: #fff;
}

.score-label {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.score-value {
  margin: 4px 0;
  font-size: clamp(2rem, 4vw, 2.6rem);
  font-weight: 800;
  line-height: 1;
}

.score-band {
  margin: 0;
  font-weight: 700;
}

.band-good {
  color: var(--good);
}

.band-mixed {
  color: var(--mixed);
}

.band-bad {
  color: var(--bad);
}

.reason-block {
  margin-top: 14px;
}

.reason-title {
  margin: 0;
  font-weight: 800;
}

#reason-list {
  margin: 8px 0 0;
  padding-left: 20px;
  color: #324042;
}

.actions {
  margin-top: 14px;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.action-btn,
.refresh-btn {
  border-radius: 999px;
  border: 1px solid #b3c0b8;
  font: inherit;
  font-weight: 700;
  padding: 10px 14px;
  cursor: pointer;
  background: #fff;
}

.action-primary {
  background: #1d8b54;
  border-color: #1d8b54;
  color: #fff;
}

.action-secondary {
  background: #ece8d9;
}

.action-tertiary {
  background: transparent;
}

.summary-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}

.summary-head-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.score-guide-link {
  color: #126063;
  font-weight: 700;
  text-decoration: none;
  border-bottom: 1px dashed #2b8889;
}

.score-guide-link:hover {
  color: #0d4d50;
}

.summary-stats {
  margin-top: 10px;
  border: 1px solid #dde2db;
  border-radius: 12px;
  padding: 10px 12px;
  background: #fff;
  display: grid;
  gap: 6px;
}

.summary-stats p {
  margin: 0;
  color: #364646;
}

.log-list-wrap h3 {
  margin: 14px 0 8px;
}

.saved-food-head {
  margin-top: 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.saved-food-head h3 {
  margin: 0;
}

.scope-toggle {
  display: flex;
  gap: 6px;
}

.scope-btn {
  border: 1px solid #bcc8bf;
  background: #fff;
  color: #2f4546;
  border-radius: 999px;
  padding: 7px 11px;
  font: inherit;
  font-size: 0.84rem;
  font-weight: 700;
  cursor: pointer;
}

.scope-btn.is-active {
  border-color: #0f8b8d;
  background: #ebf6f5;
  color: #126164;
}

.chart-wrap {
  margin-top: 14px;
  border: 1px solid #dce2da;
  border-radius: 12px;
  background: #fff;
  padding: 10px 12px;
}

.chart-wrap h3 {
  margin: 0;
}

.trend-chart {
  display: block;
  width: 100%;
  height: 220px;
  margin-top: 8px;
}

.chart-legend {
  display: flex;
  gap: 14px;
  margin-top: 6px;
}

.legend-item {
  font-size: 0.85rem;
  font-weight: 700;
  color: #374747;
}

.legend-item::before {
  content: "";
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 999px;
  margin-right: 6px;
}

.legend-blood::before {
  background: #0d8f85;
}

.legend-apob::before {
  background: #f08b2f;
}

.entry-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 8px;
}

.entry-item {
  border: 1px solid #dce1d9;
  border-radius: 12px;
  background: #fff;
  padding: 10px;
}

.entry-main {
  display: flex;
  align-items: flex-start;
  gap: 10px;
}

.entry-thumb,
.entry-thumb-placeholder {
  width: 54px;
  height: 54px;
  border-radius: 10px;
  flex: 0 0 54px;
}

.entry-thumb {
  border: 1px solid #d8ddd6;
  object-fit: cover;
}

.entry-thumb-placeholder {
  border: 1px dashed #c2cdc5;
  background: #f7faf8;
  color: #72817e;
  font-size: 0.7rem;
  font-weight: 700;
  display: grid;
  place-items: center;
}

.entry-content {
  min-width: 0;
  flex: 1;
}

.entry-actions {
  margin-left: auto;
  display: flex;
  align-items: flex-start;
}

.entry-meta {
  margin: 0;
  color: #536364;
  font-size: 0.86rem;
}

.entry-scores {
  margin: 4px 0 0;
  font-weight: 700;
}

.entry-food {
  margin: 0 0 4px;
  color: #2f4446;
  font-weight: 700;
  line-height: 1.25;
}

.entry-delete-btn {
  margin-top: 0;
  border: 1px solid #ddbcb8;
  background: #fff5f4;
  color: #9a2e24;
  border-radius: 999px;
  padding: 6px 10px;
  font: inherit;
  font-size: 0.78rem;
  font-weight: 700;
  cursor: pointer;
}

.share-card {
  margin: 14px 0;
  border: 1px solid #dce2da;
  border-radius: 12px;
  background: #fff;
  padding: 12px;
}

.share-row {
  margin-top: 8px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.hidden {
  display: none !important;
}

@media (max-width: 700px) {
  .app-shell {
    margin-top: 18px;
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .score-grid {
    grid-template-columns: 1fr;
  }

  .saved-food-head {
    flex-direction: column;
    align-items: flex-start;
  }

  .summary-head-actions {
    width: 100%;
    justify-content: flex-start;
    flex-wrap: wrap;
  }

  .results-header {
    flex-direction: column;
    align-items: flex-start;
  }

  .result-guidance {
    text-align: left;
  }
}
