/* ============================================================
   Virtual Fence Build Guide — UNL Scarlet & Cream
   ============================================================ */

:root {
  --scarlet: #D00000;
  --scarlet-dark: #9A0000;
  --cream: #F5F1E7;
  --cream-deep: #ECE6D2;
  --ink: #1A1A1A;
  --ink-soft: #4A4A4A;
  --rule: #C9C2A8;

  --tip: #2E7D32;
  --tip-bg: #E9F3EA;
  --warn: #B00020;
  --warn-bg: #FBE8EA;
  --check: var(--scarlet);
  --check-bg: #FCECEC;

  --mono: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Helvetica Neue", Arial, sans-serif;
  --serif: Georgia, "Iowan Old Style", "Times New Roman", serif;

  --max: 900px;
  --radius: 10px;
}

html, body {
  background: var(--cream);
  color: var(--ink);
  font-family: var(--sans);
  line-height: 1.6;
  font-size: 17px;
}

body {
  padding-bottom: 120px;
}

@media (min-width: 1024px) {
  body { padding-left: 280px; }
}

/* ---------- Sticky sidebar ---------- */

.sidebar {
  background: var(--cream-deep);
  border-right: 1px solid var(--rule);
  font-size: 0.9em;
}
.sidebar-inner h2 {
  margin: 0 0 14px;
  font-size: 0.78em;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--scarlet);
}
.sidebar ol {
  list-style: none;
  padding: 0;
  margin: 0;
}
.sidebar a {
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding: 9px 12px;
  border-radius: 8px;
  color: var(--ink);
  text-decoration: none;
  line-height: 1.3;
  border-left: 3px solid transparent;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.sidebar a:hover {
  background: #FFFFFF;
  color: var(--scarlet);
}
.sidebar a.active {
  background: #FFFFFF;
  color: var(--scarlet);
  border-left-color: var(--scarlet);
  font-weight: 700;
}
.sidebar .num {
  display: inline-block;
  min-width: 22px;
  color: var(--scarlet);
  font-weight: 800;
  font-size: 0.85em;
  font-variant-numeric: tabular-nums;
}

/* ---------- Top banner ---------- */

.banner {
  background: var(--scarlet);
  color: var(--cream);
  border-radius: var(--radius);
  box-shadow: 0 6px 18px rgba(208, 0, 0, 0.18);
}
.banner h1 {
  margin: 0 0 6px;
  font-size: 2.1em;
  letter-spacing: -0.01em;
}
.banner p {
  margin: 0;
  font-size: 1.05em;
  opacity: 0.92;
}

/* ---------- Table of contents ---------- */

nav.toc {
  background: var(--cream-deep);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
}
nav.toc h2 {
  margin: 0 0 10px;
  font-size: 1em;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--scarlet);
}
nav.toc a {
  color: var(--ink);
  text-decoration: none;
}
nav.toc a:hover { color: var(--scarlet); text-decoration: underline; }

/* ---------- Sections (each = one printable page) ---------- */

section.page {
  background: #FFFFFF;
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
  position: relative;
}

section.page > header {
  border-bottom: 4px solid var(--scarlet);
  padding-bottom: 14px;
  margin-bottom: 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}
section.page > header h2 {
  margin: 0;
  color: var(--scarlet);
  font-size: 1.8em;
  line-height: 1.2;
}
section.page > header .section-num {
  display: inline-block;
  background: var(--scarlet);
  color: var(--cream);
  padding: 4px 12px;
  border-radius: 999px;
  font-size: 0.8em;
  font-weight: 700;
  letter-spacing: 0.1em;
  margin-right: 10px;
}

section.page h3 {
  color: var(--scarlet-dark);
  margin-top: 1.6em;
  font-size: 1.25em;
}

section.page p, section.page li { font-size: 1em; }

/* Allow long words/URLs in body copy to break instead of overflowing. */
section.page p, section.page li, section.page td, section.page dd {
  overflow-wrap: anywhere;
}

