/* ------------------------------------------------------------------------
   Liseuse — layout & components
   ------------------------------------------------------------------------ */

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

html,
body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
}

body {
  font-family: var(--font-ui);
  font-size: 16px;
  line-height: 1.45;
  color: var(--text);
  background: var(--bg);
  background-image: radial-gradient(
    140% 110% at 50% 38%,
    var(--bg) 30%,
    var(--bg-deep) 100%
  );
  transition: background-color var(--duration-normal) ease;
  -webkit-font-smoothing: antialiased;
}

/* Paper grain over everything — atmosphere, never in the way. */
body::after {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 60;
  pointer-events: none;
  opacity: var(--grain-opacity);
  mix-blend-mode: overlay;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

img {
  -webkit-user-drag: none;
  user-select: none;
  -webkit-touch-callout: none;
}

.skip-link {
  position: fixed;
  top: 10px;
  left: 10px;
  z-index: 100;
  padding: 10px 16px;
  border-radius: 999px;
  background: var(--panel-bg);
  color: var(--text);
  font-size: 0.85rem;
  text-decoration: none;
  transform: translateY(-300%);
}
.skip-link:focus-visible {
  transform: none;
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

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

.stage {
  position: fixed;
  inset: 0;
  overflow: hidden;
  touch-action: none;
  cursor: default;
}

/* Picture light behind the planche. */
.stage::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: radial-gradient(
    ellipse 64% 56% at 50% 46%,
    var(--stage-light),
    transparent 72%
  );
}

html[data-chrome="hidden"] .stage {
  cursor: none;
}

.zoom-layer {
  position: absolute;
  inset: 0;
  transform-origin: 0 0;
  will-change: transform;
}
.zoom-layer.is-animating {
  transition: transform var(--duration-normal) var(--ease-out-expo);
}

.spread {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: calc(var(--chrome-top) + var(--stage-pad)) var(--stage-pad)
    calc(var(--chrome-bottom) + var(--stage-pad));
  transition:
    opacity 150ms var(--ease-in-soft),
    transform 150ms var(--ease-in-soft);
}

/* When the chrome sleeps, the planche leans in. */
html[data-chrome="hidden"] .spread.can-breathe {
  transform: scale(1.045);
  transition: transform var(--duration-slow) var(--ease-out-expo);
}

picture {
  display: contents;
}

.leaf {
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
  border-radius: 2px;
  box-shadow: var(--shadow-page);
  background: oklch(20% 0.015 230);
  transition: box-shadow var(--duration-normal) ease;
}
.spread[data-mode="double"] .leaf {
  max-width: calc(50% - 2px);
}

/* Waiting dot — only appears when a page is slow to decode. */
.stage.is-waiting::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  width: 10px;
  height: 10px;
  margin: -5px;
  border-radius: 50%;
  background: var(--accent);
  animation: pulse 900ms ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 0.25; transform: scale(0.8); }
  50% { opacity: 1; transform: scale(1.15); }
}

/* ------------------------------------------------------------- chrome -- */

.chrome {
  position: fixed;
  left: 0;
  right: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  transition:
    opacity var(--duration-normal) ease,
    translate var(--duration-normal) ease;
}

html[data-chrome="hidden"] .chrome,
html[data-chrome="hidden"] .edge-nav {
  opacity: 0;
  pointer-events: none;
}
html[data-chrome="hidden"] .chrome-top {
  translate: 0 -10px;
}
html[data-chrome="hidden"] .chrome-bottom {
  translate: 0 10px;
}

.chrome-top {
  top: 0;
  height: var(--chrome-top);
  justify-content: space-between;
  gap: 16px;
  padding: 0 clamp(14px, 2.5vw, 28px);
}

.masthead {
  min-width: 0;
  display: flex;
  align-items: baseline;
  gap: 14px;
}
.masthead-title {
  margin: 0;
  font-family: var(--font-display);
  font-size: clamp(1.02rem, 0.9rem + 0.6vw, 1.3rem);
  font-weight: 600;
  letter-spacing: 0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.masthead-meta {
  margin: 0;
  font-size: 0.66rem;
  font-weight: 600;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--muted);
  white-space: nowrap;
}

.toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

