﻿/* Side navigation: every section is a box picture sized to its label.
   The current section shows the "broken" picture; the rest show the intact one.

   TO USE YOUR OWN DRAWINGS: replace the two files in static/nav/ (same names),
   or change the two url() lines below. If your box has a different border
   thickness, adjust --nav-slice (how many pixels of the picture's corner to use)
   and --nav-border (how thick that border is on the page). Keep any cracks or
   gaps inside the corners of the picture so they don't stretch with long labels. */

.page-with-nav {
  display: flex;
  align-items: flex-start;
  gap: 2.5rem;
}

.page-with-nav-content {
  flex: 1;
  min-width: 0;
}

/* Sticky (not fixed): it stops where .page-with-nav ends, so it never
   reaches the footer. top = navbar height plus a little space. */
.ring-nav {
  position: sticky;
  top: 80px;
  flex: 0 0 240px;
  align-self: flex-start;
  max-height: calc(100vh - 100px);
  overflow-y: auto;
  scrollbar-width: none;
  padding: 1rem 0.9rem;
  /* panel colour: edit --nav-panel and --nav-panel-border in the THEME block of style.css */
  background: var(--nav-panel);
  border: 1px solid var(--nav-panel-border);
  border-radius: 12px;
  --nav-slice: 30;      /* pixels of the picture's corner used for the border */
  --nav-border: 14px;   /* thickness of that border on the page */
}
.ring-nav::-webkit-scrollbar { display: none; }

.nav-box-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.55rem;
}

.nav-box-item {
  position: relative;
  max-width: 100%;
  box-sizing: border-box;
  /* room for the border, plus a little padding around the label */
  padding: calc(var(--nav-border) + 0.1rem) calc(var(--nav-border) + 0.35rem);
  cursor: pointer;
  color: var(--ink-muted);
  font-size: 1.1rem;
  line-height: 1.25;
  transition: color 0.2s ease;
}

.nav-box-item.is-sub {
  margin-left: 1.1rem;
  max-width: calc(100% - 1.1rem);
  font-size: 0.97rem;
  padding-top: calc(var(--nav-border) - 2px);
  padding-bottom: calc(var(--nav-border) - 2px);
}

.nav-box-item.is-subsub {
  display: none;
  margin-left: 2.2rem;
  max-width: calc(100% - 2.2rem);
  font-size: 0.9rem;
  padding-top: calc(var(--nav-border) - 3px);
  padding-bottom: calc(var(--nav-border) - 3px);
}
.nav-box-item.is-subsub.is-shown { display: block; }

.nav-box-label { position: relative; z-index: 1; }

/* a small arrow on sections that have subsections */
.nav-group.has-subs > .nav-box-item > .nav-box-label::after {
  content: "";
  display: inline-block;
  margin-left: 0.5em;
  width: 0.38em;
  height: 0.38em;
  border-right: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: translateY(-0.15em) rotate(-45deg);
  transition: transform 0.2s ease;
}
.nav-group.has-subs.is-open > .nav-box-item > .nav-box-label::after {
  transform: translateY(-0.2em) rotate(45deg);
}

.nav-group { display: block; }

/* subsections: folded until their section is current */
.nav-sub-wrap {
  display: grid;
  grid-template-rows: 0fr;
  visibility: hidden;
  transition: grid-template-rows 0.25s ease, visibility 0s linear 0.25s;
}
.nav-group.is-open > .nav-sub-wrap {
  grid-template-rows: 1fr;
  visibility: visible;
  transition: grid-template-rows 0.25s ease, visibility 0s;
}
.nav-sub-inner {
  min-height: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.45rem;
}
.nav-sub-inner > .nav-box-item:first-child { margin-top: 0.55rem; }
.nav-sub-inner > .nav-box-item:last-child { margin-bottom: 4px; }

/* The two pictures sit behind the label, stacked, and cross-fade */
.nav-box-item::before,
.nav-box-item::after {
  content: "";
  position: absolute;
  inset: 0;
  box-sizing: border-box;
  border: var(--nav-border) solid transparent;
  border-image-slice: var(--nav-slice);
  border-image-width: var(--nav-border);
  border-image-repeat: stretch;
  pointer-events: none;
  transition: opacity 0.18s ease;
}
.nav-box-item::before {
  border-image-source: none;
  opacity: 1;
}
.nav-box-item::after {
  border-image-source: none;
  opacity: 0;
}

