/* =========================================================================
   5-layout — the page shell. A fixed sidebar (site title, nav, copyright)
   and a white content column beside it. The nav sits vertically centred
   between the title and the copyright, not stacked right under the title.

   Below 64rem the sidebar collapses off-screen and a hamburger button
   slides it in.  A checkbox-driven toggle (no JS) handles the state.

   Background tile: the content-wrap holds the tile; .page-content has
   a radial-gradient mask that punches a clear ellipse through the centre,
   so the tile only shows on the left and right sides.
   ========================================================================= */

/* ── Toggle: hidden checkbox drives sidebar open/closed state ────────────── */
.sidebar-toggle {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

/* ── Sidebar shell ─────────────────────────────────────────────────────── */
.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: var(--sidebar-width);
  height: 100vh;
  overflow: hidden;
  background-color: var(--sidebar-bg);
  z-index: 100;
}
/* Decorative tile — sits behind content via z-index: -1 */
.sidebar::before {
  content: "";
  position: absolute;
  inset: 0;
  background-image: var(--sidebar-tile);
  background-repeat: repeat;
  opacity: 0.22;
  pointer-events: none;
  z-index: -1;
}

.sidebar-inner {
  height: 100%;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  padding: var(--sp-6) var(--sp-5);
  position: relative;
  z-index: 1;
}

/* Title row: hamburger (if present) to the LEFT of the title */
.sidebar-title-wrap {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  margin-bottom: var(--sp-5);
}

.site-title {
  margin: 0;
  font-size: var(--fs-xl);
  line-height: 1.2;
}
.site-title a { color: var(--sidebar-text); text-decoration: none; }

/* Hamburger button — hidden on desktop (sidebar is always visible there) */
.sidebar-hamburger {
  display: none;
  flex-shrink: 0;
  width: 1.8rem;
  height: 1.8rem;
  border-radius: var(--radius);
  background: var(--sidebar-bg);
  cursor: pointer;
  align-items: center;
  justify-content: center;
  /* Three-line hamburger icon via CSS */
}
.sidebar-hamburger::before {
  content: "";
  display: block;
  width: 1rem;
  height: 2px;
  background: var(--sidebar-text);
  box-shadow: 0 -5px var(--sidebar-text), 0 5px var(--sidebar-text);
}
/* The in-drawer control above rides along with the off-canvas transform and
   is clipped by .sidebar's overflow:hidden, so it can only ever CLOSE the
   drawer. Opening needs a control that lives outside the sidebar. */
.sidebar-open-btn {
  display: none;
  position: fixed;
  top: var(--sp-3);
  left: var(--sp-3);
  z-index: 101;
  width: 2.4rem;
  height: 2.4rem;
  border-radius: var(--radius);
  background: var(--sidebar-bg);
  cursor: pointer;
}
.sidebar-open-btn::before {
  content: "";
  position: absolute;
  inset: 0;
  margin: auto;
  width: 1.1rem;
  height: 2px;
  background: var(--sidebar-text);
  box-shadow: 0 -5px var(--sidebar-text), 0 5px var(--sidebar-text);
}

/* When sidebar is open: show × (close) */
.sidebar-toggle:checked ~ .sidebar .sidebar-hamburger::before {
  content: "\00d7";
  background: transparent;
  box-shadow: none;
  font-size: 1.4rem;
  line-height: 1;
  color: var(--sidebar-text);
}

.side-nav {
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
  font-size: var(--fs-sm);
  margin-top: auto;
  margin-bottom: auto;
}
.side-nav a {
  color: var(--sidebar-text-dim);
  text-decoration: none;
}
.side-nav a:hover { color: var(--sidebar-text); }
.side-nav a[aria-current="page"] {
  color: var(--sidebar-text);
  font-weight: 600;
  text-decoration: underline;
}

.sidebar-foot {
  margin: var(--sp-6) 0 0;
  padding-top: var(--sp-4);
  border-top: 1px solid color-mix(in srgb, var(--sidebar-text-dim) 40%, transparent);
  color: var(--sidebar-text-dim);
  font-size: var(--fs-xs);
}

/* ── Content area ─────────────────────────────────────────────────────── */
.content-wrap {
  min-height: 100vh;
  background: var(--bg-color);
  /* Tile covers the full viewport. The radial gradient on .page-content
     punches a clear ellipse through the centre, leaving the sides tiled. */
  background-image: var(--content-tile);
  background-repeat: repeat;
  background-size: auto;
  background-position: 0 0;
  position: relative;
  z-index: 0;
}
/* Everything inside content-wrap is above the tile via local z-index */
.content-wrap > * { position: relative; z-index: 1; }

