/* Themes: each is a hue (--h), tint strength (--t) and a light or dark mode.
   Every surface and line is derived from those, so a theme is three values. */
:root {
  --h: 75;
  --t: 0.005;
  --now-h: 30;
  --font: "Schibsted Grotesk", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --display: "Newsreader", "New York", Georgia, serif;
  --hour: 52px;
}
:root, [data-mode="light"] {
  --bg: oklch(0.975 var(--t) var(--h));
  --surface: oklch(0.995 calc(var(--t) * 0.4) var(--h));
  --sunken: oklch(0.953 calc(var(--t) * 1.2) var(--h));
  --line: oklch(0.9 calc(var(--t) * 1.4) var(--h));
  --line-strong: oklch(0.82 calc(var(--t) * 1.6) var(--h));
  --text: oklch(0.24 calc(var(--t) * 1.6) var(--h));
  --muted: oklch(0.5 calc(var(--t) * 2) var(--h));
  --faint: oklch(0.62 calc(var(--t) * 1.6) var(--h));
  --accent: var(--text);
  --accent-text: oklch(0.985 calc(var(--t) * 0.6) var(--h));
  --now: oklch(0.6 0.19 var(--now-h));
  --error: oklch(0.52 0.18 28);
  --ev-mix: 15%;
  --ev-fg-mix: 52%;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-mode="light"]) {
    --bg: oklch(0.19 var(--t) var(--h));
    --surface: oklch(0.215 calc(var(--t) * 1.1) var(--h));
    --sunken: oklch(0.172 var(--t) var(--h));
    --line: oklch(0.29 calc(var(--t) * 1.3) var(--h));
    --line-strong: oklch(0.37 calc(var(--t) * 1.5) var(--h));
    --text: oklch(0.94 calc(var(--t) * 1.2) var(--h));
    --muted: oklch(0.72 calc(var(--t) * 1.6) var(--h));
    --faint: oklch(0.6 calc(var(--t) * 1.6) var(--h));
    --accent: var(--text);
    --accent-text: oklch(0.2 var(--t) var(--h));
    --now: oklch(0.7 0.17 var(--now-h));
    --error: oklch(0.72 0.15 28);
    --ev-mix: 24%;
    --ev-fg-mix: 38%;
    color-scheme: dark;
  }
}
[data-mode="dark"] {
  --bg: oklch(0.19 var(--t) var(--h));
  --surface: oklch(0.215 calc(var(--t) * 1.1) var(--h));
  --sunken: oklch(0.172 var(--t) var(--h));
  --line: oklch(0.29 calc(var(--t) * 1.3) var(--h));
  --line-strong: oklch(0.37 calc(var(--t) * 1.5) var(--h));
  --text: oklch(0.94 calc(var(--t) * 1.2) var(--h));
  --muted: oklch(0.72 calc(var(--t) * 1.6) var(--h));
  --faint: oklch(0.6 calc(var(--t) * 1.6) var(--h));
  --accent: var(--text);
  --accent-text: oklch(0.2 var(--t) var(--h));
  --now: oklch(0.7 0.17 var(--now-h));
  --error: oklch(0.72 0.15 28);
  --ev-mix: 24%;
  --ev-fg-mix: 38%;
  color-scheme: dark;
}
/* High contrast: darker text and lines, stronger event text. */
[data-contrast="more"] {
  --line: oklch(0.72 0 0);
  --line-strong: oklch(0.45 0 0);
  --muted: oklch(0.36 0 0);
  --faint: oklch(0.42 0 0);
  --text: oklch(0.12 0 0);
  --ev-mix: 18%;
  --ev-fg-mix: 70%;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  display: flex;
  flex-direction: column;
  font: 14px/1.4 var(--font);
  height: 100dvh;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { color: inherit; font: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--text); outline-offset: 2px; }
/* Fields: a quiet ring instead of a heavy outline on top of the border. */
input:focus-visible, select:focus-visible, textarea:focus-visible {
  border-color: var(--text);
  box-shadow: 0 0 0 3px color-mix(in oklab, var(--text) 14%, transparent);
  outline: 0;
}
[hidden] { display: none !important; }

/* Every event is tinted in its person's color (--c). */
.tint {
  --ev-bg: color-mix(in oklab, var(--c) var(--ev-mix), var(--surface));
  --ev-fg: color-mix(in oklab, var(--c) var(--ev-fg-mix), var(--text));
  background: var(--ev-bg);
  color: var(--ev-fg);
}
.who {
  align-items: center;
  background: var(--ev-fg);
  border-radius: 4px;
  color: var(--ev-bg);
  display: inline-flex;
  flex: none;
  font-size: 10px;
  font-weight: 600;
  height: 15px;
  justify-content: center;
  line-height: 1;
  width: 15px;
}
.is-cancelled { opacity: 0.6; }
.is-cancelled .title { text-decoration: line-through; text-decoration-thickness: 1px; }
.cancel-tag { font-size: 11px; font-weight: 600; letter-spacing: 0.02em; text-transform: uppercase; }

