/* Geist and Geist Mono (SIL Open Font License 1.1 - see fonts/OFL.txt),
   served from this site rather than Google Fonts, so a visitor's browser
   makes no request to Google. Only the latin and latin-ext subsets are
   included; other scripts fall back to the system font. The two variable
   fonts cover every weight the site uses (Geist 400-600, Geist Mono 400-500). */
@font-face {
  font-family: "Geist";
  font-style: normal;
  font-weight: 400 600;
  font-display: swap;
  src: url("fonts/geist-latin-ext.woff2") format("woff2");
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}

@font-face {
  font-family: "Geist";
  font-style: normal;
  font-weight: 400 600;
  font-display: swap;
  src: url("fonts/geist-latin.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

@font-face {
  font-family: "Geist Mono";
  font-style: normal;
  font-weight: 400 500;
  font-display: swap;
  src: url("fonts/geist-mono-latin-ext.woff2") format("woff2");
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}

@font-face {
  font-family: "Geist Mono";
  font-style: normal;
  font-weight: 400 500;
  font-display: swap;
  src: url("fonts/geist-mono-latin.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

/* Categorical palette: one hue per year group + FOSPS (8 slots). "Everyone"
   (whole school) is a neutral grey rather than a 9th hue, since it's
   structurally the "everyone" bucket, not a peer category. */
:root {
  --cal-neutral: #171717; /* Everyone: the page ink, same as the checkbox */
  --cal-1: #2a78d6; /* Reception */
  --cal-2: #eb6834; /* Year 1 */
  --cal-3: #1baf7a; /* Year 2 */
  --cal-4: #eda100; /* Year 3 */
  --cal-5: #e87ba4; /* Year 4 */
  --cal-6: #008300; /* Year 5 */
  --cal-7: #4a3aa7; /* Year 6 */
  --cal-8: #e34948; /* FOSPS */
  --cal-surface: #f2f2f2;
  --cal-surface-alt: #ffffff;
  --cal-surface-weekend: #fafafa;
  --cal-border: #ebebeb;
  --cal-muted: #666666;
  --cal-fg: #171717;
  --cal-today-ring: #171717;
  --cal-focus: #0070f3;
  --link-color: #1a5fb4;

  /* Per-slot chip TEXT colour, not a blanket white: whichever of
     near-black/white has the better WCAG contrast against that slot's own
     hex. */
  --chip-text-dark: #14140f;
  --chip-text-light: #ffffff;
  --cal-neutral-text: var(--chip-text-light);
  /* Whole School's chips (and list dots, and key) are a quiet grey rather
     than its ink: it's on most days, and solid black blocks drowned out the
     class and FOSPS colours. The checkbox and dot elsewhere keep the ink. */
  --cal-neutral-chip: #e6e6e6;
  --cal-neutral-chip-text: #171717;
  --cal-1-text: var(--chip-text-light);
  --cal-2-text: var(--chip-text-dark);
  --cal-3-text: var(--chip-text-dark);
  --cal-4-text: var(--chip-text-dark);
  --cal-5-text: var(--chip-text-dark);
  --cal-6-text: var(--chip-text-light);
  --cal-7-text: var(--chip-text-light);
  --cal-8-text: var(--chip-text-dark);

  /* Alphabetically second class in each year group: a lighter tint of the year's hue,
     mixed in OKLCH so the step in lightness is even across hues. The two
     classes stay recognisably one year while telling apart in the grid
     and the rail. Dark text on every tint. */
  --cal-1-b: color-mix(in oklch, var(--cal-1) 55%, white);
  --cal-2-b: color-mix(in oklch, var(--cal-2) 55%, white);
  --cal-3-b: color-mix(in oklch, var(--cal-3) 55%, white);
  --cal-4-b: color-mix(in oklch, var(--cal-4) 55%, white);
  --cal-5-b: color-mix(in oklch, var(--cal-5) 55%, white);
  --cal-6-b: color-mix(in oklch, var(--cal-6) 55%, white);
  --cal-7-b: color-mix(in oklch, var(--cal-7) 55%, white);
  --cal-1-b-text: var(--chip-text-dark);
  --cal-2-b-text: var(--chip-text-dark);
  --cal-3-b-text: var(--chip-text-dark);
  --cal-4-b-text: var(--chip-text-dark);
  --cal-5-b-text: var(--chip-text-dark);
  --cal-6-b-text: var(--chip-text-dark);
  --cal-7-b-text: var(--chip-text-dark);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --cal-neutral: #ededed;
    --cal-1: #3987e5;
    --cal-2: #d95926;
    --cal-3: #199e70;
    --cal-4: #c98500;
    --cal-5: #d55181;
    --cal-6: #008300;
    --cal-7: #9085e9;
    --cal-8: #e66767;
    --cal-surface: #1a1a1a;
    --cal-surface-alt: #0a0a0a;
    --cal-surface-weekend: #111111;
    --cal-border: #2e2e2e;
    --cal-muted: #a1a1a1;
    --cal-fg: #ededed;
    --cal-today-ring: #ededed;
    --cal-focus: #52a8ff;
    --link-color: #8ab4f8;

    --cal-neutral-text: var(--chip-text-dark);
    --cal-neutral-chip: #333333;
    --cal-neutral-chip-text: #ededed;
    --cal-1-text: var(--chip-text-dark);
    --cal-2-text: var(--chip-text-dark);
    --cal-3-text: var(--chip-text-dark);
    --cal-4-text: var(--chip-text-dark);
    --cal-5-text: var(--chip-text-dark);
    --cal-6-text: var(--chip-text-light);
    --cal-7-text: var(--chip-text-dark);
    --cal-8-text: var(--chip-text-dark);
  }
}
:root[data-theme="dark"] {
    --cal-neutral: #ededed;
    --cal-1: #3987e5;
    --cal-2: #d95926;
    --cal-3: #199e70;
    --cal-4: #c98500;
    --cal-5: #d55181;
    --cal-6: #008300;
    --cal-7: #9085e9;
    --cal-8: #e66767;
    --cal-surface: #1a1a1a;
    --cal-surface-alt: #0a0a0a;
    --cal-surface-weekend: #111111;
    --cal-border: #2e2e2e;
    --cal-muted: #a1a1a1;
    --cal-fg: #ededed;
    --cal-today-ring: #ededed;
    --cal-focus: #52a8ff;
    --link-color: #8ab4f8;

    --cal-neutral-text: var(--chip-text-dark);
    --cal-neutral-chip: #333333;
    --cal-neutral-chip-text: #ededed;
    --cal-1-text: var(--chip-text-dark);
    --cal-2-text: var(--chip-text-dark);
    --cal-3-text: var(--chip-text-dark);
    --cal-4-text: var(--chip-text-dark);
    --cal-5-text: var(--chip-text-dark);
    --cal-6-text: var(--chip-text-light);
    --cal-7-text: var(--chip-text-dark);
    --cal-8-text: var(--chip-text-dark);
  }

/* --- Subscribe: two steps side by side in one bordered section (stacked on
   a phone) - pick calendars, then add them to your app. --- */
.subscribe {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  border: 1px solid var(--cal-border);
  border-radius: 16px;
  overflow: hidden;
}

.subscribe-pick,
.subscribe-add {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  padding: 2rem;
  min-width: 0;
}

.subscribe-add {
  background: var(--cal-surface-weekend);
  border-left: 1px solid var(--cal-border);
}

.step-title {
  margin: 0;
  font-size: 1.375rem;
  font-weight: 600;
  line-height: 1.3;
  letter-spacing: -0.02em;
  color: var(--cal-fg);
}

.step-hint {
  margin: -0.5rem 0 0;
  font-size: 0.9375rem;
  line-height: 1.5;
  color: var(--cal-muted);
  text-wrap: pretty;
}

.subscribe-add .step-hint:not(#app-question) {
  margin-top: 0;
}

.add-body {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  min-width: 0;
}

/* Step 2's heading is a button so phones can fold the step away once the
   calendars are added (see setupAddToggle in calendar.ts). Wider screens have
   room for it, so there it's just a heading. */
.step-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  width: 100%;
  padding: 0;
  border: 0;
  background: none;
  color: inherit;
  font: inherit;
  letter-spacing: inherit;
  text-align: left;
  cursor: default;
}

@media (max-width: 600px) {
  .step-toggle {
    cursor: pointer;
  }

  .step-toggle::after {
    content: "";
    flex: none;
    width: 0.55rem;
    height: 0.55rem;
    margin-right: 0.25rem;
    border-right: 2px solid var(--cal-muted);
    border-bottom: 2px solid var(--cal-muted);
    transform: rotate(-135deg) translateY(-2px);
    transition: transform 150ms ease;
  }

  .subscribe-add.is-collapsed .step-toggle::after {
    transform: rotate(45deg) translateY(-2px);
  }

  .subscribe-add.is-collapsed .add-body {
    display: none;
  }
}

/* A calendar's name called out within otherwise-muted copy. */
.step-hint strong,
.cal-highlight {
  color: var(--cal-fg);
  font-weight: 600;
}

@media (max-width: 800px) {
  .subscribe {
    grid-template-columns: minmax(0, 1fr);
  }

  .subscribe-add {
    border-left: 0;
    border-top: 1px solid var(--cal-border);
  }
}

@media (max-width: 600px) {
  .subscribe-pick,
  .subscribe-add {
    padding: 1.5rem 1rem;
  }
}

/* Step 1: a row per calendar, two columns - each year's two classes side by
   side (see displayOrder in calendar.ts), Whole School and FOSPS first. The
   whole row is the tap target; a ticked one is shaded. The checkbox takes the
   calendar's colour, so the list doubles as the key. */
.cal-tiles {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.25rem 0.75rem;
  margin: 0 -0.5rem;
}

.cal-tile {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  min-width: 0;
  min-height: 2.75rem;
  padding: 0 0.5rem;
  border-radius: 8px;
  font-size: 0.9375rem;
  line-height: 1.3;
  color: var(--cal-fg);
  cursor: pointer;
  user-select: none;
  transition: background-color 150ms ease;
}

.cal-tile:hover {
  background: var(--cal-surface-weekend);
}

.cal-tile.is-on {
  background: var(--cal-surface);
}

.cal-tile input {
  appearance: auto;
  flex: none;
  width: 1.25rem;
  height: 1.25rem;
  margin: 0;
  accent-color: var(--tile-color, var(--cal-fg));
  cursor: pointer;
}

.cal-tile input:focus-visible {
  outline: 2px solid var(--cal-focus);
  outline-offset: 2px;
}

.cal-tile-name {
  min-width: 0;
}

.cal-tile-name strong {
  font-weight: 600;
}

.cal-tile-year {
  color: var(--cal-muted);
}

/* Step 2: the app, as one segmented choice. */
.app-choice {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 4px;
  padding: 4px;
  border-radius: 12px;
  background: var(--cal-border);
}

.app-choice button {
  min-height: 2.75rem;
  padding: 0 0.5rem;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: var(--cal-fg);
  font-family: inherit;
  font-size: 0.9375rem;
  font-weight: 500;
  cursor: pointer;
}

.app-choice button[aria-pressed="true"] {
  background: var(--cal-surface-alt);
  font-weight: 600;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.14);
}

.app-choice button:focus-visible,
.add-link:focus-visible,
.copy-button:focus-visible,
.icon-button:focus-visible,
.cal-list-item:focus-visible,
.cal-list-more:focus-visible {
  outline: 2px solid var(--cal-focus);
  outline-offset: 2px;
}

/* Full labels, or short ones on a phone: "Apple Calendar" / "Apple",
   "Add to Apple Calendar" / "Add". */
.label-short {
  display: none;
}

@media (max-width: 600px) {
  .label-long {
    display: none;
  }

  .label-short {
    display: inline;
  }
}

/* "1 of 3 added", and a bar. */
.add-progress {
  display: grid;
  gap: 0.5rem;
}

.add-progress-text {
  display: flex;
  justify-content: space-between;
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--cal-fg);
}

