:root {
  --bg: #ffffff;
  --bg-soft: #f4f5f7;
  --bg-sheet: #ffffff;
  --text: #16181d;
  --text-2: #5d6370;
  --text-3: #9aa0ab;
  --line: #e7e8ec;
  --line-strong: #cfd2d8;
  --brand: #1E40AF;
  --brand-soft: #e8edfb;
  --on-brand: #ffffff;
  --flag: #d9480f;
  --flag-soft: #fff1e8;
  --danger: #c92a2a;
  --scrim: rgba(15, 18, 25, 0.35);
  --radius: 12px;
  --addbar-h: 64px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111214;
    --bg-soft: #1c1e22;
    --bg-sheet: #18191c;
    --text: #eceef2;
    --text-2: #a4a9b4;
    --text-3: #6b717c;
    --line: #2a2d33;
    --line-strong: #3a3e46;
    --brand: #6d8ef0;
    --brand-soft: #1d2640;
    --on-brand: #0d1220;
    --flag: #ff8a4c;
    --flag-soft: #3a2116;
    --danger: #ff6b6b;
    --scrim: rgba(0, 0, 0, 0.55);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
[hidden] { display: none !important; }
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
input, select, textarea { font: inherit; color: inherit; }
svg { display: block; }
h1 { font-size: 24px; font-weight: 650; margin: 0; letter-spacing: -0.01em; }
.muted { color: var(--text-2); margin: 6px 0 0; }

/* ---------- Lock and who screens ---------- */
.screen.center {
  min-height: 100%;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: calc(24px + var(--safe-t)) 24px calc(24px + var(--safe-b));
  text-align: center;
}
.brand { margin-bottom: 28px; }
.brand-mark {
  width: 64px; height: 64px; border-radius: 18px; margin: 0 auto 14px;
  background: var(--brand); color: var(--on-brand);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 22px; letter-spacing: 0.02em;
}
.dots { display: flex; gap: 18px; margin-bottom: 10px; }
.dots span { width: 14px; height: 14px; border-radius: 50%; border: 2px solid var(--line-strong); transition: all .12s; }
.dots span.on { background: var(--brand); border-color: var(--brand); }
.dots.shake { animation: shake .35s; }
@keyframes shake { 20%, 60% { transform: translateX(-8px); } 40%, 80% { transform: translateX(8px); } }
.error { color: var(--danger); min-height: 22px; margin: 4px 0 14px; font-size: 15px; }
.keypad { display: grid; grid-template-columns: repeat(3, 76px); gap: 16px; }
.keypad button {
  width: 76px; height: 76px; border-radius: 50%;
  background: var(--bg-soft); font-size: 28px; font-weight: 400;
  transition: background .1s, transform .1s;
}
.keypad button:active { background: var(--line-strong); transform: scale(0.96); }
.keypad .key-ghost { background: none; font-size: 24px; color: var(--text-2); }

.who-list { display: flex; flex-direction: column; gap: 10px; width: 100%; max-width: 340px; margin-bottom: 20px; }
.who-list button {
  padding: 15px 18px; border-radius: var(--radius); background: var(--bg-soft);
  font-size: 18px; font-weight: 500; text-align: left;
  display: flex; align-items: center; gap: 12px;
}
.who-list button:active { background: var(--line); }
.who-add { display: flex; gap: 8px; width: 100%; max-width: 340px; }
.who-add input { flex: 1; }

input[type=text], textarea, .field-select {
  border: 1px solid var(--line-strong); border-radius: 10px; background: var(--bg);
  padding: 11px 13px; font-size: 16px; outline: none; min-width: 0;
}
input[type=text]:focus, textarea:focus { border-color: var(--brand); }
.btn {
  border-radius: 10px; padding: 11px 16px; font-weight: 600;
  background: var(--brand); color: var(--on-brand);
}
.btn-quiet { background: var(--bg-soft); color: var(--text); font-weight: 500; }
.btn-danger { background: none; color: var(--danger); font-weight: 500; }

.initial {
  width: 34px; height: 34px; border-radius: 50%; flex: none;
  background: var(--brand-soft); color: var(--brand);
  display: inline-flex; align-items: center; justify-content: center;
  font-weight: 650; font-size: 14px;
}

/* ---------- Main list ---------- */
#main { min-height: 100%; }
.topbar {
  position: sticky; top: 0; z-index: 5;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: saturate(180%) blur(12px); -webkit-backdrop-filter: saturate(180%) blur(12px);
  padding: calc(10px + var(--safe-t)) 16px 10px;
  border-bottom: 1px solid var(--line);
}
.topbar-row, .progress-row { max-width: 760px; margin: 0 auto; }
.topbar-row { display: flex; align-items: center; gap: 4px; }
.icon-btn { width: 38px; height: 38px; border-radius: 50%; display: flex; align-items: center; justify-content: center; color: var(--text-2); }
.icon-btn:active { background: var(--bg-soft); }
.day-title { flex: 1; text-align: left; padding: 2px 6px; min-width: 0; }
#day-name { display: block; font-size: 26px; font-weight: 700; letter-spacing: -0.02em; line-height: 1.15; }
.day-sub { display: block; font-size: 13px; color: var(--text-2); }
.avatar { margin-left: 6px; }
.avatar .initial { width: 36px; height: 36px; }
.progress-row { display: flex; align-items: center; gap: 10px; margin-top: 8px; }
.progress { flex: 1; height: 5px; border-radius: 3px; background: var(--bg-soft); overflow: hidden; }
.progress-fill { height: 100%; width: 0; background: var(--brand); border-radius: 3px; transition: width .3s; }
.progress-label { font-size: 13px; color: var(--text-2); font-variant-numeric: tabular-nums; min-width: 72px; text-align: right; }

.list {
  max-width: 760px; margin: 0 auto;
  padding: 6px 16px calc(var(--addbar-h) + 140px + var(--safe-b));
}
.section-head {
  display: flex; align-items: baseline; justify-content: space-between;
  font-size: 13px; font-weight: 650; color: var(--text-2);
  text-transform: uppercase; letter-spacing: 0.06em;
  padding: 20px 2px 6px;
}
.section-head .count { font-weight: 500; letter-spacing: 0; text-transform: none; color: var(--text-3); }
.item {
  display: flex; align-items: flex-start; gap: 12px;
  padding: 11px 2px; border-bottom: 1px solid var(--line);
  cursor: pointer;
}
.item:active { background: var(--bg-soft); }
.item.selected { background: var(--brand-soft); border-radius: 8px; }
.check {
  flex: none; width: 26px; height: 26px; margin-top: -1px;
  border-radius: 50%; border: 2px solid var(--line-strong);
  display: flex; align-items: center; justify-content: center;
  color: transparent; transition: all .15s;
  position: relative;
}
.check::after { content: ""; position: absolute; inset: -10px; } /* bigger tap target */
.item.flagged .check { border-color: var(--flag); }
.check.done { background: var(--brand); border-color: var(--brand) !important; color: var(--on-brand); }
.check.pop { animation: pop .25s; }
@keyframes pop { 50% { transform: scale(1.18); } }
.item-body { flex: 1; min-width: 0; }
.item-title { font-size: 17px; line-height: 1.3; overflow-wrap: anywhere; }
.item.done .item-title { color: var(--text-3); text-decoration: line-through; text-decoration-color: var(--line-strong); }
.item-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 10px; margin-top: 3px; font-size: 13px; color: var(--text-2); }
.item-meta span { display: inline-flex; align-items: center; gap: 4px; }
.item-meta .flag { color: var(--flag); font-weight: 600; }
.item-meta .done-by { color: var(--brand); font-weight: 500; }
.item-meta .carried { color: var(--flag); }

