/* Mordet på Colorama — compact reader layout */
:root {
  --ink:   #14100a;
  --cream: #f3ead8;
  --paper: #f3ead8;
  --blood: #8b1a1a;
  --gold:  #c9a84c;
  --bar-h: 0px;
}

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

html {
  font-size: 16px;
  background: var(--ink);
  overflow-anchor: none;
  height: 100%;
}

[hidden] { display: none !important; pointer-events: none !important; }

button, .audio-badge, .lang-btn, .toc-btn, .extras-btn, .nav-btn {
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

body {
  background: var(--ink);
  color: var(--cream);
  font-family: 'Crimson Text', Georgia, serif;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  overflow-x: hidden;
  overflow-anchor: none;
}

/* Subtle grain; slightly quieter so paper doesn't glow */
body::after {
  content: '';
  position: fixed;
  inset: 0;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='0.028'/%3E%3C/svg%3E");
  pointer-events: none;
  z-index: 9999;
}

/* ── Slim top bar ── */
.topbar {
  flex-shrink: 0;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.35rem 0.85rem;
  width: 100%;
  padding: 0.4rem 0.75rem 0.45rem;
  padding-top: max(0.4rem, env(safe-area-inset-top));
  background: #100c08;
  border-bottom: 1px solid rgba(201,168,76,0.16);
  z-index: 200;
  position: relative;
  isolation: isolate;
  pointer-events: auto;
}

.brand {
  min-width: 0;
  line-height: 1.15;
}

.eyebrow {
  font-size: 0.55rem;
  letter-spacing: 0.28em;
  text-transform: uppercase;
  color: var(--gold);
  opacity: 0.7;
  margin-bottom: 0.05rem;
}

.book-title {
  font-family: 'Playfair Display', serif;
  font-size: clamp(1.05rem, 3.4vw, 1.55rem);
  font-weight: 900;
  line-height: 1.05;
  color: var(--cream);
}
.book-title em { color: var(--blood); font-style: italic; }

.book-author {
  font-family: 'Playfair Display', serif;
  font-size: clamp(0.62rem, 1.6vw, 0.75rem);
  font-style: italic;
  color: var(--gold);
  opacity: 0.8;
  margin-top: 0.05rem;
}

.topbar-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem 0.6rem;
  margin-left: auto;
}

.lang-bar {
  display: inline-flex;
  border: 1px solid rgba(201,168,76,0.22);
  border-radius: 4px;
  overflow: hidden;
}
.lang-btn {
  background: transparent;
  border: none;
  color: rgba(201,168,76,0.48);
  font-family: 'Crimson Text', serif;
  font-size: 0.72rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  cursor: pointer;
  padding: 0.45rem 0.8rem;
  min-height: 44px;
  transition: background 0.2s, color 0.2s;
  display: flex; align-items: center; gap: 0.3rem;
  -webkit-tap-highlight-color: transparent;
}
.lang-btn + .lang-btn { border-left: 1px solid rgba(201,168,76,0.22); }
.lang-btn.active { background: rgba(201,168,76,0.11); color: var(--gold); }
.lang-btn:hover:not(.active) { background: rgba(201,168,76,0.06); color: rgba(201,168,76,0.72); }

.toc-btn {
  background: transparent;
  border: 1px solid rgba(201,168,76,0.18);
  color: rgba(201,168,76,0.7);
  font-family: 'Crimson Text', serif;
  font-size: 0.72rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  cursor: pointer;
  padding: 0.35rem 0.7rem;
  min-height: 36px;
  border-radius: 3px;
  -webkit-tap-highlight-color: transparent;
}
.toc-btn:hover, .toc-btn[aria-expanded="true"] { border-color: rgba(201,168,76,0.4); color: var(--gold); }

.page-jump {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.68rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: rgba(245,240,232,0.45);
  white-space: nowrap;
}
.page-jump input {
  width: 42px; height: 32px;
  background: rgba(255,255,255,0.04);
  border: 1px solid rgba(201,168,76,0.18);
  color: var(--gold);
  text-align: center;
  font-family: 'Playfair Display', serif;
  font-size: 0.84rem;
  border-radius: 3px;
  outline: none;
}
.page-jump input:focus { border-color: rgba(201,168,76,0.45); }