#add-progress-count {
  font-weight: 400;
  color: var(--cal-muted);
}

.add-progress-bar {
  height: 6px;
  border-radius: 999px;
  background: var(--cal-border);
  overflow: hidden;
}

#add-progress-fill {
  height: 100%;
  width: 0;
  background: var(--cal-fg);
  transition: width 200ms ease;
}

/* The checklist: a row per ticked calendar, each with its own Add link. */
.add-list {
  display: grid;
  gap: 0.5rem;
  margin: 0;
  padding: 0;
  list-style: none;
}

.add-list:empty {
  display: none;
}

.add-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.5rem 0.5rem 0.5rem 1rem;
  border: 1px solid var(--cal-border);
  border-radius: 12px;
  background: var(--cal-surface-alt);
}

.add-dot {
  flex: none;
  width: 0.75rem;
  height: 0.75rem;
  border-radius: 50%;
  background: var(--dot-color);
}

.add-row .cal-tile-name {
  flex-grow: 1;
  font-size: 0.9375rem;
}

.add-link {
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  min-height: 2.75rem;
  padding: 0 1rem;
  border-radius: 8px;
  background: var(--button-bg, var(--cal-fg));
  color: var(--button-fg, var(--cal-surface-alt));
  font-size: 0.9375rem;
  font-weight: 600;
  text-decoration: none;
  white-space: nowrap;
  transition: background-color 150ms ease;
}

