/* ============================================================================
   Warden — "The Fridge Door" theme
   Drop-in replacement for server/web/style.css

   Design intent: the app should read like the chore chart on the family fridge,
   not like a dashboard. Brushed-steel page, cream paper cards pinned at slight
   angles, hard offset shadows (no blur), magnet dots for status, handwriting for
   names and one-liners only — never for data.

   HARD RULES for anyone editing this file:
   1. --font-hand (Caveat) is for names, greetings and one-line asides ONLY.
      Never numbers, labels, form fields, or anything a parent must read fast.
   2. Shadows are hard offsets (Xpx Ypx 0). No blur anywhere. Blur = SaaS.
   3. Card tilt maxes out at 1deg. More than that and it stops being charming.
   4. Every status is a dot + a word. Never colour alone.
   5. All text meets WCAG AA in both themes. The -ink tokens exist for exactly
      this reason: -x for fills, -x-ink for text on the matching -x-soft tint.
   ========================================================================== */

/* ---- Tokens: light ("fridge front") -------------------------------------- */
html {
  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
  --sal: env(safe-area-inset-left, 0px);
  --sar: env(safe-area-inset-right, 0px);
}
html.native { --sat: 0px; --sab: 0px; --sal: 0px; --sar: 0px; }

:root,
:root[data-theme="light"] {
  --bg: #D9DEE2;
  --bg-sheen: linear-gradient(100deg, #D5DADE 0%, #E2E6E9 38%, #CFD5D9 100%);
  --panel: #FFFDF6;          /* paper */
  --panel-2: #F4EFE0;        /* tinted paper: inputs, chips, hover */
  --line: #DDD8C8;           /* paper rule */
  --line-strong: #2B3138;    /* ink outline */
  --text: #2B3138;
  --muted: #4F565D;          /* on cream 5.9:1, and still AA on the steel page */
  --dim: #5F666D;

  --accent: #3D7C4A;         /* fridge green — 4.62:1 with #FFF */
  --accent-2: #4E9E5F;       /* fills, hover, magnet highlights */
  --accent-ink: #FFFFFF;
  --accent-soft: #E6F0E4;
  --accent-text: #2A5C36;

  --tape: rgba(246, 231, 180, .85);
  --tape-solid: #F6E7B4;

  --ok: #3D7C4A;      --ok-ink: #2A5C36;    --ok-soft: #E6F0E4;
  --warn: #E8A33D;    --warn-ink: #7E5410;  --warn-soft: #FBF0DA;
  --bad: #C4483C;     --bad-ink: #9A3428;   --bad-soft: #FAE6E3;
  --paused: #6D5BA8;  --paused-ink: #54438C; --paused-soft: #ECE8F7;

  --radius: 6px;        /* paper barely rounds */
  --radius-sm: 8px;     /* buttons, inputs */
  --radius-pill: 999px;
  --shadow: 4px 4px 0 rgba(43, 49, 56, .18);
  --shadow-lift: 8px 8px 0 rgba(43, 49, 56, .22);
  --shadow-press: 1px 1px 0 rgba(43, 49, 56, .22);

  --font: "Figtree", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-hand: "Caveat", ui-rounded, cursive;
  --font-mono: ui-monospace, "Cascadia Code", Consolas, monospace;

  color-scheme: light;
}

/* ---- Tokens: dark ("fridge at night" — chalkboard, not cream) ------------ */
:root[data-theme="dark"] {
  --bg: #101316;
  --bg-sheen: linear-gradient(100deg, #0E1114 0%, #14181C 38%, #0D1013 100%);
  --panel: #1E232A;
  --panel-2: #262C34;
  --line: #333A43;
  --line-strong: #0A0C0E;
  --text: #F2EFE6;
  --muted: #AFB6BD;
  --dim: #98A0A8;

  --accent: #6FBF82;
  --accent-2: #8FD4A0;
  --accent-ink: #0E1A12;
  --accent-soft: #182620;
  --accent-text: #9BD9AA;

  --tape: rgba(246, 231, 180, .30);
  --tape-solid: #6A6149;

  --ok: #6FBF82;      --ok-ink: #9BD9AA;    --ok-soft: #182620;
  --warn: #E9B457;    --warn-ink: #F2C87D;  --warn-soft: #2A2317;
  --bad: #E1796B;     --bad-ink: #EE9E92;   --bad-soft: #2B1B18;
  --paused: #A98FE8;  --paused-ink: #BFA9F2; --paused-soft: #211C30;

  --shadow: 4px 4px 0 rgba(0, 0, 0, .5);
  --shadow-lift: 8px 8px 0 rgba(0, 0, 0, .55);
  --shadow-press: 1px 1px 0 rgba(0, 0, 0, .55);

  color-scheme: dark;
}

/* Follow the OS when the parent hasn't chosen. Keep this list in sync with the
   [data-theme="dark"] block above. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    --bg: #101316;
    --bg-sheen: linear-gradient(100deg, #0E1114 0%, #14181C 38%, #0D1013 100%);
    --panel: #1E232A;
    --panel-2: #262C34;
    --line: #333A43;
    --line-strong: #0A0C0E;
    --text: #F2EFE6;
    --muted: #AFB6BD;
    --dim: #98A0A8;
    --accent: #6FBF82;
    --accent-2: #8FD4A0;
    --accent-ink: #0E1A12;
    --accent-soft: #182620;
    --accent-text: #9BD9AA;
    --tape: rgba(246, 231, 180, .30);
    --tape-solid: #6A6149;
    --ok: #6FBF82;      --ok-ink: #9BD9AA;    --ok-soft: #182620;
    --warn: #E9B457;    --warn-ink: #F2C87D;  --warn-soft: #2A2317;
    --bad: #E1796B;     --bad-ink: #EE9E92;   --bad-soft: #2B1B18;
    --paused: #A98FE8;  --paused-ink: #BFA9F2; --paused-soft: #211C30;
    --shadow: 4px 4px 0 rgba(0, 0, 0, .5);
    --shadow-lift: 8px 8px 0 rgba(0, 0, 0, .55);
    --shadow-press: 1px 1px 0 rgba(0, 0, 0, .55);
    color-scheme: dark;
  }
}

/* ---- Fonts --------------------------------------------------------------- */
/* Self-host these two in server/web/fonts/ rather than hitting Google — the
   server is LAN-only and may have no outbound DNS. woff2, latin subset,
   ~30KB total. font-display:swap so first paint never blocks. */
@font-face {
  font-family: "Figtree";
  src: url("/fonts/figtree-variable.woff2") format("woff2-variations");
  font-weight: 400 800;
  font-display: swap;
}
@font-face {
  font-family: "Caveat";
  src: url("/fonts/caveat-variable.woff2") format("woff2-variations");
  font-weight: 600 700;
  font-display: swap;
}

/* ---- Base --------------------------------------------------------------- */
* { box-sizing: border-box; }

/* The page must never scroll sideways. overflow-x:clip (not hidden) avoids
   creating a scroll container, so the sticky top bar keeps working. */
html, body { -webkit-text-size-adjust: 100%; overflow-x: clip; max-width: 100%; }

body {
  margin: 0;
  background: var(--bg);
  background-image: var(--bg-sheen);
  background-attachment: fixed;
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;             /* was 14 — 15 reads better for a non-techy parent */
  line-height: 1.5;
  font-synthesis-weight: none;
}

a { color: var(--accent-text); text-decoration: none; font-weight: 700; }
a:hover { color: var(--accent); text-decoration: underline; }

button { font-family: inherit; }

.loading {
  display: grid;
  place-items: center;
  min-height: 100vh;
  color: var(--muted);
  font-family: var(--font-hand);
  font-size: 28px;
}

/* Handwriting helper. Caveat has a small x-height, so it always needs a size
   bump and a little extra line-height to sit right next to Figtree. */
.hand {
  font-family: var(--font-hand);
  font-weight: 700;
  line-height: 1.15;
  letter-spacing: .01em;
}

/* A strip of masking tape. Attach to any card that should look stuck on. */
.taped { position: relative; }
.taped::before {
  content: "";
  position: absolute;
  top: -11px;
  left: 50%;
  width: 74px;
  height: 23px;
  background: var(--tape);
  transform: translateX(-50%) rotate(-2.5deg);
  box-shadow: 0 1px 2px rgba(43, 49, 56, .18);
  pointer-events: none;
}
.taped.tape-left::before { left: 42px; transform: rotate(-3deg); }

/* ---- Layout ------------------------------------------------------------- */
.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  margin: max(14px, var(--sat)) max(14px, var(--sar)) 0 max(14px, var(--sal));
  padding: 13px 20px;
  background: var(--panel);
  border: none;
  border-radius: 10px;
  box-shadow: var(--shadow);
  position: sticky;
  top: max(14px, var(--sat));
  z-index: 10;
}

.brand {
  font-family: var(--font-hand);
  font-weight: 700;
  font-size: 30px;
  line-height: 1;
  color: var(--text);
  letter-spacing: 0;
  display: inline-flex;
  align-items: center;
  gap: 9px;
}
.brand .dot { display: none; }            /* the old "Warden." period */
.brand img, .brand svg { width: 26px; height: 30px; flex: none; }

.topbar .spacer { flex: 1; }

.topbar nav { display: flex; gap: 18px; }
.topbar nav a {
  padding: 4px 0 3px;
  border-radius: 0;
  border-bottom: 3px solid transparent;
  color: var(--muted);
  font-weight: 600;
  font-size: 14.5px;
  text-decoration: none;
  cursor: pointer;
  min-height: 32px;
  display: inline-flex;
  align-items: center;
}
.topbar nav a:hover { color: var(--text); border-bottom-color: var(--line); text-decoration: none; }
.topbar nav a.active { color: var(--text); font-weight: 800; border-bottom-color: var(--warn); }

.wrap {
  max-width: 1180px;
  margin: 0 auto;
  padding: 22px max(16px, var(--sar)) calc(72px + var(--sab)) max(16px, var(--sal));
}

.row { display: flex; gap: 12px; align-items: center; }
.spread { display: flex; justify-content: space-between; align-items: center; gap: 14px; flex-wrap: wrap; }

h1 {
  font-family: var(--font-hand);
  font-weight: 700;
  font-size: 38px;
  line-height: 1.1;
  margin: 0 0 2px;
  color: var(--text);
}

/* h2 was 15px uppercase letterspaced muted — the single biggest source of the
   old "business dashboard" feel. Now a plain, human section header. */
h2 {
  font-family: var(--font-hand);
  font-weight: 700;
  font-size: 27px;
  line-height: 1.15;
  margin: 26px 0 10px;
  color: var(--text);
  text-transform: none;
  letter-spacing: 0;
}

.sub { color: var(--muted); margin: 0 0 18px; font-size: 14.5px; }

/* ---- Buttons ------------------------------------------------------------ */
.btn {
  background: var(--panel);
  color: var(--text);
  border: 2px solid var(--line-strong);
  padding: 11px 16px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-weight: 800;
  font-size: 13.5px;
  min-height: 44px;                 /* brief §6: never below 44 */
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  transition: transform .08s ease, box-shadow .08s ease;
}
.btn:hover { background: var(--panel-2); }
.btn:active { transform: translate(2px, 2px); box-shadow: var(--shadow-press); }
.btn:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
  box-shadow: 3px 3px 0 var(--line-strong);
}
.btn.primary:hover { background: var(--accent-2); border-color: var(--accent-2); color: var(--line-strong); }
.btn.primary:active { transform: translate(3px, 3px); box-shadow: none; }

