/* ============================================================
   Carousel mode — opted into with <body class="mode-carousel">.

   Pages sit side by side and slide horizontally. A ribbon of full
   section names under the header slides with them: drag or wheel
   the ribbon and the pages follow, swipe the pages and the ribbon
   follows. The site menu is always the compact button, top right.
   ============================================================ */

.mode-carousel {
  --ribbon-h: 64px;
  --footer-h: 52px;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

/* ---------- Header: menu button at every width, far right ---------- */

.mode-carousel .header-right { gap: 12px; }
.mode-carousel .counter { order: 1; }
.mode-carousel .stepper { order: 2; display: flex; }
.mode-carousel .menu-btn  { order: 3; }

.mode-carousel .menu-btn {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  height: 38px;
  padding: 0 11px 0 13px;
  border-radius: 9px;
  border: 1px solid var(--line);
  background: var(--surf-1);
  color: var(--muted);
  cursor: pointer;
  transition: color .2s var(--ease), background .2s var(--ease), border-color .2s var(--ease);
}
.mode-carousel .menu-btn:hover { color: var(--primary); background: var(--surf-3); }
.mode-carousel .menu-btn svg { width: 15px; height: 15px; flex: 0 0 15px; }
.mode-carousel .menu-current {
  font-family: var(--mono);
  font-size: 11.5px;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--primary);
  white-space: nowrap;
}
.mode-carousel .ico-caret { transition: transform .25s var(--ease); }
.mode-carousel .menu-btn[aria-expanded="true"] {
  color: var(--primary);
  border-color: rgba(137,206,255,.45);
  background: var(--surf-3);
}
.mode-carousel .menu-btn[aria-expanded="true"] .ico-caret { transform: rotate(180deg); }

.mode-carousel .themes {
  display: none;
  position: fixed;
  top: calc(var(--header-h) + 8px);
  right: max(14px, var(--shell-pad));
  left: auto;
  flex-direction: column;
  align-items: stretch;
  gap: 2px;
  min-width: 208px;
  max-width: calc(100vw - 28px);
  padding: 6px;
  overflow: visible;
  border: 1px solid var(--line-soft);
  border-radius: 13px;
  background: rgba(12,19,36,.98);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  box-shadow: 0 20px 48px rgba(0,0,0,.55);
  z-index: 45;
}
.mode-carousel .themes.is-open { display: flex; }
.mode-carousel .theme-btn {
  padding: 11px 14px;
  font-size: 12px;
  border-radius: 9px;
  justify-content: flex-start;
}

/* ---------- Ribbon of section names ---------- */

.ribbon-wrap {
  position: fixed;
  top: var(--header-h);
  left: 0; right: 0;
  height: var(--ribbon-h);
  z-index: 35;
  background: rgba(12,19,36,.78);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--line);
}