.add-link:hover {
  background: var(--button-bg-hover, var(--cal-fg));
}

/* Tapped already: a quiet tick, still a link in case the app didn't open. */
.add-link.is-added {
  background: transparent;
  color: var(--success, #1a7a3c);
  padding: 0 0.75rem;
}

.add-link.is-added:hover {
  background: var(--cal-surface);
}

/* --- Toolbar: the title, then dates, view and refresh. --- */
.cal-nav {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.75rem 1rem;
  margin: 0 0 1rem;
}

.preview-title {
  flex-grow: 1;
  margin: 0;
  font-size: 1.375rem;
  font-weight: 600;
  line-height: 1.3;
  letter-spacing: -0.02em;
  color: var(--cal-fg);
}

.cal-nav-dates {
  display: flex;
  align-items: center;
  gap: 0.25rem;
}

.cal-nav-dates[hidden] {
  display: none;
}

.cal-nav-dates button,
.icon-button {
  height: 2.5rem;
  border: 1px solid var(--cal-border);
  border-radius: 8px;
  background: var(--cal-surface-alt);
  color: var(--cal-fg);
  font-family: inherit;
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: background-color 150ms ease;
}

.cal-nav-dates button {
  padding: 0 0.875rem;
}

.icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.5rem;
  padding: 0;
}

