:root {
  --bg: #f5f3ee;
  --surface: #ffffff;
  --other: #f8f7f3;
  --hover: #f1efe9;
  --ink: #1f2328;
  --muted: #6b7078;
  --line: #e2ded5;
  --accent: #2d6a5a;
  --on-accent: #ffffff;
  --g: #7044a8;       /* Glenn's lines */
  --m: #1d63a3;       /* Mike's lines  */
  --rec: #a24d00;     /* yearly entries */
  --mark: #ffe58a;
  --shadow: 0 10px 30px rgba(0, 0, 0, .14);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141619; --surface: #1c1f23; --other: #181a1e; --hover: #24282d;
    --ink: #e7e5e0; --muted: #969ca4; --line: #2c3036;
    --accent: #6cc2a6; --on-accent: #0d1f19;
    --g: #c5a4f2; --m: #82b8ea; --rec: #f0a35e; --mark: #6b5a12;
    --shadow: 0 10px 30px rgba(0, 0, 0, .5);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--ink);
}
[hidden] { display: none !important; }
.muted { color: var(--muted); }
mark { background: var(--mark); color: inherit; border-radius: 2px; }

button {
  font: inherit; color: var(--ink); background: var(--surface);
  border: 1px solid var(--line); border-radius: 8px; padding: 6px 12px; cursor: pointer;
}
button:hover { background: var(--hover); }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); font-weight: 600; }
button.primary:hover { filter: brightness(1.08); }
button.icon { width: 34px; height: 34px; padding: 0; font-size: 1.15rem; line-height: 1; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ── Screens ── */
.center-screen { min-height: 100dvh; display: grid; place-items: center; padding: 16px; color: var(--muted); }
.signin-card {
  background: var(--surface); border: 1px solid var(--line); border-radius: 14px;
  padding: 32px 28px; text-align: center; max-width: 360px; width: 100%; color: var(--ink);
}
.signin-card h1 { margin: 0 0 6px; font-size: 1.6rem; }
.signin-card p { color: var(--muted); margin: 0 0 20px; }

#app { display: flex; flex-direction: column; height: 100dvh; }
main { flex: 1; min-height: 0; }

/* ── Header ── */
.bar {
  display: flex; align-items: center; gap: 12px; padding: 10px 16px;
  background: var(--surface); border-bottom: 1px solid var(--line);
}
.nav { display: flex; align-items: center; gap: 8px; flex: 1; min-width: 0; }
.nav h1 { margin: 0 4px; font-size: 1.35rem; font-weight: 650; min-width: 11ch; text-align: center; }
.tools { display: flex; align-items: center; gap: 8px; }
.search { position: relative; }
#search {
  font: inherit; color: var(--ink); background: var(--bg);
  border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px; width: 240px;
}
.results {
  position: absolute; right: 0; top: calc(100% + 6px); z-index: 20;
  width: min(460px, calc(100vw - 32px)); max-height: 70vh; overflow: auto;
  background: var(--surface); border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow);
  padding: 6px;
}
.rh { font-size: .75rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); padding: 8px 8px 4px; }
.res {
  display: block; width: 100%; text-align: left; border: 0; border-radius: 8px;
  padding: 8px; background: transparent;
}
.res:hover, .res:focus { background: var(--hover); }
.rd { display: block; font-weight: 600; font-size: .85rem; margin-bottom: 2px; }
.rs { display: block; font-size: .85rem; }

/* ── Day text ── */
.ln { white-space: pre-wrap; overflow-wrap: anywhere; }
.ln.blank { height: .45em; }
.ln.g { color: var(--g); }
.ln.m { color: var(--m); }

.rec { color: var(--rec); font-style: italic; }
.ct .rec + * { margin-top: 2px; }
.rec-swatch { color: var(--rec); font-style: italic; }

/* ── Month view (desktop) ── */
.month {
  height: 100%;
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  grid-template-rows: auto repeat(var(--weeks, 5), minmax(0, 1fr));
  gap: 1px; background: var(--line);
}
.wd {
  background: var(--surface); padding: 5px 8px;
  font-size: .72rem; letter-spacing: .06em; text-transform: uppercase; color: var(--muted);
}
.cell {
  background: var(--surface); padding: 4px 7px 6px; min-height: 0;
  display: flex; flex-direction: column; cursor: pointer;
}
.cell:hover { background: var(--hover); }
.cell:focus-visible { outline-offset: -2px; }
.cell.other { background: var(--other); }
.cell.other .dn { color: var(--muted); font-weight: 500; }
.cell.other .ct { opacity: .72; }
.cell.today { box-shadow: inset 0 0 0 2px var(--accent); }
.cell.today .dn { color: var(--accent); }
.dn { font-size: .8rem; font-weight: 650; margin-bottom: 2px; }
.cell .ct { flex: 1; min-height: 0; overflow-y: auto; font-size: .78rem; line-height: 1.3; scrollbar-width: thin; }

