/* Crafted miniature: kraft and felt ground, cut-card surfaces, one leaf-green accent.
   Landscape iPad first; stacks to one column on a phone. */
:root {
  --ground: #e9dfcb;      /* kraft */
  --card: #f8f3e8;        /* matte paper */
  --card-edge: #d6c8ab;
  --ink: #2b2620;
  --muted: #74695a;
  --accent: #3f7a4f;      /* leaf */
  --accent-ink: #fbf7ee;
  --accent-soft: #dde8d6;
  --flag: #8a5a12;
  --flag-soft: #f5e6c4;
  --shadow: 0 1px 0 rgba(255,255,255,.6) inset, 0 2px 0 rgba(120,96,60,.12), 0 10px 24px -14px rgba(80,60,30,.45);
  --display: ui-serif, "New York", "Iowan Old Style", Georgia, serif;
  --ui: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", system-ui, sans-serif;
  --ease: cubic-bezier(.22, 1, .36, 1);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --ground: #1e1a24; --card: #2a2531; --card-edge: #3b3445; --ink: #f1eadf; --muted: #b0a597;
    --accent: #8cc79a; --accent-ink: #1a1f1b; --accent-soft: #2c3a30; --flag: #f2c46e; --flag-soft: #3a2f1c;
    --shadow: 0 1px 0 rgba(255,255,255,.04) inset, 0 10px 24px -14px rgba(0,0,0,.7);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --ground: #1e1a24; --card: #2a2531; --card-edge: #3b3445; --ink: #f1eadf; --muted: #b0a597;
  --accent: #8cc79a; --accent-ink: #1a1f1b; --accent-soft: #2c3a30; --flag: #f2c46e; --flag-soft: #3a2f1c;
  --shadow: 0 1px 0 rgba(255,255,255,.04) inset, 0 10px 24px -14px rgba(0,0,0,.7);
  color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--ground); color: var(--ink); font: 17px/1.45 var(--ui);
  -webkit-font-smoothing: antialiased; overscroll-behavior: none; -webkit-user-select: none; user-select: none;
}
[hidden] { display: none !important; }
button { font: inherit; color: inherit; cursor: pointer; }
button:focus-visible, input:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
#app { min-height: 100%; }

.screen {
  padding: calc(env(safe-area-inset-top, 0px) + 22px) max(20px, env(safe-area-inset-right)) calc(env(safe-area-inset-bottom, 0px) + 110px) max(20px, env(safe-area-inset-left));
  max-width: 1280px; margin: 0 auto; animation: land .5s var(--ease);
}
@keyframes land { from { opacity: 0; transform: translateY(10px) scale(.995); } }

.stamp {
  display: inline-block; font: 700 12px/1 var(--ui); text-transform: uppercase; letter-spacing: .14em; color: var(--muted);
}
h1 { font: italic 600 clamp(30px, 4vw, 44px)/1.05 var(--display); margin: 6px 0 0; letter-spacing: -.01em; text-wrap: balance; }
h2 { font: italic 600 24px/1.15 var(--display); margin: 0; text-wrap: balance; }
.top { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 22px; }
.totals { font-weight: 700; color: var(--accent); background: var(--accent-soft); padding: 8px 14px; border-radius: 999px; font-variant-numeric: tabular-nums; }
.dayname { display: flex; align-items: center; gap: 14px; }
.nudge { width: 48px; height: 48px; border-radius: 50%; border: 1.5px solid var(--card-edge); background: var(--card); font-size: 26px; line-height: 1; box-shadow: var(--shadow); }

.card {
  background: var(--card); border: 1px solid var(--card-edge); border-radius: 18px; box-shadow: var(--shadow); padding: 18px 20px;
}
.card p { margin: 8px 0 0; }
.card.flag { background: var(--flag-soft); border-color: transparent; }
.card.flag .stamp { color: var(--flag); }