/* Buttons */
.btn {
  align-items: center;
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  display: inline-flex;
  font-weight: 500;
  justify-content: center;
  min-height: 36px;
  padding: 0 12px;
}
.btn:hover { background: var(--sunken); }
.btn.icon { font-size: 20px; line-height: 1; padding: 0; width: 36px; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.primary:hover { background: color-mix(in oklch, var(--accent) 88%, var(--bg)); }
.btn.danger { color: var(--error); }
.link { background: none; border: 0; color: inherit; font-weight: 600; padding: 4px; text-decoration: underline; text-underline-offset: 3px; }

/* Header */
.bar {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: 10px 12px;
  padding: 18px 20px 10px;
}
h1 {
  font: 400 32px/1 var(--display);
  letter-spacing: -0.01em;
  margin: 0 8px 0 0;
  min-width: 0;
}
h1 .year { color: var(--faint); }
.nav { display: flex; gap: 4px; }
.seg { background: var(--sunken); border: 1px solid var(--line); border-radius: 9px; display: flex; margin-left: auto; padding: 2px; }
.seg button { background: none; border: 0; border-radius: 7px; color: var(--muted); font-weight: 500; min-height: 32px; padding: 0 12px; }
.seg button[aria-selected="true"] { background: var(--surface); box-shadow: 0 0 0 1px var(--line-strong); color: var(--text); }
.actions { display: flex; gap: 6px; }

/* Filters double as the legend */
.filters { display: flex; flex-wrap: wrap; gap: 6px; padding: 0 20px 12px; }
.chip {
  align-items: center;
  border: 1px solid transparent;
  border-radius: 999px;
  display: inline-flex;
  font-weight: 500;
  gap: 7px;
  min-height: 30px;
  padding: 0 12px 0 6px;
}
.chip[aria-pressed="false"] { background: transparent; border-color: var(--line-strong); color: var(--faint); }
.chip[aria-pressed="false"] .who { background: transparent; box-shadow: inset 0 0 0 1px var(--faint); color: var(--faint); }
.chip[aria-pressed="false"] .label { text-decoration: line-through; }

.sync {
  align-items: center;
  background: color-mix(in oklch, var(--error) 12%, var(--surface));
  border: 1px solid color-mix(in oklch, var(--error) 30%, var(--surface));
  border-radius: 8px;
  display: flex;
  gap: 8px;
  margin: 0 20px 10px;
  padding: 6px 12px;
}

main { display: flex; flex: 1; flex-direction: column; min-height: 0; padding: 0 20px 20px; }

/* Month (wide) */
.month {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  display: grid;
  flex: 1;
  grid-template-rows: auto repeat(6, minmax(116px, 1fr));
  min-height: 0;
  overflow: auto;
}
.dow { border-bottom: 1px solid var(--line); display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); }
.dow div { color: var(--muted); font-size: 11px; font-weight: 600; letter-spacing: 0.06em; padding: 8px 10px; text-transform: uppercase; }
.mweek { border-top: 1px solid var(--line); display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); min-height: 0; }
.dow + .mweek { border-top: 0; }
.mcell { border-left: 1px solid var(--line); cursor: pointer; grid-row: 1 / -1; }
.mcell:first-child { border-left: 0; }
.mcell:hover { background: color-mix(in oklch, var(--text) 3%, transparent); }
.mcell.outside { background: var(--sunken); }
.mcell.today { background: color-mix(in oklab, var(--text) 4%, var(--surface)); }
.mnum {
  align-self: start;
  background: none;
  border: 0;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  grid-row: 1;
  height: 24px;
  justify-self: start;
  margin: 5px 0 2px 6px;
  min-width: 24px;
  padding: 0 6px;
}
.mnum.outside, .mnum.past { color: var(--faint); font-weight: 500; }
.mnum.today { background: var(--now); color: oklch(0.99 0 0); }
.mbar {
  align-items: center;
  border: 0;
  border-radius: 5px;
  display: flex;
  font-size: 12px;
  font-weight: 500;
  gap: 5px;
  height: 20px;
  margin: 1px 4px;
  min-width: 0;
  overflow: hidden;
  padding: 0 5px;
  text-align: left;
  white-space: nowrap;
}
.mbar.cont-l { border-bottom-left-radius: 0; border-top-left-radius: 0; margin-left: 0; }
.mbar.cont-r { border-bottom-right-radius: 0; border-top-right-radius: 0; margin-right: 0; }
.mbar .title, .mev .title { overflow: hidden; text-overflow: ellipsis; }
.mlist { display: flex; flex-direction: column; gap: 1px; min-height: 0; overflow: hidden; padding: 1px 4px 4px; }
.mev {
  align-items: center;
  border: 0;
  border-radius: 5px;
  display: flex;
  flex: none;
  font-size: 12px;
  gap: 5px;
  height: 20px;
  min-width: 0;
  padding: 0 5px;
  text-align: left;
  white-space: nowrap;
}
.mev .t { flex: none; font-weight: 600; }
/* Past events: dimmed by mixing toward the surface, keeping text at 4.5:1. */
.tint.past-ev { background: color-mix(in oklab, var(--ev-bg) 60%, var(--surface)); color: color-mix(in oklab, var(--ev-fg) 80%, var(--surface)); }
.tint.past-ev .who { opacity: 0.6; }
.more { background: none; border: 0; border-radius: 4px; color: var(--muted); flex: none; font-size: 12px; font-weight: 600; padding: 1px 5px; text-align: left; }
.more:hover { color: var(--text); }

/* Month (phone): dot grid + selected day's agenda */
.cmonth { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 4px 4px 8px; }
.cgrid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); }
.cgrid .h { color: var(--muted); font-size: 11px; font-weight: 600; padding: 6px 0; text-align: center; }
.cday {
  align-items: center;
  background: none;
  border: 0;
  border-radius: 10px;
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-height: 48px;
  padding: 4px 0;
}
.cday .n { border-radius: 999px; font-weight: 600; height: 28px; line-height: 28px; width: 28px; }
.cday.outside .n, .cday.past .n { color: var(--faint); font-weight: 500; }
.cday.today .n { color: var(--now); }
.cday[aria-selected="true"] .n { background: var(--text); color: var(--bg); }
.cday.today[aria-selected="true"] .n { background: var(--now); color: oklch(0.99 0 0); }
.dots { display: flex; gap: 3px; height: 6px; }
.dots i { background: var(--c); border-radius: 50%; height: 6px; width: 6px; }
.agenda { margin-top: 16px; }
.agenda h3 { color: var(--muted); font-size: 12px; font-weight: 600; letter-spacing: 0.04em; margin: 0 0 8px; text-transform: uppercase; }