/* ── Day list (mobile) ── */
.agenda { height: 100%; overflow-y: auto; -webkit-overflow-scrolling: touch; padding-bottom: 40px; }
.mh {
  position: sticky; top: 0; z-index: 2; margin: 0; padding: 8px 16px;
  font-size: .8rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted);
  background: var(--bg); border-bottom: 1px solid var(--line);
}
.day { padding: 10px 16px 12px; background: var(--surface); border-bottom: 1px solid var(--line); cursor: pointer; }
.day.empty { padding-top: 7px; padding-bottom: 7px; background: var(--other); }
.day.empty .dh { color: var(--muted); }
.day.today { border-left: 4px solid var(--accent); padding-left: 12px; }
.dh { display: flex; align-items: baseline; gap: 8px; font-weight: 650; }
.day:not(.empty) .dh { margin-bottom: 4px; }
.dow { width: 2.6em; color: var(--muted); font-weight: 500; font-size: .85rem; }
.dnum { font-size: 1.05rem; }
.badge { font-size: .7rem; background: var(--accent); color: var(--on-accent); border-radius: 99px; padding: 1px 8px; }
.toggle { font-size: .85rem; color: var(--muted); white-space: nowrap; display: flex; gap: 6px; align-items: center; }

/* ── Dialogs ── */
dialog {
  border: 1px solid var(--line); border-radius: 14px; padding: 20px;
  background: var(--surface); color: var(--ink); box-shadow: var(--shadow);
  width: min(600px, 94vw);
}
dialog::backdrop { background: rgba(0, 0, 0, .35); }
dialog h2 { margin: 0 0 12px; font-size: 1.15rem; }
.editor form { display: flex; flex-direction: column; gap: 12px; }
#editor-text {
  width: 100%; min-height: 16rem; resize: vertical;
  font: inherit; font-size: 1rem; line-height: 1.45; color: var(--ink);
  background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px;
}
.editor-actions { display: flex; align-items: center; gap: 8px; }
.meta { flex: 1; font-size: .8rem; color: var(--muted); }
.note {
  font-size: .85rem; padding: 8px 10px; border-radius: 8px;
  background: color-mix(in srgb, var(--accent) 14%, var(--surface)); border: 1px solid color-mix(in srgb, var(--accent) 40%, var(--line));
}
.conflict { border-top: 1px solid var(--line); padding-top: 12px; }
.conflict p { margin: 0 0 8px; font-weight: 600; }
.theirs {
  max-height: 12rem; overflow: auto; font-size: .9rem;
  background: var(--bg); border: 1px dashed var(--line); border-radius: 10px; padding: 10px 12px; margin-bottom: 10px;
}
.conflict-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.help { width: min(640px, 94vw); max-height: 88vh; }
.help h3 { margin: 18px 0 6px; font-size: .95rem; }
.keys { border-collapse: collapse; font-size: .9rem; }
.keys td { padding: 4px 12px 4px 0; vertical-align: top; }
.keys td:first-child { white-space: nowrap; }
kbd {
  display: inline-block; min-width: 1.6em; text-align: center; font: 600 .8rem ui-monospace, Menlo, monospace;
  border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 5px; padding: 1px 5px; margin-right: 2px;
  background: var(--bg);
}
.codes { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: .82rem; color: var(--muted); }
.codes b { font-size: 1rem; }
code { font: .8rem ui-monospace, Menlo, monospace; }
.help-actions { display: flex; justify-content: space-between; margin-top: 18px; }

.sub { margin: -8px 0 0; font-size: .85rem; color: var(--rec); font-style: italic; }
.editor.is-rec #editor-text { border-color: color-mix(in srgb, var(--rec) 45%, var(--line)); }
.yearly { border-top: 1px solid var(--line); padding-top: 10px; display: flex; flex-direction: column; gap: 8px; font-size: .9rem; }
.yearly-item { display: flex; flex-direction: column; gap: 2px; }
button.link { border: 0; background: none; padding: 2px 0; color: var(--accent); text-align: left; text-decoration: underline; text-underline-offset: 2px; }
button.link:hover { background: none; filter: brightness(1.15); }

