/* Warm light (default) */
:root {
  color-scheme: light;
  --bg: #f4efe6;
  --card: #fbf8f2;
  --ink: #2b2620;
  --muted: #7a7064;
  --line: #e5ddd0;
  --red: #b3362f;
  --blue: #2f4a7a;
  --mark: #a07a2c;
  --hover: #efe8dc;
  --ferie: #e4e6d2;
  --today-bg: #2b2620;
  --today-ink: #fbf8f2;
  --past: .45;
}
/* Warm dark: system preference unless the user picked light */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #1a1815;
    --card: #23201c;
    --ink: #ece6dc;
    --muted: #a39a8d;
    --line: #35302a;
    --red: #e0675c;
    --blue: #8ea8d8;
    --mark: #d4b06a;
    --hover: #2d2924;
    --ferie: #2f3327;
    --today-bg: #ece6dc;
    --today-ink: #1a1815;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #1a1815;
  --card: #23201c;
  --ink: #ece6dc;
  --muted: #a39a8d;
  --line: #35302a;
  --red: #e0675c;
  --blue: #8ea8d8;
  --mark: #d4b06a;
  --hover: #2d2924;
  --ferie: #2f3327;
  --today-bg: #ece6dc;
  --today-ink: #1a1815;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-variant-numeric: tabular-nums;
}
.wrap { max-width: 1240px; margin: 0 auto; padding: 0 16px; }
button, select { font: inherit; color: inherit; }

/* Header */
.top { padding: 28px 0 8px; }
.top-inner { display: flex; gap: 16px; align-items: center; justify-content: space-between; }
h1 { margin: 0; font-size: clamp(28px, 5vw, 40px); letter-spacing: -.02em; line-height: 1.1; }
.today, .sun { margin: 6px 0 0; color: var(--muted); }
.sun { margin-top: 2px; }
.today strong, .sun strong { color: var(--ink); }
.week-badge {
  flex: none; display: grid; place-items: center; min-width: 96px; padding: 8px 14px 10px;
  border: 1px solid var(--line); border-radius: 14px; background: var(--card); line-height: 1;
}
.week-badge span { font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
.week-badge strong { font-size: 44px; letter-spacing: -.03em; margin-top: 4px; }

.bar { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; justify-content: space-between; margin-top: 18px; }
.year-nav, .controls { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.btn {
  display: inline-block; padding: 8px 14px; border-radius: 8px;
  border: 1px solid var(--line); background: var(--card); color: var(--ink);
  text-decoration: none; font-weight: 600;
}
.btn:hover { border-color: var(--muted); }
.btn-ghost { background: transparent; }
.btn[hidden] { display: none; }
:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; }

.city { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 14px; }
.city select {
  padding: 7px 10px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--card); color: var(--ink);
}
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; padding: 2px; background: var(--card); }
.seg button { border: 0; background: transparent; padding: 6px 12px; border-radius: 6px; cursor: pointer; color: var(--muted); font-size: 14px; }
.seg button[aria-pressed="true"] { background: var(--hover); color: var(--ink); font-weight: 600; }

.next-holiday, .stats { margin: 14px 0 0; }
.stats { margin-top: 2px; color: var(--muted); }
.next-holiday:empty, .stats:empty, .sun:empty { display: none; }
.legend { list-style: none; display: flex; flex-wrap: wrap; gap: 6px 18px; padding: 0; margin: 14px 0 0; color: var(--muted); font-size: 13px; }
.legend li { display: flex; align-items: center; gap: 6px; }
.legend .hint { font-style: italic; }
.sw { display: inline-grid; place-items: center; width: 22px; height: 22px; border-radius: 50%; font-size: 12px; position: relative; color: var(--ink); }
.sw-holiday { color: var(--red); font-weight: 700; }
.sw-today { background: var(--today-bg); color: var(--today-ink); font-weight: 700; }

