:root {
  --paper: #f3ecdd;
  --ink: #2b251c;
  --bg: #262017;
  --accent: #8a6d3b;
  --tint: #f5edd8;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: 'Cormorant Garamond', Georgia, 'Times New Roman', serif;
  font-weight: 500;
  background: var(--bg);
  color: var(--paper);
  overflow: hidden;
}

/* Full-bleed page: no frame, no box shadow. */
#stage {
  position: fixed;
  inset: 0;
  overflow: auto;
  display: flex;
  justify-content: safe center;
  align-items: safe center;
  cursor: grab;
}
#stage.dragging { cursor: grabbing; }
.page {
  position: relative;
  flex: none;
  line-height: 0;
}
/* Warm tint multiplied onto the page scan itself. */
.page::after {
  content: '';
  position: absolute;
  inset: 0;
  background: var(--tint);
  mix-blend-mode: multiply;
  pointer-events: none;
  opacity: 1;
  transition: opacity .3s ease;
}
body.no-tint .page::after { opacity: 0; }
#page-img {
  display: block;
  user-select: none;
  -webkit-user-drag: none;
}

/* Overlaid chrome; fades out when idle. */
.chrome {
  position: fixed;
  z-index: 10;
  transition: opacity .35s ease;
}
body.idle .chrome { opacity: 0; pointer-events: none; }

.hud {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 14px;
  background: rgba(15, 12, 9, 0.72);
  border-radius: 8px;
  color: var(--paper);
  font-size: 1.2rem;
}

/* Title + issue selector, top-left. */
#top { top: 14px; left: 14px; }
#top h1 { margin: 0; font-size: 1.2rem; font-weight: 500; }
.issue-nav { display: flex; gap: 8px; align-items: baseline; }
.issue-nav label { opacity: .7; }
#heft-select {
  font: inherit;
  padding: 3px 8px;
  color: var(--paper);
  background: transparent;
  border: 1px solid var(--accent);
  border-radius: 4px;
}
#heft-select option { color: var(--ink); background: var(--paper); }

/* Page/article caption, bottom-center. */
#caption {
  bottom: 14px;
  left: 50%;
  transform: translateX(-50%);
  max-width: min(84vw, 900px);
  justify-content: center;
}
#page-label { flex: none; }
#article-label {
  opacity: .75;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Zoom controls, bottom-right. */
#zoom-toolbar { bottom: 14px; right: 14px; }
#zoom-toolbar button {
  font: inherit;
  min-width: 30px;
  padding: 4px 8px;
  color: var(--paper);
  background: transparent;
  border: 1px solid transparent;
  border-radius: 4px;
  cursor: pointer;
}
#zoom-toolbar button:hover { background: rgba(243, 236, 221, 0.16); }
#tint-toggle.active {
  border-color: var(--accent);
  background: rgba(138, 109, 59, 0.30);
}
#zoom-level {
  min-width: 48px;
  text-align: center;
}
.sep { width: 1px; height: 16px; background: var(--accent); opacity: .5; }

/* Prev/next edge arrows. */
.edge {
  top: 50%;
  transform: translateY(-50%);
  width: 56px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: 8px;
  background: rgba(15, 12, 9, 0.4);
  color: var(--paper);
  cursor: pointer;
  transition: opacity .35s ease, background .15s ease;
}
.edge svg { display: block; }
.edge:hover { background: rgba(15, 12, 9, 0.72); }
#prev { left: 14px; }
#next { right: 14px; }

/* ---- Mobile & tablet: app bar + bottom controls. ----
   On narrow screens the floating caption and zoom toolbar collide
   (the toolbar alone is wider than a phone). Drop the caption; prev/next
   are standalone buttons flanking a centered zoom bar at the bottom. */
@media (max-width: 1199px) {
  /* Title + issue selector: slim full-width bar below the notch. */
  #top {
    top: 0;
    left: 0;
    right: 0;
    border-radius: 0;
    border-bottom: 1px solid rgba(138, 109, 59, 0.45);
    padding: calc(8px + env(safe-area-inset-top)) 12px 8px;
    gap: 10px;
  }
  #top h1 { font-size: 1.05rem; }
  .issue-nav { flex: 1 1 auto; min-width: 0; }
  #heft-select { width: 100%; }

  /* Drop the caption; prev/next are standalone buttons flanking the zoom bar. */
  #caption { display: none; }

  #prev,
  #next {
    top: auto;
    transform: none;
    bottom: calc(8px + env(safe-area-inset-bottom));
    width: 44px;
    height: 48px;
    border-radius: 8px;
    background: rgba(15, 12, 9, 0.72);
  }
  #prev { left: 8px; }
  #next { right: 8px; }

  /* Zoom controls: rounded bar centered between the arrows. */
  #zoom-toolbar {
    bottom: calc(8px + env(safe-area-inset-bottom));
    left: 0;
    right: 0;
    margin: 0 auto;
    width: max-content;
    max-width: calc(100vw - 120px);
    height: 48px;
    border-radius: 8px;
    justify-content: center;
    justify-content: safe center;
    gap: 1px;
    padding: 0 6px;
    font-size: 1rem;
    overflow-x: auto;
  }
  #zoom-toolbar button {
    min-width: 28px;
    padding: 10px 5px;
    flex: 0 0 auto;
  }
  #zoom-level { min-width: 28px; }
  /* Decorative separators hidden on mobile to save width. */
  .sep { display: none; }
}
