@layer reset, base, components, layout, utilities;

@layer reset {
  *,
  *::before,
  *::after {
    box-sizing: border-box;
  }

  html {
    color-scheme: light;
    scroll-behavior: smooth;
    text-size-adjust: 100%;
  }

  body,
  h1,
  h2,
  h3,
  p,
  ul,
  ol,
  dl,
  dd,
  figure,
  blockquote {
    margin: 0;
  }

  body {
    min-width: 320px;
  }

  button,
  input,
  select,
  textarea {
    color: inherit;
    font: inherit;
  }

  button,
  select,
  input[type="radio"],
  input[type="checkbox"] {
    cursor: pointer;
  }

  img,
  svg {
    display: block;
    max-width: 100%;
  }

  fieldset {
    min-inline-size: 0;
    margin: 0;
    padding: 0;
    border: 0;
  }

  legend {
    padding: 0;
  }

  table {
    width: 100%;
    border-collapse: collapse;
  }

  a {
    color: inherit;
  }

  summary {
    cursor: pointer;
  }

  dialog {
    padding: 0;
  }
}

@layer base {
  :root {
    --paper: #f5f1e8;
    --paper-deep: #eee8dc;
    --surface: #fffdf7;
    --surface-muted: #f8f5ed;
    --ink: #17201b;
    --muted: #5d675f;
    --muted-strong: #414a43;
    --green: #214f3a;
    --green-dark: #163929;
    --green-soft: #e5eee8;
    --orange: #e7632f;
    --orange-dark: #ba4520;
    --orange-soft: #fbe7dc;
    --line: #c9cec7;
    --line-soft: #e2e4df;
    --warning: #9e3f2b;
    --warning-soft: #f9e8e2;
    --success: #2d6a4f;
    --focus: #0d68a6;
    --header-height: 68px;
    --control-width: minmax(410px, 42%);
    --content-width: 1180px;
    --radius-sm: 6px;
    --radius-md: 12px;
    --radius-lg: 20px;
    --font-sans: ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    --font-serif: Georgia, "Times New Roman", serif;
    --shadow-dialog: 0 28px 80px rgb(23 32 27 / 24%);
  }

  body {
    background: var(--paper);
    color: var(--ink);
    font-family: var(--font-sans);
    font-size: 16px;
    line-height: 1.55;
    -webkit-font-smoothing: antialiased;
  }

  body:has(dialog[open]) {
    overflow: hidden;
  }

  h1,
  h2,
  h3 {
    font-family: var(--font-serif);
    font-weight: 700;
    line-height: 1.08;
    text-wrap: balance;
  }

  h1 {
    max-width: 15ch;
    font-size: clamp(2.35rem, 3.3vw, 4.4rem);
    letter-spacing: -0.045em;
  }

  h2 {
    font-size: clamp(2rem, 3vw, 3.5rem);
    letter-spacing: -0.035em;
  }

  h3 {
    font-size: clamp(1.16rem, 1.6vw, 1.48rem);
    letter-spacing: -0.018em;
  }

  code {
    border: 1px solid var(--line-soft);
    border-radius: 5px;
    background: var(--surface-muted);
    color: var(--green-dark);
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
    font-size: 0.84em;
    padding: 0.14rem 0.34rem;
  }

  ::selection {
    background: var(--orange-soft);
    color: var(--ink);
  }

  :focus-visible {
    outline: 3px solid color-mix(in srgb, var(--focus) 72%, white);
    outline-offset: 3px;
  }

  input:focus-visible,
  select:focus-visible {
    outline-offset: 0;
  }

  input,
  select {
    min-height: 44px;
    width: 100%;
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    background: var(--surface);
    padding: 0.66rem 0.72rem;
    transition: border-color 150ms ease, box-shadow 150ms ease, background-color 150ms ease;
  }

  input:hover,
  select:hover {
    border-color: #9ba39c;
  }

  input:focus,
  select:focus {
    border-color: var(--focus);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--focus) 15%, transparent);
  }

  input[aria-invalid="true"],
  select[aria-invalid="true"] {
    border-color: var(--warning);
    background: var(--warning-soft);
  }

  input[type="checkbox"] {
    accent-color: var(--green);
    min-height: auto;
    width: 20px;
    height: 20px;
    margin: 0.15rem 0 0;
  }

  button {
    border: 0;
  }
}