@media (max-width: 760px) {
  section.page > header { gap: 8px; flex-wrap: wrap; }
  section.page > header h2 { font-size: 1.4em; }
  ol.steps > li { padding-left: 44px; }
  ol.steps > li::before { width: 30px; height: 30px; line-height: 30px; font-size: 0.9em; }
  th, td { padding: 8px; }
  table.bom td.thumb { width: 70px; }
  svg.part-thumb, img.part-thumb { width: 60px; height: 50px; }
  table { font-size: 0.92em; }
}

section.page a { color: var(--scarlet); }

/* ---------- Print button ---------- */

.print-btn {
  background: var(--cream);
  color: var(--scarlet);
  border: 2px solid var(--scarlet);
  padding: 8px 16px;
  border-radius: 999px;
  font-size: 0.85em;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s, color 0.15s;
}
.print-btn:hover {
  background: var(--scarlet);
  color: var(--cream);
}
.print-btn::before { content: "🖨  "; }

/* ---------- Callouts ---------- */

.callout {
  border-left: 6px solid;
  padding: 14px 18px;
  margin: 20px 0;
  border-radius: 0 var(--radius) var(--radius) 0;
}
.callout .label {
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 0.8em;
  display: block;
  margin-bottom: 4px;
}
.callout p:last-child { margin-bottom: 0; }

.callout.tip { background: var(--tip-bg); border-color: var(--tip); }
.callout.tip .label { color: var(--tip); }

.callout.warn { background: var(--warn-bg); border-color: var(--warn); }
.callout.warn .label { color: var(--warn); }

.callout.check { background: var(--check-bg); border-color: var(--check); }
.callout.check .label { color: var(--check); }

/* ---------- Code blocks ---------- */

.code-wrap {
  position: relative;
  margin: 20px 0;
}
pre {
  background: #1A1A1A;
  color: #F5F1E7;
  padding: 18px 20px;
  border-radius: var(--radius);
  overflow-x: auto;
  font-family: var(--mono);
  font-size: 0.88em;
  line-height: 1.5;
  border: 1px solid #333;
}
pre code { font-family: inherit; }

.copy-btn {
  position: absolute;
  top: 10px;
  right: 10px;
  background: var(--scarlet);
  color: var(--cream);
  border: none;
  padding: 6px 12px;
  border-radius: 6px;
  font-size: 0.75em;
  font-weight: 700;
  cursor: pointer;
  letter-spacing: 0.05em;
}
.copy-btn:hover { background: var(--scarlet-dark); }
.copy-btn.copied { background: var(--tip); }

code.inline {
  background: var(--cream-deep);
  padding: 1px 6px;
  border-radius: 4px;
  font-family: var(--mono);
  font-size: 0.92em;
}

/* ---------- Tables ---------- */

table {
  width: 100%;
  border-collapse: collapse;
  margin: 20px 0;
  background: #FFFFFF;
}
th, td {
  text-align: left;
  padding: 10px 12px;
  border-bottom: 1px solid var(--rule);
  vertical-align: top;
}
th {
  background: var(--scarlet);
  color: var(--cream);
  font-size: 0.9em;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
tr:nth-child(even) td { background: var(--cream); }

/* ---------- Math ---------- */

.math {
  display: block;
  margin: 18px auto;
  padding: 14px 18px;
  background: var(--cream-deep);
  border-left: 4px solid var(--scarlet);
  font-family: var(--serif);
  font-style: italic;
  font-size: 1.1em;
  text-align: center;
  border-radius: 0 var(--radius) var(--radius) 0;
}
.math sub, .math sup { font-style: normal; }

/* ---------- Step list ---------- */

ol.steps {
  list-style: none;
  padding-left: 0;
  counter-reset: step;
}
ol.steps > li {
  counter-increment: step;
  position: relative;
  padding: 10px 0 10px 52px;
  margin-bottom: 8px;
}
ol.steps > li::before {
  content: counter(step);
  position: absolute;
  left: 0;
  top: 8px;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--scarlet);
  color: var(--cream);
  text-align: center;
  line-height: 36px;
  font-weight: 800;
}

/* ---------- Figures & diagrams ---------- */

