@font-face {
  font-family: "Young Serif";
  src: url("fonts/youngserif-latin-ext.woff2") format("woff2");
  font-weight: 400;
  font-display: swap;
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C4, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
  font-family: "Young Serif";
  src: url("fonts/youngserif-latin.woff2") format("woff2");
  font-weight: 400;
  font-display: swap;
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

:root {
  color-scheme: light dark;
  --bg: oklch(97.2% 0.012 75);
  --surface: oklch(99.3% 0.005 75);
  --ink: oklch(27% 0.03 25);
  --ink-2: oklch(47% 0.028 35);
  --ink-3: oklch(62% 0.022 45);
  --line: oklch(90.5% 0.014 70);
  --accent: oklch(56% 0.11 32);
  --accent-ink: oklch(99% 0.01 60);
  --accent-soft: oklch(93% 0.03 40);
  --dawn: oklch(66% 0.12 65);
  --noon: oklch(62% 0.1 105);
  --dusk: oklch(56% 0.1 290);
  --danger: oklch(52% 0.16 25);
  --shadow: 0 10px 30px -12px oklch(30% 0.04 30 / 0.25);
  --radius: 14px;
  --serif: "Young Serif", Georgia, "Times New Roman", serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --ease: cubic-bezier(0.16, 1, 0.3, 1);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: oklch(20.5% 0.014 35);
    --surface: oklch(24.5% 0.016 35);
    --ink: oklch(93% 0.012 70);
    --ink-2: oklch(76% 0.02 60);
    --ink-3: oklch(62% 0.02 55);
    --line: oklch(32% 0.018 35);
    --accent: oklch(72% 0.1 35);
    --accent-ink: oklch(20% 0.02 35);
    --accent-soft: oklch(31% 0.04 35);
    --dawn: oklch(78% 0.11 70);
    --noon: oklch(78% 0.09 105);
    --dusk: oklch(74% 0.09 290);
    --danger: oklch(70% 0.14 25);
    --shadow: 0 10px 30px -12px oklch(0% 0 0 / 0.6);
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 400 17px/1.45 var(--sans);
  -webkit-tap-highlight-color: transparent;
  caret-color: var(--accent);
}
::selection { background: var(--accent-soft); color: var(--ink); }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 8px; }

.ic {
  width: 20px; height: 20px; flex: none;
  fill: none; stroke: currentColor; stroke-width: 1.8;
  stroke-linecap: round; stroke-linejoin: round;
}

.app {
  max-width: 560px;
  margin: 0 auto;
  padding: max(20px, env(safe-area-inset-top)) 16px calc(40px + env(safe-area-inset-bottom));
}

/* Header */
.top { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; padding: 8px 4px 0; }
.day {
  margin: 0;
  font: 400 34px/1.1 var(--serif);
  letter-spacing: -0.02em;
  text-wrap: balance;
}
.day-btn {
  display: block; margin: 0 0 0 -8px; padding: 2px 8px 4px; border: 0; border-radius: 12px;
  background: transparent; font: inherit; letter-spacing: inherit; text-align: left;
}
.day-btn:active { background: var(--accent-soft); }
.day small { display: flex; align-items: center; gap: 6px; font: 400 17px/1.4 var(--sans); letter-spacing: 0; color: var(--ink-2); margin-top: 4px; }
.day small .ic { width: 16px; height: 16px; color: var(--ink-3); }
.summary { margin: 10px 0 0; color: var(--ink-2); font-size: 15px; font-variant-numeric: tabular-nums; }
.summary strong { color: var(--ink); font-weight: 600; }

.mode-btn {
  display: inline-flex; align-items: center; gap: 6px;
  min-height: 40px; padding: 0 14px 0 12px; margin-top: 4px;
  border: 1px solid var(--line); border-radius: 999px;
  background: var(--surface); color: var(--ink-2); font-size: 15px;
  transition: background 0.2s, color 0.2s, border-color 0.2s;
}
.mode-btn .ic { width: 18px; height: 18px; }
.top-actions { display: flex; gap: 8px; flex: none; }
.mode-btn.round { width: 40px; padding: 0; justify-content: center; }
.mode-btn.round .ic { width: 20px; height: 20px; }
.mode-btn[hidden] { display: none; }
.mode-btn[aria-pressed="true"] { background: var(--ink); color: var(--bg); border-color: var(--ink); }

