/* ========================================
   SECTION INDEX — sticky in the label column
======================================== */

/* Rides up with About, then sticks at 6rem. Zero height and negative margin:
   takes no room in the flow */
aside.rail {
  position: sticky;
  top: 1rem;
  z-index: 100;
  width: var(--col-label);
  height: 0;
  margin: 0 var(--page-inline) -5rem;
  padding-top: 5rem;
  /* Drops to meet the last section at the end of the page (nav.js) */
  translate: 0 var(--rail-drop, 0px);
  transition: translate 0.5s cubic-bezier(0.25, 1, 0.5, 1);
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 1.5rem;
}

/* Lands a section's content level with its label: 1.8rem per label above
   (1rem × 1.4 line height + 0.4rem gap), plus the active label's 1rem margin */
main > section:not(.hero) {
  scroll-margin-top: calc(
    1rem + var(--rail-index, 0) * 1.8rem + min(var(--rail-index, 0), 1) * 1rem
  );
}

.rail-nav {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.4rem;
}

.rail-link {
  text-decoration: none;
}

.rail-label {
  display: block;
  font-size: var(--font-size-secondary);
  line-height: 1.4;
  color: var(--muted);
  transition:
    font-size var(--t-label),
    margin var(--t-label),
    line-height var(--t-label),
    letter-spacing var(--t-label),
    color var(--t-fast);
}

.rail-link:first-child.is-active .rail-label {
  margin-top: 0;
}

.rail-link:hover .rail-label {
  color: var(--text-color);
}

.rail-link.is-active .rail-label {
  margin-block: 1rem;
  font-family: var(--font-heading);
  font-size: var(--font-size-h2);
  font-weight: 500;
  line-height: 1.05;
  letter-spacing: -0.02em;
  color: var(--text-color);
}

/* ============ LANGUAGE + THEME ============ */
.rail-tools,
.rail-langs,
.rail-themes,
.mob-tools,
.mob-langs,
.mob-themes {
  display: flex;
  align-items: center;
}

.rail-tools {
  gap: 0.25rem;
  margin-left: -0.4rem;
}

.rail-tools .lang-option,
.rail-tools .theme-option,
.mob-tools .lang-option,
.mob-tools .theme-option {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  font-family: var(--font-body);
  color: var(--muted);
  cursor: pointer;
  transition: color var(--t-fast);
}

.rail-tools .lang-option:hover,
.rail-tools .theme-option:hover,
.mob-tools .lang-option:hover,
.mob-tools .theme-option:hover {
  color: var(--text-color);
}

.rail-tools .lang-option,
.rail-tools .theme-option {
  height: 2rem;
  max-width: 2.5rem;
  padding: 0 0.4rem;
  overflow: hidden;
  white-space: nowrap;
  font-size: var(--font-size-small);
  transition:
    color var(--t-fast),
    max-width var(--t-label),
    padding var(--t-label),
    opacity var(--t-label),
    visibility 0s;
}

/* Only the active option shows until hover or focus; the others leave the
   tab order once collapsed */
.rail-langs .lang-option:not(.active),
.rail-themes .theme-option:not(.active) {
  max-width: 0;
  padding-inline: 0;
  opacity: 0;
  visibility: hidden;
  transition-delay: 0s, 0s, 0s, 0s, 420ms;
}

.rail-langs:is(:hover, :has(:focus-visible)) .lang-option,
.rail-themes:is(:hover, :has(:focus-visible)) .theme-option {
  max-width: 2.5rem;
  padding-inline: 0.4rem;
  opacity: 1;
  visibility: visible;
  transition-delay: 0s;
}

/* The active option leads (preferences.js) */
.rail-langs .lang-option.lead,
.rail-themes .theme-option.lead {
  order: -1;
}

@media (prefers-reduced-motion: reduce) {
  .rail-tools .lang-option,
  .rail-tools .theme-option {
    transition: color var(--t-fast);
  }
}

.rail-themes svg {
  width: 0.9375rem;
  height: 0.9375rem;
}

/* ============ MOBILE NAV ============ */
.mob-fab,
.mob-drawer {
  display: none;
  background: var(--background-color);
  border: 0.0625rem solid var(--border-color);
}

