:root {
  color-scheme: light dark;   /* native date pickers follow the theme */
  --ink: #1a1a1a;
  --ink-soft: #6b6b6b;
  --line: #d8d4cc;
  --line-soft: #ece8e0;
  --paper: #fbfaf7;
  --card: #ffffff;
  --accent: #b23a2f;
  --done: #f2efe8;
  --hol: #f6ead3;
  --hol-line: #cbab72;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --ink: #ece9e3;
    --ink-soft: #9a958c;
    --line: #3a3833;
    --line-soft: #2b2a26;
    --paper: #171614;
    --card: #201f1c;
    --accent: #e07a5f;
    --done: #2a2926;
    --hol: #33291a;
    --hol-line: #8a7040;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  padding: 2.5rem 1.5rem 4rem;
  background: var(--paper);
  color: var(--ink);
  font: 400 16px/1.5 ui-sans-serif, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-feature-settings: "tnum" 1;
}

.sheet { max-width: 62rem; margin: 0 auto; }

h1 {
  font-size: 1.5rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  margin: 0 0 0.15rem;
}

.subtitle {
  margin: 0;
  color: var(--ink-soft);
  font-size: 0.9rem;
}

/* ---------- setup page ---------- */
.setup {
  max-width: 30rem;
  margin: 3rem auto 0;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 2rem 2rem 1.75rem;
}

.setup h1 { font-size: 1.35rem; }
.setup .subtitle { margin-bottom: 1.75rem; }

.field { margin-bottom: 1.35rem; }

.field > label,
.field > .label,
.dates > div > label {
  display: block;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--ink-soft);
  margin-bottom: 0.4rem;
}

.field input[type="date"] {
  font: inherit;
  width: 100%;
  padding: 0.5rem 0.65rem;
  color: var(--ink);
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 7px;
}

.field input[type="date"]:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.dates { display: grid; grid-template-columns: 1fr 1fr; gap: 0.75rem; }

/* one row, seven equal columns filling the card */
.chips { display: grid; grid-template-columns: repeat(7, 1fr); gap: 0.35rem; }

.chip { position: relative; }
.chip input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }

.chip span {
  display: block;
  width: 100%;
  text-align: center;
  padding: 0.4rem 0.2rem;
  font-size: 0.85rem;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--paper);
  color: var(--ink-soft);
  cursor: pointer;
}

.chip input:checked + span {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 600;
}

.chip input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }

/* seven across still has to fit a narrow phone */
@media (max-width: 27rem) {
  .chip span { font-size: 0.72rem; padding: 0.4rem 0.1rem; }
  .chips { gap: 0.25rem; }
}

.preview {
  font-size: 0.82rem;
  color: var(--ink-soft);
  margin: 0 0 1.25rem;
  min-height: 1.25rem;
}

.preview strong { color: var(--ink); font-weight: 600; }

.error {
  font-size: 0.82rem;
  color: var(--accent);
  margin: 0 0 1rem;
}

button.primary {
  font: inherit;
  font-weight: 600;
  width: 100%;
  padding: 0.6rem 1rem;
  color: #fff;
  background: var(--accent);
  border: 1px solid var(--accent);
  border-radius: 8px;
  cursor: pointer;
}

button.primary:hover { filter: brightness(1.08); }

.cancel {
  display: block;
  text-align: center;
  margin-top: 0.9rem;
  font-size: 0.82rem;
  color: var(--ink-soft);
}

/* ---------- calendar header ---------- */
header { margin-bottom: 2rem; }

.stats {
  display: flex;
  gap: 2rem;
  align-items: baseline;
  margin: 1.4rem 0 0.7rem;
  flex-wrap: wrap;
}

.stat-num {
  font-size: 2rem;
  font-weight: 600;
  letter-spacing: -0.02em;
  line-height: 1;
}

.stat-label {
  color: var(--ink-soft);
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-left: 0.45rem;
}

.bar {
  height: 6px;
  background: var(--line-soft);
  border: 1px solid var(--line);
  border-radius: 99px;
  overflow: hidden;
}

.bar > i {
  display: block;
  height: 100%;
  width: 0;
  background: var(--accent);
  transition: width 0.25s ease;
}

/* ---------- settings menu ---------- */
.header-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
}