.cal-nav-dates button:hover,
.icon-button:hover {
  background: var(--cal-surface);
}

.cal-nav-dates button:focus-visible {
  outline: 2px solid var(--cal-focus);
  outline-offset: 2px;
}

/* Refresh: just the icon, no border. It spins while it works. */
.cal-refresh {
  border: 0;
  background: transparent;
  color: var(--cal-muted);
}

.cal-refresh.is-busy svg {
  animation: spin 900ms linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* Segmented control on a soft surface; the active segment is filled. */
.cal-view-switch {
  display: flex;
  gap: 2px;
  padding: 3px;
  border-radius: 10px;
  background: var(--cal-surface);
}

.cal-view-switch .view-button {
  height: 2.25rem;
  padding: 0 0.875rem;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--cal-muted);
  font-family: inherit;
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

/* An invisible bold copy of the label holds each button at its bold width,
   so making one active doesn't nudge its neighbours sideways. */
.cal-view-switch .view-button::after {
  content: attr(data-label);
  height: 0;
  overflow: hidden;
  visibility: hidden;
  font-weight: 600;
  user-select: none;
  pointer-events: none;
}

.cal-view-switch .view-button:hover {
  color: var(--cal-fg);
}

.cal-view-switch .view-button.active {
  background: var(--cal-fg);
  color: var(--cal-surface-alt);
  font-weight: 600;
}

.cal-view-switch .view-button:focus-visible {
  outline: 2px solid var(--cal-focus);
  outline-offset: -2px;
}

@media (max-width: 600px) {
  /* Fixed rows on a phone: title, then the view switch full width, then
     dates on the left and refresh/print on the right. Left to wrap freely,
     the controls reflowed whenever the dates were hidden (List view), so
     buttons jumped between rows as the view changed. */
  .preview-title {
    flex-basis: 100%;
  }

  .cal-nav {
    column-gap: 0.5rem;
  }

  .cal-view-switch {
    flex-basis: 100%;
  }

  .cal-view-switch .view-button {
    flex: 1 1 0;
  }

  .cal-nav-dates {
    order: 1;
  }

  .cal-refresh {
    order: 2;
    margin-left: auto;
  }

  .cal-print {
    order: 3;
  }

  /* Seven slivers of a week don't help on a phone. */
  .cal-view-switch .view-button--wide {
    display: none;
  }
}

/* The longest day title ("Wednesday, 29 September 2027") wraps to a second
   line on the narrowest phones, pushing the controls down on those days. */
@media (max-width: 380px) {
  .preview-title {
    font-size: 1.125rem;
  }
}

/* Which colour is which, for the calendars ticked. */
.cal-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1.25rem;
  margin: 0.75rem 0 0;
  padding: 0;
  list-style: none;
  font-size: 0.8125rem;
  color: var(--cal-muted);
}

.cal-legend li {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.cal-legend-swatch {
  width: 0.75rem;
  height: 0.75rem;
  border-radius: 3px;
}

/* --- Grid --- */
.cal-card-body {
  padding: 0;
}

.cal-status {
  margin: 0 0 0.75rem;
}

/* #calendar-grid[hidden] must out-rank .cal-grid's own `display: grid` -
   same-specificity class selector vs. the UA's [hidden]{display:none} is a
   tie broken by cascade order, and .cal-grid (an author style) wins over
   the UA default regardless of source order, so switching to Day view was
   leaving the month/week grid visible underneath the day agenda. */
#calendar-grid[hidden] {
  display: none;
}

.cal-grid {
  display: grid;
  /* minmax(0, 1fr), not plain 1fr: grid tracks otherwise refuse to shrink
     below their content's intrinsic width (a long unbroken chip label),
     which was overflowing the page at narrow widths instead of the 7
     columns fitting evenly. */
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 1px;
  background: var(--cal-border);
  border: 1px solid var(--cal-border);
  border-radius: 6px;
  overflow: hidden;
  width: 100%;
  box-sizing: border-box;
}

.cal-weekday {
  background: var(--cal-surface);
  color: var(--cal-muted);
  font-size: 0.75rem;
  font-weight: 500;
  text-align: center;
  padding: 0.45rem 0;
}

