:root {
  color-scheme: light dark;
  --bg: #f2f2f7;
  --surface: #ffffff;
  --text: #1c1c1e;
  --muted: #5f5f66;
  --line: #d8d8de;
  --accent: #2f5fd0;
  --accent-text: #ffffff;
  --now: #1f7a3d;
  --now-bg: #e3f4e8;
  --next-bg: #e6edfb;
  --warn: #9a4a00;
  --warn-bg: #fdefd9;
  --danger: #b3261e;
  --radius: 14px;
  --tabs: 56px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000000;
    --surface: #1c1c1e;
    --text: #f2f2f7;
    --muted: #a1a1aa;
    --line: #3a3a3f;
    --accent: #8fb0ff;
    --accent-text: #0b1a3d;
    --now: #6fdc8f;
    --now-bg: #12301c;
    --next-bg: #16233f;
    --warn: #ffbf73;
    --warn-bg: #3a2608;
    --danger: #ff8a80;
  }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  /* -apple-system-body follows the iPhone's Dynamic Type setting. */
  font: -apple-system-body;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  line-height: 1.35;
  -webkit-tap-highlight-color: transparent;
}

@supports not (font: -apple-system-body) {
  body { font-size: 1.0625rem; }
}

h1, h2, h3, p { margin: 0; }
h1 { font-size: 1.75em; font-weight: 700; letter-spacing: -0.01em; }
h2 {
  margin: 22px 4px 8px;
  font-size: 0.8em;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}
h3 { font-size: 1em; font-weight: 600; }
a { color: var(--accent); }

.screen {
  max-width: 640px;
  margin: 0 auto;
  padding: calc(env(safe-area-inset-top) + 12px) max(16px, env(safe-area-inset-right))
    calc(var(--tabs) + env(safe-area-inset-bottom) + 24px) max(16px, env(safe-area-inset-left));
}
.screen.centered {
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  align-content: center;
  padding-bottom: 24px;
}

.boot, .empty { padding: 32px 8px; text-align: center; color: var(--muted); }

.card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 12px;
}
.card > * + * { margin-top: 8px; }

/* ---- controls ---- */

button, input, .button { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { opacity: 0.5; cursor: default; }

:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

.primary, .button {
  display: inline-block;
  min-height: 44px;
  padding: 10px 18px;
  border: 0;
  border-radius: 12px;
  background: var(--accent);
  color: var(--accent-text);
  font-weight: 600;
  text-align: center;
  text-decoration: none;
}
.pill {
  min-height: 36px;
  padding: 6px 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  font-weight: 600;
}
.icon {
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  font-size: 1.6em;
  line-height: 1;
  color: var(--accent);
}
.link {
  min-height: 44px;
  padding: 0 4px;
  border: 0;
  background: none;
  color: var(--accent);
}
.danger { color: var(--danger); }

label { display: block; font-weight: 600; }
input[type="text"], input[type="email"], input[type="password"], input[type="time"] {
  width: 100%;
  min-height: 44px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg);
}
input[type="time"] { width: auto; }
input[type="checkbox"] { width: 24px; height: 24px; accent-color: var(--accent); flex: none; }

.hint, .entry-meta, .footnote { color: var(--muted); font-size: 0.88em; }
.mono { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 0.85em; overflow-wrap: anywhere; }
.form-error { color: var(--danger); min-height: 1.35em; }
.warn-text { color: var(--warn); }

.login h1 { margin-bottom: 8px; }
.login .primary { width: 100%; }

/* ---- header and week strip ---- */

.day-head { display: flex; align-items: center; gap: 4px; margin-bottom: 10px; }
.day-title { flex: 1; min-width: 0; padding: 0 4px; }
.day-title p { color: var(--muted); }

.week { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; margin-bottom: 12px; }
.week-day {
  display: grid;
  justify-items: center;
  gap: 2px;
  min-height: 60px;
  padding: 6px 0;
  border: 0;
  border-radius: 12px;
  background: transparent;
}
.week-letter { font-size: 0.72em; font-weight: 600; color: var(--muted); }
.week-number { font-size: 1.05em; font-weight: 600; }
.week-day.today .week-number { color: var(--accent); }
.week-day[aria-current="date"] { background: var(--accent); }
.week-day[aria-current="date"] .week-letter,
.week-day[aria-current="date"] .week-number { color: var(--accent-text); }
.week-dots { display: flex; gap: 3px; height: 5px; }
.week-dots i { width: 5px; height: 5px; border-radius: 50%; background: var(--muted); }
.week-day[aria-current="date"] .week-dots i { background: var(--accent-text); }

