:root {
  --bg-deep: #05060a;
  --accent: #38bdf8;
  --accent-hot: #0ea5e9;
  --accent-glow: rgba(14, 165, 233, 0.55);
  --accent-glow-soft: rgba(56, 189, 248, 0.35);
  --text: #f7f7ff;
  --muted: #9ca3af;
  --border-subtle: rgba(148, 163, 184, 0.22);
  --shadow-soft: 0 18px 40px rgba(0, 0, 0, 0.55);
  --shadow-subtle: 0 10px 25px rgba(0, 0, 0, 0.35);
  --radius-md: 10px;
  --radius-lg: 14px;
  --radius-xl: 24px;
  /* Calculator blocks — lifted from page chrome so tools read clearly */
  --calc-surface: rgba(22, 38, 54, 0.94);
  --calc-surface-inner: rgba(14, 24, 36, 0.88);
  --calc-output-bg: rgba(18, 40, 58, 0.92);
  --calc-border: rgba(56, 189, 248, 0.32);
  --calc-border-soft: rgba(56, 189, 248, 0.18);
  --calc-shadow: 0 10px 28px rgba(0, 0, 0, 0.45);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  min-height: 100vh;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 16px;
  line-height: 1.6;
  color: var(--text);
  background-color: #0a0a0a;
  background-image: linear-gradient(165deg, #25252c 0%, #121218 40%, #060608 100%);
  padding: clamp(20px, 4vw, 40px);
  display: flex;
  justify-content: center;
  overflow-x: hidden;
}

a {
  color: var(--accent);
  text-decoration: none;
  transition: color 0.12s ease, filter 0.12s ease;
}

a:hover {
  color: #7dd3fc;
}

.app-shell {
  width: 100%;
  max-width: 920px;
  background: #090a0e;
  border-radius: var(--radius-xl);
  border: 1px solid rgba(148, 163, 184, 0.18);
  box-shadow: var(--shadow-soft);
  padding: 22px 22px 20px;
  position: relative;
  overflow: visible;
}

.app-shell--tool {
  align-self: flex-start;
}

.site-header {
  position: relative;
  z-index: 20;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border-subtle);
}

.site-header__brand-row {
  display: flex;
  align-items: center;
  justify-content: center;
}

@media (min-width: 640px) {
  .site-header__brand-row {
    justify-content: flex-start;
  }
}

.brand {
  display: flex;
  align-items: center;
  text-decoration: none;
  line-height: 0;
}

.brand:hover {
  text-decoration: none;
  filter: brightness(1.06);
}

.brand-logo {
  display: block;
  height: 79px;
  width: auto;
  max-width: min(432px, 90vw);
  object-fit: contain;
  filter: drop-shadow(0 0 14px var(--accent-glow-soft));
}

.site-nav {
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--border-subtle);
}

.site-nav__list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  align-items: stretch;
  justify-content: center;
  gap: 4px 8px;
}

@media (min-width: 640px) {
  .site-nav__list {
    justify-content: flex-start;
    gap: 4px 12px;
  }
}

.site-nav__item {
  position: relative;
}

.site-nav__link {
  display: inline-flex;
  align-items: center;
  gap: 0.3em;
  padding: 0.45rem 0.15rem;
  font-size: 0.8125rem;
  font-weight: 500;
  letter-spacing: 0.01em;
  color: var(--muted);
  text-decoration: none;
  border-bottom: 2px solid transparent;
  transition: color 0.15s ease, border-color 0.15s ease;
}

.site-nav__link:hover {
  color: var(--text);
  border-bottom-color: rgba(56, 189, 248, 0.55);
}

.site-nav__caret {
  display: inline-block;
  font-size: 0.65em;
  line-height: 1;
  opacity: 0.45;
  transform: translateY(1px);
}

.site-nav__item--has-sub::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  top: 100%;
  height: 10px;
  z-index: 49;
}

.site-nav__sub {
  display: block;
  visibility: hidden;
  opacity: 0;
  pointer-events: none;
  position: absolute;
  left: 0;
  top: calc(100% + 6px);
  min-width: min(280px, calc(100vw - 48px));
  margin: 0;
  padding: 0.4rem 0;
  list-style: none;
  background: linear-gradient(165deg, rgba(15, 17, 24, 0.99), rgba(6, 8, 14, 0.99));
  border: 1px solid rgba(148, 163, 184, 0.22);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-soft);
  z-index: 50;
  transition: opacity 0.15s ease, visibility 0.15s ease;
}

