/* =========================================================
   TOKENS / CUSTOM PROPERTIES
   ========================================================= */

:root {
  --gutter: 2rem;
  --margin: 420px;
  --body-pad: 1rem;

  --content-min: 60ch;
  --content-max: 880px;
  --content: clamp(
    var(--content-min),
    calc(100vi - (2 * var(--body-pad)) - (2 * (var(--margin) + var(--gutter)))),
    var(--content-max)
  );

  --bleed: 48px;
  --fullwidth-cap: 860px;

  --bg: #333;
  --page-bg: #444;
  --fg: #f3f3f3;

  --heading: #f9f9f9;
  --link: lightblue;
  --link-2: var(--link);

  --code-bg: #f0f0f0;

  --border: #d7d7d7;
  --active-toc: #cacaca;

  --muted: #666;
  --note-color: #555;
  --note-bg: transparent;

  --chip-bg: #f0f0f0;
  --chip-fg: #444;

  /* Compatibility aliases (you reference these later) */
  --border-color: var(--border);
  --text-color: var(--fg);
  --muted-text: var(--muted);
  --link-color: var(--link);
  --link-hover-color: var(--fg);
  --bg-alt: #2a2a2a;
}

/* =========================================================
   BASE / TYPOGRAPHY
   ========================================================= */

html,
body {
  margin: 0;
  background-color: var(--page-bg);
  color: var(--fg);
  transition: background-color 0.3s, color 0.3s;
  font-family: Inter, sans-serif;
}

/* Keep your layout intent (column app shell) */
body {
  display: flex;
  flex-direction: column;
}

h1,
h2,
h3 {
  color: var(--heading);
}

a {
  color: var(--link-2);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

/* =========================================================
   PREAMBLE / HEADER
   ========================================================= */

#preamble {
  top: 0;
  z-index: 20;
  background: var(--bg);
  border-bottom: 1px dotted var(--border);
}

#preamble .banner-header,
#preamble #updated {
  max-width: 100%;
}

.banner-header {
  position: relative;               /* anchor for Close All */
  display: flex;
  justify-content: flex-start;       /* align to left */
  align-items: center;
  gap: 1rem;

  padding: 0.5rem 1rem;
}

.banner-left {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
}

.banner-logo {
  height: 80px;
  width: auto;
  border-radius: 50%;
}

nav {
  display: flex;
  gap: 1rem;
  font-weight: 600;
  font-size: 1.1rem;
}

#updated {
  font-size: 0.75rem;
  color: color-mix(in oklab, var(--muted) 30%, var(--fg) 70%);
  white-space: nowrap;
  text-align: center;
}

#close-all {
  position: absolute;
  right: 1rem;
  top: 50%;
  transform: translateY(-50%);

  background: transparent;
  border: 1px solid var(--border);
  border-radius: 4px;

  padding: 0.25rem 0.5rem;   /* smaller so it doesn't dominate */
  font-size: 0.8rem;
  color: color-mix(in oklab, var(--muted) 40%, var(--fg) 60%);
  cursor: pointer;
}

#close-all:hover {
  color: var(--fg);
  border-color: var(--fg);
}

.banner-header > a {
  display: flex;
  align-items: center;
}


@media (max-width: 768px) {
  .banner-header {
    flex-direction: column;
    gap: 0.75rem;
    text-align: center;
    align-items: center;
  }

  .banner-left {
    margin: 0 auto;
  }

  .banner-logo {
    margin: 0;
  }

  #close-all {
    position: static;
    transform: none;
  }
}


/* =========================================================
   CONTENT WRAPPER
   ========================================================= */

#content.content {
  max-width: var(--content);
  margin-left: auto !important;
  margin-right: auto !important;
  padding-left: var(--body-pad);
  padding-right: var(--body-pad);
  box-sizing: content-box;
  position: relative;
}

/* =========================================================
   TITLE SECTION
   ========================================================= */

.title-section {
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 1.5rem;
  padding-right: 8rem; /* Extra padding on right for controls */
  margin-bottom: 2rem;
  background-color: color-mix(in oklab, var(--bg) 96%, var(--fg) 4%);
  position: relative; /* For absolute positioning of controls */
}

.title-section .title {
  margin: 0 0 1rem 0;
  padding-bottom: 1rem;
  border-bottom: 1px dotted var(--border);
}

.title-metadata {
  display: flex;
  flex-wrap: wrap;
  gap: 1.5rem;
  font-size: 0.9rem;
}

.metadata-item {
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
}

.metadata-label {
  color: var(--muted);
  font-style: italic;
  font-weight: 500;
}

.metadata-value {
  color: var(--fg);
  font-weight: 400;
}

#content .figure,
#content img:not(.fullwidth) {
  max-width: 100%;
  height: auto;
}

/* =========================================================
   STACKED PANE LAYOUT
   ========================================================= */