.btn.danger { border-color: transparent; background: transparent; color: var(--bad-ink); }
.btn.danger:hover { background: var(--bad-soft); border-color: var(--bad); }

.btn.sm { padding: 8px 12px; font-size: 12.5px; min-height: 38px; border-width: 2px; }

.btn:disabled,
.btn[disabled] {
  opacity: 1;                       /* brief §6: don't communicate by dimming */
  background: var(--panel-2);
  border-color: var(--line);
  color: var(--dim);
  box-shadow: none;
  cursor: default;
  transform: none;
}

/* ---- Cards / grid ------------------------------------------------------- */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 24px;
}
/* Screen rules: sections side by side; the long ones take the whole row. */
.rule-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(440px, 100%), 1fr)); gap: 14px; align-items: start; }
.rule-grid > .rule-card { margin: 0 !important; }
.rule-grid > .rule-card.wide { grid-column: 1 / -1; }
.rule-card [data-bed], .rule-card .win-start, .rule-card .win-end, .rule-card [data-tz] { max-width: 220px; }
.cp-prof { gap: 12px 16px; align-items: flex-end; flex-wrap: wrap; }
.cp-prof .cp-name { flex: 1 1 260px; max-width: 420px; }

/* One card per kid: the cards share the row instead of leaving empty slots. */
.grid.fit { grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); }

