:root {
  color-scheme: light dark;
  --bg: #f4f6f9;
  --surface: #ffffff;
  --text: #17202b;
  --muted: #5b6776;
  --faint: #a3adba;
  --line: #e1e6ed;
  --brand: #1f4e8c;
  --brand-ink: #ffffff;
  --accent: #f2c94c;

  --holiday-bg: #cfe8c6;
  --holiday-ink: #1f5214;
  --public-bg: #f7cfcb;
  --public-ink: #a3160c;
  --ped-bg: #e3dcf5;
  --ped-ink: #4b2c93;
  --mile-bg: #ffd79a;
  --mile-ink: #7a4300;
  --weekend-ink: #7a8594;
  --today: #1f4e8c;
  --today-ink: #ffffff;

  --radius: 14px;
  /* Height taken by everything except the six calendar rows; the rows share what is left. */
  --chrome-h: 430px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1720;
    --surface: #18222e;
    --text: #e7edf4;
    --muted: #9aa7b6;
    --faint: #56626f;
    --line: #283544;
    --brand: #5b8fd6;
    --brand-ink: #0f1720;

    --holiday-bg: #24461d;
    --holiday-ink: #bfe8b0;
    --public-bg: #5a1f1b;
    --public-ink: #ffb4ab;
    --ped-bg: #3a2d63;
    --ped-ink: #d7c9ff;
    --mile-bg: #6b4712;
    --mile-ink: #ffd99c;
    --weekend-ink: #7f8c9b;
    --today: #8fb8ff;
    --today-ink: #0f1720;
  }
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  line-height: 1.45;
}

a { color: var(--brand); }

button { font: inherit; color: inherit; }

/* ---- app shell: header + one month, as tall as the month needs; the footer follows right after ---- */

.app {
  display: flex;
  flex-direction: column;
  overflow-x: clip; /* the month card slides sideways during a swipe */
}