figure.diagram {
  margin: 22px 0;
  padding: 18px;
  background: var(--cream-deep);
  border: 1px solid var(--rule);
  border-left: 4px solid var(--scarlet);
  border-radius: var(--radius);
  text-align: center;
}
figure.diagram figcaption {
  font-size: 0.85em;
  font-style: italic;
  color: var(--ink-soft);
  margin-bottom: 10px;
}
figure.diagram .mermaid {
  background: transparent;
  color: inherit;
  padding: 0;
  border: none;
  font-family: var(--sans);
  font-size: 1em;
  line-height: 1.3;
  white-space: normal;
  display: block;
}
figure.diagram .mermaid svg {
  max-width: 100%;
  height: auto;
}

.schematic {
  width: 100%;
  max-width: 420px;
  height: auto;
  background: #FFFFFF;
  border-radius: 6px;
  padding: 12px;
}

.diagram-img {
  display: block;
  width: 100%;
  height: auto;
  margin: 0 auto;
  background: #FFFFFF;
  border-radius: 8px;
  box-shadow: 0 8px 22px rgba(0,0,0,0.10);
}

.circuit-figure {
  overflow: visible;
}

.diagram-scroll {
  width: 100%;
  overflow-x: auto;
  overflow-y: hidden;
  padding-bottom: 6px;
  -webkit-overflow-scrolling: touch;
}

.diagram-link {
  display: block;
  cursor: zoom-in;
}

.receiver-schematic-img,
.receiver-realistic-img {
  display: block;
  width: 100%;
  max-width: 100%;
  height: auto;
  margin: 0 auto;
}

.zoom-hint {
  font-size: 0.85em;
  color: var(--scarlet);
  font-style: normal;
  white-space: nowrap;
}

@media (max-width: 760px) {
  figure.diagram {
    padding: 12px;
  }

  /* Keep the schematic legible on phones: force a minimum width so the
     diagram-scroll wrapper provides horizontal panning instead of crushing
     it down to ~300px where text becomes unreadable. */
  .receiver-schematic-img {
    width: 720px;
    max-width: none;
  }
  .receiver-realistic-img {
    width: 720px;
    max-width: none;
  }
}

@media (min-width: 761px) {
  .zoom-hint { display: none; }
}

/* ---------- Hero cow illustration ---------- */

figure.hero-cow {
  margin: 8px 0 26px;
  padding: 18px 22px 16px;
  background: linear-gradient(180deg, #D9EFD1 0%, #F5F1E7 70%);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  text-align: center;
}
figure.hero-cow .cow-art {
  width: 100%;
  max-width: 420px;
  height: auto;
  border-radius: var(--radius);
  box-shadow: 0 4px 12px rgba(0,0,0,0.12);
}
figure.hero-cow figcaption {
  font-size: 0.9em;
  font-style: italic;
  color: var(--ink-soft);
  margin-top: 4px;
}

/* ---------- Animated 5 kHz waveform ---------- */

svg.wave-anim {
  width: 100%;
  height: 160px;
  background: #FFFFFF;
  border: 1px solid var(--rule);
  border-radius: 6px;
  overflow: hidden;
}
@keyframes wave-scroll {
  from { transform: translateX(0); }
  to   { transform: translateX(-600px); }
}
svg.wave-anim .wave-scroll {
  animation: wave-scroll 3s linear infinite;
}
@media (prefers-reduced-motion: reduce) {
  svg.wave-anim .wave-scroll { animation: none; }
}

/* ---------- Materials cards ---------- */

.part-grid {
  margin: 18px 0 28px;
}
.part-card {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px;
  background: var(--cream);
  border: 1px solid var(--rule);
  border-left: 4px solid var(--scarlet);
  border-radius: var(--radius);
  break-inside: avoid;
  page-break-inside: avoid;
}
.part-card-img {
  flex: 0 0 96px;
  height: 96px;
  background: #FFFFFF;
  border: 1px solid var(--rule);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 6px;
}
.part-card-img img,
.part-card-img .part-card-svg {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}
.part-card-body { min-width: 0; }
.part-card-title {
  font-weight: 700;
  color: var(--ink);
  font-size: 0.98em;
  line-height: 1.25;
  margin-bottom: 4px;
}
.part-card-desc {
  font-size: 0.88em;
  color: var(--ink-soft);
  line-height: 1.4;
}
.badge-provided {
  display: inline-block;
  margin-left: 6px;
  padding: 1px 8px;
  font-size: 0.72em;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--cream);
  background: var(--tip);
  border-radius: 999px;
  vertical-align: middle;
}