/* Routine settings: grouped panels side by side; short inputs stay short. */
.rt-groups { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(380px, 100%), 1fr)); gap: 16px; }
.rt-grp { background: var(--panel-2, #F6F1E4); border-radius: 18px; padding: 14px 16px; display: flex; flex-direction: column; gap: 6px; }
.rt-grp h3 { margin: 0 0 4px; font-size: 17px; display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.rt-grp > label:not(.rt-chk) { margin-top: 4px; }
.rt-chk { gap: 8px; align-items: center; font-weight: 600; }
.rt-chk input[type=radio] { width: auto; }
.rt-fields { display: flex; flex-wrap: wrap; gap: 10px 14px; }
.rt-fields > div { display: flex; flex-direction: column; }
.rt-fields input { width: 150px; }
.rt-fields input[type=number] { width: 110px; }
.rt-potline { background: #FFF4D6; border-radius: 12px; padding: 8px 12px; font-weight: 600; font-size: 14px; }
.rt-potline:empty { display: none; }
/* Routine settings: a picture of the morning + what a kid can earn (rtPotLine). */
.rt-tl { display: grid; grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); gap: 16px; margin-bottom: 16px; }
.rt-tl:empty { display: none; }
@media (max-width: 760px) { .rt-tl { grid-template-columns: minmax(0, 1fr); } }
.rt-tl h3 { margin: 0 0 10px; font-size: 17px; }
.rt-tl-main, .rt-tl-earn { background: var(--panel-2); border-radius: 18px; padding: 14px 16px; min-width: 0; }
.rt-bar { display: flex; height: 22px; border-radius: 11px; overflow: hidden; border: 2px solid var(--line-strong); }
.rt-seg { display: block; min-width: 8px; }
.rt-seg + .rt-seg { border-left: 2px solid var(--panel); }
.rt-seg.lock, .rt-key.lock { background: var(--paused-soft); }
.rt-seg.full, .rt-key.full { background: var(--ok); }
.rt-seg.drop, .rt-key.drop { background: repeating-linear-gradient(90deg, var(--warn) 0 14px, var(--warn-soft) 14px 16px); }
.rt-seg.late, .rt-key.late { background: var(--bad); }
.rt-steps { list-style: none; margin: 12px 0 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fit, minmax(min(200px, 100%), 1fr)); gap: 10px 16px; }
.rt-steps li { display: flex; gap: 10px; align-items: flex-start; font-size: 15px; }
.rt-key { flex: none; width: 14px; height: 14px; border-radius: 4px; margin-top: 3px; border: 1.5px solid var(--line-strong); }
.rt-tl-earn ul { margin: 0 0 8px; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 6px; font-size: 15px; }
.rt-best { background: var(--warn-soft); color: var(--text); border-radius: 12px; padding: 8px 12px; font-size: 14px; margin-bottom: 6px; }
/* Today cards: where the stars came from + the run toward the weekly bonus. */
.rt-earn { margin-top: 6px; display: flex; flex-direction: column; gap: 4px; font-size: 14px; color: var(--text); }
.rt-wk { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; color: var(--muted); }
.rt-pips { display: inline-flex; gap: 4px; }
.rt-pips i { width: 12px; height: 12px; border-radius: 50%; border: 1.5px solid var(--line-strong); background: transparent; }
.rt-pips i.on { background: var(--warn); }
.rt-pips i.today { border-style: dashed; }
@media (min-width: 1300px) { .rt-pot { grid-row: span 2; } }

/* Devices page: a header per owner (kid) / group, with their screens grouped below. */
.devgroup-head { display: flex; align-items: center; gap: 10px; margin: 26px 0 12px; }
.devgroup-head:first-child { margin-top: 8px; }
.devgroup-head h2 { margin: 0; font-size: 19px; }
.devgroup-ava {
  width: 32px; height: 32px; border-radius: 50%;
  display: grid; place-items: center; font-weight: 800; font-size: 16px; flex: none;
}

/* ---- Meals --------------------------------------------------------------- */
.meal-tonight { border-left: 6px solid var(--accent); }
.meal-tonight .mt-k { font-size: 12px; font-weight: 800; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.meal-tonight .mt-name { font-size: 23px; font-weight: 800; margin: 3px 0 5px; }
.meal-tonight .mt-sub { color: var(--muted); font-weight: 600; display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.mplan { padding: 6px 8px; }
.mplan-row { display: flex; align-items: center; gap: 10px; padding: 10px 8px; }
.mplan-row + .mplan-row { border-top: 1px solid var(--line); }
.mp-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--line); flex: none; }
.mplan-row.planned .mp-dot { background: var(--accent); }
.mplan-row.cooked .mp-dot { background: var(--ok); }
.mplan-row.cooked .mp-name { color: var(--muted); text-decoration: line-through; }
.mp-name { flex: 1; font-weight: 700; }
.mp-status { font-size: 13px; color: var(--muted); font-weight: 700; }
.meal-card .meal-name { font-weight: 800; font-size: 16px; }
.meal-card .meal-score { font-weight: 800; color: var(--accent-text); white-space: nowrap; }
.meal-card.retired { opacity: .68; }
.mtags { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.mtag { font-size: 12px; font-weight: 700; padding: 3px 9px; border-radius: var(--radius-pill); background: var(--panel-2); color: var(--muted); }
.mtag.warn { background: var(--warn-soft); color: var(--warn-ink); }
.mstars { display: flex; gap: 6px; }
.mstar { font-size: 30px; line-height: 1; background: none; border: none; color: var(--line); cursor: pointer; padding: 0; }
.mstar.on { color: #F5B301; }
.mseg { display: flex; gap: 8px; flex-wrap: wrap; }
.mseg-b { font: inherit; font-weight: 700; font-size: 14px; padding: 8px 14px; border-radius: var(--radius-pill); border: 2px solid var(--line); background: var(--panel); color: var(--text); cursor: pointer; }
.mseg-b.on { border-color: var(--accent); background: var(--accent-soft); color: var(--accent-text); }
.mchecks { display: flex; flex-wrap: wrap; gap: 10px 16px; }
.mcheck { display: inline-flex; align-items: center; gap: 6px; font-weight: 600; }
.mrules { margin: 0; padding-left: 20px; }
.mrules li { margin: 5px 0; line-height: 1.35; }

/* ---- First-run setup wizard ---------------------------------------------- */
.wiz { max-width: 480px; }
.wiz-dots { display: flex; gap: 6px; justify-content: center; margin-bottom: 16px; }
.wiz-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--line); transition: transform .2s, background .2s; }
.wiz-dot.done { background: var(--accent-2); }
.wiz-dot.on { background: var(--accent); transform: scale(1.35); }
.wiz-opts { display: flex; flex-direction: column; gap: 10px; margin-top: 10px; }
.wiz-opt { border: 2px solid var(--line); border-radius: var(--radius-sm); padding: 12px 14px; cursor: pointer; transition: border-color .15s, background .15s; }
.wiz-opt.on { border-color: var(--accent); background: var(--accent-soft); }
.wiz-opt-t { font-weight: 800; }
.wiz-opt-d { font-size: 13px; color: var(--muted); margin-top: 3px; line-height: 1.35; }
.wiz-kids { display: flex; flex-wrap: wrap; gap: 8px; min-height: 28px; }
.wiz-kid { font-weight: 800; font-size: 14px; padding: 4px 12px; border-radius: var(--radius-pill); }
.wiz-list { margin: 6px 0; padding-left: 18px; }
.wiz-list li { margin: 8px 0; line-height: 1.4; }
.wiz-foot { display: flex; gap: 8px; align-items: center; margin-top: 18px; }

/* First-run "Getting started" guide card on the home view. */
.guide { margin: 0 0 16px; border: 2px solid var(--accent); }
.g-steps { display: flex; flex-direction: column; gap: 8px; margin-top: 14px; }
.g-step { display: flex; align-items: center; gap: 12px; width: 100%; text-align: left;
  background: var(--panel-2); border: 2px solid var(--line); border-radius: var(--radius-sm);
  padding: 12px 14px; cursor: pointer; color: var(--text); font: inherit; transition: border-color .12s, transform .06s; }
.g-step:hover { border-color: var(--dim); }
.g-step:active { transform: translate(1px, 1px); }
.g-ico { font-size: 22px; line-height: 1; flex: 0 0 auto; }
.g-txt { flex: 1; display: flex; flex-direction: column; gap: 2px; }
.g-txt b { font-weight: 800; }
.g-txt span { font-size: 13px; color: var(--muted); line-height: 1.35; }
.g-tick { flex: 0 0 auto; font-size: 18px; color: var(--dim); font-weight: 800; width: 22px; text-align: center; }
.g-tick.done { color: var(--accent-2); }

.card {
  background: var(--panel);
  border: none;
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
}

/* Pinned-up feel. nth-child tilt so cards don't all lean the same way.
   Never exceed 1deg. */
.grid > .card { position: relative; }
.grid > .card:nth-child(4n+1) { transform: rotate(-.8deg); }
.grid > .card:nth-child(4n+2) { transform: rotate(.6deg); }
.grid > .card:nth-child(4n+3) { transform: rotate(-.4deg); }
.grid > .card:nth-child(4n+4) { transform: rotate(.9deg); }

.device-card {
  cursor: pointer;
  padding-top: 26px;                /* room for the tape strip */
  transition: transform .12s ease, box-shadow .12s ease;
}
.device-card::before {              /* tape */
  content: "";
  position: absolute;
  top: -11px;
  left: 50%;
  width: 72px;
  height: 23px;
  background: var(--tape);
  transform: translateX(-50%) rotate(2deg);
  box-shadow: 0 1px 2px rgba(43, 49, 56, .18);
  pointer-events: none;
}
.grid > .device-card:hover { transform: rotate(0deg) translateY(-3px); box-shadow: var(--shadow-lift); }
.device-card:focus-visible { outline: 3px solid var(--accent); outline-offset: 3px; }

/* The badge is wide ("paused by you" is ~129px) and the name is Caveat at 30px,
   so in a single row a long device name gets starved and ellipsised. Let the
   badge drop to its own line instead — the name always wins.

   min-width:min-content is load-bearing: .device-name is white-space:nowrap, so
   its min-content width IS the full name width, which means the name can never
   be squeezed and the badge yields instead. Do NOT swap this for a fixed
   flex-basis — any basis value leaves a dead zone where names wider than the
   basis but narrower than the offered width still shrink and clip. */
.device-head { display: flex; align-items: center; gap: 12px; margin-bottom: 4px; flex-wrap: wrap; }
.device-head > div:nth-child(2) { flex: 1 1 auto; min-width: min-content; max-width: 100%; overflow: hidden; }
.device-head > .badge { margin-left: auto; }

.avatar {
  width: 46px;
  height: 46px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  font-size: 23px;
  background: var(--panel-2);
  border: 2px solid var(--line-strong);
  flex: none;
}

.device-name {
  font-family: var(--font-hand);
  font-weight: 700;
  font-size: 30px;
  line-height: 1.05;
  color: var(--text);
  /* Last-resort truncation, for a name wider than the whole card. .device-head
     wraps the badge away first, so this almost never fires. */
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.device-sub {
  color: var(--muted);
  font-size: 12.5px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ---- Status: magnet dots ------------------------------------------------ */
/* The badge keeps its dot + label (brief §6) but the dot is now a fridge
   magnet: a small sphere with a highlight. */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 5px 12px 5px 8px;
  border-radius: var(--radius-pill);
  font-size: 12.5px;
  font-weight: 800;
  white-space: nowrap;
}
.badge::before {
  content: "";
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background:
    radial-gradient(circle at 32% 30%, rgba(255, 255, 255, .75), transparent 55%),
    currentColor;
  box-shadow: 0 1px 2px rgba(43, 49, 56, .35);
  flex: none;
}
.b-allowed { color: var(--ok-ink);     background: var(--ok-soft); }
.b-grace   { color: var(--warn-ink);   background: var(--warn-soft); }
.b-blocked { color: var(--bad-ink);    background: var(--bad-soft); }
.b-paused  { color: var(--paused-ink); background: var(--paused-soft); }
.b-offline { color: var(--dim);        background: var(--panel-2); }

.pill {
  font-size: 11.5px;
  font-weight: 700;
  color: var(--muted);
  background: var(--panel-2);
  border: 1px solid var(--line);
  padding: 3px 9px;
  border-radius: var(--radius-pill);
  white-space: nowrap;
}
.pill.ok   { color: var(--ok-ink);   background: var(--ok-soft);   border-color: var(--ok); }
.pill.warn { color: var(--warn-ink); background: var(--warn-soft); border-color: var(--warn); }
.pill.bad  { color: var(--bad-ink);  background: var(--bad-soft);  border-color: var(--bad); }

/* ---- Time left: the punch strip ---------------------------------------- */
/* Existing markup is unchanged:
     <div class="timebar"><span style="width:62%"></span></div>
   The cell dividers are painted on TOP of the fill by ::after, so any width%
   still reads as "N squares used of 8". app.js may optionally set
   style="--cells:12" to change the divisions; 8 is the default. */
.timebar {
  --cells: 8;
  position: relative;
  height: 28px;
  background: var(--panel-2);
  border: 2px solid var(--line-strong);
  border-radius: 4px;
  overflow: hidden;
  margin: 14px 0 8px;
}
.timebar > span {
  display: block;
  height: 100%;
  background: var(--text);
  border-radius: 0;
  transition: width .3s ease;
}
.timebar::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background-image: repeating-linear-gradient(
    90deg,
    transparent 0,
    transparent calc(100% / var(--cells) - 2px),
    var(--line-strong) calc(100% / var(--cells) - 2px),
    var(--line-strong) calc(100% / var(--cells))
  );
}
.timebar.warn > span { background: var(--warn); }
.timebar.bad > span { background: var(--bad); }

.time-meta {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  font-size: 13px;
  color: var(--muted);
  font-weight: 600;
}
.time-meta > :last-child { color: var(--text); font-weight: 800; }

/* The friendly restatement under the strip, e.g. "3 squares left — 46 min".
   Handwriting is allowed here because it repeats information already shown
   numerically in .time-meta. */
.squares-left {
  font-family: var(--font-hand);
  font-weight: 700;
  font-size: 22px;
  line-height: 1.1;
  color: var(--ok-ink);
  margin-top: 2px;
}
.squares-left.warn { color: var(--warn-ink); }
.squares-left.bad { color: var(--bad-ink); }

.timeleft {
  font-size: 16px;
  font-weight: 600;
  background: var(--panel-2);
  border-radius: var(--radius);
  padding: 15px 18px;
}
.timeleft b { font-size: 19px; }

.actions { display: flex; gap: 9px; margin-top: 16px; flex-wrap: wrap; }

/* ---- Forms ------------------------------------------------------------- */
label {
  display: block;
  font-size: 13px;
  color: var(--text);
  margin: 16px 0 7px;
  font-weight: 700;
  text-transform: none;
  letter-spacing: 0;
}

input, select, textarea {
  width: 100%;
  background: var(--panel);
  border: 2px solid var(--line);
  color: var(--text);
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  font-size: 15px;
  font-family: inherit;
  font-weight: 600;
  min-height: 48px;
}
input:hover, select:hover, textarea:hover { border-color: var(--dim); }
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 4px var(--accent-soft);
}
textarea { min-height: 90px; font-family: var(--font-mono); font-size: 13.5px; }

input[type="checkbox"] {
  appearance: none;
  width: 26px !important; /* many carry an inline width:auto, which collapsed the empty box to a line */
  min-width: 26px;
  height: 26px;
  min-height: 0;
  padding: 0;
  border: 2px solid var(--line-strong);
  border-radius: 5px;
  background: var(--panel);
  display: inline-grid;
  place-items: center;
  cursor: pointer;
  flex: none;
}
input[type="checkbox"]:checked { background: var(--accent); border-color: var(--accent); }
input[type="checkbox"]:checked::after {
  content: "✓";
  color: var(--accent-ink);
  font-size: 17px;
  font-weight: 800;
  line-height: 1;
}

input[type="range"] { appearance: none; height: 28px; padding: 0; border: none; background: transparent; }
input[type="range"]::-webkit-slider-runnable-track {
  height: 10px;
  background: var(--panel-2);
  border: 2px solid var(--line-strong);
  border-radius: var(--radius-pill);
}
input[type="range"]::-webkit-slider-thumb {
  appearance: none;
  width: 26px;
  height: 26px;
  margin-top: -10px;
  border-radius: 50%;
  background: radial-gradient(circle at 32% 30%, rgba(255,255,255,.8), transparent 55%), var(--accent);
  border: 2px solid var(--line-strong);
  cursor: pointer;
}
input[type="range"]::-moz-range-track {
  height: 10px; background: var(--panel-2);
  border: 2px solid var(--line-strong); border-radius: var(--radius-pill);
}
input[type="range"]::-moz-range-thumb {
  width: 26px; height: 26px; border-radius: 50%;
  background: var(--accent); border: 2px solid var(--line-strong); cursor: pointer;
}

input[type="color"] { padding: 4px; height: 48px; cursor: pointer; }
input[type="time"] { font-variant-numeric: tabular-nums; }

/* The 7 weekday budget inputs. Desktop keeps 7 across; phones drop to 4 so the
   tap targets stop being 38px wide (brief §6 called this out explicitly). */
.field-row { display: grid; grid-template-columns: repeat(7, 1fr); gap: 8px; }
.field-row .day {
  text-align: center;
  background: var(--panel-2);
  border: 2px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 9px 4px 7px;
}
.field-row .day:focus-within { border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft); }
.field-row .day small {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  margin-bottom: 4px;
}
.field-row .day input {
  padding: 6px 2px;
  text-align: center;
  font-size: 17px;
  font-weight: 800;
  min-height: 40px;
  background: transparent;
  border: none;
}
.field-row .day input:focus { box-shadow: none; }

