/* ---------- theme tokens: light on :root; dark via system preference or data-theme ---------- */
:root {
  --bg: #f6f7f9; --card: #fff; --ink: #1f2430; --muted: #6b7280; --line: #e5e7eb;
  --accent: #1d4ed8; --closed: #b91c1c; --early: #b45309; --delayed: #0e7490;
  --radius: 12px; color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1218; --card: #171b24; --ink: #e6e8ee; --muted: #9aa3b2; --line: #2a3040;
    --accent: #3b6ff0; --closed: #ef5350; --early: #f59e0b; --delayed: #22b8cf; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f1218; --card: #171b24; --ink: #e6e8ee; --muted: #9aa3b2; --line: #2a3040;
  --accent: #3b6ff0; --closed: #ef5350; --early: #f59e0b; --delayed: #22b8cf; color-scheme: dark;
}

* { box-sizing: border-box; }
body { margin: 0; font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--ink); padding: 0 16px calc(24px + env(safe-area-inset-bottom, 0px)); min-height: 100vh; min-height: 100dvh; display: flex; flex-direction: column; }
.top, main, .panel, .foot { width: 100%; }
main { flex: 1; }
.foot { margin-top: auto; }
h1 { font-size: 1.35rem; margin: 0; }
button { font: inherit; }
.tagline { margin: 2px 0 0; color: var(--muted); font-size: .9rem; }

