:root, :root[data-theme="light"] {
    --bg: #f6f5f2; --card: #ffffff; --ink: #1d1d1f; --muted: #6e6e73; --line: #e4e2dd;
    --accent: #2f6fdf; --today: #e8f0fe; --late: #b3261e; --late-bg: #fdecea;
    --masha-bg: #f1e8fd; --masha-ink: #6a3fb5;
    --darya-bg: #e2f5f0; --darya-ink: #1f7a63;
    --dmitrii-bg: #e3edfb; --dmitrii-ink: #2457a6;
    --family-bg: #fdf1dc; --family-ink: #9a6206;
    --other-bg: #eeeeef; --other-ink: #55555a;
  }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
      --bg: #141416; --card: #1f1f22; --ink: #f2f2f4; --muted: #9a9aa2; --line: #2e2e33;
      --accent: #7aa7ff; --today: #1d2a44; --late: #ff8a80; --late-bg: #3a1f1d;
      --masha-bg: #2f2441; --masha-ink: #c9a8ff;
      --darya-bg: #17332c; --darya-ink: #7fd8bd;
      --dmitrii-bg: #1a2a45; --dmitrii-ink: #9cc0ff;
      --family-bg: #3a2d14; --family-ink: #f2c46d;
      --other-bg: #2a2a2e; --other-ink: #c4c4ca;
  }
}
:root[data-theme="dark"] {
      --bg: #141416; --card: #1f1f22; --ink: #f2f2f4; --muted: #9a9aa2; --line: #2e2e33;
      --accent: #7aa7ff; --today: #1d2a44; --late: #ff8a80; --late-bg: #3a1f1d;
      --masha-bg: #2f2441; --masha-ink: #c9a8ff;
      --darya-bg: #17332c; --darya-ink: #7fd8bd;
      --dmitrii-bg: #1a2a45; --dmitrii-ink: #9cc0ff;
      --family-bg: #3a2d14; --family-ink: #f2c46d;
      --other-bg: #2a2a2e; --other-ink: #c4c4ca;
  }
