:root {
  --bg: #fbf5ea;
  --dot: #e8dcc6;
  --panel: #fffdf8;
  --ink: #3a2e25;
  --muted: #8a7a6a;
  --line: #eadfcd;
  --card: #ffffff;
  --shadow: 0 1px 0 rgba(58, 46, 37, .06), 0 4px 12px rgba(58, 46, 37, .08);
  --accent: #e5533d;
  --accent-soft: #fde4de;
  --butter: #f6c343;
  --herb: #4f9a5c;
  --ingredient: #7fbf6a;
  --utensil: #7b8fa6;
  --dish: #f09a3e;
  --radius: 14px;
  --font: 'Nunito', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --display: 'Fredoka', var(--font);
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: var(--font);
  color: var(--ink);
  background: var(--bg);
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
}
button { font: inherit; color: inherit; cursor: pointer; }
[hidden] { display: none !important; }

/* ── Top bar ─────────────────────────────────────── */
.topbar {
  height: 64px;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  position: relative;
  z-index: 5;
}
.brand { display: flex; align-items: center; gap: 8px; min-width: 0; }
.brand-icon { font-size: 28px; }
.brand h1 { font-family: var(--display); font-weight: 600; font-size: 22px; margin: 0; white-space: nowrap; }

.mode {
  display: flex; flex: none;
  background: var(--bg); border: 1px solid var(--line);
  border-radius: 12px; padding: 3px;
}
.mode-btn {
  border: 0; background: none;
  border-radius: 9px; padding: 6px 12px;
  font-weight: 800; font-size: 14px; white-space: nowrap; color: var(--muted);
}
.mode-btn:hover { color: var(--ink); }
.mode-btn.active { background: var(--card); color: var(--ink); box-shadow: var(--shadow); }

.progress {
  flex: 1;
  max-width: 360px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 5px;
  background: none;
  border: 0;
  padding: 6px 8px;
  border-radius: 10px;
  text-align: left;
}
.progress:hover { background: var(--bg); }
.progress-label { font-size: 13px; color: var(--muted); }
.progress-label strong { color: var(--ink); font-size: 15px; }
.progress-track { height: 10px; border-radius: 99px; background: var(--line); overflow: hidden; }
.progress-fill {
  display: block; height: 100%; width: 0;
  background: linear-gradient(90deg, var(--butter), var(--accent));
  border-radius: 99px;
  transition: width .6s cubic-bezier(.2, .9, .3, 1.2);
}

