:root {
  --bg: #0d1714;
  --bg-glow: #1d3a30;
  --gold: #d9b46a;
  --gold-line: rgba(217, 180, 106, .6);
  --gold-hover: rgba(217, 180, 106, .15);
  --ink: #f2ead9;
  --muted: #b9ad95;
  --mono: 'Courier Prime', monospace;
}

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  overflow: hidden;
  overscroll-behavior: none;
}
a { color: var(--gold); }
a:hover { color: var(--ink); }

.app {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  background: radial-gradient(90% 70% at 50% 40%, var(--bg-glow) 0%, var(--bg) 75%);
  font-family: var(--mono);
  color: var(--ink);
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

/* Top bar */
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding: 14px 24px;
}
.brand {
  font-family: 'Zilla Slab', serif;
  font-weight: 700;
  font-size: 20px;
  letter-spacing: .08em;
  color: var(--gold);
  white-space: nowrap;
}
.status {
  font-size: 13px;
  letter-spacing: .12em;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}
.hint { color: var(--muted); opacity: .7; }

/* Stage */
.stage {
  flex: 1;
  min-height: 0;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  perspective: 2600px;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  touch-action: pan-y pinch-zoom;
}
.error { padding: 24px; text-align: center; color: var(--muted); font-size: 15px; }

/* Spread view */
.book { position: relative; transform-style: preserve-3d; }
.leaf {
  position: absolute;
  top: 0;
  transform-origin: left center;
  transform-style: preserve-3d;
}
.face {
  position: absolute;
  inset: 0;
  overflow: hidden;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
}
.face--back { transform: rotateY(180deg); }
.face-inner {
  position: absolute;
  left: 0;
  top: 0;
  width: 794px;
  height: 1123px;
  transform-origin: 0 0;
}
.face-shade {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: linear-gradient(to right, rgba(0, 0, 0, .28) 0%, rgba(0, 0, 0, .08) 4%, rgba(0, 0, 0, 0) 12%);
}
.face--back .face-shade {
  background: linear-gradient(to left, rgba(0, 0, 0, .28) 0%, rgba(0, 0, 0, .08) 4%, rgba(0, 0, 0, 0) 12%);
}

/* Single-page view */
.single {
  position: relative;
  perspective: 2200px;
  box-shadow: 0 18px 40px -18px rgba(0, 0, 0, .7);
}
.sheet {
  position: absolute;
  inset: 0;
  overflow: hidden;
  transform-origin: left center;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  background: #17352e;
}

/* Controls */
.controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 18px;
  padding: 14px 24px 20px;
  flex-wrap: wrap;
}
.nav-btn {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 1px solid var(--gold-line);
  background: transparent;
  color: var(--gold);
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  transition: background .15s, opacity .15s, transform .1s;
}
.nav-btn:hover:not(:disabled) { background: var(--gold-hover); }
.nav-btn:active:not(:disabled) { transform: scale(.94); }
.nav-btn:disabled { opacity: .35; cursor: default; }

.slider {
  width: min(420px, 50vw);
  accent-color: var(--gold);
  cursor: pointer;
}
.page-label {
  min-width: 130px;
  text-align: center;
  font-size: 14px;
  letter-spacing: .1em;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}
.pill {
  height: 36px;
  padding: 0 14px;
  border-radius: 18px;
  border: 1px solid var(--gold-line);
  background: transparent;
  color: var(--gold);
  font-family: var(--mono);
  font-size: 13px;
  cursor: pointer;
  transition: background .15s;
}
.pill:hover { background: var(--gold-hover); }

button:focus-visible, .slider:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 3px;
}

/* Phones */
@media (max-width: 640px) {
  .topbar { padding: 10px 16px; }
  .brand { font-size: 15px; }
  .status { display: none; }
  .controls { gap: 10px 12px; padding: 10px 16px 14px; }
  .slider { order: 5; width: 100%; }
  .page-label { min-width: 0; font-size: 13px; }
  .pill { height: 32px; padding: 0 12px; font-size: 12px; }
}

@media (prefers-reduced-motion: reduce) {
  .book, .leaf, .sheet { transition-duration: 1ms !important; }
}