/* Week */
.week { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; display: flex; flex: 1; flex-direction: column; min-height: 0; overflow: hidden; }
.whead, .wall, .wgrid { display: grid; grid-template-columns: 52px repeat(var(--days), minmax(0, 1fr)); }
.whead { border-bottom: 1px solid var(--line); }
.whead .d { border-left: 1px solid var(--line); padding: 8px 10px 6px; }
.whead .d .w { color: var(--muted); font-size: 11px; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; }
.whead .d .n { font: 400 24px/1.1 var(--display); }
.whead .d.today .w, .whead .d.today .n { color: var(--now); }
.whead .d.past .n { color: var(--faint); }
.wall { border-bottom: 1px solid var(--line); min-height: 8px; padding: 3px 0; }
.wall .gut { color: var(--faint); font-size: 10px; grid-column: 1; grid-row: 1; padding: 4px 6px 0 0; text-align: right; }
.wbody { flex: 1; min-height: 0; overflow: auto; }
.wgrid { height: calc(var(--hour) * 24); }
.hours { position: relative; }
.hours span { color: var(--faint); font-size: 10px; position: absolute; right: 8px; transform: translateY(-50%); }
.wcol {
  background-image: linear-gradient(to bottom, var(--line) 1px, transparent 1px);
  background-size: 100% var(--hour);
  border-left: 1px solid var(--line);
  cursor: cell;
  position: relative;
}
.wcol.today { background-color: color-mix(in oklab, var(--text) 3.5%, transparent); }
.wev {
  border: 0;
  border-radius: 6px;
  box-shadow: 0 0 0 1px var(--surface);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  font-size: 12px;
  gap: 1px;
  overflow: hidden;
  padding: 3px 6px;
  position: absolute;
  text-align: left;
}
.wev .top { align-items: center; display: flex; gap: 5px; min-width: 0; }
.wev .title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.wev .t { font-size: 11px; opacity: 0.85; white-space: nowrap; }
.wev.short { align-items: center; flex-direction: row; gap: 5px; padding-bottom: 0; padding-top: 0; }
.now-line { border-top: 2px solid var(--now); left: 0; pointer-events: none; position: absolute; right: 0; z-index: 2; }
.now-line::before { background: var(--now); border-radius: 50%; content: ""; height: 8px; left: -4px; position: absolute; top: -5px; width: 8px; }

/* List */
.list { display: flex; flex-direction: column; gap: 22px; max-width: 720px; overflow: auto; width: 100%; }
.list-day h3 { color: var(--muted); font-size: 12px; font-weight: 600; letter-spacing: 0.04em; margin: 0 0 8px; text-transform: uppercase; }
.list-day.is-today h3 { color: var(--now); }
.items { display: flex; flex-direction: column; gap: 6px; list-style: none; margin: 0; padding: 0; }
.item {
  align-items: flex-start;
  border: 0;
  border-radius: 10px;
  display: flex;
  gap: 12px;
  min-height: 52px;
  padding: 10px 12px;
  text-align: left;
  width: 100%;
}
.item .when { flex: none; font-size: 13px; font-weight: 600; padding-top: 1px; width: 70px; }
.item .when small { display: block; font-weight: 400; opacity: 0.8; }
.item .what { flex: 1; min-width: 0; }
.item .title { font-weight: 600; overflow-wrap: anywhere; }
.item .sub { font-size: 13px; opacity: 0.85; }
.item .who { margin-top: 2px; }
.empty { align-items: center; color: var(--muted); display: flex; flex-direction: column; gap: 12px; padding: 48px 0; text-align: center; }

/* Toast */
.toast {
  align-items: center;
  background: var(--accent);
  border-radius: 10px;
  bottom: calc(20px + env(safe-area-inset-bottom));
  box-shadow: 0 8px 24px oklch(0 0 0 / 0.18);
  color: var(--accent-text);
  display: flex;
  gap: 14px;
  left: 50%;
  padding: 10px 10px 10px 16px;
  position: fixed;
  transform: translateX(-50%);
  z-index: 10;
}
@media (prefers-reduced-motion: no-preference) {
  .toast { animation: rise 220ms cubic-bezier(0.22, 1, 0.36, 1); }
  @keyframes rise { from { opacity: 0; transform: translate(-50%, 8px); } }
}

