/* ==================== GUIDE PAGE STYLES ==================== */

/* Additional CSS variables specific to guide pages */
:root {
  --toc-radius: 10px;
  --toc-sticky-top: 10px;
  --toc-open-max: 560px;
  --toc-compact-min: 250px;
  --toc-compact-max: 20vh;
}

/* ------------------ BASE ------------------ */

/* Cover iOS Safari overscroll/rubber-band areas with the background color */
html {
  background: var(--bg1);
}

body {
  margin: 0;
  font-family: system-ui, sans-serif;
  background: linear-gradient(180deg, var(--bg1), var(--bg2));
  color: var(--text);

  display: block;
  height: auto;
}

body::after {
  content: "";
  position: fixed;
  inset: 0;

  background:
    repeating-linear-gradient(
      0deg,
      rgba(255, 255, 255, 0.015),
      rgba(255, 255, 255, 0.015) 1px,
      transparent 1px,
      transparent 2px
    );

  opacity: 0.25;
  pointer-events: none;
  z-index: 0;
}

/* ------------------ LAYOUT ------------------ */

.guide-container {
  max-width: 900px;
  margin: 0 auto;
  padding: 60px 24px 80px;
  position: relative;
}

.guide-header h1 {
  text-align: center;
}

.guide-main-title {
  display: block;
  min-height: 68px;
  overflow: visible;
  color: transparent;
  opacity: 0;
  text-shadow: none;
  transition: opacity 160ms ease-out;
}

.guide-main-title svg {
  display: block;
  max-width: 100%;
  height: auto;
  margin: 0 auto;
  overflow: visible;
}

.guide-main-title.guide-title-svg-ready,
.guide-main-title.guide-title-fallback {
  opacity: 1;
}

.guide-main-title.guide-title-fallback {
  color: var(--accent);
}

.guide-main-title.title-glow-active svg {
  filter:
    drop-shadow(0 0 6px rgba(95, 208, 255, 0.45))
    drop-shadow(0 0 14px rgba(95, 208, 255, 0.18));
}

.guide-toc,
.guide-container > h2,
.guide-container > h3,
.guide-container > h4,
.guide-container > p,
.guide-container > hr,
.guide-container > .guide-box,
.guide-container > ul > li,
.guide-container > ol > li {
  opacity: 0;
  visibility: hidden;
}

.guide-container::before,
.guide-container::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  pointer-events: none;
  opacity: 0;
  z-index: 2;
}

.guide-container::before {
  display: none;
}

.guide-container::after {
  top: calc(var(--guide-scan-core-from, 0px) - 11px);
  height: 22px;
  background: rgba(95, 208, 255, 0.14);
  z-index: 50;
}

.guide-container.guide-scanning::before,
.guide-container.guide-scanning::after {
  opacity: 1;
}

.guide-container.guide-scanning::before {
  animation: none;
}

.guide-container.guide-scanning::after {
  animation: guide-scan 2000ms linear forwards;
}

@keyframes guide-scan {
  from { top: calc(var(--guide-scan-core-from, 0px) - 11px); }
  to { top: calc(100% + 11px); }
}

/* ------------------ HEADINGS ------------------ */

h1 {
  margin: 0 0 8px;
  font-size: 3rem;
  line-height: 1.1;

  text-shadow:
    0 0 10px rgba(95, 208, 255, 0.28),
    0 0 24px rgba(95, 208, 255, 0.12);
}

h2 {
  margin: 32px 0 8px;
  color: var(--accent);

  position: relative;
  padding: 10px 0;

  text-shadow:
    0 0 8px rgba(95, 208, 255, 0.35),
    0 0 20px rgba(95, 208, 255, 0.18);
}

h2::before {
  content: "";
  position: absolute;

  left: -16px;
  right: -16px;
  top: 0;
  bottom: 0;

  background: linear-gradient(
    90deg,
    rgba(95, 208, 255, 0.06),
    rgba(255, 255, 255, 0.02)
  );

  border-radius: 8px;
  z-index: -1;
}

