/* ---------- Albersdown: Bauhaus geometric system ---------- */
:root {
  --ink: #17181a;
  --bg: #f3f5f7;
  --surface: #ffffff;
  --surface-strong: #f7f9fb;
  --muted: #636b76;
  --border: #d5dae1;
  --code-bg: #ecf0f4;
  --shadow-soft: 0 1px 3px rgba(9, 11, 15, 0.045);
  --shadow-card: 0 1px 5px rgba(9, 11, 15, 0.055);
  --content: 78ch;
  --anchor-offset: 76px;

  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-5: 1.5rem;
  --space-6: 2rem;

  --rule-thin: 1px;
  --rule-strong: 2px;
  --ribbon-opacity: 0.62;
  --nav-dash-weight: 650;
  --dash-weight: 600;
  --dash-opacity: 0.82;
  --subdash-opacity: 0.76;
  --overview-dash-weight: 620;
  --overview-dash-opacity: 0.86;
  --hr-opacity: 0.42;
  --table-divider-alpha: 72%;
  --table-hover-alpha: 70%;

  /* Homage Red (default family) */
  --A900: #cd2d26;
  --A700: #dc3925;
  --A500: #e44926;
  --A300: #e35b2d;

  --accent-ink-light: var(--A900);
  --accent-ink-dark: var(--A300);
  --accent-ink: var(--accent-ink-light);
  --accent: var(--A500);
  --accent-strong: var(--A700);
  --accent-hover: #a9351f;
  --accent-tint: rgba(228, 73, 38, 0.09);
  --accent-band: rgba(228, 73, 38, 0.14);
}

/* -- Intensity modes ------------------------------------------------------ */
/* Apply on body/container: .style-minimal or .style-assertive */
.style-minimal {
  --rule-strong: 1px;
  --ribbon-opacity: 0.46;
  --nav-dash-weight: 600;
  --dash-weight: 560;
  --dash-opacity: 0.7;
  --subdash-opacity: 0.64;
  --overview-dash-weight: 560;
  --overview-dash-opacity: 0.74;
  --hr-opacity: 0.3;
  --table-divider-alpha: 58%;
  --table-hover-alpha: 52%;
}

.style-assertive {
  --rule-strong: 3px;
  --ribbon-opacity: 0.82;
  --nav-dash-weight: 720;
  --dash-weight: 700;
  --dash-opacity: 0.96;
  --subdash-opacity: 0.9;
  --overview-dash-weight: 680;
  --overview-dash-opacity: 0.94;
  --hr-opacity: 0.62;
  --table-divider-alpha: 90%;
  --table-hover-alpha: 92%;
}

/* -- Palette families ---------------------------------------------------- */
.palette-lapis  {
  --A900: #1b2a74;
  --A700: #20399c;
  --A500: #2c4fcc;
  --A300: #4968d6;
  --accent-hover: #1a377f;
  --accent-tint: rgba(44, 79, 204, 0.1);
  --accent-band: rgba(44, 79, 204, 0.15);
}

.palette-ochre  {
  --A900: #6f5200;
  --A700: #8b6700;
  --A500: #b48900;
  --A300: #d7a700;
  --accent-hover: #7a5c00;
  --accent-tint: rgba(180, 137, 0, 0.1);
  --accent-band: rgba(180, 137, 0, 0.16);
}

.palette-teal   {
  --A900: #0d4a4a;
  --A700: #0f5e5e;
  --A500: #127373;
  --A300: #2f8c8c;
  --accent-hover: #0f6060;
  --accent-tint: rgba(18, 115, 115, 0.1);
  --accent-band: rgba(18, 115, 115, 0.15);
}

.palette-green  {
  --A900: #1b5e20;
  --A700: #2e7d32;
  --A500: #388e3c;
  --A300: #66bb6a;
  --accent-hover: #2e7d32;
  --accent-tint: rgba(56, 142, 60, 0.1);
  --accent-band: rgba(56, 142, 60, 0.15);
}