/* Dialogs */
dialog {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: 0 24px 64px oklch(0 0 0 / 0.22);
  color: var(--text);
  max-height: calc(100dvh - 32px);
  max-width: min(480px, calc(100vw - 32px));
  padding: 22px;
  width: 100%;
}
dialog::backdrop { background: oklch(0.2 0.01 70 / 0.35); }
dialog h2 { font: 400 26px/1.1 var(--display); margin: 0 0 16px; }
dialog h2:not(:first-child) { margin-top: 24px; }
.field { border: 0; display: flex; flex: 1; flex-direction: column; gap: 5px; margin: 0 0 14px; min-width: 0; padding: 0; }
.field > span, .field legend { color: var(--muted); font-size: 12px; font-weight: 600; margin-bottom: 5px; padding: 0; }
input:not([type="checkbox"]):not([type="radio"]), select, textarea {
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  min-height: 40px;
  padding: 8px 10px;
  width: 100%;
}
input::placeholder { color: var(--faint); }
textarea { resize: vertical; }
.row { align-items: flex-end; display: flex; gap: 10px; }
.check { align-items: center; display: flex; flex: none; gap: 8px; margin: 0 0 14px; min-height: 40px; }
.check input { accent-color: var(--accent); height: 17px; width: 17px; }
.cal-picker { display: flex; flex-wrap: wrap; gap: 6px; }
.cal-picker label { position: relative; }
.cal-picker input { inset: 0; opacity: 0; position: absolute; }
.cal-picker .pill {
  align-items: center;
  background: transparent;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  color: var(--text);
  display: inline-flex;
  font-weight: 500;
  gap: 7px;
  min-height: 34px;
  padding: 0 12px 0 6px;
}
.cal-picker input:checked + .pill { background: var(--ev-bg); border-color: var(--ev-fg); box-shadow: inset 0 0 0 1px var(--ev-fg); color: var(--ev-fg); }
.cal-picker input:focus-visible + .pill { outline: 2px solid var(--text); outline-offset: 2px; }
.more-opts { border-top: 1px solid var(--line); margin: 2px 0 10px; padding-top: 10px; }
.more-opts summary { color: var(--muted); cursor: pointer; font-weight: 600; margin-bottom: 10px; }
.more-opts[open] summary { margin-bottom: 14px; }
.cancelled-note {
  align-items: center;
  background: var(--sunken);
  border-radius: 10px;
  display: flex;
  gap: 12px;
  justify-content: space-between;
  margin: -4px 0 16px;
  padding: 10px 12px;
}
.cancelled-note p { margin: 0; }
.meta { color: var(--muted); font-size: 12px; margin: 0; }
.error { color: var(--error); margin: 8px 0 0; }
.error:empty { display: none; }
.hint { color: var(--muted); margin: -8px 0 14px; }
.dialog-actions { align-items: center; display: flex; flex-wrap: wrap; gap: 8px; margin-top: 18px; }
.spacer { flex: 1; }
.scope-actions { display: flex; flex-direction: column; gap: 8px; }
.scope-actions .btn { min-height: 44px; }

/* Phone */
@media (max-width: 640px) {
  .bar { padding: 12px 16px 8px; }
  h1 { font-size: 28px; }
  .seg { margin-left: 0; }
  .actions { margin-left: auto; }
  .filters { padding: 0 16px 10px; }
  .sync { margin: 0 16px 10px; }
  main { overflow: auto; padding: 0 16px 16px; }
  .btn, .seg button { min-height: 44px; }
  .btn.icon { width: 44px; }
  .chip { min-height: 36px; }
  .whead .d { padding: 6px; }
  .toast { left: 16px; right: 16px; transform: none; }
  dialog { padding: 18px; }
  .row { flex-wrap: wrap; }
}

/* Phone: New event floats within thumb reach */
@media (max-width: 640px) {
  #new-btn {
    border-radius: 999px;
    bottom: calc(20px + env(safe-area-inset-bottom));
    box-shadow: 0 6px 20px oklch(0 0 0 / 0.25);
    min-height: 52px;
    padding: 0 20px;
    position: fixed;
    right: 16px;
    z-index: 5;
  }
  .toast { bottom: calc(84px + env(safe-area-inset-bottom)); }
}

/* Person photos replace the initial wherever a person is shown */
.who.photo { background: var(--ev-fg); overflow: hidden; padding: 0; }
.who.photo img { display: block; height: 100%; object-fit: cover; width: 100%; }
.who.photo { border-radius: 50%; box-shadow: 0 0 0 1.5px var(--ev-fg); }
.chip .who, .cal-picker .who { border-radius: 6px; font-size: 11px; height: 22px; width: 22px; }
.chip .who.photo, .cal-picker .who.photo { border-radius: 50%; }
.item .who { height: 22px; width: 22px; font-size: 11px; border-radius: 6px; margin-top: 0; }
.item .who.photo { border-radius: 50%; }

/* Search */
#search-dialog { margin-top: 10vh; max-width: min(560px, calc(100vw - 32px)); padding: 0; }
#search-dialog::backdrop { background: oklch(0.2 0.01 70 / 0.25); }
.search-box { align-items: center; border-bottom: 1px solid var(--line); display: flex; gap: 10px; padding: 12px 16px; }
.search-box input { background: transparent !important; border: 0 !important; font-size: 17px; min-height: 36px; outline: 0; padding: 0 !important; }
.search-box kbd { border: 1px solid var(--line-strong); border-radius: 5px; color: var(--muted); font: 500 11px var(--font); padding: 2px 5px; }
.results { max-height: 60dvh; overflow: auto; padding: 8px 12px 14px; }
.results h3 { color: var(--muted); font-size: 11px; font-weight: 600; letter-spacing: 0.06em; margin: 12px 4px 6px; text-transform: uppercase; }
.results .date { color: var(--muted); font-size: 12px; font-weight: 600; margin: 2px 4px 4px; }
.results li + li { margin-top: 4px; }
.results mark { background: color-mix(in oklab, var(--c) 35%, transparent); border-radius: 2px; color: inherit; }
.results .empty { padding: 24px 0; }
.section { color: var(--muted); font-size: 11px; font-weight: 600; letter-spacing: 0.06em; margin: 22px 0 10px; text-transform: uppercase; }

