/* The Astronomy Tutorials page (/tutorials/). Builds on site.css. */

:root {
  --tut-panel: rgba(9, 13, 32, 0.86);
  --tut-soft: rgba(143, 180, 255, 0.08);
  --tut-accent: var(--glow-tutorials);
  --tut-top-h: 84px;
  --tut-ok: #6fe3b4;
  --tut-fix: #ff9b7a;
}

html { scroll-behavior: smooth; }
@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } }

/* ---------- Top bar: home | title + revision | author + release ---------- */

.tut-top {
  position: sticky;
  top: 0;
  z-index: 10;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 16px;
  min-height: var(--tut-top-h);
  padding: max(12px, env(safe-area-inset-top)) 24px 12px;
  background: rgba(6, 9, 24, 0.84);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--line);
}

.tut-home {
  justify-self: start;
  padding: 7px 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--ink);
  text-decoration: none;
  font-size: 14px;
  font-weight: 600;
}
.tut-home:hover { background: var(--card-hover); }

.tut-title { text-align: center; }
.tut-title h1 {
  display: inline;
  font-size: clamp(22px, 3vw, 30px);
  letter-spacing: -0.01em;
}
.tut-rev {
  display: inline-block;
  margin-left: 10px;
  padding: 3px 10px;
  border: 1px solid color-mix(in srgb, var(--tut-accent) 50%, transparent);
  border-radius: 999px;
  color: var(--tut-accent);
  font-size: 13px;
  font-weight: 600;
  vertical-align: 5px;
  font-variant-numeric: tabular-nums;
}

.tut-meta { justify-self: end; text-align: right; font-size: 13px; line-height: 1.45; color: var(--muted); }
.tut-meta strong { display: block; color: var(--ink); font-size: 15px; }

/* ---------- Layout: tutorial list on the left, content on the right ---------- */

.tut-layout {
  position: relative;
  display: grid;
  grid-template-columns: 270px minmax(0, 1fr);
  gap: 28px;
  max-width: 1320px;
  margin: 0 auto;
  padding: 28px 24px 48px;
}

.tut-nav {
  position: sticky;
  top: calc(var(--tut-top-h) + 20px);
  align-self: start;
  max-height: calc(100vh - var(--tut-top-h) - 40px);
  overflow-y: auto;
  padding: 18px 14px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--tut-panel);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
}
.tut-nav h2 {
  margin: 0 8px 10px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--accent);
}
.tut-nav ul { list-style: none; margin: 0; padding: 0; }

.tut-row { display: flex; align-items: center; gap: 4px; }
.tut-row > a {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 9px 10px;
  border-radius: 10px;
  color: var(--ink);
  text-decoration: none;
  font-weight: 600;
  font-size: 15px;
}
.tut-row > a:hover { background: var(--tut-soft); }
.tut-row > a[aria-current="page"] {
  background: color-mix(in srgb, var(--tut-accent) 14%, transparent);
  color: var(--tut-accent);
}
.tut-badge {
  padding: 1px 8px;
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
}

/* Expand / collapse a tutorial's section list. The button only shows with JavaScript. */
.tut-toggle {
  display: none;
  flex: none;
  width: 30px;
  height: 30px;
  padding: 0;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: 8px;
  background: none;
  color: var(--muted);
  cursor: pointer;
}
.js .tut-toggle { display: inline-flex; }
.tut-toggle:hover { color: var(--ink); background: var(--tut-soft); }
.tut-toggle:focus-visible { outline: 2px solid var(--tut-accent); outline-offset: 1px; }
.tut-toggle svg { width: 16px; height: 16px; transform: rotate(-90deg); transition: transform 0.2s ease; }
.tut-item.expanded .tut-toggle svg { transform: none; }

/* Section list, in collapsible parts. Without JavaScript every list shows. */
.tut-nav .tut-toc { margin: 4px 0 10px 10px; padding-left: 8px; border-left: 1px solid var(--line); }
.js .tut-item:not(.expanded) .tut-toc { display: none; }
.toc-group > summary {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 6px 0 2px;
  padding: 5px 8px;
  border-radius: 7px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
  cursor: pointer;
  list-style: none;
  user-select: none;
}
.toc-group > summary::-webkit-details-marker { display: none; }
.toc-group > summary::before {
  content: "";
  width: 0;
  height: 0;
  border-left: 5px solid currentColor;
  border-top: 4px solid transparent;
  border-bottom: 4px solid transparent;
  transition: transform 0.2s ease;
}
.toc-group[open] > summary::before { transform: rotate(90deg); }
.toc-group > summary:hover { color: var(--ink); background: var(--tut-soft); }
.toc-group > ul { margin-left: 6px; }
.tut-toc a {
  display: block;
  padding: 4px 8px;
  border-radius: 7px;
  color: var(--muted);
  text-decoration: none;
  font-size: 13.5px;
  line-height: 1.35;
}
.tut-toc a:hover { color: var(--ink); background: var(--tut-soft); }
.tut-toc a.active { color: var(--ink); background: var(--tut-soft); box-shadow: inset 2px 0 0 var(--tut-accent); }

