:root {
  color-scheme: light;
  --ink: #132d33;
  --muted: #617277;
  --paper: #f5f2e9;
  --white: #fffdf7;
  --line: #d8d6cc;
  --navy: #0d3c46;
  --teal: #087d79;
  --teal-dark: #075f5c;
  --coral: #ef6a4c;
  --coral-soft: #fff0ea;
  --green-soft: #e6f2e9;
  --shadow: 0 18px 50px rgb(19 45 51 / 10%);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
html { scroll-behavior: smooth; }
body { margin: 0; color: var(--ink); background: var(--paper); line-height: 1.5; }
button, input, select { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .48; }

.hero { max-width: 1500px; margin: auto; padding: 2.2rem 4vw 2rem; background: radial-gradient(circle at 84% 32%, rgb(8 125 121 / 12%) 0 4px, transparent 5px), linear-gradient(115deg, transparent 62%, rgb(8 125 121 / 7%) 62% 63%, transparent 63%); }
.eyebrow { margin: 0 0 .75rem; color: var(--teal); font-size: .72rem; font-weight: 800; letter-spacing: .16em; text-transform: uppercase; }
h2, legend { font-family: Georgia, "Times New Roman", serif; font-weight: 500; letter-spacing: -.035em; }
.hero__lede { max-width: 760px; margin: .6rem 0 0; color: var(--muted); font-size: 1.05rem; }
.hero__facts { display: flex; flex-wrap: wrap; gap: .7rem; margin-top: 1.15rem; }
.hero__facts span { padding: .42rem .75rem; border: 1px solid var(--line); border-radius: 100px; background: rgb(255 253 247 / 65%); font-size: .78rem; font-weight: 700; }

.workspace { max-width: 1500px; margin: 0 auto 5rem; padding: 0 4vw; display: grid; grid-template-columns: minmax(330px, 470px) minmax(0, 1fr); align-items: start; gap: 2rem; }
.configuration, .results { border: 1px solid var(--line); background: var(--white); box-shadow: var(--shadow); }
.configuration { padding: clamp(1.4rem, 3vw, 2.5rem); }
.results { min-height: 680px; overflow: hidden; }
.section-heading, .result-heading { display: flex; align-items: flex-end; justify-content: space-between; gap: 1rem; }
.section-heading h2, .result-heading h2, .empty-state h2 { margin: 0; font-size: clamp(1.8rem, 3vw, 2.5rem); line-height: 1.05; }
.section-heading--rules { margin-top: 2.7rem; }

fieldset { min-width: 0; margin: 2rem 0; padding: 0; border: 0; }
.fieldset-heading { display: flex; align-items: baseline; justify-content: space-between; gap: 1rem; }
legend { font-size: 1.25rem; }
label { display: grid; gap: .45rem; color: var(--ink); font-size: .82rem; font-weight: 750; }
input, select { width: 100%; min-height: 45px; padding: .65rem .75rem; border: 1px solid #b9c1bf; border-radius: 3px; color: var(--ink); background: white; }
input:focus, select:focus, button:focus-visible { outline: 3px solid rgb(8 125 121 / 25%); outline-offset: 2px; border-color: var(--teal); }
.field-help { margin: .45rem 0 1rem; color: var(--muted); font-size: .78rem; font-weight: 450; }
.field-grid { display: grid; gap: 1rem; margin: 1rem 0; }
.field-grid--two { grid-template-columns: 1fr 1fr; }
.field-grid--three { grid-template-columns: repeat(3, 1fr); }
.input-unit { position: relative; display: block; }
.input-unit input { padding-right: 3.6rem; }
.input-unit small { position: absolute; right: .65rem; top: 50%; transform: translateY(-50%); color: var(--muted); font-size: .7rem; text-transform: uppercase; pointer-events: none; }
.stack { display: grid; gap: .65rem; }
.crew-row { display: grid; grid-template-columns: 1fr auto; gap: .55rem; align-items: center; }
.icon-button { width: 42px; height: 42px; border: 1px solid var(--line); border-radius: 50%; background: transparent; color: var(--muted); }
.rule-card { padding: 1rem; border: 1px solid var(--line); background: #faf9f4; }
.rule-card__head { display: flex; justify-content: space-between; align-items: center; margin-bottom: .7rem; }
.rule-card__head strong { font-size: .82rem; }
.rule-grid { display: grid; grid-template-columns: 1fr 1fr; gap: .75rem; }
.rule-grid .wide { grid-column: 1 / -1; }
.rule-editor-actions { display: grid; gap: .75rem; margin-top: 1rem; padding-top: 1rem; border-top: 1px solid var(--line); }
.rule-editor-actions__row { display: flex; flex-wrap: wrap; gap: .65rem; }
.rule-editor-actions__presets { align-items: baseline; }
.rule-editor-actions__presets .text-button { padding: .3rem 0; text-align: left; }

.actions { display: flex; flex-wrap: wrap; gap: .65rem; }
.actions--primary { margin-top: 1.6rem; }
.primary-button, .secondary-button, .text-button { border-radius: 2px; font-weight: 800; }
.primary-button { flex: 1; min-height: 50px; padding: .75rem 1.2rem; border: 1px solid var(--teal); color: white; background: var(--teal); }
.primary-button:hover { background: var(--teal-dark); }
.secondary-button { min-height: 42px; padding: .55rem .85rem; border: 1px solid var(--navy); color: var(--navy); background: transparent; }
.secondary-button:hover:not(:disabled) { color: white; background: var(--navy); }
.text-button { padding: .25rem 0; border: 0; color: var(--teal-dark); background: transparent; font-size: .78rem; }
.reset-button { margin-top: 1.2rem; color: var(--muted); text-decoration: underline; text-underline-offset: 3px; }
.error-panel { margin-top: 1.2rem; padding: .9rem 1rem; border-left: 4px solid var(--coral); background: var(--coral-soft); color: #7f2e1e; font-size: .84rem; }
.error-panel ul { margin: .35rem 0 0; padding-left: 1.25rem; }

.status-strip { min-height: 84px; padding: 1rem 1.5rem; display: flex; align-items: center; gap: .9rem; border-bottom: 1px solid var(--line); background: #faf9f4; }
.status-dot { width: 11px; height: 11px; flex: 0 0 auto; border-radius: 50%; background: #9aa5a4; box-shadow: 0 0 0 5px rgb(154 165 164 / 14%); }
.status-dot.running { background: var(--coral); box-shadow: 0 0 0 5px rgb(239 106 76 / 16%); animation: pulse 1.4s infinite; }
.status-dot.complete { background: var(--teal); box-shadow: 0 0 0 5px rgb(8 125 121 / 14%); }
.status-label { color: var(--muted); font-size: .65rem; font-weight: 800; letter-spacing: .13em; text-transform: uppercase; }
#search-status { margin: .1rem 0 0; font-size: .88rem; }
@keyframes pulse { 50% { transform: scale(.72); opacity: .7; } }

.empty-state { max-width: 580px; margin: 0 auto; padding: 6rem 2rem; text-align: center; }
.empty-state > p:last-child { color: var(--muted); }
.empty-state__dial { position: relative; width: 165px; height: 165px; margin: 0 auto 2rem; border: 1px solid var(--line); border-radius: 50%; display: flex; align-items: center; justify-content: space-around; color: var(--muted); font: .68rem ui-monospace, monospace; }
.empty-state__dial::before, .empty-state__dial::after { content: ""; position: absolute; inset: 49% 16%; height: 1px; background: var(--coral); transform: rotate(-34deg); transform-origin: center; }
.empty-state__dial::after { inset: 16% 49%; width: 1px; height: auto; background: var(--line); transform: none; }

#result-content { padding: clamp(1.3rem, 3vw, 2.3rem); }
.result-heading { margin-bottom: 1.4rem; }
#live-link-panel { display: flex; align-items: center; flex-wrap: wrap; gap: .65rem; margin: -0.7rem 0 1.4rem; padding: .8rem .9rem; border: 1px solid var(--line); background: var(--green-soft); font-size: .84rem; }
#live-link-panel[hidden] { display: none; }
#live-link-panel p { margin: 0; font-weight: 700; }
#live-link-panel a { color: var(--teal-dark); font-weight: 800; }
#live-link-panel button { min-height: 32px; padding: .35rem .65rem; border: 1px solid var(--teal-dark); color: var(--teal-dark); background: transparent; }
.diagnostics { display: grid; gap: 1rem; margin-bottom: 1.5rem; }
.result-banner { padding: 1rem 1.1rem; border-left: 4px solid var(--teal); background: var(--green-soft); }
.result-banner.best-found { border-color: var(--coral); background: var(--coral-soft); }
.result-banner strong { display: block; font-family: Georgia, serif; font-size: 1.35rem; }
.result-banner p { margin: .25rem 0 0; color: var(--muted); font-size: .84rem; }
.score-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 1px; border: 1px solid var(--line); background: var(--line); }
.score-card { min-height: 91px; padding: .8rem; background: var(--white); }
.score-card span { display: block; color: var(--muted); font-size: .65rem; font-weight: 800; letter-spacing: .09em; text-transform: uppercase; }
.score-card strong { display: block; margin-top: .25rem; font-family: Georgia, serif; font-size: 1.35rem; font-weight: 500; }
.rule-evaluations { display: grid; gap: .5rem; }
.rule-evaluation { padding: .75rem .9rem; border: 1px solid var(--line); font-size: .82rem; }
.rule-evaluation strong { color: var(--teal-dark); }
.rule-evaluation.violation strong { color: #a13e2a; }

.table-shell { overflow: auto; max-height: 72vh; border: 1px solid var(--line); }
table { width: 100%; border-collapse: collapse; background: white; font-size: .79rem; }
caption { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
th, td { padding: .7rem .65rem; border-bottom: 1px solid #e7e5de; text-align: left; white-space: nowrap; }
th { position: sticky; top: 0; z-index: 2; color: white; background: var(--navy); font-size: .66rem; letter-spacing: .06em; text-transform: uppercase; }
tbody tr:nth-child(even) { background: #faf9f5; }
tbody tr.cycle-boundary td { border-top: 3px solid var(--coral); }
tbody tr.reserve-boundary td {
  border-top: 3px double var(--coral);
}
tbody tr.reserve-boundary td:first-child::before {
  content: "Reserve";
  display: block;
  font-size: 0.65rem;
  text-transform: uppercase;
}
td.role { font-weight: 800; }
td.rest { color: var(--teal-dark); font-variant-numeric: tabular-nums; }
.time-cell span { display: block; }
.time-cell small { color: var(--muted); }
.nominal-note { margin: 1rem 0 0; color: var(--muted); font-size: .75rem; }
.print-header { display: none; }

footer { padding: 2rem 4vw; border-top: 1px solid var(--line); text-align: center; color: var(--muted); font-size: .78rem; }

@media (max-width: 1050px) {
  .workspace { grid-template-columns: 1fr; }
  .results { min-height: 520px; }
}

@media (max-width: 620px) {
  .hero { padding-top: 1.6rem; }
  .workspace { padding: 0; gap: 1rem; }
  .configuration, .results { border-left: 0; border-right: 0; }
  .field-grid--three, .rule-grid, .score-grid { grid-template-columns: 1fr 1fr; }
  .result-heading { align-items: flex-start; flex-direction: column; }
}

@media print {
  @page { size: A4 landscape; margin: 7mm; }
  body { background: white; color: black; font-size: 7pt; }
  .hero, .configuration, .status-strip, footer, .result-heading, .diagnostics, .nominal-note { display: none !important; }
  .workspace { display: block; max-width: none; margin: 0; padding: 0; }
  .results { min-height: 0; border: 0; box-shadow: none; }
  #result-content { padding: 0; }
  .print-header { display: block !important; margin: 0 0 3mm; }
  #live-link-panel { display: none !important; }
  .print-header h1 { margin: 0; font: 700 13pt/1.05 Georgia, "Times New Roman", serif; letter-spacing: -.02em; }
  .print-header p { margin: 1mm 0 0; font-size: 8pt; line-height: 1.1; }
  .table-shell { max-height: none; overflow: visible; border: 0; }
  table { table-layout: auto; font-size: 6.4pt; line-height: 1.05; }
  thead { display: table-header-group; }
  #schedule-table th:nth-child(2), #schedule-table td:nth-child(2) { display: none; }
  th { position: static; color: black; background: #eee; font-size: 5.8pt; }
  th, td { padding: .8mm 1mm; border-color: #bbb; white-space: normal; overflow-wrap: anywhere; }
  #schedule-table th:nth-child(1), #schedule-table td:nth-child(1),
  #schedule-table th:nth-child(3), #schedule-table td:nth-child(3),
  #schedule-table th:nth-child(4), #schedule-table td:nth-child(4) { width: 1%; white-space: nowrap; }
  #schedule-table th:nth-child(3), #schedule-table td:nth-child(3) { padding-right: .75mm; }
  #schedule-table th:nth-child(4), #schedule-table td:nth-child(4) { padding-left: .75mm; }
  #schedule-table th:nth-child(n+6), #schedule-table td:nth-child(n+6) { border-left: .5pt solid #aaa; }
  tbody td { border-bottom: .5pt solid #777; }
  .time-cell small { font-size: inherit; line-height: inherit; }
  tbody tr { break-inside: avoid; }
}