/* Settings sheet: sticky header with Done, scrolling body */
dialog.sheet { max-width: min(520px, calc(100vw - 32px)); padding: 0; }
dialog.sheet[open] { display: flex; flex-direction: column; }
.sheet-head {
  align-items: center;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  padding: 14px 18px 12px 22px;
}
.sheet-head h2 { margin: 0 !important; }
.sheet-body { overflow: auto; padding: 4px 22px 24px; }
.sheet-body .section:first-child { margin-top: 14px; }
.sheet-body .subtle { margin: -4px 0 12px; }
.sr-only { clip: rect(0 0 0 0); height: 1px; overflow: hidden; position: absolute; white-space: nowrap; width: 1px; }

/* People */
.person { align-items: flex-start; background: none; color: inherit; display: flex; gap: 14px; padding: 10px 0; }
.person + .person { border-top: 1px solid var(--line); }
.avatar-wrap { flex: none; position: relative; }
.avatar {
  align-items: center;
  background: var(--ev-bg);
  border: 0;
  border-radius: 50%;
  box-shadow: 0 0 0 1.5px var(--ev-fg);
  color: var(--ev-fg);
  display: flex;
  font: 400 22px/1 var(--display);
  height: 52px;
  justify-content: center;
  overflow: visible;
  padding: 0;
  position: relative;
  width: 52px;
}
.avatar img { border-radius: 50%; height: 100%; object-fit: cover; width: 100%; }
.avatar .cam {
  align-items: center;
  background: var(--surface);
  border-radius: 50%;
  bottom: -3px;
  box-shadow: 0 0 0 1px var(--line-strong);
  color: var(--text);
  display: flex;
  height: 22px;
  justify-content: center;
  position: absolute;
  right: -3px;
  width: 22px;
}
.avatar .cam svg { height: 13px; width: 13px; }
.remove-photo {
  align-items: center;
  background: var(--surface);
  border: 0;
  border-radius: 50%;
  box-shadow: 0 0 0 1px var(--line-strong);
  color: var(--muted);
  display: flex;
  font-size: 15px;
  height: 22px;
  justify-content: center;
  left: -3px;
  line-height: 1;
  padding: 0;
  position: absolute;
  top: -3px;
  width: 22px;
}
.remove-photo::after { content: ""; inset: -11px; position: absolute; }
.person-main { flex: 1; min-width: 0; }
.name-row { align-items: center; display: flex; gap: 8px; }
.saved { color: var(--muted); font-size: 12px; font-weight: 600; opacity: 0; transition: opacity 200ms ease-out; white-space: nowrap; }
.saved.show { opacity: 1; }
.swatches { display: flex; flex-wrap: wrap; gap: 2px; margin: 8px 0 0 -6px; }
.swatch { cursor: pointer; display: block; height: 36px; position: relative; width: 36px; }
.swatch input { cursor: inherit; inset: 0; margin: 0; opacity: 0; position: absolute; }
.swatch span { background: var(--c); border-radius: 50%; display: block; height: 22px; margin: 7px; width: 22px; }
.swatch input:checked + span { box-shadow: 0 0 0 2px var(--surface), 0 0 0 4px var(--c); }
.swatch input:disabled + span { opacity: 0.25; }
.swatch input:disabled { cursor: not-allowed; }
.swatch input:focus-visible + span { outline: 2px solid var(--text); outline-offset: 4px; }

/* Themes */
.theme { display: block; position: relative; }
.theme input { inset: 0; margin: 0; opacity: 0; position: absolute; }
.theme .sw {
  background: var(--bg);
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  color: var(--text);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 7px 7px 6px;
}
.theme .sw > b { font-size: 12px; font-weight: 600; padding-left: 2px; }
.theme input:checked + .sw { box-shadow: 0 0 0 2px var(--surface), 0 0 0 4px var(--text); }
.theme input:focus-visible + .sw { outline: 2px solid var(--text); outline-offset: 5px; }
.theme.auto { margin-bottom: 14px; }
.theme.auto .sw { align-items: center; flex-direction: row; gap: 12px; padding: 10px 12px; }
.theme.auto small { color: var(--muted); display: block; font-size: 12px; }
.halves { border-radius: 50%; box-shadow: 0 0 0 1px var(--line-strong); display: flex; flex: none; height: 28px; overflow: hidden; width: 28px; }
.halves span { background: var(--bg); flex: 1; }
.theme-group + .theme-group { margin-top: 12px; }
.group-label { color: var(--muted); font-size: 12px; font-weight: 600; margin: 0 0 6px; }
.themes { display: grid; gap: 8px; grid-template-columns: repeat(auto-fill, minmax(88px, 1fr)); }
.mini { background: var(--surface); border: 1px solid var(--line); border-radius: 5px; display: flex; flex-direction: column; height: 46px; overflow: hidden; }
.mini-head { border-bottom: 1px solid var(--line); flex: none; height: 7px; }
.mini-cols { display: flex; flex: 1; }
.mini-cols > span { flex: 1; position: relative; }
.mini-cols > span + span { border-left: 1px solid var(--line); }
.mini-cols i { background: color-mix(in oklab, var(--c) var(--ev-mix), var(--surface)); border-left: 2px solid color-mix(in oklab, var(--c) var(--ev-fg-mix), var(--text)); border-radius: 2px; left: 2px; position: absolute; right: 2px; }
.mini-cols b { border-top: 1.5px solid var(--now); left: 0; position: absolute; right: 0; }