.nav-box-item:hover { color: var(--ink); }

.nav-box-item.is-active { color: var(--ink); font-weight: 700; }
.nav-box-item.is-active::before { opacity: 0; }
.nav-box-item.is-active::after  { opacity: 1; }

/* a quick shake the moment a box breaks */
.nav-box-item.is-active { animation: nav-break 0.35s ease-out; }
@keyframes nav-break {
  0%   { transform: translateX(0); }
  25%  { transform: translateX(-3px) rotate(-1deg); }
  55%  { transform: translateX(3px) rotate(1deg); }
  100% { transform: translateX(0); }
}
@media (prefers-reduced-motion: reduce) {
  .nav-sub-wrap, .nav-group.is-open > .nav-sub-wrap { transition: none; }
  .nav-box-item.is-active { animation: none; }
  .nav-box-item::before, .nav-box-item::after { transition: none; }
}

.nav-box-item:focus-visible {
  outline: 2px solid var(--green-text);
  outline-offset: 2px;
  border-radius: 6px;
}

@media (max-width: 992px) {
  .page-with-nav { display: block; }
  .ring-nav { display: none; }
}

/* ===== "this menu scrolls" hint: a cracked, faded edge with a bouncing arrow ===== */
.nav-more {
  position: sticky;
  display: block;
  width: calc(100% + 1.8rem);
  margin-left: -0.9rem;
  height: 50px;
  padding: 0;
  border: 0;
  cursor: pointer;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
  z-index: 3;
}
.nav-more.is-on { opacity: 1; pointer-events: auto; }
.nav-more-top    { top: -1rem;    margin-bottom: -50px; background: linear-gradient(to bottom, var(--nav-panel) 45%, transparent); }
.nav-more-bottom { bottom: -1rem; margin-top: -50px;    background: linear-gradient(to top,    var(--nav-panel) 45%, transparent); }

/* the crack: a jagged line across the edge, coloured by --box-accent */
.nav-more::before {
  content: "";
  position: absolute;
  left: 0; right: 0;
  height: 11px;
  background: var(--box-accent);
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='44' height='11' viewBox='0 0 44 11'%3E%3Cpolyline points='0,3 7,9 13,4 21,10 28,3 36,8 44,3' fill='none' stroke='black' stroke-width='2.2' stroke-linejoin='bevel'/%3E%3C/svg%3E") repeat-x center / 44px 11px;
          mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='44' height='11' viewBox='0 0 44 11'%3E%3Cpolyline points='0,3 7,9 13,4 21,10 28,3 36,8 44,3' fill='none' stroke='black' stroke-width='2.2' stroke-linejoin='bevel'/%3E%3C/svg%3E") repeat-x center / 44px 11px;
}
.nav-more-top::before    { bottom: 8px; }
.nav-more-bottom::before { top: 8px; }

/* the arrow */
.nav-more::after {
  content: "";
  position: absolute;
  left: 50%;
  width: 9px; height: 9px;
  border-right: 3px solid var(--box-accent);
  border-bottom: 3px solid var(--box-accent);
}
.nav-more-bottom::after { bottom: 9px; transform: translateX(-50%) rotate(45deg);  animation: nav-more-down 1.5s ease-in-out infinite; }
.nav-more-top::after    { top: 9px;    transform: translateX(-50%) rotate(-135deg); animation: nav-more-up 1.5s ease-in-out infinite; }
@keyframes nav-more-down { 0%,100% { transform: translate(-50%, -2px) rotate(45deg); } 50% { transform: translate(-50%, 4px) rotate(45deg); } }
@keyframes nav-more-up   { 0%,100% { transform: translate(-50%, 2px) rotate(-135deg); } 50% { transform: translate(-50%, -4px) rotate(-135deg); } }
.nav-more:focus-visible { outline: 2px solid var(--green-text); outline-offset: -2px; }
@media (prefers-reduced-motion: reduce) {
  .nav-more::after { animation: none; }
  .nav-more { transition: none; }
}