/* ---------- header ---------- */
.top { padding-top: calc(16px + env(safe-area-inset-top, 0px)); display: grid; gap: 12px; max-width: 1200px; margin: 0 auto; }
.brand-row { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.tools { display: flex; gap: 8px; flex: none; }
.tool { border: 1px solid var(--line); background: var(--card); color: var(--ink); border-radius: 10px; padding: 7px 12px; cursor: pointer; white-space: nowrap; }
.tool:hover { background: color-mix(in srgb, var(--accent) 12%, transparent); }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { --c: var(--accent); border: 2px solid var(--c); background: transparent; color: var(--c); border-radius: 999px; padding: 6px 12px; font-weight: 600; cursor: pointer; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; touch-action: manipulation; }
.chip[aria-pressed="true"] { background: var(--c); color: #fff; }
.chip small { font-weight: 400; opacity: .85; margin-left: 4px; }
.tip { margin: -6px 0 0; color: var(--muted); font-size: .8rem; }
.controls { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 16px; }
.seg, .nav { display: inline-flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; background: var(--card); }
.seg button, .nav button { border: 0; background: transparent; color: var(--ink); padding: 8px 14px; cursor: pointer; }
.seg button + button, .nav button + button { border-left: 1px solid var(--line); }
.seg button[aria-pressed="true"] { background: var(--accent); color: #fff; }
.nav button:hover, .seg button:hover { background: color-mix(in srgb, var(--accent) 12%, transparent); }

/* ---------- the date: the loudest thing on the page ---------- */
.daterow { display: flex; align-items: baseline; flex-wrap: wrap; gap: 4px 10px; padding-top: 2px; border-top: 1px solid var(--line); }
#range-label { margin: 0; font-size: 1.6rem; font-weight: 800; letter-spacing: -.02em; line-height: 1.2; }
.range-tag { background: color-mix(in srgb, var(--accent) 14%, transparent); color: var(--accent); border-radius: 999px; padding: 3px 10px; font-size: .72rem; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; }
.weather { font-weight: 500; color: var(--muted); font-size: .9rem; }

/* ---------- countdown ---------- */
.countdown { display: flex; flex-wrap: wrap; gap: 8px; }
.pill { background: var(--card); border: 1px solid var(--line); border-radius: 999px; padding: 6px 12px; font-size: .9rem; }
.pill b { font-weight: 700; }
.pill .n { color: var(--accent); font-weight: 700; }

/* ---------- main ---------- */
main { max-width: 1200px; margin: 16px auto 0; }
.hint, .empty { color: var(--muted); text-align: center; padding: 32px 8px; margin: 0; }
.banner { display: grid; gap: 6px; margin-bottom: 12px; }
.banner-item { padding: 10px 14px; border-radius: var(--radius); font-weight: 600; color: #fff; background: var(--accent); }
.kind-closed { background: var(--closed); } .kind-early { background: var(--early); } .kind-delayed { background: var(--delayed); }
.cards { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }
.card { --c: var(--accent); background: var(--card); border: 1px solid var(--line); border-top: 4px solid var(--c); border-radius: var(--radius); padding: 12px 14px; }
.card h2 { margin: 0; font-size: 1rem; display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.card h2 small { color: var(--muted); font-weight: 400; }
.day-badge { display: inline-block; margin: 8px 0 6px; padding: 6px 14px; border-radius: 10px; background: var(--c); color: #fff; font-size: 1.5rem; font-weight: 800; letter-spacing: .5px; }
.flag { display: inline-block; margin-left: 8px; padding: 3px 9px; border-radius: 8px; color: #fff; font-size: .8rem; font-weight: 700; vertical-align: middle; white-space: nowrap; }
.row .who .flag { margin-left: 2px; padding: 1px 7px; font-size: .75rem; }
.day-badge.none { background: transparent; color: var(--muted); border: 1px dashed var(--line); font-size: .95rem; font-weight: 500; }
.events { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.ev { display: grid; grid-template-columns: auto 1fr; gap: 8px; align-items: baseline; background: none; }
.ev time { color: var(--muted); font-variant-numeric: tabular-nums; font-size: .9rem; white-space: nowrap; }
.ev .venue { color: var(--muted); font-size: .85rem; }
.ev.kind-closed .title { color: var(--closed); font-weight: 600; }
.ev.kind-early .title { color: var(--early); font-weight: 600; }
.ev.kind-delayed .title { color: var(--delayed); font-weight: 600; }
.card .empty { padding: 8px 0; text-align: left; }
.district { margin-top: 12px; color: var(--muted); font-size: .9rem; }
.district ul { margin: 4px 0 0; padding-left: 18px; }

/* ---------- no-school celebration ---------- */
.party { text-align: center; padding: 36px 16px; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 12px; }
.party-title { font-size: 2rem; font-weight: 800; }
.party-why { color: var(--closed); font-weight: 600; margin-top: 6px; }
.party-line { color: var(--muted); margin-top: 10px; font-style: italic; }

/* ---------- week ---------- */
.week { display: grid; gap: 10px; grid-template-columns: repeat(5, minmax(0, 1fr)); }
.col { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px; min-width: 0; }
.col.today { outline: 2px solid var(--accent); }
.col h3 { margin: 0 0 8px; font-size: .95rem; display: flex; justify-content: space-between; gap: 6px; flex-wrap: wrap; }
.col h3 .dow { color: var(--muted); font-weight: 500; }
.col h3 .wx { color: var(--muted); font-weight: 500; font-size: .85rem; flex-basis: 100%; }
.col .banner-item { padding: 6px 10px; font-size: .85rem; font-weight: 600; margin-bottom: 6px; }
.row { --c: var(--accent); border-left: 3px solid var(--c); padding: 4px 0 4px 8px; margin: 6px 0; min-width: 0; }
.row .who { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 6px; font-size: .8rem; color: var(--muted); }
.row .who b { color: var(--c); }
.row .mini { display: inline-block; background: var(--c); color: #fff; border-radius: 6px; padding: 1px 7px; font-weight: 700; font-size: .85rem; white-space: nowrap; }
.t { font-size: .9rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.t time { color: var(--muted); font-size: .8rem; margin-right: 4px; }
.col .t.district { margin-top: 6px; color: var(--muted); font-size: .85rem; }

/* ---------- panels: news + subscribe ---------- */
.panel { max-width: 1200px; margin: 14px auto 0; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 0 14px; }
.panel summary { cursor: pointer; padding: 12px 0; font-weight: 600; }
.panel > div { padding: 0 0 12px; }
.news-list, .sub-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.news-item { --c: var(--accent); border-left: 3px solid var(--c); padding-left: 10px; }
.news-item .who { font-size: .85rem; color: var(--muted); }
.news-item .who b { color: var(--c); }
.news-item p { margin: 2px 0 0; white-space: pre-line; }
.news-item .more, .news-item .full { display: none; }
.news-item.open .short, .news-item.open .more { display: none; }
.news-item.open .full { display: inline; }
.news-item .more { display: inline; }
.linky { border: 0; background: none; color: var(--accent); cursor: pointer; padding: 0; text-decoration: underline; }
.news-item a { color: var(--accent); font-size: .9rem; margin-right: 10px; }
.sub-list li { display: flex; flex-wrap: wrap; gap: 6px 12px; align-items: baseline; }
.sub-list a { color: var(--accent); }
.sub-note { color: var(--muted); font-size: .85rem; margin: 0 0 10px; }

/* ---------- footer, toast ---------- */
.foot { max-width: 1200px; margin: 20px auto 0; padding-top: 12px; border-top: 1px solid var(--line); display: flex; flex-wrap: wrap; gap: 6px 16px; color: var(--muted); font-size: .85rem; }
.foot .made { margin-left: auto; }
.foot a { color: inherit; }
.foot .coffee { color: var(--accent); font-weight: 600; text-decoration: none; }
.foot .coffee:hover { text-decoration: underline; }
.retry { border: 1px solid var(--line); background: transparent; color: var(--ink); border-radius: 8px; padding: 4px 10px; cursor: pointer; }
.toast { position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom, 0px)); transform: translateX(-50%) translateY(20px); background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 10px; opacity: 0; transition: .25s; pointer-events: none; }
.toast.show { opacity: 1; transform: translateX(-50%); }
.toast.sticky { pointer-events: auto; display: flex; align-items: center; gap: 12px; white-space: nowrap; max-width: calc(100vw - 32px); }
.toast-btn { border: 0; background: var(--bg); color: var(--ink); font: inherit; font-weight: 600; border-radius: 8px; padding: 4px 12px; cursor: pointer; }

@media (max-width: 899px) { .week { grid-template-columns: 1fr; } .col.past { opacity: .75; } }
@media (max-width: 520px) {
  .brand-row { flex-direction: column; }
  .tools { align-self: flex-end; }
  #range-label { font-size: 1.45rem; }
  .weather { flex-basis: 100%; }
}

/* ---------- print ---------- */
@media print {
  @page { size: landscape; margin: 12mm; }
  body { background: #fff; color: #000; padding: 0; }
  .tools, .chips, .tip, .controls .seg, .controls .nav, .countdown, .panel, .foot, .toast, .retry { display: none !important; }
  .top { padding-top: 0; }
  .daterow { border-top: 0; padding-top: 0; }
  .week { grid-template-columns: repeat(5, minmax(0, 1fr)) !important; }
  .col, .card { break-inside: avoid; border-color: #bbb; }
  .col.past { opacity: 1; }
  * { print-color-adjust: exact; -webkit-print-color-adjust: exact; }
}