.empty { text-align: center; color: var(--text-2); padding: 60px 20px; }
.empty-mark { width: 54px; height: 54px; margin: 0 auto 12px; border-radius: 50%; background: var(--brand-soft); color: var(--brand); display: flex; align-items: center; justify-content: center; }
.empty strong { display: block; color: var(--text); font-size: 18px; margin-bottom: 4px; }

/* ---------- Add bar ---------- */
.addbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 6;
  padding: 10px 16px calc(10px + var(--safe-b));
  background: color-mix(in srgb, var(--bg) 94%, transparent);
  backdrop-filter: saturate(180%) blur(12px); -webkit-backdrop-filter: saturate(180%) blur(12px);
  border-top: 1px solid var(--line);
}
.add-row, .add-options { max-width: 760px; margin: 0 auto; }
.add-row { display: flex; gap: 8px; align-items: center; }
.add-row input { flex: 1; border-radius: 22px; padding: 11px 16px; background: var(--bg-soft); border-color: transparent; }
.add-row input:focus { background: var(--bg); border-color: var(--brand); }
.add-send {
  width: 44px; height: 44px; border-radius: 50%; flex: none;
  background: var(--brand); color: var(--on-brand);
  display: flex; align-items: center; justify-content: center;
}
.add-options { display: none; flex-wrap: wrap; gap: 8px; margin-bottom: 10px; align-items: center; }
.addbar.open .add-options { display: flex; }
.add-toggles { display: flex; gap: 8px; flex-wrap: wrap; }

.seg { display: inline-flex; background: var(--bg-soft); border-radius: 10px; padding: 3px; }
.seg button { padding: 6px 12px; border-radius: 8px; font-size: 14px; font-weight: 500; color: var(--text-2); }
.seg button.on { background: var(--bg); color: var(--text); box-shadow: 0 1px 2px rgba(0,0,0,.12); }
@media (prefers-color-scheme: dark) { .seg button.on { background: var(--line-strong); } }

.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 12px; border-radius: 10px; font-size: 14px; font-weight: 500;
  background: var(--bg-soft); color: var(--text-2); position: relative;
}
.chip[aria-pressed=true] { background: var(--brand-soft); color: var(--brand); }
.chip.flag-chip[aria-pressed=true] { background: var(--flag-soft); color: var(--flag); }
#add-for-label { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.chip-select select { position: absolute; inset: 0; opacity: 0; width: 100%; cursor: pointer; font-size: 16px; }

