/* Floating table of contents — student tools page */

:root {
  --toc-z: 1205;
  --toc-backdrop-z: 1200;
  --toc-offset: 20px;
  --toc-float-w: 272px;
  --toc-desktop-min: 1024px;
}

.page-toc {
  position: fixed;
  z-index: var(--toc-z);
  pointer-events: none;
}

.page-toc > * {
  pointer-events: auto;
}

.page-toc[hidden] {
  display: none;
}

/* Mobile FAB */
.page-toc-toggle {
  position: fixed;
  left: max(var(--toc-offset), env(safe-area-inset-left, 0px));
  bottom: max(var(--toc-offset), env(safe-area-inset-bottom, 0px));
  z-index: 3;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  border: 1px solid var(--border, #e4e4e7);
  border-radius: 999px;
  background: #ffffff;
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
  box-shadow:
    0 4px 6px rgba(0, 0, 0, 0.04),
    0 16px 40px rgba(0, 0, 0, 0.12);
  color: var(--text, #09090b);
  font-family: var(--font, "Inter", system-ui, sans-serif);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: -0.02em;
  cursor: pointer;
  transition:
    transform 0.2s cubic-bezier(0.22, 1, 0.36, 1),
    box-shadow 0.2s ease,
    border-color 0.2s ease;
}

.page-toc-toggle:hover {
  transform: translateY(-2px);
  border-color: var(--border-strong, #d4d4d8);
  box-shadow:
    0 8px 12px rgba(0, 0, 0, 0.06),
    0 20px 48px rgba(0, 0, 0, 0.14);
}

.page-toc-toggle:focus-visible {
  outline: 2px solid var(--accent, #2563eb);
  outline-offset: 2px;
}

.page-toc.is-open .page-toc-toggle {
  opacity: 0;
  transform: translateY(8px) scale(0.96);
  pointer-events: none;
}

.page-toc-toggle-icon {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  color: var(--accent, #2563eb);
}

/* Mobile backdrop */
.page-toc-backdrop {
  position: fixed;
  inset: 0;
  z-index: 1;
  border: none;
  background: rgba(9, 9, 11, 0.35);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  opacity: 0;
  transition: opacity 0.25s ease;
}

.page-toc-backdrop[hidden] {
  display: block;
  visibility: hidden;
  opacity: 0;
  pointer-events: none;
}

.page-toc.is-open .page-toc-backdrop {
  visibility: visible;
  opacity: 1;
  pointer-events: auto;
}

/* Floating panel */
.page-toc-panel {
  position: fixed;
  left: max(var(--toc-offset), env(safe-area-inset-left, 0px));
  bottom: max(var(--toc-offset), env(safe-area-inset-bottom, 0px));
  z-index: 2;
  width: min(var(--toc-float-w), calc(100vw - var(--toc-offset) * 2));
  max-height: min(70vh, 70svh);
  border-radius: var(--radius-lg, 16px);
  border: 1px solid rgba(255, 255, 255, 0.72);
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(20px) saturate(180%);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  box-shadow:
    0 4px 6px rgba(0, 0, 0, 0.03),
    0 20px 50px rgba(0, 0, 0, 0.14);
  overflow: hidden;
  transform: translateY(12px) scale(0.96);
  opacity: 0;
  visibility: hidden;
  transition:
    transform 0.28s cubic-bezier(0.22, 1, 0.36, 1),
    opacity 0.22s ease,
    visibility 0.22s ease;
  pointer-events: none;
}

.page-toc-panel[hidden] {
  display: block;
}

.page-toc.is-open .page-toc-panel {
  transform: translateY(0) scale(1);
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}

.page-toc-inner {
  display: flex;
  flex-direction: column;
  max-height: inherit;
}

.page-toc-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  width: 100%;
  padding: 14px 16px 10px;
  border: none;
  background: transparent;
  font: inherit;
  text-align: left;
  cursor: pointer;
  flex-shrink: 0;
  color: inherit;
  transition: background 0.15s ease;
}

.page-toc-header:hover {
  background: rgba(244, 244, 245, 0.65);
}

.page-toc-header:focus-visible {
  outline: 2px solid var(--accent, #2563eb);
  outline-offset: -2px;
}

.page-toc-heading {
  margin: 0;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: -0.02em;
  color: var(--text, #09090b);
}

.page-toc-chevron {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  margin-left: auto;
  color: var(--text-muted, #a1a1aa);
  transition: transform 0.2s ease;
}

.page-toc.is-expanded .page-toc-chevron {
  transform: rotate(180deg);
}

.page-toc-meta {
  font-size: 11px;
  font-weight: 500;
  color: var(--text-muted, #a1a1aa);
  padding: 3px 8px;
  border-radius: 999px;
  background: var(--bg-muted, #f4f4f5);
  border: 1px solid var(--border, #e4e4e7);
  white-space: nowrap;
}

.page-toc-nav {
  overflow: auto;
  padding: 4px 10px 12px;
  scrollbar-width: thin;
  scrollbar-color: var(--border-strong, #d4d4d8) transparent;
}

.page-toc-nav::-webkit-scrollbar {
  width: 5px;
}

.page-toc-nav::-webkit-scrollbar-thumb {
  background: var(--border-strong, #d4d4d8);
  border-radius: 999px;
}

.page-toc-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.page-toc-item.is-hidden {
  display: none;
}

.page-toc-item--featured .page-toc-link {
  font-weight: 600;
  color: var(--text, #09090b);
}

.page-toc-link {
  position: relative;
  display: block;
  padding: 8px 10px 8px 14px;
  border-radius: var(--radius-sm, 8px);
  font-size: 13px;
  font-weight: 500;
  line-height: 1.35;
  color: var(--text-secondary, #52525b);
  text-decoration: none;
  transition:
    background 0.15s ease,
    color 0.15s ease,
    padding-left 0.15s ease;
}

.page-toc-link::before {
  content: "";
  position: absolute;
  left: 4px;
  top: 50%;
  width: 3px;
  height: 0;
  border-radius: 999px;
  background: var(--accent, #2563eb);
  transform: translateY(-50%);
  transition: height 0.18s ease;
}

.page-toc-link:hover {
  background: rgba(244, 244, 245, 0.85);
  color: var(--text, #09090b);
}

.page-toc-link.is-active {
  background: rgba(37, 99, 235, 0.08);
  color: var(--accent, #2563eb);
  padding-left: 16px;
}

.page-toc-link.is-active::before {
  height: 60%;
}

.tool-category {
  scroll-margin-top: calc(var(--header-h, 52px) + 20px);
}

/* Desktop: persistent floating card, left side */
@media (min-width: 1024px) {
  .page-toc-toggle,
  .page-toc-backdrop {
    display: none !important;
  }

  .page-toc-panel {
    top: calc(var(--header-h, 52px) + 20px);
    bottom: auto;
    left: max(var(--toc-offset), calc((100vw - var(--directory-max, 1200px)) / 2 - var(--toc-float-w) - 28px));
    max-height: calc(100vh - var(--header-h, 52px) - 40px);
    max-height: calc(100svh - var(--header-h, 52px) - 40px);
    transform: none;
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
  }

  .page-toc.is-open .page-toc-panel {
    transform: none;
  }

  .page-toc-panel[hidden] {
    display: flex !important;
    flex-direction: column;
  }

  .page-toc-inner {
    flex: 1;
    min-height: 0;
  }

  .page-toc-nav {
    flex: 1;
    min-height: 0;
    -webkit-overflow-scrolling: touch;
  }

  .page-toc-link {
    font-size: 12px;
    padding: 7px 10px 7px 14px;
  }

  .page-toc:not(.is-expanded) .page-toc-nav {
    display: none;
  }

  .page-toc:not(.is-expanded) .page-toc-header {
    padding-bottom: 14px;
  }

  .page-toc:not(.is-expanded) .page-toc-panel {
    max-height: none;
  }
}

/* Hide floating TOC when viewport is too narrow for side float */
@media (min-width: 1024px) and (max-width: 1180px) {
  .page-toc-panel {
    left: var(--toc-offset);
  }
}

@media (prefers-reduced-motion: reduce) {
  .page-toc-toggle,
  .page-toc-panel,
  .page-toc-backdrop {
    transition: none;
  }
}
