/* =============================================================
   calendar.css — Academic Calendar
   Mobile-first. Theme-aware: surfaces and text come from style.css
   tokens; the calendar's own colours are defined below for each of
   the site's themes — dark (:root default), light and oled.
   ============================================================= */

/* ---------- Tokens ---------- */
:root {
  /* Event types — muted, equal-weight hues tuned for dark surfaces */
  --cal-holiday:  #f07a7d;
  --cal-festival: #f07a7d;
  --cal-exam:     #a796fa;
  --cal-deadline: #eba450;
  --cal-academic: #72a9fb;
  --cal-event:    #ee8cc4;
  --cal-break:    #3fc9b5;
  --cal-personal: #a3d16f;
  --cal-class:    var(--accent);

  /* Soft tints behind multi-day spans */
  --cal-exam-tint:  rgba(167, 150, 250, .16);
  --cal-break-tint: rgba(63, 201, 181, .14);
  --cal-event-tint: rgba(238, 140, 196, .14);
  --cal-vac-tint:   rgba(114, 169, 251, .09);

  /* Surfaces & lines */
  --cal-line:    rgba(255, 255, 255, .07);
  --cal-line-2:  rgba(255, 255, 255, .12);
  --cal-fill:    rgba(255, 255, 255, .06);
  --cal-fill-2:  rgba(255, 255, 255, .10);
  --cal-raised:  var(--surface);
  --cal-shadow:  0 0 0 1px rgba(255, 255, 255, .06), 0 12px 32px rgba(0, 0, 0, .35);
  --cal-shadow-sm: 0 0 0 1px rgba(255, 255, 255, .05);
  --cal-scrim:   rgba(0, 0, 0, .5);
  --cal-on-accent: #fff;

  --cal-ease: cubic-bezier(.2, .8, .2, 1);
  --cal-head-h: 140px; /* set from JS */
}

[data-theme="light"] {
  --cal-holiday:  #cc3a3f;
  --cal-festival: #cc3a3f;
  --cal-exam:     #6a4ed3;
  --cal-deadline: #b5620c;
  --cal-academic: #2e6dcc;
  --cal-event:    #bd3a87;
  --cal-break:    #0d8676;
  --cal-personal: #4b8520;

  --cal-exam-tint:  rgba(106, 78, 211, .09);
  --cal-break-tint: rgba(13, 134, 118, .09);
  --cal-event-tint: rgba(189, 58, 135, .08);
  --cal-vac-tint:   rgba(46, 109, 204, .06);

  --cal-line:    rgba(0, 0, 0, .07);
  --cal-line-2:  rgba(0, 0, 0, .12);
  --cal-fill:    rgba(0, 0, 0, .045);
  --cal-fill-2:  rgba(0, 0, 0, .08);
  --cal-raised:  #ffffff;
  --cal-shadow:  0 1px 2px rgba(16, 24, 40, .06), 0 12px 32px rgba(16, 24, 40, .10);
  --cal-shadow-sm: 0 1px 2px rgba(16, 24, 40, .05), 0 0 0 1px rgba(16, 24, 40, .05);
  --cal-scrim:   rgba(15, 18, 25, .28);
}

[data-theme="oled"] {
  --cal-line:    rgba(255, 255, 255, .08);
  --cal-line-2:  rgba(255, 255, 255, .14);
  --cal-fill:    rgba(255, 255, 255, .07);
  --cal-fill-2:  rgba(255, 255, 255, .11);
  --cal-raised:  #0d0d0d;
  --cal-shadow:  0 0 0 1px rgba(255, 255, 255, .09);
  --cal-shadow-sm: 0 0 0 1px rgba(255, 255, 255, .08);
  --cal-scrim:   rgba(0, 0, 0, .7);
}

/* ---------- Page ---------- */
.cal-page {
  background: var(--bg);
  -webkit-tap-highlight-color: transparent;
}
.cal-page .nav-logo { color: var(--accent); }

.cal-shell {
  max-width: 1120px;
  margin: 0 auto;
  padding: 12px 16px calc(104px + env(safe-area-inset-bottom));
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  color: var(--text);
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-areas: "now" "main" "list";
  row-gap: 16px;
}
.cal-now        { grid-area: now; }
.cal-main       { grid-area: main; min-width: 0; }
.cal-month-list { grid-area: list; min-width: 0; }

