:root {
  --bg: #eef1f5;
  --panel: #ffffff;
  --ink: #18212f;
  --muted: #4a5466;
  --line: #c9d1dc;
  --accent: #a84a08;
  --accent-ink: #ffffff;
  --watch: #c2570c;
  --asleep: #2f456b;
  --trance: #127a70;
  --awake: #e3d6b8;
  --gap: #b42318;
  --bad-bg: #fdecea;
  --focus: #1b64d1;
  --r: 6px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e131b;
    --panel: #151c27;
    --ink: #e6eaf0;
    --muted: #a9b3c2;
    --line: #2c3747;
    --accent: #f0a04b;
    --accent-ink: #1a1206;
    --watch: #ec8a3c;
    --asleep: #4a6597;
    --trance: #2aa596;
    --awake: #6b5f45;
    --gap: #ff8a7a;
    --bad-bg: #3a1d1b;
    --focus: #7fb0ff;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 17px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
a { color: var(--accent); }
.wrap { max-width: 1120px; margin: 0 auto; padding: 0 16px; }
.skip { position: absolute; left: -9999px; }
.skip:focus { left: 16px; top: 8px; background: var(--panel); padding: 8px 12px; z-index: 10; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
[hidden] { display: none !important; }

.top { padding: 22px 0 6px; }
h1 { font-size: 2rem; line-height: 1.15; margin: 0 0 6px; letter-spacing: -0.02em; font-weight: 800; }
.lede { margin: 0; max-width: 60ch; color: var(--muted); }
h2 { font-size: 1.3rem; line-height: 1.25; margin: 0 0 8px; letter-spacing: -0.01em; }

.btn {
  font: inherit; font-size: 1rem; min-height: 44px; padding: 8px 14px;
  border: 1px solid var(--line); border-radius: var(--r); background: var(--panel); color: var(--ink); cursor: pointer;
}
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 650; }
.btn.quiet { border-color: transparent; background: transparent; text-decoration: underline; }
.btn.icon { min-width: 44px; padding: 8px 0; font-size: 1.3rem; line-height: 1; }
.btn:disabled { opacity: 0.45; cursor: default; }
input, select { font: inherit; font-size: 1rem; color: var(--ink); background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); min-height: 44px; padding: 6px 10px; }
input[type="text"] { width: 100%; }
label { display: block; }
fieldset { border: 0; margin: 0; padding: 0; min-width: 0; }
legend { padding: 0; margin-bottom: 4px; font-weight: 650; }

.tool { padding-top: 10px; padding-bottom: 8px; }
.bar { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); padding: 10px 14px; margin-bottom: 12px; display: flex; flex-wrap: wrap; gap: 8px 16px; align-items: center; justify-content: space-between; }
.bar p { margin: 0; }
.note { background: var(--bad-bg); border-radius: var(--r); padding: 10px 14px; margin: 0 0 12px; }
.grid { display: grid; gap: 22px; }
.setup { min-width: 0; }

.camp { display: flex; flex-wrap: wrap; gap: 10px 18px; align-items: flex-end; margin-bottom: 14px; }
.camp label, .camp legend { font-weight: 650; }
.f-start input { display: block; margin-top: 4px; min-width: 9.5em; }
.pair { display: flex; gap: 6px; }

.h-party { font-size: 1.05rem; margin: 0 0 6px; }
.party { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.pc { display: grid; grid-template-columns: 1fr 44px; grid-template-areas: "name del" "kind kind" "hours hours"; gap: 6px; padding: 10px 0 12px; border-bottom: 1px solid var(--line); }
.pc-name { grid-area: name; }
.pc-kind { grid-area: kind; width: 100%; }
.pc-hours { grid-area: hours; display: flex; align-items: center; gap: 8px; }
.pc-hours input { width: 5.5em; }
.pc-del { grid-area: del; }
@media (min-width: 370px) {
  .pc { grid-template-columns: minmax(0, 1fr) 9.2em 44px; grid-template-areas: "name kind del" "hours hours hours"; padding: 6px 0; border-bottom: 0; }
  .party { gap: 4px; }
}
.party-btns { margin: 8px 0 16px; }

.watches { margin-bottom: 12px; }
.seg { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); border: 1px solid var(--line); border-radius: var(--r); overflow: hidden; max-width: 30em; }
.seg label { position: relative; display: flex; }
.seg input { position: absolute; opacity: 0; inset: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.seg span { flex: 1; display: flex; align-items: center; justify-content: center; text-align: center; padding: 8px 6px; min-height: 44px; line-height: 1.25; background: var(--panel); border-right: 1px solid var(--line); }
.seg label:last-child span { border-right: 0; }
.seg input:checked + span { background: var(--ink); color: var(--bg); font-weight: 650; }
.seg input:focus-visible + span { outline: 3px solid var(--focus); outline-offset: -3px; }
.sub { margin-top: 10px; }
.sub select { margin-left: 6px; }
.more summary, .hours summary, .kept summary { cursor: pointer; font-weight: 650; min-height: 44px; display: flex; align-items: center; gap: 8px; list-style: none; }
.more summary::-webkit-details-marker, .hours summary::-webkit-details-marker, .kept summary::-webkit-details-marker { display: none; }
.more summary::before, .hours summary::before, .kept summary::before { content: ""; width: 0; height: 0; border-style: solid; border-width: 6px 0 6px 9px; border-color: transparent transparent transparent currentColor; }
details[open] > summary::before { transform: rotate(90deg); }
.check { display: flex; align-items: center; gap: 10px; min-height: 44px; }
.check input { width: 22px; height: 22px; min-height: 0; margin: 0; flex: none; }
.party-btns #party-full { color: var(--muted); }
.peek { margin: 0 0 12px; padding: 8px 12px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); overflow-wrap: anywhere; }
.peek .nw { white-space: nowrap; }
.more label { margin: 6px 0 10px; }
.more select { display: block; margin-top: 4px; max-width: 100%; }

