:root {
  --bg: #f6f3ee; --card: #fffdf9; --ink: #1d2125; --muted: #6b6f76; --line: #e8e2d8; --soft: #f0ebe3;
  --accent: #2f6f5e; --accent-ink: #fff; --danger: #c2410c; --warn: #9a6700; --ok: #2f6f5e;
  --radius: 18px; --shadow: 0 1px 2px rgba(40, 30, 10, .05), 0 6px 20px rgba(40, 30, 10, .05);
  --font: ui-rounded, "SF Pro Rounded", "Nunito", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
  --bg: #15171a; --card: #1e2125; --ink: #eceef0; --muted: #9aa0a8; --line: #2c3036; --soft: #262a2f;
  --accent: #5fb39b; --accent-ink: #0d1412; --shadow: none; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #15171a; --card: #1e2125; --ink: #eceef0; --muted: #9aa0a8; --line: #2c3036; --soft: #262a2f;
  --accent: #5fb39b; --accent-ink: #0d1412; --shadow: none; color-scheme: dark;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 16px/1.4 var(--font); -webkit-tap-highlight-color: transparent; }
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3, h4 { margin: 0; letter-spacing: -.01em; }
.muted { color: var(--muted); }
.grow { flex: 1; min-width: 0; }
[hidden] { display: none !important; }

/* ---------- buttons & inputs */
.btn { appearance: none; border: 1px solid var(--line); background: var(--card); border-radius: 999px; padding: .55em 1em; min-height: 44px; cursor: pointer; font-weight: 600; display: inline-flex; align-items: center; justify-content: center; gap: .3em; text-decoration: none; white-space: nowrap; touch-action: manipulation; }
.btn:active { transform: scale(.97); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.small { min-height: 38px; padding: .35em .85em; font-size: .9em; }
.btn.big { min-height: 56px; font-size: 1.1em; }
.btn.icon { width: 44px; padding: 0; font-size: 1.25em; }
.btn.danger { color: var(--danger); }
.btn:disabled { opacity: .5; }
.linkish { background: none; border: 0; padding: .2em .3em; color: var(--accent); font-weight: 600; cursor: pointer; }
input:not([type=checkbox]):not([type=color]), select, textarea {
  width: 100%; border: 1px solid var(--line); background: var(--bg); border-radius: 12px; padding: .65em .8em; min-height: 46px; outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 20%, transparent); }
textarea { resize: none; }
label { display: grid; gap: .3em; font-size: .9em; font-weight: 600; color: var(--muted); }
label > input, label > select, label > textarea { color: var(--ink); font-weight: 400; font-size: 1.06rem; }
label.check { display: flex; align-items: center; gap: .6em; color: var(--ink); }
label.check input { width: 22px; height: 22px; accent-color: var(--accent); }
.lbl { margin: .2em 0 -.2em; font-size: .9em; font-weight: 600; color: var(--muted); }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: .8em; }
.stack { display: grid; gap: .8em; }
.badge { margin-left: .5em; font-size: .72em; padding: .1em .55em; border-radius: 999px; background: var(--soft); color: var(--muted); font-weight: 700; vertical-align: middle; }
.bad { color: var(--danger); }