.cal-shell button,
.cal-drawer button,
.cal-fab { font-family: inherit; }

/* Icons */
[data-icon] svg { display: block; width: 20px; height: 20px; }

/* ---------- Now card ---------- */
.cal-now {
  background: var(--cal-raised);
  border-radius: 16px;
  box-shadow: var(--cal-shadow-sm);
  padding: 16px;
}
.cal-now:empty { display: none; }
.cal-now-top {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}
.cal-eyebrow {
  font-size: 12px;
  line-height: 16px;
  font-weight: 600;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--text3);
}
.cal-now-phase {
  margin-top: 4px;
  font-size: 22px;
  line-height: 28px;
  font-weight: 700;
  letter-spacing: -.015em;
  color: var(--text);
}
.cal-now-left {
  font-size: 13px;
  line-height: 18px;
  color: var(--text2);
  text-align: right;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.cal-now-left b { color: var(--text); font-weight: 600; }
.cal-progress {
  margin-top: 12px;
  height: 4px;
  border-radius: 2px;
  background: var(--cal-fill-2);
  overflow: hidden;
}
.cal-progress > i {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--accent);
  transform-origin: left center;
}
.cal-progress-ends {
  display: flex;
  justify-content: space-between;
  margin-top: 6px;
  font-size: 12px;
  line-height: 16px;
  color: var(--text3);
  font-variant-numeric: tabular-nums;
}
.cal-now-next {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 16px;
}
.cal-next {
  appearance: none;
  border: 0;
  text-align: left;
  background: var(--cal-fill);
  border-radius: 12px;
  padding: 10px 12px;
  color: var(--text);
  cursor: pointer;
  min-width: 0;
  transition: background .18s var(--cal-ease), transform .18s var(--cal-ease);
}
.cal-next:active { transform: scale(.98); }
.cal-next-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  line-height: 16px;
  font-weight: 600;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--text3);
}
.cal-next-title,
.cal-next-when { display: block; }
.cal-next-title {
  margin-top: 2px;
  font-size: 14px;
  line-height: 20px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.cal-next-when {
  font-size: 12px;
  line-height: 16px;
  color: var(--text2);
  font-variant-numeric: tabular-nums;
}

/* ---------- Sticky header ---------- */
.cal-head {
  position: sticky;
  top: var(--nav-h);
  z-index: 30;
  margin: 0 -16px;
  padding: 8px 16px 10px;
  background: var(--bg);
  border-bottom: 1px solid transparent;
  transition: border-color .2s var(--cal-ease);
}
.cal-head.is-stuck { border-bottom-color: var(--cal-line); }
.cal-head-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.cal-head-row-2 { margin-top: 8px; }
.cal-head-row-2 .cal-pill { margin: 0 auto; }
.cal-title {
  margin: 0;
  font-size: 28px;
  line-height: 36px;
  font-weight: 700;
  letter-spacing: -.02em;
  color: var(--text);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.cal-title .y {
  margin-left: 8px;
  color: var(--text3);
  font-weight: 600;
}
.cal-head-actions {
  display: flex;
  align-items: center;
  gap: 2px;
}

.cal-icon-btn {
  appearance: none;
  display: inline-grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--text2);
  cursor: pointer;
  transition: background .18s var(--cal-ease), color .18s var(--cal-ease), transform .18s var(--cal-ease);
}
.cal-icon-btn:active { transform: scale(.94); background: var(--cal-fill-2); }
.cal-icon-btn[hidden] { display: none; }
.cal-icon-btn:disabled { opacity: .28; cursor: default; background: transparent; transform: none; }

.cal-pill {
  appearance: none;
  height: 32px;
  padding: 0 14px;
  border: 1px solid var(--cal-line-2);
  border-radius: 999px;
  background: transparent;
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background .18s var(--cal-ease), transform .18s var(--cal-ease);
}
.cal-pill:active { transform: scale(.97); }
.cal-pill[hidden] { display: none; }

/* Segmented controls */
.cal-seg {
  display: inline-flex;
  padding: 3px;
  gap: 2px;
  border-radius: 10px;
  background: var(--cal-fill);
}
.cal-seg-btn {
  appearance: none;
  height: 30px;
  min-width: 56px;
  padding: 0 14px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--text2);
  font-size: 13px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
  transition: background .18s var(--cal-ease), color .18s var(--cal-ease), box-shadow .18s var(--cal-ease);
}
.cal-seg-btn.active {
  background: var(--cal-raised);
  color: var(--text);
  box-shadow: var(--cal-shadow-sm);
}
[data-theme="oled"] .cal-seg-btn.active,
:root:not([data-theme="light"]) .cal-seg-btn.active { background: var(--cal-fill-2); box-shadow: none; }