.result { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); padding: 16px; min-width: 0; }
.r-sum { margin: 0 0 10px; color: var(--muted); }
.msg { overflow-wrap: anywhere; margin: 0 0 10px; padding: 10px 12px; border-radius: var(--r); border: 1px solid var(--line); }
.msg.bad { background: var(--bad-bg); border-color: transparent; }
.msg .btn { display: block; width: fit-content; margin-top: 8px; }
.warn { color: var(--gap); font-weight: 600; }
.rota { width: 100%; border-collapse: collapse; margin: 6px 0 14px; font-variant-numeric: tabular-nums; }
.rota th { text-align: left; font-size: 1rem; color: var(--muted); font-weight: 600; padding: 4px 8px 4px 0; border-bottom: 2px solid var(--ink); }
.rota td { padding: 9px 8px 9px 0; border-bottom: 1px solid var(--line); vertical-align: top; }
.rota .nw { white-space: nowrap; }
.rota td:last-child { overflow-wrap: anywhere; }
.rota .len { color: var(--muted); margin-left: 6px; white-space: nowrap; }
.rota .wn { display: inline-block; min-width: 1.6em; color: var(--muted); }
.rota tr.gap td { color: var(--gap); }

.timeline { margin: 4px 0 8px; font-variant-numeric: tabular-nums; }
.tl-row, .tl-ticks { display: grid; grid-template-columns: minmax(4.5em, 7.5em) 1fr; gap: 8px; align-items: center; }
.tl-row { margin: 5px 0; }
.tl-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 1rem; }
.tl-bar { position: relative; height: 22px; border-radius: 3px; overflow: hidden; background: var(--bg); }
.tl-ticks .tl-bar { height: 1.5em; overflow: visible; background: none; }
.tick { position: absolute; top: 0; transform: translateX(-50%); font-size: 0.85rem; color: var(--muted); white-space: nowrap; }
.tick.first { transform: none; }
.tick.last { transform: translateX(-100%); }
.timeline { container-type: inline-size; }
@container (max-width: 420px) { .tick.minor { display: none; } }
@container (max-width: 300px) { .tick:not(.first):not(.last) { display: none; } }
.tseg.s-watch, .k-watch { background: var(--watch); }
.tseg.s-asleep, .k-asleep { background: var(--asleep); }
.tseg.s-trance, .tseg.s-rest, .k-trance { background: var(--trance); }
.tseg.s-awake, .k-awake { background: var(--awake); }
.tseg.s-gap { background: repeating-linear-gradient(45deg, var(--gap) 0 4px, transparent 4px 8px); }
.tl-bar .tseg { position: absolute; top: 0; bottom: 0; border: 0; border-radius: 0; overflow: visible; width: auto; }
.legend { list-style: none; margin: 4px 0 12px; padding: 0; display: flex; flex-wrap: wrap; gap: 4px 16px; font-size: 1rem; color: var(--muted); }
.legend i { display: inline-block; width: 14px; height: 14px; border-radius: 3px; margin-right: 6px; vertical-align: -2px; }
.rests { list-style: none; margin: 0 0 14px; padding: 0; }
.rests li { padding: 6px 0; border-top: 1px solid var(--line); overflow-wrap: anywhere; }
.r-btns { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 8px; }
.night { display: inline-flex; align-items: center; gap: 6px; margin-left: auto; }
.scroll { overflow-x: auto; }
.scroll .hourly { min-width: 44em; }
.hourly { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; table-layout: fixed; }
.hourly thead th:first-child { width: 5.6em; }
.hourly td, .hourly thead th { overflow-wrap: break-word; }
.hourly th, .hourly td { text-align: left; padding: 6px 8px 6px 0; border-bottom: 1px solid var(--line); vertical-align: top; }
.hourly thead th { color: var(--muted); font-weight: 600; }
.hourly th[scope="row"] { white-space: nowrap; font-weight: 600; }
.none { color: var(--muted); }

