/* learn-r.org : one stylesheet for every page.
   Change the colours below and the whole site follows. */
:root {
  --menu-bg: #14233B;       /* top menu bar */
  --menu-ink: #E8EEF8;
  --menu-active: #7FB2FF;
  --footer-bg: #14233B;
  --bg: #F5F7FA;
  --surface: #FFFFFF;
  --ink: #1A2433;
  --muted: #5B677A;
  --line: #DCE2EB;
  --brand: #1F5FBF;
  --brand-soft: #E6EEFB;
  --accent: #E39A2D;
  --code-bg: #0F1B2D;
  --code-ink: #E6EDF7;
  --font-ui: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Arial, sans-serif;
  --font-body: 'Source Serif 4', Georgia, serif;
  --font-mono: 'JetBrains Mono', ui-monospace, Menlo, Consolas, monospace;
  --header-h: 60px;
}

*, *::before, *::after { box-sizing: border-box; }
html { scroll-behavior: smooth; scroll-padding-top: calc(var(--header-h) + 16px); }
body { margin: 0; background: var(--bg); color: var(--ink); font: 400 1.125rem/1.7 var(--font-body); }
a { color: var(--brand); text-underline-offset: 3px; }
a:hover { color: #153F82; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; border-radius: 3px; }
.wrap { max-width: 1320px; margin: 0 auto; padding: 0 24px; }

.skip-link { position: absolute; left: -999px; top: 8px; background: #fff; padding: 8px 14px; z-index: 100; }
.skip-link:focus { left: 8px; }

/* ---------- header / menu bar ---------- */
.site-header { background: var(--menu-bg); position: sticky; top: 0; z-index: 50; }
.header-inner { display: flex; align-items: center; justify-content: space-between; height: var(--header-h); }
.brand { font: 800 1.35rem var(--font-ui); color: #fff; text-decoration: none; letter-spacing: -0.02em; }
.brand span { color: var(--menu-active); }
.main-nav { display: flex; gap: 6px; font-family: var(--font-ui); font-weight: 500; }
.main-nav a { color: var(--menu-ink); text-decoration: none; padding: 8px 14px; border-radius: 6px; }
.main-nav a:hover { background: rgba(255,255,255,.1); }
.main-nav a[aria-current] { color: var(--menu-active); box-shadow: inset 0 -2px 0 var(--menu-active); border-radius: 6px 6px 0 0; }
.main-nav a.nav-cta { background: var(--accent); color: #14233B; font-weight: 700; margin-left: 8px; }
.main-nav a.nav-cta:hover { background: #F0AE4A; }
.nav-toggle { display: none; }
.nav-burger { display: none; cursor: pointer; padding: 10px; margin-right: -10px; }
.nav-burger span { display: block; width: 24px; height: 2px; margin: 5px 0; background: #fff; border-radius: 2px; transition: transform .2s, opacity .2s; }

/* ---------- three-column layout ---------- */
.layout { display: grid; grid-template-columns: 250px minmax(0, 1fr) 240px; gap: 36px; padding-top: 32px; padding-bottom: 56px; align-items: start; }
.layout.no-right { grid-template-columns: 250px minmax(0, 1fr); }
.col-left { position: sticky; top: calc(var(--header-h) + 24px); max-height: calc(100vh - var(--header-h) - 48px); overflow-y: auto; }
.col-main { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 40px 48px; }
.col-right { position: sticky; top: calc(var(--header-h) + 24px); font: 400 .95rem/1.55 var(--font-ui); }

/* ---------- left menu ---------- */
.side-nav { font-family: var(--font-ui); }
.side-title { margin: 0 0 10px; font-size: 1.1rem; font-weight: 700; letter-spacing: -0.01em; }
.side-title a { color: var(--ink); text-decoration: none; }
.side-title a[aria-current] { color: var(--brand); }
.side-nav summary { display: none; }
.side-nav ul { list-style: none; margin: 0; padding: 0; border-left: 2px solid var(--line); }
.side-nav li a { display: block; padding: 6px 12px; margin-left: -2px; border-left: 2px solid transparent; color: var(--muted); text-decoration: none; font-size: .95rem; line-height: 1.35; }
.side-nav li a:hover { color: var(--ink); background: var(--brand-soft); }
.side-nav li a[aria-current] { color: var(--brand); font-weight: 700; border-left-color: var(--brand); background: var(--brand-soft); }
.side-home { margin: 14px 0 0; padding-top: 12px; border-top: 1px solid var(--line); }
.side-home a { color: var(--ink); font-weight: 700; text-decoration: none; }
.side-home a:hover { color: var(--brand); }

/* ---------- article typography ---------- */
.breadcrumbs ol { list-style: none; display: flex; flex-wrap: wrap; margin: 0 0 18px; padding: 0; font: 500 .85rem var(--font-ui); color: var(--muted); }
.breadcrumbs li + li::before { content: "/"; margin: 0 8px; color: var(--line); }
.breadcrumbs a { color: var(--muted); text-decoration: none; }
.breadcrumbs a:hover { color: var(--brand); text-decoration: underline; }
h1, h2, h3 { font-family: var(--font-ui); color: var(--ink); line-height: 1.25; }
h1 { font-size: clamp(1.9rem, 4vw, 2.6rem); font-weight: 700; letter-spacing: -0.02em; margin: 0 0 10px; }
h2 { font-size: 1.6rem; font-weight: 700; letter-spacing: -0.015em; margin: 2.6em 0 .6em; }
h3 { font-size: 1.2rem; font-weight: 700; margin: 1.8em 0 .4em; }
.meta { font: 500 .85rem var(--font-ui); color: var(--muted); margin: 0 0 20px; }
.lead { font-size: 1.3rem; line-height: 1.55; color: #2B3850; max-width: 62ch; margin: 0 0 1.4em; }
article p, article li { max-width: 70ch; }
article ul, article ol { padding-left: 1.3em; }
article li { margin: .3em 0; }

code { font: 400 .86em var(--font-mono); background: var(--brand-soft); color: #153F82; padding: .12em .4em; border-radius: 4px; }
pre { position: relative; background: var(--code-bg); color: var(--code-ink); border-radius: 8px; padding: 18px 20px; overflow-x: auto; margin: 1.3em 0; border-left: 4px solid var(--accent); }
pre code { background: none; color: inherit; padding: 0; font-size: .88rem; line-height: 1.65; }
.copy-btn { position: absolute; top: 8px; right: 8px; font: 600 .75rem var(--font-ui); background: rgba(255,255,255,.1); color: var(--code-ink); border: 0; border-radius: 4px; padding: 4px 10px; cursor: pointer; }
.copy-btn:hover { background: rgba(255,255,255,.2); }

/* console output under a code block */
pre.output { background: #EEF2F8; color: var(--ink); border-left-color: var(--line); margin-top: -.6em; }
pre.output code { color: var(--ink); }

/* collapsible exercise answers */
details.answer { border: 1px solid var(--line); border-radius: 8px; padding: 4px 18px; margin: 1em 0 1.6em; max-width: 70ch; background: var(--bg); }
details.answer summary { cursor: pointer; font: 700 .98rem var(--font-ui); color: var(--brand); padding: 8px 0; }

.table-wrap { overflow-x: auto; margin: 1.3em 0; }
caption { caption-side: top; text-align: left; font-weight: 700; padding: 0 0 8px; color: var(--muted); }
table { border-collapse: collapse; width: 100%; font: 400 .95rem/1.5 var(--font-ui); }
th, td { text-align: left; padding: 10px 14px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { background: var(--brand-soft); font-weight: 700; white-space: nowrap; }

.toc { background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 14px 22px; margin: 1.6em 0; font-family: var(--font-ui); max-width: 480px; }
.toc strong { display: block; margin-bottom: 4px; }
.toc ol { margin: 0; padding-left: 1.2em; columns: 1; }
.toc a { text-decoration: none; }
.toc a:hover { text-decoration: underline; }

.note { border-left: 4px solid var(--brand); background: var(--brand-soft); padding: 12px 18px; border-radius: 0 8px 8px 0; margin: 1.4em 0; font-family: var(--font-ui); font-size: .98rem; max-width: 70ch; }
.note p { margin: 0; }

/* the one memorable element: a dplyr pipeline made visible */
.pipeline { list-style: none; display: flex; flex-wrap: wrap; align-items: center; gap: 8px 0; padding: 22px 24px; margin: 1.6em 0; background: var(--code-bg); border-radius: 10px; font-family: var(--font-mono); font-size: .9rem; }
.pipeline li { margin: 0; max-width: none; padding: 6px 12px; border: 1px solid #2D4263; border-radius: 6px; color: var(--code-ink); }
.pipeline li + li { margin-left: 42px; position: relative; }
.pipeline li + li::before { content: "|>"; position: absolute; left: -34px; top: 50%; transform: translateY(-50%); color: var(--accent); font-weight: 600; }
.pipeline li:first-child { color: #9DB4D6; border-style: dashed; }
.pipeline li:last-child { border-color: var(--accent); }

/* lesson list */
.lesson-list { list-style: none; padding: 0; margin: .8em 0 1.6em; border-top: 1px solid var(--line); }
.lesson-list li { margin: 0; max-width: none; border-bottom: 1px solid var(--line); }
.lesson-list a { display: grid; grid-template-columns: 230px 1fr; gap: 16px; padding: 12px 8px; text-decoration: none; color: var(--ink); font-family: var(--font-ui); }
.lesson-list a:hover { background: var(--brand-soft); }
.ll-name { font: 600 .92rem var(--font-mono); color: var(--brand); }
.ll-desc { color: var(--muted); font-size: .98rem; }

.faq details { border-bottom: 1px solid var(--line); padding: 4px 0; max-width: 70ch; }
.faq summary { cursor: pointer; font: 700 1.05rem var(--font-ui); padding: 10px 0; }
.faq details p { margin: 0 0 12px; }

/* previous / next */
.pager { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-top: 28px; }
.pager-link { display: flex; flex-direction: column; gap: 2px; padding: 16px 20px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); text-decoration: none; font-family: var(--font-ui); }
.pager-link:hover { border-color: var(--brand); background: var(--brand-soft); }
.pager-link.next { text-align: right; grid-column: 2; }
.pager-dir { font-size: .82rem; color: var(--muted); font-weight: 500; }
.pager-title { font-weight: 700; color: var(--brand); }


/* ---------- buttons ---------- */
.btn { display: inline-block; font: 700 1rem/1.2 var(--font-ui); text-decoration: none; padding: 12px 20px; border-radius: 8px; border: 2px solid transparent; transition: background .15s, border-color .15s, transform .1s; }
.btn:hover { transform: translateY(-1px); }
.btn-primary { background: var(--accent); color: #14233B; }
.btn-primary:hover { background: #F0AE4A; color: #14233B; }
.btn-ghost { background: transparent; color: #fff; border-color: rgba(255,255,255,.35); }
.btn-ghost:hover { background: rgba(255,255,255,.1); color: #fff; border-color: rgba(255,255,255,.6); }
.btn-block { display: block; text-align: center; }

/* ---------- hero ---------- */
.hero { background: radial-gradient(circle at 85% -20%, #2B5797 0%, rgba(43,87,151,0) 55%), linear-gradient(135deg, #14233B 0%, #1B3254 100%); color: var(--menu-ink); border-bottom: 3px solid var(--accent); }
.hero-inner { display: grid; grid-template-columns: minmax(0, 1fr); gap: 40px; align-items: center; padding-top: 30px; padding-bottom: 30px; }
.hero-copy { max-width: 760px; }
.hero p { margin: 0; }
.hero-eyebrow { font: 700 .8rem var(--font-ui); letter-spacing: .12em; text-transform: uppercase; color: var(--accent); margin-bottom: 8px !important; }
.hero-title { font: 700 clamp(1.45rem, 2.6vw, 1.9rem)/1.15 var(--font-ui); letter-spacing: -0.02em; color: #fff; margin-bottom: 8px !important; }
.hero-text { font: 400 1.05rem/1.55 var(--font-ui); color: #C8D4E6; max-width: 62ch; }
.hero-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 18px !important; }
.hero-home .hero-inner { grid-template-columns: minmax(0, 1.15fr) minmax(0, .85fr); padding-top: 56px; padding-bottom: 56px; }
.hero-home .hero-title { font-size: clamp(2rem, 4vw, 3rem); margin-bottom: 14px !important; }
.hero-home .hero-text { font-size: 1.15rem; }
.hero-home .hero-actions { margin-top: 26px !important; }
.hero-code pre { margin: 0; border-left-color: var(--accent); box-shadow: 0 18px 40px rgba(0,0,0,.35); }
.hero-code .c { color: #7F93B2; }
.hero-stats { list-style: none; display: flex; gap: 12px; margin: 16px 0 0; padding: 0; font-family: var(--font-ui); }
.hero-stats li { flex: 1; margin: 0; background: rgba(255,255,255,.06); border: 1px solid rgba(255,255,255,.12); border-radius: 8px; padding: 10px 12px; font-size: .85rem; color: #C8D4E6; }
.hero-stats strong { display: block; font-size: 1.35rem; color: #fff; }

/* ---------- left menu extras ---------- */
.side-sub { margin: 18px 0 6px; font: 700 .78rem var(--font-ui); letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
.side-more li a { color: var(--ink); font-weight: 600; }

/* ---------- right sidebar cards ---------- */
.col-right .side-card, .side-card { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 18px; margin-bottom: 18px; font-family: var(--font-ui); font-size: .95rem; line-height: 1.5; }
.side-card p { margin: 0 0 10px; }
.side-card-title { font-weight: 700; font-size: 1.05rem; color: var(--ink); letter-spacing: -0.01em; }
.side-card-kicker { font-weight: 700; font-size: .75rem; letter-spacing: .1em; text-transform: uppercase; color: var(--accent); margin-bottom: 4px !important; }
.side-card-note { margin: 8px 0 0 !important; text-align: center; font-size: .8rem; color: var(--muted); }
.side-card.side-help { background: linear-gradient(160deg, #14233B, #1F3A63); border-color: #14233B; color: #C8D4E6; }
.side-card.side-help .side-card-title { color: #fff; font-size: 1.2rem; }
.side-help .side-card-note { color: #9DB0CC; }
.side-links { list-style: none; margin: 0; padding: 0; }
.side-links li { margin: 0; border-top: 1px solid var(--line); }
.side-links li:first-child { border-top: 0; }
.side-links a { display: block; padding: 7px 0; color: var(--muted); text-decoration: none; }
.side-links a:hover, .side-links a[aria-current] { color: var(--brand); }
.side-links a[aria-current] { font-weight: 700; }

/* ---------- footer ---------- */
.site-footer { background: var(--footer-bg); color: #B9C6DA; font-family: var(--font-ui); font-size: .95rem; border-top: 3px solid var(--accent); }
.footer-grid { display: grid; grid-template-columns: 1.4fr repeat(4, 1fr); gap: 32px; padding-top: 44px; padding-bottom: 32px; }
.footer-about p { margin: 12px 0 18px; max-width: 34ch; line-height: 1.55; }
.footer-heading { margin: 4px 0 12px; font-weight: 700; color: #fff; font-size: 1rem; }
.footer-col ul { list-style: none; margin: 0; padding: 0; }
.footer-col li { margin: 0 0 8px; }
.site-footer a { color: #B9C6DA; text-decoration: none; }
.site-footer a:hover { color: var(--menu-active); }
.site-footer .brand { color: #fff; }
.site-footer .btn-primary, .site-footer .btn-primary:hover { color: #14233B; }
.footer-bottom { border-top: 1px solid rgba(255,255,255,.1); padding-top: 18px; padding-bottom: 22px; font-size: .85rem; opacity: .8; }
.footer-bottom p { margin: 0; }

/* ---------- responsive ---------- */
@media (max-width: 1099px) {
  .layout { grid-template-columns: 230px minmax(0, 1fr); }
  .col-right { position: static; grid-column: 2; display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 18px; }
  .col-right .side-card { margin-bottom: 0; }
  .footer-grid { grid-template-columns: repeat(3, 1fr); }
  .footer-about { grid-column: 1 / -1; }
  .hero-home .hero-inner { grid-template-columns: 1fr; }
  .hero-code { display: none; }
}
@media (max-width: 899px) {
  .nav-burger { display: block; }
  .main-nav { display: none; position: absolute; top: var(--header-h); left: 0; right: 0; flex-direction: column; gap: 0; background: var(--menu-bg); padding: 8px 14px 16px; border-bottom: 3px solid var(--accent); }
  .main-nav a { padding: 12px 10px; border-radius: 6px; }
  .main-nav a[aria-current] { box-shadow: inset 3px 0 0 var(--menu-active); border-radius: 0; }
  .main-nav a.nav-cta { margin: 8px 0 0; text-align: center; }
  .nav-toggle:checked ~ .main-nav { display: flex; }
  .nav-toggle:checked + .nav-burger span:nth-child(1) { transform: translateY(7px) rotate(45deg); }
  .nav-toggle:checked + .nav-burger span:nth-child(2) { opacity: 0; }
  .nav-toggle:checked + .nav-burger span:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }
}
@media (max-width: 819px) {
  .wrap { padding: 0 14px; }
  .layout, .layout.no-right { grid-template-columns: 1fr; gap: 20px; padding-top: 18px; }
  .col-left { position: static; max-height: none; }
  .col-right { grid-column: 1; }
  .col-main { padding: 24px 18px; border-radius: 8px; }
  .side-nav summary { display: block; cursor: pointer; font-weight: 700; padding: 8px 0; color: var(--brand); }
  .lesson-list a { grid-template-columns: 1fr; gap: 2px; }
  .pager { grid-template-columns: 1fr; }
  .pager-link.next { grid-column: 1; }
  .pipeline li + li { margin-left: 38px; }
  .hero-inner, .hero-home .hero-inner { padding-top: 22px; padding-bottom: 24px; }
  .hero-home .hero-title { font-size: 1.8rem; }
  .btn { padding: 11px 16px; }
  .footer-grid { grid-template-columns: 1fr 1fr; gap: 24px; padding-top: 32px; }
}
@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } }
@media print { .hero, .site-header, .col-left, .col-right, .pager, .site-footer, .copy-btn { display: none; } .layout { display: block; } .col-main { border: 0; padding: 0; } }
