/* Statistical Computing in R — family-group skim, hub-aligned */

:root {
  --ink: #1D2D3E;
  --ink-soft: #2a3140;
  --muted: #556B82;
  --line: rgba(18, 21, 28, 0.1);
  --line-strong: rgba(18, 21, 28, 0.16);
  --surface: #ffffff;
  --bg: #F5F6F7;
  --navy: #1a2b3c;
  --navy-hover: #0f1e2a;
  --accent: #0062D6;
  --accent-hover: #004BB0;
  --accent-deep: #004BB0;
  --r: #0062D6;
  --r-soft: rgba(0, 98, 214, 0.1);
  --r-pale: #e4eaef;
  --ok: #256F3A;
  --nb-input-bg: #f4f6f8;
  --nb-output-bg: #ffffff;
  --nb-border: #0062D6;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 1px 2px rgba(18, 21, 28, 0.04), 0 12px 40px rgba(26, 43, 60, 0.06);
  --font: "Figtree", "Segoe UI", sans-serif;
  --display: "Newsreader", Georgia, "Times New Roman", serif;
  --mono: ui-monospace, "Cascadia Code", "SF Mono", Menlo, Consolas, monospace;
  --max: 1180px;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
}

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

html { scroll-behavior: smooth; }

body.r-page {
  margin: 0;
  font-family: var(--font);
  color: var(--ink);
  background: var(--bg);
  min-height: 100vh;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

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

body.r-page a:hover {
  text-decoration: underline;
  text-underline-offset: 3px;
}

.skip-link {
  position: absolute;
  left: -999px;
  top: 0;
  background: var(--navy);
  color: #fff;
  padding: 0.55rem 0.9rem;
  z-index: 100;
  font-weight: 600;
  border-radius: 0 0 10px 0;
}

.skip-link:focus { left: 0; }

.atmosphere {
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  overflow: hidden;
}

.mesh {
  position: absolute;
  border-radius: 50%;
  filter: blur(80px);
  opacity: 0.45;
}

.mesh-a {
  width: min(70vw, 720px);
  height: min(70vw, 720px);
  top: -18%;
  left: -12%;
  background: radial-gradient(circle, rgba(0, 98, 214, 0.18) 0%, transparent 70%);
}

.mesh-b {
  width: min(50vw, 520px);
  height: min(50vw, 520px);
  top: 12%;
  right: -8%;
  background: radial-gradient(circle, rgba(26, 43, 60, 0.12) 0%, transparent 70%);
}

.geo-plane {
  position: absolute;
  inset: 0;
  background:
    linear-gradient(165deg, rgba(238, 241, 245, 0.2) 0%, transparent 42%),
    repeating-linear-gradient(
      -18deg,
      transparent,
      transparent 48px,
      rgba(26, 43, 60, 0.014) 48px,
      rgba(26, 43, 60, 0.014) 49px
    );
  mask-image: linear-gradient(180deg, #000 0%, #000 50%, transparent 100%);
}

/* Header — hub navy */
.site-header {
  position: sticky;
  top: 0;
  z-index: 40;
  backdrop-filter: blur(16px) saturate(1.2);
  -webkit-backdrop-filter: blur(16px) saturate(1.2);
  background: #1A2B3C;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.nav {
  max-width: var(--max);
  margin: 0 auto;
  padding: 0.85rem 1.5rem;
  min-height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.r-page .brand { color: #E8EEF5; }
.r-page .brand-tag { color: #E8EEF5; }
.r-page .brand-photo {
  border-color: rgba(255, 255, 255, 0.22);
}

.nav-links {
  display: flex;
  align-items: center;
  gap: 1.2rem;
  flex-wrap: wrap;
}

.nav-links a {
  color: #E8EEF5;
  font-size: 0.88rem;
  font-weight: 550;
  text-decoration: none;
}

.nav-links a:hover,
.nav-links a[aria-current="page"] {
  color: #7CB8FF;
  text-decoration: none;
}

.nav-toggle {
  display: none;
  width: 42px;
  height: 42px;
  border: 1px solid rgba(255, 255, 255, 0.22);
  background: rgba(255, 255, 255, 0.08);
  color: #f4f6f8;
  border-radius: var(--radius-sm);
  cursor: pointer;
}

/* Hero */
.r-hero {
  max-width: var(--max);
  margin: 0 auto;
  padding: clamp(2.25rem, 5vw, 3.5rem) 1.5rem 2rem;
}

.breadcrumb {
  font-size: 0.82rem;
  color: var(--muted);
  margin: 0 0 1.1rem;
}

.breadcrumb a { color: var(--muted); font-weight: 500; }

.hero-brand-row {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-bottom: 0.75rem;
}

.r-logo {
  flex-shrink: 0;
  border-radius: 10px;
  box-shadow: 0 4px 16px rgba(26, 43, 60, 0.22);
}

.hero-brand-text {
  display: flex;
  flex-direction: column;
  gap: 0.12rem;
}

.r-kicker {
  margin: 0;
  font-size: 0.72rem;
  font-weight: 650;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--r);
}

.r-brand {
  margin: 0;
  font-family: var(--display);
  font-size: clamp(2rem, 4.5vw, 2.85rem);
  font-weight: 500;
  letter-spacing: -0.03em;
  line-height: 1.08;
  color: var(--navy);
}

.r-hero .lead {
  margin: 0 0 1.25rem;
  color: var(--muted);
  font-size: 1.05rem;
  line-height: 1.6;
  max-width: 48ch;
}

.pill-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-bottom: 1.15rem;
}

.pill {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0.28rem 0.7rem;
  font-size: 0.74rem;
  font-weight: 550;
  color: var(--ink-soft);
  background: rgba(255, 255, 255, 0.75);
  text-decoration: none;
  transition: background 0.2s ease, border-color 0.2s ease, color 0.2s ease;
}

a.pill:hover {
  text-decoration: none;
  border-color: rgba(0, 98, 214, 0.35);
  color: var(--navy);
}

.pill.accent {
  background: var(--r-soft);
  border-color: rgba(0, 98, 214, 0.3);
  color: var(--accent-deep);
}

.disclaimer {
  margin: 0;
  padding: 0.75rem 1rem;
  border-left: 3px solid var(--navy);
  background: rgba(255, 255, 255, 0.75);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  font-size: 0.86rem;
  color: var(--muted);
  max-width: 58ch;
  line-height: 1.55;
}

/* Sections */
.section {
  max-width: var(--max);
  margin: 0 auto;
  padding: 0 1.5rem 3.25rem;
}

.section-head {
  margin-bottom: 1.35rem;
  max-width: 40rem;
}

.section-kicker {
  margin: 0 0 0.4rem;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 650;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.section h2 {
  font-family: var(--display);
  font-size: clamp(1.45rem, 2.5vw, 1.9rem);
  font-weight: 500;
  letter-spacing: -0.02em;
  margin: 0 0 0.5rem;
  color: var(--navy);
}

.section .sub {
  margin: 0;
  color: var(--muted);
  font-size: 0.96rem;
  line-height: 1.6;
}

/* Family accordion */
.family-list {
  display: grid;
  gap: 0.55rem;
}

.family {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  animation: famIn 0.45s var(--ease) both;
}

.family:nth-child(1) { animation-delay: 0.02s; }
.family:nth-child(2) { animation-delay: 0.06s; }
.family:nth-child(3) { animation-delay: 0.1s; }
.family:nth-child(4) { animation-delay: 0.14s; }
.family:nth-child(5) { animation-delay: 0.18s; }
.family:nth-child(6) { animation-delay: 0.22s; }
.family:nth-child(7) { animation-delay: 0.26s; }

@keyframes famIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: none; }
}

.family > summary {
  list-style: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.9rem 1.05rem;
  font-weight: 650;
  color: var(--navy);
  user-select: none;
}

.family > summary::-webkit-details-marker { display: none; }

.family > summary::after {
  content: "+";
  margin-left: auto;
  color: var(--muted);
  font-weight: 700;
  font-size: 1.15rem;
  line-height: 1;
}

.family[open] > summary {
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(0, 98, 214, 0.06), transparent);
}

.family[open] > summary::after { content: "–"; }

.fam-code {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 3.1rem;
  height: 1.7rem;
  padding: 0 0.45rem;
  border-radius: 7px;
  background: var(--navy);
  color: #f4f6f8;
  font-size: 0.68rem;
  font-weight: 750;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  flex-shrink: 0;
}

.fam-title {
  font-family: var(--display);
  font-size: 1.15rem;
  font-weight: 550;
  letter-spacing: -0.01em;
}

.fam-meta {
  font-size: 0.78rem;
  font-weight: 500;
  color: var(--muted);
  display: none;
}

@media (min-width: 720px) {
  .fam-meta { display: inline; }
}

.family-body {
  padding: 0.65rem 0.75rem 0.85rem;
  display: grid;
  gap: 0.4rem;
  background: rgba(238, 241, 245, 0.45);
  animation: fadeIn 0.3s var(--ease);
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(-4px); }
  to { opacity: 1; transform: none; }
}