.cal-day {
  background: var(--cal-surface-alt);
  min-height: 5.5rem;
  min-width: 0;
  padding: 0.35rem;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  box-sizing: border-box;
  overflow: hidden;
  transition: background-color 150ms ease;
}

@media (max-width: 600px) {
  .cal-day {
    min-height: 4rem;
    padding: 0.25rem;
  }
}

.cal-day:focus-visible {
  /* calendar.css's own token (not index.html's --link-color) - keeps this
     stylesheet self-contained rather than reaching into the host page's
     namespace. */
  outline: 2px solid var(--cal-focus);
  outline-offset: -2px;
}

/* Week view: same 7-column grid, just one row and more vertical room per
   day since there are only 7 cells to fit instead of 42. */
.cal-grid--week .cal-day {
  min-height: 14rem;
}

/* Day view: a single day's events, full width, no truncation - reuses the
   same .day-event row markup as the day-detail dialog. */
.cal-day:nth-child(7n + 6),
.cal-day:nth-child(7n) {
  background: var(--cal-surface-weekend);
}

.cal-day:hover {
  background: var(--cal-surface);
}

.cal-day.other-month {
  opacity: 0.35;
}

.cal-day-number {
  font-size: 0.75rem;
  color: var(--cal-muted);
}

.cal-day.is-today .cal-day-number {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.3rem;
  height: 1.3rem;
  border-radius: 50%;
  background: var(--cal-today-ring);
  color: var(--cal-surface-alt);
  font-weight: 600;
}

/* Titles wrap rather than truncate: month view clamps at three lines (the
   ellipsis only shows for a rare longer title), week view has the height
   to show them in full, and narrow screens - where a column is ~50px and
   wrapping would give ragged chips - fall back to one line. The full
   title is also on the chip's title attribute. */
.cal-chip {
  font-size: 0.7rem;
  line-height: 1.25;
  padding: 0.1rem 0.35rem;
  border-radius: 4px;
  min-width: 0;
  overflow: hidden;
  overflow-wrap: anywhere;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 3;
}

.cal-grid--week .cal-chip {
  display: block;
}

@media (max-width: 600px) {
  .cal-chip,
  .cal-grid--week .cal-chip {
    display: block;
    white-space: nowrap;
    overflow-wrap: normal;
    text-overflow: ellipsis;
  }
}

.cal-more {
  font-size: 0.68rem;
  color: var(--cal-muted);
}

/* Day dialog: a floating sheet (shadow earned, no border), weekday label
   over the date, an x to close, then the event rows. */
#day-dialog {
  width: min(40rem, calc(100vw - 2rem));
  max-height: min(80vh, 40rem);
  padding: 1.25rem 1.5rem 1.5rem;
  border: 0;
  border-radius: 12px;
  color: var(--cal-fg);
  background: var(--cal-surface-alt);
  box-shadow: 0 24px 48px -12px rgba(0, 0, 0, 0.28), 0 0 0 1px rgba(0, 0, 0, 0.04);
}

#day-dialog::backdrop {
  background: rgba(0, 0, 0, 0.32);
}

@media (prefers-reduced-motion: no-preference) {
  #day-dialog[open] {
    animation: dialog-in 160ms cubic-bezier(0.2, 0.7, 0.2, 1);
  }

  @keyframes dialog-in {
    from { opacity: 0; transform: translateY(6px) scale(0.98); }
    to { opacity: 1; transform: none; }
  }
}

/* Under an event opened from a shared link: what this site is, and a way to
   subscribe (showSubscribeInvite() in calendar.ts). */
.day-dialog-invite {
  display: grid;
  gap: 0.75rem;
  margin-top: 1.25rem;
  padding-top: 1rem;
  border-top: 1px solid var(--cal-border);
}

.day-dialog-invite[hidden] {
  display: none;
}

.day-dialog-invite p {
  margin: 0;
  font-size: 0.875rem;
  line-height: 1.5;
  color: var(--cal-muted);
  text-wrap: pretty;
}

.day-dialog-invite strong {
  color: var(--cal-fg);
  font-weight: 600;
}

.day-dialog-invite-button {
  min-height: 2.75rem;
  padding: 0.5rem 1rem;
  border: 0;
  border-radius: 8px;
  background: var(--cal-fg);
  color: var(--cal-surface-alt);
  font: inherit;
  font-size: 0.9375rem;
  font-weight: 600;
  cursor: pointer;
}

.day-dialog-invite-button:focus-visible {
  outline: 2px solid var(--cal-fg);
  outline-offset: 2px;
}

.day-dialog-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
}

#day-dialog h3 {
  display: grid;
  gap: 0.1rem;
  margin: 0;
  font-size: 1.125rem;
  font-weight: 600;
  letter-spacing: -0.02em;
  line-height: 1.25;
  color: var(--cal-fg);
}