.hint { color: var(--muted); font-size: 13px; margin-top: 7px; line-height: 1.5; }
.err { color: var(--bad-ink); font-size: 13.5px; font-weight: 700; margin-top: 10px; min-height: 20px; }

/* A titled group inside the rules editor. NEW pattern — wrap each logical
   group of policy fields in this instead of a flat run of labels. */
.rule-card {
  background: var(--panel);
  border: 2px solid var(--line);
  border-radius: var(--radius);
  padding: 18px 20px;
  margin: 16px 0;
}
.rule-card > .rule-head { display: flex; align-items: center; gap: 12px; margin-bottom: 4px; }
.rule-card > .rule-head .ico {
  width: 40px; height: 40px; flex: none;
  display: grid; place-items: center;
  font-size: 20px;
  background: var(--panel-2);
  border: 2px solid var(--line-strong);
  border-radius: 11px;
}
.rule-card > .rule-head h3 {
  font-family: var(--font-hand);
  font-weight: 700;
  font-size: 25px;
  line-height: 1.1;
  margin: 0;
}
.rule-card > .rule-head .rule-sub { color: var(--muted); font-size: 13px; font-weight: 600; }
.rule-card > .rule-head + label { margin-top: 12px; }

/* Weekday / warning-minute toggles as chips. */
.chip {
  display: inline-grid;
  place-items: center;
  padding: 10px 15px;
  min-height: 42px;
  border: 2px solid var(--line);
  border-radius: var(--radius-pill);
  background: var(--panel-2);
  color: var(--muted);
  font-weight: 700;
  font-size: 13px;
  cursor: pointer;
}
.chip.on { background: var(--accent-soft); border-color: var(--accent); color: var(--accent-text); font-weight: 800; }
.chip.add { border-style: dashed; color: var(--accent-text); background: transparent; }

