/* ============================================
   Tokens
   ============================================ */
:root {
  --paper: #F7F3EC;
  --paper-raised: #FFFFFF;
  --ink: #2B2622;
  --ink-soft: #6B6258;
  --ink-faint: #A89F93;
  --line: rgba(43, 38, 34, 0.12);
  --line-strong: rgba(43, 38, 34, 0.22);

  --spice: #C0552E;
  --spice-soft: #F3DDD2;
  --spice-deep: #8C3A1E;

  --olive: #6B7A4F;
  --olive-soft: #E3E8D8;
  --olive-deep: #4A5536;

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;

  --shadow-card: 0 1px 2px rgba(43, 38, 34, 0.06), 0 1px 1px rgba(43, 38, 34, 0.04);

  --font-display: "Fraunces", Georgia, serif;
  --font-body: "Inter", -apple-system, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #1B1815;
    --paper-raised: #252220;
    --ink: #EFE9E1;
    --ink-soft: #B3A99C;
    --ink-faint: #6E665D;
    --line: rgba(239, 233, 225, 0.12);
    --line-strong: rgba(239, 233, 225, 0.2);
    --spice: #E07A50;
    --spice-soft: #3A2620;
    --spice-deep: #F4A380;
    --olive: #9CAE7C;
    --olive-soft: #2C311F;
    --olive-deep: #C3D2A8;
    --shadow-card: 0 1px 2px rgba(0, 0, 0, 0.3);
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-body);
  -webkit-font-smoothing: antialiased;
}

button, input { font-family: inherit; }

.app {
  max-width: 640px;
  margin: 0 auto;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ============================================
   Topbar
   ============================================ */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--paper);
  border-bottom: 1px solid var(--line);
  padding-top: env(safe-area-inset-top);
}

.topbar-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 20px 14px;
  gap: 12px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-mark {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: var(--spice);
  color: var(--paper-raised);
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 15px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.brand-text h1 {
  font-family: var(--font-display);
  font-size: 19px;
  font-weight: 600;
  margin: 0;
  line-height: 1.2;
  letter-spacing: -0.01em;
}

.brand-text p {
  margin: 1px 0 0;
  font-size: 12px;
  color: var(--ink-soft);
}

.reset-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  background: transparent;
  border: 1px solid var(--line-strong);
  color: var(--ink-soft);
  font-size: 12px;
  font-weight: 500;
  padding: 7px 11px;
  border-radius: var(--radius-md);
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s, color 0.15s;
}
.reset-btn:hover { background: var(--line); color: var(--ink); }
.reset-btn:active { transform: scale(0.97); }
.reset-btn span { display: none; }
@media (min-width: 420px) {
  .reset-btn span { display: inline; }
}

.tabs {
  display: flex;
  gap: 4px;
  padding: 0 16px;
  overflow-x: auto;
}

.tab {
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--ink-soft);
  font-size: 14px;
  font-weight: 500;
  padding: 10px 12px;
  cursor: pointer;
  white-space: nowrap;
  transition: color 0.15s;
}

.tab.active {
  color: var(--spice-deep);
  border-bottom-color: var(--spice);
  font-weight: 600;
}

/* ============================================
   Content / Views
   ============================================ */
.content {
  flex: 1;
  padding: 20px 20px 32px;
}

.view { display: none; }
.view.active { display: block; animation: fadeIn 0.2s ease; }

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

.view-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.view-head h2 {
  font-family: var(--font-display);
  font-size: 22px;
  font-weight: 600;
  margin: 0;
  letter-spacing: -0.01em;
}

.view-sub {
  margin: 3px 0 0;
  font-size: 13px;
  color: var(--ink-soft);
}

.progress-pill {
  flex-shrink: 0;
  background: var(--paper-raised);
  border: 1px solid var(--line);
  color: var(--ink-soft);
  font-size: 12px;
  font-weight: 600;
  padding: 6px 12px;
  border-radius: 20px;
  font-family: var(--font-body);
  margin-top: 2px;
}

.progress-track {
  height: 4px;
  background: var(--line);
  border-radius: 2px;
  overflow: hidden;
  margin-bottom: 20px;
}

.progress-fill {
  height: 100%;
  background: var(--spice);
  border-radius: 2px;
  width: 0%;
  transition: width 0.3s ease;
}

/* ============================================
   Shopping list
   ============================================ */
.shop-groups {
  display: flex;
  flex-direction: column;
  gap: 22px;
}

.shop-group-title {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--ink-faint);
  margin: 0 0 8px;
}

.shop-items {
  display: flex;
  flex-direction: column;
  gap: 1px;
  background: var(--paper-raised);
  border-radius: var(--radius-lg);
  border: 1px solid var(--line);
  overflow: hidden;
  box-shadow: var(--shadow-card);
}

.shop-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 13px 14px;
  border-bottom: 1px solid var(--line);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}
.shop-item:last-child { border-bottom: none; }

.shop-check {
  flex-shrink: 0;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 1.5px solid var(--line-strong);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, border-color 0.15s;
}

.shop-item.checked .shop-check {
  background: var(--olive);
  border-color: var(--olive);
}

.shop-check svg {
  opacity: 0;
  transform: scale(0.6);
  transition: opacity 0.15s, transform 0.15s;
}
.shop-item.checked .shop-check svg {
  opacity: 1;
  transform: scale(1);
}