h2:first-of-type {
  margin-top: 0;
}

h2 + * {
  margin-left: 6px;
}

h3 {
  margin: 24px 0 6px;
  color: var(--accent);
  text-shadow:
    0 0 8px rgba(95, 208, 255, 0.35),
    0 0 20px rgba(95, 208, 255, 0.18);
}

hr {
  border: none;
  height: 1px;
  background: linear-gradient(to right, transparent, rgba(95, 208, 255, 0.35), transparent);
  margin: 40px 0;
  opacity: 0.6;
}

/* ------------------ TEXT ------------------ */

p { margin: 0; }
p + p { margin-top: 12px; }
h2 + p { margin-top: 6px; }

/* ------------------ LINKS ------------------ */

.guide-container a {
  color: var(--accent);
  text-decoration: none;
  border-bottom: 1px solid rgba(95, 208, 255, 0.3);
  
  transition:
    border-color .2s ease,
    text-shadow .2s ease;
}

.guide-container a:hover {
  border-bottom-color: var(--accent);
  text-shadow:
    0 0 8px rgba(95, 208, 255, 0.5);
}

.guide-container h1,
.guide-container h2,
.guide-container h3,
.guide-container h4 {
  scroll-margin-top: 220px;
}

/* ------------------ LISTS ------------------ */

.guide-container ul,
.guide-container ol {
  padding-left: 22px;
  margin: 8px 0;
}

.guide-container li {
  margin: 5px 0;
  line-height: 1.6;
}

/* ------------------ BOXES ------------------ */

.guide-box {
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 10px;

  padding: 16px 18px;
  margin: 12px 0;

  box-shadow:
    0 0 10px rgba(95, 208, 255, 0.08),
    0 0 20px rgba(95, 208, 255, 0.04);

  display: flex;
  flex-direction: column;
  justify-content: center;
  min-height: 48px;
}

.guide-box--important {
  border-color: rgba(255, 80, 80, 0.4);
}

.guide-box--note {
  border-color: rgba(95, 208, 255, 0.4);
}

.guide-box ul,
.guide-box ol {
  margin: 0;
  padding-left: 20px;
}

.guide-box li { margin: 6px 0; }

.guide-box p {
  margin: 0;
}

.guide-box p + p {
  margin-top: 12px;
}

.guide-box ul + p,
.guide-box ol + p {
  margin-top: 12px;
}

.guide-muted {
  color: var(--muted);
  font-size: 0.95rem;
}

.guide-container ol + .guide-box,
.guide-container ul + .guide-box {
  margin: 6px;
}

/* ------------------ TOC ------------------ */

.guide-toc {
  margin: 24px 0 32px;

  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: var(--toc-radius);

  background: linear-gradient(180deg, var(--bg1), var(--bg2));

  position: sticky;
  top: var(--toc-sticky-top);
  z-index: 10;

  overflow: hidden;

  transition:
    background .25s ease,
    border-color .25s ease,
    box-shadow .25s ease;
}

.guide-toc.compact {
  border-color: rgba(255, 255, 255, 0.05);
  box-shadow: 0 8px 26px rgba(0, 0, 0, 0.18);
}

/* TOGGLE */

.guide-toc-toggle {
  width: 100%;
  text-align: left;
  padding: 6px 18px;

  position: relative;

  background: none;
  border: none;

  color: var(--accent);
  cursor: pointer;

  font-size: 1.1rem;
  font-weight: 500;

  display: flex;
  align-items: center;
  justify-content: space-between;

  text-shadow:
    0 0 6px rgba(95, 208, 255, 0.25);

  transition:
    background 0.2s ease,
    text-shadow 0.2s ease;
}

.guide-toc-toggle:hover {
  background: rgba(255, 255, 255, 0.02);
  text-shadow:
    0 0 8px rgba(95, 208, 255, 0.4);
}