/* ---- Auth screens ------------------------------------------------------ */
.auth { display: grid; place-items: center; min-height: 100vh; padding: 24px; }
.auth .card {
  width: 100%;
  max-width: 420px;
  padding: 34px 30px 30px;
  transform: rotate(-.8deg);
  box-shadow: var(--shadow-lift);
  position: relative;
}
.auth .card::before {            /* tape */
  content: "";
  position: absolute;
  top: -13px;
  left: 50%;
  width: 108px;
  height: 27px;
  background: var(--tape);
  transform: translateX(-50%) rotate(-2.5deg);
  box-shadow: 0 1px 3px rgba(43, 49, 56, .22);
}
.auth h1 { text-align: center; font-size: 42px; }
.auth .sub { text-align: center; }
.auth .btn { width: 100%; margin-top: 18px; }

/* ---- Modal / drawer ---------------------------------------------------- */
.backdrop {
  position: fixed;
  inset: 0;
  background: rgba(16, 19, 22, .58);
  z-index: 50;
  display: grid;
  place-items: center;
  padding: max(20px, var(--sat)) 18px max(20px, var(--sab));
}
.modal {
  background: var(--panel);
  border: none;
  border-radius: var(--radius);
  width: 100%;
  max-width: 620px;
  max-height: 90vh;
  overflow: auto;
  box-shadow: var(--shadow-lift);
}
.modal .m-head { padding: 20px 24px 18px; border-bottom: 2px solid var(--line); }
.modal .m-head h1 { font-size: 32px; }
.modal .m-body { padding: 22px 24px; }
.modal .m-foot {
  padding: 16px 24px;
  border-top: 2px solid var(--line);
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--panel-2);
  position: sticky;
  bottom: 0;
}

.code {
  font-family: var(--font-mono);
  background: var(--panel-2);
  border: 2px dashed var(--line-strong);
  border-radius: var(--radius-sm);
  padding: 18px;
  font-size: 30px;
  font-weight: 700;
  letter-spacing: .18em;
  text-align: center;
}

/* ---- Feeds / misc ----------------------------------------------------- */
.events { font-size: 14px; }
.events .ev {
  display: flex;
  gap: 14px;
  align-items: baseline;
  padding: 11px 0;
  border-bottom: 1px dashed var(--line);
  color: var(--text);
  font-weight: 600;
}
.events .ev:last-child { border-bottom: none; }
.events .ev time {
  color: var(--muted);
  flex: none;
  width: 92px;
  font-variant-numeric: tabular-nums;
  font-weight: 600;
}

.empty {
  color: var(--muted);
  text-align: center;
  padding: 40px 24px;
  font-size: 15px;
}
.empty .hand { display: block; font-size: 30px; color: var(--text); margin-bottom: 6px; }
.empty .btn { margin-top: 18px; }

.toast {
  position: fixed;
  bottom: calc(22px + var(--sab));
  left: 50%;
  transform: translateX(-50%) rotate(-.8deg);
  background: var(--panel);
  color: var(--text);
  border: 2px solid var(--line-strong);
  padding: 13px 20px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  z-index: 100;
  font-weight: 700;
  font-size: 14.5px;
  max-width: min(92vw, 460px);
}

/* ---- More-time request banner ("a knock on the door") ----------------- */
/* Existing markup: <div class="reqbar"> … <span class="reqbtns"> … */
.reqbar {
  position: relative;
  margin: 18px max(14px, var(--sar)) 0 max(14px, var(--sal));
  background: var(--panel);
  border: none;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  transform: rotate(-.5deg);
  color: var(--text);
  padding: 20px 22px 18px 26px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
  font-family: var(--font-hand);
  font-weight: 700;
  font-size: 26px;
  line-height: 1.15;
}
.reqbar::before {                /* tape, off to one side like a real note */
  content: "";
  position: absolute;
  top: -11px;
  left: 38px;
  width: 84px;
  height: 23px;
  background: var(--tape);
  transform: rotate(-3deg);
  box-shadow: 0 1px 2px rgba(43, 49, 56, .18);
}
.reqbar .reqbtns { display: flex; gap: 9px; font-family: var(--font); font-size: 13.5px; }
.reqbar .dim { color: var(--muted); font-family: var(--font); font-size: 13px; font-weight: 600; }

/* "Notifications are off" heads-up — a plain, obvious warning bar (not the sticky
   note), so a parent never silently misses approvals. */
.notifybar {
  margin: 14px max(14px, var(--sar)) 0 max(14px, var(--sal));
  background: var(--warn-soft);
  border: 2px solid var(--warn);
  border-radius: var(--radius);
  color: var(--warn-ink);
  padding: 13px 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  font-weight: 700;
  font-size: 15px;
  line-height: 1.35;
}
.notifybar .reqbtns { display: flex; gap: 8px; }
@media (max-width: 640px) {
  .notifybar .reqbtns { width: 100%; }
  .notifybar .reqbtns .btn { flex: 1; }
}

/* ---- Reports ---------------------------------------------------------- */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 16px; margin: 6px 0 20px; }
.stat {
  background: var(--panel);
  border: none;
  border-radius: var(--radius);
  padding: 18px 20px;
  box-shadow: var(--shadow);
}
.stat:nth-child(odd) { transform: rotate(-.6deg); }
.stat:nth-child(even) { transform: rotate(.5deg); }
.stat .v { font-size: 30px; font-weight: 800; line-height: 1.05; font-variant-numeric: tabular-nums; }
.stat .l {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  margin-top: 3px;
  text-transform: none;          /* was uppercase + letterspaced */
  letter-spacing: 0;
}

.chart-wrap {
  background: var(--panel);
  border: none;
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
}
.chart-wrap svg { width: 100%; height: auto; display: block; }
/* barChartSVG() already paints with var(--ok) / var(--bad) / var(--line) /
   var(--muted), so it re-themes for free. Bump its font-size from 10 to 12 in
   app.js — 10px axis labels are under the legibility floor. */

.legend { display: flex; gap: 18px; color: var(--muted); font-size: 13px; font-weight: 600; margin-top: 12px; flex-wrap: wrap; }
.legend span { display: inline-flex; align-items: center; gap: 7px; }
.legend span::before { content: ""; width: 14px; height: 14px; border-radius: 3px; border: 1.5px solid var(--line-strong); }
.legend .u::before { background: var(--ok); }
.legend .dv::before { background: var(--c); border-color: var(--c); }
.legend .ov::before { background: var(--bad); border: none; border-radius: 50%; width: 8px; height: 8px; }
.legend .o::before { background: var(--bad); }
.legend .b::before { background: transparent; border: none; border-top: 2px dashed var(--muted); border-radius: 0; height: 0; width: 16px; }

