*,
*::before,
*::after {
  box-sizing: border-box;
}

:root {
  --fg: #0c0c0c;
  --muted: #8c8c8c;
  --bg: #ffffff;
  --rule: #ededed;
  --page-shadow: 0 1px 2px rgba(0, 0, 0, 0.06), 0 8px 24px rgba(0, 0, 0, 0.04);
  --gutter: clamp(1rem, 2.5vw, 2rem);
  --spread-gap: 4px;
  --mono: "IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

html,
body {
  height: 100%;
}

html {
  background: var(--bg);
  color: var(--fg);
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  font-family: var(--mono);
  font-size: 12.5px;
  line-height: 1.55;
  font-weight: 400;
  letter-spacing: 0.01em;
  min-height: 100dvh;
  display: grid;
  grid-template-rows: auto 1fr auto auto;
  overscroll-behavior-y: none;
}

a {
  color: inherit;
  text-decoration: none;
  transition: color 150ms ease, opacity 150ms ease;
}
a:hover,
a:focus-visible {
  color: var(--muted);
  outline: none;
}

.chrome a {
  color: var(--muted);
}
.chrome a:hover,
.chrome a:focus-visible {
  color: var(--fg);
}

/* --- top + bottom editorial rails (chrome) --- */

.chrome {
  display: grid;
  grid-template-columns: 1fr 1fr;
  padding: 1.25rem var(--gutter);
  align-items: start;
}

.chrome p {
  margin: 0;
}

.chrome-left {
  text-align: left;
}

.chrome-right {
  text-align: right;
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
}

.chrome-right a + a,
.chrome-right p + a,
.chrome-right a + p {
  margin-top: 0;
}

.mark {
  font-weight: 500;
  letter-spacing: 0.02em;
}

.role,
.focus,
.location {
  color: var(--muted);
}

.chrome-bottom {
  border-top: 1px solid var(--rule);
  padding-top: 1rem;
  padding-bottom: 1.25rem;
  align-items: end;
}

.focus {
  letter-spacing: 0.04em;
  font-size: 0.95em;
}

/* --- reader stage --- */

#reader {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 var(--gutter);
  min-height: 0;
}

#stage {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

#stage-inner {
  display: flex;
  gap: var(--spread-gap);
  justify-content: center;
  align-items: flex-start;
  max-width: 100%;
  transition: opacity 160ms ease;
}

#stage-inner.is-fading {
  opacity: 0;
}

.leaf {
  background: #fff;
  box-shadow: var(--page-shadow);
  overflow: hidden;
  position: relative;
  line-height: 0;
  user-select: none;
}

.leaf-half {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 50%;
  z-index: 2;
  background: transparent;
  border: 0;
  padding: 0;
  appearance: none;
  -webkit-appearance: none;
  outline: none;
  font: inherit;
  color: inherit;
}
.leaf-half-prev {
  left: 0;
  cursor: w-resize;
}
.leaf-half-next {
  right: 0;
  cursor: e-resize;
}
.leaf-half[data-disabled="true"] {
  cursor: default;
}
.leaf-half:focus-visible {
  outline: 1px dashed var(--muted);
  outline-offset: -6px;
}

.leaf canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.leaf-label {
  position: absolute;
  top: 0.4rem;
  left: 0.5rem;
  font-size: 10px;
  color: var(--muted);
  opacity: 0;
  transition: opacity 150ms ease;
  pointer-events: none;
  mix-blend-mode: multiply;
}

.leaf:hover .leaf-label,
.leaf:focus-visible .leaf-label {
  opacity: 1;
}

/* --- dock (prev / counter / next) --- */

.dock {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  padding: 1rem var(--gutter) 0.25rem;
  gap: 1rem;
}

.dock-btn,
.dock-zoom {
  background: transparent;
  border: 0;
  padding: 0.25rem 0;
  font: inherit;
  color: var(--fg);
  cursor: pointer;
  letter-spacing: 0.02em;
  transition: color 150ms ease, opacity 150ms ease;
  outline: none;
}

.dock-prev {
  justify-self: start;
}
.dock-next {
  justify-self: end;
}

.dock-center {
  display: inline-flex;
  align-items: center;
  gap: 1.25rem;
  justify-self: center;
}

.dock-btn[disabled] {
  color: var(--muted);
  cursor: default;
  opacity: 0.5;
}

.dock-btn:not([disabled]):hover,
.dock-btn:not([disabled]):focus-visible,
.dock-zoom:hover,
.dock-zoom:focus-visible {
  color: var(--muted);
}

.dock-zoom {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.dock-zoom:hover,
.dock-zoom:focus-visible {
  color: var(--fg);
}

.counter {
  color: var(--muted);
  letter-spacing: 0.08em;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.counter strong {
  color: var(--fg);
  font-weight: 500;
}

.fallback {
  color: var(--muted);
  text-align: center;
}

/* --- lightbox --- */

#lightbox {
  position: fixed;
  inset: 0;
  background: rgba(255, 255, 255, 0.985);
  display: none;
  z-index: 50;
  touch-action: none;
}

#lightbox.is-open {
  display: flex;
  flex-direction: column;
}

#lightbox-stage {
  flex: 1;
  position: relative;
  overflow: hidden;
  cursor: grab;
}

#lightbox-stage.is-grabbing {
  cursor: grabbing;
}

#lightbox-stage canvas {
  position: absolute;
  top: 0;
  left: 0;
  display: block;
  transform-origin: 0 0;
  will-change: transform;
  box-shadow: var(--page-shadow);
  max-width: none;
}

.lightbox-chrome {
  display: flex;
  align-items: center;
  gap: 1.25rem;
  padding: 0.9rem var(--gutter);
  justify-content: flex-end;
  border-top: 1px solid var(--rule);
  background: #fff;
}

.lightbox-chrome button {
  background: transparent;
  border: 0;
  font: inherit;
  color: var(--fg);
  cursor: pointer;
  padding: 0.25rem 0;
  letter-spacing: 0.02em;
  transition: color 150ms ease;
  outline: none;
}

.lightbox-chrome button:hover,
.lightbox-chrome button:focus-visible {
  color: var(--muted);
}

#lightbox-counter {
  color: var(--muted);
  margin-right: auto;
  letter-spacing: 0.08em;
  font-variant-numeric: tabular-nums;
}

/* --- responsive --- */

@media (max-width: 720px) {
  :root {
    --gutter: 1rem;
  }
  body {
    font-size: 12px;
  }
  .chrome {
    grid-template-columns: 1fr;
    gap: 0.35rem;
  }
  .chrome-right {
    text-align: left;
  }
  .chrome-bottom {
    padding-top: 1rem;
  }
  .focus {
    letter-spacing: 0.03em;
  }
  .dock {
    padding: 0.5rem var(--gutter) 0.25rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  #stage-inner,
  a::after,
  .dock-btn::after,
  .lightbox-chrome button::after {
    transition: none;
  }
}