/* a <details> so the menu opens without JavaScript; JS only adds
   click-outside and Escape */
.menu {
  position: relative;
  flex: none;
}

.cog {
  display: grid;
  place-items: center;
  width: 2.4rem;
  height: 2.4rem;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--card);
  color: var(--ink-soft);
  cursor: pointer;
  list-style: none;          /* kill the disclosure triangle */
}

.cog::-webkit-details-marker { display: none; }
.cog:hover { color: var(--ink); border-color: var(--ink-soft); }
.cog:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.cog svg { width: 1.15rem; height: 1.15rem; }
.cog svg .teeth { fill: currentColor; }
.cog svg .ring { fill: none; stroke: currentColor; stroke-width: 3.1; }

.menu[open] .cog { color: var(--ink); border-color: var(--ink-soft); }
.menu[open] .cog svg { transform: rotate(30deg); transition: transform 0.15s ease; }

/* holiday mode changes what a click does, so the closed menu has to show it.
   Specific enough to outrank the [open] rule above. */
body.marking .menu .cog { color: var(--hol-line); border-color: var(--hol-line); }

.menu-items {
  position: absolute;
  right: 0;
  top: calc(100% + 0.5rem);
  z-index: 20;
  min-width: 17rem;
  padding: 0.3rem;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: 0 10px 30px rgb(0 0 0 / 0.18);
}

.menu-items form { display: contents; }

.menu-items hr {
  height: 0;
  margin: 0.3rem 0.1rem;
  border: 0;
  border-top: 1px solid var(--line-soft);
}

.item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  width: 100%;
  padding: 0.45rem 0.55rem;
  font: inherit;
  font-size: 0.85rem;
  text-align: left;
  text-decoration: none;
  color: var(--ink);
  background: none;
  border: 0;
  border-radius: 6px;
  cursor: pointer;
}

.item:hover { background: var(--line-soft); }
.item:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.item.danger:hover { color: var(--accent); }

/* a fixed gutter so labels line up whether or not they are ticked */
.item-mark {
  flex: none;
  width: 1rem;
  color: var(--hol-line);
}

.item[aria-pressed="true"] { font-weight: 600; }
.item[aria-pressed="true"] .item-mark::before { content: "✓"; }

.ctl {
  font: inherit;
  font-size: 0.82rem;
  padding: 0.35rem 0.75rem;
  color: var(--ink);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 99px;
  cursor: pointer;
  text-decoration: none;
  line-height: 1.5;
}

.ctl:hover { border-color: var(--ink-soft); }

/* ---------- calendar ---------- */
.months {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(17rem, 1fr));
  gap: 1.5rem;
}

.month {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.9rem 1rem 1.1rem;
  break-inside: avoid;
}

.month h2 {
  font-size: 0.85rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  margin: 0 0 0.7rem;
  display: flex;
  justify-content: space-between;
  align-items: baseline;
}

.month h2 .year {
  font-weight: 400;
  color: var(--ink-soft);
  letter-spacing: 0.06em;
}

.grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 3px;
}

.dow {
  text-align: center;
  font-size: 0.62rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-soft);
  padding-bottom: 0.25rem;
}

.pad { aspect-ratio: 1; }

.day {
  position: relative;
  aspect-ratio: 1;
  display: flex;
  align-items: flex-start;
  justify-content: flex-start;
  padding: 0.2rem 0.3rem;
  font: inherit;
  font-size: 0.72rem;
  color: var(--ink);
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 5px;
  cursor: pointer;
  -webkit-user-select: none;
  user-select: none;
}

.day:hover { border-color: var(--ink-soft); }

.day.out {
  color: var(--line);
  border-color: var(--line-soft);
  border-style: dotted;
  cursor: default;
  pointer-events: none;
}

.day.off:not(.out) { background: var(--line-soft); }
.day.off:not(.out) > span { color: var(--ink-soft); }

.day.today {
  border-color: var(--accent);
  border-width: 2px;
  font-weight: 700;
  color: var(--accent);
}

/* the tick mark — drawn, not typed, so it centres on geometry not font metrics */
.day .tick {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 58%;
  height: 58%;
  transform: translate(-50%, -50%);
  fill: none;
  stroke: var(--accent);
  stroke-width: 1.7;
  stroke-linecap: round;
  opacity: 0;
}

