:root {
  color-scheme: light dark;
  --page-bg: #fafaf7;
  --text: #1c1c1a;
  --muted: #66665f;
  --border: #dcdcd3;
  --surface: #ffffff;
  --accent: #1f5fbf;
  --notice-bg: #fff3cf;
  --notice-border: #e8cf7a;
  --error-bg: #fde4e1;
  --error-border: #e5a39b;
  --ppm: 1.3px; /* pixels per minute in the week grid (menuRoomMin in view.go depends on it) */
  --head: 2.5rem; /* height of the day heading row in the week grid */
  --bar-h: 3.25rem; /* height of the site header */
  --lane-min: 3.6rem; /* narrowest a lesson may get when lessons overlap */
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --page-bg: #141413;
    --text: #ececE6;
    --muted: #a0a099;
    --border: #36362f;
    --surface: #1d1d1b;
    --accent: #7fb0ff;
    --notice-bg: #3a3112;
    --notice-border: #6e5c1c;
    --error-bg: #3d1d19;
    --error-border: #7a3a32;
  }
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--page-bg); color: var(--text); }
a { color: var(--accent); }
h1 { font-size: 1.6rem; line-height: 1.2; margin: 0.5rem 0 0.75rem; }
h2 { font-size: 1.1rem; margin: 1.5rem 0 0.5rem; }

.wrap { max-width: 76rem; margin: 0 auto; padding: 0 1rem; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

header.site { position: sticky; top: 0; z-index: 30; border-bottom: 1px solid var(--border); background: var(--surface); }
.bar { display: flex; align-items: center; gap: 0.75rem; height: var(--bar-h); }
.brand { font-weight: 700; font-size: 1.15rem; text-decoration: none; color: var(--text); letter-spacing: 0.01em; }

/* Header search: a compact box whose results drop down as a panel. */
.hsearch { position: relative; flex: 1; min-width: 0; max-width: 26rem; margin-left: auto; }
.hsearch input {
  width: 100%; padding: 0.4rem 0.8rem; font: inherit; font-size: 0.95rem;
  border: 1px solid var(--border); border-radius: 999px; background: var(--page-bg); color: var(--text);
}
.hsearch input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.qpanel {
  position: absolute; top: calc(100% + 0.5rem); right: 0; width: min(26rem, calc(100vw - 2rem));
  max-height: calc(100vh - var(--bar-h) - 1.5rem); overflow-y: auto; padding: 0.3rem 0.4rem 0.5rem;
  background: var(--surface); border: 1px solid var(--border); border-radius: 0.6rem;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.3);
}
.qpanel h3, .drawer-panel h3 {
  margin: 0.7rem 0.4rem 0.25rem; font-size: 0.72rem; font-weight: 600; letter-spacing: 0.05em;
  text-transform: uppercase; color: var(--muted);
}
.qpanel .hint { margin: 0.5rem 0.4rem; font-size: 0.9rem; }
.qlist, .drawer-favs { list-style: none; margin: 0; padding: 0; }
.qlist a, .drawer-favs a {
  display: flex; flex-direction: column; padding: 0.4rem 0.5rem; border-radius: 0.4rem;
  color: inherit; text-decoration: none;
}
.qlist a:hover, .qlist a:focus-visible, .drawer-favs a:hover, .drawer-favs a:focus-visible { background: var(--page-bg); outline: none; }
.qlist a:focus-visible, .drawer-favs a:focus-visible { box-shadow: inset 0 0 0 2px var(--accent); }
.qlist .name, .drawer-favs .name { font-weight: 600; }
.qlist .meta, .drawer-favs .meta { font-size: 0.8rem; }
@media (max-width: 40rem) {
  .hsearch { position: static; }
  .qpanel { position: fixed; top: var(--bar-h); left: 0; right: 0; width: auto; border-radius: 0 0 0.6rem 0.6rem; border-top: 0; }
}

