:root {
  --bg: #f4faf7;
  --card: #ffffff;
  --primary: #185a9d;
  --accent: #43cea2;
  --accent-dark: #2fae74;
  --text: #1f3a2e;
  --muted: #6b8579;
  --shadow: 0 6px 20px rgba(24, 90, 157, 0.10);
  --radius: 18px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-text-size-adjust: 100%;
}

header {
  background: linear-gradient(135deg, var(--accent) 0%, var(--primary) 100%);
  color: #fff;
  padding: 22px 18px 28px;
  text-align: center;
  border-bottom-left-radius: 26px;
  border-bottom-right-radius: 26px;
  box-shadow: var(--shadow);
}

header .logo { width: 72px; height: 72px; margin-bottom: 6px; }
header h1 { margin: 4px 0 2px; font-size: 1.5rem; letter-spacing: 0.3px; }
header p { margin: 0; font-size: 0.95rem; opacity: 0.92; }

main { max-width: 640px; margin: 0 auto; padding: 18px 14px 40px; }

#day-nav {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  flex-wrap: wrap;
  padding: 9px 10px;
  background: #fff;
  box-shadow: 0 2px 12px rgba(24, 90, 157, 0.10);
}
#day-nav button {
  border: 1px solid var(--primary);
  background: var(--primary);
  color: #fff;
  font-weight: 700;
  padding: 8px 13px;
  border-radius: 999px;
  cursor: pointer;
  font-size: 0.88rem;
  line-height: 1;
  min-height: 38px;
  display: inline-flex;
  align-items: center;
}
#day-nav #nav-date {
  min-width: 150px;
  text-align: center;
  font-weight: 700;
  color: var(--primary);
  font-size: 0.85rem;
}
#day-nav #btn-today,
#day-nav #btn-shopping {
  background: transparent;
  color: var(--primary);
}
#day-nav button:active { transform: scale(0.95); }

.date-badge {
  display: inline-block;
  background: #fff;
  color: var(--primary);
  font-weight: 700;
  padding: 8px 16px;
  border-radius: 999px;
  box-shadow: var(--shadow);
  margin: 6px 0 18px;
  font-size: 0.95rem;
}

.meal-card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 16px;
  overflow: hidden;
  animation: rise 0.4s ease both;
}

@keyframes rise {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}

.meal-card .meal-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  background: linear-gradient(90deg, rgba(67,206,162,0.16), rgba(24,90,157,0.06));
  border-left: 6px solid var(--accent);
}

.meal-card .meal-head .emoji { font-size: 1.6rem; }
.meal-card .meal-head h2 { margin: 0; font-size: 1.15rem; color: var(--primary); }

.meal-card ul { list-style: none; margin: 0; padding: 8px 16px 14px; }
.meal-card li {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 10px;
  padding: 9px 0;
  border-bottom: 1px dashed #e3ede7;
}
.meal-card li:last-child { border-bottom: none; }
.meal-card li .name { font-weight: 600; }
.meal-card li .grams {
  background: var(--accent);
  color: #fff;
  font-size: 0.8rem;
  font-weight: 700;
  padding: 3px 10px;
  border-radius: 999px;
  white-space: nowrap;
}

.section-title {
  margin: 22px 4px 10px;
  font-size: 1rem;
  color: var(--primary);
  display: flex;
  align-items: center;
  gap: 8px;
}

.box {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px 16px;
  margin-bottom: 16px;
}
.box .row { padding: 7px 0; border-bottom: 1px dashed #e3ede7; display:flex; justify-content: space-between; }
.box .row:last-child { border-bottom: none; }
.box .water { color: var(--accent-dark); font-weight: 700; }

.notes { font-size: 0.86rem; color: var(--muted); }
.notes li { padding: 5px 0; }

.loading, .error { text-align: center; padding: 40px 10px; color: var(--muted); }
.error { color: #c0392b; }

/* Install banner */
#install-banner {
  position: fixed;
  left: 50%;
  bottom: 16px;
  transform: translateX(-50%);
  background: var(--primary);
  color: #fff;
  padding: 12px 16px;
  border-radius: 14px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.25);
  display: none;
  gap: 10px;
  align-items: center;
  z-index: 50;
  max-width: 92vw;
  font-size: 0.9rem;
}
#install-banner button {
  border: none;
  background: var(--accent);
  color: #fff;
  font-weight: 700;
  padding: 8px 14px;
  border-radius: 10px;
  cursor: pointer;
}
#install-banner .dismiss { background: transparent; text-decoration: underline; }

/* Modal */
.modal {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: rgba(20, 40, 30, 0.5);
  display: none;
  align-items: flex-end;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.25s ease;
}
.modal.open { display: flex; opacity: 1; }
.modal-card {
  background: var(--bg);
  width: 100%;
  max-width: 640px;
  max-height: 85vh;
  border-top-left-radius: 22px;
  border-top-right-radius: 22px;
  box-shadow: 0 -8px 30px rgba(0, 0, 0, 0.3);
  display: flex;
  flex-direction: column;
  transform: translateY(100%);
  transition: transform 0.28s cubic-bezier(0.2, 0.8, 0.3, 1);
  overflow: hidden;
}
.modal.open .modal-card { transform: translateY(0); }
@media (min-width: 600px) {
  .modal { align-items: center; }
  .modal-card { border-radius: 22px; max-height: 80vh; }
}
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 18px;
  background: linear-gradient(90deg, rgba(67,206,162,0.16), rgba(24,90,157,0.08));
  border-bottom: 1px solid #e3ede7;
}
.modal-head h2 { margin: 0; font-size: 1.1rem; color: var(--primary); }
.modal-head .dismiss {
  border: none;
  background: transparent;
  font-size: 1.3rem;
  color: var(--muted);
  cursor: pointer;
  padding: 4px 8px;
}
.week-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 8px 12px;
  border-bottom: 1px solid #e3ede7;
  background: rgba(24, 90, 157, 0.04);
}
.week-bar button {
  border: 1px solid var(--primary);
  background: var(--primary);
  color: #fff;
  font-weight: 700;
  font-size: 0.8rem;
  padding: 6px 12px;
  border-radius: 999px;
  cursor: pointer;
}
.week-bar #week-range {
  font-weight: 700;
  color: var(--primary);
  font-size: 0.85rem;
  min-width: 150px;
  text-align: center;
}
.modal-body {
  padding: 14px 18px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.modal-foot {
  margin: 0;
  padding: 10px 18px 16px;
  font-size: 0.75rem;
  color: var(--muted);
  text-align: center;
}
.shop-group { margin-bottom: 14px; }
.shop-group h3 {
  margin: 12px 4px 4px;
  font-size: 0.92rem;
  color: var(--primary);
  border-bottom: 2px solid #e3ede7;
  padding-bottom: 4px;
}
.shopping { list-style: none; margin: 0; padding: 0; }
.shopping li {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 10px;
  padding: 10px 4px;
  border-bottom: 1px dashed #e3ede7;
}
.shopping li:last-child { border-bottom: none; }
.shopping .name { font-weight: 600; }
.shopping .grams {
  background: var(--accent);
  color: #fff;
  font-size: 0.8rem;
  font-weight: 700;
  padding: 3px 10px;
  border-radius: 999px;
  white-space: nowrap;
}

footer { text-align: center; color: var(--muted); font-size: 0.78rem; padding: 20px 12px 30px; }
footer a { color: var(--primary); }

@media (max-width: 380px) {
  header h1 { font-size: 1.3rem; }
  .meal-card li .name { font-size: 0.92rem; }
}