/* ---------- Sheets (detail and settings) ---------- */
.scrim { position: fixed; inset: 0; background: var(--scrim); z-index: 10; }
.sheet {
  position: fixed; z-index: 11; background: var(--bg-sheet);
  left: 0; right: 0; bottom: 0; top: calc(var(--safe-t) + 36px);
  border-radius: 16px 16px 0 0;
  display: flex; flex-direction: column;
  box-shadow: 0 -8px 30px rgba(0,0,0,.15);
  animation: up .22s ease-out;
}
@keyframes up { from { transform: translateY(40px); opacity: .4; } }
@keyframes in { from { transform: translateX(40px); opacity: .4; } }
@media (min-width: 900px) {
  .sheet {
    left: auto; top: 0; width: 440px; border-radius: 0;
    border-left: 1px solid var(--line); box-shadow: -8px 0 30px rgba(0,0,0,.08);
    animation: in .2s ease-out;
  }
}
/* Wide iPad / desktop: the list slides over and stays tappable beside the detail panel. */
@media (min-width: 1100px) {
  body.detail-open #main { padding-right: 440px; }
  body.detail-open .addbar { right: 440px; }
}
.sheet-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 12px 8px 16px;
}
.sheet-head h2 { font-size: 17px; margin: 0; font-weight: 650; }
.sheet-body { flex: 1; overflow-y: auto; padding: 4px 18px calc(24px + var(--safe-b)); -webkit-overflow-scrolling: touch; }
.link-btn { color: var(--brand); font-weight: 600; padding: 8px 6px; }

.detail-title { display: flex; gap: 12px; align-items: flex-start; margin: 4px 0 18px; }
.detail-title .check { width: 30px; height: 30px; margin-top: 4px; }
.detail-title textarea {
  flex: 1; border: 0; padding: 4px 0; font-size: 21px; font-weight: 600; line-height: 1.3;
  resize: none; background: none; outline: none; overflow: hidden;
}
.field { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 11px 0; border-bottom: 1px solid var(--line); min-height: 52px; }
.field-label { color: var(--text-2); font-size: 15px; flex: none; }
.field-select { padding: 7px 10px; font-size: 16px; max-width: 60%; }
.weekdays { display: flex; gap: 5px; }
.weekdays button {
  width: 32px; height: 32px; border-radius: 50%; font-size: 13px; font-weight: 600;
  background: var(--bg-soft); color: var(--text-2);
}
.weekdays button.on { background: var(--brand); color: var(--on-brand); }
.repeat-wrap { display: flex; flex-direction: column; align-items: flex-end; gap: 8px; }
.repeat-hint { font-size: 12px; color: var(--text-3); }
.fine { font-size: 13px; color: var(--text-2); padding: 12px 0 0; line-height: 1.6; }

.notes-head { font-size: 13px; font-weight: 650; color: var(--text-2); text-transform: uppercase; letter-spacing: .06em; margin: 26px 0 10px; }
.note { background: var(--bg-soft); border-radius: 12px; padding: 10px 12px; margin-bottom: 8px; }
.note-meta { font-size: 12px; color: var(--text-2); display: flex; justify-content: space-between; align-items: center; margin-bottom: 2px; }
.note-meta button { color: var(--text-3); font-size: 12px; padding: 2px 4px; }
.note-body { white-space: pre-wrap; overflow-wrap: anywhere; }
.note-form { display: flex; gap: 8px; align-items: flex-end; margin-top: 6px; }
.note-form textarea { flex: 1; resize: none; min-height: 46px; max-height: 160px; }
.detail-actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 26px; }
.detail-actions .btn-quiet, .detail-actions .btn-danger { display: inline-flex; align-items: center; gap: 6px; padding: 10px 14px; border-radius: 10px; }

.settings-group { margin: 18px 0 6px; font-size: 13px; font-weight: 650; color: var(--text-2); text-transform: uppercase; letter-spacing: .06em; }
.row { display: flex; align-items: center; gap: 12px; padding: 11px 0; border-bottom: 1px solid var(--line); }
.row-main { flex: 1; min-width: 0; }
.row-sub { font-size: 13px; color: var(--text-2); }
.row button.small { font-size: 14px; color: var(--danger); padding: 6px 4px; }
.inline-form { display: flex; gap: 8px; margin-top: 10px; }
.inline-form input { flex: 1; }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%); z-index: 20;
  bottom: calc(var(--addbar-h) + 24px + var(--safe-b));
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 12px;
  font-size: 15px; max-width: calc(100% - 32px); display: flex; gap: 14px; align-items: center;
}
.toast button { color: var(--brand-soft); font-weight: 650; }
@media (prefers-color-scheme: dark) { .toast button { color: var(--brand); } }
.offline { position: fixed; top: calc(var(--safe-t) + 4px); left: 50%; transform: translateX(-50%); z-index: 30; background: var(--flag); color: #fff; font-size: 13px; padding: 4px 12px; border-radius: 10px; }
