/*
 * Look: a summer afternoon in the hills. Sky-blue page, cloud-white surfaces, meadow and forest greens,
 * red-roof red for "costs more". Original styling; no third-party artwork.
 */
:root {
  --sky: #cfe8f5;
  --sky-deep: #8ec5e6;
  --page: #e9f3f6;
  --page-low: #eef4e6;
  --cloud: #fdfdf9;
  --meadow: #9cc77a;
  --meadow-low: #6fa257;
  --hill-far: #b7d3c4;
  --hill-far-low: #93bba6;
  --forest: #285a3f;
  --ink: #23302a;
  --ink-soft: #52615a;
  --line: #cfdcd6;
  --sun: #f4cf68;
  --sun-soft: #fbedc2;
  --roof: #a8382f;
  --leaf: #2f7a46;
  --still: #4f7fa3;
  --shadow: 0 1px 2px rgb(40 70 60 / 0.08), 0 8px 24px -12px rgb(40 70 60 / 0.25);
  --display: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  --body: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  color-scheme: light;
  font-family: var(--body);
  font-size: 16px;
  line-height: 1.5;
  color: var(--ink);
}

@media (prefers-color-scheme: dark) {
  :root {
    --sky: #3b4f74;
    --sky-deep: #1f2b48;
    --page: #182030;
    --page-low: #1a2622;
    --cloud: #222c3b;
    --meadow: #3d5e45;
    --meadow-low: #2c4634;
    --hill-far: #33475a;
    --hill-far-low: #2a3b4a;
    --forest: #a9dbb1;
    --ink: #ece8dc;
    --ink-soft: #b5bcb4;
    --line: #36465a;
    --sun: #f1d27e;
    --sun-soft: #4a4430;
    --roof: #f19b8c;
    --leaf: #9fd8a9;
    --still: #a9c8e6;
    --shadow: 0 1px 2px rgb(0 0 0 / 0.3), 0 10px 28px -14px rgb(0 0 0 / 0.6);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background: linear-gradient(180deg, var(--page) 0%, var(--page) 55%, var(--page-low) 100%) fixed;
}

h1, h2, h3, h4 { font-family: var(--display); font-weight: 600; color: var(--forest); line-height: 1.2; }
h2 { font-size: 1.35rem; margin: 0; }
h3 { font-size: 1.2rem; margin: 0 0 0.6rem; }
h4 { font-size: 1rem; margin: 1.1rem 0 0.4rem; }
p { max-width: 70ch; }

/* ---------- header ---------- */

.scene { background: linear-gradient(180deg, var(--sky-deep) 0%, var(--sky) 70%, var(--page) 100%); }
.scene-text {
  max-width: 76rem;
  margin: 0 auto;
  padding: 2.5rem clamp(1rem, 4vw, 2.5rem) 4.5rem;
}
.scene h1 { margin: 0 0 0.4rem; font-size: clamp(1.9rem, 4.5vw, 2.9rem); letter-spacing: -0.01em; color: #1f4a34; }
.scene-text p { margin: 0; font-size: 1.08rem; max-width: 40rem; color: #29423a; }
@media (prefers-color-scheme: dark) {
  .scene h1 { color: #f4efdf; }
  .scene-text p { color: #d8dccf; }
}

/* ---------- layout ---------- */

.layout {
  max-width: 76rem;
  margin: -2.5rem auto 4rem;
  padding: 0 clamp(1rem, 4vw, 2.5rem);
  display: grid;
  grid-template-columns: minmax(0, 1.05fr) minmax(22rem, 0.95fr);
  gap: 1.75rem;
  align-items: start;
  position: relative;
}
.editor { grid-column: 1; grid-row: 1; display: grid; gap: 1rem; min-width: 0; }
.results, .editor { overflow-wrap: anywhere; }
.results {
  grid-column: 2;
  grid-row: 1;
  position: sticky;
  top: 1rem;
  max-height: calc(100vh - 2rem);
  overflow: auto;
  background: var(--cloud);
  border-radius: 22px;
  box-shadow: var(--shadow);
  padding: 1.25rem 1.25rem 1.5rem;
}

@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; margin-top: -2rem; }
  .results { grid-column: 1; grid-row: 1; position: static; max-height: none; overflow: visible; }
  .editor { grid-column: 1; grid-row: 2; }
}

/* ---------- results ---------- */

.results-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 0.75rem; margin-bottom: 0.9rem; }

.toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  margin: 0;
  padding: 0.2rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 0.85rem;
}
.toggle legend { float: left; padding: 0 0.45rem 0 0.6rem; color: var(--ink-soft); }
.toggle label { position: relative; cursor: pointer; }
.toggle input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.toggle span { display: block; padding: 0.3rem 0.75rem; border-radius: 999px; }
.toggle input:checked + span { background: var(--sun); color: #2b2410; font-weight: 600; }
.toggle input:focus-visible + span { outline: 2px solid var(--forest); outline-offset: 1px; }

.baseline-card {
  border-left: 4px solid var(--still);
  padding: 0.2rem 0 0.2rem 0.85rem;
  margin: 0 0 1rem;
  color: var(--ink-soft);
}
.baseline-card p { margin: 0; }
.baseline-card strong { color: var(--ink); }

.cards { display: grid; gap: 0.9rem; }

.card {
  position: relative;
  background: var(--cloud);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 1rem 1.1rem 0.8rem 1.35rem;
  overflow-wrap: anywhere;
}
.card::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0.9rem;
  bottom: 0.9rem;
  width: 5px;
  border-radius: 0 5px 5px 0;
  background: var(--still);
}
.card-worse::before { background: var(--roof); }
.card-better::before { background: var(--leaf); }
.card-problem::before { background: var(--sun); }

.measures { margin: 0; display: grid; gap: 0.55rem; }
.measure { display: grid; grid-template-columns: 4.2rem 1fr; gap: 0.75rem; align-items: baseline; }
.measure dt { color: var(--ink-soft); font-size: 0.9rem; }
.measure dd { margin: 0; }
.measure .big { font-family: var(--display); font-size: 1.35rem; font-weight: 600; font-variant-numeric: tabular-nums lining-nums; }
.measure .small { color: var(--ink-soft); font-size: 0.88rem; white-space: nowrap; }
.measure-worse .big { color: var(--roof); }
.measure-better .big { color: var(--leaf); }
.measure-same .big { color: var(--ink-soft); }

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

.card-details { margin-top: 0.5rem; }
.card-details > summary, .side-by-side > summary, .sub > summary {
  cursor: pointer;
  color: var(--forest);
  font-weight: 600;
  font-size: 0.92rem;
  width: fit-content;
}
.card-details[open] > summary { margin-bottom: 0.4rem; }
.card-details p { font-size: 0.9rem; }

.side-by-side { margin-top: 1.25rem; padding-top: 1rem; border-top: 1px dashed var(--line); }
.side-by-side[open] > summary { margin-bottom: 0.75rem; }

/* ---------- editor ---------- */

.section {
  background: var(--cloud);
  border-radius: 18px;
  box-shadow: var(--shadow);
}
.section > summary {
  list-style: none;
  cursor: pointer;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem 1.25rem;
  border-radius: 18px;
}
.section > summary::-webkit-details-marker { display: none; }
.section > summary h2::before {
  content: "";
  display: inline-block;
  width: 0.5rem;
  height: 0.5rem;
  margin-right: 0.6rem;
  border-right: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: translateY(-0.2rem) rotate(-45deg);
  transition: transform 0.15s ease;
}
.section[open] > summary h2::before { transform: translateY(-0.3rem) rotate(45deg); }
.section-sum { color: var(--ink-soft); font-size: 0.9rem; text-align: right; }
.section-body { padding: 0 1.25rem 1.25rem; }

.sub { margin-top: 1rem; padding-top: 0.75rem; border-top: 1px dashed var(--line); }
.sub[open] > summary { margin-bottom: 0.75rem; }
.sub-sum { color: var(--ink-soft); font-weight: 400; margin-left: 0.4rem; }

.fields { display: grid; grid-template-columns: repeat(auto-fit, minmax(12rem, 1fr)); gap: 0.9rem; }
.field { display: grid; gap: 0.25rem; font-size: 0.92rem; min-width: 0; }
.field > span { font-weight: 600; color: var(--ink); }
.field-small > span { font-size: 0.8rem; font-weight: 500; color: var(--ink-soft); }
.field-check { grid-template-columns: auto 1fr; align-items: center; align-self: end; padding-bottom: 0.45rem; }
.field-check > span { font-weight: 400; }

input, select {
  font: inherit;
  color: inherit;
  background: var(--page);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.45rem 0.6rem;
  width: 100%;
  min-width: 0;
}
input[type="checkbox"], input[type="radio"] { width: auto; accent-color: var(--forest); }
:focus-visible { outline: 2px solid var(--forest); outline-offset: 2px; }

.hint, .empty { color: var(--ink-soft); font-size: 0.88rem; }
.empty { font-style: italic; }

/* ways */
.way { border: 1px solid var(--line); border-radius: 14px; margin-bottom: 0.75rem; background: var(--cloud); }
.way > summary { cursor: pointer; padding: 0.7rem 0.9rem; display: flex; flex-wrap: wrap; gap: 0.25rem 0.75rem; align-items: baseline; list-style: none; }
.way > summary::-webkit-details-marker { display: none; }
.way > summary::before {
  content: "";
  width: 0.4rem;
  height: 0.4rem;
  border-right: 2px solid var(--forest);
  border-bottom: 2px solid var(--forest);
  transform: translateY(-0.15rem) rotate(-45deg);
  transition: transform 0.15s ease;
  align-self: center;
}
.way[open] > summary::before { transform: translateY(-0.2rem) rotate(45deg); }
.way-name { font-weight: 600; color: var(--forest); min-width: 0; }
.way-sum { color: var(--ink-soft); font-size: 0.88rem; }
.way-body { padding: 0 0.9rem 0.9rem; }
.way-actions { margin: 0.75rem 0 0; }

.row { display: grid; gap: 0.5rem; align-items: end; margin-bottom: 0.5rem; }
.row-leg { grid-template-columns: minmax(6rem, 1.2fr) repeat(3, minmax(4.5rem, 1fr)) 2rem; }
.row-cost { grid-template-columns: minmax(7rem, 1.6fr) minmax(5rem, 1fr) minmax(8rem, 1.4fr) 2rem; }
.row-day { grid-template-columns: minmax(8rem, 2fr) minmax(5rem, 1fr) 2rem; }
@media (max-width: 560px) {
  .row-leg, .row-cost { grid-template-columns: 1fr 1fr 2rem; }
  .row-leg .field:first-child, .row-cost .field:first-child { grid-column: 1 / 3; grid-row: 1; }
  .row-leg .icon-button, .row-cost .icon-button { grid-column: 3; grid-row: 1; }
  .row-leg .field:nth-child(4) { grid-column: span 2; }
  .row-day { grid-template-columns: minmax(0, 1fr) 5rem 2rem; }
}

/* scenarios */
.scenario { border: 1px solid var(--line); border-radius: 14px; padding: 0.9rem; margin-bottom: 0.75rem; }
.scenario-head { display: flex; gap: 0.75rem; align-items: end; margin-bottom: 0.6rem; }
.scenario-head .field { flex: 1; }
.scenario-head { flex-wrap: wrap; }
.hide-option { font-weight: 400; color: var(--ink-soft); }
.hide-option:has(input:disabled) { opacity: 0.55; }
.scenario.is-hidden { border-style: dashed; background: transparent; }
.scenario.is-hidden .scenario-head .field input { color: var(--ink-soft); }
.baseline { display: flex; gap: 0.4rem; align-items: center; padding-bottom: 0.5rem; font-weight: 600; white-space: nowrap; }
.wfh-label { padding-bottom: 0.5rem; color: var(--ink); }
.days-total { margin: 0.25rem 0 0; font-size: 0.88rem; font-variant-numeric: tabular-nums; }
.days-total.ok { color: var(--leaf); }
.days-total.bad { color: var(--roof); font-weight: 600; }
.scenario-actions { display: flex; flex-wrap: wrap; gap: 0.5rem; margin: 0.6rem 0 0; }

.errors { margin: 0.4rem 0; padding-left: 1.1rem; color: var(--roof); font-size: 0.9rem; }
.errors:empty { display: none; }

.clear-all { margin: 0.5rem 0 0; }

/* ---------- buttons ---------- */

.button {
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid transparent;
  background: var(--forest);
  color: var(--cloud);
  border-radius: 999px;
  padding: 0.5rem 1.05rem;
}
.button:hover { filter: brightness(1.08); }
.button-small { padding: 0.3rem 0.8rem; font-size: 0.88rem; }
.button-quiet { background: transparent; color: var(--ink-soft); border-color: var(--line); font-weight: 500; }
.button:disabled { opacity: 0.45; cursor: not-allowed; }
.icon-button {
  font: inherit;
  font-size: 1.25rem;
  line-height: 1;
  cursor: pointer;
  border: none;
  background: none;
  color: var(--ink-soft);
  padding: 0.4rem;
  border-radius: 8px;
}
.icon-button:hover { color: var(--roof); }
.icon-button:disabled { visibility: hidden; }

/* ---------- notices ---------- */

.notice {
  margin: 0 0 1rem;
  padding: 0.7rem 0.9rem;
  border-radius: 12px;
  background: var(--sun-soft);
  color: var(--ink);
  font-size: 0.92rem;
}
body > .notice { position: relative; z-index: 1; max-width: 72rem; margin: 1rem auto 3.5rem; }
.notice-soft { background: transparent; border: 1px dashed var(--sun); }

/* ---------- tables ---------- */

.table-scroll { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-variant-numeric: tabular-nums; font-size: 0.9rem; }
th, td { text-align: left; padding: 0.35rem 0.5rem; border-bottom: 1px solid var(--line); vertical-align: top; }
.mini-table td, .breakdown-table td { text-align: right; }
.mini-table th[scope="row"], .breakdown-table th[scope="row"] { font-weight: 400; color: var(--ink-soft); }
.breakdown-table caption { text-align: left; color: var(--ink-soft); font-size: 0.85rem; margin-bottom: 0.3rem; }
.breakdown-table .total th, .breakdown-table .total td { font-weight: 700; color: var(--ink); border-top: 2px solid var(--forest); }
.compare-table { min-width: 34rem; }
.compare-table th[scope="row"] { font-weight: 400; color: var(--ink-soft); }
.compare-table .group th { padding-top: 0.9rem; color: var(--forest); font-family: var(--display); font-weight: 600; }
.tag { font-size: 0.75rem; padding: 0.05rem 0.45rem; border-radius: 999px; background: var(--sun-soft); white-space: nowrap; }
.neutral { color: var(--ink-soft); }

.workings, .assumptions { padding-left: 1.1rem; font-size: 0.88rem; color: var(--ink-soft); }
.workings li, .assumptions li { margin-bottom: 0.3rem; }

.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

@media (prefers-reduced-motion: reduce) {
  .section > summary h2::before, .way > summary::before { transition: none; }
}

.print-only { display: none; }
.pdf { display: flex; flex-wrap: wrap; align-items: center; gap: 0.35rem 0.75rem; }
.pdf-option { display: flex; align-items: center; gap: 0.4rem; font-size: 0.85rem; color: var(--ink-soft); cursor: pointer; }
.results-head { row-gap: 0.5rem; }

/* ---------- print / Save as PDF: a compact report ---------- */

@media print {
  :root { color-scheme: light; }
  @page { margin: 11mm 12mm; }
  body { background: #fff; color: #1d2621; font-size: 9pt; line-height: 1.35; min-height: 0; }
  h2 { font-size: 12pt; }
  h3 { font-size: 10pt; margin: 0 0 3pt; }
  p { max-width: none; }
  .scene { background: none; }
  .scene-text { padding: 0 0 6pt; max-width: none; }
  .scene h1 { color: #1f4a34; font-size: 16pt; margin: 0 0 2pt; }
  .scene-text p { font-size: 9pt; max-width: none; }

  .editor, #storage-notice, .button, .icon-button, .toggle, .pdf, .card-details, .side-by-side > summary { display: none !important; }

  .layout { display: block; margin: 0; padding: 0; max-width: none; }
  .results { position: static; max-height: none; overflow: visible; box-shadow: none; padding: 0; background: none; border-radius: 0; }
  .results-head { margin-bottom: 4pt; }
  .notice { margin: 0 0 6pt; padding: 4pt 6pt; font-size: 8.5pt; }
  .baseline-card { margin: 0 0 6pt; padding: 0 0 0 6pt; }

  .cards { grid-template-columns: 1fr 1fr; gap: 6pt; }
  .card { break-inside: avoid; padding: 6pt 8pt 6pt 10pt; border-radius: 6pt; border-color: #c9d4cf; background: #fff; }
  .card::before { top: 6pt; bottom: 6pt; width: 3pt; }
  .measures { gap: 2pt; }
  .measure { grid-template-columns: 3.2rem 1fr; gap: 4pt; }
  .measure dt { font-size: 8pt; }
  .measure .big { font-size: 10.5pt; }
  .measure .small { font-size: 8pt; }
  .time-value { margin: 3pt 0 0; font-size: 8pt; }

  .side-by-side { margin-top: 8pt; padding-top: 0; border: none; }
  .table-scroll { overflow: visible; }
  table { font-size: 7.5pt; }
  th, td { padding: 1.5pt 4pt; }
  .compare-table { min-width: 0; }
  .compare-table .group th { padding-top: 4pt; }
  .assumptions, .workings { font-size: 7.5pt; margin: 2pt 0; }
  .assumptions li, .workings li { margin-bottom: 1pt; }

  .print-only { display: block; }
  .print-inputs, .print-workings { margin-top: 8pt; }
  .print-inputs { columns: 2; column-gap: 14pt; }
  .print-inputs h2, .print-workings h2 { column-span: all; margin: 0 0 4pt; }
  .print-inputs h3 { margin-top: 4pt; break-after: avoid; }
  .print-inputs ul { padding-left: 10pt; margin: 0; }
  .print-inputs li { break-inside: avoid; }
  .print-workings { columns: 2; column-gap: 14pt; }
  .print-working { break-inside: avoid; margin-bottom: 4pt; }
}