@layer components {
  .skip-link {
    position: fixed;
    z-index: 9999;
    top: 8px;
    left: 8px;
    transform: translateY(-160%);
    border-radius: var(--radius-sm);
    background: var(--ink);
    color: white;
    font-weight: 700;
    padding: 0.7rem 1rem;
    text-decoration: none;
    transition: transform 150ms ease;
  }

  .skip-link:focus {
    transform: translateY(0);
  }

  .brand {
    display: inline-flex;
    align-items: center;
    min-width: 0;
    gap: 0.7rem;
    color: var(--ink);
    font-weight: 800;
    letter-spacing: -0.025em;
    text-decoration: none;
  }

  .brand-mark {
    flex: 0 0 auto;
    width: 38px;
    height: 38px;
  }

  .brand-mark rect {
    fill: var(--green);
  }

  .brand-mark path:not(.brand-gate) {
    fill: none;
    stroke: var(--surface);
    stroke-linecap: round;
    stroke-width: 4.7;
  }

  .brand-mark .brand-gate {
    fill: none;
    stroke: var(--orange);
    stroke-linecap: round;
    stroke-width: 3.4;
  }

  .button,
  .icon-button,
  .text-button,
  .remove-button,
  .footer-link,
  .dialog-close {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.48rem;
    min-height: 44px;
    border-radius: var(--radius-sm);
    font-weight: 750;
    line-height: 1;
    text-decoration: none;
    transition: background-color 150ms ease, border-color 150ms ease, color 150ms ease, transform 150ms ease;
  }

  .button svg,
  .icon-button svg,
  .text-button svg,
  .remove-button svg,
  .dialog-close svg {
    width: 19px;
    height: 19px;
    fill: none;
    stroke: currentColor;
    stroke-linecap: round;
    stroke-linejoin: round;
    stroke-width: 1.8;
  }

  .button:active,
  .icon-button:active,
  .text-button:active,
  .remove-button:active {
    transform: translateY(1px);
  }

  .button-secondary {
    border: 1px solid var(--line);
    background: var(--surface);
    color: var(--ink);
    padding: 0.7rem 0.9rem;
  }

  .button-secondary:hover {
    border-color: var(--green);
    background: var(--green-soft);
    color: var(--green-dark);
  }

  .button-quiet {
    border: 1px solid transparent;
    background: transparent;
    color: var(--muted-strong);
    padding: 0.65rem 0.75rem;
  }

  .button-quiet:hover {
    border-color: var(--line);
    background: var(--surface-muted);
    color: var(--ink);
  }

  .button-compact {
    min-height: 40px;
  }

  .text-button {
    min-height: 44px;
    background: transparent;
    color: var(--green);
    padding: 0.42rem 0.15rem;
  }

  .text-button:hover {
    color: var(--orange-dark);
  }

  .remove-button {
    width: 42px;
    min-width: 42px;
    min-height: 42px;
    border: 1px solid transparent;
    background: transparent;
    color: var(--muted);
  }

  .remove-button:hover {
    border-color: color-mix(in srgb, var(--warning) 28%, var(--line-soft));
    background: var(--warning-soft);
    color: var(--warning);
  }

  .icon-button {
    flex-direction: column;
    min-width: 56px;
    min-height: 53px;
    border: 1px solid var(--line-soft);
    background: var(--surface);
    color: var(--muted-strong);
    padding: 0.38rem 0.5rem;
    font-size: 0.72rem;
  }

  .icon-button:hover {
    border-color: var(--green);
    background: var(--green-soft);
    color: var(--green-dark);
  }

  .eyebrow,
  .section-kicker,
  .example-label {
    color: var(--green);
    font-size: 0.73rem;
    font-weight: 850;
    letter-spacing: 0.12em;
    line-height: 1.2;
    text-transform: uppercase;
  }

  .unit-toggle,
  .view-toggle {
    display: inline-grid;
    grid-auto-flow: column;
    gap: 2px;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: var(--paper-deep);
    padding: 3px;
  }

  .unit-toggle label,
  .view-toggle label {
    position: relative;
    display: block;
  }

  .unit-toggle input,
  .view-toggle input,
  .visual-options input {
    position: absolute;
    inline-size: 1px;
    block-size: 1px;
    opacity: 0;
    pointer-events: none;
  }

  .unit-toggle span,
  .view-toggle span {
    display: grid;
    min-height: 33px;
    place-items: center;
    border-radius: 999px;
    color: var(--muted-strong);
    font-size: 0.78rem;
    font-weight: 800;
    padding: 0.35rem 0.74rem;
  }

  .unit-toggle label:has(input:checked) span,
  .view-toggle label:has(input:checked) span {
    background: var(--surface);
    color: var(--green-dark);
  }

  .unit-toggle label:has(input:focus-visible) span,
  .view-toggle label:has(input:focus-visible) span,
  .visual-options label:has(input:focus-visible) {
    outline: 3px solid color-mix(in srgb, var(--focus) 72%, white);
    outline-offset: 2px;
  }

  .visual-options {
    display: grid;
    gap: 0.5rem;
  }

  .visual-options label {
    position: relative;
    display: grid;
    align-items: center;
    min-height: 64px;
    border: 1px solid var(--line);
    border-radius: var(--radius-md);
    background: var(--surface);
    color: var(--muted-strong);
    cursor: pointer;
    font-size: 0.82rem;
    font-weight: 750;
    line-height: 1.2;
    padding: 0.7rem 0.55rem;
    text-align: center;
    transition: border-color 150ms ease, background-color 150ms ease, color 150ms ease;
  }

  .visual-options label:hover {
    border-color: #929b93;
    background: var(--surface-muted);
    color: var(--ink);
  }

  .visual-options label:has(input:checked) {
    border-color: var(--green);
    background: var(--green-soft);
    color: var(--green-dark);
    box-shadow: inset 0 -3px 0 var(--green);
  }

  .layout-options {
    grid-template-columns: repeat(5, minmax(0, 1fr));
  }

  .option-glyph {
    font-family: var(--font-serif);
    font-size: 1.65rem;
    line-height: 0.75;
  }

  .fence-options {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .fence-swatch {
    position: relative;
    display: block;
    width: 42px;
    height: 25px;
    margin: 0 auto 0.35rem;
    border-bottom: 3px solid currentColor;
    color: var(--green);
  }

  .fence-swatch::before,
  .fence-swatch::after {
    position: absolute;
    content: "";
  }

  .fence-swatch::before {
    inset: 1px 1px 2px;
    background: repeating-linear-gradient(90deg, currentColor 0 3px, transparent 3px 7px);
    opacity: 0.78;
  }

  .swatch-panel::before,
  .swatch-vinyl::before,
  .swatch-custom::before {
    background: repeating-linear-gradient(90deg, currentColor 0 8px, transparent 8px 10px);
  }

  .swatch-picket::before {
    inset-block-start: 5px;
    background: repeating-linear-gradient(90deg, currentColor 0 3px, transparent 3px 9px);
  }

  .swatch-chain::before {
    inset: 2px 1px 4px;
    border: 1px solid currentColor;
    background-image: linear-gradient(45deg, transparent 44%, currentColor 45% 55%, transparent 56%), linear-gradient(-45deg, transparent 44%, currentColor 45% 55%, transparent 56%);
    background-position: 0 0, 4px 0;
    background-size: 8px 8px;
    opacity: 0.7;
  }

  .swatch-aluminum::before {
    background: repeating-linear-gradient(90deg, currentColor 0 2px, transparent 2px 8px);
  }

  .swatch-aluminum::after {
    top: 7px;
    right: 0;
    left: 0;
    border-top: 2px solid currentColor;
  }

  .field-grid {
    display: grid;
    gap: 0.75rem;
  }

  .two-columns {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .three-columns {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .field {
    display: grid;
    align-content: start;
    gap: 0.32rem;
    min-width: 0;
    color: var(--muted-strong);
    font-size: 0.78rem;
    font-weight: 750;
  }

  .field > span:first-child,
  .field > label:first-child {
    min-height: 1.2rem;
  }

  .field small,
  .field-message {
    color: var(--muted);
    font-size: 0.7rem;
    font-weight: 500;
    line-height: 1.35;
  }

  .field-message.is-error {
    color: var(--warning);
    font-weight: 700;
  }

  .input-with-unit {
    position: relative;
    display: block;
  }

  .input-with-unit input {
    padding-right: 3.2rem;
  }

  .input-with-unit > span:last-child {
    position: absolute;
    top: 50%;
    right: 0.72rem;
    transform: translateY(-50%);
    color: var(--muted);
    font-size: 0.74rem;
    font-weight: 800;
    pointer-events: none;
  }

  .check-row {
    display: flex;
    align-items: flex-start;
    gap: 0.7rem;
    border: 1px solid var(--line-soft);
    border-radius: var(--radius-sm);
    background: var(--surface-muted);
    padding: 0.76rem;
  }

  .check-row strong,
  .check-row small {
    display: block;
  }

  .check-row strong {
    font-size: 0.83rem;
  }

  .check-row small {
    margin-top: 0.1rem;
    color: var(--muted);
    font-size: 0.72rem;
    line-height: 1.4;
  }

  .run-editor,
  .gate-editor {
    display: grid;
    gap: 0.6rem;
  }

  .run-row,
  .gate-row {
    position: relative;
    display: grid;
    align-items: end;
    gap: 0.55rem;
    border-top: 1px solid var(--line-soft);
    padding-top: 0.75rem;
  }

  .run-row {
    grid-template-columns: minmax(0, 1fr) minmax(115px, 0.68fr) auto;
  }

  .run-row.has-direction {
    grid-template-columns: minmax(96px, 0.8fr) minmax(105px, 0.7fr) minmax(110px, 0.74fr) auto;
  }

  .run-row.is-mirrored {
    grid-template-columns: minmax(0, 1fr);
    border: 1px dashed var(--line);
    border-radius: var(--radius-sm);
    background: var(--surface-muted);
    padding: 0.68rem 0.75rem;
  }

  .run-name,
  .gate-name {
    display: flex;
    align-items: center;
    min-height: 44px;
    gap: 0.55rem;
    color: var(--ink);
    font-size: 0.84rem;
    font-weight: 800;
  }

  .run-badge,
  .gate-badge {
    display: grid;
    flex: 0 0 auto;
    width: 29px;
    height: 29px;
    place-items: center;
    border-radius: 50%;
    background: var(--green-soft);
    color: var(--green-dark);
    font-size: 0.72rem;
  }

  .gate-badge {
    background: var(--orange-soft);
    color: var(--orange-dark);
  }

  .run-mirror-note {
    color: var(--muted);
    font-size: 0.75rem;
  }

  .gate-row {
    grid-template-columns: minmax(105px, 0.75fr) minmax(90px, 0.65fr) minmax(110px, 0.78fr) auto;
    border: 1px solid var(--line-soft);
    border-radius: var(--radius-md);
    background: var(--surface-muted);
    padding: 0.75rem;
  }

  .gate-row.has-error {
    border-color: color-mix(in srgb, var(--warning) 50%, var(--line));
    background: var(--warning-soft);
  }

  .gate-row .gate-name {
    grid-column: 1 / -1;
    min-height: auto;
  }

  .gate-error {
    grid-column: 1 / -1;
    color: var(--warning);
    font-size: 0.72rem;
    font-weight: 700;
  }

  .row-remove-wrap {
    display: flex;
    align-items: end;
    min-height: 66px;
  }

  .empty-state {
    border: 1px dashed var(--line);
    border-radius: var(--radius-sm);
    background: var(--surface-muted);
    color: var(--muted);
    font-size: 0.78rem;
    line-height: 1.45;
    padding: 0.85rem;
  }

  .planner-disclosure,
  .estimate-details {
    border-top: 1px solid var(--line);
  }

  .planner-disclosure summary,
  .estimate-details summary {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    list-style: none;
    font-weight: 820;
  }

  .planner-disclosure summary::-webkit-details-marker,
  .estimate-details summary::-webkit-details-marker {
    display: none;
  }

  .planner-disclosure summary {
    min-height: 68px;
    padding: 0.8rem 2rem 0.8rem 0;
  }

  .planner-disclosure summary::after,
  .estimate-details summary::after {
    position: absolute;
    right: 0.2rem;
    content: "+";
    color: var(--green);
    font-family: var(--font-sans);
    font-size: 1.4rem;
    font-weight: 500;
    line-height: 1;
  }

  .planner-disclosure[open] summary::after,
  .estimate-details[open] summary::after {
    content: "−";
  }

  .planner-disclosure summary > span {
    display: flex;
    align-items: center;
    gap: 0.65rem;
  }

  .summary-number,
  .planner-section legend > span {
    display: grid;
    flex: 0 0 auto;
    width: 26px;
    height: 26px;
    place-items: center;
    border-radius: 50%;
    background: var(--green);
    color: white;
    font-family: var(--font-sans);
    font-size: 0.72rem;
    font-weight: 850;
  }

  .planner-disclosure summary small {
    max-width: 48%;
    color: var(--muted);
    font-size: 0.7rem;
    font-weight: 550;
    line-height: 1.35;
    text-align: right;
  }

  .disclosure-body {
    display: grid;
    gap: 0.9rem;
    padding: 0 0 1.25rem;
  }

  .inline-note {
    border-left: 3px solid var(--orange);
    color: var(--muted-strong);
    font-size: 0.74rem;
    line-height: 1.45;
    padding: 0.12rem 0 0.12rem 0.7rem;
  }

  .price-intro {
    display: flex;
    align-items: end;
    justify-content: space-between;
    gap: 1rem;
  }

  .price-intro p {
    max-width: 64ch;
    color: var(--muted);
    font-size: 0.75rem;
    line-height: 1.45;
  }

  .compact-field {
    min-width: 120px;
  }

  .view-toggle {
    border-radius: var(--radius-sm);
  }

  .view-toggle span {
    border-radius: 3px;
  }

  .warning-list {
    display: grid;
    gap: 0.45rem;
  }

  .warning-item {
    display: flex;
    align-items: flex-start;
    gap: 0.58rem;
    border-left: 3px solid var(--warning);
    background: var(--warning-soft);
    color: var(--warning);
    font-size: 0.75rem;
    font-weight: 680;
    line-height: 1.42;
    padding: 0.64rem 0.74rem;
  }

  .warning-item svg {
    flex: 0 0 auto;
    width: 17px;
    height: 17px;
    margin-top: 0.08rem;
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
  }

  .preview-paper {
    fill: var(--surface);
  }

  .preview-grid line {
    stroke: var(--line-soft);
    stroke-width: 1;
  }

  .fence-run {
    fill: none;
    stroke: var(--green);
    stroke-linecap: round;
    stroke-width: 13;
  }

  .gate-opening {
    fill: none;
    stroke: var(--orange);
    stroke-dasharray: 6 10;
    stroke-linecap: round;
    stroke-width: 12;
  }

  .gate-swing {
    fill: none;
    stroke: var(--orange);
    stroke-linecap: round;
    stroke-width: 3;
  }

  .closure-gap {
    fill: none;
    stroke: var(--warning);
    stroke-dasharray: 9 9;
    stroke-width: 4;
  }

  .post-node {
    fill: var(--surface);
    stroke: var(--green-dark);
    stroke-width: 4;
  }

  .post-gate {
    fill: var(--orange);
    stroke: var(--surface);
  }

  .post-terminal {
    fill: var(--green);
    stroke: var(--surface);
  }

  .dimension-label rect {
    fill: var(--surface);
    stroke: var(--line);
    stroke-width: 1.5;
  }

  .dimension-label text,
  .preview-legend text,
  .elevation-caption,
  .elevation-height text {
    fill: var(--muted-strong);
    font-family: var(--font-sans);
    font-size: 17px;
    font-weight: 700;
  }

  .preview-legend text {
    font-size: 15px;
  }

  .ground-line {
    stroke: var(--muted);
    stroke-width: 4;
  }

  .elevation-post {
    fill: var(--green-dark);
  }

  .elevation-panel,
  .elevation-board {
    fill: #9f7b4e;
    stroke: #785d3c;
    stroke-width: 1.5;
  }

  .elevation-panel:nth-child(even),
  .elevation-board:nth-child(even) {
    fill: #ad8858;
  }

  .elevation-rail {
    stroke: var(--green-dark);
    stroke-width: 8;
  }

  .chain-mesh {
    fill: url("#chain-pattern");
    stroke: var(--muted);
    stroke-width: 2;
  }

  .chain-pattern-line {
    fill: none;
    stroke: var(--muted);
    stroke-width: 1.6;
  }

  .elevation-gate {
    fill: color-mix(in srgb, var(--orange) 18%, var(--surface));
    stroke: var(--orange);
    stroke-width: 5;
  }

  .gate-brace {
    stroke: var(--orange);
    stroke-width: 4;
  }

  .elevation-height line {
    stroke: var(--orange-dark);
    stroke-width: 3;
  }

  .table-wrap {
    overflow-x: auto;
    overscroll-behavior-inline: contain;
  }

  th,
  td {
    border-bottom: 1px solid var(--line-soft);
    padding: 0.66rem 0.5rem;
    text-align: right;
    vertical-align: top;
  }

  th:first-child,
  td:first-child {
    padding-left: 0;
    text-align: left;
  }

  th:last-child,
  td:last-child {
    padding-right: 0;
  }

  th {
    color: var(--muted);
    font-size: 0.66rem;
    font-weight: 850;
    letter-spacing: 0.07em;
    text-transform: uppercase;
  }

  td {
    color: var(--muted-strong);
    font-size: 0.77rem;
    font-variant-numeric: tabular-nums;
  }

  td:first-child {
    color: var(--ink);
    font-weight: 750;
  }

  .row-note {
    display: block;
    max-width: 34ch;
    margin-top: 0.12rem;
    color: var(--muted);
    font-size: 0.66rem;
    font-weight: 500;
    line-height: 1.35;
  }

  .cost-breakdown {
    display: grid;
    gap: 0.38rem;
    max-width: 430px;
    margin: 1rem 0 0 auto;
  }

  .cost-breakdown > div {
    display: flex;
    justify-content: space-between;
    gap: 2rem;
    color: var(--muted-strong);
    font-size: 0.78rem;
    font-variant-numeric: tabular-nums;
  }

  .cost-breakdown dd {
    color: var(--ink);
    font-weight: 750;
  }

  .cost-breakdown .cost-total {
    align-items: baseline;
    border-top: 1px solid var(--line);
    margin-top: 0.35rem;
    padding-top: 0.6rem;
    color: var(--ink);
    font-weight: 850;
  }

  .cost-breakdown .cost-total dd {
    color: var(--orange-dark);
    font-family: var(--font-serif);
    font-size: 1.25rem;
  }

  .assumptions-details ul {
    display: grid;
    gap: 0.42rem;
    margin: 0;
    padding: 0 0 0 1.1rem;
    color: var(--muted-strong);
    font-size: 0.75rem;
  }

  .formula-note {
    margin-top: 0.9rem;
    border-left: 3px solid var(--green);
    background: var(--surface-muted);
    color: var(--muted-strong);
    font-size: 0.73rem;
    line-height: 1.5;
    padding: 0.72rem 0.8rem;
  }

  .question-list details {
    border-top: 1px solid var(--line);
  }

  .question-list details:last-child {
    border-bottom: 1px solid var(--line);
  }

  .question-list summary {
    position: relative;
    list-style: none;
    padding: 1.15rem 2.2rem 1.15rem 0;
    font-family: var(--font-serif);
    font-size: 1.08rem;
    font-weight: 700;
  }

  .question-list summary::-webkit-details-marker {
    display: none;
  }

  .question-list summary::after {
    position: absolute;
    right: 0.15rem;
    content: "+";
    color: var(--green);
    font-family: var(--font-sans);
    font-size: 1.35rem;
    font-weight: 500;
  }

  .question-list details[open] summary::after {
    content: "−";
  }

  .question-list details p {
    max-width: 78ch;
    padding: 0 3rem 1.15rem 0;
    color: var(--muted-strong);
  }

  .legal-dialog {
    width: min(720px, calc(100vw - 2rem));
    max-height: min(84vh, 820px);
    margin: auto;
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    background: var(--surface);
    box-shadow: var(--shadow-dialog);
    color: var(--ink);
  }

  .legal-dialog::backdrop {
    background: rgb(23 32 27 / 58%);
    backdrop-filter: blur(3px);
  }

  .dialog-head {
    position: sticky;
    z-index: 2;
    top: 0;
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1rem;
    border-bottom: 1px solid var(--line-soft);
    background: var(--surface);
    padding: 1.25rem 1.35rem;
  }

  .dialog-head h2 {
    margin-top: 0.25rem;
    font-size: 2rem;
  }

  .dialog-close {
    width: 44px;
    min-width: 44px;
    background: var(--surface-muted);
    color: var(--muted-strong);
  }

  .dialog-close:hover {
    background: var(--warning-soft);
    color: var(--warning);
  }

  .dialog-content {
    display: grid;
    gap: 1.2rem;
    overflow-y: auto;
    max-height: calc(min(84vh, 820px) - 95px);
    padding: 1.35rem;
  }

  .dialog-content section {
    display: grid;
    gap: 0.35rem;
  }

  .dialog-content h3 {
    font-size: 1.15rem;
  }

  .dialog-content p {
    color: var(--muted-strong);
    font-size: 0.86rem;
  }

  .dialog-content a {
    color: var(--green);
    font-weight: 750;
  }

  .toast {
    position: fixed;
    z-index: 1000;
    right: 1rem;
    bottom: 1rem;
    max-width: min(370px, calc(100vw - 2rem));
    transform: translateY(calc(100% + 2rem));
    border-radius: var(--radius-sm);
    background: var(--ink);
    color: white;
    font-size: 0.8rem;
    font-weight: 700;
    opacity: 0;
    padding: 0.78rem 0.95rem;
    pointer-events: none;
    transition: transform 180ms ease, opacity 180ms ease;
  }

  .toast[data-visible="true"] {
    transform: translateY(0);
    opacity: 1;
  }

  .mobile-result-bar {
    display: none;
  }

  .noscript-banner {
    position: fixed;
    z-index: 9999;
    right: 0;
    bottom: 0;
    left: 0;
    border-top: 3px solid var(--warning);
    background: var(--warning-soft);
    color: var(--warning);
    font-weight: 750;
    padding: 0.9rem 1rem;
    text-align: center;
  }
}

@layer layout {
  .site-header {
    position: sticky;
    z-index: 100;
    top: 0;
    display: grid;
    grid-template-columns: minmax(180px, 1fr) auto minmax(180px, 1fr);
    align-items: center;
    min-height: var(--header-height);
    border-bottom: 1px solid var(--line);
    background: color-mix(in srgb, var(--paper) 94%, transparent);
    padding: 0.7rem clamp(0.9rem, 2.4vw, 2rem);
    backdrop-filter: blur(14px);
  }

  .header-trust {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.45rem;
    color: var(--muted);
    font-size: 0.72rem;
    font-weight: 720;
  }

  .header-trust span {
    color: var(--success);
    font-size: 0.6rem;
  }

  .header-actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 0.65rem;
  }

  .calculator-shell {
    display: grid;
    grid-template-columns: var(--control-width) minmax(0, 1fr);
    height: calc(100svh - var(--header-height));
    min-height: 700px;
    border-bottom: 1px solid var(--line);
    background: var(--surface);
  }

  .control-panel,
  .result-stage {
    min-width: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
    scrollbar-color: var(--line) transparent;
    scrollbar-width: thin;
  }

  .control-panel {
    border-right: 1px solid var(--line);
    background: var(--paper);
    padding: clamp(1.25rem, 2.4vw, 2.2rem);
  }

  .calculator-intro {
    display: grid;
    gap: 0.75rem;
    max-width: 660px;
    margin-bottom: 1.75rem;
  }

  .calculator-intro > p:last-child {
    max-width: 62ch;
    color: var(--muted-strong);
    font-size: 0.9rem;
  }

  #calculator-form {
    display: grid;
    gap: 0;
    max-width: 730px;
  }

  .planner-section {
    display: grid;
    gap: 0.9rem;
    border-top: 1px solid var(--line);
    padding: 1.25rem 0;
  }

  .planner-section > legend {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    color: var(--ink);
    font-family: var(--font-serif);
    font-size: 1.17rem;
    font-weight: 700;
  }

  .section-heading-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
  }

  .section-help {
    max-width: 62ch;
    color: var(--muted);
    font-size: 0.75rem;
    line-height: 1.45;
  }

  .system-fields-wrap {
    display: grid;
    gap: 0.75rem;
    border-top: 1px dashed var(--line);
    padding-top: 0.85rem;
  }

  .system-summary-note {
    display: flex;
    align-items: flex-start;
    gap: 0.55rem;
    border-radius: var(--radius-sm);
    background: var(--green-soft);
    color: var(--green-dark);
    font-size: 0.74rem;
    line-height: 1.45;
    padding: 0.7rem 0.75rem;
  }

  .system-summary-note svg {
    flex: 0 0 auto;
    width: 18px;
    height: 18px;
    margin-top: 0.08rem;
    fill: none;
    stroke: currentColor;
    stroke-linecap: round;
    stroke-linejoin: round;
    stroke-width: 2;
  }

  .form-footer-actions {
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-top: 1px solid var(--line);
    color: var(--muted);
    font-size: 0.7rem;
    padding: 1rem 0 2.5rem;
  }

  .result-stage {
    display: grid;
    align-content: start;
    gap: 1rem;
    background: var(--surface);
    padding: clamp(1rem, 2vw, 1.8rem) clamp(1rem, 2.4vw, 2.25rem) 2.4rem;
  }

  .stage-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
  }

  .stage-toolbar p {
    color: var(--muted);
    font-size: 0.7rem;
    text-align: right;
  }

  .preview-frame {
    position: relative;
    overflow: hidden;
    min-height: 300px;
    border: 1px solid var(--line);
    border-radius: var(--radius-md);
    background: var(--surface);
    aspect-ratio: 1000 / 620;
  }

  .preview-frame::after {
    position: absolute;
    inset: 10px;
    border: 1px solid color-mix(in srgb, var(--line) 65%, transparent);
    border-radius: 7px;
    content: "";
    pointer-events: none;
  }

  #fence-preview {
    width: 100%;
    height: 100%;
  }

  .estimate-head {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 1rem;
    border-top: 1px solid var(--line);
    padding-top: 1rem;
  }

  .estimate-head h2 {
    margin-top: 0.08rem;
    color: var(--orange-dark);
    font-size: clamp(2.35rem, 4vw, 4.9rem);
    font-variant-numeric: tabular-nums;
    line-height: 0.95;
  }

  .estimate-head > div > p:last-child {
    margin-top: 0.42rem;
    color: var(--muted);
    font-size: 0.72rem;
  }

  .estimate-actions {
    display: flex;
    gap: 0.45rem;
  }

  .key-metrics {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    border-top: 1px solid var(--line);
    border-bottom: 1px solid var(--line);
  }

  .key-metrics > div {
    min-width: 0;
    padding: 0.85rem 0.75rem;
  }

  .key-metrics > div + div {
    border-left: 1px solid var(--line-soft);
  }

  .key-metrics span,
  .key-metrics strong,
  .key-metrics small {
    display: block;
  }

  .key-metrics span {
    color: var(--muted);
    font-size: 0.65rem;
    font-weight: 800;
    letter-spacing: 0.045em;
    text-transform: uppercase;
  }

  .key-metrics strong {
    overflow: hidden;
    margin-top: 0.22rem;
    color: var(--ink);
    font-family: var(--font-serif);
    font-size: clamp(1.22rem, 2vw, 1.72rem);
    font-variant-numeric: tabular-nums;
    line-height: 1.1;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .key-metrics small {
    overflow: hidden;
    margin-top: 0.2rem;
    color: var(--muted);
    font-size: 0.65rem;
    line-height: 1.35;
    text-overflow: ellipsis;
  }

  .estimate-details {
    padding: 0 0 0.9rem;
  }

  .estimate-details summary {
    min-height: 52px;
    padding: 0.75rem 2rem 0.75rem 0;
    font-size: 0.84rem;
  }

  .trust-band {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    border-bottom: 1px solid var(--line);
    background: var(--green);
    color: var(--surface);
  }

  .trust-band p {
    padding: 1.1rem clamp(1rem, 2.8vw, 2.4rem);
    font-size: 0.78rem;
    line-height: 1.45;
  }

  .trust-band p + p {
    border-left: 1px solid rgb(255 255 255 / 22%);
  }

  .trust-band strong {
    color: white;
  }

  .content-section {
    width: min(var(--content-width), calc(100% - 2rem));
    margin-inline: auto;
    border-bottom: 1px solid var(--line);
    padding-block: clamp(4rem, 8vw, 7rem);
  }

  .content-section > .section-kicker + h2,
  .content-section > div > .section-kicker + h2 {
    max-width: 18ch;
    margin-top: 0.75rem;
  }

  .section-lead {
    max-width: 66ch;
    margin-top: 1.15rem;
    color: var(--muted-strong);
    font-size: clamp(1rem, 1.4vw, 1.22rem);
  }

  .formula-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0;
    margin-top: 3rem;
    border-top: 1px solid var(--line);
    border-bottom: 1px solid var(--line);
  }

  .formula-grid article {
    min-width: 0;
    padding: 1.5rem clamp(1rem, 2.2vw, 1.8rem) 1.65rem;
  }

  .formula-grid article + article {
    border-left: 1px solid var(--line);
  }

  .formula-index {
    color: var(--orange-dark);
    font-size: 0.7rem;
    font-weight: 850;
    letter-spacing: 0.1em;
  }

  .formula-grid h3 {
    margin-top: 1.1rem;
  }

  .formula-grid p {
    margin-top: 0.75rem;
    color: var(--muted-strong);
    font-size: 0.84rem;
  }

  .example-list {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0;
    margin-top: 3rem;
    border-top: 1px solid var(--line);
  }

  .example-list article {
    padding: 1.5rem clamp(1rem, 2vw, 1.7rem) 1.7rem;
  }

  .example-list article + article {
    border-left: 1px solid var(--line);
  }

  .example-list h3 {
    margin-top: 0.6rem;
  }

  .example-list article > p:last-child {
    margin-top: 0.75rem;
    color: var(--muted-strong);
    font-size: 0.84rem;
  }

  .planning-grid,
  .sources {
    display: grid;
    grid-template-columns: minmax(220px, 0.7fr) minmax(0, 1.3fr);
    gap: clamp(2rem, 7vw, 7rem);
  }

  .planning-checklist {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    border-top: 1px solid var(--line);
  }

  .planning-checklist article {
    min-width: 0;
    padding: 1.2rem 1.2rem 1.35rem 0;
    border-bottom: 1px solid var(--line);
  }

  .planning-checklist article:nth-child(even) {
    border-left: 1px solid var(--line);
    padding-left: 1.2rem;
  }

  .planning-checklist p {
    margin-top: 0.6rem;
    color: var(--muted-strong);
    font-size: 0.82rem;
  }

  .planning-checklist .safe-dig-callout {
    background: var(--orange-soft);
    padding-right: 1.2rem;
  }

  .safe-dig-callout a {
    display: inline-block;
    margin-top: 0.85rem;
    color: var(--orange-dark);
    font-size: 0.78rem;
    font-weight: 850;
  }

  .questions h2 {
    margin-top: 0.75rem;
  }

  .question-list {
    max-width: 900px;
    margin-top: 2.8rem;
  }

  .sources > div:last-child {
    color: var(--muted-strong);
  }

  .sources ul {
    display: grid;
    gap: 0.5rem;
    margin: 1rem 0 0;
    padding: 0;
    list-style: none;
  }

  .sources a {
    color: var(--green);
    font-weight: 760;
    text-underline-offset: 0.2em;
  }

  .review-date {
    margin-top: 1.25rem;
    color: var(--muted);
    font-size: 0.72rem;
  }

  .site-footer {
    display: grid;
    grid-template-columns: minmax(180px, 1fr) minmax(220px, 2fr) auto auto;
    align-items: center;
    gap: 1.2rem;
    background: var(--ink);
    color: #e9eee9;
    padding: 2rem clamp(1rem, 3vw, 2.5rem);
  }

  .footer-brand {
    color: white;
  }

  .site-footer > p {
    color: #b8c1ba;
    font-size: 0.73rem;
  }

  .footer-link {
    min-height: 40px;
    background: transparent;
    color: white;
    padding: 0.45rem;
    text-decoration: underline;
    text-underline-offset: 0.2em;
  }

  .footer-link:hover {
    color: #ffae8b;
  }
}