/* ---- banners ---- */

.banner {
  margin-bottom: 12px;
  padding: 10px 14px;
  border-radius: 12px;
  background: var(--surface);
  color: var(--muted);
  font-size: 0.92em;
}
.banner.warn { background: var(--warn-bg); color: var(--warn); }
.banner.warn a { color: inherit; font-weight: 600; }
[hidden] { display: none !important; }

.briefing p:first-child { font-weight: 600; }

/* ---- all-day ---- */

.all-day, .plain, .timeline { list-style: none; margin: 0; padding: 0; }
.all-day {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 4px 16px;
}
.all-day li { display: flex; align-items: center; gap: 10px; padding: 9px 0; }
.all-day li + li { border-top: 1px solid var(--line); }
.dot {
  --dot: var(--muted);
  flex: none;
  display: inline-block;
  width: 10px;
  height: 10px;
  margin-right: 8px;
  border-radius: 50%;
  background: var(--dot);
}
.all-day .dot { margin-right: 0; }

/* ---- timeline ---- */

.entry {
  --cal: var(--muted);
  display: grid;
  grid-template-columns: 5.2em 4px 1fr;
  gap: 10px;
  padding: 12px 14px 12px 12px;
  margin-bottom: 8px;
  border-radius: var(--radius);
  background: var(--surface);
}
.entry-time { display: grid; align-content: start; text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }
.entry-end { font-weight: 400; color: var(--muted); font-size: 0.88em; }
.entry-bar { border-radius: 2px; background: var(--cal); }
.entry-body { min-width: 0; }
.entry-title { font-weight: 600; overflow-wrap: anywhere; }
.entry.current { background: var(--now-bg); box-shadow: inset 0 0 0 2px var(--now); }
.entry.next { background: var(--next-bg); }
/* Past events are quieter, but still readable: muted text rather than see-through. */
.entry.past .entry-time, .entry.past .entry-title { color: var(--muted); font-weight: 400; }
.entry.past .entry-bar { opacity: 0.5; }
.entry.declined .entry-title, .all-day .declined span { text-decoration: line-through; color: var(--muted); }

.badges { display: flex; flex-wrap: wrap; gap: 6px; }
.badges:empty { display: none; }
.badge {
  margin-top: 6px;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.78em;
  font-weight: 600;
  border: 1px solid currentColor;
}
.badge.now { color: var(--now); }
.badge.next { color: var(--accent); }
.badge.conflict { color: var(--warn); background: var(--warn-bg); }
.badge.muted { color: var(--muted); }

.gap {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin: 0 4px 8px;
  padding: 6px 12px;
  border: 1px dashed var(--line);
  border-radius: 10px;
  color: var(--muted);
  font-size: 0.88em;
}
.gap-range { font-variant-numeric: tabular-nums; }

.footnote { display: flex; align-items: center; justify-content: center; gap: 8px; margin-top: 8px; }

/* ---- settings ---- */

.row { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 4px 12px; min-height: 44px; }
.row label { flex: 1; font-weight: 400; display: flex; align-items: center; flex-wrap: wrap; }
.plain li + li { border-top: 1px solid var(--line); }
.card.plain { padding: 4px 16px; }
.card.plain > * + * { margin-top: 0; }

/* ---- tab bar ---- */

.tabs {
  position: fixed;
  inset: auto 0 0 0;
  display: flex;
  justify-content: center;
  gap: 8px;
  padding: 6px 12px calc(env(safe-area-inset-bottom) + 6px);
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  border-top: 1px solid var(--line);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
}
.tab {
  flex: 1;
  max-width: 200px;
  min-height: 44px;
  display: grid;
  place-items: center;
  border-radius: 10px;
  color: var(--muted);
  font-weight: 600;
  text-decoration: none;
}
.tab[aria-current="page"] { color: var(--accent); background: var(--next-bg); }