/* Today: three meal cards */
.meals3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 18px; }
.meal {
  position: relative; display: flex; flex-direction: column; background: var(--card); border: 1px solid var(--card-edge);
  border-radius: 20px; box-shadow: var(--shadow); overflow: hidden; animation: land .6s var(--ease) both;
}
.meal:nth-child(2) { animation-delay: .06s; } .meal:nth-child(3) { animation-delay: .12s; }
.meal .pic { aspect-ratio: 16 / 11; width: 100%; display: block; object-fit: cover; background: #cdb894; }
.meal .body { padding: 14px 18px 18px; display: flex; flex-direction: column; gap: 4px; flex: 1; }
.meal .macro { color: var(--muted); font-variant-numeric: tabular-nums; font-size: 15px; }
.meal .row { display: flex; gap: 10px; margin-top: auto; padding-top: 12px; }
.primary, .ghost {
  border-radius: 14px; padding: 12px 18px; font-weight: 700; border: 1.5px solid var(--accent); min-height: 48px;
  transition: transform .2s var(--ease), background .2s;
}
.primary { background: var(--accent); color: var(--accent-ink); }
.ghost { background: transparent; color: var(--accent); }
.primary:active, .ghost:active { transform: scale(.97); }
.primary.wide { flex: 1; }
.ghost.small { min-height: 40px; padding: 8px 14px; font-size: 15px; }
.done-toggle { width: 52px; flex: none; padding: 0; font-size: 20px; }
.meal.is-done .pic { filter: saturate(.6) brightness(.97); }
.sticker {
  position: absolute; top: 14px; right: 14px; background: var(--accent); color: var(--accent-ink); font: 700 13px/1 var(--ui);
  letter-spacing: .1em; text-transform: uppercase; padding: 9px 12px 8px; border-radius: 8px; transform: rotate(4deg);
  box-shadow: 0 4px 10px -4px rgba(0,0,0,.4); clip-path: polygon(0 0, 100% 0, 100% 72%, 86% 100%, 0 100%);
  animation: press .35s var(--ease);
}
@keyframes press { from { transform: rotate(10deg) scale(1.3); opacity: 0; } }
.banner {
  display: flex; align-items: center; justify-content: space-between; gap: 14px; margin-bottom: 18px;
  background: var(--accent-soft); border-radius: 18px; padding: 14px 18px; font-weight: 600;
  outline: 2px dashed color-mix(in srgb, var(--accent) 45%, transparent); outline-offset: -7px;
}

/* Week */
.weekgrid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 10px; }
.wday { background: var(--card); border: 1px solid var(--card-edge); border-radius: 16px; padding: 12px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.wday.today { outline: 2px dashed var(--accent); outline-offset: -6px; }
.wday h3 { font: italic 600 20px/1 var(--display); margin: 0 0 2px; display: flex; justify-content: space-between; align-items: baseline; }
.wday h3 small { font: 700 10px/1 var(--ui); letter-spacing: .1em; text-transform: uppercase; color: var(--accent); }
.wmeal { text-align: left; border: 0; background: color-mix(in srgb, var(--ground) 55%, var(--card)); border-radius: 10px; padding: 8px 9px; font-size: 14px; line-height: 1.25; min-height: 52px; }
.wmeal b { display: block; font-size: 10px; letter-spacing: .1em; text-transform: uppercase; color: var(--muted); margin-bottom: 3px; }
.wmeal.done { text-decoration: line-through; color: var(--muted); }
.tips { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; margin-top: 20px; }

/* Groceries */
.progress { display: flex; align-items: center; gap: 12px; font-weight: 700; color: var(--muted); font-variant-numeric: tabular-nums; min-width: 260px; }
.bar { flex: 1; height: 10px; border-radius: 99px; background: var(--card-edge); overflow: hidden; }
.bar span { display: block; height: 100%; width: 0; background: var(--accent); transition: width .4s var(--ease); }
.grocols { columns: 2; column-gap: 18px; }
.grogroup { break-inside: avoid; margin-bottom: 18px; }
.grogroup .stamp { margin: 0 0 8px 4px; }
.grolist { background: var(--card); border: 1px solid var(--card-edge); border-radius: 18px; box-shadow: var(--shadow); overflow: hidden; }
.gro { display: flex; align-items: center; gap: 14px; width: 100%; text-align: left; background: none; border: 0; border-top: 1px solid var(--card-edge); padding: 14px 18px; min-height: 64px; }
.gro:first-child { border-top: 0; }
.gro .box { width: 28px; height: 28px; flex: none; border-radius: 8px; border: 2px solid var(--card-edge); display: grid; place-items: center; transition: background .2s, border-color .2s; }
.gro.on .box { background: var(--accent); border-color: var(--accent); }
.gro.on .box::after { content: ""; width: 12px; height: 7px; border: 3px solid var(--accent-ink); border-top: 0; border-right: 0; transform: rotate(-45deg) translate(1px, -1px); }
.gro .t { flex: 1; min-width: 0; }
.gro .t b { font-weight: 700; }
.gro .t small { display: block; color: var(--muted); font-size: 14px; }
.gro .q { font-weight: 700; color: var(--accent); font-variant-numeric: tabular-nums; white-space: nowrap; }
.gro.on .t b, .gro.on .q { color: var(--muted); text-decoration: line-through; }
#groReset { margin-top: 18px; }

/* All meals */
.mealgrid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; }
.mtile { text-align: left; padding: 0; border: 1px solid var(--card-edge); background: var(--card); border-radius: 18px; overflow: hidden; box-shadow: var(--shadow); display: flex; flex-direction: column; }
.mtile img { width: 100%; aspect-ratio: 16 / 11; object-fit: cover; display: block; background: #cdb894; }
.mtile div { padding: 10px 14px 14px; }
.mtile h2 { font-size: 19px; }
.mtile span { color: var(--muted); font-size: 14px; font-variant-numeric: tabular-nums; }

/* Settings */
.syncbox { max-width: 640px; display: flex; flex-direction: column; gap: 10px; }
.syncbox p { margin: 0; }
.keyrow { display: flex; gap: 10px; }
.keyrow input { flex: 1; min-width: 0; font: 17px var(--ui); padding: 12px 14px; border-radius: 12px; border: 1.5px solid var(--card-edge); background: var(--ground); color: var(--ink); -webkit-user-select: text; user-select: text; }
.hint { color: var(--muted); font-size: 15px; }
.install { max-width: 640px; margin-top: 16px; }

/* Bottom tabs */
.tabs {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(env(safe-area-inset-bottom, 0px) + 14px);
  display: flex; gap: 6px; padding: 6px; background: var(--card); border: 1px solid var(--card-edge); border-radius: 20px; box-shadow: 0 14px 30px -14px rgba(60,40,20,.5); z-index: 10;
  max-width: calc(100% - 24px);
}
.tabs button { border: 0; background: none; padding: 12px 18px; border-radius: 14px; font-weight: 700; color: var(--muted); white-space: nowrap; min-height: 50px; }
.tabs button[aria-current="page"] { background: var(--accent); color: var(--accent-ink); }
.tabs .count { font-variant-numeric: tabular-nums; opacity: .8; font-weight: 600; }
.tabs .sync { padding: 12px 16px; }
.dot { display: inline-block; width: 12px; height: 12px; border-radius: 50%; background: var(--card-edge); vertical-align: middle; }
.dot.ok { background: var(--accent); } .dot.err { background: #c4422f; } .dot.busy { background: var(--flag); }

/* Cook mode */
.cook {
  position: fixed; inset: 0; z-index: 20; background: var(--ground); display: flex; flex-direction: column;
  padding: calc(env(safe-area-inset-top, 0px) + 12px) max(16px, env(safe-area-inset-right)) calc(env(safe-area-inset-bottom, 0px) + 14px) max(16px, env(safe-area-inset-left));
  animation: rise .45s var(--ease);
}
@keyframes rise { from { opacity: 0; transform: translateY(24px); } }
.cookbar { display: flex; align-items: center; gap: 14px; justify-content: space-between; padding-bottom: 12px; }
.back { border: 0; background: none; font: italic 600 24px/1.1 var(--display); padding: 8px 4px; min-height: 48px; text-align: left; }
.timerpill { margin-left: auto; background: var(--flag-soft); color: var(--flag); padding: 8px 14px; border-radius: 999px; font-weight: 700; font-variant-numeric: tabular-nums; }
.cookbody { flex: 1; min-height: 0; display: grid; grid-template-columns: minmax(0, 1.35fr) minmax(0, 1fr); gap: 20px; }
.stage { position: relative; border-radius: 22px; overflow: hidden; box-shadow: var(--shadow); border: 1px solid var(--card-edge); min-height: 0; }
.stage canvas { width: 100%; height: 100%; display: block; }
/* tilt-shift: a sharp band through the middle, soft above and below */
.tilt { position: absolute; left: 0; right: 0; height: 26%; pointer-events: none; -webkit-backdrop-filter: blur(5px); backdrop-filter: blur(5px); }
.tilt.top { top: 0; -webkit-mask-image: linear-gradient(#000, transparent); mask-image: linear-gradient(#000, transparent); }
.tilt.bottom { bottom: 0; -webkit-mask-image: linear-gradient(transparent, #000); mask-image: linear-gradient(transparent, #000); }
.steptext { display: flex; flex-direction: column; gap: 20px; min-height: 0; overflow-y: auto; padding: 10px 6px; }
#stepPane { animation: land .45s var(--ease); }
#stepPane .say { font: 500 clamp(24px, 2.6vw, 32px)/1.3 var(--ui); margin: 10px 0 0; letter-spacing: -.005em; text-wrap: pretty; }
#stepPane ul { margin: 12px 0 0; padding-left: 22px; font-size: 19px; }
#stepPane li { margin: 4px 0; }
#stepPane .gf { margin-top: 14px; }
.timer { display: flex; align-items: center; gap: 12px; }
.timerbtn {
  display: flex; align-items: center; gap: 14px; border: 0; border-radius: 20px; background: var(--card); box-shadow: var(--shadow);
  padding: 14px 22px; font: 700 40px/1 var(--ui); font-variant-numeric: tabular-nums; min-height: 76px; border: 1.5px solid var(--card-edge);
}
.timerbtn #timerIcon { font-size: 24px; color: var(--accent); }
.timerbtn.ring { animation: ring .8s ease-in-out infinite; background: var(--flag-soft); color: var(--flag); }
@keyframes ring { 50% { transform: scale(1.04); } }
.cookfoot { display: flex; align-items: center; gap: 16px; padding-top: 14px; }
.big { min-height: 64px; min-width: 160px; font-size: 20px; border-radius: 18px; }
.dots { flex: 1; display: flex; justify-content: center; gap: 10px; }
.dots i { width: 12px; height: 12px; border-radius: 50%; background: var(--card-edge); transition: background .3s, transform .3s var(--ease); }
.dots i.on { background: var(--accent); transform: scale(1.25); }
.dots i.past { background: color-mix(in srgb, var(--accent) 50%, var(--card-edge)); }

.toast { position: fixed; left: 50%; bottom: calc(env(safe-area-inset-bottom, 0px) + 92px); transform: translateX(-50%); background: var(--ink); color: var(--ground); padding: 12px 18px; border-radius: 14px; font-weight: 600; z-index: 40; animation: land .3s var(--ease); max-width: calc(100% - 32px); }

/* Portrait iPad and phones */
@media (max-width: 1000px) {
  .weekgrid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .mealgrid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (max-width: 900px), (orientation: portrait) {
  .cookbody { grid-template-columns: 1fr; grid-template-rows: minmax(240px, 58%) minmax(0, 1fr); gap: 14px; }
}
@media (max-width: 760px) {
  .meals3, .tips { grid-template-columns: 1fr; }
  .grocols { columns: 1; }
  .weekgrid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .mealgrid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .tabs { left: 10px; right: 10px; transform: none; max-width: none; justify-content: space-between; gap: 2px; }
  .tabs button { padding: 10px 9px; font-size: 15px; }
  .big { min-width: 0; flex: 1; }
  .dots { display: none; }
}
@media (max-width: 430px) {
  .tabs .count { display: none; }
  .tabs button { padding: 10px 7px; font-size: 14px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