#stack-root {
  position: relative;
  width: 100vw;
  height: calc(100vh - 120px);
  overflow-x: auto;
  overflow-y: hidden;
  flex: 1 1 auto;
  scroll-snap-type: x proximity;
}

.stack-track {
  display: flex;
  flex-direction: row;
  align-items: stretch;
  width: max-content;
  height: 100%;
}

.stack-pane {
  flex: 0 0 auto;

  width: clamp(420px, 33vw, 860px);
  max-width: 100vw;

  height: 100%;
  overflow-y: auto;
  overflow-x: hidden;

  position: relative; /* needed for ::after positioning */
  background-color: var(--bg);
  border-right: 1px dotted var(--border);
}

.stack-pane::after {
  content: "";
  position: absolute;
  top: 0;
  right: 0;
  width: 12px;
  height: 100%;
  pointer-events: none;
  opacity: 0.15;
}

.stack-pane:last-child {
  box-shadow: -4px 0 16px color-mix(in oklab, var(--fg) 6%, transparent);
}

/* Scrollbar (WebKit) */
.stack-pane::-webkit-scrollbar {
  width: 8px;
}

.stack-pane::-webkit-scrollbar-thumb {
  background-color: color-mix(in oklab, var(--fg) 25%, transparent);
  border-radius: 4px;
}

/* =========================================================
   PANE HEADER + CLOSE BUTTON
   ========================================================= */

.pane-root {
  background-color: var(--bg);
}
.pane-root .pane-close {
  display: none !important;
}

.pane-header {
  display: none; /* Hide the old pane-header */
}

/* Title section controls */
.title-controls {
  position: absolute;
  top: 1.5rem;
  right: 1.5rem;
  display: flex;
  gap: 0.5rem;
  z-index: 10;
}

.title-controls button {
  background: none;
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 0.9rem;
  line-height: 1;
  cursor: pointer;
  color: var(--muted);
  padding: 0.3rem 0.6rem;
  transition: color 0.15s ease, border-color 0.15s ease, background-color 0.15s ease;
}

.title-controls button:hover {
  color: var(--fg);
  border-color: var(--fg);
  background-color: color-mix(in oklab, var(--bg) 90%, var(--fg) 10%);
}

.pane-close {
  font-size: 1.2rem;
}

.pane-fullscreen,
.pane-edit {
  font-weight: 500;
}

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

footer {
  color: var(--fg);
  padding: 1rem;
  border-radius: 6px;
  text-align: center;
  font-size: 0.9rem;
  font-style: italic;

  flex-shrink: 0;
  margin-top: 0;

  border-top: 1px dotted var(--border);
  background: var(--bg);

  /* If you want it sticky later, use:
     position: sticky;
     bottom: 0;
  */
  bottom: 0;
  z-index: 10;
}

/* =========================================================
   LISTS
   ========================================================= */

ul,
ol {
  margin: 1rem 0 1.5rem 1.5rem;
  padding: 0;
  line-height: 1.5;
}

ul {
  list-style: none;
}

ul li {
  position: relative;
  padding-left: 1.2em;
}

ul li::before {
  content: "•";
  position: absolute;
  left: 0;
  top: 0;
  color: var(--heading);
  font-weight: bold;
}

ol {
  counter-reset: list-counter;
  list-style: none;
}

ol li {
  counter-increment: list-counter;
  position: relative;
  padding-left: 1.8em;
}

ol li::before {
  content: counter(list-counter) ".";
  position: absolute;
  left: 0;
  top: 0;
  color: var(--heading);
  font-weight: bold;
}

li {
  margin-bottom: 8px;
  display: flow-root;
}

li::after {
  content: none;
}

li ul,
li ol {
  margin-top: 0.5rem;
  margin-bottom: 0.5rem;
}

li ul li::before {
  content: "–";
  font-weight: normal;
  color: var(--note-color);
}

li ol li::before {
  font-weight: normal;
  color: var(--note-color);
}

/* =========================================================
   EPIGRAPH
   ========================================================= */

.epigraph {
  margin: 2rem auto;
  max-width: 80%;
  font-style: italic;
}

.epigraph blockquote {
  margin: 0;
  padding: 1rem 1.5rem;
  border-left: 4px dotted var(--heading);
  background-color: color-mix(in oklab, var(--bg) 94%, var(--fg) 6%);
  color: var(--fg);
  line-height: 1.6;
}

.epigraph blockquote footer {
  margin-top: 0.75rem;
  font-style: normal;
  font-size: 0.9em;
  color: var(--muted);
  text-align: right;
}

.epigraph blockquote cite {
  font-style: italic;
  font-weight: 500;
  color: var(--link);
}

.epigraph blockquote::before,
.epigraph blockquote::after {
  content: none;
}