@media (prefers-reduced-motion: no-preference) {
  .entry, .week-day { transition: background-color 0.15s; }
}

/* ---- forms (reminders) ---- */

select, textarea, input[type="date"] {
  font: inherit;
  color: inherit;
  width: 100%;
  min-height: 44px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg);
}
textarea { resize: vertical; }
.reminder-form label { margin-top: 10px; font-size: 0.88em; color: var(--muted); }
.reminder-form input[type="time"] { width: 100%; }
.field-pair { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.field-pair > div { min-width: 0; }
.add-row { display: flex; gap: 8px; }
.add-row input { flex: 1; min-width: 0; }
summary { min-height: 44px; display: flex; align-items: center; color: var(--accent); cursor: pointer; }
.actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 10px; }

/* ---- list chips ---- */

.chips { display: flex; gap: 8px; margin-bottom: 12px; padding-bottom: 2px; overflow-x: auto; }
.chip {
  flex: none;
  min-height: 36px;
  padding: 6px 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  white-space: nowrap;
}
.chip[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }
.chip.add { border-style: dashed; color: var(--accent); background: transparent; }

/* ---- reminder rows ---- */

.reminder-list { list-style: none; margin: 0; padding: 0; }
.reminder { background: var(--surface); border-radius: var(--radius); margin-bottom: 8px; }
.reminder-line { display: flex; align-items: center; gap: 4px; padding: 4px 12px 4px 4px; }
.check { margin: 10px; }
.reminder-main {
  flex: 1;
  min-width: 0;
  min-height: 44px;
  display: grid;
  align-content: center;
  gap: 2px;
  padding: 6px 0;
  border: 0;
  background: none;
  text-align: left;
  text-decoration: none;
  color: inherit;
}
.reminder-title { font-weight: 600; overflow-wrap: anywhere; }
.reminder.done .reminder-title { font-weight: 400; text-decoration: line-through; color: var(--muted); }
.reminder.overdue .entry-meta { color: var(--warn); }
.priority { color: var(--danger); font-weight: 700; }
.reminder-panel { padding: 0 16px 14px 50px; }
.notes { white-space: pre-wrap; overflow-wrap: anywhere; color: var(--muted); }
h2.warn-text { color: var(--warn); }

.entry.reminder-entry { grid-template-columns: 5.2em 4px 1fr auto; align-items: center; padding-right: 4px; }
.entry.reminder-entry .entry-bar { align-self: stretch; background: var(--accent); }
.all-day .all-day-reminder { padding: 0; gap: 0; }
.all-day .all-day-reminder .check { margin-left: -1px; }
.all-day .all-day-reminder .entry-meta { margin-left: auto; }

.log { list-style: none; margin: 0; padding: 0; font-size: 0.88em; color: var(--muted); }
.log li { padding: 6px 0; overflow-wrap: anywhere; }
.log li + li { border-top: 1px solid var(--line); }

.chips { scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }

/* ---- quick add ---- */

.quick-add input[type="text"] { margin: 0; }
.quick-preview { margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--line); }
.quick-preview > * + * { margin-top: 6px; }
.quick-preview .chips { margin-bottom: 4px; }
.quick-preview .event-form { padding: 0; margin: 0; background: none; }

/* ---- event details ---- */

.entry-open {
  display: grid;
  gap: 2px;
  width: 100%;
  min-height: 44px;
  padding: 0;
  border: 0;
  background: none;
  text-align: left;
  color: inherit;
}
.entry-open .entry-title { display: block; }
.entry-panel { margin-top: 8px; padding-top: 8px; border-top: 1px solid var(--line); }
.entry-panel > * + * { margin-top: 6px; }
.all-day .all-day-event { display: block; padding: 0; }
.all-day-line { display: flex; align-items: center; gap: 10px; min-height: 44px; }
.all-day .all-day-edit { display: block; padding: 8px 0; }
.all-day .all-day-edit .event-form { padding: 0; margin: 0; background: none; }
.all-day .all-day-event .entry-panel { margin: 0 0 10px; }

/* ---- month grid ---- */

