/* Backyard Court Math. Mobile first, no framework. */

:root {
  --bg: #f6f8f4;
  --surface: #ffffff;
  --surface-2: #ebf0e8;
  --text: #19221e;
  --muted: #44514a;
  --border: #c3ccc3;
  --input-border: #6a756d;
  --accent: #0b5c47;
  --accent-text: #ffffff;
  --accent-soft: #dcefe5;
  --focus: #1a4fd8;
  --ok: #0b6b2e;
  --ok-bg: #e1f3e6;
  --bad: #a3231b;
  --bad-bg: #fbe7e5;
  --warn: #6d4a00;
  --warn-bg: #fff2cc;
  --radius: 10px;
  --gutter: 16px;
  --max: 72rem;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;

  /* Canvas colors, read by assets/draw.js on every redraw */
  --cv-yard-bg: #eef2e9;
  --cv-yard-line: #44514a;
  --cv-runoff: #cfe5d7;
  --cv-runoff-line: #2d6a4f;
  --cv-court: #1f6f50;
  --cv-kitchen: #17553d;
  --cv-court-line: #ffffff;
  --cv-net: #ffd966;
  --cv-net-outline: #19221e;
  --cv-obstacle: #d9d3c5;
  --cv-obstacle-line: #5c5546;
  --cv-obstacle-text: #241f17;
  --cv-text: #19221e;
  --cv-text-on-runoff: #0f2a1e;
  --cv-text-on-court: #ffffff;
  --cv-dim-line: #44514a;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111613;
    --surface: #1a211d;
    --surface-2: #232c27;
    --text: #e8eee9;
    --muted: #b3c0b8;
    --border: #3a4740;
    --input-border: #7f8c84;
    --accent: #6fd3ae;
    --accent-text: #08231a;
    --accent-soft: #1d3a2f;
    --focus: #8fb2ff;
    --ok: #7fe0a1;
    --ok-bg: #173523;
    --bad: #ff9d94;
    --bad-bg: #3d1b18;
    --warn: #ffd978;
    --warn-bg: #3a2f10;

    --cv-yard-bg: #1a211d;
    --cv-yard-line: #b3c0b8;
    --cv-runoff: #6aa88d;
    --cv-runoff-line: #9fd6bb;
    --cv-court: #14503a;
    --cv-kitchen: #0e3a2a;
    --cv-court-line: #ffffff;
    --cv-net: #ffd966;
    --cv-net-outline: #0b0f0d;
    --cv-obstacle: #4a463b;
    --cv-obstacle-line: #cfc8b6;
    --cv-obstacle-text: #f4f0e4;
    --cv-text: #e8eee9;
    --cv-text-on-runoff: #08140e;
    --cv-text-on-court: #ffffff;
    --cv-dim-line: #b3c0b8;
  }
}

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

[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; color-scheme: light dark; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 1rem/1.6 var(--font);
}

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

a { color: var(--accent); text-underline-offset: 0.15em; }
a:hover { text-decoration-thickness: 2px; }

:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
  border-radius: 3px;
}

.visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px;
  margin: -1px; padding: 0; border: 0;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap;
}

.skip-link {
  position: absolute;
  left: var(--gutter);
  top: -4rem;
  background: var(--accent);
  color: var(--accent-text);
  padding: 0.6rem 1rem;
  border-radius: var(--radius);
  z-index: 10;
}
.skip-link:focus { top: var(--gutter); }

.wrap { max-width: var(--max); margin: 0 auto; padding: 0 var(--gutter); }

/* Header and footer */
.site-header { background: var(--surface); border-bottom: 1px solid var(--border); }
.site-header .wrap { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 0.5rem 1.5rem; padding-top: 0.75rem; padding-bottom: 0.75rem; }
.brand { font-weight: 700; font-size: 1.15rem; color: var(--text); text-decoration: none; }
.site-header nav ul { list-style: none; display: flex; flex-wrap: wrap; gap: 0.25rem 1.25rem; margin: 0; padding: 0; }

.breadcrumb { font-size: 0.9rem; color: var(--muted); padding: 0.75rem 0 0; }
.breadcrumb ol { list-style: none; display: flex; flex-wrap: wrap; gap: 0.4rem; margin: 0; padding: 0; }
.breadcrumb li + li::before { content: "/"; margin-right: 0.4rem; color: var(--muted); }

.site-footer { margin-top: 3rem; padding: 2rem 0 3rem; background: var(--surface); border-top: 1px solid var(--border); font-size: 0.95rem; }
.site-footer p { margin: 0 0 0.75rem; max-width: 60rem; }
.site-footer ul { list-style: none; display: flex; flex-wrap: wrap; gap: 1.25rem; margin: 0 0 1rem; padding: 0; }