@layer utilities {
  [hidden] {
    display: none !important;
  }

  .sr-only {
    position: absolute !important;
    overflow: hidden !important;
    width: 1px !important;
    height: 1px !important;
    margin: -1px !important;
    padding: 0 !important;
    border: 0 !important;
    clip: rect(0 0 0 0) !important;
    clip-path: inset(50%) !important;
    white-space: nowrap !important;
  }
}

@media (max-width: 1220px) {
  :root {
    --control-width: minmax(390px, 45%);
  }

  .header-trust {
    display: none;
  }

  .site-header {
    grid-template-columns: minmax(180px, 1fr) auto;
  }

  .fence-options {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .price-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .key-metrics {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .key-metrics > div:nth-child(3) {
    border-left: 0;
    border-top: 1px solid var(--line-soft);
  }

  .key-metrics > div:nth-child(4) {
    border-top: 1px solid var(--line-soft);
  }
}

@media (max-width: 980px) {
  :root {
    --header-height: 64px;
  }

  html {
    scroll-padding-top: calc(var(--header-height) + 10px);
  }

  body {
    padding-bottom: calc(76px + env(safe-area-inset-bottom));
  }

  .calculator-shell {
    display: block;
    height: auto;
    min-height: 0;
  }

  .control-panel,
  .result-stage {
    overflow: visible;
  }

  .control-panel {
    border-right: 0;
    border-bottom: 1px solid var(--line);
    padding: clamp(1.1rem, 4vw, 2.5rem);
  }

  .result-stage {
    padding: clamp(1.1rem, 4vw, 2.5rem);
  }

  #calculator-form,
  .calculator-intro {
    max-width: 820px;
    margin-inline: auto;
  }

  .calculator-intro {
    margin-bottom: 1.8rem;
  }

  .result-stage > * {
    width: min(820px, 100%);
    margin-inline: auto;
  }

  .mobile-result-bar {
    position: fixed;
    z-index: 90;
    right: 0.75rem;
    bottom: max(0.75rem, env(safe-area-inset-bottom));
    left: 0.75rem;
    display: grid;
    grid-template-columns: 1fr 0.8fr auto;
    align-items: center;
    min-height: 64px;
    border: 1px solid rgb(255 255 255 / 18%);
    border-radius: 14px;
    background: var(--ink);
    box-shadow: 0 12px 30px rgb(23 32 27 / 24%);
    color: white;
    padding: 0.56rem 0.7rem 0.56rem 0.85rem;
    text-align: left;
  }

  .mobile-result-bar span {
    display: block;
    min-width: 0;
  }

  .mobile-result-bar small,
  .mobile-result-bar strong {
    display: block;
  }

  .mobile-result-bar small {
    color: #b9c4bc;
    font-size: 0.6rem;
    font-weight: 750;
    letter-spacing: 0.04em;
    text-transform: uppercase;
  }

  .mobile-result-bar strong {
    overflow: hidden;
    margin-top: 0.06rem;
    font-family: var(--font-serif);
    font-size: 1.05rem;
    font-variant-numeric: tabular-nums;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .mobile-result-action {
    border-left: 1px solid rgb(255 255 255 / 18%);
    color: #ffd2bd;
    font-size: 0.7rem;
    font-weight: 800;
    padding-left: 0.8rem;
  }

  .toast {
    right: 0.75rem;
    bottom: calc(86px + env(safe-area-inset-bottom));
    left: 0.75rem;
    max-width: none;
  }
}

@media (max-width: 760px) {
  .site-header {
    gap: 0.6rem;
    padding-inline: 0.75rem;
  }

  .brand {
    gap: 0.48rem;
    font-size: 0.9rem;
  }

  .brand-mark {
    width: 34px;
    height: 34px;
  }

  .header-actions {
    gap: 0.35rem;
  }

  .button-compact {
    min-width: 40px;
    width: 40px;
    padding: 0;
  }

  .button-compact span {
    position: absolute;
    overflow: hidden;
    width: 1px;
    height: 1px;
    clip: rect(0 0 0 0);
  }

  h1 {
    font-size: clamp(2.25rem, 12vw, 3.6rem);
  }

  .layout-options {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .fence-options {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .two-columns,
  .three-columns,
  .price-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .gate-row {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .gate-row .row-remove-wrap {
    position: absolute;
    top: 0.5rem;
    right: 0.5rem;
    min-height: 42px;
  }

  .gate-row .gate-name {
    padding-right: 2.8rem;
  }

  .price-intro {
    display: grid;
  }

  .compact-field {
    max-width: 180px;
  }

  .estimate-head {
    align-items: flex-start;
  }

  .estimate-head h2 {
    font-size: clamp(2.5rem, 13vw, 4rem);
  }

  .estimate-actions {
    gap: 0.25rem;
  }

  .icon-button {
    min-width: 48px;
  }

  .formula-grid,
  .example-list,
  .planning-grid,
  .sources {
    grid-template-columns: 1fr;
  }

  .formula-grid article + article,
  .example-list article + article {
    border-top: 1px solid var(--line);
    border-left: 0;
  }

  .planning-grid,
  .sources {
    gap: 2.4rem;
  }

  .site-footer {
    grid-template-columns: 1fr auto;
  }

  .site-footer > p:nth-of-type(1) {
    grid-column: 1 / -1;
  }
}

@media (max-width: 520px) {
  :root {
    --header-height: 60px;
  }

  .site-header {
    grid-template-columns: minmax(0, 1fr) auto;
  }

  .brand > span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .unit-toggle span {
    min-height: 31px;
    padding-inline: 0.56rem;
  }

  .control-panel,
  .result-stage {
    padding-inline: 0.9rem;
  }

  .calculator-intro > p:last-child {
    font-size: 0.84rem;
  }

  .planner-section {
    padding-block: 1.1rem;
  }

  .layout-options,
  .fence-options {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .visual-options label {
    min-height: 58px;
  }

  .two-columns,
  .three-columns,
  .price-grid {
    grid-template-columns: 1fr;
  }

  .run-row,
  .run-row.has-direction {
    grid-template-columns: minmax(0, 1fr) minmax(105px, 0.7fr);
  }

  .run-row.has-direction .field:nth-of-type(2) {
    grid-column: 1 / -1;
  }

  .run-row .row-remove-wrap {
    grid-column: 1 / -1;
    min-height: 0;
  }

  .gate-row {
    grid-template-columns: 1fr;
  }

  .section-heading-row {
    align-items: flex-start;
  }

  .section-heading-row .text-button {
    flex: 0 0 auto;
  }

  .planner-disclosure summary {
    align-items: flex-start;
  }

  .planner-disclosure summary small {
    display: none;
  }

  .stage-toolbar {
    align-items: flex-start;
  }

  .stage-toolbar p {
    max-width: 18ch;
    font-size: 0.64rem;
  }

  .preview-frame {
    min-height: 250px;
    aspect-ratio: 4 / 3;
  }

  .estimate-head {
    display: grid;
  }

  .estimate-actions {
    justify-content: stretch;
  }

  .icon-button {
    flex: 1 1 0;
    flex-direction: row;
  }

  .key-metrics {
    grid-template-columns: 1fr 1fr;
  }

  .key-metrics > div {
    padding-inline: 0.55rem;
  }

  th:nth-child(3),
  td:nth-child(3) {
    display: none;
  }

  .planning-checklist {
    grid-template-columns: 1fr;
  }

  .planning-checklist article:nth-child(even) {
    border-left: 0;
    padding-left: 0;
  }

  .planning-checklist .safe-dig-callout {
    margin-inline: -0.9rem;
    padding-inline: 0.9rem;
  }

  .content-section {
    width: calc(100% - 1.8rem);
  }

  .question-list details p {
    padding-right: 0;
  }

  .site-footer {
    grid-template-columns: 1fr;
    text-align: left;
  }

  .footer-link {
    justify-content: flex-start;
    padding-left: 0;
  }

  .mobile-result-bar {
    grid-template-columns: 1fr 0.7fr auto;
  }

  .mobile-result-action {
    max-width: 72px;
    line-height: 1.25;
  }
}

@media (max-width: 360px) {
  .brand > span {
    max-width: 112px;
  }

  .unit-toggle span {
    padding-inline: 0.46rem;
  }

  .button-compact {
    display: none;
  }

  .mobile-result-bar {
    grid-template-columns: 1fr 0.72fr;
  }

  .mobile-result-action {
    display: none !important;
  }
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }

  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
  }
}

@media print {
  @page {
    size: auto;
    margin: 12mm;
  }

  :root {
    --paper: white;
    --surface: white;
  }

  body {
    padding: 0;
    background: white;
    color: black;
    font-size: 10pt;
  }

  .site-header,
  .control-panel,
  .trust-band,
  .content-section,
  .site-footer,
  .mobile-result-bar,
  .toast,
  .stage-toolbar,
  .estimate-actions,
  .warning-list:empty,
  .legal-dialog {
    display: none !important;
  }

  .calculator-shell {
    display: block;
    height: auto;
    min-height: 0;
    border: 0;
  }

  .result-stage {
    display: block;
    overflow: visible;
    padding: 0;
  }

  .result-stage > * {
    break-inside: avoid;
    margin-bottom: 8mm;
  }

  .preview-frame {
    max-height: 115mm;
    border-color: #777;
    border-radius: 0;
    aspect-ratio: 1000 / 620;
  }

  .preview-frame::after {
    display: none;
  }

  .estimate-head {
    border-color: #777;
  }

  .estimate-head h2 {
    color: black;
    font-size: 30pt;
  }

  .key-metrics,
  .key-metrics > div,
  .estimate-details,
  th,
  td {
    border-color: #aaa;
  }

  .estimate-details {
    display: block;
  }

  .estimate-details > summary {
    list-style: none;
  }

  .estimate-details > summary::after {
    display: none;
  }

  .estimate-details:not([open]) > :not(summary) {
    display: block;
  }

  .cost-breakdown .cost-total dd,
  .warning-item {
    color: black;
  }

  a {
    text-decoration: none;
  }
}