.tut-history { margin: 14px 8px 0; padding-top: 10px; border-top: 1px solid var(--line); font-size: 13px; }
.tut-history a { color: var(--muted); text-decoration: none; }
.tut-history a:hover { color: var(--ink); text-decoration: underline; }

/* ---------- Revision history popup ---------- */

button.tut-rev { background: none; font-family: inherit; cursor: pointer; }
button.tut-rev:hover { background: color-mix(in srgb, var(--tut-accent) 14%, transparent); }

.rev-dialog {
  width: min(560px, calc(100vw - 32px));
  max-height: min(80vh, 640px);
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: #0b1030;
  color: var(--ink);
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.6);
}
.rev-dialog::backdrop { background: rgba(3, 5, 14, 0.6); backdrop-filter: blur(3px); }
.rev-head {
  position: sticky;
  top: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--line);
  background: #0b1030;
}
.rev-head h2 { margin: 0; font-size: 18px; }
.rev-close {
  width: 32px;
  height: 32px;
  border: 0;
  border-radius: 8px;
  background: none;
  color: var(--muted);
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
}
.rev-close:hover { color: var(--ink); background: var(--tut-soft); }
.rev-list { list-style: none; margin: 0; padding: 8px 20px 20px; }
.rev-list > li { padding: 12px 0; border-bottom: 1px solid var(--line); }
.rev-list > li:last-child { border-bottom: 0; }
.rev-meta { margin: 0 0 6px; color: var(--muted); font-size: 13px; }
.rev-meta b { color: var(--tut-accent); font-size: 14px; }
.rev-list ul { margin: 0; padding-left: 20px; font-size: 14px; line-height: 1.5; color: rgba(238, 241, 255, 0.88); }
.rev-list ul li { margin-bottom: 3px; }

/* ---------- Tutorial content ---------- */

.tut-main { min-width: 0; }

.tutorial {
  max-width: 940px;
  padding: 36px 44px 44px;
  border: 1px solid var(--line);
  border-radius: 22px;
  background: var(--tut-panel);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  font-size: 16px;
  line-height: 1.6;
  color: rgba(238, 241, 255, 0.9);
}
.tutorial + .tutorial { margin-top: 28px; }
.js .tutorial[hidden] { display: none; }

.tutorial h1 {
  font-size: clamp(28px, 4vw, 40px);
  margin: 0 0 6px;
}
.tut-sub { margin: 0 0 6px; color: var(--muted); font-size: 16px; }
.tut-updated { margin: 0 0 14px; color: var(--muted); font-size: 13px; }
.tut-download { margin: 0 0 26px; }
.tut-download a {
  display: inline-block;
  padding: 7px 14px;
  border: 1px solid color-mix(in srgb, var(--tut-accent) 50%, transparent);
  border-radius: 999px;
  color: var(--tut-accent);
  font-size: 14px;
  font-weight: 600;
  text-decoration: none;
}
.tut-download a::before { content: "\2193  "; }
.tut-download a:hover { background: color-mix(in srgb, var(--tut-accent) 14%, transparent); }
.tut-download span { margin-left: 8px; color: var(--muted); font-size: 13px; }

.tutorial h2 {
  margin: 40px 0 12px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--line);
  font-size: 22px;
  letter-spacing: -0.01em;
  color: var(--ink);
}
.tutorial h3 { margin: 22px 0 8px; font-size: 17px; color: var(--ink); }
.tutorial .tut-part {
  margin: 56px 0 4px;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--tut-accent);
}
.tutorial .tut-part + h2 { margin-top: 6px; }
.tutorial section, .tutorial h2, .tutorial h3 { scroll-margin-top: calc(var(--tut-top-h) + 20px); }

.tutorial p { margin: 0 0 12px; }
.tutorial ul, .tutorial ol { margin: 0 0 14px; padding-left: 24px; }
.tutorial li { margin-bottom: 6px; }
.tutorial b, .tutorial strong { color: var(--ink); }
.tutorial a { color: var(--accent); }

.tutorial code {
  padding: 1px 6px;
  border-radius: 5px;
  background: rgba(143, 180, 255, 0.12);
  font-family: ui-monospace, Menlo, Consolas, monospace;
  font-size: 0.86em;
  overflow-wrap: anywhere;
}

.tbl { margin: 6px 0 18px; overflow-x: auto; border: 1px solid var(--line); border-radius: 12px; }
.tutorial table { width: 100%; border-collapse: collapse; font-size: 14.5px; line-height: 1.45; }
.tutorial th, .tutorial td { padding: 9px 12px; text-align: left; vertical-align: top; border-bottom: 1px solid var(--line); }
.tutorial tr:last-child td { border-bottom: 0; }
.tutorial th { background: rgba(143, 180, 255, 0.1); color: var(--ink); font-weight: 600; }
.tutorial td:first-child { white-space: nowrap; }
.tutorial td.wrap { white-space: normal; }

.formula {
  margin: 8px 0 12px;
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(143, 180, 255, 0.07);
  font-family: ui-monospace, Menlo, Consolas, monospace;
  font-size: 14.5px;
  color: var(--ink);
}