.guide-toc-toggle::after {
  content: "+";
  font-size: 1.6rem;
  line-height: 1;
  transition: none;
}

.guide-toc.open .guide-toc-toggle::after {
  content: "−";
}

/* Initial hint animation */
@keyframes toc-hint-pulse {
  0%, 100% { 
    text-shadow:
      0 0 6px rgba(95, 208, 255, 0.25);
  }
  50% { 
    text-shadow:
      0 0 12px rgba(95, 208, 255, 0.6),
      0 0 24px rgba(95, 208, 255, 0.3);
  }
}

.guide-toc-toggle.hint-active {
  animation: toc-hint-pulse 1.2s ease-in-out 2;
}

/* CONTENT */

.guide-toc-content {
  max-height: 0;
  overflow: hidden;
  padding: 0 18px;

  transition:
    max-height .28s cubic-bezier(0.22, 1, 0.36, 1),
    padding .28s cubic-bezier(0.22, 1, 0.36, 1);
}

.guide-toc.open .guide-toc-content {
  max-height: min(var(--toc-open-max), 60vh);
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 4px 18px 14px;
}

.guide-toc.open.compact .guide-toc-content {
  min-height: var(--toc-compact-min);
  max-height: var(--toc-compact-max);
  overflow-y: auto;
}

/* SCROLLBAR STYLING */

.guide-toc-content::-webkit-scrollbar {
  width: 4px;
}

.guide-toc-content::-webkit-scrollbar-track {
  background: transparent;
}

.guide-toc-content::-webkit-scrollbar-thumb {
  background: rgba(95, 208, 255, 0);
  border-radius: 2px;
  transition: background 0.3s ease;
}

/* Show scrollbar only in compact mode when hovering TOC */
.guide-toc.compact:hover .guide-toc-content::-webkit-scrollbar-thumb {
  background: rgba(95, 208, 255, 0.25);
}

.guide-toc.compact .guide-toc-content::-webkit-scrollbar-thumb:hover {
  background: rgba(95, 208, 255, 0.45);
}

/* Firefox scrollbar - hidden by default, visible on compact hover */
.guide-toc-content {
  scrollbar-width: none;
  scrollbar-color: transparent transparent;
  scrollbar-gutter: auto;
}

.guide-toc.compact:hover .guide-toc-content {
  scrollbar-width: thin;
  scrollbar-color: rgba(95, 208, 255, 0.25) transparent;
}

.guide-toc.compact::after {
  content: "";
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 32px;

  background: linear-gradient(to bottom, transparent, var(--bg2));
  pointer-events: none;
}

/* LISTS */

.guide-toc ul {
  list-style: none;
  margin: 0;
  padding: 0;
}

.guide-toc li ul {
  display: block;
  max-height: 0;
  opacity: 0;
  transform: translateY(-4px);
  overflow: hidden;
  padding-left: 14px;
  pointer-events: none;

  transition:
    max-height .24s cubic-bezier(0.22, 1, 0.36, 1),
    opacity .18s ease,
    transform .24s cubic-bezier(0.22, 1, 0.36, 1);
}

