:root {
  --accent: #ff6b6b;
  --primary: #f8f9fa;
  --secondary: #6c757d;
  --ink: #37424a;
  --board: #eef2f5;
  --metal: #cfd6dc;
  --shadow: 0 6px 14px rgba(40, 50, 60, 0.18);
  --marker: 'Comic Sans MS', 'Segoe Print', 'Chalkboard SE', 'Marker Felt', cursive;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  height: 100%;
  overscroll-behavior: none;
}

body {
  font-family: 'Comic Sans MS', 'Segoe Print', 'Marker Felt', 'Trebuchet MS', sans-serif;
  color: var(--ink);
  background: #b9c1c8;
}

/* Fridge door */
.fridge {
  position: relative;
  max-width: 520px;
  height: 100dvh;
  margin: 0 auto;
  background:
    radial-gradient(1200px 400px at 20% -10%, #ffffff66, transparent),
    linear-gradient(180deg, #f3f6f8 0%, #e8edf1 55%, #dfe6ec 100%);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* Dry-erase smudges */
.smudge {
  position: absolute;
  border-radius: 60% 40% 55% 45%;
  background: radial-gradient(circle at 35% 30%, rgba(120,135,150,0.10), rgba(120,135,150,0.02) 70%);
  filter: blur(4px);
  pointer-events: none;
  z-index: 0;
}
.s1 { width: 130px; height: 90px; top: 6%; left: -20px; transform: rotate(-18deg); }
.s2 { width: 110px; height: 70px; top: 34%; right: -30px; transform: rotate(24deg); }
.s3 { width: 90px; height: 60px; top: 68%; left: -10px; transform: rotate(10deg); }
.s4 { width: 120px; height: 80px; top: 86%; right: -20px; transform: rotate(-30deg); }
.s5 { width: 70px; height: 50px; top: 22%; left: 40%; transform: rotate(14deg); }

.app-header {
  position: relative;
  z-index: 2;
  text-align: center;
  padding: calc(12px + env(safe-area-inset-top)) 16px 6px;
}
.app-title {
  display: block;
  font-family: var(--marker);
  font-size: 26px;
  font-weight: 700;
  letter-spacing: 0.5px;
  color: #2c363f;
  text-shadow: 1px 2px 0 rgba(255,255,255,0.6);
}
.app-sub {
  display: block;
  font-size: 11px;
  color: var(--secondary);
  letter-spacing: 1px;
  text-transform: uppercase;
  margin-top: 2px;
}

.board {
  position: relative;
  z-index: 1;
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 8px 16px calc(110px + env(safe-area-inset-bottom));
}
.board::-webkit-scrollbar { display: none; }

.tab-panel { display: none; }
.tab-panel.active { display: block; animation: fadeIn 0.25s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(6px);} to { opacity:1; transform:none;} }

.hidden { display: none !important; }

/* ---------- DASHBOARD OVERLAY ---------- */
.dash-overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  background:
    radial-gradient(1200px 400px at 20% -10%, #ffffff66, transparent),
    linear-gradient(180deg, #f3f6f8 0%, #e8edf1 55%, #dfe6ec 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity 0.4s, transform 0.4s;
}
.dash-overlay.hidden { opacity: 0; pointer-events: none; transform: scale(1.06); }
.dash-overlay .smudge { z-index: 0; }
.dash-inner { position: relative; z-index: 1; text-align: center; padding: 24px; }

.enter-btn {
  margin-top: 22px;
  padding: 13px 26px;
  border: none;
  border-radius: 14px;
  background: linear-gradient(160deg, #ff8a8a, var(--accent));
  color: #fff;
  font-family: var(--marker);
  font-size: 16px;
  font-weight: 700;
  box-shadow: var(--shadow), inset 0 3px 5px rgba(255,255,255,0.4);
  cursor: pointer;
}

/* ---------- DASHBOARD ---------- */
#tab-dashboard { text-align: center; padding-top: 4px; }
.dash-note {
  font-family: var(--marker);
  font-size: 15px;
  color: #46545f;
  margin-bottom: 8px;
  transform: rotate(-2deg);
}

.magnet-number {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 116px;
  height: 116px;
  border-radius: 22px;
  box-shadow: var(--shadow), inset 0 -8px 12px rgba(0,0,0,0.22), inset 0 5px 8px rgba(255,255,255,0.5);
  transform: rotate(-4deg);
  color: #fff;
  font-weight: 800;
  background: linear-gradient(160deg, #ff8a8a, var(--accent));
  position: relative;
}
.magnet-number::after {
  content: '';
  position: absolute;
  inset: 10px;
  border-radius: 14px;
  background: radial-gradient(circle at 30% 20%, rgba(255,255,255,0.55), transparent 55%);
  pointer-events: none;
}
.magnet-number .mn-inner { font-size: 52px; text-shadow: 0 3px 0 rgba(0,0,0,0.15); z-index: 1; }

.magnet-number.days-count {
  background: linear-gradient(160deg, #6ec6ff, #2f9bf0);
  transform: rotate(5deg);
  width: 92px;
  height: 92px;
  margin-top: 6px;
}
.days-count .mn-inner { font-size: 40px; }

.dash-label {
  font-family: var(--marker);
  font-size: 13px;
  color: #46545f;
  margin-top: 4px;
  margin-bottom: 14px;
}

.quick-btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-top: 6px;
  padding: 13px 20px;
  border: none;
  border-radius: 16px;
  font-family: var(--marker);
  font-size: 15px;
  font-weight: 700;
  color: #fff;
  background: linear-gradient(160deg, #b79bf0, #8a5cf0);
  box-shadow: var(--shadow), inset 0 3px 5px rgba(255,255,255,0.4), inset 0 -5px 8px rgba(0,0,0,0.2);
  transform: rotate(-1deg);
  cursor: pointer;
}
.quick-btn:active { transform: rotate(-1deg) scale(0.96); }
.quick-btn .qb-icon {
  font-family: var(--marker);
  font-size: 18px;
  line-height: 1;
}
.dash-hint {
  margin-top: 16px;
  font-size: 12px;
  color: var(--secondary);
}

/* ---------- PANEL HEADS ---------- */
.panel-head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 8px; }
.panel-head h2 {
  font-family: var(--marker);
  font-size: 20px;
  margin: 0;
  color: #2c363f;
  transform: rotate(-1deg);
}
.week-range, .panel-sub { font-size: 11px; color: var(--secondary); }

/* ---------- SEARCH ---------- */
.search-box input {
  width: 100%;
  padding: 11px 14px;
  border: none;
  border-radius: 14px;
  background: #fff;
  box-shadow: 0 3px 8px rgba(40,50,60,0.12);
  font-family: inherit;
  font-size: 14px;
  color: var(--ink);
  outline: none;
  margin-bottom: 14px;
}
.search-box input::placeholder { color: #a7b0b8; }

/* ---------- WEEK GRID ---------- */
.week-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.day-col {
  background: rgba(255,255,255,0.55);
  border: 1px dashed #c6d0d8;
  border-radius: 16px;
  padding: 8px;
}
.day-col.today { border-style: solid; border-color: var(--accent); }
.day-name {
  font-family: var(--marker);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--secondary);
  margin-bottom: 6px;
}
.day-col.today .day-name { color: var(--accent); }
.day-col.empty-day { cursor: pointer; }
.empty-plus {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  color: #a9b3bb; font-family: var(--marker); font-size: 12px; padding: 14px 0;
}
.empty-plus b { font-size: 22px; line-height: 1; }

/* Meal magnet card */
.meal-card {
  position: relative;
  background: #fff;
  border-radius: 14px;
  box-shadow: 0 4px 10px rgba(40,50,60,0.16), inset 0 2px 3px rgba(255,255,255,0.6);
  margin-bottom: 10px;
  cursor: pointer;
  overflow: hidden;
  transform: rotate(var(--rot, 0deg));
}
.meal-card .m-strip {
  height: 7px;
}
.meal-card .m-body { padding: 9px 10px 10px; }
.meal-card .m-name {
  font-family: var(--marker);
  font-size: 15px;
  line-height: 1.2;
  color: #2c363f;
}
.meal-card .m-day {
  display: inline-block;
  margin-top: 7px;
  padding: 3px 8px;
  border-radius: 20px;
  font-family: var(--marker);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: #fff;
}

/* magnets on card */
.m-heart {
  position: absolute;
  top: 6px; right: 6px;
  width: 18px; height: 18px;
  border-radius: 4px;
  background: var(--accent);
  box-shadow: inset 0 2px 2px rgba(255,255,255,0.5), 0 2px 3px rgba(0,0,0,0.2);
  transform: rotate(8deg);
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-size: 11px; line-height: 1;
}
.m-spatula {
  position: absolute;
  top: 6px; left: 6px;
  width: 18px; height: 18px;
  border-radius: 50%;
  background: linear-gradient(160deg, #ffc46b, #e8a13d);
  box-shadow: inset 0 2px 2px rgba(255,255,255,0.5), 0 2px 3px rgba(0,0,0,0.2);
  transform: rotate(-8deg);
  display: flex; align-items: center; justify-content: center;
  font-size: 10px;
}

/* day colours */
.d0 .m-strip { background: #ff6b6b; } .d0 .m-day { background: #ff6b6b; }
.d1 .m-strip { background: #ff9f43; } .d1 .m-day { background: #ff9f43; }
.d2 .m-strip { background: #ffc94d; } .d2 .m-day { background: #ffc94d; }
.d3 .m-strip { background: #2ecc71; } .d3 .m-day { background: #2ecc71; }
.d4 .m-strip { background: #54a0ff; } .d4 .m-day { background: #54a0ff; }
.d5 .m-strip { background: #9b6bff; } .d5 .m-day { background: #9b6bff; }
.d6 .m-strip { background: #f368e0; } .d6 .m-day { background: #f368e0; }

.ic-day.d0 { background: #ff6b6b; } .ic-day.d1 { background: #ff9f43; }
.ic-day.d2 { background: #ffc94d; } .ic-day.d3 { background: #2ecc71; }
.ic-day.d4 { background: #54a0ff; } .ic-day.d5 { background: #9b6bff; }
.ic-day.d6 { background: #f368e0; }

/* ---------- LISTS (fav/history) ---------- */
.card-list .meal-card { margin-bottom: 12px; }

/* ---------- INSPIRE ---------- */
.inspire-deck {
  position: relative;
  height: 320px;
  margin-top: 6px;
}
.inspire-card {
  position: absolute;
  left: 50%; top: 50%;
  transform: translate(-50%, -50%) rotate(0deg);
  width: 86%;
  min-height: 220px;
  background: #fff;
  border-radius: 18px;
  box-shadow: var(--shadow);
  padding: 18px 16px;
  transition: transform 0.2s, opacity 0.2s;
  will-change: transform;
}
.inspire-card.swiping { transition: none; }
.inspire-card .ic-day {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 20px;
  font-family: var(--marker);
  font-size: 11px;
  text-transform: uppercase;
  color: #fff;
  margin-bottom: 10px;
}
.inspire-card .ic-name {
  font-family: var(--marker);
  font-size: 22px;
  color: #2c363f;
}
.inspire-card .ic-note {
  margin-top: 12px;
  font-size: 13px;
  color: var(--secondary);
}
.inspire-card .ic-note:empty { display: none; }
.inspire-hint {
  text-align: center; font-size: 11px; color: var(--secondary); margin-top: 14px;
}
.swipe-hint-r { position: absolute; right: -34px; top: 50%; transform: translateY(-50%); font-size: 26px; color: var(--secondary); opacity: 0; }
.swipe-hint-l { position: absolute; left: -34px; top: 50%; transform: translateY(-50%); font-size: 26px; color: var(--secondary); opacity: 0; }

/* ---------- HISTORY ---------- */
.history-week { margin-bottom: 18px; }
.history-week-head {
  font-family: var(--marker);
  font-size: 12px;
  color: var(--secondary);
  margin-bottom: 8px;
  border-bottom: 1px dashed #c6d0d8;
  padding-bottom: 4px;
}
.hist-wrap { position: relative; }
.repurpose-btn {
  display: block;
  width: 100%;
  margin: -2px 0 12px;
  padding: 9px;
  border: none;
  border-radius: 10px;
  background: #fff;
  color: #2c363f;
  font-family: var(--marker);
  font-size: 12px;
  font-weight: 700;
  box-shadow: 0 3px 8px rgba(40,50,60,0.14);
  cursor: pointer;
}
.repurpose-btn:active { transform: scale(0.98); }

/* swipe wrap for favourites */
.swipe-wrap { position: relative; overflow: hidden; }

/* ---------- EMPTY STATES ---------- */
.panel-empty { text-align: center; padding: 40px 10px; }
.panel-empty p { font-family: var(--marker); color: var(--secondary); font-size: 14px; max-width: 240px; margin: 12px auto 0; }
.empty-magnet {
  width: 74px; height: 74px; margin: 0 auto;
  border-radius: 18px;
  box-shadow: var(--shadow), inset 0 -6px 8px rgba(0,0,0,0.2), inset 0 4px 6px rgba(255,255,255,0.5);
  background: linear-gradient(160deg, #d7dde3, #aeb7c0);
  transform: rotate(-5deg);
  display: flex; align-items: center; justify-content: center;
  color: rgba(255,255,255,0.9); font-size: 30px;
}
.empty-magnet.m-heart { background: linear-gradient(160deg, #ffb3b3, #ff6b6b); font-size: 24px; }
.empty-magnet.m-log { background: linear-gradient(160deg, #ffd58a, #e8a13d); }
.empty-magnet.m-shuffle { background: linear-gradient(160deg, #b79bf0, #8a5cf0); }

/* ---------- TAB BAR ---------- */
.tabbar {
  position: fixed;
  bottom: 0; left: 50%; transform: translateX(-50%);
  width: 100%; max-width: 520px;
  display: flex;
  justify-content: space-around;
  align-items: flex-start;
  padding: 8px 6px calc(8px + env(safe-area-inset-bottom));
  background:
    linear-gradient(180deg, #c2c9cf, #aeb7be);
  border-top: 2px solid #8f9aa3;
  box-shadow: 0 -6px 14px rgba(0,0,0,0.25);
  z-index: 20;
}
.tab-btn {
  background: none; border: none;
  display: flex; flex-direction: column; align-items: center;
  gap: 3px; cursor: pointer; padding: 0;
}
.tab-label { font-size: 10px; color: #46545f; font-weight: 600; }

/* fruit magnets */
.fruit {
  width: 40px; height: 40px;
  border-radius: 50%;
  display: block;
  box-shadow: 0 3px 6px rgba(0,0,0,0.35), inset 0 3px 4px rgba(255,255,255,0.4), inset 0 -3px 5px rgba(0,0,0,0.25);
  filter: saturate(0.35) brightness(0.9);
  transform: rotate(0deg);
  transition: transform 0.2s, filter 0.2s;
  position: relative;
}
.tab-btn.active .fruit {
  filter: saturate(1.1) brightness(1.05);
  transform: rotate(-12deg) scale(1.12);
  box-shadow: 0 5px 10px rgba(0,0,0,0.4), inset 0 3px 4px rgba(255,255,255,0.5), inset 0 -4px 6px rgba(0,0,0,0.25);
}

/* apple */
.fruit-apple {
  background: radial-gradient(circle at 32% 28%, #ff8a8a, #e0453f 70%);
}
.fruit-apple .stem {
  position: absolute; top: -5px; left: 24px;
  width: 4px; height: 8px;
  background: #7a5230; border-radius: 3px; transform: rotate(-24deg);
}
/* watermelon */
.fruit-watermelon {
  border-radius: 48% 48% 52% 52%;
  background: linear-gradient(180deg, #5fd36e 0%, #37a94a 46%, #ff6b6b 46%, #e0453f 100%);
}
/* lemon */
.fruit-lemon {
  background: radial-gradient(circle at 34% 30%, #ffe27a, #f0b429 75%);
  border-radius: 14% 48% 14% 48%;
  transform: rotate(45deg);
}
.tab-btn .fruit-lemon { transform: rotate(45deg); }
.tab-btn.active .fruit-lemon { transform: rotate(30deg) scale(1.12); }
/* grape */
.fruit-grape {
  background: radial-gradient(circle at 34% 30%, #c68bff, #8a4bd0 75%);
}
.fruit-grape::before {
  content: '';
  position: absolute; top: -6px; left: 16px;
  width: 10px; height: 10px; border-radius: 50%;
  background: #7a5230;
}
.fruit-star {
  background: radial-gradient(circle at 34% 30%, #fff, #cfd6dc 70%);
}

/* ---------- MODAL ---------- */
.modal { position: fixed; inset: 0; z-index: 40; display: flex; align-items: flex-end; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(30,40,50,0.5); }
.modal-card {
  position: relative;
  width: 100%; max-width: 520px; margin: 0 auto;
  background: #fff;
  border-radius: 22px 22px 0 0;
  padding: 18px 18px calc(18px + env(safe-area-inset-bottom));
  box-shadow: 0 -10px 30px rgba(0,0,0,0.3);
  animation: slideUp 0.25s ease;
  max-height: 88dvh;
  overflow-y: auto;
}
@keyframes slideUp { from { transform: translateY(40px); opacity: 0;} to { transform:none; opacity:1;} }
.modal-card h3 { font-family: var(--marker); margin: 0 0 14px; color: #2c363f; }
.modal-card label { display: block; margin-bottom: 12px; font-size: 13px; color: var(--secondary); font-weight: 600; }
.modal-card input, .modal-card select, .modal-card textarea {
  width: 100%;
  margin-top: 5px;
  padding: 11px 12px;
  border: 2px solid #dce3e9;
  border-radius: 12px;
  font-family: inherit; font-size: 14px; color: var(--ink);
  background: #f8fafb;
  outline: none;
}
.modal-card input:focus, .modal-card select:focus, .modal-card textarea:focus { border-color: var(--accent); background: #fff; }
.modal-card .opt { font-weight: 400; font-size: 11px; }
.modal-card .check { display: flex; align-items: center; gap: 8px; }
.modal-card .check input { width: auto; margin: 0; }
.modal-actions { display: flex; gap: 10px; margin-top: 6px; }
.btn {
  flex: 1;
  padding: 12px;
  border: none;
  border-radius: 12px;
  font-family: var(--marker);
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
}
.btn.solid { background: var(--accent); color: #fff; box-shadow: 0 3px 8px rgba(255,107,107,0.4); }
.btn.ghost { background: #eceff2; color: var(--secondary); }
.btn.danger { background: #fbe9e7; color: #c0392b; margin-top: 10px; }

/* ---------- TOAST ---------- */
.toast {
  position: fixed;
  left: 50%; bottom: calc(90px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: #2c363f;
  color: #fff;
  padding: 11px 18px;
  border-radius: 24px;
  font-family: var(--marker);
  font-size: 13px;
  box-shadow: 0 6px 16px rgba(0,0,0,0.3);
  z-index: 60;
  opacity: 0;
  transition: opacity 0.25s, transform 0.25s;
  white-space: nowrap;
  max-width: 86%;
  text-align: center;
  overflow: hidden; text-overflow: ellipsis;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(-6px); }

@media (min-width: 600px) {
  .modal-card { border-radius: 22px; margin: auto 16px; }
}