.site-nav__item--has-sub:hover .site-nav__sub,
.site-nav__item--has-sub:focus-within .site-nav__sub {
  visibility: visible;
  opacity: 1;
  pointer-events: auto;
}

.site-nav__sub-link {
  display: block;
  padding: 0.5rem 0.95rem;
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--muted);
  text-decoration: none;
  transition: color 0.12s ease, background 0.12s ease;
}

.site-nav__sub-link:hover {
  color: var(--text);
  background: rgba(56, 189, 248, 0.09);
}

.site-nav__sub-link[aria-current="page"] {
  color: var(--accent);
  background: rgba(56, 189, 248, 0.08);
}

.site-nav__sub-link:focus-visible {
  outline: 2px solid rgba(56, 189, 248, 0.6);
  outline-offset: -2px;
}

.site-nav__sub-heading {
  list-style: none;
  padding: 0.45rem 0.95rem 0.2rem;
  margin-top: 0.2rem;
  border-top: 1px solid var(--border-subtle);
}

.site-nav__sub-heading-text {
  display: block;
  font-size: 0.65rem;
  font-weight: 600;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--muted);
  opacity: 0.9;
}

/* Nested flyout (e.g. Fire Engineering → Ch. 37 topics) */
.site-nav__sub > li {
  position: relative;
  list-style: none;
}

.site-nav__sub-link--flyout {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

.site-nav__sub-link-text {
  flex: 1;
  min-width: 0;
}

.site-nav__sub-caret {
  display: inline-block;
  font-size: 0.65em;
  line-height: 1;
  opacity: 0.55;
  flex-shrink: 0;
}

.site-nav__sub-link--branch {
  color: var(--accent);
  background: rgba(56, 189, 248, 0.06);
}

.site-nav__sub--nested {
  display: block;
  visibility: hidden;
  opacity: 0;
  pointer-events: none;
  position: absolute;
  left: calc(100% + 4px);
  top: 0;
  min-width: min(260px, calc(100vw - 64px));
  max-height: min(70vh, 420px);
  overflow-y: auto;
  margin: 0;
  padding: 0.4rem 0;
  list-style: none;
  background: linear-gradient(165deg, rgba(15, 17, 24, 0.99), rgba(6, 8, 14, 0.99));
  border: 1px solid rgba(148, 163, 184, 0.22);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-soft);
  z-index: 60;
  transition: opacity 0.15s ease, visibility 0.15s ease;
}

.site-nav__sub-item--has-sub::after {
  content: "";
  position: absolute;
  left: 100%;
  top: 0;
  width: 8px;
  height: 100%;
  z-index: 59;
}

.site-nav__sub-item--has-sub:hover .site-nav__sub--nested,
.site-nav__sub-item--has-sub:focus-within .site-nav__sub--nested {
  visibility: visible;
  opacity: 1;
  pointer-events: auto;
}

@media (max-width: 900px) {
  .site-nav__sub--nested {
    left: auto;
    right: calc(100% + 4px);
  }
}

.page-main {
  min-height: 0;
  padding-top: 1.25rem;
}

.page-reading-guide {
  max-width: 48rem;
  margin-bottom: 1.25rem;
  padding: 1rem 1.1rem;
  background: rgba(14, 165, 233, 0.06);
  border: 1px solid rgba(56, 189, 248, 0.22);
  border-radius: var(--radius-lg);
}

.page-reading-guide__title {
  font-size: 0.9375rem;
  font-weight: 600;
  margin: 0 0 0.6rem;
  color: var(--text);
}

/* Opt-in: main headings use the same cyan gradient family as index.html CTA buttons */
body.page--accent-headings .page-reading-guide__title,
body.page--accent-headings .page-content__title,
body.page--accent-headings .page-section > h2 {
  color: transparent;
  -webkit-text-fill-color: transparent;
  background: linear-gradient(90deg, #7dd3fc 0%, #38bdf8 50%, #0ea5e9 100%);
  -webkit-background-clip: text;
  background-clip: text;
}

body.page--accent-headings .page-section > h2 {
  border-bottom-color: rgba(56, 189, 248, 0.35);
}

.page-figure {
  margin: 1rem 0 1.25rem;
  max-width: 48rem;
}

.page-figure__img {
  display: block;
  width: 100%;
  max-width: 440px;
  height: auto;
  margin: 0 auto;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-subtle);
  background: rgba(248, 250, 252, 0.96);
  padding: 0.5rem;
}

.page-figure__img--tall {
  max-width: 280px;
  max-height: 380px;
  object-fit: contain;
}

.page-figure-grid {
  display: grid;
  gap: 1rem;
  margin: 1rem 0 1.25rem;
  max-width: 48rem;
}