/* TOC as overlay — must not push the book down */
.toc-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.35);
  z-index: 150;
}
.toc-panel {
  position: absolute;
  z-index: 160;
  top: 100%;
  right: 0.75rem;
  left: auto;
  width: min(420px, calc(100vw - 1.5rem));
  max-height: min(70dvh, 480px);
  overflow-y: auto;
  background: #1a140c;
  border: 1px solid rgba(201,168,76,0.22);
  border-radius: 4px;
  box-shadow: 0 16px 48px rgba(0,0,0,0.65);
}
.topbar { position: relative; }
.toc-inner { padding: 0.8rem 1rem; }
.toc-head {
  font-family: 'Playfair Display', serif;
  font-size: 0.65rem;
  letter-spacing: 0.28em;
  text-transform: uppercase;
  color: var(--gold);
  opacity: 0.55;
  margin-bottom: 0.55rem;
}
.toc-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.35rem 0;
  border-bottom: 1px solid rgba(255,255,255,0.04);
  cursor: pointer;
  font-family: 'Playfair Display', serif;
  font-size: clamp(0.78rem, 2.2vw, 0.88rem);
  min-height: 40px;
  gap: 0.5rem;
  -webkit-tap-highlight-color: transparent;
}
.toc-item:last-child { border-bottom: none; }
.toc-item:hover { color: var(--gold); }
.toc-item span { font-size: 0.7rem; opacity: 0.32; font-family:'Crimson Text',serif; white-space:nowrap; }

/* ── Reader (book fills leftover viewport) ── */
.reader {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  width: 100%;
  padding: 0.35rem 0.6rem 0.25rem;
  overflow-anchor: none;
}

.book-slot {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  overflow-anchor: none;
}

.book-wrap {
  position: relative;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow-anchor: none;
}

.book-stage {
  position: relative;
  z-index: 2;
  flex: 0 0 auto;
  overflow: hidden;
  overflow-anchor: none;
  background: #100c08;
  border-radius: 2px;
  box-shadow:
    0 0 0 1px rgba(201,168,76,0.12),
    0 8px 28px rgba(0,0,0,0.55);
}

#book {
  margin: 0 auto;
  background: #100c08;
  overflow: hidden;
  overflow-anchor: none;
}

/* Warm paper tone: white of the JPEG becomes cream via multiply.
   isolation keeps the blend on the page, not the dark surroundings. */
.book-page {
  background: var(--paper);
  isolation: isolate;
  overflow: hidden;
  position: relative;
}
.book-page img {
  width: 100%;
  height: 100%;
  object-fit: fill;
  display: block;
  user-select: none;
  -webkit-user-drag: none;
  pointer-events: none;
  mix-blend-mode: multiply;
  filter: none;
}

.slide-book {
  position: relative;
  width: 100%;
  height: 100%;
  margin: 0 auto;
  background: var(--paper);
  isolation: isolate;
  border-radius: 2px;
  overflow: hidden;
  overflow-anchor: none;
  touch-action: pan-y;
  user-select: none;
  box-shadow:
    0 0 0 1px rgba(201,168,76,0.12),
    0 8px 28px rgba(0,0,0,0.55);
}
.slide-inner {
  display: flex;
  justify-content: center;
  align-items: stretch;
  width: 100%;
  height: 100%;
  transition: transform 0.28s ease, opacity 0.28s ease;
  background: var(--paper);
}
.slide-book.is-animating .slide-inner.dir-next { transform: translateX(-6%); opacity: 0; }
.slide-book.is-animating .slide-inner.dir-prev { transform: translateX(6%); opacity: 0; }
@media (prefers-reduced-motion: reduce) {
  .slide-book .slide-inner { transition-duration: 0.15s; }
}
.slide-inner img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: fill;
  background: var(--paper);
  mix-blend-mode: multiply;
  user-select: none;
  -webkit-user-drag: none;
  pointer-events: none;
}
.slide-book.is-spread .slide-inner img { width: 50%; }
.slide-book.is-cover .slide-inner { justify-content: flex-end; background: #100c08; }
.slide-book.is-cover .slide-inner img { width: 50%; }
.slide-hotspot {
  position: absolute;
  top: 0; bottom: 0;
  width: 28%;
  z-index: 3;
  cursor: pointer;
  background: transparent;
  border: 0;
  padding: 0;
}
.slide-hotspot.prev { left: 0; }
.slide-hotspot.next { right: 0; }

.prog-wrap {
  flex-shrink: 0;
  width: min(100%, 1160px);
  height: 2px;
  background: rgba(255,255,255,0.05);
  margin: 0.3rem auto 0.3rem;
  border-radius: 1px;
  overflow: hidden;
  overflow-anchor: none;
}
.prog-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--blood), var(--gold));
  transition: width 0.35s ease;
}

