:root {
  --primary: #fdfbf7;
  --secondary: #4a4a4a;
  --accent: #ff6b35;
  --board: #f6f6f6;
  --steel: #aab2bd;
  --steel-dark: #7c8490;
  --shadow: rgba(0, 0, 0, 0.22);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --hand: 'Segoe Print', 'Comic Sans MS', 'Bradley Hand', cursive;
}

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

html, body {
  height: 100%;
  background: var(--steel-dark);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  color: var(--secondary);
}

.app {
  height: 100%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* Board surface with stainless frame */
.board-top {
  background: linear-gradient(180deg, #3c4148, #2a2e33);
  color: #fff;
  padding: calc(var(--safe-top) + 14px) 20px 12px;
  border-bottom: 3px solid #5a5f66;
}
.app-title {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: 0.5px;
}
.tagline { font-size: 12px; color: #c8ccd1; margin-top: 2px; }

.board {
  flex: 1;
  overflow-y: auto;
  background:
    radial-gradient(circle at 18% 20%, rgba(255,255,255,0.7), transparent 40%),
    linear-gradient(160deg, #fafaf8, var(--board) 55%, #ececea);
  background-color: var(--board);
  padding: 16px 14px calc(96px + var(--safe-bottom));
  box-shadow: inset 0 6px 22px rgba(0,0,0,0.10);
  border-bottom: 4px solid #5a5f66;
}
.board::-webkit-scrollbar { display: none; }

.hidden { display: none !important; }

.section-title {
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: #8a8f96;
  margin: 20px 4px 12px;
}

/* ---- HOME ---- */
.magnet-row {
  display: flex;
  gap: 14px;
  margin-top: 6px;
}
.big-magnet {
  flex: 1;
  border-radius: 50%;
  aspect-ratio: 1 / 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background:
    radial-gradient(circle at 30% 22%, rgba(255,255,255,0.55), transparent 42%),
    linear-gradient(145deg, #c3cad3, #89919c 60%, #6f7782);
  box-shadow: 0 5px 10px var(--shadow), inset 0 1px 2px rgba(255,255,255,0.6);
  border-radius: 50%;
  text-align: center;
  padding: 8px;
}
.magnet-num {
  font-size: 44px;
  font-weight: 800;
  color: #fff;
  text-shadow: 0 1px 1px rgba(0,0,0,0.25), inset 0 1px 0 rgba(255,255,255,0.3);
  line-height: 1;
}
.magnet-label {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.4px;
  text-transform: uppercase;
  color: #eef0f2;
  text-shadow: 0 1px 1px rgba(0,0,0,0.2);
  margin-top: 4px;
  line-height: 1.15;
}

.quick-add {
  width: 100%;
  margin-top: 22px;
  padding: 15px;
  border: none;
  border-radius: 14px;
  background: linear-gradient(145deg, #ff7a4d, var(--accent));
  color: #fff;
  font-size: 16px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  box-shadow: 0 6px 14px rgba(255,107,53,0.4);
  cursor: pointer;
}
.quick-add .plus { font-size: 22px; line-height: 1; }

.recent-list { list-style: none; }

/* ---- sticky notes ---- */
.sticky {
  position: relative;
  padding: 26px 12px 10px;
  border-radius: 4px;
  box-shadow: 0 4px 9px var(--shadow);
  font-family: var(--hand);
  transform: rotate(var(--rot, -1deg));
}
.sticky .magnet {
  position: absolute;
  top: -5px;
  left: 50%;
  width: 15px;
  height: 15px;
  border-radius: 50%;
  transform: translateX(-50%);
  background:
    radial-gradient(circle at 35% 30%, #e8ecf0, #9aa3ad 70%),
    linear-gradient(145deg, #cfd6dd, #a9b1bb);
  box-shadow: 0 3px 4px rgba(0,0,0,0.35);
}
.sticky .magnet::after {
  content: '';
  position: absolute;
  top: 15px;
  left: 50%;
  transform: translateX(-50%);
  width: 9px;
  height: 8px;
  background: rgba(0,0,0,0.25);
  border-radius: 50%;
  filter: blur(1px);
}
.sticky .day-lab {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.8px;
  text-transform: uppercase;
  color: rgba(0,0,0,0.55);
  display: block;
  margin-bottom: 5px;
}
.sticky .meal-name {
  font-size: 15px;
  font-weight: 700;
  line-height: 1.2;
  color: #333;
  word-break: break-word;
}
.sticky .type-tag {
  display: inline-block;
  margin-top: 6px;
  font-family: -apple-system, BlinkMacSystemFont, sans-serif;
  font-size: 9px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  color: rgba(0,0,0,0.55);
  background: rgba(255,255,255,0.5);
  border-radius: 6px;
  padding: 2px 6px;
}
.sticky.yellow { background: linear-gradient(180deg, #ffe37a, #f6cd3d); --rot: -1.5deg; }
.sticky.pink   { background: linear-gradient(180deg, #ffb3c1, #f88fa0); --rot: 1.2deg; }
.sticky.blue   { background: linear-gradient(180deg, #b8ddf2, #8cc4e6); --rot: -1deg; }
.sticky.green  { background: linear-gradient(180deg, #c6e6a8, #9fd078); --rot: 1.4deg; }

.recent-item {
  display: flex;
  align-items: center;
  gap: 10px;
  background: #fff;
  border-radius: 10px;
  padding: 10px 12px;
  margin-bottom: 9px;
  box-shadow: 0 2px 5px rgba(0,0,0,0.08);
  border-left: 4px solid var(--accent);
}
.recent-item .ri-name { font-weight: 600; font-size: 14px; flex: 1; }
.recent-item .ri-meta { font-size: 11px; color: #9a9fa6; }
.recent-item .ri-fav { color: var(--accent); }

/* ---- WEEK GRID ---- */
.week-grid { display: flex; flex-direction: column; gap: 10px; }
.week-day { display: flex; gap: 10px; align-items: stretch; }
.week-day .wd-label {
  width: 34px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 10px;
  text-transform: uppercase;
  color: #8a8f96;
}
.wd-card {
  flex: 1;
  min-height: 62px;
  border-radius: 6px;
}
.wd-empty {
  border: 2px dashed #cfd3d8;
  border-radius: 6px;
  min-height: 62px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #b6bbc2;
  font-size: 26px;
  background: rgba(255,255,255,0.35);
  cursor: pointer;
  flex: 1;
}
.wd-empty span { font-size: 26px; line-height: 1; }
.week-today .wd-label { color: var(--accent); }

/* ---- ALL MEALS ---- */
.search-wrap { margin-top: 8px; }
.search-wrap input {
  width: 100%;
  padding: 13px 16px;
  border: 2px solid #e3e0d6;
  border-radius: 12px;
  background: #fff;
  font-size: 15px;
  outline: none;
  color: var(--secondary);
}
.search-wrap input:focus { border-color: var(--accent); }

.meal-list { list-style: none; }
.meal-row {
  position: relative;
  background: #fff;
  border-radius: 10px;
  padding: 13px 42px 13px 14px;
  margin-bottom: 10px;
  box-shadow: 0 2px 5px rgba(0,0,0,0.08);
  cursor: pointer;
  overflow: hidden;
  border-left: 4px solid #ccc;
}
.meal-row.m-yellow { border-left-color: #f6cd3d; }
.meal-row.m-pink { border-left-color: #f88fa0; }
.meal-row.m-blue { border-left-color: #8cc4e6; }
.meal-row.m-green { border-left-color: #9fd078; }
.meal-row .mr-name { font-weight: 600; font-size: 15px; }
.meal-row .mr-meta { font-size: 11px; color: #9a9fa6; margin-top: 2px; }
.meal-row .mr-fav { color: var(--accent); font-weight: 700; }
.meal-row .delete {
  position: absolute;
  right: 0;
  top: 0;
  bottom: 0;
  width: 46px;
  background: #e53935;
  color: #fff;
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  cursor: pointer;
  transform: translateX(100%);
  transition: transform 0.2s ease;
}
.meal-row.swiped .delete { transform: translateX(0); }
.meal-row.swiped .mr-body { transform: translateX(-46px); }
.mr-body { transition: transform 0.2s ease; }

/* ---- FAVORITES ---- */
.fav-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.fav-card { cursor: pointer; }
.fav-card .day-lab { font-size: 8px; }
.fav-card .meal-name { font-size: 13px; }
.fav-card .copy-badge {
  position: absolute;
  bottom: 6px;
  right: 8px;
  font-family: -apple-system, sans-serif;
  font-size: 9px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  color: rgba(0,0,0,0.5);
}

.empty-hint {
  text-align: center;
  color: #b6bbc2;
  font-size: 14px;
  padding: 30px 10px;
  font-family: var(--hand);
}

/* ---- TAB BAR ---- */
.tabbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  height: 74px;
  padding: 8px 10px calc(8px + var(--safe-bottom));
  display: flex;
  justify-content: space-around;
  align-items: flex-end;
  background: linear-gradient(180deg, #3c4148, #2a2e33);
  border-top: 3px solid #5a5f66;
  z-index: 20;
}
.tab {
  background: none;
  border: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  cursor: pointer;
  padding: 2px;
}
.tab-letter {
  width: 46px;
  height: 46px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  font-weight: 800;
  font-family: -apple-system, 'Segoe UI', sans-serif;
  background: linear-gradient(150deg, #df9a5a, #c77b3a);
  color: #fff;
  text-shadow: 0 1px 1px rgba(0,0,0,0.3);
  box-shadow: 0 3px 4px rgba(0,0,0,0.4);
  transition: transform 0.15s ease, filter 0.15s ease;
  position: relative;
}
.tab:nth-child(1) .tab-letter { background: linear-gradient(150deg, #ff8f70, #f26b4a); }
.tab:nth-child(2) .tab-letter { background: linear-gradient(150deg, #7fb6e0, #4f91c4); }
.tab:nth-child(3) .tab-letter { background: linear-gradient(150deg, #95cf6f, #6fae48); }
.tab:nth-child(4) .tab-letter { background: linear-gradient(150deg, #e085c0, #c05e9d); }

.tab-name {
  font-size: 9px;
  font-weight: 600;
  color: #cfd3d8;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}
.tab.active .tab-letter {
  transform: translateY(-6px) rotate(-8deg);
  filter: saturate(1.15);
  box-shadow: 0 6px 8px rgba(0,0,0,0.5);
}
.tab.active .tab-letter::before {
  content: '';
  position: absolute;
  bottom: -7px;
  left: 50%;
  transform: translateX(-50%);
  width: 16px;
  height: 5px;
  border-radius: 3px;
  background: #111;
  box-shadow: 0 2px 3px rgba(0,0,0,0.4);
}
.tab.active .tab-name { color: #fff; }

/* ---- MODAL ---- */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(20, 20, 24, 0.55);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 40;
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
.modal {
  width: 100%;
  max-width: 480px;
  background: var(--primary);
  border-radius: 18px 18px 0 0;
  padding: 20px 18px calc(20px + env(safe-area-inset-bottom, 0px));
  max-height: 88vh;
  overflow-y: auto;
}
.modal-title { font-size: 18px; font-weight: 700; margin-bottom: 16px; }
.field { display: block; margin-bottom: 14px; }
.field > span { display: block; font-size: 12px; font-weight: 600; color: #8a8f96; margin-bottom: 6px; }
.field input[type="text"], .field select {
  width: 100%;
  padding: 12px 14px;
  border: 2px solid #e3e0d6;
  border-radius: 10px;
  font-size: 15px;
  background: #fff;
  color: var(--secondary);
  outline: none;
}
.field input:focus, .field select:focus { border-color: var(--accent); }
.field .error { display: block; color: #e53935; font-size: 11px; margin-top: 4px; min-height: 0; }
.field.toggle { display: flex; align-items: center; gap: 10px; }
.field.toggle .toggle-text { font-weight: 600; color: var(--secondary); font-size: 14px; }
.field.toggle input {
  width: 22px;
  height: 22px;
  accent-color: var(--accent);
}
.modal-actions { display: flex; gap: 10px; margin-top: 18px; }
.btn {
  flex: 1;
  padding: 13px;
  border: none;
  border-radius: 12px;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
}
.btn.ghost { background: #ececec; color: var(--secondary); }
.btn.solid { background: linear-gradient(145deg, #ff7a4d, var(--accent)); color: #fff; box-shadow: 0 4px 10px rgba(255,107,53,0.35); }