/* Month grid */
.months { display: grid; gap: 16px; margin-top: 20px; grid-template-columns: repeat(auto-fill, minmax(268px, 1fr)); }
.month { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 14px 14px 12px; }
.month.current { border-color: var(--muted); }
.mh { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; margin-bottom: 8px; }
.mh h2 { margin: 0; font-size: 16px; text-transform: capitalize; }
.mh .wd { font-size: 12px; color: var(--muted); }
.month table { width: 100%; border-collapse: collapse; table-layout: fixed; }
.month th { font-size: 11px; font-weight: 600; color: var(--muted); padding: 2px 0 6px; text-align: center; }
.month th.sun { color: var(--red); }
.month td { text-align: center; padding: 1px 0; height: 30px; }
.month td.wk, .month th.wk { font-size: 11px; color: var(--muted); border-right: 1px solid var(--line); width: 13%; }
.month tr.this-week td.wk { color: var(--ink); font-weight: 700; }

.d {
  display: inline-grid; place-items: center; width: 28px; height: 28px; border-radius: 50%;
  position: relative; border: 0; padding: 0; background: transparent; cursor: pointer;
}
.d:hover { background: var(--hover); }
.d.sun, .d.holiday { color: var(--red); }
.d.holiday { font-weight: 700; }
.d.past { opacity: var(--past); }
.d.today { background: var(--today-bg); color: var(--today-ink); font-weight: 700; opacity: 1; }

/* Flag/mark dot under the number */
.flag::after, .mark::after {
  content: ""; position: absolute; bottom: 1px; left: 50%; transform: translateX(-50%);
  width: 5px; height: 5px; border-radius: 50%;
}
.flag::after { background: var(--blue); }
.mark::after { background: var(--mark); }
.d.today.flag::after, .d.today.mark::after { background: var(--today-ink); }

/* Moon phase marker, top right */
.moon::before {
  content: ""; position: absolute; top: 0; right: -1px; width: 8px; height: 8px;
  border-radius: 50%; border: 1px solid var(--muted); box-sizing: border-box;
}
.sw.moon::before { position: static; width: 11px; height: 11px; }
.moon-0::before { background: var(--muted); }
.moon-1::before { background: linear-gradient(90deg, var(--muted) 50%, transparent 50%); }
.moon-2::before { background: transparent; }
.moon-3::before { background: linear-gradient(90deg, transparent 50%, var(--muted) 50%); }

/* School holiday band */
.month td.ferie { background: var(--ferie); }
.sw-ferie { background: var(--ferie); border-radius: 5px; }
.list-sub { font-size: 13px; color: var(--muted); }
.src { margin: 10px 0 0; font-size: 12px; color: var(--muted); }
.src:empty { display: none; }
.src a { color: var(--blue); }

/* Mobile month carousel (hidden on wide screens) */
.month-nav, .view-seg { display: none; }

.notes { list-style: none; margin: 10px 0 0; padding: 8px 0 0; border-top: 1px solid var(--line); font-size: 12.5px; color: var(--muted); }
.notes:empty { display: none; }
.notes li { display: flex; gap: 6px; }
.notes b { min-width: 2.2em; font-weight: 600; color: var(--ink); }
.notes .holiday b, .notes .holiday { color: var(--red); }

/* Long weekends */
.long-weekends { margin-top: 36px; }
.long-weekends > h2 { margin: 0; font-size: 20px; }
.lead { margin: 4px 0 14px; color: var(--muted); }
.lw-grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }
.lw { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; }
.lw.past { opacity: .55; }
.lw h3 { margin: 0 0 6px; font-size: 16px; display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.lw h3 span { font-size: 13px; font-weight: 400; color: var(--muted); }
.lw ul { list-style: none; margin: 0; padding: 0; }
.lw li { padding: 7px 0; border-top: 1px solid var(--line); font-size: 14px; }
.lw li:first-child { border-top: 0; }
.lw .days { font-weight: 700; color: var(--red); }
.lw .vac { color: var(--muted); font-size: 13px; }

/* Lists */
.lists { display: grid; gap: 16px; margin: 32px 0 0; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }
.list { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 16px; }
.list-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; margin-bottom: 10px; }
.list h2 { margin: 0; font-size: 17px; }
.link-btn { border: 0; background: none; padding: 0; color: var(--blue); cursor: pointer; font-size: 13px; text-decoration: underline; text-underline-offset: 2px; }
.list ul { list-style: none; margin: 0; padding: 0; }
.list li { display: grid; grid-template-columns: 7.8em 1fr; gap: 8px; padding: 5px 0; border-top: 1px solid var(--line); font-size: 14px; }
.list li:first-child { border-top: 0; }
.list li .when { color: var(--muted); }
.list li.past { opacity: var(--past); }
.list li.is-today { font-weight: 700; }