.palette-violet {
  --A900: #4a148c;
  --A700: #6a1b9a;
  --A500: #8e24aa;
  --A300: #ba68c8;
  --accent-ink-dark: #d59ae7;
  --accent-hover: #71208d;
  --accent-tint: rgba(142, 36, 170, 0.11);
  --accent-band: rgba(142, 36, 170, 0.16);
}

/* -- Presets: ground / surface / ink variations --------------------------- */

/* Study — clean analytical white (Interaction of Color plates) */
.preset-study {
  --bg: #f7f9fb;
  --surface: #ffffff;
  --surface-strong: #fbfcfd;
  --ink: #17181a;
  --muted: #68717d;
  --border: #dde2e8;
  --code-bg: #f1f4f8;
}

/* Structural — beton brut, shadowless precision (Structural Constellations) */
.preset-structural {
  --bg: #e6e9ed;
  --surface: #f1f3f6;
  --surface-strong: #eceff2;
  --ink: #101214;
  --muted: #4b5360;
  --border: #c1c8d0;
  --code-bg: #e0e5ea;
  --shadow-soft: none;
  --shadow-card: none;
}

/* Adobe — warm architectural grey, Le Corbusier beton (not sandy) */
.preset-adobe {
  --bg: #ece9e7;
  --surface: #f3f1ef;
  --surface-strong: #efedeb;
  --ink: #1f1c19;
  --muted: #66615d;
  --border: #ccc7c3;
  --code-bg: #e3dfdc;
  --shadow-soft: 0 2px 7px rgba(0, 0, 0, 0.04);
  --shadow-card: 0 2px 9px rgba(0, 0, 0, 0.05);
}

/* Midnight — deep dark (jewel-tone accents against indigo-black) */
.preset-midnight {
  --bg: #0d1117;
  --surface: #151b24;
  --surface-strong: #1a212d;
  --ink: #e8e6e1;
  --muted: #9aa2b0;
  --border: #2c3342;
  --code-bg: #111722;
  --shadow-soft: 0 6px 20px rgba(0, 0, 0, 0.4);
  --shadow-card: 0 6px 24px rgba(0, 0, 0, 0.45);
  --accent-ink: var(--accent-ink-dark);
  --accent-hover: #f2b2a7;
  --accent-tint: rgba(228, 73, 38, 0.2);
  --accent-band: rgba(228, 73, 38, 0.25);
}

/* -- Dark mode (system / Bootstrap) -------------------------------------- */
@media (prefers-color-scheme: dark) {
  :root {
    --ink: #ece8de;
    --bg: #111315;
    --surface: #171a1e;
    --surface-strong: #1c2025;
    --muted: #a7aeb8;
    --border: #313844;
    --code-bg: #181d24;
    --shadow-soft: 0 6px 20px rgba(0, 0, 0, 0.35);
    --shadow-card: 0 6px 24px rgba(0, 0, 0, 0.4);
    --accent-ink: var(--accent-ink-dark);
    --accent-hover: #f2b2a7;
    --accent-tint: rgba(228, 73, 38, 0.2);
    --accent-band: rgba(228, 73, 38, 0.25);
  }
}

[data-bs-theme="dark"] {
  --ink: #ece8de;
  --bg: #111315;
  --surface: #171a1e;
  --surface-strong: #1c2025;
  --muted: #a7aeb8;
  --border: #313844;
  --code-bg: #181d24;
  --shadow-soft: 0 6px 20px rgba(0, 0, 0, 0.35);
  --shadow-card: 0 6px 24px rgba(0, 0, 0, 0.4);
  --accent-ink: var(--accent-ink-dark);
  --accent-hover: #f2b2a7;
  --accent-tint: rgba(228, 73, 38, 0.2);
  --accent-band: rgba(228, 73, 38, 0.25);
}

/* -- Base typography & layout -------------------------------------------- */
:root { scrollbar-gutter: stable both-edges; }