@media (min-width: 640px) {
  .page-figure-grid--2 {
    grid-template-columns: 1fr 1fr;
    align-items: start;
  }
}

.page-figure__caption {
  margin-top: 0.5rem;
  font-size: 0.8125rem;
  color: var(--muted);
  line-height: 1.55;
  text-align: center;
  max-width: 440px;
  margin-left: auto;
  margin-right: auto;
}

.page-figure__license {
  display: block;
  margin-top: 0.35rem;
  font-size: 0.75rem;
  color: #64748b;
}

.page-sources {
  margin-top: 1.5rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border-subtle);
  font-size: 0.8125rem;
  color: var(--muted);
  line-height: 1.6;
}

.page-sources ul {
  margin: 0;
  padding-left: 1.2rem;
}

.page-reading-guide__list {
  margin: 0 0 0.65rem;
  padding-left: 1.2rem;
  font-size: 0.875rem;
  color: var(--muted);
  line-height: 1.65;
}

.page-reading-guide__list li {
  margin-bottom: 0.35rem;
}

.page-reading-guide__note {
  margin: 0;
  font-size: 0.8125rem;
  color: #94a3b8;
  line-height: 1.55;
}

.topic-one-liner {
  max-width: 48rem;
  margin: 0 0 1.25rem;
  padding: 0.85rem 1rem;
  font-size: 0.9375rem;
  line-height: 1.65;
  color: var(--muted);
  border-left: 3px solid rgba(148, 163, 184, 0.35);
  background: rgba(8, 10, 16, 0.45);
  border-radius: 0 var(--radius-md) var(--radius-md) 0;
}

.topic-one-liner strong {
  color: var(--text);
}

.plain-box {
  max-width: 48rem;
  margin-bottom: 1.25rem;
  padding: 1rem 1.1rem;
  background: rgba(18, 22, 32, 0.85);
  border: 1px solid rgba(148, 163, 184, 0.15);
  border-radius: var(--radius-lg);
}

.plain-box__title {
  font-size: 1rem;
  font-weight: 600;
  margin: 0 0 0.5rem;
  color: var(--text);
}

.plain-box p {
  margin: 0 0 0.65rem;
  font-size: 0.9375rem;
  color: var(--muted);
  line-height: 1.7;
}

.plain-box p:last-child {
  margin-bottom: 0;
}

.example-walkthrough {
  max-width: 48rem;
  margin-bottom: 1.25rem;
  padding: 1rem 1.1rem;
  border: 1px dashed rgba(148, 163, 184, 0.25);
  border-radius: var(--radius-lg);
}

.example-walkthrough__title {
  font-size: 0.9375rem;
  font-weight: 600;
  margin: 0 0 0.65rem;
  color: #e2e8f0;
}

.example-walkthrough ol {
  margin: 0;
  padding-left: 1.2rem;
  font-size: 0.875rem;
  color: var(--muted);
  line-height: 1.65;
}

.example-walkthrough li {
  margin-bottom: 0.4rem;
}

.page-content {
  max-width: 48rem;
  color: var(--text);
}

.page-content__header {
  margin-bottom: 1.75rem;
  padding-bottom: 1.25rem;
  border-bottom: 1px solid var(--border-subtle);
}

.page-content__title {
  font-size: clamp(1.35rem, 3vw, 1.65rem);
  font-weight: 700;
  letter-spacing: -0.03em;
  line-height: 1.25;
}

.page-lead {
  margin: 0.75rem 0 0;
  font-size: 1rem;
  font-weight: 400;
  color: var(--muted);
  line-height: 1.65;
  max-width: 40rem;
}

.page-content__crumb {
  margin: 0.75rem 0 0;
  font-size: 0.875rem;
  color: var(--muted);
}

.page-content__crumb p {
  margin: 0;
}

.page-content__crumb a {
  color: var(--accent);
  text-decoration: none;
}

.page-content__crumb a:hover {
  text-decoration: underline;
}

.page-section {
  margin-bottom: 1.75rem;
}

.page-section:last-child {
  margin-bottom: 0;
}

.page-section h2 {
  font-size: 1.125rem;
  font-weight: 600;
  letter-spacing: -0.02em;
  margin: 0 0 1rem;
  color: var(--text);
  line-height: 1.35;
  padding-bottom: 0.35rem;
  border-bottom: 1px solid rgba(148, 163, 184, 0.12);
}

.page-section strong {
  color: var(--text);
}

.page-section p {
  margin: 0 0 1rem;
  font-size: 0.9375rem;
  color: var(--muted);
  line-height: 1.75;
  max-width: 42rem;
}