.kept { margin-top: 18px; }
.kept-list { list-style: none; padding: 0; margin: 4px 0 10px; }
.kept-list li { overflow-wrap: anywhere; display: flex; flex-wrap: wrap; justify-content: space-between; gap: 6px 12px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.kept-list .when { color: var(--muted); }
.kept-btns { display: flex; flex-wrap: wrap; gap: 8px; }

.toast { overflow-wrap: anywhere; position: fixed; left: 50%; bottom: 16px; transform: translateX(-50%); width: min(560px, calc(100% - 32px)); background: var(--ink); color: var(--bg); border-radius: var(--r); padding: 10px 14px; display: flex; gap: 12px; align-items: center; justify-content: space-between; z-index: 20; pointer-events: none; }
.toast .btn { pointer-events: auto; }

.prose { max-width: 760px; padding-top: 24px; padding-bottom: 24px; }
.prose h2 { margin-top: 26px; }
.prose h3 { font-size: 1.05rem; margin: 18px 0 4px; }
.prose p { margin: 0 0 12px; }
.sources { font-size: 1rem; color: var(--muted); overflow-wrap: anywhere; }
.print-card { display: none; }

.site-foot { border-top: 1px solid var(--line); padding: 18px 0 28px; margin-top: 12px; color: var(--muted); }
.sb-footer p { margin: 0 0 10px; }
.sb-more { line-height: 1.8; }
.sb-footer a { color: var(--ink); }

@media (min-width: 900px) {
  h1 { font-size: 2.4rem; }
  .grid { grid-template-columns: minmax(0, 1fr) minmax(0, 1.15fr); align-items: start; }
  .peek { display: none; }
}
@media (prefers-reduced-motion: reduce) { * { scroll-behavior: auto !important; transition: none !important; } }

@media print {
  @page { margin: 12mm; }
  body { background: #fff; color: #000; font-size: 10.5pt; }
  body > *:not(.print-card) { display: none !important; }
  .print-card { display: block !important; color: #000; }
  .print-card .p-title { font-size: 18pt; margin: 0 0 2pt; }
  .print-card h3 { font-size: 12pt; margin: 10pt 0 4pt; break-after: avoid; }
  .pc-sub { margin: 0 0 8pt; color: #333; }
  .print-card .msg { border: 1px solid #999; background: none; padding: 4pt 6pt; margin: 0 0 6pt; }
  .print-card .warn { color: #000; }
  .p-rota { width: calc(100% - 2px); margin: 0 1px 10pt; border-collapse: collapse; font-size: 12pt; }
  .p-rota th, .p-rota td { border: 1px solid #666; padding: 2pt 6pt; text-align: left; }
  .p-rota th { background: none; font-size: 10pt; }
  .p-rota td.box { width: 12mm; }
  .p-rota tr, .hourly tr { break-inside: avoid; }
  .p-tl .tl-bar { background: #fff; border: 0.5pt solid #888; height: 12pt; }
  .p-tl .tl-ticks .tl-bar { border: 0; height: 12pt; }
  .p-tl .tick { color: #333; font-size: 8.5pt; }
  .p-tl .tl-row, .p-tl .tl-ticks { grid-template-columns: minmax(5em, 12em) 1fr; }
  .p-tl .tl-row { margin: 2pt 0; }
  .p-tl .tl-name { font-size: 10pt; }
  .print-card .tseg, .print-card .legend i { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .print-card .tseg.s-watch, .print-card .k-watch { background: #d9822b; }
  .print-card .tseg.s-asleep, .print-card .k-asleep { background: #8597b8; }
  .print-card .tseg.s-trance, .print-card .tseg.s-rest, .print-card .k-trance { background: #7cc4b9; }
  .print-card .tseg.s-awake, .print-card .k-awake { background: #f1e7cf; }
  .print-card .tseg.s-gap { background: repeating-linear-gradient(45deg, #b42318 0 3px, #fff 3px 6px); }
  .print-card .legend { color: #333; font-size: 9.5pt; margin: 4pt 0 6pt; }
  .print-card .rests { margin: 0; }
  .print-card .rests li { border-top: 0.5pt solid #bbb; padding: 2pt 0; }
  .print-card .hourly { width: calc(100% - 2px); margin: 0 1px; font-size: 9pt; line-height: 1.3; }
  .print-card .hourly th, .print-card .hourly td { border-bottom: 0.5pt solid #bbb; padding: 1.5pt 6pt 1.5pt 0; color: #000; }
  .print-card .hourly thead th:nth-child(2) { width: 25%; }
  .print-card .hourly thead th:nth-child(3) { width: 18%; }
  .print-card .hourly td { overflow-wrap: anywhere; }
  .blank { display: inline-block; min-width: 9em; border-bottom: 0.8pt solid #000; font-weight: 700; }
  .tl-name .blank, .hourly .blank { min-width: 3em; }
  .p-foot { margin-top: 6pt; font-size: 8.5pt; color: #444; break-before: avoid; }
}