/* Phone calendar subscription */
.sub-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.sub-actions .btn, .feeds .btn { text-decoration: none; }
.feeds { display: flex; flex-direction: column; gap: 6px; list-style: none; margin: 0; padding: 0; }
.feeds li { align-items: center; display: flex; gap: 10px; }
.feeds .who { height: 22px; width: 22px; font-size: 11px; border-radius: 6px; }
.feeds .label { flex: 1; font-weight: 500; }

@media (max-width: 640px) {
  dialog.sheet { border: 0; border-radius: 0; height: 100dvh; margin: 0; max-height: 100dvh; max-width: 100vw; width: 100vw; }
  .sheet-head { padding: calc(10px + env(safe-area-inset-top)) 16px 10px 18px; }
  .sheet-body { padding: 4px 18px calc(28px + env(safe-area-inset-bottom)); }
  .themes { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
.swatch input:disabled + span { background-image: linear-gradient(135deg, transparent 44%, var(--surface) 44% 56%, transparent 56%); opacity: 0.45; }
#theme-note { margin: 12px 0 0; }
.themes .theme .sw { height: 100%; }

/* Several people on one event: overlapping faces */
.whos { display: inline-flex; flex: none; }
.whos .who + .who { box-shadow: 0 0 0 1.5px var(--surface); margin-left: -5px; }
.item .whos .who + .who { margin-left: -7px; }

/* Event dialog */
.quick { background: var(--sunken); border-radius: 10px; margin: 0 0 16px; padding: 10px 12px 2px; }
.quick .field { margin-bottom: 6px; }
.quick .hint { font-size: 12px; margin: 0 0 8px; }
.when { margin-bottom: 14px; }
.switch { align-items: center; cursor: pointer; display: inline-flex; font-weight: 500; gap: 8px; margin-bottom: 8px; min-height: 32px; position: relative; }
.switch input { height: 100%; inset: 0; margin: 0; opacity: 0; position: absolute; width: 100%; }
.switch span { background: var(--line-strong); border-radius: 999px; flex: none; height: 20px; position: relative; transition: background 150ms ease-out; width: 34px; }
.switch span::after { background: var(--surface); border-radius: 50%; box-shadow: 0 1px 2px oklch(0 0 0 / 0.2); content: ""; height: 16px; left: 2px; position: absolute; top: 2px; transition: transform 150ms ease-out; width: 16px; }
.switch input:checked + span { background: var(--accent); }
.switch input:checked + span::after { transform: translateX(14px); }
.switch input:focus-visible + span { outline: 2px solid var(--text); outline-offset: 2px; }
.when-row { align-items: center; display: flex; flex-wrap: wrap; gap: 8px; }
.when-row input[type="date"] { flex: 0 1 160px; }
.times { align-items: center; display: flex; flex: 1 1 236px; gap: 6px; }
.times .time { flex: 0 1 110px; min-width: 88px; }
.duration { color: var(--muted); font-size: 13px; white-space: nowrap; }
@media (max-width: 640px) {
  .when-row input[type="date"] { flex: 1 1 100%; }
}

/* Weather */
.icon { fill: none; flex: none; height: 16px; stroke: currentColor; stroke-linecap: round; stroke-linejoin: round; stroke-width: 1.6; width: 16px; }
.wx { align-items: center; color: var(--muted); display: inline-flex; font-size: 12px; font-weight: 500; gap: 3px; white-space: nowrap; }
.wx .lo { color: var(--faint); }
.wx-notes { display: flex; flex-direction: column; gap: 2px; list-style: none; margin: 4px 0 0; padding: 0; }
.wx-note { align-items: flex-start; color: var(--wx-fg); display: flex; font-size: 12px; font-weight: 500; gap: 4px; line-height: 1.3; }
.wx-note .icon { height: 14px; margin-top: 1px; width: 14px; }
:root { --wx-rain: oklch(0.55 0.12 240); --wx-warm: oklch(0.55 0.13 50); }
[data-mode="dark"], .wx-dark { --wx-rain: oklch(0.75 0.1 240); --wx-warm: oklch(0.75 0.11 60); }
@media (prefers-color-scheme: dark) { :root:not([data-mode="light"]) { --wx-rain: oklch(0.75 0.1 240); --wx-warm: oklch(0.75 0.11 60); } }
.wx-note, .mnote { --wx-fg: var(--wx-rain); }
.wx-note.heat, .mnote.heat { --wx-fg: var(--wx-warm); }
.wx-note.wind, .wx-note.cold, .mnote.wind, .mnote.cold { --wx-fg: var(--muted); }

/* Week header: date left, forecast right, notes below */
.whead .dh { align-items: flex-start; display: flex; gap: 6px; justify-content: space-between; }
.whead .wx { margin-top: 2px; }
.whead .wx-notes { margin-top: 2px; }
.wx-band {
  background: repeating-linear-gradient(135deg, color-mix(in oklab, var(--wx-rain) 9%, transparent) 0 6px, transparent 6px 12px);
  border-left: 2px solid color-mix(in oklab, var(--wx-rain) 40%, transparent);
  left: 0;
  pointer-events: none;
  position: absolute;
  right: 0;
}
.now-line { z-index: 0; }
.wev { z-index: 1; }

/* Month: forecast beside the date, one note atop the list */
.mwx { align-self: start; grid-row: 1; justify-self: end; margin: 8px 8px 0 0; pointer-events: none; }
.mnote { align-items: center; color: var(--wx-fg); display: flex; flex: none; font-size: 11px; font-weight: 500; gap: 3px; height: 18px; min-width: 0; padding: 0 3px; white-space: nowrap; }
.mnote span { overflow: hidden; text-overflow: ellipsis; }
.mnote .icon { height: 13px; width: 13px; }

/* List/agenda/day dialog headings carry the forecast */
.day-head { align-items: center; display: flex; gap: 10px; justify-content: space-between; }
.day-head .wx { font-size: 12px; letter-spacing: 0; text-transform: none; }
.list-day .wx-notes, .agenda .wx-notes { margin: -2px 0 8px; }
.day-wx { margin: -8px 0 14px; }

/* Settings: weather */
.wx-place { align-items: center; display: flex; gap: 8px; }
.wx-place input { flex: 1; }
.wx-place .seg { margin: 0; }
.seg button[aria-checked="true"] { background: var(--surface); box-shadow: 0 0 0 1px var(--line-strong); color: var(--text); }
.wx-results { display: flex; flex-direction: column; gap: 4px; list-style: none; margin: 8px 0 0; padding: 0; }
.wx-results .btn { justify-content: flex-start; width: 100%; }

/* Header: Search and Settings as icons when space is tight */
#search-btn .icon, #settings-btn .icon { display: none; }
@media (max-width: 760px) {
  #search-btn, #settings-btn { padding: 0; width: 44px; }
  #search-btn .icon, #settings-btn .icon { display: block; height: 18px; width: 18px; }
  #search-btn .label, #settings-btn .label { display: none; }
  .seg button { padding: 0 10px; }
}
@media (max-width: 640px) {
  main { padding-bottom: 16px; }
  .list, .agenda { padding-bottom: 72px; }
  .whead .dh { flex-direction: column; gap: 0; }
}

/* Dim past and cancelled week events with color, not transparency, so grid lines
   and the now line don't show through them. */
.wev.is-cancelled, .wev.past-ev { opacity: 1; }

.wev.is-cancelled { background: color-mix(in oklab, var(--ev-bg) 45%, var(--surface)); color: color-mix(in oklab, var(--ev-fg) 50%, var(--surface)); }
.wev.is-cancelled .who, .wev.past-ev .who { opacity: 0.55; }

@media (max-width: 640px) {
  /* Search and Settings ride on the title row. */
  h1 { flex: 1 1 auto; order: -2; }
  .actions { margin-left: auto; order: -1; }
}

/* Week grid v2: hour lines as a layer (night hours are half height), routines behind events */
.wgrid { position: relative; }
.wcol { background-image: none; }
.wlines { bottom: 0; left: 52px; pointer-events: none; position: absolute; right: 0; top: 0; }
.wlines i { border-top: 1px solid var(--line); left: 0; position: absolute; right: 0; }
.night-shade { background: color-mix(in oklab, var(--text) 2.5%, transparent); left: 0; position: absolute; right: 0; }
.hours span.night { opacity: 0.7; }
.whead .d.today { box-shadow: inset 0 -2px 0 var(--now); }
.now-line { border-top-width: 1.5px; z-index: 3; }
.now-label {
  background: var(--now);
  border-radius: 4px;
  color: oklch(0.99 0 0) !important;
  font-size: 10px;
  font-weight: 600;
  padding: 1px 4px;
  right: 4px !important;
  z-index: 4;
}
.wev { z-index: 2; }
.wroutine {
  background: color-mix(in oklab, var(--ev-bg) 45%, transparent);
  border: 1px solid color-mix(in oklab, var(--ev-fg) 30%, transparent);
  border-radius: 6px;
  color: var(--ev-fg);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  font-size: 11px;
  gap: 0;
  left: 2px;
  overflow: hidden;
  padding: 2px 6px;
  position: absolute;
  right: 2px;
  text-align: left;
  z-index: 1;
}
.wroutine .title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.wroutine .t { opacity: 0.8; white-space: nowrap; }
.wroutine:hover { background: color-mix(in oklab, var(--ev-bg) 80%, transparent); }
.tint.wroutine.past-ev { background: color-mix(in oklab, var(--ev-bg) 25%, transparent); }
.wx-band {
  background: color-mix(in oklab, var(--wx-rain) 9%, transparent);
  border-left: 0;
  z-index: 0;
}
.wx-band span { align-items: center; color: var(--wx-rain); display: flex; font-size: 10px; font-weight: 600; gap: 2px; position: absolute; right: 4px; top: 2px; }
.wx-band .icon { height: 11px; width: 11px; }
.wmark {
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  box-shadow: 0 2px 6px oklch(0 0 0 / 0.12);
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
  left: 50%;
  padding: 2px 8px;
  position: absolute;
  transform: translateX(-50%);
  white-space: nowrap;
  z-index: 5;
}
.wmark:hover { color: var(--text); }

/* Routines in lists: one quiet line */
.item.routine {
  align-items: center;
  background: transparent;
  border: 1px dashed color-mix(in oklab, var(--ev-fg) 30%, transparent);
  font-size: 13px;
  gap: 10px;
  min-height: 0;
  padding: 6px 12px;
}
.item.routine .when { font-weight: 500; }
.item.routine .title { font-weight: 500; }
.item.routine .sub { font-size: 12px; margin-left: auto; opacity: 0.8; white-space: nowrap; }
.routine-switch { margin: -2px 0 0; }
.routine-switch + .hint { font-size: 12px; margin: 0 0 12px; }

/* Temperature feel: a word plus a color, cold blue to hot red. */
:root, [data-mode="light"] {
  --feel-cold: oklch(0.5 0.13 250);
  --feel-cool: oklch(0.5 0.08 205);
  --feel-mild: oklch(0.5 0.09 150);
  --feel-warm: oklch(0.53 0.13 65);
  --feel-hot: oklch(0.52 0.17 30);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-mode="light"]) {
    --feel-cold: oklch(0.78 0.1 250);
    --feel-cool: oklch(0.8 0.07 205);
    --feel-mild: oklch(0.8 0.09 150);
    --feel-warm: oklch(0.82 0.12 75);
    --feel-hot: oklch(0.76 0.14 35);
  }
}
[data-mode="dark"] {
  --feel-cold: oklch(0.78 0.1 250);
  --feel-cool: oklch(0.8 0.07 205);
  --feel-mild: oklch(0.8 0.09 150);
  --feel-warm: oklch(0.82 0.12 75);
  --feel-hot: oklch(0.76 0.14 35);
}
.wx.feel-cold { --feel: var(--feel-cold); }
.wx.feel-cool { --feel: var(--feel-cool); }
.wx.feel-mild { --feel: var(--feel-mild); }
.wx.feel-warm { --feel: var(--feel-warm); }
.wx.feel-hot { --feel: var(--feel-hot); }
.wx { gap: 4px; }
.wx .icon { color: var(--feel); }
.wx .feel { color: var(--feel); font-weight: 600; }
.wx .hi { color: var(--feel); font-weight: 600; }
.wx .lo { color: var(--faint); }

