/*
 * Case page shell: "All cases" back pill, section contents on the right
 * and the floating previous / all cases / next bar (js/case-shell.js).
 * Surfaces reuse the case back-button glass (case-study.css).
 */

:root {
  --case-shell-surface: rgba(12, 12, 12, 0.52);
  --case-shell-surface-hover: rgba(255, 255, 255, 0.1);
  --case-shell-line: rgba(255, 255, 255, 0.12);
  --case-shell-ink: #f4f4ef;
  --case-shell-ink-muted: rgba(244, 244, 239, 0.62);
  --case-shell-mark: rgba(236, 234, 228, 0.28);
  --case-shell-mark-active: #eceae4;
  --case-shell-panel: rgba(22, 22, 20, 0.92);
}

html[data-theme="light"] {
  --case-shell-surface: var(--site-header-light-top-bg, #141414);
  --case-shell-surface-hover: rgba(255, 255, 255, 0.12);
  --case-shell-line: transparent;
  --case-shell-mark: rgba(27, 27, 25, 0.22);
  --case-shell-mark-active: #1b1b19;
  --case-shell-panel: rgba(255, 255, 255, 0.96);
}

/* Back: the existing glass circle becomes a labelled pill. */
body:has(.section_post-content) > .back-button.case-shell-back,
body:has(.section_post-header) > .back-button.case-shell-back {
  width: auto;
  gap: 0.5rem;
  padding: 0 1.125rem 0 0.875rem;
  border-radius: 999px;
  font-size: 0.9375rem;
  font-weight: 500;
  line-height: 1;
  letter-spacing: -0.011em;
  text-decoration: none;
  white-space: nowrap;
}

/* footer-lang.js clones the back button into the mobile bar as an icon-only circle. */
.navbar_mobile-back .case-shell-back__label {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
}

.case-shell-back .back-button__icon {
  width: 1.125rem;
  height: 1.125rem;
  flex-shrink: 0;
}

/* Contents: quiet marks on the right edge, labels on hover or focus. */
.case-toc {
  position: fixed;
  z-index: 300;
  top: 50%;
  right: calc(20px + env(safe-area-inset-right, 0px));
  transform: translateY(-50%);
  display: none;
}

@media (min-width: 1200px) {
  .case-toc {
    display: block;
  }
}

.case-toc__list {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  margin: 0;
  padding: 0.5rem;
  list-style: none;
  border-radius: 1rem;
  transition-property: background-color, box-shadow;
  transition-duration: 0.2s;
  transition-timing-function: ease;
}

.case-toc__link {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.75rem;
  min-height: 1.5rem;
  padding: 0.125rem 0;
  border-radius: 0.375rem;
  color: var(--_colors---grey--500, #797770);
  font-size: 0.8125rem;
  line-height: 1.25;
  letter-spacing: -0.006em;
  text-decoration: none;
}

.case-toc__label {
  max-width: 0;
  overflow: hidden;
  opacity: 0;
  white-space: nowrap;
  text-overflow: ellipsis;
  transition-property: max-width, opacity;
  transition-duration: 0.24s, 0.16s;
  transition-timing-function: cubic-bezier(0.2, 0, 0, 1), ease;
}

.case-toc__mark {
  flex-shrink: 0;
  width: 0.875rem;
  height: 2px;
  border-radius: 1px;
  background: var(--case-shell-mark);
  transition-property: background-color;
  transition-duration: 0.2s;
  transition-timing-function: ease;
}

.case-toc__link.is-active {
  color: var(--case-shell-mark-active);
}

.case-toc__link.is-active .case-toc__mark {
  background: var(--case-shell-mark-active);
}

.case-toc:hover .case-toc__list,
.case-toc:focus-within .case-toc__list {
  background: var(--case-shell-panel);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.18);
}

.case-toc:hover .case-toc__label,
.case-toc:focus-within .case-toc__label {
  max-width: 16rem;
  opacity: 1;
}

.case-toc__link:hover {
  color: var(--case-shell-mark-active);
}

.case-toc__link:hover .case-toc__mark {
  background: var(--case-shell-mark-active);
}

.case-toc__link:focus-visible {
  outline: 2px solid var(--case-shell-mark-active);
  outline-offset: 2px;
}

/* Floating previous / all cases / next. */
.case-pager {
  position: fixed;
  z-index: 300;
  left: 50%;
  bottom: var(--navbar-float-bottom, max(1.25rem, env(safe-area-inset-bottom, 0px)));
  display: flex;
  align-items: center;
  gap: 0.125rem;
  padding: 0.25rem;
  border: 1px solid var(--case-shell-line);
  border-radius: 999px;
  background-color: var(--case-shell-surface);
  box-shadow:
    0 4px 12px rgba(0, 0, 0, 0.12),
    inset 0 1px 0 rgba(255, 255, 255, 0.08);
  -webkit-backdrop-filter: blur(16px) saturate(165%);
  backdrop-filter: blur(16px) saturate(165%);
  transform: translateX(-50%);
}

html[data-theme="light"] .case-pager {
  box-shadow: none;
  -webkit-backdrop-filter: none;
  backdrop-filter: none;
}

.case-pager .case-pager__btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  /* Bar height equals the back-to-top button, so both sit on one line. */
  width: calc(var(--back-to-top-size, 3.5rem) - 0.5rem - 2px);
  height: calc(var(--back-to-top-size, 3.5rem) - 0.5rem - 2px);
  border-radius: 999px;
  color: var(--case-shell-ink);
  text-decoration: none;
  transition: background-color 0.18s ease;
}

html[data-theme="light"] .case-pager .case-pager__btn {
  color: var(--case-shell-ink);
}

.case-pager .case-pager__btn:hover,
html[data-theme="light"] .case-pager .case-pager__btn:hover {
  background-color: var(--case-shell-surface-hover);
  color: var(--case-shell-ink);
}

.case-pager__btn:focus-visible {
  outline: 2px solid var(--case-shell-ink);
  outline-offset: -2px;
}

.case-pager__btn svg {
  width: 1.25rem;
  height: 1.25rem;
}

/* Case pages have no chat button, so back-to-top drops onto the pager line. */
body:has(.case-pager) .back-to-top {
  bottom: var(--navbar-float-bottom, max(1.25rem, env(safe-area-inset-bottom, 0px)));
}

/* Name of the neighbouring case, shown above the bar on hover. */
.case-pager__btn[data-tip] {
  position: relative;
}

.case-pager__btn[data-tip]::after {
  content: attr(data-tip);
  position: absolute;
  bottom: calc(100% + 0.75rem);
  left: 50%;
  padding: 0.375rem 0.625rem;
  border-radius: 0.5rem;
  background: var(--case-shell-surface);
  color: var(--case-shell-ink);
  font-size: 0.8125rem;
  line-height: 1.2;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 0.25rem);
  transition-property: opacity, transform;
  transition-duration: 0.16s;
  transition-timing-function: ease;
}

html:not([data-theme="light"]) .case-pager__btn[data-tip]::after {
  background: rgba(22, 22, 20, 0.94);
  border: 1px solid var(--case-shell-line);
}

.case-pager__btn[data-tip]:hover::after,
.case-pager__btn[data-tip]:focus-visible::after {
  opacity: 1;
  transform: translate(-50%, 0);
}

@media (hover: none) {
  .case-pager__btn[data-tip]::after {
    display: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  .case-toc__label,
  .case-toc__mark,
  .case-pager__btn[data-tip]::after {
    transition: none;
  }
}
