:root {
  color-scheme: dark;
  --bg: #080706;
  --panel: #11100e;
  --panel-soft: rgba(17, 16, 14, 0.72);
  --text: #f8efe2;
  --muted: #b9a995;
  --line: rgba(248, 239, 226, 0.16);
  --gold: #d9ad63;
  --gold-strong: #f1c979;
  --shadow: rgba(0, 0, 0, 0.42);
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  background:
    radial-gradient(circle at 50% 0%, rgba(217, 173, 99, 0.18), transparent 34rem),
    linear-gradient(180deg, #14110e 0%, var(--bg) 52%, #050504 100%);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  overflow-x: hidden;
}

button,
input {
  font: inherit;
}

.reader {
  min-height: 100svh;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 0.8rem;
  padding: clamp(0.9rem, 2vw, 1.5rem);
}

.masthead {
  text-align: center;
  line-height: 1.1;
  user-select: none;
}

.masthead h1 {
  margin: 0.14rem 0;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(1.65rem, 4vw, 3rem);
  font-weight: 600;
  letter-spacing: 0;
}

.subtitle,
.author {
  margin: 0;
  color: var(--muted);
  font-size: clamp(0.76rem, 1.8vw, 0.94rem);
}

.subtitle {
  text-transform: uppercase;
  letter-spacing: 0.14em;
}

.stage {
  position: relative;
  min-height: 0;
  display: grid;
  place-items: center;
  padding: 0.25rem 0;
}

.book {
  width: min(100%, 1120px);
  height: min(74svh, 842px);
  opacity: 0;
  transition: opacity 240ms ease;
  filter: drop-shadow(0 1.4rem 2rem var(--shadow));
}

.book.is-ready {
  opacity: 1;
}

.page {
  background: #090806;
  overflow: hidden;
}

.page img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #090806;
  user-select: none;
  -webkit-user-drag: none;
}

.loading {
  position: absolute;
  z-index: 3;
  color: var(--muted);
  font-size: 0.92rem;
}

.loading.is-hidden {
  display: none;
}

.start-hint {
  position: absolute;
  z-index: 5;
  bottom: clamp(1rem, 4vw, 2rem);
  left: 50%;
  transform: translateX(-50%);
  padding: 0.7rem 1rem;
  border: 1px solid rgba(217, 173, 99, 0.46);
  border-radius: 999px;
  background: rgba(8, 7, 6, 0.7);
  color: var(--gold-strong);
  box-shadow: 0 0.75rem 1.8rem rgba(0, 0, 0, 0.34);
  backdrop-filter: blur(12px);
  cursor: pointer;
}

.reader.has-started .start-hint {
  display: none;
}

.controls {
  width: min(100%, 720px);
  justify-self: center;
  display: grid;
  grid-template-columns: 2.6rem minmax(0, 1fr) 2.6rem auto;
  align-items: center;
  gap: 0.6rem;
  padding: 0.62rem;
  border: 1px solid var(--line);
  border-radius: 0.5rem;
  background: var(--panel-soft);
  box-shadow: 0 1rem 2rem rgba(0, 0, 0, 0.2);
  backdrop-filter: blur(16px);
  opacity: 0;
  pointer-events: none;
  transform: translateY(0.5rem);
  transition: opacity 180ms ease, transform 180ms ease;
}

.reader.has-started .controls {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0);
}

.icon-button,
.text-button {
  min-height: 2.3rem;
  border: 1px solid var(--line);
  background: #171411;
  color: var(--text);
  cursor: pointer;
}

.icon-button {
  width: 2.6rem;
  border-radius: 50%;
  font-size: 1.8rem;
  line-height: 1;
}

.text-button {
  border-radius: 0.38rem;
  padding: 0 0.85rem;
  font-size: 0.86rem;
}

.icon-button:hover,
.text-button:hover,
.icon-button:focus-visible,
.text-button:focus-visible {
  border-color: rgba(217, 173, 99, 0.58);
  color: var(--gold-strong);
  outline: none;
}

.icon-button:disabled,
.text-button:disabled {
  cursor: not-allowed;
  opacity: 0.42;
}

.page-status {
  min-width: 0;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 0.75rem;
  color: var(--muted);
  font-size: 0.9rem;
}

.jump-control {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
}

.jump-control span {
  color: rgba(248, 239, 226, 0.72);
  font-size: 0.78rem;
}

.jump-control input {
  width: 4.25rem;
  min-height: 2rem;
  border: 1px solid var(--line);
  border-radius: 0.35rem;
  background: #0e0c0a;
  color: var(--text);
  padding: 0 0.5rem;
}

@media (max-width: 760px) {
  .reader {
    gap: 0.55rem;
    padding: 0.75rem 0.75rem max(0.75rem, env(safe-area-inset-bottom));
  }

  .masthead h1 {
    font-size: clamp(1.45rem, 8vw, 2.1rem);
  }

  .book {
    width: min(100%, 595px);
    height: min(72svh, calc((100vw - 1.5rem) * 1.414));
  }

  .controls {
    grid-template-columns: 2.45rem minmax(0, 1fr) 2.45rem;
    gap: 0.45rem;
    padding: 0.5rem;
  }

  .text-button {
    grid-column: 1 / -1;
  }

  .page-status {
    gap: 0.5rem;
    font-size: 0.82rem;
  }

  .jump-control span {
    display: none;
  }
}

@media (max-height: 680px) {
  .subtitle,
  .author {
    display: none;
  }

  .book {
    height: 70svh;
  }
}