html,
body {
  background-color: var(--bg);
  color: var(--ink);
  font-family: "Avenir Next", "Gill Sans", system-ui, -apple-system, sans-serif;
  font-size: 17.5px;
  line-height: 1.58;
  letter-spacing: 0.01em;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

main,
.content,
.page-content,
.vignette,
.contents {
  max-width: var(--content);
  margin-inline: auto;
  padding-inline: clamp(16px, 2.4vw, 34px);
}

/* -- Surfaces ------------------------------------------------------------ */
.page-content,
.article,
.reference,
.template-home {
  position: relative;
  background: var(--surface);
  border: var(--rule-thin) solid var(--border);
  box-shadow: var(--shadow-soft);
}

.page-content::before,
.article::before,
.reference::before,
.template-home::before {
  content: "";
  position: absolute;
  top: calc(-1 * var(--rule-thin));
  bottom: calc(-1 * var(--rule-thin));
  left: calc(-1 * var(--rule-thin));
  width: var(--rule-strong);
  background: var(--A500);
  opacity: var(--ribbon-opacity);
  pointer-events: none;
}

.page-header,
.template-home .page-header {
  background: var(--surface-strong);
  border-top: var(--rule-thin) solid var(--border);
  border-bottom: var(--rule-thin) solid var(--border);
}

.navbar {
  background: var(--surface-strong) !important;
  border-top: var(--rule-strong) solid var(--A500);
  border-bottom: var(--rule-thin) solid var(--border);
  backdrop-filter: none;
  box-shadow: none;
}

.navbar .navbar-brand,
.navbar .nav-link {
  color: var(--ink) !important;
  font-weight: 650;
  letter-spacing: 0.045em;
  text-transform: uppercase;
  font-size: 0.85em;
  text-decoration: none !important;
}

.navbar .navbar-brand {
  font-weight: 730;
  letter-spacing: 0.055em;
}

.navbar .nav-link {
  border-bottom: var(--rule-thin) solid transparent;
  padding-bottom: 0.18rem;
}

.navbar .nav-link:hover,
.navbar .nav-link:focus-visible {
  border-bottom-color: var(--A500);
}

.navbar .nav-link.active,
.navbar .active > a {
  border-bottom-color: var(--A500);
}

.navbar .nav-link.active::after,
.navbar .active > a::after {
  content: " —";
  margin-left: var(--space-1);
  color: var(--A500);
  font-weight: var(--nav-dash-weight);
}

.sidebar,
.toc {
  background: var(--surface);
  border: var(--rule-thin) solid var(--border);
}

/* -- Typography ---------------------------------------------------------- */
p { margin-block: 0 1.02rem; }

h1,
h2,
h3 {
  color: var(--ink);
  line-height: 1.18;
  margin-top: var(--space-6);
  margin-bottom: 0.65rem;
}

h1 {
  font-size: clamp(2rem, 2.6vw, 2.42rem);
  letter-spacing: 0.012em;
  text-wrap: balance;
  font-weight: 760;
}

h2 {
  font-size: clamp(1.34rem, 2vw, 1.58rem);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  font-weight: 730;
}

h3 {
  font-size: clamp(1.08rem, 1.5vw, 1.24rem);
  letter-spacing: 0.02em;
  font-weight: 690;
}

h2,
h3 {
  position: relative;
  padding-left: 0.82em;
  padding-right: 1.45em;
  scroll-margin-top: var(--anchor-offset);
}

h2::before,
h3::before {
  content: "—";
  position: absolute;
  left: 0;
  top: 0.02em;
  color: var(--A500);
  line-height: 1;
  font-weight: var(--dash-weight);
  opacity: var(--dash-opacity);
}

h3::before {
  content: "–";
  color: var(--A700);
  opacity: var(--subdash-opacity);
}

/* -- Links --------------------------------------------------------------- */
a,
a:visited {
  color: var(--accent-ink) !important;
  text-decoration: underline;
  text-decoration-thickness: 0.09em;
  text-underline-offset: 0.14em;
  text-decoration-skip-ink: auto;
  transition: color 0.15s ease;
}

a:hover {
  color: var(--accent-hover) !important;
}

a:focus-visible,
button.copy-code:focus-visible,
.anchor:focus-visible {
  outline: 2px solid var(--accent-ink);
  outline-offset: 2px;
  box-shadow: 0 0 0 3px var(--accent-tint);
}

a:focus { outline: none; }

/* -- Code ---------------------------------------------------------------- */
code,
pre,
kbd,
samp {
  font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, "Liberation Mono", monospace;
  font-size: 0.95em;
  line-height: 1.52;
}

pre {
  background: var(--code-bg);
  border: var(--rule-thin) solid var(--border);
  border-left: var(--rule-strong) solid var(--A500);
  box-shadow: none;
  padding: var(--space-5) var(--space-4);
  margin-block: 1.35rem;
  overflow: auto;
  position: relative;
  tab-size: 2;
  -moz-tab-size: 2;
}

pre code {
  background: transparent;
  border: none;
  padding: 0;
  word-break: normal;
  overflow-wrap: normal;
}

button.copy-code {
  position: absolute;
  top: 8px;
  right: 8px;
  border: var(--rule-thin) solid var(--A500);
  background: var(--surface);
  color: var(--accent-ink);
  padding: 4px 8px;
  font: 650 11px/1 "Avenir Next", system-ui, sans-serif;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  cursor: pointer;
}

button.copy-code:hover {
  background: var(--accent-tint);
}

button.copy-code:active {
  transform: translateY(1px);
}

p code {
  background: var(--code-bg);
  border: var(--rule-thin) solid var(--border);
  padding: 0.12em 0.36em;
}

/* -- Tables -------------------------------------------------------------- */
table {
  width: 100%;
  border-collapse: collapse;
  font-variant-numeric: tabular-nums;
  border: var(--rule-thin) solid var(--border);
}

th,
td {
  border-bottom: var(--rule-thin) solid var(--border);
  padding: 10px 9px;
}

th + th,
td + td {
  border-left: var(--rule-thin) solid color-mix(in srgb, var(--border) var(--table-divider-alpha), transparent);
}

thead th {
  background: var(--surface-strong);
  border-bottom: var(--rule-strong) solid var(--A500);
  font-weight: 700;
  text-transform: uppercase;
  font-size: 0.84em;
  letter-spacing: 0.06em;
  text-align: left;
}

tbody tr:nth-child(odd) {
  background: var(--accent-tint);
}

tbody tr:hover {
  background: color-mix(in srgb, var(--accent-band) var(--table-hover-alpha), transparent);
}

caption {
  caption-side: bottom;
  color: var(--muted);
  padding-top: 0.7rem;
  font-size: 0.94em;
}

/* -- Callouts ------------------------------------------------------------ */
blockquote,
.callout {
  border-left: var(--rule-strong) solid var(--A500);
  border-top: var(--rule-thin) solid var(--border);
  background: var(--accent-band);
  padding: 16px 22px;
  margin-block: 1.45rem;
}

blockquote p { margin: 0; }

/* -- Anchors ------------------------------------------------------------- */
h2:hover .anchor,
h3:hover .anchor,
h2:focus-within .anchor,
h3:focus-within .anchor {
  opacity: 1;
  transform: translateY(-50%) translateX(0);
}

.anchor {
  opacity: 0;
  position: absolute;
  right: 0;
  top: 50%;
  transform: translateY(-50%) translateX(0.2em);
  text-decoration: none;
  color: var(--A500);
  line-height: 1;
  font-weight: 700;
  letter-spacing: 0.04em;
  transition: opacity 0.15s ease-in-out, transform 0.15s ease-in-out;
}

/* -- Homage hero & structural elements ----------------------------------- */
.homage-hero {
  aspect-ratio: 8 / 3;
  min-height: clamp(72px, 14vw, 168px);
  margin-block: 1.5rem;
  border: 0;
  border-radius: 0;
  box-shadow: none;
  background:
    linear-gradient(90deg, var(--A900) 0 25%, transparent 25% 100%),
    linear-gradient(90deg, transparent 0 25%, var(--A700) 25% 50%, transparent 50% 100%),
    linear-gradient(90deg, transparent 0 50%, var(--A500) 50% 75%, transparent 75% 100%),
    linear-gradient(90deg, transparent 0 75%, var(--A300) 75% 100%),
    var(--surface);
}

.homage-hero--letterbox {
  aspect-ratio: 12 / 1;
  margin-block: 1rem 0.55rem;
}

.hr-notch {
  height: 0;
  border-top: var(--rule-thin) solid var(--border);
  border-bottom: var(--rule-thin) solid var(--A500);
  margin: 1.5rem 0;
  opacity: var(--hr-opacity);
}

.overview ul {
  list-style: none;
  margin: 0;
  padding-left: 0;
}

.overview li {
  position: relative;
  padding-left: 1.1em;
  margin-bottom: var(--space-2);
}

.overview li::before {
  content: "—";
  position: absolute;
  left: 0;
  top: 0.02em;
  color: var(--A500);
  font-weight: var(--overview-dash-weight);
  opacity: var(--overview-dash-opacity);
}

/* -- Responsive ---------------------------------------------------------- */
@media (max-width: 920px) {
  html,
  body { font-size: 16.8px; }

  :root { --anchor-offset: 64px; }

  h2,
  h3 {
    padding-left: 0.62em;
    padding-right: 1.2em;
  }

  .page-content,
  .article,
  .reference,
  .template-home {
    box-shadow: none;
    border-left: none;
    border-right: none;
  }

  .page-content::before,
  .article::before,
  .reference::before,
  .template-home::before {
    display: none;
  }

  button.copy-code {
    font-size: 10px;
    letter-spacing: 0.05em;
  }
}

@media (max-width: 760px) {
  :root {
    --anchor-offset: 58px;
    --content: 74ch;
  }

  main,
  .content,
  .page-content,
  .vignette,
  .contents {
    padding-inline: 14px;
  }

  .navbar .navbar-brand,
  .navbar .nav-link {
    font-size: 0.78em;
    letter-spacing: 0.035em;
  }

  h1 { font-size: clamp(1.72rem, 7.2vw, 2.02rem); }
  h2 {
    font-size: clamp(1.16rem, 5.2vw, 1.35rem);
    letter-spacing: 0.045em;
  }
  h3 { font-size: clamp(1rem, 4.3vw, 1.14rem); }

  pre {
    padding: var(--space-5) var(--space-3);
    font-size: 0.91em;
  }

  button.copy-code {
    min-height: 30px;
    padding: 6px 10px;
  }

  table {
    display: block;
    overflow-x: auto;
    white-space: nowrap;
    -webkit-overflow-scrolling: touch;
  }
}

@media (max-width: 520px) {
  :root { --anchor-offset: 54px; }

  main,
  .content,
  .page-content,
  .vignette,
  .contents {
    padding-inline: 12px;
  }

  .navbar { border-top-width: 2px; }

  .navbar .navbar-brand,
  .navbar .nav-link {
    font-size: 0.74em;
    letter-spacing: 0.03em;
  }

  h2,
  h3 {
    padding-right: 1em;
  }

  .anchor { right: -0.08em; }

  pre {
    border-left-width: 2px;
    padding: var(--space-4) var(--space-3);
  }

  button.copy-code {
    top: 6px;
    right: 6px;
    min-height: 28px;
    padding: 5px 8px;
    font-size: 9px;
  }
}

@media (prefers-contrast: more) {
  :root {
    --border: #9aa1ad;
    --muted: #4f5661;
    --accent-tint: rgba(228, 73, 38, 0.18);
    --accent-band: rgba(228, 73, 38, 0.24);
    --rule-strong: 3px;
  }

  a { text-decoration-thickness: 0.12em; }

  pre,
  table,
  blockquote,
  .callout {
    border-width: 2px;
  }

  .navbar .nav-link.active::after,
  .navbar .active > a::after { color: var(--A700); }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

@media print {
  body { background: #fff !important; }

  .navbar,
  .sidebar,
  .toc,
  .page-header,
  .homage-hero,
  .hr-notch,
  button.copy-code,
  .anchor { display: none !important; }

  .page-content,
  .article,
  .reference,
  .template-home {
    border: none;
    box-shadow: none;
    background: #fff;
  }

  .page-content::before,
  .article::before,
  .reference::before,
  .template-home::before {
    display: none;
  }

  pre { page-break-inside: avoid; }

  a {
    color: inherit !important;
    text-decoration: none;
  }
}