/* Typography */
h1 { font-size: 1.75rem; line-height: 1.2; margin: 1rem 0 0.75rem; }
h2 { font-size: 1.4rem; line-height: 1.25; margin: 2rem 0 0.75rem; }
h3 { font-size: 1.1rem; margin: 1.25rem 0 0.5rem; }
p, ul, ol { margin: 0 0 1rem; }
.lede { font-size: 1.1rem; color: var(--muted); max-width: 46rem; }
.meta-line { color: var(--muted); font-size: 0.9rem; }

/* Cards and notices */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem; }
.notice { border: 1px solid var(--border); border-left-width: 6px; border-radius: var(--radius); background: var(--surface); padding: 0.75rem 1rem; margin: 1rem 0; }
.notice strong:first-child { display: inline-block; margin-right: 0.35rem; }
.notice-warn { border-color: var(--warn); background: var(--warn-bg); color: var(--warn); }
.notice-error { border-color: var(--bad); background: var(--bad-bg); color: var(--bad); }
.notice-ok { border-color: var(--ok); background: var(--ok-bg); color: var(--ok); }
.notice-info { border-color: var(--accent); background: var(--accent-soft); color: var(--text); }
.notice-warn a, .notice-error a, .notice-ok a { color: inherit; }
.notice ul { margin: 0.5rem 0 0; padding-left: 1.25rem; }
.notice p:last-child { margin-bottom: 0; }

/* Tool layout */
.tool { display: grid; gap: 1.5rem; }
@media (min-width: 62rem) {
  .tool { grid-template-columns: minmax(0, 24rem) minmax(0, 1fr); align-items: start; }
  .results-col { position: sticky; top: 1rem; }
}

fieldset { border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); margin: 0 0 1rem; padding: 0.75rem 1rem 1rem; min-width: 0; }
legend { font-weight: 700; padding: 0 0.4rem; }
.hint { color: var(--muted); font-size: 0.9rem; margin: 0.25rem 0 0.5rem; }

label { display: inline-block; }
.field { display: flex; flex-direction: column; gap: 0.25rem; min-width: 0; }
.field > label { font-size: 0.9rem; font-weight: 600; }
.field-row { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.75rem; margin-bottom: 0.5rem; }

input[type="number"], input[type="text"], select {
  font: inherit;
  color: var(--text);
  background: var(--bg);
  border: 2px solid var(--input-border);
  border-radius: 8px;
  padding: 0.5rem 0.6rem;
  min-height: 2.75rem;
  width: 100%;
  min-width: 0;
}
input[aria-invalid="true"] { border-color: var(--bad); background: var(--bad-bg); }

button, .btn {
  font: inherit;
  font-weight: 700;
  display: inline-block;
  min-height: 2.75rem;
  padding: 0.6rem 1.1rem;
  border-radius: 8px;
  border: 2px solid var(--accent);
  background: var(--accent);
  color: var(--accent-text);
  text-decoration: none;
  cursor: pointer;
  text-align: center;
}
button.secondary, .btn.secondary { background: var(--surface); color: var(--accent); }
button:hover:not(:disabled), .btn:hover { filter: brightness(1.08); }
button:disabled { opacity: 0.55; cursor: not-allowed; }
button.link { background: none; border: 0; color: var(--accent); text-decoration: underline; padding: 0 0.25rem; min-height: 2.75rem; font-weight: 600; }

/* Obstacles */
.obstacle-list { list-style: none; margin: 0 0 0.75rem; padding: 0; display: grid; gap: 0.75rem; }
.obstacle { border: 1px dashed var(--border); border-radius: var(--radius); padding: 0.6rem 0.75rem 0.75rem; }
.obstacle-head { display: flex; justify-content: space-between; align-items: center; gap: 0.5rem; margin-bottom: 0.4rem; }
.obstacle-head strong { font-size: 0.95rem; }
.obstacle .field-row { margin-bottom: 0; }
.obstacle .field-row + .field-row { margin-top: 0.5rem; }
.obstacle .field.wide { grid-column: 1 / -1; }

/* Results */
.results-col h2 { margin-top: 0; }
.result-status { margin: 0 0 1rem; }
.result-status .big { display: block; font-size: 1.5rem; font-weight: 800; line-height: 1.2; }
.result-status .sub { display: block; margin-top: 0.25rem; }
.runoff-stats { display: grid; gap: 0.75rem; grid-template-columns: repeat(2, minmax(0, 1fr)); margin: 0 0 1rem; }
.stat { background: var(--accent-soft); border: 2px solid var(--accent); border-radius: var(--radius); padding: 0.6rem 0.9rem; }
.stat .label { display: block; font-weight: 700; font-size: 0.9rem; }
.stat .value { display: block; font-size: 2rem; line-height: 1.1; font-weight: 800; color: var(--text); font-variant-numeric: tabular-nums; }
.stat .unit { font-size: 1rem; font-weight: 700; margin-left: 0.25rem; }
.stat .sub { display: block; font-size: 0.85rem; color: var(--muted); }