.page-content {
  --col-max: var(--content-max);
  padding: var(--sp-6) var(--sp-5);
  max-width: var(--col-max);
  width: 100%;
  margin-inline: auto;
  background: var(--bg-color);
  position: relative;
  z-index: 1;
}
/* Push past the fixed sidebar -- but only when there is one. Logged-out
   pages render no .sidebar at all, and they are meant to be plainly
   centred rather than offset by the width of absent chrome. */
.sidebar ~ .content-wrap .page-content {
  margin-left: max(calc(var(--sidebar-width) + var(--sp-5)),
                   calc(50vw - var(--col-max) / 2));
}

/* Radial gradient creates a transparent centre window — the tile shows
   through on the left and right sides only. */
.page-content::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: -1;
  background: var(--content-tile);
  background-repeat: repeat;
  mask-image: radial-gradient(
    ellipse 100% 100% at 50% 50%,
    transparent 20%,
    black 50%
  );
  -webkit-mask-image: radial-gradient(
    ellipse 100% 100% at 50% 50%,
    transparent 20%,
    black 50%
  );
  opacity: 0.15;
}
/* When .sidebar is absent from the DOM (logged-out), the sibling
   selector never matches, so this reverts to plain centring. */
.sidebar ~ .content-wrap .page-content {
  margin-inline: auto;
  margin-left: auto;
}

/* The logged-out home: just the site name, centred in the viewport.
   No chrome, no nav, nothing to operate -- so no border either. */
.page-content.blank-home {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding-block: var(--sp-6);
}
.blank-wordmark {
  margin: 0;
  font-size: var(--fs-2xl);
  color: var(--text-color);
}

.page-title { font-size: var(--fs-2xl); margin-bottom: var(--sp-5); }
.page-title:empty { display: none; }

/* ── Background tile variants — set via data-bg-tile on <body> ─────────── */
body[data-bg-tile="waterdrops"]    { --content-tile: var(--tile-waterdrops); }
body[data-bg-tile="arabesque"]     { --content-tile: var(--tile-arabesque); }
body[data-bg-tile="arabesque90"]   { --content-tile: var(--tile-arabesque90); }
body[data-bg-tile="arabesque180"]  { --content-tile: var(--tile-arabesque180); }

/* ── Below 64 rem: sidebar collapses off-screen, hamburger appears ─────── */
@media (max-width: 64rem) {
  /* Hamburger visible on mobile — sits to the left of the title via flex */
  .sidebar-hamburger { display: flex; }

  /* Fixed open button: on screen only while the drawer is shut. */
  .sidebar-open-btn { display: block; }
  .sidebar-toggle:checked ~ .sidebar-open-btn { display: none; }

  /* Clear the button so it does not sit on top of the page title. The
     sibling selector means this only applies when the button exists,
     i.e. signed in -- the logged-out shell has no chrome to clear. */
  .sidebar-open-btn ~ .content-wrap .page-content {
    padding-top: calc(2.4rem + var(--sp-3) + var(--sp-4));
  }

  /* Sidebar: slide off-screen to the left by default */
  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: var(--sidebar-width);
    height: 100vh;
    transform: translateX(calc(-1 * var(--sidebar-width)));
    transition: transform 0.2s ease-in;
    z-index: 100;
  }
  /* When open: slide in */
  .sidebar-toggle:checked ~ .sidebar {
    transform: translateX(0);
  }

  .sidebar-inner {
    padding: var(--sp-4) var(--sp-4);
  }
  .sidebar-title-wrap {
    margin-bottom: var(--sp-3);
  }
  .site-title {
    margin-bottom: 0;
    font-size: var(--fs-lg);
  }

  /* Nav and footer: hidden when closed, shown when open */
  .side-nav,
  .sidebar-foot {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.2s ease-in;
  }
  .side-nav { gap: var(--sp-3); margin-top: 0; margin-bottom: 0; }
  .sidebar-toggle:checked ~ .sidebar .side-nav {
    max-height: 30rem;
    margin-top: var(--sp-4);
  }
  .sidebar-toggle:checked ~ .sidebar .sidebar-foot {
    max-height: 4rem;
  }

  /* Page content centres on mobile */
  .page-content {
    margin-inline: auto;
    margin-left: auto;
    padding-left: var(--sp-4);
    padding-right: var(--sp-4);
  }
}