@media (max-width: 540px) {
  .part-grid { grid-template-columns: 1fr !important; }
  .part-card-img { flex-basis: 72px; height: 72px; }
}

/* ---------- BOM thumbnails (legacy table style) ---------- */

table.bom td.thumb {
  width: 110px;
  padding: 6px 8px;
  text-align: center;
  background: var(--cream);
}
table.bom tr:nth-child(even) td.thumb {
  background: var(--cream-deep);
}
svg.part-thumb,
img.part-thumb {
  width: 96px;
  height: 80px;
  object-fit: contain;
  display: inline-block;
  vertical-align: middle;
  background: #FFFFFF;
  border-radius: 6px;
  padding: 4px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}

/* ---------- Glossary ---------- */

dl.glossary dt {
  font-weight: 800;
  color: var(--scarlet);
  margin-top: 14px;
}
dl.glossary dd {
  margin: 4px 0 0 0;
}

/* ---------- Footer ---------- */

footer.site-footer {
  text-align: center;
  color: var(--ink-soft);
  font-size: 0.9em;
  border-top: 1px solid var(--rule);
}

/* ============================================================
   PRINT MODE
   - Each section can be printed individually via body.print-only
   - Color accuracy preserved (UNL scarlet must survive on paper)
   ============================================================ */

@media print {
  html, body {
    background: #FFFFFF;
    padding: 0;
    font-size: 12pt;
    print-color-adjust: exact;
    -webkit-print-color-adjust: exact;
  }

  .banner, nav.toc, footer.site-footer, .sidebar { display: none; }

  section.page,
  .banner,
  nav.toc,
  footer.site-footer {
    margin: 0 !important;
    max-width: 100% !important;
    padding-left: 0 !important;
    padding-right: 0 !important;
  }

  .print-btn, .copy-btn, .zoom-hint { display: none !important; }

  section.page {
    box-shadow: none;
    border: none;
    margin: 0 !important;
    padding: 0 !important;
    max-width: 100% !important;
    page-break-after: always;
    break-after: page;
  }

  section.page > header {
    border-bottom: 3px solid var(--scarlet);
  }

  pre {
    background: #F4F4F4 !important;
    color: #111 !important;
    border: 1px solid #888;
    page-break-inside: avoid;
    break-inside: avoid;
    white-space: pre-wrap;
    word-wrap: break-word;
  }

  th {
    background: var(--scarlet) !important;
    color: var(--cream) !important;
  }

  .callout,
  figure.diagram {
    page-break-inside: avoid;
    break-inside: avoid;
  }

  figure.diagram .mermaid svg,
  .schematic,
  .diagram-img {
    max-width: 100% !important;
  }

  .circuit-figure {
    width: 100% !important;
    max-width: 100% !important;
  }

  .diagram-scroll {
    overflow: visible !important;
    padding-bottom: 0 !important;
  }

  .receiver-schematic-img,
  .receiver-realistic-img {
    width: 100% !important;
    max-width: 100% !important;
  }

  svg.wave-anim .wave-scroll { animation: none !important; }

  svg.part-thumb,
  img.part-thumb {
    width: 70px !important;
    height: 60px !important;
  }

  .part-grid {
    grid-template-columns: 1fr 1fr !important;
    gap: 10px !important;
  }
  .part-card {
    background: #FFFFFF !important;
    page-break-inside: avoid;
    break-inside: avoid;
  }
  .part-card-img { flex-basis: 70px; height: 70px; padding: 4px; }
  .badge-provided {
    background: var(--tip) !important;
    color: var(--cream) !important;
  }

  ol.steps > li::before {
    background: var(--scarlet) !important;
    color: var(--cream) !important;
  }

  a {
    color: var(--ink);
    text-decoration: none;
  }

  h2, h3 { page-break-after: avoid; }
}

/* When a single section is being printed, hide the others. */
@media print {
  body.print-only-target section.page:not(.print-target) { display: none; }
}