/* Night hours: thin strips that open on click */
.night-strip {
  align-items: center;
  background: var(--sunken);
  border: 0;
  border-bottom: 1px solid var(--line);
  border-top: 1px solid var(--line);
  color: var(--muted);
  display: flex;
  font-size: 11px;
  font-weight: 600;
  justify-content: center;
  left: 0;
  padding: 0;
  position: absolute;
  right: 0;
  z-index: 4;
}
.night-strip:hover { color: var(--text); }
.night-strip.open {
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  height: 20px;
  left: auto;
  padding: 0 8px;
  right: 6px;
  transform: translateY(2px);
}
.night-strip.bottom.open { transform: translateY(-22px); }

/* Routine bands keep their person: a thin edge in their color */
.wroutine { border-left: 3px solid color-mix(in oklab, var(--ev-fg) 55%, transparent); }

/* Sign-in */
body.gated > :not(.gate):not(script) { display: none !important; }
.gate { align-items: center; display: flex; flex: 1; justify-content: center; padding: 24px 16px; }
.gate-card { display: flex; flex-direction: column; gap: 14px; max-width: 380px; width: 100%; }
.gate-card h1 { font-size: 40px; margin: 0; }
.gate-text { color: var(--muted); font-size: 15px; margin: 0; }
.gate-btn { font-size: 15px; min-height: 48px; }
.gate-alt { color: var(--muted); font-size: 13px; text-align: left; }
.gate-hint { color: var(--faint); font-size: 13px; margin: 8px 0 0; }