/* People switcher */
.people {
  display: flex; gap: 8px; margin: 18px -16px -6px; padding: 4px 16px 16px;
  overflow-x: auto; scrollbar-width: none;
}
.people::-webkit-scrollbar { display: none; }
.person {
  flex: none; display: inline-flex; align-items: center; gap: 8px;
  min-height: 42px; padding: 0 16px;
  border: 1px solid var(--line); border-radius: 999px;
  background: transparent; color: var(--ink-2); font-size: 16px;
  transition: background 0.2s, color 0.2s, border-color 0.2s;
}
.person .count { font-size: 13px; color: var(--ink-3); font-variant-numeric: tabular-nums; }
.person[aria-selected="true"] { background: var(--surface); color: var(--ink); border-color: var(--ink-3); font-weight: 600; box-shadow: var(--shadow); }
.person[aria-selected="true"] .count { color: var(--ink-2); font-weight: 400; }
.person.add { color: var(--ink-3); padding: 0 14px; border-style: dashed; }

/* Periods */
.period { margin-top: 26px; }
.period-head { display: flex; align-items: center; gap: 10px; padding: 0 4px 10px; }
.period-head h2 { margin: 0; font: 400 22px/1.2 var(--serif); letter-spacing: -0.01em; }
.period-head .ic { width: 22px; height: 22px; }
.period[data-period="morning"] .period-head .ic { color: var(--dawn); }
.period[data-period="afternoon"] .period-head .ic { color: var(--noon); }
.period[data-period="evening"] .period-head .ic { color: var(--dusk); }
.period-head .now {
  font-size: 12px; font-weight: 600; letter-spacing: 0.02em;
  color: var(--accent); background: var(--accent-soft);
  padding: 2px 8px; border-radius: 999px;
}
.period-head .tally { margin-left: auto; font-size: 14px; color: var(--ink-3); font-variant-numeric: tabular-nums; }
.period.complete .period-head h2 { color: var(--ink-2); }

.list {
  list-style: none; margin: 0; padding: 0;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  overflow: hidden;
}
.list li + li { border-top: 1px solid var(--line); }
.who { margin: 14px 4px 8px; font-size: 14px; font-weight: 600; color: var(--ink-2); }
.period-head + .who { margin-top: 2px; }
.tag {
  flex: none; margin-left: auto; padding: 2px 8px; border-radius: 999px;
  border: 1px solid var(--line); color: var(--ink-3); font-size: 12px; white-space: nowrap;
}
.tag.late {
  display: inline-flex; align-items: center; gap: 4px; padding-left: 5px;
  border-color: transparent; background: color-mix(in oklch, var(--danger) 14%, transparent);
  color: var(--danger); font-weight: 600;
}
.tag.late .ic { width: 15px; height: 15px; stroke-width: 2.2; }
.edit-row .name { display: flex; align-items: center; gap: 8px; }
.empty-period {
  margin: 0; padding: 14px 16px; border: 1px dashed var(--line); border-radius: var(--radius);
  color: var(--ink-3); font-size: 15px;
}

