:root {
  color-scheme: light;
  --bg: #f6f7fb;
  --surface: #ffffff;
  --surface-2: #f1f3f8;
  --text: #161a23;
  --muted: #5d6475;
  --border: #e3e6ee;
  --accent: #4f46e5;
  --accent-soft: #eef0ff;
  --shadow: 0 1px 2px rgba(16, 24, 40, .04), 0 4px 16px rgba(16, 24, 40, .06);
  --radius: 14px;

  --c-closure: #dc2626;   --c-closure-bg: #fdecec;
  --c-deadline: #d97706;  --c-deadline-bg: #fdf3e2;
  --c-exam: #7c3aed;      --c-exam-bg: #f2ecfe;
  --c-sports: #059669;    --c-sports-bg: #e5f6ef;
  --c-spirit: #db2777;    --c-spirit-bg: #fce9f2;
  --c-academic: #2563eb;  --c-academic-bg: #e8effd;
  --c-meeting: #475569;   --c-meeting-bg: #eef1f5;
  --c-drill: #6b7280;     --c-drill-bg: #f0f1f3;
  --c-event: #0d9488;     --c-event-bg: #e3f5f3;
}

/* Dark theme: follows the system unless the toggle forces light or dark. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0f1218;
    --surface: #171b24;
    --surface-2: #1e2430;
    --text: #e8ebf2;
    --muted: #98a0b3;
    --border: #2a3140;
    --accent: #8b85ff;
    --accent-soft: #23234a;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 16px rgba(0, 0, 0, .25);
    --c-closure: #f87171;   --c-closure-bg: #3a1a1d;
    --c-deadline: #fbbf24;  --c-deadline-bg: #3a2c12;
    --c-exam: #a78bfa;      --c-exam-bg: #2a2142;
    --c-sports: #34d399;    --c-sports-bg: #12332a;
    --c-spirit: #f472b6;    --c-spirit-bg: #3a1a2c;
    --c-academic: #60a5fa;  --c-academic-bg: #172a46;
    --c-meeting: #94a3b8;   --c-meeting-bg: #222a36;
    --c-drill: #9ca3af;     --c-drill-bg: #24272d;
    --c-event: #2dd4bf;     --c-event-bg: #123330;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0f1218;
  --surface: #171b24;
  --surface-2: #1e2430;
  --text: #e8ebf2;
  --muted: #98a0b3;
  --border: #2a3140;
  --accent: #8b85ff;
  --accent-soft: #23234a;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 16px rgba(0, 0, 0, .25);
  --c-closure: #f87171;   --c-closure-bg: #3a1a1d;
  --c-deadline: #fbbf24;  --c-deadline-bg: #3a2c12;
  --c-exam: #a78bfa;      --c-exam-bg: #2a2142;
  --c-sports: #34d399;    --c-sports-bg: #12332a;
  --c-spirit: #f472b6;    --c-spirit-bg: #3a1a2c;
  --c-academic: #60a5fa;  --c-academic-bg: #172a46;
  --c-meeting: #94a3b8;   --c-meeting-bg: #222a36;
  --c-drill: #9ca3af;     --c-drill-bg: #24272d;
  --c-event: #2dd4bf;     --c-event-bg: #123330;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
a { color: var(--accent); }
h1, h2, h3 { margin: 0; line-height: 1.25; }
.wrap { max-width: 1200px; margin: 0 auto; padding: 0 16px; }
.muted { color: var(--muted); }
.small { font-size: 13px; font-weight: 400; }
[hidden] { display: none !important; }

/* ---------- top bar ---------- */
.chrome { position: sticky; top: 0; z-index: 10; }
.topbar {
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--border);
}
.topbar-inner { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding-top: 12px; padding-bottom: 12px; }
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; flex: 1; }
.brand > div { min-width: 0; }
.brand-mark { font-size: 26px; width: 42px; height: 42px; display: grid; place-items: center; background: var(--accent-soft); border-radius: 12px; flex: none; }
.brand h1 { font-size: 18px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand p { margin: 0; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top-actions { display: flex; align-items: center; gap: 8px; flex: none; }
.grade-picker { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); background: var(--surface-2); border-radius: 10px; padding: 4px 4px 4px 10px; }
.grade-picker select { border: 0; background: var(--surface); color: var(--text); border-radius: 7px; padding: 4px 6px; font: inherit; font-weight: 600; }

/* ---------- buttons / inputs ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  border: 1px solid transparent; border-radius: 10px; padding: 8px 14px;
  font: inherit; font-weight: 600; cursor: pointer; transition: background .15s, opacity .15s;
}
.btn svg { width: 16px; height: 16px; stroke: currentColor; stroke-width: 2.5; fill: none; stroke-linecap: round; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { opacity: .92; }
.btn-primary:disabled { opacity: .55; cursor: progress; }
.btn-ghost { background: transparent; color: var(--muted); border-color: var(--border); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }
.btn.small { padding: 5px 10px; font-size: 13px; }
.url-row { display: flex; gap: 8px; }
.url-row input {
  flex: 1; min-width: 0; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font: inherit;
}
.url-row input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.status { min-height: 1.5em; margin: 8px 0 0; font-size: 14px; color: var(--muted); }
.status.error { color: var(--c-closure); }
.status.busy::before { content: ""; display: inline-block; width: 12px; height: 12px; margin-right: 8px; vertical-align: -1px; border: 2px solid var(--accent); border-right-color: transparent; border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- dialog ---------- */
dialog {
  width: min(560px, calc(100vw - 32px)); border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface); color: var(--text); box-shadow: var(--shadow); padding: 22px;
}
dialog::backdrop { background: rgba(10, 12, 20, .45); }
dialog h2 { font-size: 18px; margin-bottom: 4px; }
dialog h3 { font-size: 14px; margin: 18px 0 8px; }
dialog p { margin: 0 0 12px; }
.history { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; max-height: 220px; overflow: auto; }
.history button { width: 100%; text-align: left; background: var(--surface-2); border: 1px solid transparent; color: var(--text); padding: 8px 10px; border-radius: 9px; cursor: pointer; font: inherit; }
.history button:hover { border-color: var(--border); }
.history button.active { border-color: var(--accent); }
.dialog-foot { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.dialog-foot #sign-out { margin-right: auto; }
.pw-row { display: grid; gap: 6px; margin-bottom: 10px; }
.pw-row label { font-size: 13px; font-weight: 600; }
.pw-row input, #empty-pw {
  padding: 10px 12px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font: inherit;
}
.pw-row input:focus, #empty-pw:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