/* ------------------------------------------------------------ buttons -- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 38px;
  min-width: 38px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--btn-bg);
  color: var(--muted);
  font-family: var(--font-ui);
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  text-decoration: none;
  cursor: pointer;
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  transition:
    color var(--duration-fast) ease,
    border-color var(--duration-fast) ease,
    background-color var(--duration-fast) ease,
    box-shadow var(--duration-fast) ease,
    transform var(--duration-fast) ease;
}
.btn:hover {
  color: var(--text);
  border-color: color-mix(in oklab, var(--accent) 45%, var(--line));
  background: var(--btn-bg-hover);
}
.btn:active {
  transform: scale(0.94);
}
.btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.btn[aria-pressed="true"],
.btn[aria-expanded="true"] {
  color: var(--accent);
  border-color: color-mix(in oklab, var(--accent) 55%, transparent);
  background: var(--accent-soft);
}
.btn svg {
  width: 17px;
  height: 17px;
  flex-shrink: 0;
}

.btn-download {
  padding: 0 15px;
  color: var(--text);
  border-color: color-mix(in oklab, var(--accent) 50%, transparent);
}
.btn-download:hover {
  color: var(--accent-warm);
  border-color: color-mix(in oklab, var(--accent-warm) 65%, transparent);
  box-shadow: 0 4px 20px -6px color-mix(in oklab, var(--accent-warm) 45%, transparent);
}
.btn-download .dl-size {
  color: var(--muted);
  font-weight: 400;
}

/* Theme button shows the mood you would switch to. */
html[data-theme="encre"] .icon-moon {
  display: none;
}
html[data-theme="papier"] .icon-sun {
  display: none;
}

/* ----------------------------------------------------------- edge nav -- */

.edge-nav {
  position: fixed;
  top: 50%;
  z-index: 30;
  width: 46px;
  height: 46px;
  margin-top: -23px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--btn-bg);
  color: var(--text);
  cursor: pointer;
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  opacity: 0;
  transition:
    opacity var(--duration-normal) ease,
    border-color var(--duration-fast) ease,
    background-color var(--duration-fast) ease,
    transform var(--duration-fast) ease;
}
.edge-nav.prev { left: clamp(10px, 2vw, 26px); }
.edge-nav.next { right: clamp(10px, 2vw, 26px); }
.edge-nav svg { width: 20px; height: 20px; }

.stage:hover ~ .edge-nav,
.edge-nav:hover,
.edge-nav:focus-visible {
  opacity: 0.95;
}
@media (hover: none) {
  .edge-nav { opacity: 0.55; }
}
.edge-nav:hover {
  border-color: color-mix(in oklab, var(--accent) 50%, var(--line));
  background: var(--btn-bg-hover);
}
.edge-nav:active { transform: scale(0.92); }
.edge-nav:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.edge-nav[disabled] {
  opacity: 0 !important;
  pointer-events: none;
}

/* ------------------------------------------------------------- pager --- */

.chrome-bottom {
  bottom: 0;
  height: var(--chrome-bottom);
  flex-direction: column;
  justify-content: center;
  gap: 3px;
  padding-bottom: max(6px, env(safe-area-inset-bottom));
}

.page-label {
  font-family: var(--font-display);
  font-size: 1.02rem;
  font-weight: 600;
  letter-spacing: 0.01em;
}
.page-counter {
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.14em;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.progress {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  height: 2px;
  z-index: 45;
  background: var(--line);
}
.progress-fill {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--accent-warm));
  transform-origin: 0 50%;
  transform: scaleX(0);
  transition: transform var(--duration-slow) var(--ease-out-expo);
}

/* ------------------------------------------------------------- thumbs -- */

.thumbs {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 50;
  padding: 16px clamp(14px, 3vw, 28px)
    calc(16px + env(safe-area-inset-bottom));
  background: var(--panel-bg);
  border-top: 1px solid var(--line);
  box-shadow: var(--shadow-float);
  -webkit-backdrop-filter: blur(18px);
  backdrop-filter: blur(18px);
  transform: translateY(105%);
  transition: transform 380ms var(--ease-out-expo);
}
.thumbs.is-open {
  transform: translateY(0);
}