.month { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.month .week-letter { text-align: center; padding: 4px 0; }
.month-day {
  position: relative;
  display: grid;
  justify-items: center;
  align-content: start;
  gap: 4px;
  min-height: 56px;
  padding: 8px 0 6px;
  border-radius: 12px;
  background: var(--surface);
  color: inherit;
  text-decoration: none;
}
.month-day.other { background: transparent; color: var(--muted); }
.month-day.today { box-shadow: inset 0 0 0 2px var(--accent); }
.month-day.today .month-number { color: var(--accent); }
.month-number { font-weight: 600; font-variant-numeric: tabular-nums; }
.month-more { font-size: 0.68em; color: var(--muted); line-height: 1; }
.week-dots i.reminder-dot { background: var(--accent); }
.month-key { display: flex; align-items: center; justify-content: center; gap: 6px; margin-top: 12px; }
.month-key .week-dots { display: inline-flex; height: auto; }

.tab { font-size: 0.92em; }

/* ---- automations ---- */

.step { margin: 12px 0 0; padding: 4px 12px 12px; border: 1px solid var(--line); border-radius: 12px; }
.step legend { padding: 0 6px; font-size: 0.8em; font-weight: 600; color: var(--muted); }
input[type="number"] {
  width: 100%;
  min-height: 44px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg);
}
.switch-label { flex: none !important; font-size: 0.88em; color: var(--muted); }
.reminder-form .chips { margin: 4px 0 0; flex-wrap: wrap; overflow: visible; }

/* Five tabs have to fit a phone. */
.tabs { gap: 2px; padding-left: 6px; padding-right: 6px; }
.tab { font-size: 0.8em; min-width: 0; }
.row > h3 { flex: 1; min-width: 0; }

/* ---- large text ---- */

input, select, textarea { max-width: 100%; }
.mono { overflow-wrap: anywhere; }
main:focus { outline: none; }

/* Connection test results */
.checks { list-style: none; margin: 12px 0 0; padding: 0; font-size: 0.88em; }
.checks li { padding: 6px 0; overflow-wrap: anywhere; }
.checks li + li { border-top: 1px solid var(--line); }
.check-ok strong { color: var(--now); }
.check-warn strong { color: var(--warn); }
.check-fail strong { color: var(--danger); }
.check-skip { color: var(--muted); }

/* ---- chat ---- */

/* Six tabs: each as wide as its word, and the bar scrolls sideways if text is very large. */
.tabs { justify-content: flex-start; overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tabs { gap: 0; padding-left: 4px; padding-right: 4px; }
.tab { flex: 1 0 auto; max-width: none; padding: 0 3px; font-size: 0.75em; }

.chat-log { display: flex; flex-direction: column; gap: 8px; margin-top: 8px; }
.bubble {
  max-width: 88%;
  padding: 9px 13px;
  border-radius: 18px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.bubble.me { align-self: flex-end; background: var(--accent); color: var(--accent-text); border-bottom-right-radius: 6px; }
.bubble.them { align-self: flex-start; background: var(--surface); border-bottom-left-radius: 6px; }
.proposals { display: flex; flex-direction: column; gap: 8px; }
.proposals:empty { display: none; }
.proposal { border-left: 4px solid var(--accent); margin: 0; }
.proposal-label { font-size: 0.8em; font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase; color: var(--muted); }
.proposal-summary { margin-top: 4px; font-weight: 600; overflow-wrap: anywhere; }
.proposal-done { color: var(--now); font-weight: 600; flex: 1; min-width: 0; }
.danger-fill { background: var(--danger); border-color: var(--danger); color: var(--surface); }
.chat-status { min-height: 1.4em; margin: 8px 4px 0; color: var(--muted); font-size: 0.88em; }
.chat-form {
  position: sticky;
  bottom: calc(var(--tabs) + env(safe-area-inset-bottom) + 8px);
  display: flex;
  gap: 8px;
  align-items: center;
  margin-top: 4px;
  padding: 8px;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--line);
}
.chat-form input[type="text"] { flex: 1; min-width: 0; margin: 0; }
.chat-form button { flex: none; margin: 0; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.chips:empty { display: none; }
