@font-face {
  font-family: "Fredoka";
  src: url("/static/fonts/fredoka.woff2") format("woff2");
  font-weight: 400 700;
  font-display: swap;
}

:root {
  --paper: #fbf2e4;
  --card: #fffdf8;
  --ink: #4a3b34;
  --muted: #9d8c7e;
  --line: #efe1cd;

  --terra: #e07a5f;       /* primary */
  --terra-deep: #c25e44;
  --honey: #eab646;
  --sage: #82a37e;
  --sage-deep: #5f7f5d;
  --sage-soft: #eef4e8;
  --sky: #7cabc6;
  --plum: #b585ab;
  --berry: #d56a8b;
  --red: #d4665a;

  --radius: 26px;
  --shadow: 0 16px 30px -20px rgba(120, 70, 40, 0.55);
  --display: "Fredoka", ui-rounded, "SF Pro Rounded", system-ui, sans-serif;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--sans);
  color: var(--ink);
  line-height: 1.45;
  font-size: 17px;
  background:
    radial-gradient(440px 340px at 88% 4%, rgba(234,182,70,0.18), transparent 70%),
    radial-gradient(400px 320px at 2% 12%, rgba(124,171,198,0.16), transparent 70%),
    radial-gradient(560px 380px at 50% 102%, rgba(130,163,126,0.14), transparent 70%),
    var(--paper);
  background-attachment: fixed;
}
body::before {  /* faint paper dot texture */
  content: ""; position: fixed; inset: 0; z-index: -1; pointer-events: none;
  background-image: radial-gradient(rgba(120,70,40,0.045) 1.4px, transparent 1.5px);
  background-size: 22px 22px;
}
.wrap { width: 100%; max-width: 860px; margin: 0 auto; padding: 0 16px; }
h1, h2, h3, .brand, .weeklabel strong, .aname, .pi-name, .fr-name, .btn, .chip, .count {
  font-family: var(--display);
}