/* Settings: who can sign in */
.signins { display: flex; flex-direction: column; gap: 4px; list-style: none; margin: 0 0 10px; padding: 0; }
.signins li { display: flex; justify-content: space-between; }
.signins .subtle { margin: 0; }
.invite-row, .device-row { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 10px; }
.invite-row input { flex: 1 1 160px; }
.link-out { background: var(--sunken); border-radius: 10px; margin-bottom: 12px; padding: 10px 12px; }
.link-out .subtle { margin: 0 0 8px; }
.link-copy { align-items: center; display: flex; gap: 8px; }
.link-copy code { flex: 1; font-size: 11px; overflow-wrap: anywhere; }

/* Settings: Google Calendar */
.g-accounts { display: flex; flex-direction: column; gap: 4px; list-style: none; margin: 0 0 10px; padding: 0; }
.g-accounts li { align-items: center; display: flex; justify-content: space-between; }
#g-connect { margin-bottom: 12px; }
.g-links { display: flex; flex-direction: column; gap: 8px; }
.g-row { align-items: center; display: grid; gap: 10px; grid-template-columns: 120px 1fr; }
.g-person { align-items: center; display: inline-flex; font-weight: 500; gap: 7px; }
.g-person .who { border-radius: 6px; font-size: 11px; height: 22px; width: 22px; }

/* Events from Google Calendar */
.src { align-items: center; display: inline-flex; flex: none; opacity: 0.7; }
.src .icon { height: 12px; width: 12px; }
.item .title .src { margin-left: 6px; vertical-align: -1px; }
.g-suggest { background: var(--sunken); border-radius: 10px; margin: 0 0 14px; padding: 12px 14px; }
.g-suggest-title { font-weight: 600; margin: 0 0 6px; }
.g-suggest ul { margin: 0 0 8px; padding-left: 18px; }
.g-suggest .subtle { margin: 0 0 10px; }
.g-label { color: var(--muted); font-size: 12px; font-weight: 600; margin: 4px 0 8px; }

/* Copies shown as one */
.copies { border: 1px solid currentColor; border-radius: 4px; flex: none; font-size: 10px; font-weight: 700; line-height: 1; opacity: 0.75; padding: 1px 3px; }
.item .title .copies { margin-left: 6px; vertical-align: 1px; }
.event-copies { background: var(--sunken); border-radius: 10px; margin-top: 10px; padding: 10px 12px; }
.copies-title { font-size: 13px; font-weight: 600; margin: 0 0 6px; }
.copy-row { align-items: center; display: flex; font-size: 13px; gap: 8px; justify-content: space-between; }
.copy-row + .copy-row { margin-top: 6px; }
.g-extras { display: flex; flex-direction: column; gap: 12px; }
.g-extra-row { display: flex; flex-direction: column; gap: 6px; }
.g-cal { font-weight: 600; }
#g-extras-label { margin-top: 18px; }