/* ---------- avatars */
.avatar { --c: #888; display: inline-grid; place-items: center; width: 40px; height: 40px; flex: none; border-radius: 50%; background: color-mix(in srgb, var(--c) 18%, var(--card)); box-shadow: inset 0 0 0 2.5px var(--c); font-size: 1.25em; line-height: 1; }
.avatar.sm { width: 30px; height: 30px; font-size: 1em; box-shadow: inset 0 0 0 2px var(--c); }
.avatar.xs { width: 22px; height: 22px; font-size: .75em; box-shadow: inset 0 0 0 1.5px var(--c); }

/* ---------- header */
.top { display: flex; align-items: center; gap: 1rem; padding: calc(10px + env(safe-area-inset-top)) 16px 10px; }
.brand { min-width: 0; }
.brand h1 { font-size: 1.35rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand p { margin: 0; font-size: .9rem; }
.clock { display: none; font-size: 2.6rem; font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: -.03em; }
.people { display: none; gap: .5rem; flex-wrap: wrap; }
.person { display: flex; align-items: center; gap: .45rem; background: var(--card); border-radius: 999px; padding: 4px 12px 4px 4px; box-shadow: var(--shadow); }
.pname { font-weight: 700; }
.stars { color: #b7791f; font-weight: 700; font-size: .9em; }
.top-actions { margin-left: auto; display: flex; gap: .5rem; }
#btnAddEvent { display: none; }

/* ---------- panels */
#board { padding: 0 16px calc(88px + env(safe-area-inset-bottom)); }
.panel { display: none; background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px; }
body[data-view=calendar] #p-calendar, body[data-view=chores] #p-chores, body[data-view=shopping] #p-shopping,
body[data-view=meals] #p-meals, body[data-view=notes] #p-notes, body[data-view=settings] #p-settings { display: block; }
.panel-head { display: flex; align-items: center; gap: .5rem; margin-bottom: 10px; flex-wrap: wrap; }
.panel-head h2 { font-size: 1.25rem; margin-right: auto; }
@media (max-width: 1099px) { #p-calendar .panel-head h2, #p-chores .panel-head h2, #p-meals .panel-head h2 { flex-basis: 100%; } #p-calendar .panel-head .seg, #p-chores .panel-head .seg, #p-meals .panel-head .seg { margin-right: auto; } }
.seg { display: flex; align-items: center; background: var(--soft); border-radius: 999px; }
.seg .btn { min-height: 36px; padding: .2em .75em; }
.count { background: var(--accent); color: var(--accent-ink); border-radius: 999px; padding: 0 .55em; font-weight: 700; font-size: .85em; }
.count:empty { display: none; }
.empty { color: var(--muted); margin: .4em 0; font-size: .95em; }
.empty.big { text-align: center; padding: 1.5em 0; font-size: 1.05em; }
.notice { background: var(--soft); border-radius: 12px; padding: .6em .8em; margin-bottom: 10px; font-size: .95em; }
.notice.warn { color: var(--warn); }

/* ---------- events */
.ev { --c: #4f7cff; display: grid; grid-template-columns: auto 1fr; column-gap: .55em; align-items: baseline; padding: .45em .6em; border-radius: 10px; background: color-mix(in srgb, var(--c) 12%, var(--card)); border-left: 4px solid var(--c); margin-bottom: 6px; }
.ev.allday { background: var(--c); color: #fff; border-left-color: transparent; }
.ev.allday .ev-time { color: rgba(255, 255, 255, .85); }
.ev-time { font-size: .8em; font-weight: 700; color: var(--muted); font-variant-numeric: tabular-nums; }
.ev-title { font-weight: 600; overflow-wrap: anywhere; }
.ev-loc { grid-column: 2; font-size: .8em; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ev.allday .ev-loc { color: rgba(255, 255, 255, .85); }

/* agenda (phones) */
.agenda { display: grid; gap: 14px; }
.aday-head { display: flex; align-items: baseline; gap: .5em; margin-bottom: 6px; }
.aday.is-today .aday-head strong { color: var(--accent); }
.meal-chip { margin-left: auto; border: 0; background: var(--soft); border-radius: 999px; padding: .25em .7em; font-size: .85em; cursor: pointer; max-width: 55%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.meal-chip.none { color: var(--muted); }

/* week grid (family screen) */
.week { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 8px; flex: 1; min-height: 0; }
.day { display: flex; flex-direction: column; background: var(--bg); border-radius: 14px; padding: 8px; min-height: 0; }
.day.is-today { background: color-mix(in srgb, var(--accent) 10%, var(--card)); box-shadow: inset 0 0 0 2px var(--accent); }
.day.is-past { opacity: .6; }
.day-head { display: flex; align-items: baseline; gap: .35em; padding: 2px 4px 8px; }
.dow { font-weight: 700; text-transform: uppercase; font-size: .78em; letter-spacing: .06em; color: var(--muted); }
.dnum { font-size: 1.6em; font-weight: 800; }
.is-today .dnum, .is-today .dow { color: var(--accent); }
.day-events { flex: 1; overflow-y: auto; min-height: 0; }
.day .ev { grid-template-columns: 1fr; font-size: .92em; }
.day .ev-loc { grid-column: 1; }
.meal { margin-top: 6px; display: flex; gap: .4em; align-items: center; border: 1px dashed var(--line); background: var(--card); border-radius: 10px; padding: .45em .55em; text-align: left; cursor: pointer; font-weight: 600; font-size: .9em; min-height: 44px; }
.meal.none { color: var(--muted); font-weight: 400; }

/* ---------- chores */
.chore-groups { display: grid; gap: 12px; }
.cgroup { --c: #888; }
.cgroup-head { display: flex; align-items: center; gap: .5em; margin-bottom: 4px; }
.bar { flex: 1; height: 6px; background: var(--soft); border-radius: 9px; overflow: hidden; margin-left: .4em; }
.bar i { display: block; height: 100%; background: var(--c); border-radius: 9px; transition: width .3s; }
.chore { display: flex; align-items: center; gap: .5em; padding: 4px 0; }
.tick { flex: none; width: 40px; height: 40px; border-radius: 50%; border: 2.5px solid var(--c, var(--accent)); background: transparent; color: #fff; font-weight: 800; font-size: 1.1em; cursor: pointer; display: grid; place-items: center; transition: background .15s; }
.done .tick { background: var(--c, var(--accent)); }
.tick.sq { width: 34px; height: 34px; border-radius: 10px; --c: var(--accent); }
.chore-title { flex: 1; text-align: left; background: none; border: 0; padding: .4em 0; font-weight: 600; cursor: pointer; min-height: 44px; }
.chore-title small { color: var(--muted); font-weight: 500; }
.chore-title em { color: var(--danger); font-style: normal; font-size: .85em; }
.done .chore-title { color: var(--muted); text-decoration: line-through; }
.cstars { color: #d69e2e; letter-spacing: -.1em; }
.more { width: 40px; height: 40px; border: 0; background: none; color: var(--muted); font-size: 1.2em; cursor: pointer; border-radius: 50%; }
.burst { position: fixed; left: 50%; top: 45%; font-size: 5rem; pointer-events: none; animation: burst .9s ease-out forwards; z-index: 50; }
@keyframes burst { 0% { transform: translate(-50%, -50%) scale(.3); opacity: 0; } 30% { opacity: 1; transform: translate(-50%, -50%) scale(1.2); } 100% { transform: translate(-50%, -120%) scale(1); opacity: 0; } }

/* ---------- lists */
.add-row { display: flex; gap: .5em; margin-bottom: 10px; align-items: flex-end; }
.add-row .btn { flex: none; }
.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; align-items: center; gap: .65em; padding: 6px 0; border-bottom: 1px solid var(--line); }
.list li:last-child { border-bottom: 0; }
.list li.done .grow { color: var(--muted); text-decoration: line-through; }
.list li.done .tick { background: var(--accent); }
.x { border: 0; background: none; color: var(--muted); width: 40px; height: 40px; cursor: pointer; border-radius: 50%; }

.meals { display: grid; gap: 8px; }
.meal-row { display: grid; grid-template-columns: 80px 1fr; align-items: center; gap: .6em; }
.meal-row.is-today span { color: var(--accent); }

.notes { display: grid; gap: 10px; }
.note { --c: #888; background: color-mix(in srgb, var(--c) 9%, var(--card)); border-radius: 14px; padding: .7em .85em; border-top: 4px solid var(--c); }
.note.pinned { box-shadow: inset 0 0 0 2px var(--c); }
.note p { margin: 0 0 .5em; white-space: pre-wrap; overflow-wrap: anywhere; font-size: 1.05em; }
.note footer { display: flex; align-items: center; gap: .45em; font-size: .85em; flex-wrap: wrap; }

/* ---------- settings */
.sset { border-top: 1px solid var(--line); padding: 14px 0 6px; }
.sset h3 { font-size: 1.05rem; margin-bottom: 10px; }
.sset h4 { font-size: .95rem; margin-top: 6px; }
.srow { display: flex; align-items: center; gap: .6em; flex-wrap: wrap; }
.copyline { display: flex; gap: .5em; align-items: center; background: var(--soft); border-radius: 10px; padding: .5em .7em; }
.copyline code { flex: 1; overflow-wrap: anywhere; font-size: .88em; }
.cals { display: grid; gap: 6px; }
.cal { display: flex; align-items: center; gap: .7em; color: var(--ink); font-weight: 600; }
.cal input[type=checkbox] { width: 24px; height: 24px; accent-color: var(--accent); }
.cal input[type=color] { width: 36px; height: 36px; border: 0; background: none; padding: 0; }
.swatches, .emojis { display: flex; flex-wrap: wrap; gap: 8px; }
.sw { width: 40px; height: 40px; border-radius: 50%; border: 3px solid var(--card); background: var(--c); box-shadow: 0 0 0 1px var(--line); cursor: pointer; }
.sw.on { box-shadow: 0 0 0 3px var(--ink); }
.em { width: 46px; height: 46px; border-radius: 12px; border: 1px solid var(--line); background: var(--card); font-size: 1.5em; cursor: pointer; }
.em.on { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent); }
.code { font-size: 2.2rem; font-weight: 800; letter-spacing: .12em; text-align: center; margin: .2em 0; font-variant-numeric: tabular-nums; }
.row-btns { display: flex; gap: .5em; flex-wrap: wrap; }

/* ---------- modal */
.modal-wrap { position: fixed; inset: 0; background: rgba(20, 18, 14, .45); display: grid; place-items: end center; z-index: 40; animation: fade .15s; }
.modal { width: min(560px, 100%); max-height: 92vh; overflow: auto; background: var(--card); border-radius: 22px 22px 0 0; padding: 18px 18px calc(18px + env(safe-area-inset-bottom)); animation: rise .2s ease-out; }
.modal h2 { font-size: 1.25rem; margin-bottom: 12px; }
.modal-body { display: grid; gap: 12px; }
.modal-body p { margin: 0; }
.modal-foot { display: flex; gap: .5em; justify-content: flex-end; flex-wrap: wrap; margin-top: 4px; }
.modal-foot .danger { margin-right: auto; }
@keyframes fade { from { opacity: 0; } }
@keyframes rise { from { transform: translateY(30px); opacity: 0; } }

/* PIN pad */
.who { display: flex; gap: .5em; flex-wrap: wrap; justify-content: center; }
.whob { display: flex; align-items: center; gap: .4em; border: 1px solid var(--line); background: var(--card); border-radius: 999px; padding: 4px 12px 4px 4px; font-weight: 600; cursor: pointer; }
.whob.on { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent); }
.pindots { display: flex; gap: 14px; justify-content: center; padding: .4em 0; }
.pindots i { width: 16px; height: 16px; border-radius: 50%; border: 2px solid var(--ink); }
.pindots i.on { background: var(--ink); }
.pindots.shake { animation: shake .35s; }
@keyframes shake { 25% { transform: translateX(-8px); } 75% { transform: translateX(8px); } }
.pinpad { display: grid; grid-template-columns: repeat(3, 84px); gap: 12px; justify-content: center; }
.pinpad button { height: 72px; border-radius: 18px; border: 1px solid var(--line); background: var(--bg); font-size: 1.6rem; font-weight: 700; cursor: pointer; }
.pinpad button:active { background: var(--soft); }
.pinpad .ok { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-size: 1.2rem; }

/* setup */
.setup { position: fixed; inset: 0; z-index: 30; background: var(--bg); overflow: auto; display: grid; place-items: center; padding: 20px; }
.setup-card { width: min(620px, 100%); background: var(--card); border-radius: 24px; padding: 28px; box-shadow: var(--shadow); display: grid; gap: 14px; }
.setup-card h1 { font-size: 2rem; }

/* ---------- phone tabs */
.tabs { position: fixed; left: 0; right: 0; bottom: 0; display: grid; grid-template-columns: repeat(5, 1fr); background: color-mix(in srgb, var(--card) 92%, transparent); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); z-index: 20; }
.tabs button { border: 0; background: none; padding: 8px 0 6px; display: grid; justify-items: center; gap: 2px; font-size: .72rem; font-weight: 600; color: var(--muted); cursor: pointer; }
.tabs button span { font-size: 1.35rem; filter: grayscale(1); opacity: .7; }
.tabs button.on { color: var(--accent); }
.tabs button.on span { filter: none; opacity: 1; }

/* ---------- toast */
.toast { position: fixed; left: 50%; bottom: calc(96px + env(safe-area-inset-bottom)); transform: translate(-50%, 20px); background: var(--ink); color: var(--bg); padding: .6em 1.1em; border-radius: 999px; font-weight: 600; opacity: 0; pointer-events: none; transition: .2s; z-index: 60; max-width: 90vw; text-align: center; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.bad { background: var(--danger); color: #fff; }

/* ---------- on-screen keyboard (family screen) */
.kbd { position: fixed; left: 0; right: 0; bottom: 0; z-index: 70; background: #d6d1c8; padding: 8px 8px 12px; display: grid; gap: 8px; box-shadow: 0 -6px 24px rgba(0, 0, 0, .15); user-select: none; }
.krow { display: flex; gap: 8px; justify-content: center; }
.key { flex: 1; max-width: 120px; height: 66px; border: 0; border-radius: 12px; background: #fffdf9; color: #1d2125; font-size: 1.6rem; font-weight: 600; box-shadow: 0 2px 0 rgba(0, 0, 0, .18); cursor: pointer; }
.key.mod { background: #b9b3a8; font-size: 1.2rem; }
.key.on { background: #1d2125; color: #fff; }
.key.space { flex: 5; max-width: 600px; font-size: 1rem; }
.key:active { transform: translateY(2px); box-shadow: none; }
body.kbd-open { padding-bottom: 380px; }
body.kbd-open .modal-wrap { place-items: start center; padding-top: 2vh; }
body.kbd-open .modal { max-height: calc(100vh - 420px); }
body.kbd-open .setup { place-items: start center; padding-bottom: 420px; }

/* ---------- night dimming */
.night { position: fixed; inset: 0; z-index: 80; background: rgba(0, 0, 0, .82); display: none; place-items: end center; padding-bottom: 4vh; color: rgba(255, 255, 255, .35); font-size: 1.1rem; }
body.night .night { display: grid; }

/* ======================================================= family screen / wide layout */
@media (min-width: 1100px) {
  html { font-size: clamp(16px, .95vw, 21px); }
  body { font-size: 1rem; height: 100vh; overflow: hidden; display: grid; grid-template-rows: auto minmax(0, 1fr); }
  body.kbd-open { overflow: auto; height: auto; }
  .top { padding: 14px 20px 10px; gap: 1.5rem; }
  .brand h1 { font-size: 1.6rem; }
  .clock, .people { display: flex; }
  #btnAddEvent { display: inline-flex; }
  .tabs { display: none; }
  #board { padding: 0 20px 20px; display: grid; gap: 16px; min-height: 0;
    grid-template-columns: minmax(0, 2.5fr) minmax(320px, 1fr); grid-template-rows: minmax(0, 1.25fr) minmax(0, 1fr) minmax(0, .9fr); }
  .panel { display: flex !important; flex-direction: column; min-height: 0; overflow: hidden; }
  .panel > :not(.panel-head):not(.add-row):not(.notice) { overflow-y: auto; min-height: 0; }
  #p-calendar { grid-column: 1; grid-row: 1 / 4; }
  #p-chores { grid-column: 2; grid-row: 1; }
  #p-shopping { grid-column: 2; grid-row: 2; }
  #p-notes { grid-column: 2; grid-row: 3; }
  #p-meals { display: none !important; }
  #p-settings { display: none !important; }
  body[data-view=settings] #p-settings { display: flex !important; position: fixed; z-index: 35; top: 4vh; bottom: 4vh; left: 50%; transform: translateX(-50%); width: min(760px, 92vw); overflow-y: auto; box-shadow: 0 30px 80px rgba(0, 0, 0, .3); }
  body[data-view=settings] #p-settings > * { flex: none; }
  body.kbd-open[data-view=settings] #p-settings { top: 2vh; bottom: 400px; }
  body[data-view=settings]::after { content: ""; position: fixed; inset: 0; background: rgba(20, 18, 14, .45); z-index: 34; }
  .modal-wrap { place-items: center; }
  .modal { border-radius: 22px; padding: 24px; }
  .notes { grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); align-content: start; }
  .add-row textarea { min-height: 46px; }
  .toast { bottom: 30px; }
}
