/* The Big Calendar
   Layout: one sheet, 12 month rows × 31 day columns, like the wall poster.
   Stickers fill cells; marker notes spill freely across them. */
:root {
  --page: #dfe7f3;
  --paper: #ffffff;
  --ink: #2457b3;
  --ink-strong: #163a80;
  --line: #a9bfe2;
  --weekend: #dde9f8;
  --muted: #5a6c8f;
  --marker: #1c1d22;
  --void: #eef2f8;
  --sel: rgba(36, 87, 179, .22);
  --sticker-ink: #1c1d22;
  --shadow: rgba(22, 58, 128, .14);
  --danger: #b4261e;
  --ok: #1f7a3d;

  --s-purple: #a95bd9;
  --s-yellow: #f3e66c;
  --s-orange: #f2a14c;
  --s-red: #e4493f;
  --s-green: #a7dc5e;
  --s-blue: #62b9ee;
  --s-pink: #f190ba;

  --f-display: "Big Shoulders Display", "Arial Narrow", Impact, sans-serif;
  --f-hand: "Caveat", "Bradley Hand", "Segoe Print", cursive;
  --f-ui: "IBM Plex Sans Condensed", "Arial Narrow", system-ui, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --page: #0c1220; --paper: #131c30; --ink: #8db0ff; --ink-strong: #c4d5ff;
    --line: #2b3b5f; --weekend: #1a2845; --muted: #8b9bbd; --marker: #edf0f6;
    --void: #172036; --sel: rgba(141, 176, 255, .25); --shadow: rgba(0, 0, 0, .4);
    --danger: #ff8a80; --ok: #7ddc9a;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--page); color: var(--ink-strong);
  font-family: var(--f-ui); font-size: 15px; line-height: 1.4;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  padding-block: max(20px, env(safe-area-inset-top, 0px)) max(32px, env(safe-area-inset-bottom, 0px));
}
button, input, textarea, select { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--ink-strong); outline-offset: 1px; }
a { color: var(--ink); }
[hidden] { display: none !important; }

.btn {
  border: 1.5px solid var(--ink); background: var(--paper); color: var(--ink);
  border-radius: 999px; padding: 6px 14px; font-weight: 600; font-size: 14px; cursor: pointer;
  text-decoration: none; display: inline-flex; align-items: center; gap: 6px; white-space: nowrap;
}
.btn:hover { background: var(--weekend); }
.btn.primary { background: var(--ink); color: var(--paper); }
.btn.primary:hover { background: var(--ink-strong); }
.btn.danger { border-color: var(--danger); color: var(--danger); }
.btn.small { padding: 3px 10px; font-size: 13px; }
.btn.link { border: 0; padding: 0; background: none; color: var(--ink); text-decoration: underline; font-weight: 500; }

/* ---------- Auth pages ---------- */
.auth {
  max-width: 420px; margin: 8vh auto 0; background: var(--paper); border-radius: 8px;
  padding: 28px 24px; box-shadow: 0 2px 0 var(--shadow), 0 18px 40px -20px var(--shadow);
  display: grid; gap: 16px;
}
.wordmark {
  margin: 0; font-family: var(--f-display); font-weight: 800; text-transform: uppercase;
  color: var(--ink); line-height: .9; font-size: 2.6rem; text-wrap: balance;
}
.auth h2 { margin: 0; font-size: 18px; font-weight: 600; }
.auth p { margin: 0; color: var(--muted); }
.auth form { display: grid; gap: 14px; }
.auth .foot { font-size: 14px; display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.errorlist { list-style: none; margin: 0; padding: 0; color: var(--danger); font-size: 13px; }
.form-error { color: var(--danger); font-size: 14px; margin: 0; }
.helptext { font-size: 12px; color: var(--muted); font-weight: 400; }
.helptext ul { margin: 4px 0 0; padding-left: 18px; }

.field { display: grid; gap: 4px; font-size: 13px; font-weight: 600; color: var(--muted); }
.field input, .field textarea, .field select {
  border: 1.5px solid var(--line); border-radius: 5px; padding: 8px 10px; background: var(--paper);
  font-weight: 400; font-size: 15px; color: var(--ink-strong); min-width: 0; width: 100%;
}
.field input:focus, .field textarea:focus { border-color: var(--ink); outline: none; }

/* ---------- Calendar sheet ---------- */
.sheet {
  max-width: 1800px; margin: 0 auto; background: var(--paper); border-radius: 6px;
  box-shadow: 0 2px 0 var(--shadow), 0 18px 40px -20px var(--shadow);
  padding: 20px clamp(12px, 2vw, 32px) 18px; display: grid; gap: 14px;
}
.top { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 12px 24px; }
h1.wordmark { font-size: clamp(2rem, 5.2vw, 4rem); }
.yearnav { display: inline-flex; align-items: center; gap: 2px; }
.yearnav button {
  border: 0; background: none; cursor: pointer; color: var(--ink);
  font-family: var(--f-display); font-weight: 800; font-size: .7em; padding: 0 .15em; line-height: 1; opacity: .45;
}
.yearnav button:hover { opacity: 1; }
#yearLabel { font-variant-numeric: tabular-nums; }

.tools { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.calpick {
  border: 1.5px solid var(--ink); border-radius: 999px; padding: 6px 30px 6px 14px; font-weight: 600; font-size: 14px;
  color: var(--ink); background: var(--paper); cursor: pointer; max-width: 16rem;
  appearance: none; -webkit-appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--ink) 50%), linear-gradient(135deg, var(--ink) 50%, transparent 50%);
  background-position: calc(100% - 16px) 55%, calc(100% - 11px) 55%; background-size: 5px 5px; background-repeat: no-repeat;
}