.day-dialog-weekday {
  font-size: 0.8125rem;
  font-weight: 500;
  letter-spacing: 0;
  color: var(--cal-muted);
}

/* Previous day, next day, close - top right, so on a phone they stay in the
   pinned heading. */
.day-dialog-actions {
  display: flex;
  flex-shrink: 0;
  align-items: center;
  gap: 0.25rem;
  margin: -0.6rem -0.85rem 0 0;
}

.day-dialog-step {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.75rem;
  height: 2.75rem;
  border: 1px solid var(--cal-border);
  border-radius: 8px;
  background: transparent;
  color: var(--cal-fg);
  cursor: pointer;
  transition: background-color 150ms ease;
}

.day-dialog-step:hover {
  background: var(--cal-surface);
}

.day-dialog-step:focus-visible {
  outline: 2px solid var(--cal-focus);
  outline-offset: 2px;
}

.day-dialog-empty {
  margin: 0;
}

#day-dialog-close {
  flex-shrink: 0;
  width: 2.75rem;
  height: 2.75rem;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--cal-muted);
  font-size: 1.35rem;
  line-height: 1;
  cursor: pointer;
  transition: background-color 150ms ease, color 150ms ease;
}

#day-dialog-close:hover {
  background: var(--cal-surface);
  color: var(--cal-fg);
}

#day-dialog-close:focus-visible {
  outline: 2px solid var(--cal-focus);
  outline-offset: 2px;
}

/* Phones: the dialog takes the whole screen, its heading (and close button)
   pinned to the top while a long day or description scrolls under it. */
@media (max-width: 600px) {
  #day-dialog {
    inset: 0;
    width: 100%;
    max-width: none;
    height: 100%;
    height: 100dvh;
    max-height: none;
    margin: 0;
    padding: 0 1rem calc(1.5rem + env(safe-area-inset-bottom));
    border-radius: 0;
    box-shadow: none;
  }

  .day-dialog-head {
    position: sticky;
    top: 0;
    z-index: 1;
    margin: 0 -1rem 0.75rem;
    padding: calc(1rem + env(safe-area-inset-top)) 1rem 0.75rem;
    background: var(--cal-surface-alt);
    border-bottom: 1px solid var(--cal-border);
  }

  .day-dialog-actions {
    margin: -0.6rem -0.6rem 0 0;
  }
}

@media (max-width: 600px) and (prefers-reduced-motion: no-preference) {
  #day-dialog[open] {
    animation: dialog-up 200ms cubic-bezier(0.2, 0.7, 0.2, 1);
  }

  @keyframes dialog-up {
    from { opacity: 0; transform: translateY(24px); }
    to { opacity: 1; transform: none; }
  }
}

/* Event rows: time column, body, and a bar in the calendar's colour. */
.day-events {
  display: grid;
  gap: 0.25rem;
}

.day-event {
  position: relative;
  display: grid;
  grid-template-columns: 4.5rem minmax(0, 1fr);
  gap: 0 1rem;
  padding: 0.6rem 0 0.6rem 1rem;
}

.day-event::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0.7rem;
  bottom: 0.7rem;
  width: 3px;
  border-radius: 2px;
  background: var(--event-color, var(--cal-fg));
}

.day-event-time {
  display: grid;
  align-content: start;
  gap: 0.1rem;
  padding-top: 0.15rem;
  font-size: 0.8125rem;
  line-height: 1.3;
  font-variant-numeric: tabular-nums;
  color: var(--cal-muted);
}

.day-event-time span:first-child {
  color: var(--cal-fg);
  font-weight: 500;
}

.day-event-body {
  min-width: 0;
}

.day-event-title {
  margin: 0;
  font-size: 0.9375rem;
  font-weight: 500;
  line-height: 1.35;
  letter-spacing: -0.01em;
  color: var(--cal-fg);
  text-wrap: pretty;
}

/* A multi-day event's whole span (eventSpanText()). */
.day-event-span {
  margin-top: 0.1rem;
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--cal-fg);
}

.day-event-meta,
.day-event-location {
  margin-top: 0.1rem;
  font-size: 0.8125rem;
  color: var(--cal-muted);
}

.day-event-desc {
  margin: 0.4rem 0 0;
  font-size: 0.875rem;
  line-height: 1.5;
  color: var(--cal-fg);
  text-wrap: pretty;
  white-space: pre-line; /* keep the line breaks typed into descriptions */
}

/* A web address in a description, made into a link (appendLinkified()). */
.day-event-desc-link {
  color: var(--cal-fg);
  text-decoration: underline;
  text-decoration-color: var(--cal-border);
  text-underline-offset: 0.2em;
  overflow-wrap: anywhere; /* a long address mustn't widen the dialog */
}

.day-event-desc-link:hover {
  text-decoration-color: currentColor;
}

