/* UX rebuild, phase UX-1: design tokens, base components and shell.
   Staging-only at /next until cutover (see docs/PLAN.md). No external fonts or assets. */

:root {
  --bg: #F5F5EF;
  --card: #FFFFFF;
  --ink: #17241C;
  --ink-2: #3F4A43;
  --mute: #5B675F;
  --line: #E3E5DC;
  --line-2: #D9DCD1;
  --seg: #E9EBE3;
  --yellow: #FFD23F;
  --yellow-edge: #EDBE1C;
  --yellow-soft: #FFF8DC;
  --green: #1E6B45;
  --green-soft: #DDEFE3;
  --orange: #C2410C;
  --orange-soft: #FCE3D6;
  --blue: #2D5A85;
  --blue-soft: #E2EEF7;
  --danger: #B4361E;
  --focus: #2D5A85;
  --r-card: 20px;
  --r-ctl: 14px;
  --touch: 44px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-display: var(--font);
  --nav-h: 78px;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: #DCDFD3; }
body { font-family: var(--font); color: var(--ink); -webkit-font-smoothing: antialiased; }
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---- app frame: a phone-sized column on desktop, full screen on phones ---- */
.app {
  position: relative; display: flex; flex-direction: column; overflow: hidden;
  width: 390px; height: 844px; margin: 24px auto; background: var(--bg);
  border: 1px solid #cfd3c6; border-radius: 36px; box-shadow: 0 20px 60px rgba(23, 36, 28, .25);
  font-size: 15px; line-height: 1.4;
}
@media (max-width: 500px) {
  html, body { background: var(--bg); }
  .app { width: 100vw; height: 100dvh; margin: 0; border: 0; border-radius: 0; box-shadow: none; }
}
@media (max-height: 880px) and (min-width: 501px) { .app { height: min(844px, 96dvh); } }

/* ---- type ---- */
.h1 { font-size: 28px; line-height: 1.1; font-weight: 750; letter-spacing: -.02em; margin: 0; font-family: var(--font-display); }
.h2 { font-size: 18px; line-height: 1.2; font-weight: 700; letter-spacing: -.01em; margin: 0; font-family: var(--font-display); }
.h3 { font-size: 16px; line-height: 1.25; font-weight: 700; margin: 0; font-family: var(--font-display); }
.sm { font-size: 13px; }
.xs { font-size: 12px; }
.mute { color: var(--mute); }
.b { font-weight: 600; }
.eyebrow { font-size: 12px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: #5C4500; }

/* ---- layout helpers ---- */
.row { display: flex; align-items: center; gap: 10px; }
.row.sp { justify-content: space-between; }
.row.wrap { flex-wrap: wrap; }
.col { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.grow { flex: 1 1 auto; min-width: 0; }
.scr { flex: 1 1 auto; min-height: 0; overflow-y: auto; padding: calc(16px + env(safe-area-inset-top, 0px)) 18px 28px; display: flex; flex-direction: column; gap: 14px; -webkit-overflow-scrolling: touch; }

/* ---- buttons ---- */
.btn {
  appearance: none; display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 46px; padding: 0 16px; border-radius: var(--r-ctl); border: 1px solid var(--line-2);
  background: var(--card); color: var(--ink); font-weight: 600; font-size: 15px; text-decoration: none; white-space: nowrap;
}
.btn.pri { background: var(--yellow); border-color: var(--yellow-edge); }
.btn.dark { background: var(--ink); border-color: var(--ink); color: #fff; }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.danger { color: var(--danger); }
.btn.s { min-height: var(--touch); padding: 0 13px; font-size: 14px; border-radius: 12px; }
.btn.big { min-height: 58px; font-size: 17px; border-radius: 18px; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .5; cursor: default; }
.ib {
  appearance: none; width: var(--touch); height: var(--touch); flex: 0 0 auto; display: inline-flex; align-items: center; justify-content: center;
  border-radius: 14px; border: 1px solid var(--line-2); background: var(--card); color: var(--ink); padding: 0;
}
.ib.plain { border-color: transparent; background: transparent; }
.ib.pri { background: var(--yellow); border-color: var(--yellow-edge); }

/* ---- surfaces ---- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--r-card); padding: 14px 16px; display: flex; flex-direction: column; gap: 10px; }
.card.together { background: var(--yellow-soft); border-color: #F3DE8E; }
.card.note { background: #EEF3FB; border-color: #D3DEF2; }
.card.warn { background: #FDF0E8; border-color: #F5D5C2; }
.pill { display: inline-flex; align-items: center; gap: 4px; border-radius: 999px; padding: 3px 9px; font-size: 12px; font-weight: 600; background: var(--seg); color: var(--ink-2); white-space: nowrap; }
.pill.y { background: #FFF1BF; color: #5C4500; }
.pill.g { background: var(--green-soft); color: var(--green); }
.pill.o { background: var(--orange-soft); color: #9A3412; }
.bar { height: 6px; border-radius: 6px; background: var(--seg); overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--green); border-radius: 6px; }
.bar.y > i { background: #E0A800; }
.list { display: flex; flex-direction: column; }
.list > * + * { border-top: 1px solid #EEF0E8; }
.li {
  display: flex; align-items: center; gap: 12px; width: 100%; min-height: 50px; padding: 11px 0;
  background: transparent; border: 0; text-align: left; font-size: 15px;
}
.empty { align-items: flex-start; }
.empty h2, .empty h3 { margin: 0; }

/* ---- controls ---- */
.inp {
  width: 100%; min-height: 46px; padding: 0 14px; border-radius: var(--r-ctl); border: 1px solid var(--line-2);
  background: var(--card); font-size: 16px; /* 16px stops iOS zooming on focus */
}
.lbl { display: block; font-size: 13px; font-weight: 600; color: var(--ink-2); margin-bottom: 6px; }
.seg { display: flex; gap: 4px; padding: 4px; border-radius: 14px; background: var(--seg); }
.seg > button { flex: 1 1 0; min-height: var(--touch); border: 0; border-radius: 10px; background: transparent; font-weight: 600; font-size: 14px; color: var(--ink-2); }
.seg > button[aria-pressed="true"] { background: var(--card); color: var(--ink); box-shadow: 0 1px 2px rgba(23, 36, 28, .12); }
.chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 2px; }
.chip {
  flex: 0 0 auto; min-height: var(--touch); padding: 0 14px; border-radius: 999px; border: 1px solid var(--line-2);
  background: var(--card); font-weight: 600; font-size: 14px; white-space: nowrap;
}
.chip[aria-pressed="true"] { background: var(--ink); border-color: var(--ink); color: #fff; }
.tog {
  position: relative; width: 52px; height: 32px; flex: 0 0 auto; padding: 0; border: 0; border-radius: 32px; background: #C9CDC1;
}
.tog::after { content: ""; position: absolute; inset: -8px -4px; } /* bigger hit area */
.tog > i { position: absolute; top: 4px; left: 4px; width: 24px; height: 24px; border-radius: 50%; background: #fff; transition: left .15s; }
.tog[aria-checked="true"] { background: var(--green); }
.tog[aria-checked="true"] > i { left: 24px; }

/* ---- bottom navigation ---- */
.nav {
  flex: 0 0 auto; min-height: var(--nav-h); display: flex; align-items: center; justify-content: space-around;
  padding: 0 6px calc(10px + env(safe-area-inset-bottom, 0px)); background: var(--card); border-top: 1px solid var(--line);
}
.nb {
  position: relative; min-width: 62px; min-height: 52px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  border: 0; background: transparent; color: #6B766F; font-size: 11px; font-weight: 600;
}
.nb[aria-current="page"] { color: var(--ink); }
.nb .dot { position: absolute; top: 6px; right: 16px; width: 8px; height: 8px; border-radius: 50%; background: var(--orange); }
.fab {
  width: 58px; height: 58px; margin-top: -22px; display: flex; align-items: center; justify-content: center;
  border: 0; border-radius: 20px; background: var(--yellow); color: var(--ink); box-shadow: 0 6px 14px rgba(224, 168, 0, .35);
}

/* ---- sheets, toast ---- */
.sheetbg { position: absolute; inset: 0; z-index: 20; display: flex; align-items: flex-end; background: rgba(23, 36, 28, .4); }
.sheet {
  width: 100%; max-height: 88%; overflow-y: auto; display: flex; flex-direction: column; gap: 14px;
  padding: 10px 18px calc(26px + env(safe-area-inset-bottom, 0px)); background: var(--bg); border-radius: 26px 26px 0 0;
}
.grab { align-self: center; width: 40px; height: 5px; border-radius: 5px; background: #CDD1C5; }
.toast {
  position: absolute; left: 18px; right: 18px; bottom: calc(94px + env(safe-area-inset-bottom, 0px)); z-index: 30;
  display: flex; align-items: center; gap: 8px; padding: 12px 14px; border-radius: var(--r-ctl);
  background: var(--ink); color: #fff; font-size: 14px; pointer-events: none;
}
.qa { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.qb {
  min-height: 92px; padding: 14px; display: flex; flex-direction: column; align-items: flex-start; justify-content: space-between;
  border-radius: 18px; border: 1px solid var(--line); background: var(--card); font-weight: 600; font-size: 15px; text-align: left;
}
.qb[disabled] { color: var(--mute); }

/* ---- state screens ---- */
.center { flex: 1 1 auto; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; padding: 24px; text-align: center; }

/* ---- motion ---- */
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { transition: none !important; animation: none !important; } }

/* ---- UX-2: Today, Focus, Food ---- */
.top { flex: 0 0 auto; display: flex; align-items: center; gap: 8px; padding: calc(12px + env(safe-area-inset-top, 0px)) 12px 4px; }
.top + .scr { padding-top: 8px; }
.pill.big { font-size: 14px; padding: 7px 12px; }
.tiles { display: grid; gap: 10px; }
.tile {
  min-height: 124px; padding: 12px; display: flex; flex-direction: column; gap: 6px; text-align: left; font-size: 13px;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--r-card);
}
.tile .v { font-weight: 750; font-size: 21px; letter-spacing: -.02em; line-height: 1.1; font-family: var(--font-display); }
.tile .v.sm-v { font-size: 17px; }
.tic { width: 32px; height: 32px; flex: 0 0 auto; display: inline-flex; align-items: center; justify-content: center; border-radius: 11px; background: var(--seg); color: var(--ink-2); }
.tic.y { background: #FFF1BF; color: #7A5B00; } .tic.g { background: var(--green-soft); color: var(--green); }
.tic.o { background: var(--orange-soft); color: #9A3412; } .tic.w { background: var(--blue-soft); color: var(--blue); }
.tic.big { width: 36px; height: 36px; border-radius: 12px; }
.bar.over > i { background: var(--orange); }
.ring {
  width: 236px; height: 236px; align-self: center; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  border-radius: 50%; background: var(--card); border: 10px solid var(--seg);
}
.ring.live { border-color: var(--yellow); }
.ring.pause { border-color: #C9CDC1; border-style: dashed; }
.ring .t { font-size: 52px; line-height: 1; font-weight: 750; letter-spacing: -.03em; font-variant-numeric: tabular-nums; font-family: var(--font-display); }
.macros { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; margin-top: 4px; }
.composer { flex: 0 0 auto; display: flex; align-items: center; gap: 8px; padding: 10px 14px; background: var(--bg); border-top: 1px solid var(--line); }
.composer label.ib { cursor: pointer; }
.center-card { align-items: center; text-align: center; padding: 28px; }
.skel { height: 60px; border-radius: 12px; background: linear-gradient(90deg, var(--seg), #F2F3EC, var(--seg)); }
.spin { width: 28px; height: 28px; border-radius: 50%; border: 3px solid var(--seg); border-top-color: var(--ink); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.qb .ic { width: 36px; height: 36px; display: inline-flex; align-items: center; justify-content: center; border-radius: 12px; background: var(--seg); }

/* children of a scrolling screen keep their own size instead of being squashed */
.scr > * { flex: 0 0 auto; }
.ring { aspect-ratio: 1 / 1; flex: 0 0 auto; }
.chips > * { flex: 0 0 auto; }

.today-card { border-color: var(--yellow); }
select.inp { appearance: auto; }

.gcell { border: 1px solid var(--line); border-radius: 10px; background: var(--card); color: var(--ink); }
.gcol { border: 0; background: var(--seg); border-radius: 10px; color: var(--ink-2); }