/* Nested problems */
.problem {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  overflow: hidden;
}

.problem.featured {
  border-color: rgba(0, 98, 214, 0.35);
  box-shadow: 0 0 0 1px rgba(0, 98, 214, 0.08);
}

.problem > summary {
  list-style: none;
  cursor: pointer;
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.35rem 0.75rem;
  padding: 0.75rem 0.9rem;
  user-select: none;
}

.problem > summary::-webkit-details-marker { display: none; }

.problem > summary::after {
  content: "";
  width: 0;
  height: 0;
  margin-left: auto;
  border-left: 4px solid transparent;
  border-right: 4px solid transparent;
  border-top: 5px solid var(--muted);
  transition: transform 0.25s var(--ease);
  align-self: center;
}

.problem[open] > summary {
  background: var(--r-soft);
  border-bottom: 1px solid var(--line);
}

.problem[open] > summary::after { transform: rotate(180deg); }

.prob-label {
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #004BB0;
  background: #E8F1FC;
  border: 1px solid rgba(0, 98, 214, 0.22);
  border-radius: 4px;
  padding: 0.12rem 0.4rem;
}

.prob-title {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--ink);
  flex: 1 1 12rem;
}

.prob-result {
  font-size: 0.82rem;
  font-weight: 550;
  color: var(--ok);
}