/* Header with scalloped bottom edge */
.topbar {
  position: sticky; top: 0; z-index: 10; color: #fff; overflow: visible;
  background: linear-gradient(118deg, #e67d5c 0%, #e89a55 60%, #edb24f 100%);
  padding-top: env(safe-area-inset-top);
}
.topbar::after {
  content: ""; position: absolute; left: 0; right: 0; bottom: -15px; height: 16px;
  pointer-events: none;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='120' height='16'%3E%3Cpath d='M0 16 V7 Q15 -1 30 7 T60 7 T90 7 T120 7 V16 Z' fill='%23fbf2e4'/%3E%3C/svg%3E") repeat-x;
  background-size: 60px 16px;
}
.topbar-inner { display: flex; align-items: center; justify-content: space-between; min-height: 62px; gap: 10px; flex-wrap: wrap; }
.brand { color: #fff; text-decoration: none; font-weight: 700; font-size: 1.42rem; display: inline-flex; align-items: center; gap: 8px; text-shadow: 0 2px 6px rgba(150,70,40,0.3); }
.brand .logo { display: inline-block; animation: wiggle 3s ease-in-out infinite; transform-origin: 70% 70%; }
@keyframes wiggle { 0%,90%,100%{transform:rotate(0)} 93%{transform:rotate(13deg)} 97%{transform:rotate(-9deg)} }
.tabs { display: flex; gap: 6px; }
.tabs a {
  color: #fff; text-decoration: none; padding: 8px 15px; border-radius: 999px;
  font-size: 0.95rem; font-weight: 600; font-family: var(--display);
  background: rgba(255,255,255,0.2); transition: transform .12s ease, background .12s ease;
}
.tabs a:hover { transform: translateY(-1px); }
.tabs a.on { background: #fff; color: var(--terra-deep); box-shadow: 0 4px 10px -5px rgba(150,70,40,0.5); }

main.wrap { padding-top: 26px; padding-bottom: 48px; }

/* Week nav */
.weeknav { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; }
.weeklabel { flex: 1; text-align: center; font-size: 1.2rem; }
.weeklabel strong { font-weight: 600; }
.wbtn {
  flex: 0 0 auto; width: 54px; height: 54px; border-radius: 50%;
  background: var(--card); border: 2px solid var(--line);
  box-shadow: 0 4px 0 var(--line), var(--shadow);
  display: flex; align-items: center; justify-content: center;
  font-size: 1.8rem; color: var(--terra); text-decoration: none; font-weight: 700;
  transition: transform .12s ease;
}
.wbtn:hover { transform: translateY(-2px); }
.wbtn:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--line); }
.badge { font-size: 0.7rem; padding: 3px 10px; border-radius: 999px; vertical-align: middle; font-weight: 700; font-family: var(--display); }
.badge.now { background: var(--sage-soft); color: var(--sage-deep); margin-left: 8px; }
.thisweek { display: inline-block; margin-top: 2px; font-size: 0.85rem; color: var(--terra); font-weight: 600; }

/* Cards — squircle "sticker" panels */
.card {
  background: var(--card); border-radius: var(--radius); border: 2px solid var(--line);
  padding: 22px; margin-bottom: 20px;
  box-shadow: 0 3px 0 var(--line), var(--shadow);
}
.card h2 { margin: 0 0 18px; font-size: 1.4rem; font-weight: 600; display: flex; align-items: baseline; gap: 9px; flex-wrap: wrap; }
.card h2 .sub { font-size: 0.82rem; font-weight: 400; color: var(--muted); font-family: var(--sans); }

/* Celebration banner */
.celebrate {
  background: linear-gradient(110deg, #f3f9ec, #fff6e2);
  border: 2px solid #d6e8c5; border-radius: var(--radius); padding: 15px 20px; margin-bottom: 20px;
  box-shadow: 0 3px 0 #e3eed5, var(--shadow); display: flex; align-items: center; gap: 13px;
  font-weight: 600; color: var(--sage-deep); font-family: var(--display); font-size: 1.05rem;
  animation: pop .4s ease;
}
.celebrate .big { font-size: 1.8rem; animation: bounce 1.4s ease-in-out infinite; }
@keyframes bounce { 0%,100%{transform:translateY(0) rotate(0)} 50%{transform:translateY(-5px) rotate(-8deg)} }
@keyframes pop { from{transform:scale(.93);opacity:0} to{transform:scale(1);opacity:1} }

/* Allergen grid — food cards with sticker badges */
.allergen-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(232px, 1fr)); gap: 16px; }
.allergen {
  --tint: var(--sky);
  position: relative; background: color-mix(in srgb, var(--tint) 7%, #fff);
  border: 2px solid color-mix(in srgb, var(--tint) 22%, var(--line));
  border-radius: 20px; padding: 16px; display: flex; flex-direction: column;
  box-shadow: 0 3px 0 var(--line); transition: transform .14s ease, box-shadow .14s ease;
}
.allergen:hover { transform: translateY(-3px) rotate(-0.6deg); box-shadow: 0 3px 0 var(--line), var(--shadow); }
.allergen:nth-child(6n+1){--tint:var(--terra)} .allergen:nth-child(6n+2){--tint:var(--sky)}
.allergen:nth-child(6n+3){--tint:var(--honey)} .allergen:nth-child(6n+4){--tint:var(--plum)}
.allergen:nth-child(6n+5){--tint:var(--berry)} .allergen:nth-child(6n+6){--tint:var(--sage)}
.allergen.met { background: var(--sage-soft); border-color: #cfe3c2; box-shadow: 0 3px 0 #d9e8cd; }

.allergen-head { display: flex; align-items: center; gap: 12px; }
.sticker {
  width: 52px; height: 52px; flex: none; border-radius: 50%; display: grid; place-items: center;
  font-size: 1.6rem; background: #fff; transform: rotate(-5deg);
  box-shadow: inset 0 0 0 3.5px color-mix(in srgb, var(--tint) 60%, #fff),
              0 5px 11px -5px color-mix(in srgb, var(--tint) 65%, transparent);
}
.ahead-text { min-width: 0; flex: 1; }
.aname { font-weight: 600; font-size: 1.06rem; display: block; line-height: 1.15; }
.ahead-meta { display: flex; align-items: center; gap: 7px; margin-top: 3px; flex-wrap: wrap; }
.badge.prio { background: #fdeadf; color: var(--terra-deep); }
.count { font-variant-numeric: tabular-nums; color: var(--muted); font-weight: 600; font-size: 0.92rem; }
.count.ok { color: var(--sage-deep); }
.met-tick {
  position: absolute; top: 12px; right: 12px; width: 26px; height: 26px; border-radius: 50%;
  background: var(--sage); color: #fff; display: grid; place-items: center; font-weight: 800;
  font-size: 0.9rem; box-shadow: 0 3px 7px -3px rgba(95,127,93,0.8); animation: pop .3s ease;
}
.dots { display: flex; gap: 8px; margin: 13px 0 4px; flex-wrap: wrap; }
.dot { width: 18px; height: 18px; border-radius: 50%; background: #fff; border: 3px solid color-mix(in srgb, var(--tint) 35%, #fff); }
.dot.filled {
  border-color: transparent; background: var(--tint);
  box-shadow: 0 3px 6px -2px color-mix(in srgb, var(--tint) 70%, transparent); animation: pop .25s ease;
}
.allergen.met .dot.filled { background: var(--sage); }
.prep { font-size: 0.82rem; color: var(--muted); margin: 9px 0 14px; }
.allergen .row { margin-top: auto; }

/* Buttons — chunky tactile pills */
.btn {
  appearance: none; border: 2px solid var(--line); background: #fff; color: var(--ink);
  border-radius: 14px; padding: 11px 18px; font-size: 0.96rem; font-weight: 600;
  cursor: pointer; min-height: 46px; line-height: 1;
  box-shadow: 0 3px 0 var(--line); transition: transform .1s ease, box-shadow .1s ease, background .1s ease;
}
.btn:hover { transform: translateY(-1px); }
.btn:active { transform: translateY(3px); box-shadow: 0 0 0 var(--line); }
.btn.primary { background: var(--terra); border-color: var(--terra); color: #fff; box-shadow: 0 4px 0 var(--terra-deep); }
.btn.primary:active { box-shadow: 0 0 0 var(--terra-deep); }
.btn.ghost { background: #f6efe4; border-color: var(--line); color: var(--muted); box-shadow: 0 3px 0 var(--line); }
.btn.danger { color: var(--red); border-color: #eecbc5; background: #fdf1ef; box-shadow: 0 3px 0 #eecbc5; }
.btn.danger.on { background: var(--red); border-color: var(--red); color: #fff; box-shadow: 0 4px 0 #b04a3f; }
.btn.on { background: var(--sage); border-color: var(--sage); color: #fff; box-shadow: 0 4px 0 var(--sage-deep); }
.btn.small { min-height: 40px; padding: 9px 14px; font-size: 0.85rem; }
.row { display: flex; align-items: center; }
.row.gap { gap: 8px; }
form { margin: 0; }

/* Progress bar */
.progress { height: 14px; border-radius: 999px; background: #f0e6d6; overflow: hidden; margin: 2px 0 16px; box-shadow: inset 0 1px 3px rgba(120,70,40,0.12); }
.progress > span { display: block; height: 100%; border-radius: 999px; background: linear-gradient(90deg, var(--sage), var(--honey)); transition: width .5s cubic-bezier(.2,1,.3,1); }

/* Plan & food lists */
.planlist, .foodlist { list-style: none; margin: 0; padding: 0; }
.planitem, .foodrow {
  display: flex; align-items: center; gap: 12px; justify-content: space-between;
  padding: 13px 15px; border-radius: 16px; margin-bottom: 9px; flex-wrap: wrap;
  background: #fff; border: 2px solid var(--line); box-shadow: 0 2px 0 var(--line);
}
.planitem.status-tolerated, .foodrow.status-tolerated { background: var(--sage-soft); border-color: #cfe3c2; box-shadow: 0 2px 0 #d9e8cd; }
.planitem.status-reacted, .foodrow.status-reacted { background: #fdf1ef; border-color: #eecbc5; box-shadow: 0 2px 0 #eecbc5; }
.pi-name, .fr-name { font-weight: 600; }
.pi-main, .fr-main { flex: 1 1 220px; min-width: 0; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.pi-main .emoji, .fr-main .emoji { font-size: 1.4rem; }
.pi-main .prep, .fr-main .prep { flex-basis: 100%; margin: 0; }

.pill { font-size: 0.7rem; padding: 3px 10px; border-radius: 999px; font-weight: 700; white-space: nowrap; font-family: var(--display); }
.pill.cat { background: #f3ecf6; color: #8a6aa0; }
.pill.st.introduced { background: #e8f0f6; color: #4884a8; }
.pill.st.tolerated { background: var(--sage-soft); color: var(--sage-deep); }
.pill.st.reacted { background: #fbe2dd; color: var(--red); }
.pill.st.todo { background: #f2ecdf; color: var(--muted); }
.muted { color: var(--muted); font-size: 0.8rem; }

/* Quick picks */
.quickpicks { margin-top: 14px; }
.qp-head { font-size: 1rem; font-family: var(--display); font-weight: 600; color: var(--terra-deep); margin: 4px 0 10px; display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.qp-head span { font-size: 0.76rem; color: var(--muted); font-family: var(--sans); font-weight: 400; }
.chip.pick { border-color: color-mix(in srgb, var(--terra) 38%, var(--line)); background: color-mix(in srgb, var(--honey) 13%, #fff); }
.chip.pick:hover { border-color: var(--terra); }

/* Write-in "I gave this" */
.writein { display: flex; gap: 9px; flex-wrap: wrap; align-items: center; margin-top: 16px; padding-top: 16px; border-top: 2px dashed var(--line); }
.writein input[type=text] {
  flex: 1 1 220px; min-width: 0; padding: 11px 14px; font-size: 1rem; font-family: var(--sans);
  border: 2px solid var(--line); border-radius: 13px; background: #fffdf8;
}
.writein input[type=text]:focus { outline: 3px solid color-mix(in srgb, var(--terra) 45%, #fff); border-color: var(--terra); }

/* Planner */
.planner { margin-top: 14px; border-top: 2px dashed var(--line); padding-top: 8px; }
.planner summary { cursor: pointer; font-weight: 600; font-family: var(--display); color: var(--terra-deep); padding: 10px 0; min-height: 46px; display: flex; align-items: center; list-style: none; font-size: 1.02rem; }
.planner summary::-webkit-details-marker { display: none; }
.planner summary::before { content: "🧺"; margin-right: 9px; font-size: 1.15rem; }
.planner-cat h3 { font-size: 0.78rem; color: var(--muted); margin: 15px 0 9px; text-transform: uppercase; letter-spacing: 0.06em; font-family: var(--sans); font-weight: 700; }
.chiprow { display: flex; flex-wrap: wrap; gap: 9px; }
.chip {
  border: 2px solid var(--line); background: #fff; border-radius: 999px; padding: 9px 15px;
  font-size: 0.9rem; font-weight: 600; cursor: pointer; min-height: 42px; color: var(--ink);
  box-shadow: 0 2px 0 var(--line); transition: transform .1s ease, border-color .1s ease;
}
.chip:hover { transform: translateY(-1px); border-color: var(--terra); }
.chip:active { transform: translateY(2px); box-shadow: 0 0 0 var(--line); }

/* Foods page */
.filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 8px; }
.flabel { color: var(--muted); font-size: 0.85rem; margin-right: 2px; }
.fchip { text-decoration: none; color: var(--muted); background: #f3ecdf; border-radius: 999px; padding: 7px 14px; font-size: 0.85rem; font-weight: 700; font-family: var(--display); }
.fchip.on { background: var(--terra); color: #fff; box-shadow: 0 3px 0 var(--terra-deep); }
.cathead { font-size: 1.08rem; color: var(--ink); margin: 22px 0 10px; font-family: var(--display); font-weight: 600; display: flex; align-items: center; gap: 8px; }
.cathead .emoji { font-size: 1.3rem; }
.select { min-height: 42px; border-radius: 12px; border: 2px solid var(--line); padding: 7px 10px; font-size: 0.9rem; background: #fff; font-family: var(--sans); }

.addform { display: grid; gap: 15px; }
.addform label { font-weight: 600; font-size: 0.92rem; font-family: var(--display); }
.addform input, .addform select {
  display: block; width: 100%; margin-top: 6px; padding: 12px; font-size: 1rem;
  border: 2px solid var(--line); border-radius: 13px; background: #fffdf8; font-weight: 400; font-family: var(--sans);
}
.addform input:focus, .addform select:focus, .select:focus { outline: 3px solid color-mix(in srgb, var(--terra) 45%, #fff); border-color: var(--terra); }
.addform small { display: block; color: var(--muted); font-weight: 400; margin-top: 5px; font-family: var(--sans); }
.addform .btn { justify-self: start; }

/* Guide page */
.bullets { margin: 0; padding-left: 4px; list-style: none; }
.bullets li { margin: 10px 0; padding-left: 28px; position: relative; }
.bullets li::before { content: "•"; position: absolute; left: 6px; top: -2px; color: var(--terra); font-weight: 900; font-size: 1.4rem; }
.src { font-size: 0.78rem; color: var(--muted); margin: 15px 0 0; }
.avoidlist { list-style: none; margin: 0; padding: 0; }
.avoidlist li { padding: 12px 0; border-bottom: 2px solid var(--line); }
.avoidlist li:last-child { border-bottom: none; }
.age { display: inline-block; min-width: 96px; font-size: 0.7rem; font-weight: 700; font-family: var(--display);
  color: var(--red); background: #fbe2dd; border-radius: 999px; padding: 4px 10px; margin-right: 9px; text-align: center; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 22px; }
.ok-h { color: var(--sage-deep); margin: 0 0 6px; font-family: var(--display); }
.bad-h { color: var(--red); margin: 0 0 6px; font-family: var(--display); }

.empty { color: var(--muted); font-style: italic; }
.foot { color: var(--muted); font-size: 0.78rem; padding-top: 8px; padding-bottom: 30px; text-align: center; }

/* Day-by-day diary */
.daycard .days { display: flex; flex-direction: column; gap: 9px; }
.day {
  display: flex; align-items: center; gap: 12px; padding: 11px 13px; border-radius: 15px;
  border: 2px solid var(--line); background: #fff; box-shadow: 0 2px 0 var(--line);
  text-decoration: none; color: inherit; transition: transform .1s ease, border-color .1s ease;
}
.day:hover { transform: translateY(-1px); border-color: color-mix(in srgb, var(--terra) 40%, var(--line)); }
.day.active { border-color: var(--terra); box-shadow: 0 2px 0 var(--terra-deep), 0 0 0 3px color-mix(in srgb, var(--terra) 22%, #fff); }
.day.future { opacity: 0.5; }
.dlabel {
  flex: 0 0 84px; font-family: var(--display); font-weight: 600; font-size: 0.95rem; color: var(--muted);
}
.day.is-today .dlabel { color: var(--terra-deep); }
.day.active .dlabel { color: var(--terra-deep); }
.ditems { display: flex; flex-wrap: wrap; gap: 7px; align-items: center; }
.ditem { position: relative; font-size: 1.3rem; line-height: 1; }
.ditem .dx {
  position: absolute; right: -7px; bottom: -5px; font-size: 0.56rem; font-weight: 800; font-family: var(--display);
  background: var(--sage); color: #fff; border-radius: 999px; min-width: 14px; height: 14px;
  display: flex; align-items: center; justify-content: center; padding: 0 2px; border: 2px solid #fff;
}
.dnone { color: var(--line); font-weight: 700; }

/* Week layout: main + plate sidebar */
.weekgrid { display: flex; gap: 20px; align-items: flex-start; }
.weekmain { flex: 1 1 auto; min-width: 0; }
.plate-side { flex: 0 0 250px; position: sticky; top: 86px; }
.plate-card { padding: 20px; text-align: center; }
.plate-card h2 { justify-content: center; }

/* A real round plate */
.plate {
  aspect-ratio: 1; border-radius: 50%; margin: 4px auto 0; max-width: 220px;
  display: flex; flex-wrap: wrap; align-content: center; justify-content: center; gap: 9px;
  padding: 30px;
  background: radial-gradient(circle at 50% 42%, #ffffff 0%, #fdf6ec 60%, #f6ead8 61%, #fffaf2 72%, #f0e3cf 73%);
  box-shadow: inset 0 0 0 7px #f7eedd, inset 0 0 0 9px #efe1cd, inset 0 4px 14px rgba(120,70,40,0.08), var(--shadow);
}
.plate-item {
  position: relative; font-size: 2rem; line-height: 1; cursor: default;
  animation: plate-pop .42s cubic-bezier(.2,1.5,.4,1) both; transition: transform .12s ease;
}
.plate-item:hover { transform: scale(1.3) rotate(-8deg); }
.plate-item .pc {
  position: absolute; right: -8px; bottom: -6px; font-size: 0.6rem; font-weight: 800; font-family: var(--display);
  background: var(--terra); color: #fff; border-radius: 999px; min-width: 16px; height: 16px;
  display: flex; align-items: center; justify-content: center; padding: 0 3px; border: 2px solid #fffaf2;
}
.plate-empty { margin: 0; font-size: 0.9rem; }
@keyframes plate-pop { from { transform: scale(0) rotate(-30deg); opacity: 0; } to { transform: scale(1) rotate(0); opacity: 1; } }

/* Button press squish */
.btn.pressed { animation: squish .22s ease; }
@keyframes squish { 0%{transform:scale(1)} 40%{transform:scale(.86)} 100%{transform:scale(1)} }

/* Confetti + flying food emoji */
.confetti-bit { position: fixed; z-index: 9999; pointer-events: none; will-change: transform, opacity; animation: confetti-fly 0.95s ease-out forwards; }
@keyframes confetti-fly { 0% { transform: translate(0,0) rotate(0); opacity: 1; } 100% { transform: translate(var(--dx), var(--dy)) rotate(var(--rot)); opacity: 0; } }
.fly-emoji { position: fixed; z-index: 9999; pointer-events: none; font-size: 2.4rem; filter: drop-shadow(0 3px 5px rgba(0,0,0,.18)); animation: fly-up 0.92s cubic-bezier(.2,.8,.3,1) forwards; }
@keyframes fly-up { 0% { transform: translate(-50%,-50%) scale(.5) rotate(-12deg); opacity: 0; } 22% { transform: translate(-50%,-150%) scale(1.5) rotate(6deg); opacity: 1; } 100% { transform: translate(-50%,-300%) scale(1) rotate(0); opacity: 0; } }

@media (max-width: 900px) {
  .weekgrid { flex-direction: column; }
  .plate-side { position: static; flex-basis: auto; width: 100%; order: -1; }
  .plate { max-width: 260px; }
}
@media (max-width: 540px) {
  .pi-actions, .fr-actions { width: 100%; }
  .two-col { grid-template-columns: 1fr; }
}