:root[data-theme="dark"] { color-scheme: dark; }
:root[data-theme="light"] { color-scheme: light; }
  * { box-sizing: border-box; }
  html { -webkit-text-size-adjust: 100%; }
  body {
    margin: 0; background: var(--bg); color: var(--ink);
    font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  }
  .wrap { max-width: 480px; margin: 0 auto; padding: 16px 16px 32px; }
  header h1 { font-size: 24px; line-height: 1.2; margin: 4px 0 2px; }
  header .snap { color: var(--muted); font-size: 13px; margin: 0 0 6px; }
  header .legend { color: var(--muted); font-size: 13px; margin: 0 0 16px; }
  .day {
    background: var(--card); border: 1px solid var(--line); border-radius: 14px;
    padding: 12px 14px; margin: 0 0 10px;
  }
  .day.is-today { background: var(--today); border-color: transparent; }
  .day.late { background: var(--late-bg); border-color: transparent; }
  .day h2 { font-size: 15px; font-weight: 600; margin: 0 0 8px; display: flex; align-items: center; gap: 8px; }
  .badge {
    font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em;
    color: var(--accent); border: 1px solid currentColor; border-radius: 999px; padding: 1px 7px;
  }
  .ev { display: flex; gap: 8px; padding: 8px 0; border-top: 1px solid var(--line); }
  .day h2 + .ev { border-top: 0; padding-top: 0; }
  .ico { flex: 0 0 20px; font-size: 15px; line-height: 21px; text-align: center; }
  .time { flex: 0 0 70px; white-space: nowrap; font-variant-numeric: tabular-nums; font-weight: 600; font-size: 15px; }
  .time small { display: block; font-weight: 400; color: var(--muted); font-size: 13px; }
  .what { flex: 1; min-width: 0; overflow-wrap: anywhere; }
  .title { font-weight: 700; font-size: 16px; }
  .busy .title { font-weight: 600; color: var(--muted); }
  .reminder .title { font-weight: 600; }
  .sub { color: var(--muted); font-size: 13px; margin-top: 1px; }
  .who { display: inline-block; font-size: 12px; font-weight: 600; border-radius: 6px; padding: 1px 7px; margin-top: 4px; }
  .who.masha { background: var(--masha-bg); color: var(--masha-ink); }
  .who.darya { background: var(--darya-bg); color: var(--darya-ink); }
  .who.dmitrii { background: var(--dmitrii-bg); color: var(--dmitrii-ink); }
  .who.family { background: var(--family-bg); color: var(--family-ink); }
  .who.other { background: var(--other-bg); color: var(--other-ink); }
  .empty { color: var(--muted); font-size: 14px; margin: 0; }
  .free { color: var(--muted); font-size: 14px; padding: 10px 14px; margin: 0 0 10px; }
  .late .time { color: var(--late); }
  .more { color: var(--muted); font-size: 13px; margin: 6px 0 0; }
  footer { color: var(--muted); font-size: 12px; margin-top: 18px; }

  [hidden] { display: none !important; }
  html, body { min-height: 100%; }
  body { -webkit-tap-highlight-color: transparent; overscroll-behavior-y: none; }
  .wrap { padding-bottom: calc(32px + env(safe-area-inset-bottom)); }
  .status { color: var(--muted); font-size: 15px; text-align: center; margin: 40vh 16px 0; }
  .ev[data-ref] { align-items: flex-start; }
  .check {
    flex: 0 0 44px; width: 44px; height: 44px; margin: -8px -10px -8px 0; padding: 0;
    border: 0; background: none; color: inherit; cursor: pointer; position: relative;
  }
  .check::before {
    content: ""; position: absolute; left: 10px; top: 10px; width: 20px; height: 20px;
    border: 2px solid var(--muted); border-radius: 50%; box-sizing: border-box;
  }
  .ev.task .check::before { border-radius: 6px; }
  .ev.is-done .check::before { background: var(--accent); border-color: var(--accent); }
  .ev.is-done .check::after {
    content: ""; position: absolute; left: 17px; top: 13px; width: 5px; height: 10px;
    border: solid var(--card); border-width: 0 2.5px 2.5px 0; transform: rotate(45deg);
  }
  .ev.is-done .title { text-decoration: line-through; color: var(--muted); }
  .ev.is-pending { opacity: .55; }
  .move {
    display: inline-block; margin: 4px 0 0; padding: 2px 0; border: 0; background: none;
    color: var(--accent); font: inherit; font-size: 13px; cursor: pointer;
  }
  .who + .move { margin-left: 10px; }
  .sheet-backdrop { position: fixed; inset: 0; background: rgba(0, 0, 0, .4); z-index: 10; }
  .sheet {
    position: absolute; left: 0; right: 0; bottom: 0; max-width: 480px; margin: 0 auto;
    background: var(--card); color: var(--ink); border-radius: 16px 16px 0 0;
    padding: 18px 16px calc(18px + env(safe-area-inset-bottom));
  }
  .sheet h2 { font-size: 17px; margin: 0 0 2px; overflow-wrap: anywhere; }
  .sheet-now { color: var(--muted); font-size: 13px; margin: 0 0 12px; }
  .opts { display: grid; gap: 8px; margin-bottom: 12px; }
  .opts button, .sheet-actions button {
    width: 100%; min-height: 44px; border-radius: 10px; border: 1px solid var(--line);
    background: var(--bg); color: var(--ink); font: inherit; font-size: 15px; cursor: pointer;
  }
  .sheet-free { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; font-size: 15px; }
  .sheet-free span { flex: 0 0 auto; color: var(--muted); }
  .sheet-free input {
    flex: 1; min-width: 0; min-height: 40px; border-radius: 10px; border: 1px solid var(--line);
    background: var(--bg); color: var(--ink); font: inherit; padding: 0 10px;
  }
  .sheet-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
  .sheet-actions .primary { background: var(--accent); border-color: var(--accent); color: var(--card); font-weight: 600; }
  .toast {
    position: fixed; left: 16px; right: 16px; bottom: calc(16px + env(safe-area-inset-bottom)); z-index: 20;
    max-width: 448px; margin: 0 auto; padding: 12px 14px; border-radius: 12px;
    background: var(--ink); color: var(--bg); font-size: 14px; text-align: center;
  }