/* Filter chips (double as the legend) */
.cal-filters {
  display: flex;
  gap: 6px;
  margin: 10px -16px 0;
  padding: 0 16px 2px;
  overflow-x: auto;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
  scroll-snap-type: x proximity;
}
.cal-filters::-webkit-scrollbar { display: none; }
.cal-chip {
  appearance: none;
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 32px;
  padding: 0 12px;
  border: 1px solid var(--cal-line-2);
  border-radius: 999px;
  background: transparent;
  color: var(--text2);
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  cursor: pointer;
  scroll-snap-align: start;
  transition: background .18s var(--cal-ease), color .18s var(--cal-ease), border-color .18s var(--cal-ease), transform .18s var(--cal-ease);
}
.cal-chip:active { transform: scale(.97); }
.cal-chip.on {
  background: var(--text);
  border-color: var(--text);
  color: var(--bg);
}
.cal-chip i {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex: 0 0 auto;
}

/* Type colour helpers */
.t-holiday  { --c: var(--cal-holiday); }
.t-festival { --c: var(--cal-festival); }
.t-exam     { --c: var(--cal-exam); }
.t-deadline { --c: var(--cal-deadline); }
.t-academic { --c: var(--cal-academic); }
.t-event    { --c: var(--cal-event); }
.t-break    { --c: var(--cal-break); }
.t-personal { --c: var(--cal-personal); }
.t-class    { --c: var(--cal-class); }
.cal-chip i, .cal-dot, .cal-bar { background: var(--c, var(--text3)); }

/* ---------- Month grid ---------- */
.cal-month { margin-top: 4px; }
.cal-weekdays {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  padding: 8px 0 4px;
}
.cal-weekdays div {
  text-align: center;
  font-size: 11px;
  line-height: 16px;
  font-weight: 600;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--text3);
}
.cal-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  row-gap: 2px;
  touch-action: pan-y;
  will-change: transform;
}

.cal-cell {
  appearance: none;
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  height: 54px;
  padding: 4px 0 0;
  border: 0;
  background: none;
  color: var(--text);
  cursor: pointer;
  min-width: 0;
  outline: none;
}
.cal-cell.blank { cursor: default; }

/* Span band (mid break, exam week, fest, vacation) */
.cal-cell[data-band]::before {
  content: "";
  position: absolute;
  top: 4px;
  left: 0;
  right: 0;
  height: 34px;
  background: var(--band);
}
.cal-cell.band-start::before { left: 4px; border-top-left-radius: 17px; border-bottom-left-radius: 17px; }
.cal-cell.band-end::before   { right: 4px; border-top-right-radius: 17px; border-bottom-right-radius: 17px; }
.cal-cell[data-band="exam"]  { --band: var(--cal-exam-tint); }
.cal-cell[data-band="break"] { --band: var(--cal-break-tint); }
.cal-cell[data-band="event"] { --band: var(--cal-event-tint); }
.cal-cell[data-band="vac"]   { --band: var(--cal-vac-tint); }

.cal-num {
  position: relative;
  z-index: 1;
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  font-size: 15px;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  transition: transform .15s var(--cal-ease), background .15s var(--cal-ease);
}
.cal-cell.weekend .cal-num { color: var(--text2); }
.cal-cell.holiday .cal-num { color: var(--cal-holiday); font-weight: 650; }
.cal-cell.past .cal-num    { opacity: .55; }
.cal-cell:active .cal-num  { transform: scale(.92); }
.cal-cell.is-selected .cal-num { box-shadow: inset 0 0 0 1.5px var(--text); }
.cal-cell.is-today .cal-num {
  background: var(--accent);
  color: var(--cal-on-accent);
  font-weight: 700;
  opacity: 1;
}
.cal-cell:focus-visible .cal-num { box-shadow: 0 0 0 2px var(--accent); }

.cal-dots {
  position: relative;
  z-index: 1;
  display: flex;
  gap: 3px;
  height: 5px;
  margin-top: 5px;
}
.cal-dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
}
.cal-chips { display: none; }
.cal-shell { overflow-x: clip; }