.ribbon {
  position: relative;
  height: 100%;
  display: flex;
  align-items: center;
  gap: 44px;
  overflow-x: auto;
  overflow-y: hidden;
  scroll-snap-type: x mandatory;
  scrollbar-width: none;
  overscroll-behavior-x: contain;
  cursor: grab;
  /* names fade out toward both edges, so the centre reads as "here" */
  -webkit-mask-image: linear-gradient(90deg, transparent 0, #000 22%, #000 78%, transparent 100%);
          mask-image: linear-gradient(90deg, transparent 0, #000 22%, #000 78%, transparent 100%);
}
.ribbon::-webkit-scrollbar { display: none; }
.ribbon.is-following,
.ribbon.is-dragging { scroll-snap-type: none; }
.ribbon.is-dragging { cursor: grabbing; }
.ribbon.is-dragging .rb-item { pointer-events: none; }

.rb-item {
  position: relative;
  flex: 0 0 auto;
  scroll-snap-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  border: 0;
  background: none;
  padding: 0 2px 16px;
  cursor: pointer;
  color: var(--dim);
  font: inherit;
  white-space: nowrap;
  transition: color .3s var(--ease);
}
.rb-title {
  display: flex;
  align-items: baseline;
  gap: 8px;
  font-family: var(--mono);
  font-size: 13px;
  letter-spacing: .08em;
  text-transform: uppercase;
  transition: transform .3s var(--ease);
}
.rb-idx { font-size: 10.5px; opacity: .6; }
.rb-sum {
  /* out of flow, so a long summary never widens the gap between names */
  position: absolute;
  top: 22px;
  left: 50%;
  margin-left: -150px;
  width: 300px;
  text-align: center;
  font-size: 11.5px;
  color: var(--muted);
  opacity: 0;
  transform: translateY(-3px);
  transition: opacity .3s var(--ease), transform .3s var(--ease);
}
.rb-item:hover { color: var(--muted); }
.rb-item.is-active { color: #fff; }
.rb-item.is-active .rb-title { transform: scale(1.12); }
.rb-item.is-active .rb-idx { color: var(--primary); opacity: 1; }
.rb-item.is-active .rb-sum { opacity: 1; transform: none; }
.rb-item:focus-visible { outline: 2px solid var(--primary); outline-offset: 4px; border-radius: 6px; }

/* the fixed centre: a short bright bar the names slide over */
.ribbon-mark {
  position: absolute;
  left: 50%;
  bottom: -1px;
  width: 56px;
  height: 2px;
  margin-left: -28px;
  border-radius: 2px;
  background: var(--primary);
  box-shadow: 0 0 12px rgba(14,165,233,.7);
  pointer-events: none;
}
/* whole-tour progress, a hairline along the bottom edge */
.ribbon-progress {
  position: absolute;
  left: 0; bottom: -1px;
  height: 1px;
  width: 0;
  background: linear-gradient(90deg, rgba(14,165,233,0), rgba(14,165,233,.8));
  pointer-events: none;
}

/* ---------- Post navigation bar (blog posts) ----------
   All posts, previous and next stay in reach on every page of a post. */

.mode-carousel:has(.post-bar) { --postbar-h: 38px; }
.post-bar {
  position: fixed;
  top: calc(var(--header-h) + var(--ribbon-h));
  left: 0; right: 0;
  height: var(--postbar-h);
  z-index: 34;
  display: flex;
  align-items: center;
  padding: 0 28px;
  background: rgba(12,19,36,.72);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--line);
}
.post-bar-inner {
  width: 100%;
  max-width: 1080px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}
.post-bar .back-link { margin: 0; }

/* ---------- The pages ---------- */

.mode-carousel .deck {
  position: fixed;
  top: calc(var(--header-h) + var(--ribbon-h) + var(--postbar-h, 0px));
  left: 0; right: 0; bottom: var(--footer-h);
  padding: 0;
  display: flex;
  overflow-x: auto;
  overflow-y: hidden;
  scroll-snap-type: x mandatory;
  scrollbar-width: none;
  overscroll-behavior-x: contain;
}
.mode-carousel .deck::-webkit-scrollbar { display: none; }
/* Chrome draws a focus ring on scroll containers it focuses for keyboard
   scrolling; the ribbon already says which page has focus. */
.mode-carousel .deck:focus, .mode-carousel .deck:focus-visible,
.mode-carousel .chapter:focus, .mode-carousel .chapter:focus-visible { outline: none; }
.mode-carousel .deck.is-following { scroll-snap-type: none; }

.mode-carousel .chapter {
  flex: 0 0 100%;
  width: 100%;
  height: 100%;
  min-height: 0;
  display: block;
  overflow-y: auto;
  overflow-x: hidden;
  overscroll-behavior-y: contain;
  scroll-snap-align: start;
  scroll-snap-stop: always;
  padding: 20px 28px 56px;
  border-top: 0;
}
.mode-carousel .deck > .chapter:first-of-type { padding-top: 20px; }

/* pages that are sliding away dim and settle back slightly */
.mode-carousel .chapter-inner {
  transition: none;
  will-change: opacity, transform;
}

.mode-carousel .site-footer {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 35;
  height: var(--footer-h);
  max-width: none;
  margin: 0;
  padding: 0 var(--shell-pad);
  flex-wrap: nowrap;
  background: rgba(7,13,31,.82);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
}
.mode-carousel .site-footer > span:first-child {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.mode-carousel .site-footer > span:nth-child(2) { white-space: nowrap; }
.mode-carousel .foot-social { flex: 0 0 auto; }
.mode-carousel .foot-social a { width: 36px; height: 36px; }
.mode-carousel .foot-social svg { width: 18px; height: 18px; }

@media (max-width: 900px) {
  .mode-carousel { --ribbon-h: 58px; --footer-h: 48px; }
  .post-bar { padding: 0 18px; }
  .mode-carousel .site-footer { padding: 0 12px 0 18px; }
  .mode-carousel .site-footer > span:nth-child(2) { display: none; }
  .mode-carousel .counter, .mode-carousel .stepper { display: none; }
  .ribbon { gap: 30px; }
  .rb-title { font-size: 12px; }
  .mode-carousel .chapter { padding: 16px 18px 48px; }
  .mode-carousel .deck > .chapter:first-of-type { padding-top: 16px; }
}

@media (max-width: 430px) {
  .mode-carousel .menu-current { max-width: 22vw; overflow: hidden; text-overflow: ellipsis; }
}