.problem-body {
  padding: 0.85rem 0.95rem 1rem;
  animation: fadeIn 0.3s var(--ease);
}

.approach {
  margin: 0 0 0.65rem;
  font-size: 0.9rem;
  color: var(--ink-soft);
  line-height: 1.55;
}

.tech-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
  margin-bottom: 0.85rem;
}

.tech-tag {
  font-size: 0.68rem;
  font-weight: 600;
  padding: 0.15rem 0.45rem;
  border-radius: 4px;
  background: rgba(238, 241, 245, 0.95);
  border: 1px solid var(--line);
  color: var(--ink-soft);
  font-family: var(--mono);
}

/* Detail panel — notebook cells */
.detail-panel {
  display: grid;
  grid-template-columns: 1.15fr 0.85fr;
  gap: 0.85rem;
}

.detail-block.nb-input,
.detail-block.nb-output {
  border-radius: var(--radius-sm);
  overflow: hidden;
  border: 1px solid var(--line);
  box-shadow: 0 1px 3px rgba(26, 43, 60, 0.05);
}

.detail-block.nb-input {
  background: var(--nb-input-bg);
  border-left: 3px solid var(--nb-border);
}

.detail-block.nb-output {
  background: var(--nb-output-bg);
}

.nb-label {
  font-family: var(--mono);
  font-size: 0.68rem;
  font-weight: 600;
  color: var(--accent);
  padding: 0.5rem 0.85rem 0;
  letter-spacing: 0.02em;
}