.subbar { display: flex; flex-wrap: wrap; gap: 8px 20px; align-items: center; justify-content: space-between; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; align-items: center; }
.legend .lab, .eyebrow { font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); font-weight: 600; }
.chip { display: inline-flex; align-items: center; gap: 6px; }
.swatch { width: 18px; height: 18px; border-radius: 3px; flex: none; box-shadow: inset 0 0 0 1px rgba(0,0,0,.12); }
.chip input {
  border: 0; border-bottom: 1px dashed transparent; background: none; padding: 2px 0;
  width: 9ch; field-sizing: content; min-width: 4ch; font-size: 14px; color: var(--ink-strong);
}
.chip input:hover, .chip input:focus { border-bottom-color: var(--line); outline: none; }

.account { display: flex; gap: 12px; align-items: center; font-size: 13px; color: var(--muted); flex-wrap: wrap; }
.account form { display: inline; }
.sync { display: inline-flex; align-items: center; gap: 6px; }
.sync::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--ok); }
.sync.busy::before { background: var(--ink); opacity: .5; }
.sync.err::before { background: var(--danger); }
.sync.err { color: var(--danger); }

.board-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.board {
  min-width: 1040px; container-type: inline-size;
  border-top: 2px solid var(--ink); border-left: 2px solid var(--ink);
  --lab: 3.4rem;
  --rowh: calc((100cqi - 3.4rem) / 31 * 1.5);
  user-select: none; -webkit-user-select: none;
}
.board.loading { opacity: .5; }
.month-row { display: grid; grid-template-columns: var(--lab) repeat(31, minmax(0, 1fr)); grid-template-rows: var(--rowh); }
.mlabel {
  grid-row: 1; grid-column: 1; display: flex; align-items: center; justify-content: center;
  font-family: var(--f-display); font-weight: 800; font-size: clamp(16px, 1.6cqi, 26px);
  color: var(--ink); border-right: 2px solid var(--ink); border-bottom: 1px solid var(--line);
}
.month-row:last-child > .mlabel, .month-row:last-child > .day, .month-row:last-child > .void {
  border-bottom-color: var(--ink); border-bottom-width: 2px;
}
.day, .void {
  grid-row: 1; border: 0; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line);
  background: var(--paper); padding: 2px 3px 0; margin: 0;
  display: flex; align-items: flex-start; gap: 3px;
  font-size: clamp(8px, .72cqi, 11px); line-height: 1; color: var(--ink);
  min-width: 0; cursor: crosshair; text-align: left;
}
.day.d31, .void.d31 { border-right: 2px solid var(--ink); }
.day.wknd { background: var(--weekend); }
.day .dnum { font-weight: 600; font-variant-numeric: tabular-nums; }
.day .dow { opacity: .7; text-transform: uppercase; letter-spacing: .02em; }
.day.today { box-shadow: inset 0 0 0 2px var(--ink); }
.day.sel { background: var(--sel); }
.void { cursor: default; background: repeating-linear-gradient(135deg, var(--void) 0 4px, var(--paper) 4px 8px); }

