/* ============================================================
   Mindful Bites — calm food journal
   Palette: warm paper, soft sage, muted clay
   Type: Fraunces (display serif) + Hanken Grotesk (body)
   ============================================================ */

:root {
  --paper:      #f4efe6;
  --paper-deep: #ece4d6;
  --card:       #fbf8f2;
  --card-edge:  #e4dccd;
  --ink:        #3b372f;
  --ink-soft:   #6f685b;
  --ink-faint:  #9a9183;

  --sage:       #7f8a6b;
  --sage-deep:  #636e51;
  --sage-wash:  #e8ebdf;
  --clay:       #b07d62;
  --clay-wash:  #f0e2d8;

  --danger:     #a9503f;

  --radius:     18px;
  --radius-sm:  12px;
  --shadow-sm:  0 1px 2px rgba(59, 55, 47, 0.05);
  --shadow-md:  0 14px 40px -22px rgba(59, 55, 47, 0.45);
  --ring:       0 0 0 3px rgba(127, 138, 107, 0.28);

  --ease:       cubic-bezier(0.22, 0.61, 0.36, 1);
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  min-height: 100dvh;
  font-family: "Hanken Grotesk", system-ui, sans-serif;
  color: var(--ink);
  background:
    radial-gradient(120% 90% at 12% -10%, #faf6ee 0%, rgba(250, 246, 238, 0) 55%),
    radial-gradient(130% 100% at 100% 0%, var(--sage-wash) 0%, rgba(232, 235, 223, 0) 45%),
    var(--paper);
  background-attachment: fixed;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

/* subtle film grain over the whole page */
.grain {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  opacity: 0.4;
  mix-blend-mode: multiply;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='0.5'/%3E%3C/svg%3E");
}

.shell {
  position: relative;
  z-index: 1;
  width: min(960px, 100%);
  margin: 0 auto;
  padding: clamp(1.1rem, 4vw, 2.4rem) clamp(1rem, 4vw, 2rem) 3rem;
}

/* ---------- masthead ---------- */
.masthead {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: clamp(1.4rem, 4vw, 2.6rem);
}

.brand { display: flex; align-items: center; gap: 0.85rem; }

.brand-mark {
  display: grid;
  place-items: center;
  width: 46px; height: 46px;
  flex: none;
  color: var(--sage-deep);
  background: var(--card);
  border: 1px solid var(--card-edge);
  border-radius: 14px;
  box-shadow: var(--shadow-sm);
}
.brand-mark svg { width: 26px; height: 26px; }

.brand-words h1 {
  margin: 0;
  font-family: "Fraunces", serif;
  font-weight: 500;
  font-size: clamp(1.5rem, 5vw, 2rem);
  letter-spacing: -0.015em;
  line-height: 1;
}
.brand-words p {
  margin: 0.3rem 0 0;
  font-size: 0.82rem;
  color: var(--ink-soft);
  font-style: italic;
  font-family: "Fraunces", serif;
}

/* ---------- buttons ---------- */
.ghost-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.5rem 0.85rem;
  font: inherit;
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--ink-soft);
  background: transparent;
  border: 1px solid var(--card-edge);
  border-radius: 999px;
  cursor: pointer;
  transition: all 0.25s var(--ease);
}
.ghost-btn:hover { color: var(--ink); border-color: var(--ink-faint); background: var(--card); }
.ghost-btn:focus-visible { outline: none; box-shadow: var(--ring); }

.primary-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.55rem;
  width: 100%;
  margin-top: 0.4rem;
  padding: 0.95rem 1.2rem;
  font: inherit;
  font-weight: 600;
  font-size: 0.95rem;
  letter-spacing: 0.01em;
  color: #fbf8f2;
  background: linear-gradient(165deg, var(--sage) 0%, var(--sage-deep) 100%);
  border: none;
  border-radius: 999px;
  cursor: pointer;
  box-shadow: 0 10px 24px -12px rgba(99, 110, 81, 0.8);
  transition: transform 0.22s var(--ease), box-shadow 0.22s var(--ease), filter 0.22s var(--ease);
}
.primary-btn:hover { transform: translateY(-2px); filter: saturate(1.05); box-shadow: 0 16px 30px -14px rgba(99, 110, 81, 0.9); }
.primary-btn:active { transform: translateY(0); }
.primary-btn:focus-visible { outline: none; box-shadow: var(--ring), 0 10px 24px -12px rgba(99, 110, 81, 0.8); }
.primary-btn svg { transition: transform 0.22s var(--ease); }
.primary-btn:hover svg { transform: translateX(3px); }

.danger-btn {
  font: inherit; font-weight: 600; font-size: 0.88rem;
  color: #fbf8f2;
  background: var(--danger);
  border: none; border-radius: 999px;
  padding: 0.7rem 1.15rem;
  cursor: pointer;
  transition: filter 0.2s var(--ease);
}
.danger-btn:hover { filter: brightness(1.08); }
.danger-btn:focus-visible { outline: none; box-shadow: 0 0 0 3px rgba(169, 80, 63, 0.3); }