.applist { display: flex; flex-direction: column; gap: 10px; }
/* Mobile data on a kid's phone (openDataUse): a bar a day for 14 days. */
.du-total { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 12px; font-size: 18px; margin-bottom: 10px; }
.du-bars { display: grid; grid-template-columns: repeat(14, minmax(0, 1fr)); gap: 4px; height: 120px; align-items: end; margin-bottom: 14px; }
.du-col { display: flex; flex-direction: column; justify-content: flex-end; align-items: stretch; height: 100%; min-width: 0; }
.du-bar { background: var(--accent-2); border-radius: 4px 4px 0 0; min-height: 2px; }
.du-bar.none { background: var(--line); }
.du-wd { text-align: center; font-size: 11px; color: var(--muted); margin-top: 3px; }
.du-num { font-variant-numeric: tabular-nums; white-space: nowrap; }
.approw { display: grid; grid-template-columns: minmax(0, 160px) 1fr auto; align-items: center; gap: 12px; font-size: 14px; }
.approw .track {
  background: var(--panel-2);
  border: 2px solid var(--line-strong);
  border-radius: 4px;
  height: 20px;
  overflow: hidden;
}
.approw .track > span { display: block; height: 100%; background: var(--accent); }
.approw .app { color: var(--text); font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.approw .t { color: var(--muted); font-weight: 700; font-variant-numeric: tabular-nums; }

/* ---- Mobile ----------------------------------------------------------- */
/* Bottom tab bar. NEW markup — see README §"Bottom nav". The top bar stays
   sticky (brief §2) and keeps the brand + account; the tabs move down. */
.tabbar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 20;
  display: none;
  background: var(--panel);
  border-top: 2px solid var(--line);
  padding: 6px 4px calc(6px + var(--sab));
}
.tabbar a {
  flex: 1 1 0;
  min-width: 0;                 /* let items shrink evenly instead of overflowing */
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 8px 2px;
  min-height: 54px;
  color: var(--muted);
  font-size: 11.5px;
  font-weight: 700;
  text-decoration: none;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}
.tabbar a .ico { font-size: 21px; line-height: 1; }
.tabbar a.active { color: var(--accent-text); font-weight: 800; }

@media (max-width: 720px) {
  body { font-size: 15px; }
  /* Flush to the top edge: with the desktop 14px margin the page's h1 peeked
     out ABOVE the sticky bar while scrolling (looked like broken alignment). */
  .topbar {
    gap: 10px;
    margin: 0;
    padding: calc(11px + var(--sat)) max(15px, var(--sar)) 11px max(15px, var(--sal));
    border-radius: 0 0 12px 12px;
    top: 0;
  }
  .topbar nav { display: none; }          /* tabs move to .tabbar */
  .wrap { padding-top: 18px; }

  /* Family sub-nav: one row that scrolls sideways instead of orphaning a pill. */
  .famnav { flex-wrap: nowrap; overflow-x: auto; -webkit-overflow-scrolling: touch; scrollbar-width: none; padding-bottom: 2px; }
  .famnav::-webkit-scrollbar { display: none; }
  .famnav .btn { flex: none; white-space: nowrap; }

  /* Routine kid cards: name + badges wrap; "Edit steps" always sits on its own
     line under the emoji strip, the same for every kid (it used to float right
     only when the badges happened to be short). */
  .kidhead { flex-direction: column; align-items: stretch; gap: 10px; }
  .kidhead > div { min-width: 0; }
  .kidhead .device-name { white-space: normal; line-height: 1.25; display: flex; flex-wrap: wrap; align-items: center; gap: 6px 8px; }
  .kidhead .device-sub { margin-top: 6px; letter-spacing: 2px; }
  .kidhead > .btn { align-self: flex-start; }
  .brand { font-size: 26px; }
  h1 { font-size: 32px; }
  h2 { font-size: 24px; }
  .wrap { padding-bottom: calc(96px + var(--sab)); }
  .tabbar { display: flex; }

  /* When .spread wraps, the action buttons stack right above the grid; the first
     card's tape strip (top:-11px) needs clearance so it doesn't overlap them. */
  .spread { row-gap: 14px; }
  .grid { grid-template-columns: 1fr; gap: 22px; margin-top: 20px; }
  /* Tilt reads as sloppy in a single column on a small screen. */
  .grid > .card,
  .stat { transform: none; }
  .device-card:hover { transform: translateY(-2px); }

  /* The fix the brief asked for by name: 7 tiny inputs → 4 real tap targets. */
  .field-row { grid-template-columns: repeat(4, 1fr); }
  .field-row .day input { min-height: 48px; font-size: 18px; }

  .reqbar { font-size: 23px; padding: 20px 18px 16px 20px; }
  .reqbar .reqbtns { width: 100%; }
  .reqbar .reqbtns .btn { flex: 1; }

  .modal { max-height: 94vh; border-radius: var(--radius) var(--radius) 0 0; }
  .backdrop { place-items: end center; padding: 0; }

  .approw { grid-template-columns: minmax(0, 1fr) auto; }
  .approw .track { grid-column: 1 / -1; order: 3; }
}

@media (max-width: 380px) {
  .field-row { grid-template-columns: repeat(3, 1fr); }
  h1 { font-size: 28px; }
}

/* ---- Motion / accessibility ------------------------------------------ */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
  .device-card:hover { transform: none; }
}

@media (prefers-contrast: more) {
  :root { --muted: var(--text); --dim: var(--text); --line: var(--line-strong); }
  .card, .stat, .reqbar, .topbar { border: 2px solid var(--line-strong); }
}

/* Keyboard users get a visible ring everywhere, not just on .btn. */
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

/* Print (the weekly recap, if it ever gets printed for the fridge). */
@media print {
  body { background: #fff; }
  .topbar, .tabbar, .toast, .actions, .reqbar .reqbtns { display: none; }
  .card, .stat, .chart-wrap { box-shadow: none; border: 1px solid #999; transform: none; }
}

/* Photo screensaver management grid */
.photo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 10px; margin-top: 8px; }
.photo-thumb { position: relative; aspect-ratio: 1; border-radius: 12px; overflow: hidden; background: var(--panel-2); }
.photo-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.photo-del { position: absolute; top: 4px; right: 4px; width: 26px; height: 26px; border: none;
  border-radius: 50%; background: rgba(0,0,0,.6); color: #fff; font-weight: 800; cursor: pointer; line-height: 1; }

/* Emoji picker (reward/chore/to-do/event modals) */
.emoji-picked { font-size: 30px; text-align: center; margin: 4px 0 6px; line-height: 1; }
.emoji-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(42px, 1fr)); gap: 4px;
  max-height: 240px; overflow-y: auto; padding: 6px; background: var(--panel-2);
  border: 1px solid var(--line); border-radius: 8px; }
.emoji-opt { font-size: 24px; line-height: 1; padding: 6px 0; border: 2px solid transparent;
  border-radius: 8px; background: transparent; cursor: pointer; }