.top {
  flex: none;
  background: var(--brand);
  color: var(--brand-ink);
  padding-top: env(safe-area-inset-top, 0px);
  box-shadow: 0 1px 8px rgb(0 0 0 / 0.15);
}
@media (prefers-color-scheme: dark) { .top { background: #111b27; color: var(--text); } }

.top-inner {
  max-width: 600px;
  margin-inline: auto;
  height: 56px;
  padding-inline: max(16px, env(safe-area-inset-left, 0px)) max(16px, env(safe-area-inset-right, 0px));
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.brand { display: flex; align-items: center; gap: 10px; color: inherit; text-decoration: none; min-height: 44px; min-width: 0; }
.brand span { display: flex; flex-direction: column; line-height: 1.15; min-width: 0; }
.brand small { opacity: 0.8; font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.today-btn {
  flex: none;
  font-size: 14px;
  font-weight: 600;
  min-height: 40px;
  padding: 6px 14px;
  border-radius: 999px;
  border: 1px solid rgb(255 255 255 / 0.4);
  background: transparent;
  cursor: pointer;
}

.month-nav {
  max-width: 600px;
  margin-inline: auto;
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding: 0 16px 10px;
  scrollbar-width: none;
}
.month-nav::-webkit-scrollbar { display: none; }
.month-nav button {
  flex: none;
  font-size: 14px;
  font-weight: 600;
  padding: 8px 12px;
  border: 0;
  border-radius: 999px;
  background: rgb(255 255 255 / 0.12);
  min-width: 48px;
  cursor: pointer;
}
.month-nav button.active { background: var(--accent); color: #1a1a1a; }

.view {
  width: 100%;
  max-width: 600px;
  margin-inline: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 12px max(16px, env(safe-area-inset-right, 0px)) 10px max(16px, env(safe-area-inset-left, 0px));
}

.loading { color: var(--muted); margin: 0; }

/* ---- month card ---- */

.month {
  flex: none;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-radius: var(--radius);
  padding: 12px 12px 8px;
  box-shadow: 0 1px 2px rgb(0 0 0 / 0.06);
  touch-action: pan-y pinch-zoom; /* horizontal drags are month swipes, handled in app.js */
}

.month-head {
  flex: none;
  display: grid;
  grid-template-columns: 44px 1fr 44px;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}
.month-title { text-align: center; }
.month-title h1 { font-size: 20px; margin: 0; line-height: 1.2; }
.month-title .days { font-size: 13px; color: var(--muted); }

.nav-btn {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--bg);
  display: grid;
  place-items: center;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.nav-btn svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2.5; stroke-linecap: round; stroke-linejoin: round; }
.nav-btn:disabled { opacity: 0.3; cursor: default; }
.nav-btn:not(:disabled):active { background: var(--line); }
.nav-btn:focus-visible, .month-nav button:focus-visible, .today-btn:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

.grid { flex: none; display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 3px; }
.dow { text-align: center; font-size: 12px; font-weight: 600; color: var(--muted); padding-bottom: 2px; }
.dow.we { color: var(--weekend-ink); }

.d {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  height: clamp(34px, calc((100dvh - var(--chrome-h)) / 6), 58px);
  border: 0;
  border-radius: 9px;
  background: transparent;
  padding: 0;
  font-size: 15px;
  font-variant-numeric: tabular-nums;
  color: var(--text);
}
button.d { cursor: pointer; -webkit-tap-highlight-color: transparent; }
button.d:focus-visible { outline: 3px solid var(--today); outline-offset: 1px; }
.d.we { color: var(--weekend-ink); }
.d.out { opacity: 0.35; }

.d.is-holiday { background: var(--holiday-bg); color: var(--holiday-ink); font-weight: 600; }
.d.is-public { color: var(--public-ink); font-weight: 700; }
.d.is-public:not(.is-holiday) { background: var(--public-bg); }
.d.is-holiday.is-public::after {
  content: "";
  position: absolute;
  top: 5px;
  right: 5px;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--public-ink);
}
.d.is-pedagogical, .d.is-preparation { background: var(--ped-bg); color: var(--ped-ink); font-weight: 600; }
.d.is-milestone { background: var(--mile-bg); color: var(--mile-ink); font-weight: 700; }
.d .n { display: grid; place-items: center; width: 2em; height: 2em; border-radius: 50%; }
/* Today: the number sits in a solid circle, so the cell's own colour (holiday, public holiday…) still shows around it. */
.d.today .n { background: var(--today); color: var(--today-ink); font-weight: 800; box-shadow: 0 1px 3px rgb(0 0 0 / 0.25); }

/* ---- event list: as tall as its entries, so the card ends right after the last one ---- */

.events {
  list-style: none;
  margin: 10px 0 0;
  padding: 8px 0 0;
  border-top: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.events li {
  display: grid;
  grid-template-columns: 14px 7.5em 1fr;
  gap: 10px;
  align-items: start;
  font-size: 14px;
  padding: 5px 6px;
  border-radius: 8px;
}
.events li.none { display: block; color: var(--muted); }
.events .swatch { margin-top: 3px; }
.events .when { color: var(--muted); font-variant-numeric: tabular-nums; }
.events .what small { color: var(--muted); display: block; }
.events li.flash { animation: flash 1.6s ease-out; }
@keyframes flash { from { background: color-mix(in srgb, var(--accent) 55%, transparent); } to { background: transparent; } }

/* ---- legend ---- */

.legend { flex: none; list-style: none; padding: 0; margin: 0; display: flex; flex-wrap: wrap; justify-content: center; gap: 4px 14px; font-size: 12px; color: var(--muted); }
.legend li { display: flex; align-items: center; gap: 5px; }
.legend[hidden], .legend li[hidden] { display: none; }

.swatch { width: 14px; height: 14px; border-radius: 4px; flex: none; display: inline-block; }
.legend .swatch { width: 12px; height: 12px; }
.t-holiday { background: var(--holiday-bg); box-shadow: inset 0 0 0 1px var(--holiday-ink); }
.t-public { background: var(--public-bg); box-shadow: inset 0 0 0 1px var(--public-ink); }
.t-pedagogical, .t-preparation { background: var(--ped-bg); box-shadow: inset 0 0 0 1px var(--ped-ink); }
.t-milestone { background: var(--mile-bg); box-shadow: inset 0 0 0 1px var(--mile-ink); }
.t-today { background: var(--today); border-radius: 50%; }

/* ---- footer (below the fold) ---- */

.foot {
  max-width: 600px;
  margin-inline: auto;
  color: var(--muted);
  font-size: 13px;
  padding: 20px 16px calc(24px + env(safe-area-inset-bottom, 0px));
}
.foot p { margin: 0 0 6px; }

@media (max-width: 380px) {
  .events li { grid-template-columns: 14px 6.8em 1fr; gap: 8px; }
  .d { font-size: 14px; }
}