.foot { color: var(--muted); font-size: 13px; padding-top: 24px; padding-bottom: 40px; }

/* Day dialog */
dialog {
  width: min(420px, calc(100% - 32px)); padding: 22px 22px 18px; border: 1px solid var(--line);
  border-radius: 14px; background: var(--card); color: var(--ink);
}
dialog::backdrop { background: rgba(20, 16, 12, .4); }
dialog .close {
  position: absolute; top: 10px; right: 10px; width: 32px; height: 32px; border-radius: 50%;
  border: 0; background: transparent; font-size: 22px; line-height: 1; cursor: pointer; color: var(--muted);
}
dialog .close:hover { background: var(--hover); color: var(--ink); }
.dd-kicker { margin: 0; color: var(--muted); font-size: 13px; }
dialog h2 { margin: 2px 0 4px; font-size: 22px; padding-right: 30px; }
.dd-rel { margin: 0 0 12px; }
.dd-events { list-style: none; margin: 0 0 12px; padding: 0; }
.dd-events li { padding: 4px 0; display: flex; gap: 8px; align-items: baseline; flex-wrap: wrap; }
.tag { font-size: 11px; padding: 1px 7px; border-radius: 999px; border: 1px solid currentColor; }
.tag-holiday { color: var(--red); }
.tag-flag { color: var(--blue); }
.tag-mark { color: var(--mark); }
.dd-facts { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; margin: 0; padding-top: 12px; border-top: 1px solid var(--line); font-size: 14px; }
.dd-facts dt { color: var(--muted); }
.dd-facts dd { margin: 0; }

@media (max-width: 520px) {
  .week-badge { min-width: 76px; padding: 6px 10px 8px; }
  .week-badge strong { font-size: 34px; }
}

@media screen and (max-width: 700px) {
  .view-seg { display: inline-flex; }
  body:not(.view-year) .month-nav {
    display: flex; align-items: center; justify-content: space-between; gap: 12px;
    position: sticky; top: 0; z-index: 2; margin-top: 12px; padding: 8px 0; background: var(--bg);
  }
  .month-nav strong { font-size: 18px; }
  .month-nav .btn { min-width: 44px; padding: 8px 0; text-align: center; font-size: 18px; line-height: 1.2; cursor: pointer; }
  body:not(.view-year) .months {
    position: relative; display: flex; gap: 12px; overflow-x: auto;
    scroll-snap-type: x mandatory; overscroll-behavior-x: contain; scrollbar-width: none;
    margin: 4px -16px 0; padding: 0 16px; scroll-padding: 0 16px;
  }
  body:not(.view-year) .months::-webkit-scrollbar { display: none; }
  body:not(.view-year) .month { flex: 0 0 100%; scroll-snap-align: start; scroll-snap-stop: always; }
  body:not(.view-year) .mh h2 { font-size: 18px; }
  body:not(.view-year) .month td { height: 46px; }
  body:not(.view-year) .month .d { width: 40px; height: 40px; font-size: 17px; }
  body:not(.view-year) .notes { font-size: 14px; }
}

/* Print: one A4 landscape page with the year */
@media print {
  @page { size: A4 landscape; margin: 10mm; }
  :root, :root[data-theme], :root:not([data-theme="light"]) {
    --bg: #fff; --card: #fff; --ink: #000; --muted: #555; --line: #ccc; --past: 1;
    --today-bg: transparent; --today-ink: #000; --red: #b3362f;
  }
  body { font-size: 10px; }
  .bar, .legend, .next-holiday, .stats, .today, .sun, .week-badge,
  .long-weekends, .lists, .foot, dialog { display: none; }
  .top { padding: 0 0 4mm; }
  h1 { font-size: 20px; }
  .wrap { max-width: none; padding: 0; }
  .months { grid-template-columns: repeat(4, 1fr); gap: 3mm; margin: 0; }
  .month { padding: 2mm; border-radius: 0; break-inside: avoid; }
  .mh { margin-bottom: 1mm; }
  .mh h2 { font-size: 11px; }
  .month td { height: auto; }
  .d { width: auto; height: auto; }
  .d::after, .d::before { display: none; }
  .notes { font-size: 8px; margin-top: 1mm; padding-top: 1mm; }
}