/* =========================================================
   UTILITIES / MISC
   ========================================================= */

.hidden {
  display: none !important;
}

/* bigger-picture.js controls */
.bp-x {
  right: 72px;
}
.bp-next,
.bp-prev {
  right: 8px;
}
.bp-prev {
  left: 8px;
}
.bp-wrap {
  transition: opacity 0.18s ease;
}
.bp-wrap.bp-fadeout {
  opacity: 0;
}
.bp-controls {
  padding-top: env(safe-area-inset-top, 0);
  padding-right: calc(env(safe-area-inset-right, 0) + 8px);
}

/* code copy button */
.copy-btn {
  position: absolute;
  top: 0.4em;
  right: 0.4em;
  background-color: var(--code-bg);
  color: var(--heading);
  border: 1px dotted var(--heading);
  border-radius: 4px;
  padding: 0.2em 0.6em;
  font-size: 0.8rem;
  cursor: pointer;
  z-index: 10;
  transition: background-color 0.3s;
}

/* =========================================================
   BACKLINKS
   ========================================================= */

.backlinks-section {
  margin-top: 4rem;
  padding-top: 1.5rem;
  border-top: 1px dotted var(--border);
  opacity: 0.95;
  color: var(--muted);
}

.backlinks-list {
  margin-top: 0.75rem;
  padding-left: 0;
}

.backlinks-list li {
  margin-bottom: 0.4rem;
  font-size: 0.9rem;
  list-style: none;
}

.backlinks-list li::before {
  content: "↩ ";
  opacity: 0.5;
  margin-right: 0.2rem;
}

.backlinks-list li a {
  text-decoration: none;
  font-weight: 500;
  color: var(--link);
  border-bottom: 1px dotted color-mix(in oklab, var(--fg) 20%, transparent);
  padding-bottom: 0.05em;
  transition: color 0.15s ease, border-color 0.15s ease;
}

.backlinks-list li a:hover,
.backlinks-list li a:focus {
  color: var(--fg);
  border-bottom-color: currentColor;
}

/* =========================================================
   SEARCH
   ========================================================= */

.banner-search {
  position: relative;
  max-width: 28rem;
}

#search-box {
  width: 100%;
  padding: 0.55rem 0.75rem;
  font-size: 0.95rem;
  font-family: inherit;

  background-color: var(--bg-alt);
  color: var(--fg);

  border: 1px solid var(--border);
  border-radius: 4px;

  transition: border-color 0.15s ease, box-shadow 0.15s ease,
    background-color 0.15s ease;
}

#search-box:focus {
  outline: none;
  background-color: var(--bg);
  border-color: var(--link);
  box-shadow: 0 0 0 2px color-mix(in oklab, var(--link) 20%, transparent);
}

#search-box::placeholder {
  color: color-mix(in oklab, var(--muted) 30%, var(--fg) 70%);
  font-style: italic;
}

#search-results {
  position: absolute;
  top: calc(100% + 0.3rem);
  left: 0;
  right: 0;

  background-color: var(--bg);
  border: 1px dotted var(--border);
  border-radius: 4px;

  box-shadow: 0 8px 24px color-mix(in oklab, var(--fg) 8%, transparent);

  max-height: 18rem;
  overflow-y: auto;

  z-index: 1000;
}

#search-results > * {
  padding: 0.45rem 0.65rem;
  font-size: 0.9rem;
  line-height: 1.3;

  cursor: pointer;
  border-bottom: 1px dotted color-mix(in oklab, var(--fg) 5%, transparent);
}

#search-results > *:last-child {
  border-bottom: none;
}

#search-results > *:hover,
#search-results > *.active {
  background-color: color-mix(in oklab, var(--link) 12%, transparent);
}

/* =========================================================
   RESPONSIVE
   ========================================================= */

@media (max-width: 768px) {
  #stack-root {
    overflow-x: hidden;
    overflow-y: auto;
  }

  .stack-track {
    flex-direction: column;
    width: 100%;
  }

  .stack-pane {
    width: 100%;
    height: auto;
    border-right: none;
    border-bottom: 1px dotted var(--border);
  }

    .pane-fullscreen {

	display: none !important;
    }
}
/* =========================================================
   FULLSCREEN PANE MODE
   ========================================================= */

body.pane-fullscreen #stack-root {
  overflow: hidden;
}

body.pane-fullscreen .stack-track {
  width: 100%;
}

body.pane-fullscreen .stack-pane {
  width: 100% !important;
  max-width: none;
  border-right: none;
}

body.pane-fullscreen .stack-pane::after {
  display: none;
}

/* Only the active fullscreen pane remains */
body.pane-fullscreen .stack-pane:not(.is-fullscreen) {
  display: none;
}

/* Optional: make content breathe more in fullscreen */
body.pane-fullscreen #content.content {
  max-width: 900px;
}