/* ---------- layout ---------- */
main.wrap { padding-top: 28px; padding-bottom: 48px; }
.section-title { font-size: 16px; font-weight: 700; margin-bottom: 12px; display: flex; align-items: baseline; gap: 8px; }
.section-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 4px; }
.section-head .section-title { margin-bottom: 8px; }
.columns { display: grid; grid-template-columns: minmax(0, 1fr) 360px; gap: 28px; margin-top: 28px; align-items: start; }
.stack { display: grid; grid-template-columns: minmax(0, 1fr); gap: 12px; }
.side-col, .timeline-col { min-width: 0; display: grid; gap: 28px; align-content: start; }
.timeline-col { display: block; }
.card, .ref, .event { overflow-wrap: anywhere; }
.note { background: var(--c-deadline-bg); color: var(--text); border-radius: 10px; padding: 10px 14px; margin: 0 0 16px; font-size: 14px; }

/* ---------- next up: this week ---------- */
.week-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.week-head .section-title { margin-bottom: 0; }
.week-nav { display: flex; align-items: center; gap: 6px; flex: none; }
.icon-btn:disabled { opacity: .35; cursor: default; }
.icon-btn:disabled:hover { background: var(--surface); }
.week { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 8px; }
.wday {
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 8px;
  min-height: 132px; display: flex; flex-direction: column; gap: 8px; min-width: 0;
}
.wday-head { display: flex; align-items: baseline; gap: 6px; padding: 0 2px; }
.wday-dow { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.wday-num { font-size: 20px; font-weight: 750; line-height: 1; }
.wday-today {
  margin-left: auto; font-size: 10.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em;
  color: #fff; background: var(--accent); border-radius: 999px; padding: 2px 7px;
}
.wday.today { border: 2px solid var(--accent); padding: 7px; background: color-mix(in srgb, var(--accent-soft) 55%, var(--surface)); }
.wday.today .wday-dow, .wday.today .wday-num { color: var(--accent); }
.wday.past { opacity: .5; background: transparent; }
.wday-events { display: grid; gap: 5px; align-content: start; }
.wday-none { font-size: 12px; color: var(--muted); padding: 0 2px; }
.wev {
  display: grid; gap: 1px; padding: 5px 7px; border-radius: 7px; cursor: pointer;
  border-left: 3px solid var(--cat); background: var(--surface-2); font-size: 12.5px; line-height: 1.3;
  transition: transform .12s, border-color .12s;
}
.wev:hover { transform: translateY(-1px); }
.wev:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.wev.important { background: var(--cat-bg); }
.wev.important .wev-title { font-weight: 650; }
.wev.minor { opacity: .75; }
.wev-title {
  font-weight: 550; overflow-wrap: anywhere;
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden;
}
.wev-time { font-size: 11.5px; color: var(--muted); }

/* ---------- filters ---------- */
.filters { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.chip-btn {
  border: 1px solid var(--border); background: var(--surface); color: var(--muted); border-radius: 999px;
  padding: 4px 11px; font: inherit; font-size: 13px; cursor: pointer; display: inline-flex; align-items: center; gap: 6px;
}
.chip-btn .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--cat, var(--muted)); }
.chip-btn[aria-pressed="true"] { background: var(--text); color: var(--bg); border-color: var(--text); }