.item {
  grid-row: 1; position: relative; z-index: 2; border: 0; padding: 0 4px;
  margin: clamp(11px, 1.05cqi, 15px) 2px 2px; min-width: 0; cursor: pointer; text-align: left;
  font-family: var(--f-hand); font-weight: 700; line-height: .95; font-size: clamp(13px, 1.15cqi, 19px);
  display: flex; align-items: center; overflow: visible;
}
.item.sticker { background: var(--c); color: var(--sticker-ink); border-radius: 2px; box-shadow: 0 1px 0 rgba(0,0,0,.18); }
.item.sticker .txt { overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; }
/* One-day stickers let their label spill onto the neighbors, like marker on the poster. */
.item.sticker.single .txt { display: block; overflow: visible; width: max-content; max-width: 6.5em; white-space: normal; }
.item.sticker.cont-l { margin-left: 0; border-top-left-radius: 0; border-bottom-left-radius: 0; }
.item.sticker.cont-r { margin-right: 0; border-top-right-radius: 0; border-bottom-right-radius: 0; }
.item.note { background: transparent; color: var(--marker); justify-content: center; z-index: 3; }
.item.note .txt { display: block; flex: none; min-width: 100%; width: max-content; max-width: max(100%, 6.5em); text-align: center; white-space: normal; }
.item.note.multi .span { display: flex; align-items: center; gap: 3px; width: 100%; }
.item.note.multi .rule { flex: 1; height: 1.5px; background: var(--marker); min-width: 4px; }
.item.note.multi .arrow { font-family: var(--f-ui); font-weight: 600; font-size: .8em; }
.item.note.multi .txt { min-width: 0; width: auto; max-width: none; white-space: nowrap; }
.item:hover { filter: brightness(1.04); outline: 1.5px dashed var(--ink); outline-offset: 1px; }
.item.pending { opacity: .6; }

.hint { margin: 0; font-size: 13px; color: var(--muted); }
.hint b { color: var(--ink-strong); font-weight: 600; }

/* ---------- Dialogs ---------- */
dialog {
  border: 0; border-radius: 8px; padding: 0; background: var(--paper); color: var(--ink-strong);
  width: min(460px, calc(100vw - 32px)); max-height: calc(100vh - 48px); overflow: auto;
  box-shadow: 0 30px 60px -20px rgba(0,0,0,.45);
}
dialog::backdrop { background: rgba(10, 20, 40, .45); }
dialog > form, dialog > .dlg { display: grid; gap: 14px; padding: 20px; }
dialog h2 { margin: 0; font-family: var(--f-display); font-weight: 800; font-size: 28px; text-transform: uppercase; color: var(--ink); line-height: 1; }
dialog p { margin: 0; }
.field input#edLabel { font-family: var(--f-hand); font-size: 22px; font-weight: 700; padding-block: 4px; }
.field textarea { font-family: ui-monospace, Menlo, monospace; font-size: 12px; min-height: 180px; resize: vertical; }
.dates { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
fieldset { border: 0; margin: 0; padding: 0; display: grid; gap: 6px; }
legend { font-size: 13px; font-weight: 600; color: var(--muted); padding: 0; margin-bottom: 4px; }
.colors { display: grid; grid-template-columns: repeat(auto-fill, minmax(118px, 1fr)); gap: 6px; }
.colors label {
  display: flex; align-items: center; gap: 7px; padding: 5px 8px; border-radius: 5px;
  border: 1.5px solid var(--line); cursor: pointer; font-size: 13px; min-width: 0;
}
.colors label span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.colors input { position: absolute; opacity: 0; pointer-events: none; }
.colors label:has(input:checked) { border-color: var(--ink); background: var(--weekend); }
.colors label:has(input:focus-visible) { outline: 2px solid var(--ink-strong); }
.swatch.none { background: transparent; box-shadow: inset 0 0 0 1.5px var(--marker); position: relative; }
.swatch.none::after { content: "✎"; position: absolute; inset: 0; display: grid; place-items: center; font-size: 11px; color: var(--marker); }
.actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.actions .spacer { flex: 1; }
.err { color: var(--danger); font-size: 13px; margin: 0; min-height: 1em; }
.note-text { font-size: 14px; color: var(--muted); }

.people { list-style: none; margin: 0; padding: 0; display: grid; border-top: 1px solid var(--line); }
.people li { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--line); min-width: 0; }
.people .who { flex: 1; min-width: 0; display: grid; }
.people .who b { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.people .who span { font-size: 13px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tag { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); border: 1px solid var(--line); border-radius: 999px; padding: 1px 7px; }
.inline-form { display: flex; gap: 8px; align-items: center; }
.textin, .copyline input {
  border: 1.5px solid var(--line); border-radius: 5px; padding: 6px 10px; background: var(--paper);
  color: var(--ink-strong); font-size: 15px;
}
.textin:focus { border-color: var(--ink); outline: none; }
.inline-form input { flex: 1; min-width: 0; }
.copyline { display: flex; gap: 8px; }
.copyline input { flex: 1; min-width: 0; font-size: 12px; }

.toast {
  position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom, 0px)); transform: translateX(-50%);
  background: var(--ink-strong); color: var(--paper); padding: 8px 16px; border-radius: 999px;
  font-size: 14px; font-weight: 600; z-index: 20; max-width: calc(100vw - 32px);
}
.toast.bad { background: var(--danger); }

@media (max-width: 640px) {
  .sheet { padding: 16px 12px; }
  .dates { grid-template-columns: 1fr; }
}
@media (prefers-reduced-motion: no-preference) {
  .item { transition: filter .12s, opacity .12s; }
}