/* Task row (today mode) */
.task {
  display: flex; align-items: center; gap: 14px; width: 100%;
  min-height: 58px; padding: 12px 16px;
  border: 0; background: transparent; text-align: left;
}
.task:active { background: var(--accent-soft); }
.box {
  flex: none; display: grid; place-items: center;
  width: 28px; height: 28px; border-radius: 50%;
  border: 1.8px solid var(--ink-3);
  transition: background 0.25s var(--ease), border-color 0.25s var(--ease), transform 0.35s var(--ease);
}
.box .ic { width: 18px; height: 18px; stroke-width: 2.4; color: var(--accent-ink); stroke-dasharray: 20; stroke-dashoffset: 20; transition: stroke-dashoffset 0.35s var(--ease) 0.05s; }
.task .label { flex: 1; min-width: 0; overflow-wrap: anywhere; transition: color 0.25s; }
.task[aria-checked="true"] .box { background: var(--accent); border-color: var(--accent); }
.task[aria-checked="true"] .box .ic { stroke-dashoffset: 0; }
.task[aria-checked="true"] .label { color: var(--ink-3); text-decoration: line-through; text-decoration-thickness: 1px; text-decoration-color: var(--ink-3); }
.task.just-checked .box { animation: pop 0.45s var(--ease); }
@keyframes pop { 0% { transform: scale(0.82); } 100% { transform: scale(1); } }

/* Plan (edit) mode */
.edit-row { display: flex; align-items: center; gap: 4px; min-height: 58px; padding: 6px 6px 6px 4px; }
.edit-row .name {
  flex: 1; min-width: 0; min-height: 46px; padding: 0 12px;
  border: 0; background: transparent; text-align: left; overflow-wrap: anywhere;
  border-radius: 10px;
}
.edit-row .name:active { background: var(--accent-soft); }
.icon-btn {
  flex: none; display: grid; place-items: center;
  width: 44px; height: 44px; border: 0; border-radius: 12px;
  background: transparent; color: var(--ink-2);
}
.icon-btn:active { background: var(--accent-soft); }
.icon-btn:disabled { color: var(--line); cursor: default; }
.add-btn {
  display: flex; align-items: center; gap: 10px; width: 100%;
  min-height: 52px; margin-top: 8px; padding: 0 16px;
  border: 1px dashed var(--ink-3); border-radius: var(--radius);
  background: transparent; color: var(--ink-2); font-size: 16px;
}
.add-btn:active { background: var(--accent-soft); }
.plan-note { margin: 18px 4px 0; color: var(--ink-2); font-size: 15px; }
.person-tools { display: flex; gap: 8px; margin-top: 30px; }
.text-btn {
  min-height: 44px; padding: 0 14px; border: 1px solid var(--line); border-radius: 999px;
  background: transparent; color: var(--ink-2); font-size: 15px;
}

/* Backup */
.backup { margin-top: 40px; padding-top: 22px; border-top: 1px solid var(--line); }
.backup h2 { margin: 0 4px 6px; font: 400 20px/1.25 var(--serif); }
.backup p { margin: 0 4px 14px; color: var(--ink-2); font-size: 15px; max-width: 60ch; }
.backup-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.sheet-text { margin: 0 0 14px; color: var(--ink-2); }

/* Empty state */
.empty {
  margin-top: 40px; padding: 28px 20px; text-align: center;
  border: 1px dashed var(--line); border-radius: var(--radius);
}
.empty h2 { margin: 0 0 6px; font: 400 22px/1.25 var(--serif); }
.empty p { margin: 0 0 18px; color: var(--ink-2); }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 50px; padding: 0 22px; border-radius: 999px;
  border: 1px solid transparent; font-size: 16px; font-weight: 600;
}
.btn.primary { background: var(--ink); color: var(--bg); }
.btn.ghost { background: transparent; color: var(--ink-2); border-color: var(--line); font-weight: 500; }
.btn.danger { background: transparent; color: var(--danger); border-color: transparent; font-weight: 500; padding: 0 12px; }
.btn.danger.armed { background: var(--danger); color: var(--surface); }