@media (max-width: 56.25rem) {
  aside.rail {
    display: none;
  }

  main > section:not(.hero) {
    scroll-margin-top: 1rem;
  }

  .mob-fab {
    display: flex;
    position: fixed;
    bottom: 1.5rem;
    right: 1.5rem;
    width: 2.75rem;
    height: 2.75rem;
    border-radius: 50%;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 200;
    color: var(--text-color);
    transition: transform var(--t-fast);
  }

  .mob-fab:hover {
    transform: scale(1.06);
  }

  .mob-fab-icon {
    width: 1.125rem;
    height: 1.125rem;
  }

  .mob-fab-icon--close {
    display: none;
    position: absolute;
  }

  .mob-fab.open .mob-fab-icon--open {
    display: none;
  }

  .mob-fab.open .mob-fab-icon--close {
    display: block;
  }

  .mob-drawer {
    display: block;
    position: fixed;
    bottom: 5.5rem;
    right: 1.5rem;
    min-width: 11rem;
    border-radius: 1rem;
    z-index: 199;
    transform-origin: bottom right;
    opacity: 0;
    transform: scale(0.92) translateY(0.375rem);
    pointer-events: none;
    transition: opacity 0.2s ease, transform 0.22s cubic-bezier(0.25, 1, 0.5, 1);
  }

  .mob-drawer.open {
    opacity: 1;
    transform: scale(1) translateY(0);
    pointer-events: auto;
  }

  .mob-links {
    display: flex;
    flex-direction: column;
    padding: 0.5rem;
    gap: 0.1rem;
  }

  .mob-link {
    display: flex;
    align-items: center;
    height: 2.5rem;
    padding: 0 0.75rem;
    border-radius: 0.6rem;
    text-decoration: none;
    font-size: var(--font-size-secondary);
    color: var(--muted);
    transition: color var(--t-fast), background var(--t-fast);
  }

  .mob-link:hover {
    color: var(--text-color);
    background: color-mix(in srgb, var(--text-color) 6%, transparent);
  }

  .mob-link.is-active {
    color: var(--text-color);
    background: color-mix(in srgb, var(--text-color) 7%, transparent);
  }

  .mob-tools {
    padding: 0.5rem 0.6rem;
    border-top: 0.0625rem solid var(--border-color);
    gap: 0.25rem;
  }

  .mob-tools .lang-option,
  .mob-tools .theme-option {
    font-size: var(--font-size-secondary);
    height: 2.5rem;
    padding: 0 0.7rem;
    border-radius: 0.5rem;
  }

  .mob-langs .lang-option:not(.active),
  .mob-themes .theme-option:not(.active) {
    display: none;
  }

  .mob-themes svg {
    width: 1.125rem;
    height: 1.125rem;
  }

  .mob-sep {
    width: 0.0625rem;
    height: 0.875rem;
    background: var(--border-color);
    margin: 0 0.2rem;
    flex-shrink: 0;
  }
}

/* ========================================
   FOOTER
======================================== */

footer {
  padding: 0 0 3.5rem;
}

.footer-inner {
  align-items: baseline;
}

.footer-name,
.footer-meta {
  padding-top: 2rem;
}

.footer-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem 2rem;
  border-top: 0.0625rem solid var(--border-color);
}

.footer-name {
  font-family: var(--font-heading);
  font-size: var(--font-size-secondary);
  color: var(--text-color);
  letter-spacing: 0.01em;
  text-decoration: none;
}

@media (hover: hover) {
  .footer-name:hover {
    text-decoration: underline;
  }
}

.footer-year {
  margin-left: auto;
  font-size: var(--font-size-small);
  color: var(--muted);
}

.footer-made {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  font-size: var(--font-size-small);
  color: var(--muted);
}

.footer-cross {
  width: auto;
  height: 1.5em;
  color: var(--asturias-cross);
  flex-shrink: 0;
}

@media (max-width: 56.25rem) {
  /* Centred and stacked, like the hero */
  footer {
    padding: 0 0 3rem;
  }

  .footer-inner {
    justify-items: center;
    text-align: center;
    border-top: 0.0625rem solid var(--border-color);
  }

  .footer-name {
    padding-top: 2.5rem;
  }

  .footer-meta {
    flex-direction: column;
    gap: 0.375rem;
    padding-top: 0.75rem;
    border-top: none;
  }

  .footer-year {
    margin-left: 0;
  }
}