.guide-toc li.open > ul {
  max-height: 360px;
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

/* LINKS */

.guide-toc a {
  display: block;
  padding: 4px 12px;

  position: relative;

  border-radius: 6px;
  border-bottom: none;

  color: var(--muted);
  text-decoration: none;

  transition:
    color .2s ease,
    background .2s ease,
    text-shadow .2s ease;
}

.guide-toc a:hover {
  color: var(--accent);
  border-bottom: none;
  text-shadow: none;
}

.guide-toc li {
  margin: 2px 0;
  border-bottom: none;
  position: relative;
}

.guide-toc li::after {
  content: "";
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 1px;
  background: linear-gradient(to right, transparent, rgba(95, 208, 255, 0.18), transparent);
}

.guide-toc li:last-child::after {
  display: none;
}

/* EXPAND TOGGLE */

.toc-row {
  display: flex;
  align-items: stretch;
  border-radius: 6px;

  transition:
    background .2s ease;
}

.toc-row:hover {
  background: rgba(255, 255, 255, 0.02);
}

.toc-row > a {
  flex: 1;
  padding: 4px 4px 4px 12px;
  border-radius: 6px 0 0 6px;
}

.toc-row > a:hover {
  background: none;
}

.toc-row > a.active {
  background: none;
}

.toc-row:has(a.active) {
  background: linear-gradient(
    90deg,
    rgba(95, 208, 255, 0.10),
    rgba(95, 208, 255, 0.03)
  );
}

.toc-expand {
  flex-shrink: 0;
  width: clamp(44px, 10%, 84px);

  background: none;
  border: none;
  cursor: pointer;

  color: var(--muted);
  font-size: 1.1rem;
  line-height: 1;

  display: flex;
  align-items: center;
  justify-content: center;

  border-radius: 0 6px 6px 0;

  transition: color .2s ease;
}

.toc-expand:hover {
  color: var(--accent);
}

.toc-expand:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
  border-radius: 4px;
}

.guide-toc a.active {
  color: var(--accent);

  text-shadow:
    0 0 6px rgba(95, 208, 255, 0.35);
}

.guide-toc a.active:not(.toc-row a) {
  background: linear-gradient(
    90deg,
    rgba(95, 208, 255, 0.10),
    rgba(95, 208, 255, 0.03)
  );
}

.guide-toc a.active::before {
  content: "";
  position: absolute;

  left: -8px;
  top: 50%;
  transform: translateY(-50%);

  width: 3px;
  height: 60%;

  border-radius: 2px;
  background: var(--accent);

  box-shadow:
    0 0 8px rgba(95, 208, 255, 0.6);
}

.guide-toc.guide-revealed,
.guide-container > h2.guide-revealed,
.guide-container > h3.guide-revealed,
.guide-container > h4.guide-revealed,
.guide-container > p.guide-revealed,
.guide-container > hr.guide-revealed,
.guide-container > .guide-box.guide-revealed,
.guide-container > ul > li.guide-revealed,
.guide-container > ol > li.guide-revealed {
  opacity: 1;
  visibility: visible;
  filter:
    drop-shadow(0 0 6px rgba(127, 227, 255, 0.42))
    drop-shadow(0 0 12px rgba(95, 208, 255, 0.18));
  transition: opacity 80ms ease-out, filter 140ms ease-out;
}

.guide-toc.guide-glow-settled,
.guide-container > h2.guide-glow-settled,
.guide-container > h3.guide-glow-settled,
.guide-container > h4.guide-glow-settled,
.guide-container > p.guide-glow-settled,
.guide-container > hr.guide-glow-settled,
.guide-container > .guide-box.guide-glow-settled,
.guide-container > ul > li.guide-glow-settled,
.guide-container > ol > li.guide-glow-settled {
  filter: none;
}

.guide-toc.guide-revealed {
  opacity: 1;
  transition:
    opacity 50ms ease-out,
    filter 140ms ease-out,
    background .25s ease,
    border-color .25s ease,
    box-shadow .25s ease;
}


/* ------------------ MOBILE (max-width: 768px) ------------------ */

@media (max-width: 768px) {
  .guide-container {
    padding: 40px 16px 60px;
  }

  h2::before {
    left: 0;
    right: 0;
  }

  h1, h2, h3, h4 {
    scroll-margin-top: 80px;
  }

  .guide-main-title {
    max-width: 100%;
    overflow: hidden;
  }

  .guide-toc-toggle {
    min-height: 44px;
    touch-action: manipulation;
  }

  .guide-toc-toggle:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
  }
}


/* ------------------ MOBILE SMALL (max-width: 480px) ------------------ */

@media (max-width: 480px) {
  .guide-container {
    padding: 32px 16px 32px;
  }
}