/* Bottom sheet */
.sheet {
  width: 100%; max-width: 560px; margin: auto auto 0; padding: 0;
  border: 0; border-radius: 22px 22px 0 0;
  background: var(--surface); color: var(--ink);
  box-shadow: 0 -10px 40px -10px oklch(20% 0.03 30 / 0.35);
}
.sheet::backdrop { background: oklch(20% 0.02 30 / 0.35); backdrop-filter: blur(2px); }
.sheet[open] { animation: rise 0.4s var(--ease); }
@keyframes rise { from { transform: translateY(40px); opacity: 0; } to { transform: none; opacity: 1; } }
.sheet-body { padding: 22px 18px calc(18px + env(safe-area-inset-bottom)); }
.sheet h2 { margin: 0 0 18px; font: 400 24px/1.2 var(--serif); }
.field { display: block; margin-bottom: 18px; }
.field > span { display: block; margin-bottom: 8px; font-size: 14px; color: var(--ink-2); }
.input, .select {
  width: 100%; min-height: 52px; padding: 0 14px;
  border: 1px solid var(--line); border-radius: 12px; background: var(--bg);
  font-size: 17px;
}
.input:focus, .select:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: transparent; }
.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chip { position: relative; }
.chip input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.chip span {
  display: inline-flex; align-items: center; gap: 6px;
  min-height: 44px; padding: 0 14px; border-radius: 999px;
  border: 1px solid var(--line); color: var(--ink-2); font-size: 15px;
}
.chip span .ic { width: 18px; height: 18px; }
.chip input:checked + span { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.chip input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }
.days-field .chips { gap: 6px; }
.days-field .chip span { min-width: 44px; padding: 0 10px; justify-content: center; }
.hint { margin: -8px 0 18px; font-size: 14px; color: var(--ink-3); }
.error { margin: -8px 0 14px; font-size: 14px; color: var(--danger); }
.sheet-actions { display: flex; align-items: center; gap: 10px; margin-top: 6px; }
.sheet-actions .spacer { flex: 1; }

/* History sheet */
.sheet { max-height: 90dvh; }
.cal-top { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; }
.cal-top h2 { margin: 0; }
.btn.small { min-height: 40px; padding: 0 16px; font-size: 15px; }
.cal-nav { display: flex; align-items: center; justify-content: space-between; margin: 6px -6px 6px; }
.cal-month { font-weight: 600; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; text-align: center; }
.cal-wd { padding: 4px 0 6px; font-size: 12px; color: var(--ink-3); }
.cal-day {
  position: relative; display: grid; place-items: center; height: 44px;
  border: 0; border-radius: 12px; background: transparent;
  font-size: 16px; font-variant-numeric: tabular-nums; color: var(--ink);
}
button.cal-day:active { background: var(--accent-soft); }
.cal-day.off { color: var(--ink-3); opacity: 0.55; }
.cal-day.is-today { box-shadow: inset 0 0 0 1px var(--ink-3); }
.cal-day.is-selected { background: var(--ink); color: var(--bg); }
.dot {
  position: absolute; bottom: 5px; left: 50%; width: 6px; height: 6px; margin-left: -3px;
  border-radius: 50%; border: 1.5px solid var(--accent);
}
.dot.full { background: var(--accent); }
.cal-day.is-selected .dot { border-color: var(--bg); }
.cal-day.is-selected .dot.full { background: var(--bg); }
.cal-detail { margin-top: 18px; padding-top: 16px; border-top: 1px solid var(--line); }
.hint-block { margin: 0 0 8px; color: var(--ink-2); }
.hist-date { margin: 0; font: 400 20px/1.25 var(--serif); }
.hist-sum { margin: 4px 0 0; color: var(--ink-2); font-size: 15px; }
.hist-person .who { margin-top: 18px; }
.hist-period { margin: 10px 4px 4px; font-size: 13px; color: var(--ink-3); }
.hist-list { list-style: none; margin: 0; padding: 0; }
.hist-list li { display: flex; align-items: center; gap: 12px; min-height: 40px; padding: 0 4px; color: var(--ink-2); }
.hist-list .mark {
  flex: none; display: grid; place-items: center; width: 22px; height: 22px;
  border-radius: 50%; border: 1.6px solid var(--ink-3);
}
.hist-list .mark .ic { width: 14px; height: 14px; stroke-width: 2.6; color: var(--accent-ink); }
.hist-list li.is-done { color: var(--ink); }
.hist-list li.is-done .mark { background: var(--accent); border-color: var(--accent); }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

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