:root {
  --primary: #d94a38;
  --secondary: #2e6b75;
  --accent: #f4b41a;
  --fridge-dark: #242b33;
  --fridge-dark2: #1b2128;
  --paper: #fdfbf5;
  --paper-line: #e7e2d2;
  --ink: #3a3a35;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--fridge-dark2);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--ink);
  -webkit-tap-highlight-color: transparent;
}

body {
  display: flex;
  justify-content: center;
}

.fridge {
  position: relative;
  width: 100%;
  max-width: 480px;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  background:
    radial-gradient(circle at 12% 8%, rgba(255,255,255,0.06), transparent 40%),
    radial-gradient(circle at 88% 92%, rgba(0,0,0,0.35), transparent 45%),
    linear-gradient(160deg, #333b45 0%, var(--fridge-dark) 45%, #1c232b 100%);
  overflow: hidden;
}

/* Whiteboard panel */
.whiteboard {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  margin: 10px 8px 8px;
  padding: 18px 16px 64px;
  background:
    radial-gradient(ellipse at 20% 12%, rgba(255,255,255,0.14), transparent 45%),
    radial-gradient(ellipse at 85% 15%, rgba(255,255,255,0.08), transparent 40%),
    #f0eee6;
  border: 4px solid #dcd8c6;
  border-radius: 14px;
  box-shadow:
    inset 0 0 0 2px #fff,
    0 6px 16px rgba(0,0,0,0.45);
  scrollbar-width: thin;
}
.whiteboard::-webkit-scrollbar { width: 6px; }
.whiteboard::-webkit-scrollbar-thumb { background: #c9c4b0; border-radius: 4px; }

.board-title {
  margin: 0 0 4px;
  font-family: "Comic Sans MS", "Segoe Script", "Bradley Hand", cursive;
  font-size: 2rem;
  letter-spacing: 0.5px;
  color: var(--secondary);
  text-shadow: 1px 1px 0 rgba(0,0,0,0.06);
  text-align: center;
}

.screen { animation: fade 0.22s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

/* Counters */
.counters {
  display: flex;
  gap: 14px;
  justify-content: center;
  margin: 14px 0 4px;
}
.counter {
  text-align: center;
  min-width: 92px;
}
.letter {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 72px;
  min-height: 76px;
  padding: 8px 10px;
  border-radius: 8px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-weight: 800;
  font-size: 2.4rem;
  color: #fff;
  background: linear-gradient(180deg, var(--primary), #c13a2b);
  box-shadow: 0 4px 0 rgba(0,0,0,0.22), inset 0 -2px 3px rgba(0,0,0,0.25), inset 0 1px 0 rgba(255,255,255,0.35);
  text-shadow: 1px 2px 0 rgba(0,0,0,0.3);
}
.counter:nth-child(2) .letter { background: linear-gradient(180deg, var(--secondary), #24535b); }
.sticker-label {
  margin-top: 6px;
  font-family: "Comic Sans MS", "Segoe Script", cursive;
  font-size: 0.92rem;
  color: #3c4a4f;
}

/* Add meal button */
.add-meal-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  margin: 16px 0 6px;
  padding: 14px;
  font-family: "Comic Sans MS", "Segoe Script", cursive;
  font-size: 1.25rem;
  font-weight: 700;
  color: #2a2a26;
  background: var(--accent);
  border: 0;
  border-radius: 10px;
  box-shadow: 0 5px 0 rgba(180,132,16,0.9), 0 3px 6px rgba(0,0,0,0.2);
  cursor: pointer;
}
.add-meal-btn .plus { font-size: 1.6rem; line-height: 1; }
.add-meal-btn:active { transform: translateY(2px); box-shadow: 0 3px 0 rgba(180,132,16,0.9); }

.section-head {
  margin: 18px 0 8px;
  font-family: "Comic Sans MS", "Segoe Script", cursive;
  font-size: 1.05rem;
  color: #6a6355;
  border-bottom: 2px dashed var(--paper-line);
  padding-bottom: 4px;
}

/* Meal tiles */
.meal-list, .plan-groups { display: flex; flex-direction: column; gap: 8px; }

.meal-tile {
  position: relative;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 12px;
  background: #fff;
  border: 1px solid #e2ded2;
  border-left: 4px solid var(--secondary);
  border-radius: 9px;
  box-shadow: 0 2px 4px rgba(0,0,0,0.08);
}
.meal-tile.cooked { border-left-color: #4caf50; }
.meal-tile .emoji { font-size: 1.5rem; flex: 0 0 auto; }
.meal-tile .tile-info { flex: 1 1 auto; min-width: 0; }
.meal-tile .tile-name {
  font-family: "Comic Sans MS", "Segoe Script", cursive;
  font-size: 1.05rem;
  color: #333;
  line-height: 1.2;
}
.meal-tile .tile-meta {
  font-size: 0.72rem;
  color: #8a8678;
  margin-top: 2px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.meal-tile .tile-actions { display: flex; gap: 6px; flex: 0 0 auto; }
.meal-tile .act {
  border: 0;
  background: #f0eee4;
  border-radius: 7px;
  padding: 7px 9px;
  font-size: 0.78rem;
  font-weight: 600;
  color: #3a3a35;
  cursor: pointer;
}
.meal-tile .act.edit { background: #e8f0ef; color: var(--secondary); }
.meal-tile .act.del { background: #fbe7e2; color: var(--primary); }
.meal-tile .act:active { opacity: 0.7; }

/* Plan groups */
.day-group { margin-bottom: 14px; }
.day-head {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin: 0 0 6px;
  font-family: "Comic Sans MS", "Segoe Script", cursive;
  color: var(--secondary);
  font-size: 1.05rem;
}
.day-head .count { font-size: 0.72rem; color: #9a9584; font-family: sans-serif; }
.day-empty { font-size: 0.8rem; color: #a29c8a; font-style: italic; padding-left: 4px; }

/* Search */
.search-wrap { margin: 0 0 14px; }
.search {
  width: 100%;
  padding: 12px 14px;
  font-size: 1rem;
  border: 2px solid #d8d2bd;
  border-radius: 999px;
  background: #fff;
  outline: none;
}
.search:focus { border-color: var(--secondary); }

/* Notepad form */
.notepad {
  background: #fff;
  border-radius: 10px;
  box-shadow: 0 4px 8px rgba(0,0,0,0.1);
  overflow: hidden;
}
.notepad::before {
  content: "";
  display: block;
  height: 8px;
  background: repeating-linear-gradient(90deg, var(--primary) 0 22px, transparent 22px 34px, var(--accent) 34px 56px, transparent 56px 64px, var(--secondary) 64px 86px, transparent 86px 100px);
}
.form-title {
  padding: 16px 18px 4px;
  font-family: "Comic Sans MS", "Segoe Script", cursive;
  font-size: 1.3rem;
  color: #333;
}
form#mealForm {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 6px 18px 18px;
}
form#mealForm label { font-size: 0.78rem; font-weight: 700; color: #6a655a; }
form#mealForm select,
form#mealForm input,
form#mealForm textarea {
  width: 100%;
  padding: 11px 12px;
  font-size: 1rem;
  border: 2px solid #d8d2bd;
  border-radius: 8px;
  background: #fbfaf5;
  outline: none;
}
form#mealForm select:focus,
form#mealForm input:focus,
form#mealForm textarea:focus { border-color: var(--secondary); background: #fff; }
.form-error {
  background: #fbe7e2;
  color: var(--primary);
  padding: 10px;
  border-radius: 8px;
  font-size: 0.85rem;
  font-weight: 600;
}
.form-actions { display: flex; gap: 10px; margin-top: 6px; }
.btn-primary {
  flex: 1;
  padding: 13px;
  border: 0;
  border-radius: 9px;
  background: var(--primary);
  color: #fff;
  font-size: 1rem;
  font-weight: 700;
  box-shadow: 0 4px 0 #a93525;
  cursor: pointer;
}
.btn-primary:active { transform: translateY(2px); box-shadow: 0 2px 0 #a93525; }
.btn-ghost {
  padding: 13px 16px;
  border: 2px solid #d8d2bd;
  border-radius: 9px;
  background: #fff;
  color: #666;
  font-weight: 600;
  cursor: pointer;
}

/* Groceries */
.grocery-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
  font-family: "Comic Sans MS", "Segoe Script", cursive;
  font-size: 1.2rem;
  color: #333;
}
.clear-btn {
  border: 2px solid var(--primary);
  color: var(--primary);
  background: #fff;
  border-radius: 999px;
  padding: 7px 12px;
  font-size: 0.8rem;
  font-weight: 700;
  cursor: pointer;
}
.clear-btn:active { background: var(--primary); color: #fff; }
.grocery-list {
  background: #fffdf4;
  border: 2px dashed #d9d2ba;
  border-radius: 8px;
  padding: 10px 14px;
}
.grocery-item {
  display: flex;
  gap: 8px;
  padding: 6px 0;
  font-size: 0.96rem;
  border-bottom: 1px dotted #e2dcc6;
}
.grocery-item:last-child { border-bottom: 0; }
.grocery-item .bullet { color: var(--secondary); font-weight: 800; }
.grocery-empty { text-align: center; color: #a29c8a; padding: 30px 0; font-style: italic; }

/* Marker tray */
.tray {
  position: absolute;
  left: 6%;
  right: 6%;
  bottom: 0;
  height: 26px;
  background: linear-gradient(180deg, #232323, #111);
  border-radius: 12px 12px 6px 6px;
  box-shadow: 0 -1px 0 rgba(255,255,255,0.1), inset 0 3px 4px rgba(0,0,0,0.7);
}
.tray-ink {
  position: absolute;
  top: 6px;
  left: 8px;
  right: 8px;
  height: 6px;
  border-radius: 4px;
  background: linear-gradient(90deg, #333 0 10%, #444 10% 24%, #2b2b2b 24% 46%, #3a3a3a 46% 68%, #333 68% 100%);
  box-shadow: inset 0 1px 2px rgba(0,0,0,0.9);
}

/* Bottom tab bar: spice jars */
.tabbar {
  flex: 0 0 auto;
  display: flex;
  justify-content: space-around;
  align-items: flex-start;
  padding: 10px 6px calc(12px + env(safe-area-inset-bottom));
  background: linear-gradient(180deg, #39424d, #2b323b);
  border-top: 3px solid #1f252c;
  position: relative;
  z-index: 5;
}
.tab {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  width: 22%;
  padding: 0;
  background: none;
  border: 0;
  cursor: pointer;
}
.jar { position: relative; width: 44px; height: 46px; display: block; filter: saturate(0.85); }
.jar-body {
  position: absolute;
  bottom: 2px;
  left: 6px;
  right: 6px;
  height: 30px;
  border-radius: 7px 7px 9px 9px;
  background: linear-gradient(180deg, #fdf6e3, #efe3c0);
  box-shadow: 0 3px 0 rgba(0,0,0,0.35), inset 0 -3px 4px rgba(0,0,0,0.12);
}
.jar-oregano .jar-body { background: linear-gradient(180deg, #eef7ee, #cfe5cf); }
.jar-yellow .jar-body { background: linear-gradient(180deg, #fdf3c6, #efd98c); }
.jar-black .jar-body { background: linear-gradient(180deg, #e6e6e6, #c4c4c4); }

.jar .lid {
  position: absolute;
  top: 3px;
  left: 8px;
  right: 8px;
  height: 13px;
  border-radius: 3px;
  background: linear-gradient(180deg, #c9c3b0, #9e9888);
  box-shadow: 0 1px 1px rgba(0,0,0,0.4);
  transition: transform 0.18s ease, top 0.18s ease;
}
.jar-oregano .lid { background: linear-gradient(180deg, #b6cfae, #8fae87); }
.jar-yellow .lid { background: linear-gradient(180deg, #d9c26f, #b89e3f); }
.jar-black .lid { background: linear-gradient(180deg, #b5b5b5, #8a8a8a); }

/* Jar spice dot pattern */
.jar::after {
  content: "";
  position: absolute;
  top: 22px;
  left: 14px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: radial-gradient(circle, #b03a28 0 3px, transparent 3px),
              radial-gradient(circle, #b03a28 0 3px, transparent 3px),
              radial-gradient(circle, #b03a28 0 3px, transparent 3px),
              #d94a38;
  background-size: 6px 6px;
  background-position: 1px 1px, 4px 8px, 8px 2px;
  opacity: 0.7;
  z-index: 1;
}
.jar-oregano::after {
  background: radial-gradient(circle, #2e6b75 0 2px, transparent 2px),
              radial-gradient(circle, #2e6b75 0 2px, transparent 2px),
              radial-gradient(circle, #2e6b75 0 2px, transparent 2px),
              #4caf50;
  background-size: 5px 5px;
  background-position: 2px 2px, 4px 9px, 8px 3px;
}
.jar-yellow::after {
  background: radial-gradient(circle, #d9a411 0 2px, transparent 2px),
              radial-gradient(circle, #d9a411 0 2px, transparent 2px),
              radial-gradient(circle, #d9a411 0 2px, transparent 2px),
              #f4b41a;
  background-size: 5px 5px;
  background-position: 2px 2px, 4px 9px, 8px 3px;
}
.jar-black::after {
  background: radial-gradient(circle, #3a3a3a 0 2px, transparent 2px),
              radial-gradient(circle, #3a3a3a 0 2px, transparent 2px),
              radial-gradient(circle, #3a3a3a 0 2px, transparent 2px),
              #5a5a5a;
  background-size: 5px 5px;
  background-position: 2px 2px, 4px 9px, 8px 3px;
}

.tab-label {
  font-size: 0.6rem;
  font-weight: 700;
  letter-spacing: 0.4px;
  color: #cfd6dd;
  text-transform: uppercase;
}

/* Active jar: lid popped, spices + shadow */
.tab.active .jar { filter: saturate(1.05) drop-shadow(0 3px 3px rgba(0,0,0,0.45)); }
.tab.active .lid {
  transform: translate(-4px, -2px) rotate(-12deg);
  top: -3px;
}
.tab.active .jar::after { opacity: 1; }
.tab.active .tab-label { color: #fff; }