/* ---------- Event rows (month list + agenda) ---------- */
.cal-caption {
  margin: 8px 0 4px;
  font-size: 12px;
  line-height: 16px;
  font-weight: 600;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--text3);
}
.cal-row {
  appearance: none;
  display: grid;
  grid-template-columns: 44px 3px minmax(0, 1fr) auto;
  align-items: center;
  column-gap: 12px;
  width: 100%;
  padding: 12px 0;
  border: 0;
  border-bottom: 1px solid var(--cal-line);
  background: none;
  color: var(--text);
  text-align: left;
  cursor: pointer;
  transition: background .18s var(--cal-ease);
}
.cal-row:last-child { border-bottom: 0; }
.cal-row:active .cal-row-title { opacity: .7; }
.cal-row.is-past { opacity: .45; }
.cal-row.same-day .cal-row-date { visibility: hidden; }
.cal-row-date {
  text-align: center;
  font-variant-numeric: tabular-nums;
}
.cal-row-day {
  display: block;
  font-size: 20px;
  line-height: 24px;
  font-weight: 650;
  letter-spacing: -.01em;
}
.cal-row-dow {
  display: block;
  font-size: 11px;
  line-height: 14px;
  font-weight: 600;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--text3);
}
.cal-row.is-today .cal-row-day { color: var(--accent); }
.cal-bar {
  align-self: stretch;
  width: 3px;
  min-height: 28px;
  border-radius: 2px;
}
.cal-row-main { display: block; min-width: 0; }
.cal-row-title,
.cal-row-meta { display: block; }
.cal-row-title {
  font-size: 15px;
  line-height: 20px;
  font-weight: 550;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}