/* Switcher drawer: a <details>, so it opens without JavaScript. */
.drawer > summary {
  display: flex; align-items: center; gap: 0.4rem; padding: 0.35rem 0.6rem; cursor: pointer; list-style: none;
  border: 1px solid var(--border); border-radius: 0.5rem; font-size: 0.9rem; white-space: nowrap; user-select: none;
}
.drawer > summary::-webkit-details-marker { display: none; }
.drawer > summary:hover, .drawer[open] > summary { border-color: var(--accent); }
.drawer > summary:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
@media (max-width: 40rem) {
  .drawer-lbl { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
}
.drawer[open]::before { content: ""; position: fixed; inset: var(--bar-h) 0 0 0; background: rgba(0, 0, 0, 0.45); z-index: 39; }
.drawer-panel {
  position: fixed; top: var(--bar-h); left: 0; bottom: 0; z-index: 40; width: min(22rem, 88vw);
  overflow-y: auto; padding: 0.9rem 1rem 2rem; background: var(--surface);
  border-right: 1px solid var(--border); box-shadow: 0 0 30px rgba(0, 0, 0, 0.35);
}
.drawer-school { margin: 0 0 0.75rem; display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 0.25rem 0.75rem; font-weight: 600; }
.drawer-school .change { font-size: 0.85rem; font-weight: 400; }
.drawer-filter {
  width: 100%; padding: 0.45rem 0.8rem; font: inherit; border: 1px solid var(--border);
  border-radius: 0.5rem; background: var(--page-bg); color: var(--text);
}
.drawer-filter[hidden] { display: none; }
.drawer-chips { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 0.35rem; }
.drawer-chips[hidden], .drawer-favs[hidden], .drawer-chips li[hidden], .drawer-favs li[hidden] { display: none; }
.drawer-chips a {
  display: block; padding: 0.3rem 0.65rem; font-size: 0.9rem; color: inherit; text-decoration: none;
  background: var(--page-bg); border: 1px solid var(--border); border-radius: 999px;
}
.drawer-chips a:hover, .drawer-chips a:focus-visible { border-color: var(--accent); color: var(--accent); }
.drawer a[aria-current] { border-color: var(--accent); color: var(--accent); font-weight: 600; }

main { padding-top: 1rem; padding-bottom: 2rem; min-height: 60vh; }
.foot { color: var(--muted); font-size: 0.85rem; padding-bottom: 2rem; }

.meta, .hint { color: var(--muted); }
.crumbs { font-size: 0.9rem; color: var(--muted); }

/* Search */
.search { display: flex; gap: 0.5rem; margin: 1rem 0; }
.search input {
  flex: 1; min-width: 0; padding: 0.7rem 0.9rem; font: inherit;
  border: 1px solid var(--border); border-radius: 0.5rem;
  background: var(--surface); color: var(--text);
}
.search button {
  padding: 0.7rem 1.2rem; font: inherit; font-weight: 600; cursor: pointer;
  border: 0; border-radius: 0.5rem; background: var(--accent); color: var(--page-bg);
}
.cards { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.5rem; }
.cards a {
  display: flex; flex-direction: column; padding: 0.7rem 0.9rem; text-decoration: none; color: inherit;
  background: var(--surface); border: 1px solid var(--border); border-radius: 0.5rem;
}
.cards a:hover, .cards a:focus-visible { border-color: var(--accent); }
.cards .name { font-weight: 600; }
.cards .meta { font-size: 0.875rem; }

/* Favourites: a card plus a remove button */
.favs li { display: flex; gap: 0.5rem; align-items: stretch; }
.favs li > a { flex: 1; min-width: 0; }
.favs li form { display: flex; }
button.icon {
  width: 2.75rem; font: inherit; cursor: pointer; color: var(--muted);
  background: var(--surface); border: 1px solid var(--border); border-radius: 0.5rem;
}
button.icon:hover, button.icon:focus-visible { color: var(--text); border-color: var(--accent); }

/* Schedule title with the save button */
.titlebar { display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; }
.titlebar h1 { margin: 0.5rem 0 0.75rem; }
.fav-btn {
  padding: 0.4rem 0.9rem; font: inherit; cursor: pointer; color: var(--text);
  background: var(--surface); border: 1px solid var(--border); border-radius: 999px;
}
.fav-btn:hover, .fav-btn:focus-visible { border-color: var(--accent); }
.fav-btn.on { color: var(--accent); border-color: var(--accent); font-weight: 600; }

/* Class and room pickers */
.chips { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 0.5rem; }
.chips a {
  display: block; padding: 0.4rem 0.8rem; text-decoration: none; color: inherit;
  background: var(--surface); border: 1px solid var(--border); border-radius: 999px;
}
.chips a:hover, .chips a:focus-visible { border-color: var(--accent); color: var(--accent); }

.notice { padding: 0.6rem 0.9rem; border-radius: 0.5rem; background: var(--notice-bg); border: 1px solid var(--notice-border); }
.notice.error { background: var(--error-bg); border-color: var(--error-border); }

/* A message the school left in its own words */
blockquote.note {
  margin: 1rem 0; padding: 0.7rem 1rem; border-left: 4px solid var(--accent);
  background: var(--surface); border-radius: 0 0.5rem 0.5rem 0;
}
blockquote.note p { margin: 0; }
blockquote.note footer { margin-top: 0.4rem; font-size: 0.85rem; color: var(--muted); }

/* Running text, such as the about page */
.prose { max-width: 42rem; line-height: 1.5; }
.prose code { overflow-wrap: anywhere; background: var(--surface); border: 1px solid var(--border); border-radius: 0.25rem; padding: 0.1rem 0.35rem; font-size: 0.9em; }

/* Week navigation */
.weeknav { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 0.5rem; margin: 0.5rem 0 1rem; }
.weeknav .current { text-align: center; }
.weeknav .current .meta { display: block; font-size: 0.85rem; }
.weeknav a { text-decoration: none; padding: 0.35rem 0.7rem; border: 1px solid var(--border); border-radius: 0.5rem; background: var(--surface); }
.weeknav a.today-link { grid-column: 1 / -1; justify-self: start; font-size: 0.9rem; }

/* Schedule: a time-positioned week grid, on every screen size. It scrolls
   sideways when the week is wider than the screen; the hour axis stays put.
   A day's column is as wide as its busiest moment needs (--dl lessons side
   by side), so overlapping lessons stay readable. */
.weekscroll { overflow-x: auto; overscroll-behavior-x: contain; padding-bottom: 0.25rem; }
@media (max-width: 78rem) { .weekscroll { margin-inline: -1rem; } }
.week { display: flex; gap: 0 0.3rem; width: max-content; min-width: 100%; }
.axis {
  flex: none; width: 3rem; position: sticky; left: 0; z-index: 5;
  padding-top: var(--head); background: var(--page-bg);
  height: calc(var(--head) + (var(--range-end) - var(--range-start)) * var(--ppm));
  font-size: 0.75rem; color: var(--muted); font-variant-numeric: tabular-nums;
}
.axis span {
  position: absolute; right: 0.3rem;
  top: calc(var(--head) + (var(--m) - var(--range-start)) * var(--ppm));
  transform: translateY(-0.55em);
}
.day {
  flex: 1 0 max(7rem, calc(var(--dl, 1) * var(--lane-min)));
  scroll-margin: calc(var(--bar-h) + 0.5rem) 0 0 3.3rem;
}
.day h2 {
  height: var(--head); margin: 0; display: flex; align-items: center; justify-content: center;
  font-size: 0.95rem; text-align: center;
}
.day.today h2 { background: var(--accent); color: var(--page-bg); border-radius: 0.4rem 0.4rem 0 0; }
.lessons {
  list-style: none; margin: 0; padding: 0; position: relative;
  height: calc((var(--range-end) - var(--range-start)) * var(--ppm));
  border-left: 1px solid var(--border);
  background-image: repeating-linear-gradient(
    to bottom, transparent 0, transparent calc(60 * var(--ppm) - 1px),
    var(--border) calc(60 * var(--ppm) - 1px), var(--border) calc(60 * var(--ppm)));
}
.day.today .lessons { background-color: color-mix(in srgb, var(--accent) 8%, transparent); }

/* A lesson is a slot placed by time and lane, sized by its container: the
   box inside adapts to the room it gets (see the container queries). */
.lesson {
  position: absolute; container-type: size; outline: none; color: var(--lfg, #111);
  top: calc((var(--s) - var(--range-start)) * var(--ppm));
  height: calc((var(--e) - var(--s)) * var(--ppm) - 2px);
  left: calc(100% * var(--lane) / var(--lanes) + 1px);
  width: calc(100% * var(--span) / var(--lanes) - 2px);
  font-size: 0.75rem; line-height: 1.25; border-radius: 0.35rem;
}
.lesson:focus-visible .box { outline: 2px solid var(--accent); outline-offset: 1px; }
.box {
  height: 100%; overflow: hidden; padding: 0.2rem 0.35rem; border-radius: inherit;
  background: var(--lbg, #e9e9e1); color: var(--lfg, #111);
}
.box time { display: none; font-size: 0.68rem; font-variant-numeric: tabular-nums; opacity: 0.8; white-space: nowrap; }
.box .line { display: block; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.box .first { font-weight: 600; }
.box .block { display: block; font-size: 0.68rem; opacity: 0.75; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }

/* Room for time + three lines: one line each, with the time when it fits. */
@container (min-height: 4.1rem) and (min-width: 6rem) { .box time { display: block; } }
/* Less than that: the lines run together and wrap, clamped to what fits. */
@container (max-height: 4.1rem) {
  .box .text { display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 3; overflow: hidden; overflow-wrap: anywhere; }
  .box .line, .box .block { display: inline; white-space: normal; overflow: visible; }
}
@container (max-height: 3.2rem) { .box .text { -webkit-line-clamp: 2; } }
@container (max-height: 2.27rem) { .box .text { -webkit-line-clamp: 1; } }

/* Hover or focus (a tap focuses) opens the lesson to its full content. */
.lesson:hover, .lesson:focus { z-index: 15; }
.lesson:hover .box, .lesson:focus .box {
  position: absolute; top: 0; left: 0;
  width: max-content; min-width: 100%; max-width: 16rem; height: auto; min-height: 100%; overflow: visible;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.25), 0 6px 20px rgba(0, 0, 0, 0.35);
}
.lesson:hover .box time, .lesson:focus .box time { display: block; }
.lesson:hover .box .text, .lesson:focus .box .text { display: block; overflow: visible; }
.lesson:hover .box .line, .lesson:focus .box .line,
.lesson:hover .box .block, .lesson:focus .box .block { display: block; white-space: normal; overflow: visible; }
/* Opens towards the side with room: schedule.js sets data-side when it can; the
   last two days are the fallback, since they would run off the right edge. */
:where(.week > .day:nth-last-child(-n + 2)) .lesson:hover .box,
:where(.week > .day:nth-last-child(-n + 2)) .lesson:focus .box { left: auto; right: 0; }
.lesson[data-side="left"]:hover .box, .lesson[data-side="left"]:focus .box { left: 0; right: auto; }
.lesson[data-side="right"]:hover .box, .lesson[data-side="right"]:focus .box { left: auto; right: 0; }

/* A lunch lesson with the day's menu: the dishes open in a popover, since
   the lesson is only as tall as the lunch break. */
.lesson.has-menu { cursor: help; }
.lesson.has-menu::after { content: "▾"; position: absolute; top: 0.05rem; right: 0.3rem; font-size: 0.7rem; opacity: 0.6; pointer-events: none; }
.lesson .lunch-menu {
  display: none; position: absolute; z-index: 20; top: 100%; left: 0;
  width: max(100%, 15rem); margin: 0; padding: 0.6rem 0.7rem; border: 1px solid var(--border);
  border-radius: 0.5rem; background: var(--surface); color: var(--text);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.25); font-size: 0.85rem; line-height: 1.35; cursor: default;
}
.lesson.menu-up .lunch-menu { top: auto; bottom: 100%; }
.lesson.has-menu:hover .lunch-menu,
.lesson.has-menu:focus .lunch-menu,
.lesson.has-menu:focus-within .lunch-menu { display: block; }
:where(.week > .day:nth-last-child(-n + 2)) .lesson .lunch-menu { left: auto; right: 0; }
.lesson[data-side="left"] .lunch-menu { left: 0; right: auto; }
.lesson[data-side="right"] .lunch-menu { left: auto; right: 0; }
.lesson .lunch-head { font-size: 0.8rem; }
.lesson .lunch-menu .dishes { gap: 0.35rem; margin-top: 0.25rem; }
.lesson .lunch-menu .tag { color: inherit; border-color: currentColor; opacity: 0.85; }
.lesson .lunch-menu .menu-note { margin: 0.25rem 0 0; font-size: 0.85rem; }
.free { color: var(--muted); margin: 0; }
.source { margin-top: 1.5rem; font-size: 0.85rem; }

/* Lunch menus */
.lunch { margin-top: 2rem; }
.lunch-link { margin-top: 1.5rem; }
.menu { display: grid; gap: 0.75rem; }
.menu-day { padding: 0.7rem 0.9rem; background: var(--surface); border: 1px solid var(--border); border-radius: 0.5rem; }
.menu-day.today { border-color: var(--accent); }
.menu-day h3 { margin: 0 0 0.4rem; font-size: 0.95rem; }
.menu-day.today h3 { color: var(--accent); }
.menu-note { margin: 0 0 0.4rem; font-style: italic; }
.dishes { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.5rem; }
.dishes .kind { font-size: 0.8rem; color: var(--muted); }
.dishes .labels { display: flex; flex-wrap: wrap; gap: 0.25rem; margin-top: 0.15rem; }
.tag { font-size: 0.72rem; padding: 0.05rem 0.5rem; border-radius: 999px; border: 1px solid var(--border); color: var(--muted); }
.chips.canteens { margin-bottom: 1rem; }
.chips a.current { border-color: var(--accent); color: var(--accent); font-weight: 600; }
@media (min-width: 56rem) {
  .menu { grid-template-columns: repeat(auto-fit, minmax(12rem, 1fr)); }
}

@media print {
  header.site, .weeknav, .foot, .search, .fav { display: none; }
  .weekscroll { overflow: visible; margin-inline: 0; }
  .week { width: auto; }
  :root { --page-bg: #fff; --text: #000; }
}