.page-section p:last-child {
  margin-bottom: 0;
}

.page-section ul,
.page-section ol {
  margin: 0 0 0.85rem;
  padding-left: 1.25rem;
  font-size: 0.9375rem;
  color: var(--muted);
  line-height: 1.6;
}

.page-section li {
  margin-bottom: 0.35rem;
}

.page-section li:last-child {
  margin-bottom: 0;
}

.page-section .page-subhead {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text);
  margin: 1rem 0 0.4rem;
}

.page-section .page-subhead:first-child {
  margin-top: 0;
}

.page-nested-list {
  margin-top: 0.35rem !important;
  margin-bottom: 0.75rem !important;
}

.page-callout {
  margin: 1rem 0 0;
  padding: 0.85rem 1rem;
  border-left: 3px solid rgba(56, 189, 248, 0.55);
  background: rgba(15, 17, 24, 0.6);
  border-radius: 0 var(--radius-lg) var(--radius-lg) 0;
  font-size: 0.9375rem;
  color: var(--muted);
}

.page-callout p {
  margin-bottom: 0.5rem;
}

.page-callout p:last-child {
  margin-bottom: 0;
}

.page-callout strong {
  color: var(--text);
}

.page-section h3 {
  font-size: 1.02rem;
  font-weight: 600;
  margin: 2rem 0 0.65rem;
  color: var(--text);
  letter-spacing: -0.02em;
  line-height: 1.35;
}

.page-section h3:first-child {
  margin-top: 0;
}

.page-section h4,
.term-block__title {
  font-size: 0.8125rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: #94a3b8;
  margin: 0 0 0.65rem;
}

.term-block {
  margin-top: 1.25rem;
  padding: 0.9rem 1rem;
  background: rgba(8, 10, 16, 0.5);
  border: 1px solid rgba(148, 163, 184, 0.12);
  border-radius: var(--radius-lg);
}

.term-block .term-list {
  margin: 0;
}

.term-list {
  display: grid;
  gap: 0.85rem;
}

.term-list dt {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text);
  margin: 0;
}

.term-list dd {
  margin: 0.2rem 0 0;
  padding: 0;
  font-size: 0.875rem;
  color: var(--muted);
  line-height: 1.65;
}

.formula-block {
  margin: 0.5rem 0 0.85rem;
  padding: 0.65rem 0.85rem;
  background: var(--calc-surface-inner);
  border: 1px solid var(--calc-border-soft);
  border-radius: var(--radius-lg);
  font-family: ui-monospace, "Cascadia Code", "Consolas", monospace;
  font-size: 0.8125rem;
  color: #e2e8f0;
  line-height: 1.5;
  overflow-x: auto;
}

.calc {
  margin-top: 1rem;
  padding: 1rem 1.1rem;
  background: var(--calc-surface);
  border: 1px solid var(--calc-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--calc-shadow);
}

.calc__title {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--accent);
  margin: 0 0 0.75rem;
}

.calc__desc {
  font-size: 0.8125rem;
  font-weight: 400;
  text-transform: none;
  letter-spacing: normal;
  line-height: 1.5;
  color: var(--muted);
  margin: -0.35rem 0 0.75rem;
}

.calc-grid {
  display: grid;
  gap: 0.65rem;
}

.calc-field {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.calc-field label {
  font-size: 0.8125rem;
  color: var(--muted);
  font-weight: 500;
}

.calc-field input,
.calc-field select {
  padding: 0.45rem 0.55rem;
  font-size: 0.875rem;
  border-radius: var(--radius-lg);
  border: 1px solid var(--calc-border-soft);
  background: var(--calc-surface-inner);
  color: var(--text);
  font-family: inherit;
  max-width: 100%;
}

.calc-field input:focus,
.calc-field select:focus {
  outline: 2px solid rgba(56, 189, 248, 0.45);
  outline-offset: 0;
}

.calc-output {
  margin-top: 0.85rem;
  padding: 0.75rem 0.85rem;
  background: var(--calc-output-bg);
  border-radius: var(--radius-lg);
  border: 1px solid var(--calc-border);
  font-size: 0.875rem;
  color: var(--text);
  line-height: 1.55;
}

.calc-output strong {
  color: var(--text);
}

.calc-output-note {
  display: block;
  margin-top: 0.5rem;
  font-size: 0.8125rem;
  color: var(--muted);
  font-weight: 400;
}

.page-section .calc-hint {
  font-size: 0.8125rem;
  color: var(--muted);
  margin: 0.35rem 0 0;
}