.thumbs-list {
  display: flex;
  gap: 14px;
  justify-content: safe center;
  margin: 0;
  padding: 4px;
  list-style: none;
  overflow-x: auto;
  scroll-snap-type: x proximity;
  scrollbar-width: thin;
}
.thumb-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 7px;
  padding: 0;
  border: 0;
  background: none;
  color: var(--muted);
  font-family: var(--font-ui);
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  cursor: pointer;
  scroll-snap-align: center;
}
.thumb-btn img {
  height: clamp(96px, 16vh, 138px);
  width: auto;
  border-radius: 4px;
  border: 2px solid transparent;
  box-shadow: 0 4px 14px -4px oklch(0% 0 0 / 0.4);
  transition:
    border-color var(--duration-fast) ease,
    transform var(--duration-fast) ease;
}
.thumb-btn:hover img {
  transform: translateY(-3px);
}
.thumb-btn:hover {
  color: var(--text);
}
.thumb-btn:focus-visible {
  outline: none;
}
.thumb-btn:focus-visible img {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.thumb-btn[aria-current="true"] {
  color: var(--accent);
}
.thumb-btn[aria-current="true"] img {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent-soft), 0 6px 18px -4px oklch(0% 0 0 / 0.45);
}

/* --------------------------------------------------------------- help -- */

.help {
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 0;
  max-width: min(440px, calc(100vw - 32px));
  background: var(--panel-bg);
  color: var(--text);
  box-shadow: var(--shadow-float);
  -webkit-backdrop-filter: blur(18px);
  backdrop-filter: blur(18px);
}
.help::backdrop {
  background: oklch(10% 0.02 230 / 0.55);
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
}
.help-inner {
  padding: 26px 28px 24px;
}
.help h2 {
  margin: 0 0 4px;
  font-family: var(--font-display);
  font-size: 1.25rem;
  font-weight: 600;
}
.help-sub {
  margin: 0 0 18px;
  font-size: 0.8rem;
  color: var(--muted);
}
.help dl {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 9px 16px;
  margin: 0;
  font-size: 0.83rem;
}
.help dt {
  display: flex;
  gap: 4px;
  justify-content: flex-end;
}
.help dd {
  margin: 0;
  color: var(--muted);
  align-self: center;
}
.help kbd {
  display: inline-block;
  min-width: 20px;
  padding: 2px 7px;
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 6px;
  background: var(--btn-bg);
  font-family: ui-monospace, "SF Mono", monospace;
  font-size: 0.7rem;
  text-align: center;
}
.help-close {
  position: absolute;
  top: 14px;
  right: 14px;
}
.help-footer {
  margin: 20px 0 0;
  padding-top: 14px;
  border-top: 1px solid var(--line);
  font-size: 0.74rem;
  color: var(--muted);
}

/* --------------------------------------------------------- utilities --- */

.sr-announcer,
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.noscript {
  position: fixed;
  inset: auto 16px 16px;
  z-index: 90;
  margin: 0;
  padding: 14px 18px;
  border-radius: 12px;
  background: var(--panel-bg);
  border: 1px solid var(--line);
  font-size: 0.9rem;
  text-align: center;
}

.error-panel {
  position: fixed;
  inset: 50% auto auto 50%;
  translate: -50% -50%;
  z-index: 80;
  padding: 22px 26px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--panel-bg);
  text-align: center;
  font-size: 0.92rem;
  box-shadow: var(--shadow-float);
}

/* --------------------------------------------------------- boot scene -- */

@keyframes boot-rise {
  from { opacity: 0; transform: translateY(16px) scale(0.988); }
  to { opacity: 1; transform: none; }
}
@keyframes boot-fade {
  from { opacity: 0; }
  to { opacity: 1; }
}

html.booting .spread {
  animation: boot-rise 700ms var(--ease-out-expo) 80ms backwards;
}
html.booting .chrome-top {
  animation: boot-fade 600ms ease 320ms backwards;
}
html.booting .chrome-bottom,
html.booting .progress {
  animation: boot-fade 600ms ease 440ms backwards;
}
html.booting .stage::before {
  animation: boot-fade 1100ms ease backwards;
}

/* ---------------------------------------------------- small screens ---- */

@media (max-width: 700px) {
  .masthead { flex-direction: column; gap: 1px; }
  .masthead-title { font-size: 0.98rem; }
  .masthead-meta { display: none; }
  .toolbar { gap: 5px; }
  .btn { height: 34px; min-width: 34px; }
  .btn svg { width: 15px; height: 15px; }
  .btn-download { padding: 0 11px; }
  .btn-download .dl-size { display: none; }
  .btn-mode { display: none; }
  .page-label { font-size: 0.94rem; }
}

/* ------------------------------------------------------ reduced motion - */

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
  html[data-chrome="hidden"] .spread.can-breathe {
    transform: none;
  }
}