.day-event-link {
  display: inline-block;
  margin-top: 0.4rem;
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--cal-fg);
  text-decoration: underline;
  text-decoration-color: var(--cal-border);
  text-underline-offset: 0.2em;
}

.day-event-link:hover {
  text-decoration-color: currentColor;
}

/* An event's poster (attached in the class rep tool); tap for full size. */
.day-event-poster {
  display: block;
  width: fit-content;
  max-width: min(100%, 22rem);
  margin-top: 0.6rem;
  border: 1px solid var(--cal-border);
  border-radius: 0.5rem;
  overflow: hidden;
  line-height: 0;
}

.day-event-poster img {
  display: block;
  max-width: 100%;
  max-height: 28rem;
  height: auto;
  object-fit: contain;
}

.day-event-poster:focus-visible {
  outline: 2px solid var(--cal-fg);
  outline-offset: 2px;
}

/* Day view agenda on the page reuses the rows with no sheet around them. */
.cal-day-agenda {
  display: grid;
  gap: 0.25rem;
}

/* Same tie-break as #calendar-grid[hidden]: .cal-day-agenda's own display
   would otherwise beat the UA's [hidden] and leave the agenda showing under
   the grid after switching back to Week / Month. */
#calendar-day-agenda[hidden] {
  display: none;
}

/* --- List view: the coming weeks by day. --- */
.cal-list {
  display: grid;
}

.cal-list[hidden] {
  display: none;
}

.cal-list-day {
  display: grid;
  grid-template-columns: 3.5rem minmax(0, 1fr);
  gap: 1rem;
  padding: 0.875rem 0;
  border-top: 1px solid var(--cal-border);
}

.cal-list-date {
  display: flex;
  flex-direction: column;
  align-items: center;
  line-height: 1.15;
}

.cal-list-weekday,
.cal-list-month {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  color: var(--cal-muted);
}

.cal-list-daynum {
  font-size: 1.375rem;
  font-weight: 600;
  color: var(--cal-fg);
}

.cal-list-today {
  margin-top: 0.25rem;
  padding: 0.05rem 0.4rem;
  border-radius: 999px;
  background: var(--cal-today-ring);
  color: var(--cal-surface-alt);
  font-size: 0.6875rem;
  font-weight: 600;
}

.cal-list-items {
  display: grid;
  gap: 0.25rem;
}

.cal-list-item {
  display: grid;
  grid-template-columns: 0.625rem minmax(0, 1fr);
  gap: 0.75rem;
  align-items: start;
  min-height: 2.75rem;
  padding: 0.25rem 0.5rem 0.25rem 0.25rem;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--cal-fg);
  font-family: inherit;
  text-align: left;
  cursor: pointer;
}

.cal-list-item:hover {
  background: var(--cal-surface-weekend);
}

.cal-list-dot {
  width: 0.625rem;
  height: 0.625rem;
  margin-top: 0.45rem;
  border-radius: 50%;
  background: var(--dot-color);
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.08);
}

.cal-list-text {
  display: grid;
}

.cal-list-title {
  font-size: 1rem;
  font-weight: 600;
  line-height: 1.4;
  text-wrap: pretty;
}

.cal-list-meta {
  font-size: 0.875rem;
  color: var(--cal-muted);
}

.cal-list-more {
  justify-self: start;
  min-height: 2.75rem;
  margin-top: 0.5rem;
  padding: 0 1rem;
  border: 1px solid var(--cal-border);
  border-radius: 8px;
  background: var(--cal-surface-alt);
  color: var(--cal-fg);
  font-family: inherit;
  font-size: 0.9375rem;
  font-weight: 500;
  cursor: pointer;
}

/* --- Help: each calendar's address, to copy. --- */
.copy-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(15rem, 1fr));
  gap: 0.5rem;
  padding: 0;
  list-style: none;
}

.copy-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  padding: 0.25rem 0.25rem 0.25rem 0.75rem;
  border: 1px solid var(--cal-border);
  border-radius: 10px;
}

.copy-name {
  flex-grow: 1;
  font-size: 0.9375rem;
}

.copy-button {
  min-height: 2.5rem;
  padding: 0 0.875rem;
  border: 1px solid var(--cal-border);
  border-radius: 8px;
  background: var(--cal-surface-alt);
  color: var(--cal-fg);
  font-family: inherit;
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
}

.copy-button.is-copied {
  border-color: transparent;
  color: var(--success, #1a7a3c);
  font-weight: 600;
}

/* Shown when the browser won't let the page copy: the address, to copy by hand. */
.copy-row code {
  flex-basis: 100%;
  margin: 0 0.5rem 0.5rem 0;
  white-space: normal;
  overflow-wrap: anywhere;
  user-select: all;
}

@media (prefers-reduced-motion: reduce) {
  .cal-tile,
  .add-link,
  .icon-button,
  .cal-nav-dates button,
  .cal-day,
  #add-progress-fill {
    transition: none;
  }

  .cal-refresh.is-busy svg {
    animation: none;
  }
}