.emoji-opt:hover { background: var(--panel); }
.emoji-opt.sel { border-color: var(--accent); background: var(--accent-soft); }
.emoji-grp { grid-column: 1 / -1; font: 800 12px var(--text-font, inherit); color: var(--muted, #7b7392); text-transform: uppercase; letter-spacing: .06em; margin: 8px 2px 2px; }
.emoji-grp:first-child { margin-top: 0; }
.emoji-grid.tall { max-height: min(60vh, 520px); }
.cp-iconbtn { width: 64px; height: 42px; border-radius: 12px; border: 2px solid var(--line-strong, #2B3138); font-size: 24px; line-height: 1; color: #fff; font-weight: 800; cursor: pointer; }

/* ---- Pull to refresh (touch; the installed app's WebView has none) ---- */
html, body { overscroll-behavior-y: contain; }   /* our handler owns the top pull */
html, body { overscroll-behavior-y: none; }

#ptr {
  position: fixed; top: calc(var(--sat)); left: 0; right: 0;
  display: flex; justify-content: center; pointer-events: none; z-index: 60;
  transform: translateY(-56px); transition: transform .12s ease;
}
.ptr-pill {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 9px 16px; border-radius: 999px;
  background: var(--panel); color: var(--muted); border: 2px solid var(--line-strong);
  font-weight: 700; font-size: 14px; box-shadow: 0 6px 18px rgba(0,0,0,.18);
}
.ptr-ico { display: inline-block; font-size: 18px; line-height: 1; transition: transform .15s ease; }
#ptr.armed .ptr-pill { color: var(--text); }
#ptr.armed .ptr-ico { transform: rotate(180deg); }
#ptr.busy .ptr-ico { animation: ptr-spin .8s linear infinite; }
@keyframes ptr-spin { to { transform: rotate(360deg); } }

/* Drag-to-reorder handles (morning steps editors) */
.drag-handle { cursor: grab; user-select: none; -webkit-user-select: none; touch-action: none; color: var(--muted); font-size: 22px; line-height: 1; padding: 6px 4px; border-radius: 8px; }
.drag-handle:active { cursor: grabbing; }
.stepedit.dragging { opacity: .35; }
.stepedit.dragging .drag-handle { background: var(--panel-2); }

/* ---- Map (Where is everyone?) ----------------------------------------- */
.lmap-card { padding: 0; overflow: hidden; }
/* isolation: Leaflet's panes use z-index 400–1000; keep them under modals and the tab bar */
.lmap { height: min(62vh, 520px); min-height: 300px; width: 100%; background: var(--line); position: relative; z-index: 0; isolation: isolate; }
.lmap.placing { cursor: crosshair; outline: 3px dashed var(--accent); outline-offset: -3px; }
.lmap .leaflet-popup-content { font-size: 13.5px; line-height: 1.45; }
.mpin-wrap { background: none; border: 0; }
.mpin { width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; flex: none;
  background: var(--c); color: #fff; font-weight: 800; font-size: 16px; border: 3px solid #fff;
  box-shadow: 0 2px 6px rgba(0,0,0,.35); }
.mpin-wrap.stale .mpin { opacity: .55; filter: grayscale(.5); }
.mloc.sel { outline: 2px solid var(--accent); }
.mloc-where { margin-top: 8px; }
.mtrailbar { margin-top: 10px; display: flex; gap: 10px; align-items: center; justify-content: space-between; flex-wrap: wrap; padding: 10px 14px; }
.mplace-row { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.mplace-row:last-child { border-bottom: 0; }
.mplace-ico { font-size: 22px; width: 30px; text-align: center; }
.mplace-name { flex: 1; min-width: 0; }
.ot-steps { padding-left: 20px; margin: 0 0 8px; }
.ot-steps li { margin-bottom: 8px; }
.ot-url { margin: 6px 0; padding: 8px; background: var(--line); border-radius: 8px; word-break: break-all; font-size: 12.5px; user-select: all; }

/* ---- Lights view ---------------------------------------------------------- */
.lights-grid { grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 16px; }
.light-card { transition: box-shadow .2s; }
.light-card.is-on { box-shadow: 0 0 0 2px var(--accent-soft), 0 6px 18px rgba(255, 200, 80, .18); }
.light-card.is-unavail { opacity: .55; }
.light-name { font-weight: 800; display: flex; align-items: center; gap: 8px; }
.light-dot { width: 14px; height: 14px; border-radius: 50%; border: 2px solid var(--line-strong); flex: none; }
.light-party { display: inline-flex; align-items: center; gap: 4px; font-size: 18px; cursor: pointer; margin: 0; }
.light-party input { width: 16px; height: 16px; margin: 0; }
.light-row { display: flex; align-items: center; gap: 8px; margin-top: 10px; }
.light-row input[type="range"] { flex: 1; min-width: 0; }
.swatches { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; align-items: center; }
.swatch { width: 26px; height: 26px; border-radius: 50%; border: 2px solid var(--line-strong); cursor: pointer; padding: 0; }
.swatch.sel { outline: 3px solid var(--accent); outline-offset: 2px; }
.swatches input[type="color"] { width: 30px; height: 30px; padding: 0; border: 2px solid var(--line-strong); border-radius: 50%; background: none; cursor: pointer; }
.light-effect { max-width: 150px; }

/* ---- On-screen keyboard (Board only; see osk.js) ------------------------- */
#hb-osk { position: fixed; left: 0; right: 0; bottom: 0; z-index: 9999; display: none;
  padding: 10px 10px calc(10px + var(--sab, 0px)); background: var(--panel-2, #20252b);
  border-top: 2px solid var(--line-strong, #3a414a); box-shadow: 0 -6px 18px rgba(0,0,0,.25);
  user-select: none; -webkit-user-select: none; touch-action: manipulation; }
#hb-osk.show { display: block; }
#hb-osk .osk-row { display: flex; gap: 8px; justify-content: center; margin-bottom: 8px; }
#hb-osk .osk-row:last-child { margin-bottom: 0; }
#hb-osk .osk-k { flex: 1 1 0; max-width: 88px; min-height: 58px; font: 600 22px/1 var(--font, system-ui);
  border-radius: 10px; border: 2px solid var(--line-strong, #3a414a); background: var(--panel, #2a3038);
  color: var(--text); cursor: pointer; padding: 0; }
#hb-osk .osk-k:active { transform: translateY(2px); background: var(--accent-soft, #37506b); }
#hb-osk .osk-fn { flex: 1.5 1 0; max-width: 132px; font-size: 18px; background: var(--panel-2, #20252b); }
#hb-osk .osk-fn.on { background: var(--accent, #5b8cff); color: #fff; }
#hb-osk .osk-space { flex: 5 1 0; max-width: 420px; }
#hb-osk.num .osk-k { max-width: 140px; min-height: 66px; font-size: 26px; }
#hb-osk .osk-extra .osk-k { max-width: 180px; font-size: 17px; min-height: 46px; }

/* ---- Board: setup QR, back-to-board bar ---------------------------------- */
.qr-box { display: flex; justify-content: center; margin: 14px 0 6px; }
.qr-box svg { width: min(240px, 70vw); height: auto; background: #fff; padding: 10px; border-radius: 12px; }
.qr-url { text-align: center; font-size: 13px; word-break: break-all; color: var(--muted); }
.board-bar { position: fixed; left: 50%; bottom: calc(14px + var(--sab, 0px)); transform: translateX(-50%); z-index: 80; }

/* Help requests and bug reports (app.js supportModal / reportsModal) */
.sup-form label{display:block}
.sup-kinds{display:flex;flex-wrap:wrap;gap:8px;margin-bottom:4px}
.sup-kind{display:flex!important;align-items:center;gap:8px;padding:6px 14px;min-height:0!important;line-height:1.25;font-weight:600;border:1px solid var(--line,#D9D4C7);border-radius:999px;cursor:pointer;margin:0!important}
.sup-kind input{width:18px!important;height:18px!important;min-height:0!important;padding:0!important;margin:0;flex:none}
.sup-check{display:flex!important;align-items:flex-start;gap:8px;margin-top:12px}
.sup-check input{width:20px!important;height:20px!important;min-height:0!important;margin:2px 0 0;flex:none}
.sup-check .hint{display:inline;margin:0}
.sup-pre{font-size:12px;background:var(--panel-2,#F6F1E4);padding:10px;border-radius:8px;white-space:pre-wrap;word-break:break-word;max-height:260px;overflow:auto}
#sup-preview summary{cursor:pointer;margin-top:8px;color:var(--accent,#2F6F8F)}
.sup-item{padding:10px 0;border-top:1px solid var(--line-soft,#D9D4C7)}
.sup-item:first-child{border-top:0;padding-top:0}
.sup-item-top{display:flex;gap:10px;align-items:flex-start;justify-content:space-between}
.sup-item-text{margin-top:6px;white-space:pre-wrap;font-size:14px}

/* Demo banner (app.js loadDemoBar) */
.reqbar.demobar{background:#E3F2F7;border-radius:12px;margin:12px max(14px, var(--sar)) 0 max(14px, var(--sal));display:flex;gap:8px 12px;align-items:center;flex-wrap:wrap;
  transform:none;padding:10px 14px;font-family:var(--font);font-weight:500;font-size:15px;line-height:1.4;box-shadow:inset 0 0 0 2px #5AA9E6}
.reqbar.demobar::before{display:none}
.reqbar.demobar > span:first-of-type{flex:1;min-width:220px}
.reqbar.demobar b{font-weight:800}
@media (prefers-color-scheme:dark){.reqbar.demobar{background:#1E3440;border-color:#3D7FA8}}

/* One time pool per kid (Screens strip, Kids card) and the grouped device window */
.devgroup-head.has-pool{flex-wrap:wrap;gap:10px 14px}
.kidpool{display:flex;align-items:center;gap:12px;flex:1;min-width:220px;max-width:520px}
.kidpool-txt{display:flex;flex-direction:column;line-height:1.2;white-space:nowrap}
.kidpool-txt small{color:var(--muted);font-size:13px}
.kidpool .timebar{flex:1;margin:0;min-width:80px;height:16px}
/* The kid strip's bar shows time LEFT (green squares), slimmer than a device card's. */
.kidpool .timebar > span{background:var(--ok,#3D7C4A)}
.kidpool .timebar.warn > span{background:var(--warn)}
.kidpool .timebar.bad > span{background:var(--bad)}
.kidpool-btns{display:flex;gap:6px;flex-wrap:wrap}
.kidpool-none{color:var(--muted);font-size:14px}
.kidcard-time{display:flex;align-items:center;justify-content:space-between;gap:8px;margin-top:10px;font-size:15px}
.dm .timeleft{font-size:15px;margin:0 0 6px}
.dm > .device-sub{margin:0 0 10px}
.dm-now{display:flex;gap:8px;flex-wrap:wrap;margin:12px 0 4px}
.dm-rules{margin:14px 0 4px;padding:10px 12px;border-radius:12px;background:var(--panel-2,#F6F1E4);font-size:15px;line-height:1.45}
.dm-sec{border-top:1px solid var(--line-soft,#D9D4C7);margin-top:12px;padding-top:10px}
.dm-sec > summary{cursor:pointer;font-weight:700;padding:4px 0;list-style:revert}
.dm-row{display:flex;gap:8px;flex-wrap:wrap;margin:10px 0 6px}
.dm-set{margin:12px 0 4px}
.dm-set .hint{margin:4px 0 0}
/* Phones: compact device cards. The status sits under the name (not on a line of its
   own), the name is smaller, and the actions sit closer, so about twice as many
   screens fit on a phone. */
@media (max-width: 640px) {
  .device-card { padding: 14px 14px 12px; }
  .device-head { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; grid-template-areas: "ava who badge"; column-gap: 10px; align-items: start; margin-bottom: 2px; }
  .device-head > .badge { padding: 4px 10px 4px 6px; gap: 6px; }
  .device-head > .badge::before { width: 13px; height: 13px; }
  .device-head > .avatar { grid-area: ava; align-self: start; width: 40px; height: 40px; font-size: 20px; }
  .device-head > div:nth-child(2) { grid-area: who; min-width: 0; }
  .device-head > .badge { grid-area: badge; justify-self: start; margin-left: 0; }
  .device-card .device-name { font-size: 24px; white-space: normal; overflow: visible; }
  /* What's on (left) and the device's buttons (right) share one row. */
  .grid > .device-card { transform: none; display: grid; grid-template-columns: minmax(0, 1fr) auto; column-gap: 8px; align-items: center; }
  .grid > .device-card > * { grid-column: 1 / -1; }
  .grid > .device-card > .device-sub { grid-column: 1; margin: 8px 0 0 52px; }
  .grid > .device-card > .actions { grid-column: 2; margin: 8px 0 0; gap: 6px; justify-content: flex-end; }
  .grid > .device-card > .actions:empty { display: none; }
  .device-card .actions .btn.sm { padding: 6px 12px; min-height: 38px; }
}

/* Shopping list: the add box, the usuals, store sections side by side. */
.shop-addcard { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; padding: 14px; }
.shop-addcard #shop-in { flex: 3 1 240px; min-width: 0; font-size: 17px; }
.shop-addcard #shop-qty { flex: 1 1 110px; min-width: 0; max-width: 180px; font-size: 17px; }
.shop-usual { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: 12px 0 4px; }
.shop-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(320px, 100%), 1fr)); gap: 14px; align-items: start; margin-top: 14px; }
.shop-sec, .shop-cart { padding: 12px 14px; margin: 0; }
.shop-cart { margin-top: 14px; }
.shop-row { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-top: 1px solid var(--line); }
.shop-row:first-of-type { border-top: 0; }
.shop-tick { width: 34px; height: 34px; flex: none; border-radius: 10px; border: 2px solid var(--line); background: transparent;
  font: 900 20px/1 inherit; color: #fff; cursor: pointer; }
.shop-row.got .shop-tick { background: #2f8f57; border-color: #2f8f57; }
.shop-main { flex: 1; min-width: 0; cursor: pointer; }
.shop-t { font-size: 17px; font-weight: 700; overflow-wrap: anywhere; }
.shop-row.got .shop-t { text-decoration: line-through; color: var(--dim); }
.shop-q { color: var(--dim); }
.shop-wmcard { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; justify-content: space-between; padding: 12px 14px; margin-top: 14px; }
/* "Time to re-order?" (lib/groceries.js): due products from the family's order history. */
.reo-card { padding: 12px 14px; margin-top: 14px; }
.reo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(300px, 100%), 1fr)); gap: 4px 18px; margin-top: 6px; }
.reo-row { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-top: 1px solid var(--line); min-width: 0; }
.reo-row img, .reo-row .reo-em { width: 42px; height: 42px; flex: none; border-radius: 10px; object-fit: contain; background: #fff; display: grid; place-items: center; font-size: 24px; }
.reo-main { flex: 1; min-width: 0; }
.reo-t { font-weight: 700; overflow-wrap: anywhere; }
.reo-tbl { width: 100%; border-collapse: collapse; font-size: 14px; }
.reo-tbl th, .reo-tbl td { text-align: left; padding: 6px 8px; border-top: 1px solid var(--line); vertical-align: middle; }
.reo-tbl td.n { font-variant-numeric: tabular-nums; white-space: nowrap; }
.reo-tbl input, .reo-tbl select { width: auto; min-width: 0; padding: 4px 6px; }
.reo-row.skipped .reo-t { text-decoration: line-through; color: var(--dim); }
.qty-step { display: flex; align-items: center; gap: 6px; font-variant-numeric: tabular-nums; }
.qty-step b { min-width: 1.6em; text-align: center; }
.order-sum { display: grid; gap: 6px; padding: 12px 14px; margin-top: 14px; font-variant-numeric: tabular-nums; }
/* Usual groceries: name + match on the first line, amount / how often / remove under it. */
.stp-row { flex-wrap: wrap; }
.stp-row .reo-main { flex: 1 1 calc(100% - 60px); }
.stp-ctl { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-left: 52px; }
.stp-ctl select { width: auto; min-width: 0; padding: 4px 6px; flex: 0 1 auto; }
@media (max-width: 560px) {
  .stp-ctl { margin-left: 0; flex: 1 1 100%; flex-wrap: nowrap; }
  .stp-ctl select { flex: 1 1 auto; }
}
#stp-box .shop-wm { text-align: left; }
/* Phones: a product row's buttons go under its name instead of squeezing it. */
@media (max-width: 560px) {
  .reo-row { flex-wrap: wrap; }
  .reo-row .reo-main { flex: 1 1 calc(100% - 60px); }
  .reo-row .reo-main + .btn, .reo-row .reo-main + .qty-step { margin-left: 52px; }
}
.shop-wm { display: inline-block; margin-top: 4px; padding: 3px 0; border: 0; background: none; font: 600 13px/1.3 inherit;
  color: var(--accent-text, #2563eb); cursor: pointer; text-align: left; overflow-wrap: anywhere; }
.shop-wm.on { color: var(--dim); font-weight: 500; }
/* Walmart products found by the family's AI server: tap one to use it. */
.wm-found { margin-bottom: 4px; }
.wm-cands { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(150px, 100%), 1fr)); gap: 8px; margin-top: 10px; }
.wm-cand { display: flex; flex-direction: column; gap: 4px; align-items: stretch; text-align: left; padding: 8px; border-radius: 12px;
  border: 2px solid var(--line); background: transparent; color: inherit; font: inherit; cursor: pointer; min-width: 0; }
.wm-cand.on { border-color: var(--accent-text); }
.wm-cand img, .wm-cand .wm-noimg { width: 100%; aspect-ratio: 1; object-fit: contain; background: #fff; border-radius: 8px; display: grid; place-items: center; font-size: 30px; }
.wm-cn { font-size: 13px; font-weight: 600; line-height: 1.25; overflow-wrap: anywhere; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.wm-cp { font-size: 13px; color: var(--dim); }
/* A shared console's check-out on its Screens card. */
.co-line { margin-top: 8px; font-size: 15px; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.co-dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