.note, .finding {
  margin: 14px 0 18px;
  padding: 12px 16px;
  border-left: 3px solid #ff9b7a;
  border-radius: 0 10px 10px 0;
  background: rgba(255, 155, 122, 0.1);
}
.note.teal { border-color: #6fe3b4; background: rgba(111, 227, 180, 0.09); }
.finding { border-color: #a99cff; background: rgba(169, 156, 255, 0.11); }
.note p:last-child, .finding p:last-child { margin-bottom: 0; }

.ok { color: var(--tut-ok); font-weight: 600; }
.fix { color: var(--tut-fix); font-weight: 600; }
.swatch { display: inline-block; width: 11px; height: 11px; margin-right: 6px; border: 1px solid; border-radius: 3px; vertical-align: -1px; }

.shot { margin: 14px 0 20px; text-align: center; }
.shot a { display: inline-block; max-width: 100%; }
.shot img {
  display: block;
  max-width: 100%;
  height: auto;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
}
.shot.small img { max-width: min(100%, 520px); margin: 0 auto; }
.shot.diagram img { max-width: min(100%, 560px); margin: 0 auto; padding: 8px; }
.caption { margin-top: 8px; font-size: 13px; color: var(--muted); }

.soon-box {
  padding: 22px;
  border: 1px dashed var(--line);
  border-radius: 14px;
  color: var(--muted);
}

/* ---------- Narrow screens ---------- */

@media (max-width: 900px) {
  :root { --tut-top-h: 0px; }
  .tut-top {
    position: static;
    grid-template-columns: 1fr;
    justify-items: center;
    text-align: center;
    gap: 8px;
    padding: max(16px, env(safe-area-inset-top)) 16px 14px;
  }
  .tut-title { order: 1; }
  .tut-meta { order: 2; justify-self: center; text-align: center; }
  .tut-meta strong { display: inline; margin-right: 6px; }
  .tut-home { order: 3; justify-self: center; }

  .tut-layout { grid-template-columns: 1fr; gap: 16px; padding: 16px 16px 40px; }
  .tut-nav { position: static; max-height: none; padding: 12px; }
  .tut-nav .tut-toc { max-height: 60vh; overflow-y: auto; }
  .rev-dialog { max-height: 85vh; }

  .tutorial { padding: 24px 18px 30px; border-radius: 16px; font-size: 15.5px; }
  .tutorial td:first-child { white-space: normal; }
}

/* ---------- Print: the WBPP PDF is printed from this page ---------- */

@media print {
  @page { size: letter; margin: 0.6in 0.65in; }
  :root {
    --ink: #1f1f1d;
    --muted: #5f5e5a;
    --line: #d3d1c7;
    --accent: #2f4fb8;
    --tut-accent: #0f6e56;
    --tut-ok: #0f6e56;
    --tut-fix: #993c1d;
    color-scheme: light;
  }
  html { scroll-behavior: auto; }
  body { background: #fff; color: #2c2c2a; }
  .sky, .tut-top, .tut-nav, .tut-download, #nina-setup, .rev-dialog { display: none !important; }
  .tut-layout { display: block; max-width: none; padding: 0; }
  .tutorial, .js .tutorial[hidden] {
    display: block;
    max-width: none;
    padding: 0;
    border: 0;
    border-radius: 0;
    background: none;
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
    color: #2c2c2a;
    font-size: 10.5pt;
    line-height: 1.45;
  }
  .tutorial h1 { background: none; color: #1f1f1d; -webkit-text-fill-color: #1f1f1d; font-size: 20pt; }
  .tutorial h2 { margin: 18pt 0 6pt; font-size: 13pt; }
  .tutorial h3 { margin: 12pt 0 4pt; font-size: 11pt; }
  .tutorial h2, .tutorial h3 { break-after: avoid; }
  .tut-sub, .tut-updated { font-size: 10pt; }
  .tutorial .tut-part { break-before: page; margin-top: 0; font-size: 11pt; }
  .tutorial h2[id^="wbpp-step-"] { break-before: page; margin-top: 0; }
  .tutorial a { color: inherit; text-decoration: none; }
  .tutorial code { background: #f1efe8; }
  .tbl { overflow: visible; border-radius: 0; break-inside: avoid; }
  .tutorial table { font-size: 9.5pt; }
  .tutorial th, .tutorial td { padding: 5pt 7pt; }
  .tutorial th { background: #f1efe8; }
  .tutorial tr, .tutorial li { break-inside: avoid; }
  .formula { background: #f7f6f2; font-size: 10pt; }
  .note { background: #faece7; border-color: #993c1d; break-inside: avoid; }
  .note.teal { background: #e1f5ee; border-color: #0f6e56; }
  .finding { background: #eeedfe; border-color: #534ab7; break-inside: avoid; }
  .shot { break-inside: avoid; margin: 4pt 0 8pt; }
  .shot img { width: auto; max-height: 3.5in; border-radius: 0; }
  .shot.small img { max-height: 3in; }
  .shot.diagram { break-after: page; }
  .shot.diagram img { max-height: 7.2in; padding: 0; border: 0; }
  .caption { font-size: 9pt; }
}