.shop-label {
  font-size: 14.5px;
  color: var(--ink);
  position: relative;
  line-height: 1.4;
}

.shop-item.checked .shop-label {
  color: var(--ink-faint);
}

.shop-label .strike {
  position: absolute;
  left: -2%;
  top: 50%;
  width: 0%;
  height: 1.4px;
  background: var(--ink-faint);
  transform: rotate(-1.5deg);
  transition: width 0.25s ease;
}
.shop-item.checked .shop-label .strike {
  width: 104%;
}

.shop-item-remove {
  margin-left: auto;
  flex-shrink: 0;
  background: none;
  border: none;
  color: var(--ink-faint);
  padding: 4px;
  cursor: pointer;
  display: none;
  align-items: center;
}
.shop-item.custom .shop-item-remove { display: flex; }
.shop-item-remove:hover { color: var(--spice-deep); }

.add-row {
  display: flex;
  gap: 8px;
  margin-top: 18px;
}

.add-row input {
  flex: 1;
  background: var(--paper-raised);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-md);
  padding: 11px 14px;
  font-size: 14px;
  color: var(--ink);
}
.add-row input:focus {
  outline: none;
  border-color: var(--spice);
  box-shadow: 0 0 0 3px var(--spice-soft);
}
.add-row input::placeholder { color: var(--ink-faint); }

.add-row button {
  flex-shrink: 0;
  width: 42px;
  height: 42px;
  border-radius: var(--radius-md);
  background: var(--spice);
  color: var(--paper-raised);
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.15s;
}
.add-row button:hover { background: var(--spice-deep); }
.add-row button:active { transform: scale(0.96); }

/* ============================================
   Menu view
   ============================================ */
.day-pills {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding-bottom: 4px;
  margin: 0 -20px 18px;
  padding-left: 20px;
}

.day-pills-spacer {
  flex: 0 0 14px;
}

.day-pill {
  flex-shrink: 0;
  background: var(--paper-raised);
  border: 1px solid var(--line);
  color: var(--ink-soft);
  font-size: 13px;
  font-weight: 500;
  padding: 8px 14px;
  border-radius: 20px;
  cursor: pointer;
  white-space: nowrap;
}

.day-pill.active {
  background: var(--spice);
  border-color: var(--spice);
  color: var(--paper-raised);
  font-weight: 600;
}

.menu-day {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.meal-card {
  background: var(--paper-raised);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 14px 16px;
  box-shadow: var(--shadow-card);
}

.meal-card-top {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 4px;
}

.meal-label {
  font-family: var(--font-display);
  font-size: 13px;
  font-weight: 600;
  color: var(--spice-deep);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.meal-text {
  font-size: 14.5px;
  color: var(--ink);
  line-height: 1.5;
}

.day-kcal-tag {
  margin-top: 6px;
  display: inline-block;
  font-size: 11.5px;
  color: var(--ink-soft);
  background: var(--olive-soft);
  padding: 3px 10px;
  border-radius: 12px;
}

/* ============================================
   Prep view
   ============================================ */
.prep-steps {
  list-style: none;
  margin: 0 0 24px;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.prep-step {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  background: var(--paper-raised);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 14px 16px;
  cursor: pointer;
  box-shadow: var(--shadow-card);
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

.prep-step.done {
  background: var(--olive-soft);
  border-color: transparent;
}

.prep-check {
  flex-shrink: 0;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 1.5px solid var(--line-strong);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-display);
  font-size: 12px;
  font-weight: 600;
  color: var(--ink-soft);
  margin-top: 1px;
  transition: background 0.15s, border-color 0.15s;
}

.prep-step.done .prep-check {
  background: var(--olive);
  border-color: var(--olive);
}
.prep-step.done .prep-check svg { opacity: 1; transform: scale(1); }
.prep-check svg { opacity: 0; transform: scale(0.6); transition: opacity 0.15s, transform 0.15s; color: var(--paper-raised); }
.prep-check .num { transition: opacity 0.15s; }
.prep-step.done .prep-check .num { opacity: 0; }

.prep-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--ink);
  margin: 0 0 3px;
}
.prep-step.done .prep-title { color: var(--olive-deep); }

.prep-detail {
  font-size: 13px;
  color: var(--ink-soft);
  line-height: 1.5;
  margin: 0 0 6px;
}

.prep-time {
  font-size: 11.5px;
  color: var(--ink-faint);
  display: flex;
  align-items: center;
  gap: 4px;
}

.storage-note h3 {
  font-family: var(--font-display);
  font-size: 15px;
  font-weight: 600;
  margin: 0 0 10px;
}

.storage-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 8px;
}

.storage-item {
  background: var(--paper-raised);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  padding: 10px 12px;
}

.storage-item-name {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--ink);
}

.storage-item-time {
  font-size: 11.5px;
  color: var(--ink-soft);
  margin-top: 2px;
}

/* ============================================
   Footer
   ============================================ */
.foot {
  text-align: center;
  padding: 16px 20px calc(20px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
}

.foot p {
  margin: 0;
  font-size: 11.5px;
  color: var(--ink-faint);
}

/* Focus visibility for keyboard users */
button:focus-visible, input:focus-visible {
  outline: 2px solid var(--spice);
  outline-offset: 2px;
}

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