.day[aria-pressed="true"] { background: var(--done); }
.day[aria-pressed="true"] > span { opacity: 0.35; text-decoration: line-through; }
.day[aria-pressed="true"] .tick { opacity: 1; }

.day.last {
  border-color: var(--ink);
  border-width: 2px;
  font-weight: 700;
}

/* holidays */
.day.holiday {
  background: var(--hol);
  border-color: var(--hol-line);
  border-style: dashed;
}

.day .hol {
  position: absolute;
  right: 2px;
  bottom: 0;
  font-size: 0.52rem;
  font-weight: 700;
  line-height: 1.4;
  color: var(--hol-line);
  display: none;
}

.day.holiday .hol { display: block; }
.day.holiday[aria-pressed="true"] { background: var(--done); }

body.marking .day[data-date] { cursor: crosshair; }
body.marking .day[data-date]:hover { border-color: var(--hol-line); border-style: dashed; }

/* legend */
.legend {
  display: flex;
  gap: 1.25rem;
  flex-wrap: wrap;
  list-style: none;
  margin: 1.5rem 0 0;
  padding: 0;
  font-size: 0.75rem;
  color: var(--ink-soft);
}

.legend li { display: flex; align-items: center; gap: 0.4rem; }

.legend .k {
  display: grid;
  place-items: center;
  width: 1.15rem;
  height: 1.15rem;
  border: 1px solid var(--line);
  border-radius: 4px;
  font-size: 0.62rem;
  line-height: 1;           /* otherwise the glyph rides low in the box */
  color: var(--ink);
}

.legend .k.tick { color: var(--accent); }

/* drawn, not typed — a glyph never centres reliably in a box this small */
.legend .k svg {
  display: block;
  width: 78%;
  height: 78%;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
}

.legend .k.hol { background: var(--hol); border-color: var(--hol-line); border-style: dashed; color: var(--hol-line); font-weight: 700; }
.legend .k.off { background: var(--line-soft); }
.legend .k.now { border-color: var(--accent); border-width: 2px; }

footer {
  margin-top: 2rem;
  color: var(--ink-soft);
  font-size: 0.78rem;
}

/* ---------- print ---------- */
@media print {
  :root {
    --ink: #000;
    --ink-soft: #555;
    --line: #999;
    --line-soft: #e5e5e5;
    --paper: #fff;
    --card: #fff;
    --accent: #000;
    --done: #f0f0f0;
    --hol: #fff;
    --hol-line: #000;
  }

  @page {
    size: A4 portrait;
    margin: 14mm 12mm;
  }

  body {
    padding: 0 0.7mm 0 0;  /* keeps the last column's border inside the printable area */
    background: #fff;
    color: #000;
    font-size: 10.5pt;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  .sheet { max-width: none; }

  header { margin-bottom: 8mm; }
  h1 { font-size: 15pt; }
  .subtitle { font-size: 9pt; }
  /* live tallies go stale the moment the page leaves the printer */
  .setup, .stats, .bar, .menu, footer, .volatile, .no-print { display: none !important; }

  .months {
    grid-template-columns: repeat(2, 1fr);
    gap: 5mm 8mm;
  }

  .month {
    border-radius: 0;
    border: 1px solid #999;
    padding: 3mm 3.5mm 4mm;
    page-break-inside: avoid;
    break-inside: avoid;
  }

  .month h2 { font-size: 9.5pt; margin-bottom: 2.5mm; }
  .dow { font-size: 7pt; padding-bottom: 1mm; }

  /* wider than tall, so three rows of months still fit one page */
  .day, .pad { aspect-ratio: auto; height: 8mm; }

  .day { font-size: 8.5pt; border-radius: 2px; }
  .day .tick { width: 4.8mm; height: 4.8mm; stroke-width: 1.9; }
  .day .hol { font-size: 6.5pt; }
  .day.today { border-width: 1.5px; }
  .day.holiday { border-style: dashed; }

  .legend { margin-top: 4mm; font-size: 7.5pt; gap: 6mm; page-break-inside: avoid; }
  .legend .k { width: 4mm; height: 4mm; font-size: 6pt; border-radius: 1px; }
}