.actions { display: flex; gap: 8px; }
.btn {
  border: 1px solid var(--line);
  background: var(--card);
  border-radius: 10px;
  padding: 8px 12px;
  font-weight: 700;
  font-size: 14px;
  box-shadow: 0 1px 0 rgba(58, 46, 37, .05);
  white-space: nowrap;
}
.btn:hover { border-color: #d8c7ab; background: #fffaf1; }
.btn:active { transform: translateY(1px); }
.btn.danger { color: #b3392a; }
.icon-btn { border: 0; background: none; font-size: 20px; padding: 6px 10px; border-radius: 8px; color: var(--muted); }
.icon-btn:hover { background: var(--bg); color: var(--ink); }

/* ── Layout ──────────────────────────────────────── */
.layout {
  height: calc(100% - 64px);
  display: grid;
  grid-template-columns: 1fr 340px;
}

.counter-col { display: flex; flex-direction: column; min-height: 0; min-width: 0; }

/* ── Mission bar ─────────────────────────────────── */
.mission {
  flex: none;
  display: flex; flex-wrap: wrap; align-items: center; gap: 10px 18px;
  padding: 10px 16px;
  background: linear-gradient(90deg, #fff4dc, var(--panel));
  border-bottom: 1px solid var(--line);
}
.mission-target { display: flex; align-items: center; gap: 10px; }
.mission-target .ico { width: 40px; height: 40px; font-size: 32px; }
.mission-target strong { display: block; font-family: var(--display); font-weight: 600; font-size: 19px; line-height: 1.15; }
.mission-label { font-size: 12px; font-weight: 800; color: var(--accent); text-transform: uppercase; letter-spacing: .06em; }
.mission-slots { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.mission-slots .plus { color: var(--muted); font-weight: 800; }
.slot {
  width: 38px; height: 34px;
  border: 2px dashed #e0c9a3; border-radius: 10px; background: var(--card);
  font-weight: 800; font-size: 16px; color: var(--muted);
}
.slot:hover { border-color: var(--butter); color: var(--ink); }
.slot-waiting {
  width: auto; min-width: 46px; padding: 0 6px;
  font-size: 12px; font-weight: 700; letter-spacing: 0; cursor: default;
  border-style: solid; opacity: .7;
}
.slot-waiting:hover { border-color: #e0c9a3; color: var(--muted); }
.slot-item { border: 0; background: none; padding: 0; border-radius: 10px; }
.slot-item .item { font-size: 13px; padding: 3px 9px 3px 5px; box-shadow: none; }
.slot-item:hover .item { border-color: #d0bb97; background: #fffaf1; }
.mission-done { font-family: var(--display); font-size: 18px; font-weight: 600; }
.mission.mission-new { animation: mission-new .7s ease-out; }
@keyframes mission-new { 0% { background: #ffe29a; } 100% { background: #fff4dc; } }

.table {
  flex: 1; min-height: 0;
  position: relative;
  z-index: 2; /* dragged items float above the pantry */
  background-color: var(--bg);
  background-image: radial-gradient(var(--dot) 1.3px, transparent 1.3px);
  background-size: 22px 22px;
  touch-action: none;
}
.table-help {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center; color: var(--muted); pointer-events: none; padding: 24px;
  transition: opacity .3s;
}
.table-help p { margin: 4px 0; }
.table-help .big { font-family: var(--display); font-size: 22px; color: var(--ink); opacity: .75; }
.table-help .small { font-size: 13px; margin-top: 10px; }
.table.has-items .table-help { opacity: 0; }

/* ── Pantry (sidebar) ────────────────────────────── */
.pantry {
  display: flex; flex-direction: column;
  background: var(--panel);
  border-left: 1px solid var(--line);
  min-height: 0;
  position: relative;
  z-index: 1;
}
.pantry-search { padding: 12px; border-bottom: 1px solid var(--line); }
.pantry-search input {
  width: 100%;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--card);
  font: inherit; font-size: 15px;
  outline: none;
}
.pantry-search input:focus { border-color: var(--butter); box-shadow: 0 0 0 3px #fbe9b8; }
.pantry-list { flex: 1; overflow-y: auto; padding: 4px 12px 16px; }
.pantry-section h3 {
  font-size: 12px; text-transform: uppercase; letter-spacing: .08em;
  color: var(--muted); margin: 14px 2px 8px; font-weight: 800;
  display: flex; justify-content: space-between;
}
.pantry-items { display: flex; flex-wrap: wrap; gap: 6px; }
.pantry-empty { font-size: 13px; color: var(--muted); padding: 4px 2px; }

.pantry-trash {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: rgba(229, 83, 61, .12);
  border: 3px dashed var(--accent);
  color: var(--accent); font-weight: 800; font-size: 18px;
  opacity: 0; pointer-events: none; transition: opacity .15s;
}
.pantry-trash::before { content: '🗑️'; margin-right: 8px; }
.pantry.trash-hot .pantry-trash { opacity: 1; }

/* ── Item pill (shared by pantry, counter, book) ── */
.item {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 11px 5px 7px;
  background: var(--card);
  border: 1px solid var(--line);
  border-left: 4px solid var(--ingredient);
  border-radius: 10px;
  font-weight: 700; font-size: 14px;
  box-shadow: var(--shadow);
  user-select: none; -webkit-user-select: none;
  white-space: nowrap;
}
.item.utensil { border-left-color: var(--utensil); }
.item.dish { border-left-color: var(--dish); }
.pantry .item { cursor: grab; touch-action: pan-y; }
.pantry .item:hover { background: #fffaf1; border-color: #dccbb0; }
.pantry .item.fresh { animation: fresh 1.6s ease-out; }

.ico {
  position: relative;
  display: inline-flex; align-items: center; justify-content: center;
  width: 26px; height: 26px; font-size: 20px; line-height: 1; flex: none;
}
.ico svg {
  width: 22px; height: 22px; fill: none; stroke: #4d5f74;
  stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round;
}
.ico .badge {
  position: absolute; right: -5px; bottom: -4px;
  font-size: 11px;
  background: var(--card); border-radius: 50%;
  width: 16px; height: 16px;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 0 0 1px var(--line);
}

/* ── Things on the counter ───────────────────────── */
.stack {
  position: absolute; top: 0; left: 0;
  touch-action: none;
  cursor: grab;
  will-change: transform;
}
.stack.dragging { cursor: grabbing; z-index: 1000 !important; }
.stack.dragging > .item, .stack.dragging > .pile { transform: scale(1.06) rotate(-1.5deg); box-shadow: 0 10px 24px rgba(58, 46, 37, .2); }
.stack > .item, .stack > .pile { transition: transform .12s, box-shadow .12s; }
.stack.selected > .item, .stack.selected > .pile { outline: 2.5px solid var(--accent); outline-offset: 2px; }
.stack.drop-target > .item, .stack.drop-target > .pile { outline: 3px solid var(--butter); outline-offset: 2px; }

.marquee {
  position: absolute; z-index: 1400; pointer-events: none;
  border: 1.5px dashed var(--accent);
  background: rgba(229, 83, 61, .08);
  border-radius: 4px;
}

.pile {
  background: var(--card);
  border: 2px dashed #e0c9a3;
  border-radius: var(--radius);
  padding: 8px;
  box-shadow: var(--shadow);
  display: flex; flex-direction: column; gap: 6px;
  min-width: 150px;
}
.pile-items { display: flex; flex-direction: column; gap: 5px; }
.pile .item { box-shadow: none; cursor: grab; font-size: 13px; padding: 3px 9px 3px 5px; }
.pile .item:hover { border-color: #d0bb97; }
.cook {
  border: 0;
  border-radius: 10px;
  padding: 7px 10px;
  font-weight: 800; font-size: 14px;
  color: #fff;
  background: linear-gradient(180deg, #f06a4f, var(--accent));
  box-shadow: 0 2px 0 #b93f2c;
}
.cook:hover { filter: brightness(1.06); }
.cook:active { transform: translateY(2px); box-shadow: 0 0 0 #b93f2c; }

.stack.shake > * { animation: shake .45s; }
.stack.cooked > .item { animation: pop .55s cubic-bezier(.2, 1.6, .4, 1); }
.stack.spawn > .item { animation: spawn .25s ease-out; }

.spark {
  position: absolute; pointer-events: none; font-size: 18px; z-index: 1500;
  animation: spark .8s ease-out forwards;
}

/* ── Recipe book modal ───────────────────────────── */
.modal {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(58, 46, 37, .35);
  display: flex; align-items: center; justify-content: center;
  padding: 16px;
  animation: fade .15s;
}
.modal-card {
  width: min(960px, 100%); max-height: min(760px, 100%);
  background: var(--panel);
  border-radius: 18px;
  box-shadow: 0 20px 60px rgba(58, 46, 37, .3);
  display: flex; flex-direction: column;
  overflow: hidden;
}
.modal-head { display: flex; justify-content: space-between; align-items: flex-start; padding: 18px 20px 10px; }
.modal-head h2 { font-family: var(--display); font-weight: 600; margin: 0; font-size: 24px; }
.book-sub { margin: 4px 0 0; color: var(--muted); font-size: 14px; }
.tabs { display: flex; flex-wrap: wrap; gap: 6px; padding: 4px 20px 12px; border-bottom: 1px solid var(--line); flex: none; }
.tab {
  border: 1px solid var(--line); background: var(--card);
  border-radius: 99px; padding: 6px 12px;
  font-size: 13px; font-weight: 700; white-space: nowrap;
}
.tab .count { color: var(--muted); font-weight: 600; margin-left: 4px; }
.tab.active { background: var(--ink); color: #fff; border-color: var(--ink); }
.tab.active .count { color: #e8dcc6; }
.tab.complete:not(.active) { border-color: var(--herb); }

.book-grid {
  flex: 1; overflow-y: auto;
  padding: 16px 20px;
  display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: 10px; align-content: start;
}
.book-card {
  background: var(--card); border: 1px solid var(--line); border-radius: 12px;
  padding: 12px; display: flex; flex-direction: column; gap: 6px;
  text-align: left;
}
button.book-card:hover { border-color: var(--dish); }
.book-card .top { display: flex; align-items: center; gap: 8px; font-weight: 800; }
.book-card .ico { width: 32px; height: 32px; font-size: 26px; }
.book-card .recipe { font-size: 12px; color: var(--muted); line-height: 1.5; }.book-card.locked { background: repeating-linear-gradient(135deg, #fbf7ef, #fbf7ef 8px, #f6f0e4 8px, #f6f0e4 16px); border-style: dashed; }
.book-card.locked .top { color: #b9a990; }
.book-card.locked .ico { filter: grayscale(1); opacity: .5; }
.modal-foot {
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
  padding: 12px 20px; border-top: 1px solid var(--line);
}
.muted { color: var(--muted); font-size: 13px; }

/* ── Saves modal ─────────────────────────────────── */
.saves-card { width: min(560px, 100%); max-height: min(600px, 100%); }
.slot-list { flex: 1; overflow-y: auto; padding: 4px 20px 20px; display: flex; flex-direction: column; gap: 10px; }
.slot-card {
  border: 1px solid var(--line); border-radius: 14px; background: var(--card);
  padding: 14px; display: flex; flex-direction: column; gap: 10px;
}
.slot-card.active { border-color: var(--butter); box-shadow: 0 0 0 2px #fbe9b8; }
.slot-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.slot-head strong { font-family: var(--display); font-size: 16px; font-weight: 600; }
.slot-active-tag { font-size: 11px; font-weight: 800; color: var(--accent); text-transform: uppercase; letter-spacing: .06em; }
.slot-summary { font-size: 13px; color: var(--muted); }
.slot-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.slot-actions .btn { padding: 6px 10px; font-size: 13px; }

/* ── Toasts ──────────────────────────────────────── */
.toasts {
  position: fixed; top: 76px; left: 50%; transform: translateX(-50%);
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  z-index: 60; pointer-events: none; width: max-content; max-width: calc(100vw - 32px);
}
.toast {
  background: var(--ink); color: #fff;
  padding: 10px 16px; border-radius: 12px;
  font-weight: 700; font-size: 14px;
  box-shadow: 0 8px 24px rgba(58, 46, 37, .25);
  display: flex; align-items: center; gap: 8px;
  animation: toast-in .3s cubic-bezier(.2, 1.4, .4, 1);
}
.toast.new { background: linear-gradient(135deg, #f06a4f, #f0a23e); font-size: 16px; padding: 12px 18px; }
.toast.new .ico .badge { box-shadow: none; }
.toast.out { animation: toast-out .25s forwards; }

/* ── Animations ──────────────────────────────────── */
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-7px) rotate(-2deg); }
  40% { transform: translateX(6px) rotate(2deg); }
  60% { transform: translateX(-4px); }
  80% { transform: translateX(3px); }
}
@keyframes pop { 0% { transform: scale(.3); } 100% { transform: scale(1); } }
@keyframes spawn { 0% { transform: scale(.7); opacity: 0; } 100% { transform: scale(1); opacity: 1; } }
@keyframes spark {
  0% { transform: translate(0, 0) scale(.6); opacity: 1; }
  100% { transform: translate(var(--dx), var(--dy)) scale(1.1); opacity: 0; }
}
@keyframes fresh { 0%, 40% { background: #fff1c9; border-color: var(--butter); } 100% { background: var(--card); } }
@keyframes fade { from { opacity: 0; } }
@keyframes toast-in { from { transform: translateY(-12px) scale(.9); opacity: 0; } }
@keyframes toast-out { to { transform: translateY(-8px); opacity: 0; } }

/* ── Small screens ───────────────────────────────── */
@media (max-width: 860px) {
  .actions .btn span { display: none; }
  .brand h1 { font-size: 18px; }
}
@media (max-width: 760px) {
  .topbar { height: auto; flex-wrap: wrap; padding: 8px 16px; gap: 8px; }
  .brand { order: 1; }
  .actions { order: 2; margin-left: auto; }
  .mode { order: 3; }
  .mode-btn { padding: 5px 9px; font-size: 13px; }
  .progress { order: 4; flex: 1; min-width: 0; max-width: none; padding: 2px 0; margin: 0; }
  .mission { padding: 8px 16px; gap: 6px 12px; }
  .mission-target .ico { width: 32px; height: 32px; font-size: 26px; }
  .mission-target strong { font-size: 16px; }
  .layout { height: calc(100% - 108px); grid-template-columns: 1fr; grid-template-rows: 1fr 42%; }
  .pantry { border-left: 0; border-top: 1px solid var(--line); }
  .pantry-search { padding: 8px 16px; }
  .pantry-list { padding: 0 16px 16px; }
  .toasts { top: 116px; }
  .tabs { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; padding: 4px 16px 12px; }
  .book-grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); padding: 12px 16px; }
  .modal-foot { flex-direction: column; align-items: stretch; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