.nav-row {
  flex-shrink: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  width: min(100%, 1160px);
  margin: 0 auto 0.15rem;
}
.nav-btn {
  flex: 1;
  min-height: 40px;
  background: transparent;
  border: 1px solid rgba(201,168,76,0.22);
  color: var(--gold);
  font-family: 'Playfair Display', serif;
  font-size: clamp(0.8rem, 2.2vw, 0.95rem);
  cursor: pointer;
  border-radius: 3px;
  display: flex; align-items: center; justify-content: center; gap: 0.4rem;
  -webkit-tap-highlight-color: transparent;
}
.nav-btn:hover:not(:disabled) {
  background: rgba(201,168,76,0.08);
  border-color: rgba(201,168,76,0.45);
  color: var(--cream);
}
.nav-btn:disabled { opacity: 0.18; cursor: not-allowed; }
.nav-btn svg { width: 14px; height: 14px; flex-shrink: 0; }
.nav-first {
  flex: 1.15;
  border-color: rgba(201,168,76,0.38);
  color: var(--gold);
  letter-spacing: 0.02em;
}
.nav-first:hover:not(:disabled) {
  background: rgba(201,168,76,0.12);
  border-color: rgba(201,168,76,0.6);
}

/* ── Extras (trailer / audio) below the book ── */
.extras {
  flex-shrink: 0;
  width: 100%;
  max-width: 760px;
  margin: 0 auto;
  padding: 0.15rem 0.75rem 0.5rem;
}
.extras-toggles {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 0.45rem 0.8rem;
}
.extras-btn {
  background: transparent;
  border: 1px solid rgba(201,168,76,0.22);
  color: var(--gold);
  font-family: 'Playfair Display', serif;
  font-size: 0.78rem;
  letter-spacing: 0.08em;
  cursor: pointer;
  padding: 0.3rem 0.8rem;
  min-height: 36px;
  border-radius: 3px;
  -webkit-tap-highlight-color: transparent;
}
.extras-btn:hover, .extras-btn[aria-expanded="true"] {
  background: rgba(201,168,76,0.08);
  border-color: rgba(201,168,76,0.4);
}

.audio-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.3rem 0.75rem;
  border: 1px solid rgba(201,168,76,0.28);
  border-radius: 99px;
  background: rgba(139,26,26,0.16);
  font-size: 0.7rem;
  letter-spacing: 0.06em;
  color: var(--gold);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.audio-badge:hover, .audio-badge:focus {
  background: rgba(139,26,26,0.28);
  color: var(--cream);
}
.dot {
  width: 6px; height: 6px;
  background: var(--blood);
  border-radius: 50%;
  flex-shrink: 0;
  animation: blink 1.6s ease-in-out infinite;
}
@keyframes blink { 0%,100%{opacity:1;transform:scale(1)} 50%{opacity:0.35;transform:scale(0.6)} }

.kb-hint {
  font-size: 0.62rem;
  color: rgba(245,240,232,0.2);
  letter-spacing: 0.1em;
}

.trailer-wrap {
  width: 100%;
  max-width: 640px;
  margin: 0.7rem auto 0;
}
.trailer-heading {
  font-family: 'Playfair Display', serif;
  font-size: 0.72rem;
  letter-spacing: 0.25em;
  text-transform: uppercase;
  color: var(--gold);
  opacity: 0.75;
  text-align: center;
  margin-bottom: 0.5rem;
}
.trailer-box {
  position: relative;
  border-radius: 4px;
  overflow: hidden;
  box-shadow: 0 0 0 1px rgba(201,168,76,0.18), 0 8px 28px rgba(0,0,0,0.55);
  background: #000;
}
.trailer-box video {
  width: 100%;
  display: block;
  max-height: 360px;
  object-fit: contain;
}

.audio-wrap {
  display: none;
  width: 100%;
  max-width: 640px;
  margin: 0.7rem auto 0;
}
.audio-wrap.show { display: block; }