.import { width: min(680px, 94vw); max-height: 90vh; }
.import p { margin: 0 0 12px; font-size: .9rem; }
#import-file { font: inherit; margin-bottom: 8px; max-width: 100%; }
.import-preview { font-size: .9rem; }
.import-preview ul { padding-left: 20px; margin: 8px 0 12px; }
.import-preview li { margin-bottom: 4px; }
.import-preview .skipped { max-height: 9rem; overflow: auto; font-size: .8rem; color: var(--muted); }
.import-preview .warn { color: #c0392b; }
.import-preview .summary { font-size: .95rem; margin-top: 8px; }
#import-progress { width: 100%; margin: 8px 0; accent-color: var(--accent); }

.history-wrap:has(#history-btn[hidden]) { display: none; }
.history { margin-top: 8px; max-height: 16rem; overflow: auto; display: flex; flex-direction: column; gap: 8px; }
.hv { border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; background: var(--bg); font-size: .85rem; }
.hv-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; color: var(--muted); font-size: .8rem; margin-bottom: 4px; }
.hv-text { max-height: 6rem; overflow: auto; }

.banner {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap; padding: 8px 16px; font-size: .88rem;
  background: color-mix(in srgb, #e6a700 18%, var(--surface)); border-bottom: 1px solid color-mix(in srgb, #e6a700 45%, var(--line));
}
.banner span { flex: 1; min-width: 12rem; }
.banner button { padding: 4px 10px; font-size: .85rem; }
.banner button.icon { width: 28px; height: 28px; }

/* ── Floating bits ── */
.kb-hint, .toast {
  position: fixed; left: 50%; transform: translateX(-50%); z-index: 50;
  border-radius: 99px; padding: 8px 16px; box-shadow: var(--shadow);
}
.kb-hint { bottom: 24px; background: var(--ink); color: var(--bg); font: 600 1rem ui-monospace, Menlo, monospace; letter-spacing: .1em; }
.toast {
  bottom: 72px; background: var(--surface); border: 1px solid var(--line); font-size: .9rem; max-width: calc(100vw - 32px);
  display: flex; align-items: center; gap: 14px;
}
.toast[hidden] { display: none; }
.toast-btn { white-space: nowrap; border: 0; background: none; padding: 2px 4px; color: var(--accent); font-weight: 700; }
.toast-btn:hover { background: none; text-decoration: underline; }
.toast.error { border-color: #c0392b; color: #c0392b; }

/* ── Desktop / mobile switch (keep in sync with app.js: 760px) ── */
@media (min-width: 761px) { .mobile-only { display: none !important; } }
@media (max-width: 760px) {
  .desktop-only { display: none !important; }
  .bar { flex-wrap: wrap; padding: 10px 16px; gap: 8px; padding-top: max(10px, env(safe-area-inset-top)); }
  .app-title { margin: 0; font-size: 1.2rem; flex: 1; }
  .tools { width: 100%; flex-wrap: wrap; }
  .search { flex: 1; min-width: 0; }
  #search { width: 100%; font-size: 16px; } /* 16px stops iOS zooming */
  .mobile-opts { order: 3; width: 100%; display: flex; align-items: center; justify-content: space-between; gap: 12px; }
  .seg { display: inline-flex; border: 1px solid var(--line); border-radius: 9px; padding: 2px; background: var(--bg); }
  .seg button { border: 0; background: transparent; padding: 5px 12px; font-size: .85rem; color: var(--muted); border-radius: 7px; }
  .seg button.on { background: var(--surface); color: var(--ink); font-weight: 600; box-shadow: 0 1px 2px rgba(0,0,0,.12); }
  dialog.editor {
    width: 100vw; max-width: 100vw; height: 100dvh; max-height: 100dvh;
    margin: 0; border-radius: 0; border: 0; padding: 16px;
    padding-top: max(16px, env(safe-area-inset-top));
  }
  .editor form { height: 100%; }
  #editor-text { flex: 1; min-height: 8rem; font-size: 16px; }
  .editor-actions { flex-wrap: wrap; }
  .meta { width: 100%; flex-basis: 100%; }
}
