:root {
  --bg: #EFECE6;
  --panel: #FFFFFF;
  --ink: #1D1B18;
  --muted: #6B655C;
  --line: #E2DDD4;
  --accent: #B4441E;
  --accent-ink: #FFFFFF;
  --gh: #C62D2D;
  --rh: #2F6FB0;
  --radius: 10px;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--ink); font-family: 'Instrument Sans', system-ui, sans-serif; font-size: 14px; }
button, input { font: inherit; color: inherit; }

.app { display: grid; grid-template-columns: 340px minmax(0, 1fr); height: 100vh; }
.panel { background: var(--panel); border-right: 1px solid var(--line); overflow-y: auto; padding: 22px 22px 40px; }
.preview { overflow-y: auto; padding: 28px; }

.brand { display: flex; gap: 12px; align-items: center; margin-bottom: 22px; }
.brand-mark { width: 38px; height: 38px; border-radius: 9px; background: var(--ink); position: relative; flex: none; }
.brand-mark::before { content: ''; position: absolute; inset: 9px 8px 8px; border: 2px solid #fff; border-radius: 3px; border-top-width: 5px; }
.brand h1 { font-size: 17px; margin: 0; letter-spacing: -0.01em; }
.brand p { margin: 2px 0 0; color: var(--muted); font-size: 12.5px; }

.controls { display: flex; flex-direction: column; gap: 18px; }
.field { border: 0; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.field > span, .field legend { font-size: 12px; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); padding: 0; margin-bottom: 8px; }
.year-row { display: grid; grid-template-columns: 44px 1fr 44px; gap: 6px; }
.year-row input { height: 44px; border: 1px solid var(--line); border-radius: var(--radius); text-align: center; font-size: 20px; font-weight: 700; background: #FBFAF7; }
.year-row input:focus-visible, .step:focus-visible, .btn:focus-visible, .theme-card:focus-within, .seg label:focus-within { outline: 2px solid var(--accent); outline-offset: 2px; }
.step { height: 44px; border: 1px solid var(--line); border-radius: var(--radius); background: #fff; cursor: pointer; font-size: 18px; }
.step:hover { background: #F6F3EE; }

.theme-list { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.theme-card { position: relative; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; cursor: pointer; background: #fff; }
.theme-card input { position: absolute; opacity: 0; pointer-events: none; }
.theme-card .sw { display: block; height: 54px; }
.theme-card .nm { display: block; padding: 7px 9px 8px; font-size: 12.5px; font-weight: 600; line-height: 1.25; }
.theme-card:has(input:checked) { border-color: var(--ink); box-shadow: 0 0 0 1px var(--ink); }

.seg { display: grid; grid-template-columns: 1fr 1fr; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.seg label { position: relative; cursor: pointer; }
.seg input { position: absolute; opacity: 0; }
.seg span { display: block; text-align: center; padding: 11px 0; font-weight: 600; }
.seg input:checked + span { background: var(--ink); color: #fff; }

.check { display: flex; gap: 10px; align-items: center; cursor: pointer; min-height: 32px; }
.check input { width: 18px; height: 18px; accent-color: var(--ink); }
.optional { border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; }
.optional summary { cursor: pointer; font-weight: 600; display: flex; justify-content: space-between; min-height: 28px; align-items: center; }
.optional summary em { font-style: normal; color: var(--muted); font-weight: 500; font-size: 12.5px; }
.opt-list { display: grid; gap: 2px; margin-top: 6px; }
.opt-list .check { min-height: 30px; font-size: 13px; }
.hint { color: var(--muted); font-size: 12.5px; line-height: 1.5; margin: 6px 0 4px; }
.hint.small { margin-top: -6px; text-align: center; }

.actions { display: grid; gap: 8px; }
.btn { height: 46px; border-radius: var(--radius); border: 1px solid var(--line); background: #fff; font-weight: 700; cursor: pointer; }
.btn:hover { background: #F6F3EE; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { background: #983817; }
.btn:disabled { opacity: 0.6; cursor: progress; }

.hol-summary { margin-top: 26px; border-top: 1px solid var(--line); padding-top: 18px; }
.hol-summary h2 { font-size: 14px; margin: 0; }
.hol-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 6px; }
.hol-tools { display: flex; gap: 4px; }
.link-btn { border: 0; background: none; color: var(--accent); font-weight: 700; font-size: 12.5px; cursor: pointer; padding: 6px 8px; border-radius: 6px; }
.link-btn:hover { background: #F6F3EE; }
.hol-list li { cursor: pointer; }
.hol-list li:hover { background: #FBFAF7; }
.hol-list li.edited span { text-decoration: underline dotted; }
.hol-list li .tag { display: inline-block; font-size: 10px; font-weight: 700; background: #1D1B18; color: #fff; border-radius: 4px; padding: 1px 5px; margin-left: 6px; vertical-align: 1px; }

/* holiday editor dialog */
.editor { border: 0; padding: 0; border-radius: 14px; }
.editor::backdrop { background: rgba(20,18,15,.5); }
.editor-card { padding: 22px; display: grid; gap: 12px; min-width: min(360px, 90vw); }
.editor-card h3 { margin: 0 0 4px; font-size: 16px; }
.editor-card .field input, .editor-card .field select { height: 42px; border: 1px solid var(--line); border-radius: var(--radius); padding: 0 12px; width: 100%; background: #FBFAF7; }
.editor-row { display: flex; gap: 8px; align-items: center; margin-top: 4px; }
.editor-row .spacer { flex: 1; }
.editor-row .btn { height: 42px; padding: 0 16px; }
.btn.danger { background: #fff; border-color: #E5B3B3; color: #A12020; }
.btn.danger:hover { background: #FDECEC; }
.legend { display: flex; gap: 6px 12px; flex-wrap: wrap; align-items: center; color: var(--muted); font-size: 12px; margin: 0 0 10px; }
.legend .sw { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: -6px; }
.sw.gh { background: var(--gh); } .sw.rh { background: var(--rh); } .sw.sun { background: #E9A39A; }
.hol-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 1px; }
.hol-list li { display: grid; grid-template-columns: 74px 1fr; gap: 8px; padding: 5px 0; border-bottom: 1px dashed var(--line); font-size: 12.5px; line-height: 1.35; }
.hol-list li time { color: var(--muted); font-variant-numeric: tabular-nums; }
.hol-list li.gh span { font-weight: 700; color: var(--gh); }
.hol-list li.rh span { color: var(--rh); }
.hol-list li small { display: block; color: var(--muted); font-size: 11px; }

/* page previews */
.pages { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 26px 22px; max-width: 1400px; margin: 0 auto; }
.page-wrap { position: relative; aspect-ratio: 210 / 297; background: #fff; box-shadow: 0 1px 2px rgba(0,0,0,.08), 0 8px 24px rgba(0,0,0,.08); border-radius: 3px; overflow: hidden; cursor: zoom-in; border: 0; padding: 0; width: 100%; }
.page-wrap:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
.page-wrap .page { position: absolute; left: 0; top: 0; transform-origin: 0 0; }
.page-label { font-size: 12px; color: var(--muted); margin-top: 8px; display: flex; justify-content: space-between; }
.page-item { display: flex; flex-direction: column; }

/* long holiday months: three narrower columns */
.page .cal-hols.many ul { columns: 3; column-gap: 16px; font-size: 9.5px; }

/* A4 page at 96 dpi */
.page { width: 794px; height: 1123px; overflow: hidden; position: relative; background: #fff; }

.export-stage { position: fixed; left: -12000px; top: 0; width: 794px; }
.busy { position: fixed; inset: 0; background: rgba(20, 18, 15, .45); display: grid; place-items: center; z-index: 50; }
.busy[hidden] { display: none; }
.busy-card { background: #fff; border-radius: 14px; padding: 26px 34px; display: flex; gap: 14px; align-items: center; font-weight: 600; }
.spinner { width: 22px; height: 22px; border-radius: 50%; border: 3px solid var(--line); border-top-color: var(--accent); animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.lightbox { position: fixed; inset: 0; background: rgba(20,18,15,.82); z-index: 40; display: grid; place-items: center; padding: 20px; }
.lightbox[hidden] { display: none; }
.lb-stage { position: relative; background: #fff; box-shadow: 0 20px 60px rgba(0,0,0,.4); overflow: hidden; }
.lb-stage .page { transform-origin: 0 0; position: absolute; left: 0; top: 0; }
.lb-close { position: absolute; top: 14px; right: 18px; width: 44px; height: 44px; border-radius: 50%; border: 0; background: #fff; font-size: 26px; cursor: pointer; }

@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; height: auto; }
  .panel { border-right: 0; border-bottom: 1px solid var(--line); padding: 18px 16px 24px; }
  .preview { padding: 18px 16px 40px; }
  .pages { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 16px 12px; }
}

/* Printing: only the pages, one per A4 sheet, at full size */
@media print {
  @page { size: A4 portrait; margin: 0; }
  html, body { background: #fff; height: auto; }
  .app, .busy, .lightbox { display: none !important; }
  .export-stage { position: static; left: auto; width: auto; }
  .export-stage .page { page-break-after: always; break-after: page; }
  * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}