.audio-heading {
  font-size: 0.65rem;
  letter-spacing: 0.28em;
  text-transform: uppercase;
  color: rgba(201,168,76,0.52);
  margin-bottom: 0.4rem;
  display: flex; align-items: center; gap: 0.5rem;
}
.audio-heading::before, .audio-heading::after {
  content:''; flex:1; height:1px; background:rgba(201,168,76,0.13);
}
.audio-box {
  background: rgba(255,255,255,0.02);
  border: 1px solid rgba(201,168,76,0.13);
  border-radius: 4px;
  padding: 0.7rem 0.9rem;
}
.audio-row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin-bottom: 0.5rem;
}
.play-btn {
  width: 40px; height: 40px;
  min-width: 40px;
  border-radius: 50%;
  background: var(--blood);
  border: none; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 2px 12px rgba(139,26,26,0.4);
  -webkit-tap-highlight-color: transparent;
}
.play-btn:hover { background: #a02020; }
.play-btn svg { width:14px; height:14px; fill:var(--cream); margin-left:2px; }
.play-btn.playing svg { margin-left:0; }
.seek-wrap {
  flex: 1;
  height: 4px;
  background: rgba(255,255,255,0.07);
  border-radius: 2px;
  cursor: pointer;
  position: relative;
}
.seek-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--blood), var(--gold));
  border-radius: 2px;
  width: 0%;
  pointer-events: none;
}
.audio-time {
  font-family: 'Playfair Display', serif;
  font-size: 0.75rem;
  color: rgba(201,168,76,0.65);
  white-space: nowrap;
  min-width: 76px;
  text-align: right;
}
.speed-row { display: flex; align-items: center; gap: 0.3rem; flex-wrap: wrap; }
.speed-lbl {
  font-size: 0.65rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: rgba(245,240,232,0.28);
  margin-right: 0.15rem;
}
.spd {
  background: transparent;
  border: 1px solid rgba(201,168,76,0.14);
  color: rgba(201,168,76,0.42);
  font-family: 'Crimson Text', serif;
  font-size: 0.74rem;
  cursor: pointer;
  padding: 0.15rem 0.45rem;
  border-radius: 3px;
  min-height: 30px;
  -webkit-tap-highlight-color: transparent;
}
.spd.active, .spd:hover { border-color:rgba(201,168,76,0.4); color:var(--gold); background:rgba(201,168,76,0.07); }

footer {
  flex-shrink: 0;
  width: 100%;
  text-align: center;
  padding: 0.4rem 1rem 0.7rem;
  padding-bottom: max(0.7rem, env(safe-area-inset-bottom));
  font-size: 0.58rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: rgba(245,240,232,0.16);
}

.noscript-note {
  max-width: 640px;
  margin: 1rem auto;
  padding: 1rem;
  color: var(--cream);
  text-align: center;
}

@media (prefers-reduced-motion: reduce) {
  .dot { animation: none; }
  .prog-fill { transition: none; }
}

/* Mobile: reading surface fills the viewport; extras are a sheet so you need not scroll to read */
@media (max-width: 799px) {
  html, body {
    height: 100dvh;
    max-height: 100dvh;
    overflow: hidden;
    overscroll-behavior: none;
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }
  .nav-btn { min-height: 44px; }
  .nav-first { min-width: 7.5rem; }
  .topbar {
    padding-top: max(0.7rem, env(safe-area-inset-top, 0px));
    row-gap: 0.5rem;
  }
  .lang-btn, .toc-btn { min-height: 44px; }
  .reader { flex: 1 1 auto; }
  .kb-hint { display: none; }
  .extras {
    max-width: none;
    padding: 0.1rem 0.6rem 0.35rem;
  }
  .trailer-wrap, .audio-wrap.show {
    position: fixed;
    left: 0.6rem;
    right: 0.6rem;
    bottom: max(0.6rem, env(safe-area-inset-bottom));
    max-height: 52dvh;
    overflow: auto;
    z-index: 45;
    margin: 0;
    padding: 0.7rem 0.75rem;
    background: #16110b;
    border: 1px solid rgba(201,168,76,0.22);
    border-radius: 6px;
    box-shadow: 0 -12px 40px rgba(0,0,0,0.55);
  }
  .audio-wrap.show + .trailer-wrap,
  .trailer-wrap + .audio-wrap.show {
    /* if both were open, stack; JS will usually only open one at a time on mobile */
  }
  footer { padding: 0.2rem 0.6rem 0.35rem; }
}