.cal-row-meta {
  margin-top: 2px;
  font-size: 13px;
  line-height: 18px;
  color: var(--text2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-variant-numeric: tabular-nums;
}
.cal-row-rel {
  font-size: 12px;
  line-height: 16px;
  color: var(--text3);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.cal-row-rel.soon { color: var(--text); font-weight: 600; }
.cal-empty {
  padding: 20px 0;
  font-size: 14px;
  line-height: 20px;
  color: var(--text3);
}

/* Agenda view */
.cal-agenda { margin-top: 4px; }
.cal-agenda-month {
  position: sticky;
  top: calc(var(--nav-h) + var(--cal-head-h));
  z-index: 5;
  margin: 0 -16px;
  padding: 16px 16px 6px;
  background: var(--bg);
  font-size: 13px;
  line-height: 18px;
  font-weight: 700;
  letter-spacing: -.005em;
  color: var(--text);
}
.cal-agenda-month span { color: var(--text3); font-weight: 600; margin-left: 4px; }
.cal-agenda-end {
  padding: 24px 0 8px;
  text-align: center;
  font-size: 13px;
  color: var(--text3);
}
.cal-agenda-end a { color: var(--text2); }

/* ---------- FAB ---------- */
.cal-fab {
  position: fixed;
  right: 16px;
  bottom: calc(20px + env(safe-area-inset-bottom));
  z-index: 60;
  display: grid;
  place-items: center;
  width: 56px;
  height: 56px;
  border: 0;
  border-radius: 18px;
  background: var(--accent);
  color: var(--cal-on-accent);
  box-shadow: 0 8px 24px rgba(0, 0, 0, .28), 0 2px 6px rgba(0, 0, 0, .18);
  cursor: pointer;
  transition: transform .18s var(--cal-ease), box-shadow .18s var(--cal-ease);
}
.cal-fab svg { width: 24px; height: 24px; }
.cal-fab:active { transform: scale(.94); }
.cal-fab:focus-visible { outline: 2px solid var(--text); outline-offset: 3px; }

/* ---------- Overflow menu ---------- */
.cal-menu-wrap { position: relative; }
.cal-menu {
  position: absolute;
  right: 0;
  top: 46px;
  z-index: 80;
  width: 288px;
  max-width: calc(100vw - 32px);
  padding: 6px;
  border-radius: 14px;
  background: var(--cal-raised);
  box-shadow: var(--cal-shadow);
  transform-origin: top right;
  animation: cal-pop .18s var(--cal-ease);
}
.cal-menu[hidden] { display: none; }
.cal-menu-item {
  appearance: none;
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 10px 12px;
  border: 0;
  border-radius: 10px;
  background: none;
  color: var(--text);
  text-align: left;
  text-decoration: none;
  cursor: pointer;
}
.cal-menu-item:hover,
.cal-menu-item:focus-visible { background: var(--cal-fill); outline: none; }
.cal-menu-item[hidden] { display: none; }
.cal-menu-item > [data-icon] { color: var(--text2); flex: 0 0 auto; }
.cal-menu-item b {
  display: block;
  font-size: 14px;
  line-height: 20px;
  font-weight: 600;
}
.cal-menu-item small {
  display: block;
  font-size: 12px;
  line-height: 16px;
  color: var(--text3);
}
.cal-menu-item > span:nth-child(2) { flex: 1; min-width: 0; }
.cal-menu-sep { height: 1px; margin: 6px 8px; background: var(--cal-line); }
.cal-switch {
  position: relative;
  flex: 0 0 auto;
  width: 34px;
  height: 20px;
  border-radius: 999px;
  background: var(--cal-fill-2);
  transition: background .18s var(--cal-ease);
}
.cal-switch::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 2px rgba(0, 0, 0, .25);
  transition: transform .18s var(--cal-ease);
}
[aria-checked="true"] > .cal-switch { background: var(--accent); }
[aria-checked="true"] > .cal-switch::after { transform: translateX(14px); }

/* ---------- Day sheet ---------- */
.cal-drawer-backdrop {
  position: fixed;
  inset: 0;
  z-index: 900;
  background: var(--cal-scrim);
  animation: cal-fade .2s var(--cal-ease);
}
.cal-drawer-backdrop[hidden] { display: none; }
.cal-drawer {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 901;
  display: flex;
  flex-direction: column;
  max-height: 88vh;
  max-height: 88dvh;
  background: var(--cal-raised);
  color: var(--text);
  border-radius: 20px 20px 0 0;
  box-shadow: var(--cal-shadow);
  padding-bottom: env(safe-area-inset-bottom);
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  animation: cal-sheet-up .26s var(--cal-ease);
  touch-action: pan-y;
}
.cal-drawer[hidden] { display: none; }
.cal-drawer.dragging { transition: none; animation: none; }
.cal-drawer.settling { transition: transform .22s var(--cal-ease); }
.cal-drawer-grip {
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  height: 20px;
  cursor: grab;
}
.cal-drawer-grip span {
  width: 36px;
  height: 4px;
  border-radius: 2px;
  background: var(--cal-line-2);
}
.cal-drawer-head {
  flex: 0 0 auto;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 4px 12px 12px 20px;
  border-bottom: 1px solid var(--cal-line);
}
.cal-drawer-sub {
  font-size: 12px;
  line-height: 16px;
  font-weight: 600;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--text3);
}
.cal-drawer-sub .hol { color: var(--cal-holiday); }
.cal-drawer-date {
  margin-top: 2px;
  font-size: 22px;
  line-height: 28px;
  font-weight: 700;
  letter-spacing: -.015em;
  font-variant-numeric: tabular-nums;
}
.cal-drawer-body {
  flex: 1 1 auto;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 4px 20px 20px;
}

.cal-ev {
  display: grid;
  grid-template-columns: 3px minmax(0, 1fr) auto;
  column-gap: 12px;
  align-items: center;
  padding: 14px 0;
  border-bottom: 1px solid var(--cal-line);
}
.cal-ev .cal-bar { min-height: 36px; }
.cal-ev-type {
  font-size: 11px;
  line-height: 16px;
  font-weight: 600;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--c, var(--text3));
}
.cal-ev-title {
  margin-top: 1px;
  font-size: 16px;
  line-height: 22px;
  font-weight: 600;
  overflow-wrap: anywhere;
}
.cal-ev-note {
  margin-top: 2px;
  font-size: 13px;
  line-height: 18px;
  color: var(--text2);
  overflow-wrap: anywhere;
}
.cal-ev-note b { color: var(--text); font-weight: 600; font-variant-numeric: tabular-nums; }
.cal-ev-actions { display: flex; gap: 2px; }
.cal-ev-actions .cal-icon-btn { width: 36px; height: 36px; }
.cal-ev-actions [data-icon] svg { width: 18px; height: 18px; }
.cal-ev-src {
  font-size: 11px;
  line-height: 16px;
  color: var(--text3);
}
.cal-drawer-empty {
  padding: 20px 0 4px;
  font-size: 14px;
  line-height: 20px;
  color: var(--text3);
}