.canvas-wrap { margin: 0 0 1rem; }
.canvas-wrap canvas { display: block; max-width: 100%; margin: 0 auto; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.canvas-wrap figcaption { font-size: 0.9rem; color: var(--muted); margin-top: 0.4rem; }
.legend { list-style: none; display: flex; flex-wrap: wrap; gap: 0.25rem 1rem; margin: 0.4rem 0 0; padding: 0; font-size: 0.85rem; color: var(--muted); }
.legend .swatch { display: inline-block; width: 0.9rem; height: 0.9rem; border: 1px solid var(--muted); margin-right: 0.35rem; vertical-align: -0.1em; }
.sw-yard { background: var(--cv-yard-bg); }
.sw-runoff { background: var(--cv-runoff); }
.sw-court { background: var(--cv-court); }
.sw-obstacle { background: var(--cv-obstacle); }

.tier-list { list-style: none; margin: 0 0 1rem; padding: 0; display: grid; gap: 0.5rem; }
.tier-item { border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); padding: 0.5rem 0.75rem; }
.tier-item p { margin: 0.2rem 0 0; font-size: 0.95rem; }
.badge { display: inline-block; font-weight: 700; font-size: 0.85rem; border-radius: 999px; padding: 0.05rem 0.65rem; border: 2px solid currentColor; margin-right: 0.4rem; }
.badge-ok { color: var(--ok); background: var(--ok-bg); }
.badge-bad { color: var(--bad); background: var(--bad-bg); }
.badge-info { color: var(--warn); background: var(--warn-bg); }
.tier-name { font-weight: 700; }

.sr-summary { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius); padding: 0.5rem 0.75rem; font-size: 0.95rem; }
.sr-summary summary { cursor: pointer; font-weight: 700; min-height: 2.75rem; display: flex; align-items: center; }
.sr-summary p { margin: 0 0 0.5rem; }

.error-list { margin: 0.5rem 0 0; padding-left: 1.25rem; }
.error-list a { color: inherit; }

/* Article content */
.content { max-width: 46rem; }
.content h2:first-child { margin-top: 0; }
.guide { max-width: 52rem; }
table.data { width: 100%; border-collapse: collapse; font-size: 0.95rem; margin: 0 0 1.25rem; }
table.data caption { text-align: left; font-weight: 700; padding-bottom: 0.4rem; }
table.data th, table.data td { text-align: left; padding: 0.4rem 0.5rem; border-bottom: 1px solid var(--border); vertical-align: top; }
table.data thead th { background: var(--surface-2); }
table.data td.num, table.data th.num { text-align: right; font-variant-numeric: tabular-nums; }
.table-scroll { overflow-x: auto; }
.source-note { font-size: 0.9rem; color: var(--muted); }

.disclosure { font-size: 0.9rem; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface-2); padding: 0.6rem 0.8rem; margin: 0 0 1rem; }
.products { list-style: none; margin: 0 0 1rem; padding: 0; display: grid; gap: 1rem; }
@media (min-width: 40rem) { .products { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.product { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem; }
.product h3 { margin: 0 0 0.25rem; font-size: 1.05rem; }
.product .kind { font-size: 0.85rem; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: 0.03em; margin: 0; }
.product .price { font-size: 1.25rem; font-weight: 800; margin: 0.25rem 0; }
.product .spec { font-size: 0.9rem; color: var(--muted); margin: 0.25rem 0; }
.product p:last-child { margin-bottom: 0; }

.tool-cards { display: grid; gap: 1rem; margin: 1.5rem 0; padding: 0; list-style: none; }
.tool-cards h3 { margin-top: 0; }
@media (min-width: 40rem) { .tool-cards { grid-template-columns: repeat(2, 1fr); } }

.steps { padding-left: 1.4rem; }
.steps li { margin-bottom: 0.5rem; }

@media (min-width: 40rem) {
  h1 { font-size: 2.2rem; }
  h2 { font-size: 1.6rem; }
}

@media (prefers-reduced-motion: reduce) {
  * { scroll-behavior: auto !important; transition: none !important; animation: none !important; }
}

@media print {
  .site-header, .site-footer, .skip-link, button { display: none; }
}