/* ---------- layout ---------- */
.layout {
  display: grid;
  gap: clamp(1rem, 3vw, 1.6rem);
  align-items: start;
}
@media (min-width: 760px) {
  .layout { grid-template-columns: 1fr 1fr; }
}

.panel {
  position: relative;
  background: var(--card);
  border: 1px solid var(--card-edge);
  border-radius: var(--radius);
  padding: clamp(1.2rem, 4vw, 1.8rem);
  box-shadow: var(--shadow-md);
}
@media (min-width: 760px) {
  .journal-panel { position: sticky; top: 1.5rem; }
}

.panel-eyebrow {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.18em;
  color: var(--sage-deep);
  font-weight: 600;
}
.panel-title {
  margin: 0.35rem 0 1.3rem;
  font-family: "Fraunces", serif;
  font-weight: 500;
  font-size: clamp(1.4rem, 4vw, 1.7rem);
  letter-spacing: -0.01em;
}

/* ---------- form ---------- */
.field { margin-bottom: 1.25rem; }
.field:last-of-type { margin-bottom: 0.4rem; }

label, .field-label {
  display: block;
  font-size: 0.86rem;
  font-weight: 600;
  margin-bottom: 0.5rem;
  color: var(--ink);
}
.muted { color: var(--ink-faint); font-weight: 400; }

input[type="text"], textarea {
  width: 100%;
  font: inherit;
  font-size: 0.95rem;
  color: var(--ink);
  background: var(--paper);
  border: 1px solid var(--card-edge);
  border-radius: var(--radius-sm);
  padding: 0.8rem 0.9rem;
  transition: border-color 0.2s var(--ease), box-shadow 0.2s var(--ease), background 0.2s var(--ease);
  resize: vertical;
}
textarea { min-height: 3rem; }
input[type="text"]::placeholder, textarea::placeholder { color: var(--ink-faint); }
input[type="text"]:focus, textarea:focus {
  outline: none;
  background: var(--card);
  border-color: var(--sage);
  box-shadow: var(--ring);
}

.field.invalid input[type="text"] { border-color: var(--danger); }
.field-error {
  display: block;
  min-height: 0;
  font-size: 0.78rem;
  color: var(--danger);
  margin-top: 0.4rem;
  opacity: 0;
  transform: translateY(-3px);
  transition: opacity 0.2s var(--ease), transform 0.2s var(--ease);
}
.field.invalid .field-error { opacity: 1; transform: translateY(0); }

/* ---------- mood chips ---------- */
.moods {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.5rem;
}
@media (min-width: 420px) {
  .moods { grid-template-columns: repeat(6, 1fr); }
}
@media (min-width: 760px) and (max-width: 980px) {
  .moods { grid-template-columns: repeat(3, 1fr); }
}

.mood {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.32rem;
  padding: 0.62rem 0.3rem;
  background: var(--paper);
  border: 1px solid var(--card-edge);
  border-radius: var(--radius-sm);
  cursor: pointer;
  color: var(--ink-soft);
  transition: transform 0.18s var(--ease), border-color 0.18s var(--ease), background 0.18s var(--ease), color 0.18s var(--ease);
}
.mood svg { width: 26px; height: 26px; }
.mood span {
  font-size: 0.66rem;
  font-weight: 600;
  letter-spacing: 0.01em;
}
.mood:hover { transform: translateY(-2px); border-color: var(--ink-faint); }
.mood:focus-visible { outline: none; box-shadow: var(--ring); }
.mood[aria-checked="true"] {
  color: var(--sage-deep);
  background: var(--sage-wash);
  border-color: var(--sage);
  box-shadow: inset 0 0 0 1px var(--sage);
}

/* ---------- satiety slider ---------- */
.slider-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.5rem;
}
.satiety-read {
  font-family: "Fraunces", serif;
  font-style: italic;
  font-size: 0.95rem;
  color: var(--clay);
  font-weight: 500;
}

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 8px;
  margin: 0.6rem 0 0.4rem;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--sage) 0%, var(--clay) 100%);
  cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 24px; height: 24px;
  border-radius: 50%;
  background: var(--card);
  border: 2px solid var(--sage-deep);
  box-shadow: 0 3px 8px -2px rgba(59, 55, 47, 0.4);
  transition: transform 0.15s var(--ease);
}
input[type="range"]::-webkit-slider-thumb:active { transform: scale(1.15); }
input[type="range"]::-moz-range-thumb {
  width: 22px; height: 22px;
  border-radius: 50%;
  background: var(--card);
  border: 2px solid var(--sage-deep);
  box-shadow: 0 3px 8px -2px rgba(59, 55, 47, 0.4);
}
input[type="range"]:focus-visible { outline: none; }
input[type="range"]:focus-visible::-webkit-slider-thumb { box-shadow: var(--ring); }