/* --- Below the calendar: next day off, and recently changed. Each a strip
   under the legend, hidden when it has nothing to say. --- */
.cal-strip {
  margin: 1rem 0 0;
  padding: 0.75rem 1rem;
  border: 1px solid var(--cal-border);
  border-radius: 8px;
  background: var(--cal-surface-alt);
  color: var(--cal-fg);
  font-size: 0.9375rem;
}

.cal-strip[hidden] {
  display: none;
}

.cal-strip-label {
  display: block;
  margin-bottom: 0.125rem;
  color: var(--cal-muted);
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.cal-dayoff {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 2rem;
}

.cal-dayoff-item {
  margin: 0;
}

.cal-changes-list {
  display: grid;
  gap: 0.125rem;
  margin: 0.25rem 0 0;
  padding: 0;
  list-style: none;
}

.cal-change {
  display: grid;
  grid-template-columns: 0.625rem minmax(0, 1fr) auto;
  gap: 0.75rem;
  align-items: start;
  width: 100%;
  padding: 0.375rem 0.5rem 0.375rem 0.25rem;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--cal-fg);
  font: inherit;
  text-align: left;
}

button.cal-change {
  cursor: pointer;
}

button.cal-change:hover {
  background: var(--cal-surface-weekend);
}

button.cal-change:focus-visible,
.cal-changes-more:focus-visible,
.share-selection-button:focus-visible {
  outline: 2px solid var(--cal-focus);
  outline-offset: 2px;
}

.cal-change .cal-list-dot {
  margin-top: 0.4rem;
}

.cal-change-text {
  display: grid;
}

.cal-change-title {
  font-weight: 600;
}

.cal-change-title.is-cancelled {
  text-decoration: line-through;
  color: var(--cal-muted);
}

.cal-change-what,
.cal-change-when {
  color: var(--cal-muted);
  font-size: 0.875rem;
}

.cal-change-when {
  white-space: nowrap;
  padding-top: 0.125rem;
}

.cal-changes-foot {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.25rem 1rem;
  margin-top: 0.375rem;
}

.cal-changes-note {
  margin: 0;
  color: var(--cal-muted);
  font-size: 0.8125rem;
}

.cal-changes-more {
  padding: 0.25rem 0;
  border: 0;
  background: none;
  color: var(--link-color);
  font: inherit;
  font-size: 0.875rem;
  cursor: pointer;
}

@media (max-width: 600px) {
  /* No room for "2 days ago" on phones; drop it and its column. */
  .cal-change {
    grid-template-columns: 0.625rem minmax(0, 1fr);
  }

  .cal-change-when {
    display: none;
  }
}

/* --- Share these calendars (under step 1's ticks) --- */
.share-selection {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.25rem 0.75rem;
  margin-top: 0.75rem;
}

.share-selection-button {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  min-height: 2.5rem;
  padding: 0 0.875rem;
  border: 1px solid var(--cal-border);
  border-radius: 8px;
  background: var(--cal-surface-alt);
  color: var(--cal-fg);
  font: inherit;
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
}

.share-selection-button[hidden] {
  display: none;
}

.share-selection-button:hover {
  background: var(--cal-surface);
}

/* Print: a borderless icon, like Refresh. */
.cal-print {
  border: 0;
  background: transparent;
  color: var(--cal-muted);
}

/* Shown only on paper, and the location only on paper (on screen it's in
   the day's dialog). */
.print-heading,
.cal-list-location {
  display: none;
}

/* --- Print: the List view to the end of term, and nothing else. --- */
@media print {
  :root {
    color-scheme: light;
  }

  body {
    background: #fff !important;
    color: #000 !important;
  }

  .hero,
  .subscribe,
  .help,
  .cal-nav,
  .cal-strip,
  .cal-legend,
  .cal-status,
  .cal-list-more,
  #calendar-grid,
  #calendar-day-agenda,
  #theme-toggle {
    display: none !important;
  }

  #calendar-list {
    display: grid !important;
  }

  .print-heading {
    display: block;
    margin: 0 0 1rem;
    font-size: 1.125rem;
    font-weight: 600;
  }

  .cal-list-day {
    break-inside: avoid;
  }

  .cal-list-item {
    min-height: 0;
    color: #000;
  }

  .cal-list-dot {
    print-color-adjust: exact;
    -webkit-print-color-adjust: exact;
  }

  .cal-list-meta,
  .cal-list-location {
    color: #333;
  }

  .cal-list-location {
    display: block;
    font-size: 0.875rem;
  }
}
