:root {
  --bg-0: #f3e8d3;
  --bg-1: #ddc6a4;
  --ink: #281f17;
  --muted: #6b5a47;
  --paper: #fffef9;
  --paper-edge: #eadfcf;
  --accent: #9e5f2b;
  --accent-press: #804715;
  --shell: rgba(255, 249, 239, 0.8);
}

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

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

body {
  color: var(--ink);
  font-family: 'Avenir Next', 'Gill Sans', 'Trebuchet MS', sans-serif;
  background:
    radial-gradient(circle at 15% 15%, rgba(255, 255, 255, 0.55), transparent 40%),
    radial-gradient(circle at 85% 80%, rgba(255, 238, 201, 0.4), transparent 45%),
    linear-gradient(160deg, var(--bg-0), var(--bg-1));
}

#app {
  width: 100%;
  height: 100dvh;
  display: flex;
  justify-content: center;
  align-items: stretch;
  padding: max(10px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) max(16px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
}

#reader-shell {
  width: min(100%, 560px);
  height: 100%;
  border-radius: 22px;
  border: 1px solid rgba(78, 52, 25, 0.12);
  background: var(--shell);
  backdrop-filter: blur(8px);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.7),
    0 18px 45px rgba(81, 45, 15, 0.22);
  display: grid;
  grid-template-rows: 1fr auto;
  overflow: hidden;
}

#book-stage {
  position: relative;
  width: 100%;
  height: 100%;
  min-height: 0;
  padding: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  touch-action: pinch-zoom;
}

#overlay-layer {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  pointer-events: none;
  z-index: 3;
  transition: opacity 0.2s ease;
}

#overlay-layer.is-flipping {
  opacity: 0;
  pointer-events: none;
}

#overlay-layer.is-flipping .hotspot {
  pointer-events: none;
}

.hotspot {
  position: absolute;
  display: none;
  pointer-events: auto;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 10px;
  cursor: pointer;
  padding: 0;
  transition: background 0.18s ease, border-color 0.18s ease, box-shadow 0.18s ease;
  -webkit-tap-highlight-color: transparent;
}

.hotspot:hover,
.hotspot:focus-visible {
  background: rgba(158, 95, 43, 0.1);
  border-color: rgba(158, 95, 43, 0.3);
  box-shadow: 0 0 0 3px rgba(158, 95, 43, 0.08);
  outline: none;
}

.hotspot:active {
  background: rgba(158, 95, 43, 0.18);
}

#return-btn {
  display: inline-block;
  border: none;
  background: none;
  padding: 0;
  color: var(--accent);
  font: inherit;
  font-size: 0.82rem;
  font-weight: 650;
  letter-spacing: 0.01em;
  text-decoration: underline;
  text-decoration-color: rgba(158, 95, 43, 0.4);
  text-underline-offset: 2px;
  cursor: pointer;
  touch-action: manipulation;
  transition: text-decoration-color 0.15s ease, opacity 0.15s ease;
}

#return-btn::before {
  content: '\2190\00a0';
}

#return-btn:hover,
#return-btn:focus-visible {
  text-decoration-color: var(--accent);
  outline: none;
}

#return-btn:active {
  opacity: 0.65;
}

#return-btn[hidden] {
  display: none;
}

#book {
  width: 100%;
  height: 100%;
  filter: drop-shadow(0 9px 22px rgba(30, 16, 8, 0.28));
  pointer-events: none;
}

#controls {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 8px;
  padding: 10px 12px 12px;
  border-top: 1px solid rgba(85, 51, 21, 0.12);
}

#page-indicator-wrap {
  justify-self: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

#page-indicator {
  min-width: 82px;
  text-align: center;
  padding: 5px 10px;
  border-radius: 999px;
  color: #4b3420;
  font-size: 0.75rem;
  letter-spacing: 0.03em;
  font-weight: 650;
  line-height: 1;
  border: 1px solid rgba(109, 74, 41, 0.2);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.88), rgba(247, 236, 220, 0.9));
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.86),
    0 3px 8px rgba(75, 44, 18, 0.1);
  user-select: none;
}

#prev-btn {
  justify-self: stretch;
}

#next-btn {
  justify-self: stretch;
}

#controls button:not(#return-btn) {
  height: 44px;
  border-radius: 999px;
  border: 0;
  color: #fff8f0;
  background: linear-gradient(180deg, #b7753f, var(--accent));
  font-size: 0.95rem;
  letter-spacing: 0.02em;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.12s ease, filter 0.12s ease;
  touch-action: manipulation;
  user-select: none;
}

#controls button:not(#return-btn):active {
  transform: scale(0.97);
  background: linear-gradient(180deg, var(--accent), var(--accent-press));
}

#controls button:not(#return-btn):disabled {
  opacity: 0.45;
  cursor: not-allowed;
  transform: none;
}

.pdf-page {
  width: 100%;
  height: 100%;
  background: linear-gradient(92deg, var(--paper-edge) 0%, var(--paper) 6%, #fff 100%);
  border: 1px solid rgba(106, 72, 39, 0.16);
  overflow: hidden;
  user-select: none;
}

.pdf-page img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
  pointer-events: none;
}

.loading-overlay {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(30, 20, 9, 0.56);
  z-index: 200;
}

.loading-card {
  min-width: 180px;
  padding: 14px 18px;
  border-radius: 14px;
  background: rgba(255, 252, 246, 0.95);
  border: 1px solid rgba(77, 49, 20, 0.15);
  box-shadow: 0 14px 34px rgba(0, 0, 0, 0.22);
  display: flex;
  align-items: center;
  gap: 12px;
}

.spinner {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 2px solid rgba(130, 79, 32, 0.18);
  border-top-color: #9f5f2b;
  animation: spin 0.8s linear infinite;
}

.loading-text {
  color: #51341d;
  font-size: 0.9rem;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

@media (min-width: 760px) {
  #app {
    padding: 20px;
  }

  #reader-shell {
    max-height: 900px;
  }
}