.slider-scale {
  display: flex;
  justify-content: space-between;
  font-size: 0.68rem;
  color: var(--ink-faint);
  letter-spacing: 0.01em;
}

/* ---------- journal / dashboard ---------- */
.journal-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
}
.journal-head .panel-title { margin-bottom: 1rem; }

.count-pill {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--sage-deep);
  background: var(--sage-wash);
  border-radius: 999px;
  padding: 0.2rem 0.62rem;
  margin-top: 0.2rem;
}

.entries { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.7rem; }

.entry {
  position: relative;
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.85rem;
  padding: 0.9rem 1rem 0.9rem 0.9rem;
  background: var(--paper);
  border: 1px solid var(--card-edge);
  border-left: 4px solid var(--entry-accent, var(--sage));
  border-radius: var(--radius-sm);
  animation: rise 0.4s var(--ease) both;
}
@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

.entry-mood {
  display: grid;
  place-items: center;
  width: 42px; height: 42px;
  flex: none;
  border-radius: 11px;
  color: var(--entry-accent, var(--sage-deep));
  background: var(--entry-wash, var(--sage-wash));
}
.entry-mood svg { width: 24px; height: 24px; }

.entry-body { min-width: 0; }
.entry-top {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.5rem;
}
.entry-meal {
  font-family: "Fraunces", serif;
  font-weight: 500;
  font-size: 1.02rem;
  line-height: 1.25;
  color: var(--ink);
  overflow-wrap: anywhere;
}
.entry-time { font-size: 0.7rem; color: var(--ink-faint); white-space: nowrap; flex: none; }

.entry-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem 0.6rem;
  margin-top: 0.4rem;
  font-size: 0.74rem;
  color: var(--ink-soft);
}
.tag {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.12rem 0.5rem;
  border-radius: 999px;
  background: var(--card);
  border: 1px solid var(--card-edge);
  font-weight: 500;
}
.tag b { color: var(--entry-accent, var(--sage-deep)); font-weight: 600; }

.entry-note {
  margin: 0.5rem 0 0;
  font-size: 0.84rem;
  color: var(--ink-soft);
  font-style: italic;
  font-family: "Fraunces", serif;
  overflow-wrap: anywhere;
}

.entry-remove {
  position: absolute;
  top: 0.55rem; right: 0.55rem;
  width: 26px; height: 26px;
  display: grid; place-items: center;
  color: var(--ink-faint);
  background: transparent;
  border: none; border-radius: 8px;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.2s var(--ease), color 0.2s var(--ease), background 0.2s var(--ease);
}
.entry:hover .entry-remove, .entry-remove:focus-visible { opacity: 1; }
.entry-remove:hover { color: var(--danger); background: var(--clay-wash); }
.entry-remove:focus-visible { outline: none; box-shadow: var(--ring); }

/* ---------- empty state ---------- */
.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 0.5rem;
  padding: 2.4rem 1rem;
  color: var(--ink-faint);
}
.empty svg { color: var(--ink-faint); opacity: 0.7; }
.empty-title { margin: 0.4rem 0 0; font-family: "Fraunces", serif; font-size: 1.05rem; color: var(--ink-soft); }
.empty-sub { margin: 0; font-size: 0.82rem; max-width: 22ch; }

/* ---------- footnote ---------- */
.footnote {
  margin-top: 2rem;
  text-align: center;
  font-size: 0.74rem;
  color: var(--ink-faint);
}

/* ---------- confirm dialog ---------- */
.overlay[hidden] { display: none; }
.overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 1.2rem;
  background: rgba(59, 55, 47, 0.32);
  backdrop-filter: blur(3px);
  animation: fade 0.2s var(--ease);
}
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

.dialog {
  width: min(380px, 100%);
  background: var(--card);
  border: 1px solid var(--card-edge);
  border-radius: var(--radius);
  padding: 1.6rem;
  box-shadow: var(--shadow-md);
  animation: pop 0.25s var(--ease);
}
@keyframes pop { from { opacity: 0; transform: scale(0.95) translateY(8px); } to { opacity: 1; transform: none; } }
.dialog h3 { margin: 0 0 0.5rem; font-family: "Fraunces", serif; font-weight: 500; font-size: 1.3rem; }
.dialog p { margin: 0 0 1.4rem; font-size: 0.9rem; color: var(--ink-soft); }
.dialog-actions { display: flex; justify-content: flex-end; gap: 0.6rem; }

/* ---------- toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: max(1.3rem, env(safe-area-inset-bottom));
  transform: translateX(-50%) translateY(20px);
  z-index: 60;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.7rem 1.1rem;
  font-size: 0.86rem;
  font-weight: 500;
  color: var(--card);
  background: var(--ink);
  border-radius: 999px;
  box-shadow: var(--shadow-md);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s var(--ease), transform 0.3s var(--ease);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.001ms !important; transition-duration: 0.001ms !important; }
}
