:root {
  --bg: #f2f2f2;
  --card: #ffffff;
  --ink: #111111;
  --mute: #8a8a8a;
  --line: #e4e4e4;
  --holiday: #a16207;
  --holy: #6b21a8;
  --holiday-tag: #facc15;
  --holiday-ink: #422006;
  --accent: #2563eb;
  --radius: 12px;
  color-scheme: light;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); }
body { font-family: 'Inter', system-ui, -apple-system, sans-serif; -webkit-font-smoothing: antialiased; }
button, input, select { font: inherit; color: inherit; }
.hide { display: none !important; }

/* ---------- header ---------- */
.top {
  display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap;
  padding: 18px max(16px, env(safe-area-inset-left)) 10px; max-width: 1680px; margin: 0 auto;
}
.brand { display: flex; align-items: center; gap: 14px; }
.logo { width: 44px; height: auto; }
h1 { margin: 0; font-size: 26px; font-weight: 900; letter-spacing: .04em; text-transform: uppercase; }
.sub { margin: 2px 0 0; color: var(--mute); font-size: 13px; }
.actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.btn {
  border: 0; background: var(--ink); color: #fff; font-weight: 700; font-size: 13px;
  padding: 9px 14px; border-radius: 999px; cursor: pointer;
}
.btn.ghost { background: #fff; color: var(--ink); border: 1px solid var(--line); }
.btn.blue { background: var(--accent); }
.btn.danger { background: #fff; color: #b91c1c; border: 1px solid #f1c4c4; }
.btn:disabled { opacity: .5; cursor: default; }
.save { font-size: 12px; color: var(--mute); min-width: 60px; text-align: right; }
.save.err { color: #b91c1c; font-weight: 700; }

main { max-width: 1680px; margin: 0 auto; padding: 0 max(16px, env(safe-area-inset-left)) 40px; }

/* ---------- pulpit counter ---------- */
.pulpit { display: flex; gap: 10px; flex-wrap: wrap; margin: 6px 0 12px; }
.pc {
  background: var(--card); border-radius: var(--radius); padding: 10px 14px; min-width: 190px;
  border-left: 6px solid var(--c, var(--ink)); display: grid; gap: 2px;
}
.pc b { font-size: 15px; font-weight: 800; }
.pc .big { font-size: 22px; font-weight: 900; line-height: 1.1; }
.pc small { color: var(--mute); font-size: 12px; }

/* ---------- guide (collapsible legend) ---------- */
.guide { margin-bottom: 14px; }
.guide > summary {
  list-style: none; cursor: pointer; display: inline-flex; align-items: center; gap: 8px;
  background: var(--card); border-radius: 999px; padding: 7px 14px; font-weight: 800; font-size: 13px; user-select: none;
}
.guide > summary::-webkit-details-marker { display: none; }
.guide > summary::before { content: '▸'; font-size: 11px; transition: transform .15s; }
.guide[open] > summary::before { transform: rotate(90deg); }
.guide > summary .muted { font-weight: 500; color: var(--mute); font-size: 12px; }
.guide[open] > summary { margin-bottom: 8px; }
.guide .legend { margin-bottom: 0; }

/* ---------- legend ---------- */
.legend {
  display: flex; flex-wrap: wrap; gap: 6px 14px; align-items: center;
  background: var(--card); border-radius: var(--radius); padding: 10px 14px; margin-bottom: 14px; font-size: 12px;
}
.legend .grp { font-weight: 800; text-transform: uppercase; letter-spacing: .08em; font-size: 10px; color: var(--mute); margin-right: -6px; }
.legend .it { display: inline-flex; align-items: center; gap: 6px; }
.sw { width: 12px; height: 12px; border-radius: 3px; display: inline-block; flex: none; }
.legend .dates { color: var(--mute); }
.hint { font-size: 13px; color: var(--accent); font-weight: 600; margin: -4px 0 12px; }

/* ---------- year grid ---------- */
.year { display: grid; grid-template-columns: 1fr; gap: 16px; max-width: 1280px; margin: 0 auto; }
.month { scroll-margin-top: 56px; }

/* Month jump bar: stays at the top while scrolling. */
.mnav {
  position: sticky; top: 0; z-index: 10; display: flex; gap: 4px; flex-wrap: wrap; justify-content: center;
  max-width: 1280px; margin: 0 auto 12px; padding: 8px 0; background: var(--bg);
}
.mnav a {
  text-decoration: none; color: var(--ink); background: var(--card); border-radius: 999px;
  padding: 5px 11px; font-size: 12px; font-weight: 800; letter-spacing: .04em; text-transform: uppercase;
}
.mnav a:hover { background: var(--ink); color: #fff; }

.month { background: var(--card); border-radius: var(--radius); padding: 12px 10px 8px; }
.month h2 { margin: 0 0 6px 2px; font-size: 18px; font-weight: 900; text-transform: uppercase; letter-spacing: .06em; }
/* Sun..Sat widths; keep in sync with COLW in app.js. Tuesday is wider for midweek themes. */
.grid { display: grid; grid-template-columns: minmax(0, 1.9fr) minmax(0, 1fr) minmax(0, 1.45fr) repeat(4, minmax(0, 1fr)); font-size: 11px; }
.wd { color: var(--mute); font-size: 9px; font-weight: 800; letter-spacing: .08em; padding: 0 4px 5px; }
.cell {
  min-height: 38px; padding: 3px 4px 4px; border-top: 1px solid var(--line); position: relative;
  overflow: hidden; cursor: pointer; text-align: left; background: none; border-left: 0; border-right: 0; border-bottom: 0;
  display: flex; flex-direction: column; gap: 1px; min-width: 0;
}
.cell.empty { cursor: default; }
.cell:not(.empty):not(.sun):hover { background: #f7f7f7; }
.cell.today .n { background: var(--ink); color: #fff; border-radius: 999px; padding: 0 5px; align-self: flex-start; }
.n { color: var(--mute); font-size: 11px; font-weight: 600; }
.cell.past .n { opacity: .6; }

.sun { border-top: 0; border-radius: 8px; margin: 3px 4px 3px 0; background: #f6f6f6; color: var(--ink); }
.sun.has-series { color: #fff; }
.sun.has-series .n { color: rgba(255,255,255,.8); }
.sun:hover { filter: brightness(1.05); }
.who { font-weight: 800; font-size: 12.5px; line-height: 1.1; overflow-wrap: break-word; }
.who.none { font-weight: 600; opacity: .55; font-size: 11px; }
.sun:not(.has-series) .who:not(.none) { color: var(--pc, var(--ink)); }
.ser { font-size: 8.5px; font-weight: 800; text-transform: uppercase; letter-spacing: .03em; opacity: .9; line-height: 1.15;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.sacred {
  align-self: flex-start; font-size: 8.5px; font-weight: 900; letter-spacing: .06em; text-transform: uppercase;
  background: #fff; color: #111; border-radius: 4px; padding: 1px 4px; margin: 1px 0;
}
.sun:not(.has-series) .sacred { background: #111; color: #fff; }
/* Away: orange stripes with a solid orange banner carrying the trip name. */
.cell.away:not(.sun) { background: repeating-linear-gradient(135deg, #fed7aa 0 6px, #fff7ed 6px 12px); overflow: visible; }
.cell.away:not(.sun):hover { background: repeating-linear-gradient(135deg, #fdba74 0 6px, #ffedd5 6px 12px); }
.sun.away { box-shadow: inset 0 0 0 3px #fff, inset 0 0 0 6px #ea580c; }
.awsp { display: block; height: calc(var(--rows, 1) * 17px); flex: none; }
/* Holy Week: royal purple stripes, a "Holy Week" banner, and each day's title. */
.cell.holy:not(.sun) { background: repeating-linear-gradient(135deg, #e9d5ff 0 6px, #faf5ff 6px 12px); overflow: visible; }
.cell.holy:not(.sun):hover { background: repeating-linear-gradient(135deg, #d8b4fe 0 6px, #f3e8ff 6px 12px); }
.hwb {
  position: absolute; left: 2px; top: 19px; z-index: 3; height: 15px; line-height: 13px; padding: 1px 5px;
  width: calc(var(--span, 1) * 100% - 4px); background: var(--holy); color: #fff; border-radius: 4px;
  font-size: 9px; font-weight: 800; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  box-shadow: 0 1px 2px rgba(59, 7, 100, .35);
}
.hwd { font-size: 9px; font-weight: 800; color: var(--holy); line-height: 1.15; overflow-wrap: break-word; hyphens: auto; }
.holy-sw { background: repeating-linear-gradient(135deg, #6b21a8 0 3px, #faf5ff 3px 6px); border: 1px solid #6b21a8; }
.awl { font-size: 9px; font-weight: 800; line-height: 1.2; background: #ea580c; color: #fff; border-radius: 4px; padding: 1px 5px; }
.sun .awl { align-self: flex-start; overflow-wrap: break-word; }
.cell:not(.sun) .awl {
  position: absolute; left: 2px; top: calc(19px + var(--row, 0) * 17px); z-index: 2; height: 15px; line-height: 13px;
  width: calc(var(--span, 1) * 100% - 4px); white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  box-shadow: 0 1px 2px rgba(154, 52, 18, .35);
}
.away-sw { background: repeating-linear-gradient(135deg, #ea580c 0 3px, #fff7ed 3px 6px); border: 1px solid #ea580c; }
.away-row { background: repeating-linear-gradient(135deg, #fed7aa 0 6px, #fff7ed 6px 12px); }
.gap {
  align-self: flex-start; font-size: 8.5px; font-weight: 800; border-radius: 999px; padding: 0 5px; margin: 1px 0;
  background: rgba(17, 17, 17, .08); color: inherit;
}
.sun.has-series .gap { background: rgba(255, 255, 255, .28); color: #fff; }
/* Tuesday midweek: a see-through tint of its series color, lighter than Sundays. */
.cell.mid:not(.holy) { background: color-mix(in srgb, var(--mc) 14%, transparent); }
.cell.mid { box-shadow: inset 3px 0 0 color-mix(in srgb, var(--mc) 70%, transparent); }
.cell.mid:not(.holy):hover { background: color-mix(in srgb, var(--mc) 22%, transparent); }
/* Soft-box event days (e.g. Leadership development): tinted day, darker label. */
.cell.evbox:not(.holy):not(.away) { background: color-mix(in srgb, var(--bc) 18%, transparent); }
.cell.evbox { box-shadow: inset 3px 0 0 var(--bc); }
.cell.evbox:not(.holy):not(.away):hover { background: color-mix(in srgb, var(--bc) 26%, transparent); }
.cell.evbox .ev { color: color-mix(in srgb, var(--ec) 55%, #111); }
.mser { font-size: 8px; font-weight: 900; text-transform: uppercase; letter-spacing: .02em; color: var(--mc); line-height: 1.15;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.cell:not(.sun) { padding-left: 3px; padding-right: 3px; }
.cell:not(.sun) .hol, .cell:not(.sun) .ev, .hwd { font-size: 8.5px; letter-spacing: -.01em; }
.mttl {
  font-size: 9px; font-weight: 600; line-height: 1.15; color: color-mix(in srgb, var(--mc) 80%, #111);
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; overflow-wrap: normal; word-break: normal; hyphens: none;
}
.sw-tue { background: color-mix(in srgb, var(--c) 22%, #fff) !important; box-shadow: inset 3px 0 0 var(--c); }
.dgrp { margin: 8px 0 0; font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--mute); }
.item-tue { background: color-mix(in srgb, var(--c) 6%, #fff); }
.ttl { font-size: 9.5px; font-weight: 600; line-height: 1.15; opacity: .95;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
/* Sunday top line: date, Sacred tag and rotation badge side by side. */
.shead { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; min-width: 0; }
.shead .gap, .shead .sacred { margin: 0; }
.note { font-size: 9.5px; font-style: italic; opacity: .9; line-height: 1.15; overflow-wrap: anywhere; }
.hol {
  font-size: 9px; font-weight: 800; color: var(--holiday); line-height: 1.15; overflow-wrap: break-word; hyphens: auto;
}
.sun .hol { background: var(--holiday-tag); color: var(--holiday-ink); border-radius: 4px; padding: 1px 4px; align-self: flex-start; }
.sun.has-series .hol { box-shadow: 0 1px 2px rgba(0,0,0,.25); }
.ev { font-size: 9px; font-weight: 700; line-height: 1.15; overflow-wrap: break-word; hyphens: auto; color: var(--ec, var(--ink)); }
.sun.has-series .ev { color: #fff; opacity: .95; }
.sun.has-series .ev::before { content: '• '; }

body.editing .cell:not(.empty) { outline: 1px dashed transparent; }
body.editing .cell:not(.empty):hover { outline-color: var(--accent); }

/* ---------- dialog ---------- */
dialog {
  border: 0; border-radius: 16px; padding: 0; width: min(440px, calc(100vw - 32px));
  box-shadow: 0 20px 60px rgba(0,0,0,.25);
}
dialog::backdrop { background: rgba(15, 15, 20, .45); }
#dlgBody { padding: 18px; display: grid; gap: 12px; }
.dh { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.dh h3 { margin: 0; font-size: 18px; font-weight: 900; }
.dh small { color: var(--mute); display: block; margin-top: 2px; }
.x { border: 0; background: #f0f0f0; width: 32px; height: 32px; border-radius: 999px; font-size: 20px; line-height: 1; cursor: pointer; flex: none; }
.lbl { font-size: 11px; font-weight: 800; text-transform: uppercase; letter-spacing: .08em; color: var(--mute); }
.pick { display: flex; flex-wrap: wrap; gap: 6px; }
.pick button {
  border: 2px solid var(--c); background: #fff; color: var(--c); font-weight: 800; border-radius: 999px;
  padding: 7px 12px; cursor: pointer; font-size: 13px;
}
.pick button.on { background: var(--c); color: #fff; }
.field { display: grid; gap: 4px; }
.field input, .field select, .row input, .row select {
  border: 1px solid #d6d6d6; border-radius: 10px; padding: 9px 10px; background: #fff; width: 100%; min-width: 0;
}
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.check { display: flex; align-items: center; gap: 8px; font-size: 14px; }
.check input { width: 18px; height: 18px; }
.btns { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }
.evlist { display: grid; gap: 6px; }
.evrow {
  display: flex; align-items: center; gap: 8px; padding: 8px 10px; border-radius: 10px; background: #f6f6f6;
  border: 0; text-align: left; cursor: pointer; width: 100%;
}
.evrow .t { font-weight: 700; flex: 1; }
.evrow small { color: var(--mute); }
.err { color: #b91c1c; font-size: 13px; font-weight: 600; }
.ro { display: grid; gap: 6px; font-size: 14px; }
.ro .pill { display: inline-block; color: #fff; border-radius: 999px; padding: 3px 10px; font-weight: 800; font-size: 12px; }

/* ---------- drawer ---------- */
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(460px, 100vw); background: #fff; z-index: 20;
  box-shadow: -10px 0 40px rgba(0,0,0,.18); transform: translateX(105%); transition: transform .2s ease;
  display: flex; flex-direction: column;
}
.drawer.open { transform: none; }
.drawer-head { display: flex; justify-content: space-between; align-items: center; padding: 14px 16px; border-bottom: 1px solid var(--line); gap: 8px; }
.tabs { display: flex; gap: 4px; background: #f0f0f0; padding: 3px; border-radius: 999px; }
.tab { border: 0; background: none; padding: 7px 12px; border-radius: 999px; font-weight: 700; font-size: 13px; cursor: pointer; }
.tab.on { background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.12); }
.drawer-body { padding: 16px; overflow: auto; display: grid; gap: 12px; align-content: start; }
.item { border: 1px solid var(--line); border-radius: 12px; padding: 12px; display: grid; gap: 8px; border-left: 6px solid var(--c, #ccc); }
.item .row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.colors { display: flex; flex-wrap: wrap; gap: 6px; }
.colors button { width: 26px; height: 26px; border-radius: 999px; border: 3px solid #fff; box-shadow: 0 0 0 1px #ddd; cursor: pointer; background: var(--c); }
.colors button.on { box-shadow: 0 0 0 2px var(--ink); }
.item-foot { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.item-foot small { color: var(--mute); }

/* ---------- laptop / desktop views: 1 month (full width, bigger text) or 3 months (compact) ---------- */
@media screen and (min-width: 681px) {
  body.v3 .year { grid-template-columns: repeat(3, minmax(0, 1fr)); max-width: none; gap: 14px; }
  body.v3 .mnav { max-width: none; }
}
@media screen and (min-width: 681px) {
  body.v1 .month { padding: 16px 16px 12px; }
  body.v1 .month h2 { font-size: 22px; margin-bottom: 8px; }
  body.v1 .grid { font-size: 12px; }
  body.v1 .wd { font-size: 10px; }
  body.v1 .cell { min-height: 64px; padding: 5px 7px 6px; }
  body.v1 .cell:not(.sun) { padding-left: 7px; padding-right: 7px; }
  body.v1 .n { font-size: 12px; }
  body.v1 .who { font-size: 15px; }
  body.v1 .ser { font-size: 10px; }
  body.v1 .ttl { font-size: 12px; }
  body.v1 .note { font-size: 11px; }
  body.v1 .gap, body.v1 .sacred { font-size: 10px; }
  body.v1 .mser { font-size: 10px; }
  body.v1 .mttl { font-size: 12px; }
  body.v1 .hol, body.v1 .ev, body.v1 .hwd, body.v1 .cell:not(.sun) .hol, body.v1 .cell:not(.sun) .ev, body.v1 .hwd { font-size: 11px; letter-spacing: 0; }
  body.v1 .awl, body.v1 .sun .awl { font-size: 11px; }
  body.v1 .hwb, body.v1 .cell:not(.sun) .awl { top: calc(24px + var(--row, 0) * 22px); height: 19px; line-height: 17px; font-size: 11px; padding: 1px 7px; }
  body.v1 .awsp { height: calc(var(--rows, 1) * 22px); }
}

/* View switch */
.views { display: inline-flex; background: #fff; border: 1px solid var(--line); border-radius: 999px; padding: 2px; }
.views button { border: 0; background: none; font-weight: 700; font-size: 13px; padding: 7px 12px; border-radius: 999px; cursor: pointer; }
.views button.on { background: var(--ink); color: #fff; }

/* ---------- phone ---------- */
@media (max-width: 680px) {
  h1 { font-size: 22px; }
  .logo { width: 36px; }
  .pc { min-width: 0; flex: 1 1 140px; }
  .cell { min-height: 58px; }
  .grid { font-size: 12px; }
  .who { font-size: 14px; }
  .ser, .ttl, .note, .sun .hol, .sun .ev { font-size: 10.5px; }
  .sacred, .gap { font-size: 9.5px; }
  .cell:not(.sun) .mser, .cell:not(.sun) .mttl { display: none; }
  .cell:not(.sun) .awl { position: static; font-size: 0; width: 100%; height: 5px; padding: 0; border-radius: 3px; margin-top: 2px; flex: none; box-shadow: none; }
  .awsp { display: none; }
  .hwb { position: static; font-size: 0; width: 100%; height: 5px; padding: 0; border-radius: 3px; margin-top: 2px; flex: none; box-shadow: none; }
  .hwd { font-size: 0; width: 100%; height: 0; }
  .sun .awl { font-size: 9.5px; }
  #editBtn, #manageBtn, .views { display: none; }
  /* Weekday cells are too narrow for words on a phone: show a colored mark,
     tap the day for the details. Sundays keep their words. */
  .cell:not(.sun) .hol, .cell:not(.sun) .ev {
    font-size: 0; width: 100%; height: 5px; border-radius: 3px; margin-top: 2px; flex: none;
  }
  .cell:not(.sun) .hol { background: var(--holiday-tag); }
  .cell:not(.sun) .ev { background: var(--ec, var(--ink)); }
}

/* ---------- print: one landscape tabloid page ---------- */
@media print {
  @page { size: 17in 11in; margin: .35in; }
  html, body { background: #fff; }
  body { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .actions, .hint, .drawer, dialog, .mnav, .views { display: none !important; }
  .year { max-width: none; }
  .top { padding: 0 0 6px; max-width: none; }
  .logo { width: 30px; }
  h1 { font-size: 18px; }
  .sub { font-size: 10px; }
  main { padding: 0; max-width: none; }
  .pulpit { margin: 0 0 6px; gap: 6px; }
  .pc { padding: 4px 8px; border: 1px solid var(--line); border-left-width: 5px; min-width: 0; }
  .pc .big { font-size: 13px; }
  .pc b, .pc small { font-size: 9px; }
  .legend { padding: 4px 0; margin-bottom: 6px; font-size: 9px; }
  .year { grid-template-columns: repeat(4, 1fr) !important; gap: 6px; }
  .month { padding: 6px; border: 1px solid var(--line); break-inside: avoid; }
  .month h2 { font-size: 11px; margin-bottom: 4px; }
  .cell { min-height: 30px; padding: 2px; }
  .sun { margin: 1px 2px 1px 0; border-radius: 4px; }
  .who { font-size: 9px; }
  .n { font-size: 8px; }
  .ser, .ttl, .note, .hol, .ev, .sacred, .awl, .hwb, .hwd, .gap, .mser, .mttl { font-size: 7px; }
  .guide > summary { display: none; }
  .wd { font-size: 7px; padding-bottom: 2px; }
}