.cal-add-btn {
  appearance: none;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  height: 46px;
  margin-top: 16px;
  border: 0;
  border-radius: 12px;
  background: var(--cal-fill);
  color: var(--text);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: background .18s var(--cal-ease), transform .18s var(--cal-ease);
}
.cal-add-btn:active { transform: scale(.98); }
.cal-add-btn[hidden] { display: none; }
.cal-add-btn [data-icon] svg { width: 18px; height: 18px; }

.cal-add-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 16px;
}
.cal-add-form[hidden] { display: none; }
.cal-input {
  width: 100%;
  height: 46px;
  padding: 0 14px;
  border: 1px solid var(--cal-line-2);
  border-radius: 12px;
  background: var(--bg);
  color: var(--text);
  font-family: inherit;
  font-size: 16px; /* 16px stops iOS zooming on focus */
  outline: none;
  transition: border-color .18s var(--cal-ease), box-shadow .18s var(--cal-ease);
}
.cal-input::placeholder { color: var(--text3); }
.cal-input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-bg); }
.cal-textarea {
  height: auto;
  min-height: 76px;
  padding: 12px 14px;
  resize: vertical;
  line-height: 22px;
}
.cal-form-row {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}
.cal-time-label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--text3);
}
.cal-time-input { width: 140px; }
.cal-color-picker {
  display: flex;
  gap: 10px;
  padding-bottom: 9px;
}
.cal-swatch {
  width: 28px;
  height: 28px;
  border: 0;
  border-radius: 50%;
  cursor: pointer;
  transition: box-shadow .15s var(--cal-ease), transform .15s var(--cal-ease);
}
.cal-swatch:active { transform: scale(.9); }
.cal-swatch.active { box-shadow: 0 0 0 2px var(--cal-raised), 0 0 0 4px var(--text); }
.cal-form-actions {
  display: flex;
  gap: 8px;
  margin-top: 4px;
}
.cal-btn {
  appearance: none;
  flex: 1;
  height: 46px;
  border: 0;
  border-radius: 12px;
  background: var(--cal-fill);
  color: var(--text);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: background .18s var(--cal-ease), transform .18s var(--cal-ease), filter .18s var(--cal-ease);
}
.cal-btn:active { transform: scale(.98); }
.cal-btn-primary { background: var(--accent); color: var(--cal-on-accent); }

/* Hover — pointer devices only, so taps don't leave a stuck highlight */
@media (hover: hover) {
  .cal-next:hover { background: var(--cal-fill-2); }
  .cal-icon-btn:hover { background: var(--cal-fill); color: var(--text); }
  .cal-icon-btn.danger:hover { color: var(--cal-holiday); }
  .cal-pill:hover { background: var(--cal-fill); }
  .cal-seg-btn:hover { color: var(--text); }
  .cal-chip:hover { color: var(--text); background: var(--cal-fill); }
  .cal-cell:hover .cal-num   { background: var(--cal-fill); }
  .cal-row:hover { background: linear-gradient(90deg, transparent, var(--cal-fill) 12%, var(--cal-fill) 88%, transparent); }
  .cal-fab:hover { transform: translateY(-1px); }
  .cal-add-btn:hover { background: var(--cal-fill-2); }
  .cal-btn:hover { background: var(--cal-fill-2); }
  .cal-btn-primary:hover { background: var(--accent); filter: brightness(1.06); }
}

/* Focus rings */
.cal-shell :focus-visible,
.cal-drawer :focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.cal-cell:focus-visible { outline: none; }
.cal-input:focus-visible { outline: none; }

/* ---------- Motion ---------- */
@keyframes cal-fade { from { opacity: 0; } }
@keyframes cal-pop { from { opacity: 0; transform: scale(.96) translateY(-4px); } }
@keyframes cal-sheet-up { from { transform: translateY(100%); } }
@keyframes cal-sheet-right { from { transform: translateX(100%); } }