.code-block {
  margin: 0;
  padding: 0.65rem 0.85rem 0.85rem;
  background: transparent;
  color: #1e2a38;
  font-family: var(--mono);
  font-size: 0.76rem;
  line-height: 1.6;
  overflow-x: auto;
  white-space: pre;
  border: none;
}

.code-block .cm { color: #556B82; font-style: italic; }
.code-block .kw { color: var(--navy); font-weight: 600; }
.code-block .fn { color: var(--r); }
.code-block .st { color: #8A5A00; }

.nb-output .metric-grid,
.nb-output .result-callout {
  padding: 0 0.85rem;
}

.nb-output .metric-grid { padding-top: 0.15rem; }
.nb-output .result-callout { margin: 0.65rem 0.85rem 0.85rem; }

.result-callout {
  background: var(--r-pale);
  border: 1px solid rgba(0, 98, 214, 0.15);
  border-radius: var(--radius-sm);
  padding: 0.85rem 0.95rem;
  margin-bottom: 0.85rem;
}

.result-callout strong {
  display: block;
  font-size: 0.95rem;
  color: var(--ink);
  margin-bottom: 0.35rem;
}

.result-callout p {
  margin: 0;
  font-size: 0.86rem;
  color: var(--muted);
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.55rem;
  margin-bottom: 0.85rem;
}

.metric {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.65rem 0.75rem;
}

.metric b {
  display: block;
  font-family: var(--display);
  font-size: 1.15rem;
  font-weight: 550;
  color: var(--accent-deep);
}

.metric span {
  font-size: 0.7rem;
  color: var(--muted);
  font-weight: 500;
}

.chart-box {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 0.5rem;
  min-height: 200px;
  margin: 0 0.85rem 0.85rem;
}

.nb-output > .chart-box:last-child {
  margin-bottom: 0.85rem;
}

/* Charts section */
.charts-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1rem;
}

.chart-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.15rem 1.2rem 1rem;
  animation: famIn 0.5s var(--ease) both;
  animation-delay: 0.12s;
}

.chart-card h3 {
  margin: 0 0 0.35rem;
  font-family: var(--display);
  font-size: 1.15rem;
  font-weight: 550;
  color: var(--navy);
}

.chart-card p {
  margin: 0 0 0.75rem;
  font-size: 0.86rem;
  color: var(--muted);
}

.chart-card .chart-box { margin: 0; }

/* Footer */
.footer {
  border-top: 1px solid var(--line);
  padding: 1.75rem 1.5rem 2.5rem;
  margin-top: 0.5rem;
}

.footer-inner {
  max-width: var(--max);
  margin: 0 auto;
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 1rem;
  align-items: center;
}

.footer-brand {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.footer-brand span { font-size: 0.85rem; color: var(--muted); }

.footer-links {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  font-size: 0.9rem;
}

/* Responsive */
@media (max-width: 900px) {
  .detail-panel { grid-template-columns: 1fr; }
  .charts-grid { grid-template-columns: 1fr; }
}

@media (max-width: 720px) {
  .nav-toggle { display: grid; place-items: center; }
  .nav-drawer {
    display: none;
    position: absolute;
    left: 0;
    right: 0;
    top: 64px;
    background: rgba(26, 43, 60, 0.98);
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    padding: 1rem 1.5rem 1.25rem;
  }
  .nav-drawer.is-open { display: block; }
  .nav-links { flex-direction: column; align-items: flex-start; gap: 0.75rem; }

  .family > summary {
    flex-wrap: wrap;
  }

  .prob-result {
    width: 100%;
    order: 3;
  }
}

/* Dark bar: beat body.r-page a so links stay light on #1A2B3C */
.r-page .site-header a,
.r-page .skip-link {
  color: #E8EEF5;
}
.r-page .site-header .nav-home-btn,
.r-page .site-header .nav-links a:hover,
.r-page .site-header .nav-links a[aria-current="page"] {
  color: #7CB8FF;
}
.r-page .site-header .nav-home-btn:hover {
  color: #7CB8FF;
  text-decoration: none;
}
