:root {
  --bg: #f6f1e7;
  --paper: #fffaf2;
  --ink: #231a17;
  --muted: #5d504a;
  --line: #ddd0bf;
  --red: #b2231b;
  --red-ink: #fff8ee;
  --gold: #e9b949;
  --gold-soft: #f6e3b0;
  --focus: #1f5fbf;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --num: "Bahnschrift", "DIN Alternate", "Avenir Next Condensed", "Arial Narrow", system-ui, sans-serif;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17110f;
    --paper: #221a17;
    --ink: #f3ebe4;
    --muted: #c9bbb1;
    --line: #463833;
    --red: #ff8a73;
    --red-ink: #2a0d09;
    --gold: #e9b949;
    --gold-soft: #4a3a14;
    --focus: #8ab4ff;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 17px/1.55 var(--sans); }
.wrap { max-width: 760px; margin: 0 auto; padding: 0 16px; }
a { color: var(--red); text-underline-offset: 2px; }
.vh { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip { position: absolute; left: -9999px; top: 0; background: var(--paper); color: var(--ink); padding: 10px 14px; z-index: 10; }
.skip:focus { left: 8px; top: 8px; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
[hidden] { display: none !important; }

/* header */
.top { padding: 20px 0 6px; }
.brand { display: flex; align-items: center; gap: 8px; margin: 0 0 10px; font-weight: 600; font-size: 16px; color: var(--muted); }
.brand svg { color: var(--ink); flex: none; }
h1 { font-family: var(--serif); font-size: clamp(28px, 6vw, 40px); line-height: 1.12; margin: 0 0 10px; letter-spacing: -0.01em; }
.lede { margin: 0; max-width: 60ch; font-size: 18px; }
h2 { font-family: var(--serif); font-size: 26px; line-height: 1.2; margin: 0 0 12px; }
h3 { font-size: 18px; margin: 22px 0 6px; }

/* picker */
.tool { padding-top: 14px; }
.pick { display: flex; gap: 10px; align-items: stretch; }
.seg { display: flex; border: 0; margin: 0; padding: 0; flex: 1 1 0; min-width: 0; }
.seg label { flex: 1; position: relative; min-width: 0; }
.seg input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.seg span { display: flex; align-items: center; justify-content: center; min-height: 48px; padding: 0 4px; border: 2px solid var(--ink); margin-left: -2px; font-weight: 600; background: var(--paper); white-space: nowrap; }
.seg label:first-of-type span { border-radius: 6px 0 0 6px; margin-left: 0; }
.seg label:last-of-type span { border-radius: 0 6px 6px 0; }
.seg input:checked + span { background: var(--red); border-color: var(--red); color: var(--red-ink); position: relative; z-index: 1; }
.seg input:focus-visible + span { outline: 3px solid var(--focus); outline-offset: 2px; z-index: 2; }
.yearpick select { min-height: 48px; }
select, input[type="text"] { font: inherit; font-size: 16px; color: var(--ink); background: var(--paper); border: 2px solid var(--line); border-radius: 6px; padding: 8px 10px; max-width: 100%; }
select { padding-right: 28px; }
.headline { font-size: 19px; margin: 16px 0 12px; }
.headline strong { font-weight: 700; }
.away { color: var(--red); font-weight: 600; }

/* choose tasks */
.choose { border-top: 2px solid var(--ink); border-bottom: 1px solid var(--line); margin: 0 0 18px; }
.choose > summary { cursor: pointer; padding: 12px 0; min-height: 48px; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; list-style: none; }
.choose > summary::-webkit-details-marker { display: none; }
.choose > summary::before { content: "+"; display: inline-grid; place-items: center; width: 26px; height: 26px; border: 2px solid var(--ink); border-radius: 50%; font-weight: 700; line-height: 1; }
.choose[open] > summary::before { content: "−"; }
.sum-main { font-weight: 700; font-size: 18px; }
.sum-count { color: var(--muted); }
.hint { color: var(--muted); margin: 0 0 10px; }
.tasks { list-style: none; margin: 0; padding: 0; }
.trow { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 6px 12px; align-items: center; padding: 8px 0; border-top: 1px solid var(--line); }
.trow.off .incl span { color: var(--muted); text-decoration: line-through; text-decoration-thickness: 1px; }
.incl { display: flex; gap: 10px; align-items: flex-start; cursor: pointer; min-height: 44px; padding-top: 10px; }
.incl input, .tick input { width: 22px; height: 22px; margin: 1px 0 0; flex: none; accent-color: var(--red); }
.trow-ctl { display: flex; gap: 8px; align-items: center; }
.trow-ctl select { width: 15.5em; min-height: 44px; }
.addform { border-top: 1px solid var(--line); padding: 4px 0 16px; }
.addh { margin-top: 14px; }
.addrow { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; }
.addrow label { display: flex; flex-direction: column; gap: 4px; font-weight: 600; font-size: 16px; }
.addrow .grow { flex: 1 1 220px; }
.addrow input, .addrow select { min-height: 44px; width: 100%; }
.addrow select { width: 15.5em; }
.formerr { color: var(--red); font-weight: 600; margin: 8px 0 0; }

/* buttons */
a.btn { display: inline-flex; align-items: center; text-decoration: none; }
.btn { font: inherit; font-weight: 600; font-size: 16px; min-height: 44px; padding: 8px 16px; border-radius: 6px; border: 2px solid var(--ink); background: var(--paper); color: var(--ink); cursor: pointer; }
.btn:hover { background: var(--gold-soft); }
.btn.primary { background: var(--red); border-color: var(--red); color: var(--red-ink); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.small { min-height: 44px; padding: 6px 12px; font-size: 16px; }
.btn.danger { border-color: var(--red); color: var(--red); }
.row { display: flex; gap: 8px; flex-wrap: wrap; }

/* plan: tear-off calendar leaves */
.plan h2 { margin-top: 4px; }
.progress { margin: 0 0 14px; color: var(--muted); }
.days { list-style: none; margin: 0; padding: 0; }
.day { display: grid; grid-template-columns: 58px 1fr; gap: 14px; padding: 8px 0; border-top: 1px dashed var(--line); }
.day:first-child { border-top: 0; }
.leaf { display: flex; flex-direction: column; align-items: center; background: var(--paper); border: 2px solid var(--ink); border-radius: 6px; overflow: hidden; align-self: start; font-family: var(--num); line-height: 1; }
.leaf .mon { display: block; width: 100%; text-align: center; background: var(--ink); color: var(--bg); font-size: 14px; font-weight: 700; padding: 4px 0 3px; letter-spacing: .04em; }
.leaf .num { font-size: 26px; font-weight: 700; padding: 4px 0 1px; }
.leaf .wd { font-size: 14px; padding: 0 0 4px; color: var(--muted); }
.day.key .leaf { border-color: var(--red); }
.day.key .leaf .mon { background: var(--red); color: var(--red-ink); }
.day.today .leaf { box-shadow: 0 0 0 4px var(--gold); }
.day.past .leaf { opacity: .6; }
.dhead { margin: 0 0 2px; display: flex; flex-wrap: wrap; gap: 6px 10px; align-items: baseline; }
.lunar { color: var(--muted); font-size: 16px; }
.tag { font-weight: 700; color: var(--red); }
.tag.now { background: var(--gold); color: #231a17; padding: 0 8px; border-radius: 4px; }
.dtasks { list-style: none; margin: 0; padding: 0; }
.tick { display: flex; gap: 10px; align-items: flex-start; padding: 5px 0; cursor: pointer; min-height: 44px; }
.tick.done span { text-decoration: line-through; color: var(--muted); }
.customs { color: var(--muted); margin: 16px 0 12px; }
.actions { display: flex; gap: 10px; flex-wrap: wrap; margin: 4px 0 8px; }
.savenote { color: var(--muted); margin: 6px 0 10px; }
.savenote.off { color: var(--red); font-weight: 600; }
.banner { background: var(--gold-soft); border-radius: 6px; padding: 12px 14px; margin: 0 0 14px; }
.banner p { margin: 0 0 8px; }
.copies-block { margin: 6px 0 24px; }
.copies-block > summary { cursor: pointer; min-height: 44px; display: flex; align-items: center; color: var(--muted); font-weight: 600; }
.copies { list-style: none; padding: 0; margin: 0 0 12px; }
.copies li { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 6px 0; border-top: 1px solid var(--line); }
.copies .when { display: block; color: var(--muted); font-size: 16px; }
.copies .none { color: var(--muted); }
.confirm { margin-top: 12px; padding: 12px; border: 2px solid var(--red); border-radius: 6px; }
.confirm p { margin: 0 0 8px; }

/* toast and undo */
.toast, .undo { position: fixed; left: 50%; transform: translateX(-50%); bottom: 16px; z-index: 20; width: min(560px, calc(100% - 32px)); background: var(--ink); color: var(--bg); padding: 12px 16px; border-radius: 6px; box-shadow: 0 6px 24px rgba(0,0,0,.25); }
.toast { pointer-events: none; }
.toast input { pointer-events: auto; width: 100%; margin-top: 8px; }
.undo { display: flex; justify-content: space-between; align-items: center; gap: 12px; bottom: 16px; }
.undo .btn { background: var(--bg); color: var(--ink); border-color: var(--bg); }

/* content */
.content { padding-top: 20px; padding-bottom: 20px; border-top: 2px solid var(--ink); margin-top: 8px; }
.content section { margin: 18px 0 26px; }
.content p { max-width: 68ch; }
.faq h3 { margin-top: 18px; }
.faq p { margin: 0 0 8px; }
.sources ul { padding-left: 20px; }
.sources li { margin: 6px 0; }

/* footer */
footer { border-top: 1px solid var(--line); padding: 18px 0 28px; color: var(--muted); }
.sb-footer p { margin: 8px 0; font-size: 16px; }
.sb-more { line-height: 1.7; }
.sb-footer a { color: inherit; }

.print-root { display: none; }

@media (max-width: 480px) {
  body { font-size: 16px; }
  .lede { font-size: 17px; }
  .trow { grid-template-columns: minmax(0, 1fr); }
  .trow-ctl { padding-left: 32px; }
  .trow-ctl select { flex: 1 1 0; width: 0; min-width: 0; }
  .addrow select { width: 100%; }
  .addrow label:not(.grow) { flex: 1 1 100%; }
  .day { grid-template-columns: 50px 1fr; gap: 12px; }
  .leaf .num { font-size: 24px; }
  .yearpick select { padding-left: 8px; }
  .actions .btn { flex: 1 1 auto; }
}
@media (prefers-reduced-motion: reduce) { * { scroll-behavior: auto !important; transition: none !important; } }

/* print: only the plan sheet */
@media print {
  @page { margin: 14mm 13mm; }
  body { background: #fff; color: #000; font-size: 11pt; line-height: 1.4; }
  body > *:not(.print-root) { display: none !important; }
  .print-root { display: block !important; }
  .ptable th.phead { text-align: left; font-weight: 400; padding: 0 0 8pt; border: 0; }
  .pt1 { display: block; font-family: var(--serif); font-size: 19pt; font-weight: 700; }
  .pt2 { display: block; font-size: 11pt; margin-top: 2pt; }
  .pt3 { display: block; font-size: 9.5pt; color: #333; margin-top: 2pt; }
  .ptable { width: calc(100% - 2px); margin: 0 1px; border-collapse: collapse; table-layout: fixed; }
  .ptable col.c1 { width: 24%; }
  .pcols th { text-align: left; font-size: 10pt; border-bottom: 1.5pt solid #000; padding: 3pt 6pt; }
  .ptable tbody { break-inside: avoid; page-break-inside: avoid; }
  .ptable tbody th, .ptable tbody td { vertical-align: top; text-align: left; border-bottom: 0.75pt solid #999; padding: 3pt 6pt; }
  .ptable tbody th { font-weight: 400; }
  .pd { display: block; font-weight: 700; }
  .pl { display: block; font-size: 10pt; color: #333; }
  .pk { margin: 0 0 3pt; font-weight: 700; color: #8a1a14; print-color-adjust: exact; -webkit-print-color-adjust: exact; }
  .pt { margin: 0 0 2pt; display: flex; gap: 6pt; align-items: flex-start; }
  .box { flex: none; display: inline-block; width: 10pt; height: 10pt; border: 1pt solid #000; margin-top: 2pt; font-size: 8pt; line-height: 9pt; text-align: center; }
}
@media (max-width: 360px) {
  .pick { gap: 6px; }
  .seg span { font-size: 15px; padding: 0 2px; }
  .yearpick select { padding: 8px 20px 8px 6px; background-position: right 4px center; }
}