/* ---------- timeline ---------- */
.group { margin-top: 18px; }
.group-title { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 0 0 8px; display: flex; align-items: center; gap: 10px; }
.group-title::after { content: ""; flex: 1; height: 1px; background: var(--border); }
.day { display: grid; grid-template-columns: 58px minmax(0, 1fr); gap: 12px; padding: 4px 0; }
.day + .day { border-top: 1px dashed var(--border); padding-top: 10px; margin-top: 6px; }
.day-badge { text-align: center; border-radius: 12px; padding: 6px 0; background: var(--surface); border: 1px solid var(--border); height: fit-content; }
.day-badge .dow { font-size: 11px; font-weight: 700; text-transform: uppercase; color: var(--muted); letter-spacing: .05em; }
.day-badge .num { font-size: 22px; font-weight: 750; line-height: 1.1; }
.day-badge .mon { font-size: 11px; color: var(--muted); }
.day.today .day-badge { background: var(--accent); border-color: var(--accent); color: #fff; }
.day.today .day-badge .dow, .day.today .day-badge .mon { color: rgba(255, 255, 255, .85); }
.day-events { display: grid; gap: 8px; }

.event {
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 10px 12px;
  border-left: 4px solid var(--cat); box-shadow: var(--shadow);
}
.event.minor { box-shadow: none; background: transparent; opacity: .85; }
.event.important { background: linear-gradient(90deg, var(--cat-bg), var(--surface) 65%); }
.event-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.event-title { font-weight: 600; font-size: 15px; }
.event-meta { display: flex; flex-wrap: wrap; gap: 6px 10px; align-items: center; margin-top: 4px; font-size: 13px; color: var(--muted); }
.event-details { margin: 6px 0 0; font-size: 13.5px; color: var(--muted); }
.event a.more { font-size: 13px; font-weight: 600; text-decoration: none; }
.event a.more:hover { text-decoration: underline; }

.tag {
  display: inline-flex; align-items: center; gap: 4px; font-size: 11.5px; font-weight: 650; border-radius: 999px;
  padding: 2px 8px; background: var(--cat-bg); color: var(--cat); white-space: nowrap;
}
.tag.grade { background: var(--surface-2); color: var(--text); }
.tag.flag { background: var(--c-closure); color: #fff; }

/* category variables */
[data-cat="closure"]  { --cat: var(--c-closure);  --cat-bg: var(--c-closure-bg); }
[data-cat="deadline"] { --cat: var(--c-deadline); --cat-bg: var(--c-deadline-bg); }
[data-cat="exam"]     { --cat: var(--c-exam);     --cat-bg: var(--c-exam-bg); }
[data-cat="sports"]   { --cat: var(--c-sports);   --cat-bg: var(--c-sports-bg); }
[data-cat="spirit"]   { --cat: var(--c-spirit);   --cat-bg: var(--c-spirit-bg); }
[data-cat="academic"] { --cat: var(--c-academic); --cat-bg: var(--c-academic-bg); }
[data-cat="meeting"]  { --cat: var(--c-meeting);  --cat-bg: var(--c-meeting-bg); }
[data-cat="drill"]    { --cat: var(--c-drill);    --cat-bg: var(--c-drill-bg); }
[data-cat="event"]    { --cat: var(--c-event);    --cat-bg: var(--c-event-bg); }

#toggle-past { margin-top: 18px; }
#past { opacity: .7; }

/* ---------- announcements ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.card h3 { font-size: 15px; margin-bottom: 4px; }
.card p { margin: 0; font-size: 14px; color: var(--muted); }
.card .card-img { width: 100%; max-height: 160px; object-fit: cover; border-radius: 9px; margin-bottom: 10px; cursor: zoom-in; background: var(--surface-2); }
.card details { margin-top: 8px; font-size: 14px; }
.card summary { cursor: pointer; color: var(--accent); font-weight: 600; font-size: 13px; }
.card ul.body { margin: 8px 0 0; padding-left: 18px; color: var(--text); }
.card ul.body li { margin: 3px 0; }
.links { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.links a {
  font-size: 12.5px; font-weight: 600; text-decoration: none; background: var(--accent-soft); color: var(--accent);
  padding: 4px 10px; border-radius: 999px; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.links a:hover { text-decoration: underline; }

.lightbox { position: fixed; inset: 0; background: rgba(0, 0, 0, .82); display: grid; place-items: center; z-index: 50; cursor: zoom-out; padding: 16px; }
.lightbox img { max-width: 100%; max-height: 100%; border-radius: 8px; }

/* ---------- reference ---------- */
.reference { margin-top: 40px; }
.ref-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 12px; align-items: start; }
.ref { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.ref summary { list-style: none; cursor: pointer; padding: 12px 14px; font-weight: 600; display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.ref summary::-webkit-details-marker { display: none; }
.ref summary::after { content: "›"; font-size: 20px; line-height: 1; color: var(--muted); transition: transform .15s; }
.ref[open] summary::after { transform: rotate(90deg); }
.ref .ref-body { padding: 0 14px 14px; font-size: 14px; }
.ref .ref-body p { margin: 0 0 6px; }
.ref .old { font-size: 11px; font-weight: 500; color: var(--muted); margin-left: auto; margin-right: 6px; }

/* ---------- other grades ---------- */
.other-grades { margin-top: 40px; border: 1px dashed var(--border); border-radius: var(--radius); background: var(--surface-2); }
.other-grades > summary { cursor: pointer; padding: 14px 16px; font-weight: 700; display: flex; gap: 10px; align-items: baseline; }
.other-body { padding: 0 16px 16px; display: grid; gap: 16px; }

.foot { margin-top: 36px; display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; }

/* ---------- empty ---------- */
.empty { display: grid; place-items: center; min-height: 60vh; }
.empty-card { max-width: 560px; width: 100%; background: var(--surface); border: 1px solid var(--border); border-radius: 18px; padding: 28px; box-shadow: var(--shadow); }
.empty-card h2 { font-size: 22px; margin-bottom: 8px; }
.empty-card p { color: var(--muted); }

/* ---------- responsive ---------- */
@media (max-width: 1040px) {
  .columns { gap: 28px; }
}
@media (max-width: 980px) {
  .columns { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 560px) {
  .btn-primary span { display: none; }
  .brand-mark { display: none; }
  .grade-picker > span { display: none; }
  .grade-picker { padding: 4px; }
  .url-row { flex-direction: column; }
  .day { grid-template-columns: 48px minmax(0, 1fr); gap: 10px; }
}

/* ---------- theme toggle ---------- */
.icon-btn {
  display: inline-grid; place-items: center; width: 38px; height: 38px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text); cursor: pointer; font-size: 22px; line-height: 1;
}
.icon-btn:hover { background: var(--surface-2); }
.icon-btn.small { width: 32px; height: 32px; }
.icon-btn svg { width: 18px; height: 18px; stroke: currentColor; stroke-width: 2; fill: none; stroke-linecap: round; }
/* The icon shows the theme you'd switch to: moon in light mode, sun in dark mode. */
.i-sun { display: none; }
:root[data-theme="dark"] .i-sun { display: block; }
:root[data-theme="dark"] .i-moon { display: none; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .i-sun { display: block; }
  :root:not([data-theme="light"]) .i-moon { display: none; }
}

/* ---------- search ---------- */
.search-row { padding-bottom: 12px; }
.search { position: relative; display: flex; align-items: center; }
.search svg { position: absolute; left: 12px; width: 18px; height: 18px; stroke: var(--muted); stroke-width: 2; fill: none; stroke-linecap: round; pointer-events: none; }
.search input {
  width: 100%; padding: 10px 40px 10px 38px; border-radius: 12px; border: 1px solid var(--border);
  background: var(--surface-2); color: var(--text); font: inherit; font-size: 15px;
}
.search input:focus { outline: 2px solid var(--accent); outline-offset: -1px; background: var(--surface); }
.search input::-webkit-search-cancel-button { display: none; }
.search-clear {
  position: absolute; right: 6px; width: 30px; height: 30px; border: 0; border-radius: 8px; background: transparent;
  color: var(--muted); font-size: 20px; cursor: pointer;
}
.search-clear:hover { background: var(--surface-2); color: var(--text); }
.search-results { display: grid; gap: 24px; }
.search-results .section-title { margin-bottom: 8px; }
.search-summary { margin: 0; color: var(--muted); font-size: 14px; }
mark { background: color-mix(in srgb, #facc15 55%, transparent); color: inherit; border-radius: 3px; padding: 0 1px; }
.tag.past { background: var(--surface-2); color: var(--muted); }

/* ---------- clickable events + event dialog ---------- */
.event { cursor: pointer; transition: transform .12s, box-shadow .12s, border-color .12s; }
.event:hover { transform: translateY(-1px); border-color: var(--cat); }
.event:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.add-cal { font-size: 12px; font-weight: 600; color: var(--muted); white-space: nowrap; opacity: 0; transition: opacity .12s; }
.event:hover .add-cal, .event:focus-visible .add-cal { opacity: 1; }
@media (hover: none) { .add-cal { opacity: 1; } }

.event-dialog { width: min(480px, calc(100vw - 32px)); }
.ev-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.event-dialog h2 { font-size: 20px; margin-bottom: 6px; }
.ev-when { font-weight: 600; color: var(--text); margin: 0 0 10px; }
.ev-details { color: var(--muted); font-size: 14px; margin: 0 0 6px; white-space: pre-line; }
.ev-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 18px; }
.ev-actions .btn { text-decoration: none; }
.ev-hint { margin: 10px 0 0; }

/* ---------- tabs ---------- */
.tabs {
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--border);
}
.tabs-inner { display: flex; gap: 4px; }
.tab {
  position: relative; display: inline-flex; align-items: center; gap: 8px;
  padding: 11px 14px; border: 0; background: transparent; color: var(--muted);
  font: inherit; font-weight: 600; cursor: pointer; border-radius: 0;
}
.tab svg { width: 18px; height: 18px; stroke: currentColor; stroke-width: 2; fill: none; stroke-linecap: round; stroke-linejoin: round; }
.tab:hover { color: var(--text); }
.tab[aria-selected="true"] { color: var(--accent); }
.tab[aria-selected="true"]::after { content: ""; position: absolute; left: 10px; right: 10px; bottom: -1px; height: 3px; border-radius: 3px 3px 0 0; background: var(--accent); }
.tab:focus-visible { outline: 2px solid var(--accent); outline-offset: -4px; border-radius: 8px; }
.tab-count { font-size: 12px; font-weight: 700; background: var(--surface-2); color: var(--muted); border-radius: 999px; padding: 0 7px; min-width: 22px; text-align: center; }
.tab-count:empty { display: none; }
.tab[aria-selected="true"] .tab-count { background: var(--accent-soft); color: var(--accent); }

.panel { animation: fade .18s ease-out; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
.upcoming { margin-top: 28px; }
.other-grades { margin-top: 36px; }

/* ---------- news tab ---------- */
.news-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 14px; align-items: start; }
.news-grid .card-img { max-height: 200px; }

/* ---------- reference tab ---------- */
.ref-groups { display: grid; gap: 32px; margin-top: 18px; }
.ref-group-title {
  font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--muted);
  margin: 0 0 10px 4px;
}
.ref-rows {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); overflow: hidden;
}
.ref-row + .ref-row { border-top: 1px solid var(--border); }
.ref-row > summary, .ref-row.static {
  list-style: none; display: flex; align-items: center; gap: 14px; padding: 14px 18px; cursor: pointer;
}
.ref-row.static { cursor: default; align-items: flex-start; flex-wrap: wrap; }
.ref-row > summary::-webkit-details-marker { display: none; }
.ref-row > summary:hover { background: var(--surface-2); }
.ref-row > summary:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.ref-row-main { flex: 1; min-width: 0; }
.ref-row-title { font-weight: 650; font-size: 15.5px; display: flex; gap: 8px; align-items: baseline; flex-wrap: wrap; }
.ref-row-sum {
  color: var(--muted); font-size: 14px; margin-top: 2px;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.ref-row[open] .ref-row-sum { display: none; }
.chev { flex: none; width: 18px; height: 18px; stroke: var(--muted); stroke-width: 2.2; fill: none; stroke-linecap: round; transition: transform .15s; }
.ref-row[open] .chev { transform: rotate(90deg); }
.ref-row .old { font-size: 11px; font-weight: 500; color: var(--muted); }

.ref-row-body { padding: 0 18px 18px; font-size: 15px; line-height: 1.65; max-width: 70ch; }
.ref-row-body p { margin: 0 0 10px; }
.ref-row-body ul { margin: 0 0 12px; padding-left: 20px; }
.ref-row-body li { margin: 4px 0; }
.ref-row-body li::marker { color: var(--accent); }
.kv { display: grid; grid-template-columns: max-content minmax(0, 1fr); margin: 4px 0 12px; border: 1px solid var(--border); border-radius: 10px; overflow: hidden; }
.kv dt, .kv dd { margin: 0; padding: 7px 12px; font-size: 14px; }
.kv dt { font-weight: 650; font-variant-numeric: tabular-nums; white-space: nowrap; color: var(--text); background: var(--surface-2); }
.kv dt:not(:first-of-type), .kv dd:not(:first-of-type) { border-top: 1px solid var(--border); }
.contact {
  display: flex; gap: 10px; align-items: flex-start; margin: 4px 0 12px; padding: 10px 12px; border-radius: 10px;
  background: var(--surface-2); font-size: 14px;
}
.contact svg { flex: none; width: 18px; height: 18px; margin-top: 2px; stroke: var(--muted); stroke-width: 2; fill: none; }
.ref-row-body .links, .ref-row.static .links { margin-top: 4px; }
.ref-row.static .links { margin-top: 0; }

/* ---------- phone: tab bar at the bottom ---------- */
@media (max-width: 640px) {
  body { padding-bottom: calc(68px + env(safe-area-inset-bottom)); }
  .tabs {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
    border-bottom: 0; border-top: 1px solid var(--border);
    padding-bottom: env(safe-area-inset-bottom);
  }
  .tabs .wrap { padding: 0; }
  .tabs-inner { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0; }
  .tab { flex-direction: column; gap: 2px; padding: 8px 4px 9px; font-size: 11.5px; }
  .tab svg { width: 22px; height: 22px; }
  .tab[aria-selected="true"]::after { display: none; }
  .tab-count { position: absolute; top: 4px; left: calc(50% + 8px); font-size: 10px; padding: 0 5px; min-width: 18px; }
  .news-grid { grid-template-columns: minmax(0, 1fr); }
  .ref-row > summary, .ref-row.static { padding: 13px 14px; }
  .ref-row-body { padding: 0 14px 16px; }
}

@media (max-width: 640px) {
  .section-title { flex-wrap: wrap; row-gap: 2px; }
}

/* ---------- news: masonry columns + tags ---------- */
/* JS deals cards into columns (shortest first) so tall cards don't leave gaps;
   until then (or without JS) it's a plain grid. */
.news-grid.masonry { display: flex; gap: 14px; align-items: flex-start; }
.masonry-col { flex: 1; min-width: 0; display: grid; gap: 14px; }
.news-card { padding: 0; overflow: hidden; border-top: 3px solid var(--cat); }
/* Show flyers whole: full card width, natural height, never cropped. */
.news-card .card-img { display: block; width: 100%; height: auto; max-height: none; object-fit: contain; border-radius: 0; margin: 0; background: var(--surface-2); }
.flyer-img { display: block; width: 100%; padding: 0; border: 0; background: var(--surface-2); cursor: zoom-in; }
.flyer-img img { display: block; width: 100%; height: auto; }
.flyer-card .news-body { padding-top: 12px; padding-bottom: 14px; }
.flyer-card .news-tags { margin-bottom: 0; }
.flyer-card .news-tags + p { margin-top: 8px; }
.news-card .news-body { padding: 14px 16px 16px; }
.news-tags { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.news-card h3 { font-size: 16px; line-height: 1.3; margin-bottom: 6px; }
.news-dates { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.date-chip {
  display: inline-flex; align-items: center; gap: 5px; font-size: 12.5px; font-weight: 600; cursor: pointer;
  padding: 4px 10px; border-radius: 8px; background: var(--surface-2); color: var(--text); border: 1px solid var(--border);
}
.date-chip:hover { border-color: var(--cat); }
.date-chip svg { width: 14px; height: 14px; stroke: var(--cat); stroke-width: 2; fill: none; }
.date-chip .muted { font-weight: 500; }

/* Next Up on phones: one row per day instead of seven narrow columns. */
@media (max-width: 760px) {
  .week { grid-template-columns: minmax(0, 1fr); gap: 6px; }
  .wday { min-height: 0; flex-direction: row; align-items: flex-start; gap: 12px; padding: 8px 10px; }
  .wday.today { padding: 7px 9px; }
  .wday-head { flex-direction: column; align-items: center; gap: 2px; width: 40px; flex: none; padding: 0; }
  .wday-today { margin: 2px 0 0; font-size: 9px; padding: 1px 5px; }
  .wday-events { flex: 1; min-width: 0; }
  .wday.no-events .wday-events { align-self: center; }
  .wev { font-size: 13.5px; }
  .wev-title { -webkit-line-clamp: 2; }
}

/* ---------- search: school website fallback ---------- */
.site-results-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.site-result {
  display: grid; gap: 4px; padding: 12px 14px; border-radius: 12px; text-decoration: none; color: var(--text);
  background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow);
  --cat: var(--accent); --cat-bg: var(--accent-soft);
}
.site-result:hover { border-color: var(--accent); }
.site-result:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.site-result-top { display: flex; gap: 8px; align-items: center; }
.site-result-title { font-weight: 650; font-size: 15px; }
.site-result-title .ext { color: var(--accent); font-weight: 600; }
.site-result-snippet { font-size: 13.5px; color: var(--muted); }
.site-result-url { font-size: 12px; color: var(--muted); overflow-wrap: anywhere; }
.site-search-link { margin: 4px 0 0; font-size: 14px; }
.site-search-link a { font-weight: 600; text-decoration: none; }
.site-search-link a:hover { text-decoration: underline; }