/* ---------- Phones: nothing pinned but the site bar; tighter summary ---------- */
@media (max-width: 599px) {
  .cal-head { position: static; padding-top: 4px; }
  .cal-agenda-month { top: var(--nav-h); }
  .cal-shell { row-gap: 12px; padding-top: 10px; }
  .cal-now { padding: 14px 14px 12px; border-radius: 14px; }
  .cal-now-phase { margin-top: 2px; font-size: 20px; line-height: 26px; }
  .cal-progress { margin-top: 10px; }
  .cal-progress-ends { margin-top: 4px; }
  .cal-now-next { margin-top: 12px; }
  .cal-next { padding: 8px 10px; border-radius: 10px; }
  .cal-next-when { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
}

/* ---------- Small phones ---------- */
@media (max-width: 374px) {
  .cal-title { font-size: 24px; }
  .cal-title .y { margin-left: 6px; }
  .cal-seg-btn { min-width: 0; padding: 0 11px; }
  .cal-icon-btn { width: 36px; height: 36px; }
  .cal-num { width: 32px; height: 32px; font-size: 14px; }
}

/* ---------- Tablet ---------- */
@media (min-width: 600px) {
  .cal-shell { padding-left: 24px; padding-right: 24px; }
  .cal-head { margin: 0 -24px; padding-left: 24px; padding-right: 24px; }
  .cal-filters { margin-left: -24px; margin-right: -24px; padding-left: 24px; padding-right: 24px; }
  .cal-agenda-month { margin: 0 -24px; padding-left: 24px; padding-right: 24px; }
  .cal-cell { height: 64px; }
  .cal-drawer {
    left: 50%;
    right: auto;
    width: 560px;
    transform: translateX(-50%);
    animation: cal-fade .2s var(--cal-ease);
  }
}

/* ---------- Desktop: grid left, summary + month list right ---------- */
@media (min-width: 900px) {
  .cal-shell {
    padding-top: 20px;
    grid-template-columns: minmax(0, 1fr) 340px;
    grid-template-rows: auto 1fr;
    grid-template-areas: "main now" "main list";
    column-gap: 32px;
    row-gap: 20px;
    align-items: start;
  }
  .cal-month-list {
    position: sticky;
    top: calc(var(--nav-h) + 16px);
  }
  .cal-head { margin: 0; padding: 0 0 10px; top: var(--nav-h); }
  .cal-filters { margin: 12px 0 0; padding: 0 0 2px; flex-wrap: wrap; overflow: visible; }
  .cal-agenda-month { margin: 0; padding-left: 0; padding-right: 0; }
  .cal-title { font-size: 32px; line-height: 40px; }

  .cal-weekdays div { text-align: left; padding-left: 10px; }
  .cal-grid { row-gap: 0; }
  .cal-cell {
    height: 112px;
    align-items: stretch;
    text-align: left;
    padding: 6px 4px 4px;
    border-top: 1px solid var(--cal-line);
  }
  .cal-cell[data-band]::before { top: 3px; bottom: 3px; height: auto; }
  .cal-cell.band-start::before { left: 3px; border-radius: 10px 0 0 10px; }
  .cal-cell.band-end::before { right: 3px; border-top-right-radius: 10px; border-bottom-right-radius: 10px; }
  .cal-cell.band-start.band-end::before { border-radius: 10px; }
  .cal-num { width: 28px; height: 28px; font-size: 14px; margin-left: 2px; }
  .cal-dots { display: none; }
  .cal-chips {
    position: relative;
    z-index: 1;
    display: flex;
    flex-direction: column;
    gap: 2px;
    margin-top: 4px;
    min-width: 0;
  }
  .cal-tag {
    display: block;
    padding: 2px 6px 2px 7px;
    border-radius: 5px;
    background: var(--cal-fill);
    box-shadow: inset 2px 0 0 var(--c, var(--text3));
    color: var(--text);
    font-size: 11.5px;
    line-height: 16px;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .cal-tag-more {
    padding-left: 7px;
    font-size: 11px;
    line-height: 16px;
    color: var(--text3);
  }

  .cal-drawer {
    top: var(--nav-h);
    left: auto;
    right: 0;
    bottom: 0;
    width: 420px;
    max-height: none;
    transform: none;
    border-radius: 0;
    animation: cal-sheet-right .26s var(--cal-ease);
  }
  .cal-drawer-grip { display: none; }
  .cal-drawer-head { padding-top: 20px; }
  .cal-fab { right: 28px; bottom: 28px; }
}

@media (prefers-reduced-motion: reduce) {
  .cal-shell *, .cal-drawer, .cal-drawer *, .cal-menu, .cal-drawer-backdrop, .cal-fab {
    animation: none !important;
    transition: none !important;
  }
}
