:root {
  --bg: #fff2d8;
  --fg: #3b281d;
  --muted: #755840;
  --line: #c58b54;
  --accent: #963f20;
  --sidebar-bg: #f5dca8;
  --nav-level-0: #f1b553;
  --nav-level-1: #f4cf83;
  --nav-level-2: #e8a36a;
  --nav-level-3: #efbd79;
  --header-fallback: #783d28;
  --divider: #d88a3c;
  --sidebar-w: 16rem;
  --max-text: 38rem;
}

@font-face {
  font-family: "Righteous";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("fonts/Righteous-latin.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA,
    U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191,
    U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

@font-face {
  font-family: "Righteous";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("fonts/Righteous-latin-ext.woff2") format("woff2");
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7,
    U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F,
    U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C4, U+2113, U+2C60-2C7F,
    U+A720-A7FF;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 16px/1.6 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

.brand, .nav, h1, h2, h3 { font-family: "Righteous", sans-serif; }

img { display: block; max-width: 100%; }
a { color: var(--accent); }

/* The mobile menu is a checkbox, so it needs no JavaScript and stores nothing.
   It stays in the accessibility tree and keyboard-focusable - never display:none it. */
.nav-toggle { position: absolute; width: 1px; height: 1px; opacity: 0; }

/* Scrim: lets a tap outside the open mobile panel close it. Inert at desktop
   widths, where the sidebar is never an overlay. */
.nav-scrim { display: none; }

.topbar {
  position: relative;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.9rem 1rem;
  background-color: var(--header-fallback);
  background-image:
    radial-gradient(circle at 91% 22%, #e4a344 0 1.1rem, transparent 1.15rem),
    radial-gradient(circle at 96% 78%, #a84925 0 2rem, transparent 2.05rem),
    linear-gradient(110deg, rgb(157 68 33 / 88%), rgb(74 37 26 / 94%)),
    url("header.jpg");
  background-position: center, center, center, center;
  background-size: auto, auto, auto, cover;
  background-repeat: no-repeat;
  color: #ffffff;
}
/* Keeps the title readable over both the color pattern and an optional header photo. */
.topbar::before {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, #35190f12, #35190f70);
  pointer-events: none;
}
.topbar::after {
  content: "";
  position: absolute;
  right: 0;
  bottom: -13px;
  left: 0;
  height: 26px;
  border-bottom: 5px solid var(--divider);
  border-radius: 50%;
  pointer-events: none;
}
.topbar > * { position: relative; }
.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.6rem;
  font-weight: 600;
  font-size: 1.15rem;
  letter-spacing: 0.02em;
  text-decoration: none;
  color: #ffffff;
  text-shadow: 0 1px 3px #00000099;
}
.brand-logo { width: auto; height: 3.5rem; object-fit: contain; }
.language-switch {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  min-height: 44px;
  margin-left: auto;
  padding: 0.35rem 0.7rem;
  border: 1px solid #ffffffa6;
  border-radius: 0.25rem;
  color: #ffffff;
  font-size: 0.9rem;
  font-weight: 600;
  text-decoration: none;
  text-shadow: 0 1px 3px #00000099;
}
.language-switch:hover, .language-switch:focus-visible {
  background: #ffffff26;
  text-decoration: underline;
}
.hamburger {
  display: none;
  color: #ffffff;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  min-height: 44px;
  font-size: 1.5rem;
  cursor: pointer;
}
/* White, not --accent: the topbar is now a dark photo, where the dark blue
   accent is close to invisible. */
.nav-toggle:focus-visible ~ .topbar .hamburger { outline: 2px solid #ffffff; }

.sidebar {
  position: relative;
  padding: 1rem;
  background-color: var(--sidebar-bg);
  background-image: url("retro-flowers.svg");
  background-position: right 0.65rem top 3.5rem;
  background-size: 12rem 20rem;
  background-repeat: repeat-y;
}
.sidebar::after {
  content: "";
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  width: 28px;
  border-right: 5px solid var(--divider);
  border-radius: 50%;
  pointer-events: none;
}
.content {
  min-width: 0;
  min-height: 100%;
  padding: 1rem;
  background:
    radial-gradient(circle at 92% 8%, #f7d99c 0, transparent 28rem),
    linear-gradient(145deg, #fff1d2, #edc27f);
}
.site-footer {
  padding: 0.35rem 1rem;
  color: var(--muted);
  font-size: 0.85rem;
  text-align: right;
}
.site-footer p { margin: 0; }

.nav, .nav ul { margin: 0; padding: 0; list-style: none; }
/* Keep nested lists full width so each level's background spans the sidebar;
   the link padding below carries the visual hierarchy instead. */
.nav ul { margin: 0; padding: 0; }
.nav-item + .nav-item { position: relative; }
.nav-item + .nav-item::before {
  content: "";
  display: block;
  width: 84%;
  height: 0.6rem;
  margin: 0 auto -0.5rem;
  border-top: 2px solid var(--line);
  border-radius: 50%;
}
.nav-item + .nav-item > a { padding-top: 0.5rem; }
.nav a {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  min-height: 44px;
  padding: 0.25rem;
  color: var(--fg);
  text-decoration: none;
}
.nav-depth-0 > a, .nav-depth-1 > a { padding-left: 0.25rem; }
.nav-depth-2 > a { padding-left: calc(1.75rem + 1px); }
.nav-depth-3 > a { padding-left: calc(3.25rem + 2px); }
.nav-depth-4 > a {
  padding-left: calc(4.75rem + 3px);
  background: linear-gradient(to right, var(--nav-level-3), var(--sidebar-bg));
}
.nav-depth-0 > a { background: linear-gradient(to right, var(--nav-level-0), var(--sidebar-bg)); }
.nav-depth-1 > a { background: linear-gradient(to right, var(--nav-level-1), var(--sidebar-bg)); }
.nav-depth-2 > a { background: linear-gradient(to right, var(--nav-level-2), var(--sidebar-bg)); }
.nav-depth-3 > a { background: linear-gradient(to right, var(--nav-level-3), var(--sidebar-bg)); }
.nav-date { font-size: 0.8em; line-height: 1.3; color: var(--muted); }
.nav-title { line-height: 1.3; }
.nav a:hover { text-decoration: underline; }
.nav .is-current > a { font-weight: 600; color: var(--accent); }
.sidebar-logo {
  display: block;
  width: 100%;
  height: auto;
  margin: 1rem auto 0;
}

h1 { margin: 1rem 0 0.25rem; color: #743b24; font-size: 1.6rem; }
.date {
  margin: 0 0 1.25rem;
  color: var(--muted);
  text-shadow: 0 1px 2px #5a403099;
}
.story { max-width: var(--max-text); }
.story .admonition {
  margin: 1.25rem 0;
  padding: 0.75rem 1rem;
  border-left: 0.3rem solid var(--admonition-accent);
  background: var(--admonition-bg);
}
.story .admonition-title { margin: 0 0 0.25rem; font-weight: 700; }
.story .admonition > :last-child { margin-bottom: 0; }
.story .admonition-note { --admonition-accent: #9c5b2b; --admonition-bg: #fbebc9; }
.story .admonition-tip { --admonition-accent: #805126; --admonition-bg: #f5e4bd; }
.story .admonition-important { --admonition-accent: #9a4827; --admonition-bg: #f8dfbf; }
.story .admonition-warning { --admonition-accent: #aa5a1b; --admonition-bg: #fff0cb; }
.story .admonition-caution { --admonition-accent: #a4432d; --admonition-bg: #f9e2d2; }
.story .admonition-danger { --admonition-accent: #7e2b1d; --admonition-bg: #f6ddd1; }
.story-disclosure > summary {
  min-height: 44px;
  padding: 0.5rem 0;
  cursor: pointer;
}
.story-gallery-layout .desktop-column { display: none; }

.hero { position: relative; display: block; width: 100%; aspect-ratio: 16 / 9; overflow: hidden; }
.hero::after {
  position: absolute;
  inset: 0;
  content: "";
  background: linear-gradient(to top, #000000b8, #00000066 45%, transparent 100%);
  pointer-events: none;
}
.hero picture { display: block; width: 100%; height: 100%; }
.hero img { width: 100%; height: 100%; object-fit: cover; }
.hero-meta { position: absolute; right: 1rem; bottom: 1rem; left: 1rem; z-index: 1; color: #ffffff; text-shadow: 0 1px 3px #000000; }
.hero-meta h1 { margin: 0; color: inherit; }
.hero-meta .date { margin: 0.25rem 0 0; color: inherit; }

.grid {
  display: grid;
  /* Phones only - the desktop breakpoint pins the tracks to a flat 180px.
     min(180px, 46%) rather than a bare 180px: on the narrowest phones two
     180px columns plus the gap and .content's padding overflow, so the grid
     would fall back to one column. 46% guarantees two fit down to 320px. */
  grid-template-columns: repeat(auto-fill, minmax(min(180px, 46%), 1fr));
  gap: 0.5rem;
  margin-top: 1.5rem;
}
.tile { display: block; overflow: hidden; }
/* height: auto is what makes aspect-ratio work at all: the markup carries
   width="400" height="400", and an attribute height counts as a fixed CSS
   length that beats aspect-ratio. Without auto the tile is 180px wide and
   400px tall - oblong, not square. object-fit: cover then crops the picture
   into the square, which is wanted here (unlike in the lightbox). */
.tile img {
  width: 100%;
  height: auto;
  aspect-ratio: 1;
  object-fit: cover;
  transform: scale(1);
  transition: transform 180ms ease;
}
.tile:hover img, .tile:focus-visible img { transform: scale(1.04); }

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 1.25rem;
}
.card {
  display: block;
  overflow: hidden;
  border: 2px solid #bc713a;
  border-radius: 1rem 1rem 2rem 1rem;
  background: #80472b;
  color: #fff0d3;
  text-decoration: none;
}
.card img { width: 100%; height: auto; aspect-ratio: 4 / 3; object-fit: cover; transform: scale(1); transition: transform 180ms ease; }
.card:hover img, .card:focus-visible img { transform: scale(1.04); }
.card h2 { margin: 0.75rem 0.75rem 0.25rem; font-size: 1.1rem; }
.card .date, .card .excerpt { margin: 0 0.75rem 0.75rem; }
.card .date,
.card .excerpt {
  color: #ffffff;
  text-shadow: 0 1px 2px #5a4030aa;
}
.card .excerpt { font-size: 0.9rem; }

@media (prefers-reduced-motion: reduce) {
  .card img, .tile img { transition: none; }
}

/* Phones: the sidebar slides in over the page, sub-trees stay expanded. */
@media (max-width: 767px) {
  .hamburger { display: inline-flex; }
  /* The sidebar paints over .topbar when open, so the topbar needs its own
     stacking context above it - otherwise the hamburger is buried under the
     open panel and there is no way to close the menu again. */
  .topbar { position: relative; z-index: 30; }
  .sidebar {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    width: min(20rem, 80vw);
    z-index: 20;
    overflow-y: auto;
    /* Must match the desktop sidebar, not --bg: the panel is the same menu. */
    background-color: var(--sidebar-bg);
    border-right: 1px solid var(--line);
    transform: translateX(-100%);
    transition: transform 0.2s ease;
  }
  .nav-toggle:checked ~ .shell .sidebar { transform: none; }
  .nav-toggle:checked ~ .nav-scrim { display: block; position: fixed; inset: 0; z-index: 10; }
}

@media (min-width: 768px) {
  .shell { display: grid; grid-template-columns: var(--sidebar-w) 1fr; align-items: start; }
  .sidebar {
    position: sticky;
    top: 0;
    /* .shell uses align-items: start, so the sidebar is only as tall as its
       own list. Now that it is a coloured panel, a short menu would leave a
       cut-off grey block instead of a column - min-height fills it out, and
       together with max-height it pins the panel to exactly one viewport. */
    min-height: 100vh;
    max-height: 100vh;
    overflow-y: auto;
    border-right: 1px solid var(--line);
    border-bottom: 0;
  }
  .topbar { padding: 1.1rem 2rem; }
  .brand { font-size: 1.3rem; }
  .brand-logo { height: 5rem; }
  .content { padding: 1.5rem 2rem; }
  /* Flat 180px tracks, not minmax(180px, 1fr): a 1fr track stretches the
     leftover row width into the columns, so the thumbnails would end up
     wider than 180px and, with .tile img's aspect-ratio: 1, taller too.
     Fixed tracks keep every thumbnail exactly 180 x 180. */
  .grid { grid-template-columns: repeat(auto-fill, 180px); }
  .hero { aspect-ratio: 3 / 1; }
  .story-gallery-layout {
    display: grid;
    grid-template-columns: minmax(0, 2fr) minmax(0, 3fr);
    align-items: start;
    gap: 1.5rem;
    margin-top: 1.5rem;
  }
  .story-gallery-layout .mobile-story,
  .story-gallery-layout .mobile-gallery { display: none; }
  .story-gallery-layout .desktop-column { display: block; min-width: 0; }
  .story-gallery-layout .desktop-column > summary {
    min-height: 44px;
    padding: 0.5rem 0;
    cursor: pointer;
    font-weight: 600;
  }
  .story-gallery-layout .desktop-column > .grid { margin-top: 0; }
  .story-gallery-layout:has(.desktop-story:not([open])) {
    grid-template-columns: max-content minmax(0, 1fr);
  }
  .story-gallery-layout:has(.desktop-gallery:not([open])) {
    grid-template-columns: minmax(0, 1fr) max-content;
  }
  .story-gallery-layout:has(.desktop-story:not([open])):has(.desktop-gallery:not([open])) {
    grid-template-columns: max-content max-content;
  }
  h1 { font-size: 2rem; }
  /* Sub-trees collapse to the current branch once there is a permanent sidebar. */
  .nav li > ul { display: none; }
  .nav .is-open > ul { display: block; }
}

@media (prefers-reduced-motion: reduce) {
  .sidebar, .lb-chrome { transition: none; }
}

/* ---------- Lightbox ---------- */

body.lb-open { overflow: hidden; overscroll-behavior: contain; }

.lb {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  /* dvh follows the collapsing address bar; without it the picture is clipped
     on iOS Safari and Chrome for Android. The vh line above is the fallback. */
  height: 100dvh;
  z-index: 100;
  display: none;
  background: #000000;
}
.lb[open] { display: block; }

.lb-stage {
  position: absolute;
  inset: 0;
  /* flex, not grid: the img's max-height: 100% has to resolve against
     something with a definite height. In a grid the img's containing block is
     its grid area, and an auto-sized row counts as indefinite, so the
     percentage silently becomes none - only max-width applied, the picture
     stayed full height and overflow: hidden cropped it. A flex item's
     containing block is this box, which inset gives a definite height. */
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  /* The browser must not claim pan or pinch - the lightbox handles both. */
  touch-action: none;
}
.lb-stage img {
  /* width/height must be auto, and must stay auto: lightbox.js sets the img's
     width/height attributes to the picture's real pixel size, and those count
     as fixed CSS lengths. With fixed lengths, max-width and max-height clamp
     each axis on its own - the box grows to the full stage, the picture
     overflows it and .lb-stage's overflow: hidden crops it. With both auto,
     the intrinsic-ratio constraint rules shrink it proportionally instead, so
     the whole picture fits the stage. */
  width: auto;
  height: auto;
  max-width: 100%;
  max-height: 100%;
  /* Flex items get an automatic minimum size from their content; zeroing it
     keeps that from fighting the two max constraints. */
  min-width: 0;
  min-height: 0;
  object-fit: contain;
  will-change: transform;
}

.lb-chrome {
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: 1;
  transition: opacity 0.2s ease;
}
.lb-chrome > * { pointer-events: auto; }
/* Children re-declare pointer-events: auto above (and .lb-close/.lb-original
   re-declare it a second time below, since .lb-top/.lb-bottom now default to
   none), so the idle override must be scoped to all of them too - otherwise
   an invisible close button and original link still sit over the picture
   after the chrome fades, and the arrows still catch a swipe meant for the
   stage. */
.lb.is-idle .lb-chrome,
.lb.is-idle .lb-chrome > *,
.lb.is-idle .lb-close,
.lb.is-idle .lb-original { pointer-events: none; }

.lb-top, .lb-bottom {
  position: absolute;
  left: 0;
  right: 0;
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.75rem 1rem;
  color: #ffffff;
  /* Full-width, ~68px tall bars would otherwise swallow every swipe/tap that
     starts in their strip. Only their interactive children need to catch
     pointer events. */
  pointer-events: none;
}
.lb-close, .lb-prev, .lb-next, .lb-original { pointer-events: auto; }
.lb-top {
  top: 0;
  justify-content: space-between;
  padding-top: calc(0.75rem + env(safe-area-inset-top, 0px));
  background: linear-gradient(#000000aa, #00000000);
}
.lb-bottom {
  bottom: 0;
  justify-content: space-between;
  padding-bottom: calc(0.75rem + env(safe-area-inset-bottom, 0px));
  background: linear-gradient(#00000000, #000000aa);
}
.lb-caption { font-size: 0.95rem; }
.lb a { color: #ffffff; }
.lb-original {
  padding: 0.25rem 0.65rem;
  border-radius: 0.25rem;
  background: #00000080;
  opacity: 0.7;
  text-decoration: none;
  transition: opacity 0.2s ease, background-color 0.2s ease;
}
.lb-original:hover, .lb-original:focus-visible {
  background: #000000cc;
  opacity: 1;
  text-decoration: underline;
}
.lb button {
  min-width: 44px;
  min-height: 44px;
  padding: 0;
  border: 0;
  background: none;
  color: #ffffff;
  font-size: 1.5rem;
  cursor: pointer;
}
.lb-prev, .lb-next {
  position: absolute;
  top: 50%;
  display: none;
  width: 4rem;
  height: 4rem;
  transform: translateY(-50%);
  font-size: 3.25rem;
}
.lb-prev { left: 0.5rem; }
.lb-next { right: 0.5rem; }

/* Desktop: contain the picture and put the chrome outside it, where it is free. */
@media (min-width: 768px) {
  .lb { background: #000000dd; }
  .lb {
    -webkit-backdrop-filter: blur(6px);
    backdrop-filter: blur(6px);
  }
  .lb-stage { inset: 1rem 4rem; }
  .lb-bottom { background: none; }
  .lb-prev, .lb-next { display: block; }
  .lb.is-idle .lb-chrome { opacity: 1; }
  /* The idle rule above keeps the chrome visible on desktop, so its four
     actual controls must also stay clickable - but only those four: naming
     .lb-chrome or .lb-chrome > * here would restore pointer-events on the
     full-viewport chrome container and the full-width top/bottom bars too,
     turning them back into an invisible click/scroll/drag blocker over the
     whole stage for the rest of the session. */
  .lb.is-idle .lb-close,
  .lb.is-idle .lb-prev,
  .lb.is-idle .lb-next,
  .lb.is-idle .lb-original { pointer-events: auto; }
}
