:root {
  --ink: #f8f3ea;
  --muted: rgba(248, 243, 234, 0.68);
  --panel: #fbf7ef;
  --panel-ink: #26231f;
  --line: rgba(255, 255, 255, 0.14);
  --accent: #2f777b;
  --shadow: 0 24px 70px rgba(0, 0, 0, 0.36);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100svh;
  overflow: hidden;
  overscroll-behavior: none;
  color: var(--ink);
  background:
    radial-gradient(circle at 50% -10%, rgba(255, 238, 196, 0.2), transparent 34rem),
    linear-gradient(135deg, #302d29 0%, #141414 100%);
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  height: 100vh;
  height: 100svh;
}

.reader {
  height: 100vh;
  height: 100svh;
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
}

.stage-wrap {
  position: relative;
  min-height: 0;
  overflow: hidden;
  display: grid;
  place-items: center;
  padding: 18px 64px;
  user-select: none;
  pointer-events: none;
  touch-action: none;
}

.stage-wrap::before {
  content: "";
  position: absolute;
  inset: 0;
  background:
    radial-gradient(circle at 50% 0%, rgba(255, 232, 180, 0.16), transparent 32rem),
    linear-gradient(90deg, rgba(0, 0, 0, 0.2), transparent 24%, transparent 76%, rgba(0, 0, 0, 0.2));
  pointer-events: none;
}

.book-stage {
  position: relative;
  width: min(100%, 1280px);
  height: 100%;
  display: grid;
  place-items: center;
  perspective: 2200px;
  pointer-events: none;
}

.flip-book {
  position: relative;
  filter: drop-shadow(var(--shadow));
  pointer-events: auto;
  touch-action: pan-y;
}

.book-page {
  position: relative;
  overflow: hidden;
  background: #fbfaf7;
  border-radius: 8px;
}

.book-page canvas {
  display: block;
  width: 100%;
  height: 100%;
  background: #fbfaf7;
}

.book-page.--left {
  border-radius: 8px 0 0 8px;
}

.book-page.--right {
  border-radius: 0 8px 8px 0;
}

.page-label {
  position: absolute;
  right: 12px;
  bottom: 8px;
  z-index: 2;
  color: rgba(35, 31, 26, 0.42);
  font-size: 12px;
  pointer-events: none;
}

.loading {
  position: absolute;
  inset: 0;
  display: none;
  place-items: center;
  gap: 12px;
  color: white;
  background: rgba(0, 0, 0, 0.22);
  border-radius: 8px;
  z-index: 5;
}

.loading.active {
  display: grid;
}

.spinner {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 3px solid rgba(255, 255, 255, 0.28);
  border-top-color: white;
  animation: spin 850ms linear infinite;
}

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

.page-hotspot {
  position: absolute;
  top: 0;
  bottom: 0;
  width: var(--hotspot-width, min(22vw, 280px));
  display: block;
  border: 0;
  padding: 0;
  background: transparent;
  z-index: 4;
  pointer-events: auto;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.page-hotspot.left {
  left: 0;
}

.page-hotspot.right {
  right: 0;
}

.drawer-open .page-hotspot {
  pointer-events: none;
}

.toolbar {
  min-height: 64px;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 18px;
  background: rgba(19, 18, 17, 0.82);
  backdrop-filter: blur(16px);
  border-top: 1px solid var(--line);
  z-index: 3;
  pointer-events: auto;
}

.book-title {
  min-width: 132px;
  display: grid;
  gap: 2px;
}

.book-title strong {
  font-size: 16px;
}

.book-title span {
  color: var(--muted);
  font-size: 13px;
}

.toolbar-group {
  display: flex;
  align-items: center;
  gap: 8px;
}

.toolbar-group.grow {
  flex: 1;
  min-width: 140px;
}

.icon-button {
  width: 40px;
  height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  display: grid;
  place-items: center;
  background: rgba(255, 255, 255, 0.08);
  color: white;
  font-size: 22px;
}

.icon-button:hover,
.segmented:hover {
  background: rgba(255, 255, 255, 0.16);
}

.icon-button.dark {
  color: var(--panel-ink);
  background: rgba(0, 0, 0, 0.04);
  border-color: rgba(0, 0, 0, 0.12);
}

.page-control {
  height: 40px;
  display: flex;
  align-items: center;
  gap: 7px;
  color: var(--muted);
}

.page-control input {
  width: 70px;
  height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.08);
  color: white;
  text-align: center;
}

#pageRange {
  width: 100%;
  accent-color: var(--accent);
}

.mode-group {
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  gap: 0;
}

.segmented {
  min-width: 62px;
  height: 40px;
  padding: 0 12px;
  border: 0;
  color: var(--muted);
  background: transparent;
}

.segmented.active {
  color: white;
  background: var(--accent);
  font-weight: 800;
}

.thumbnail-drawer {
  position: fixed;
  inset: 0 auto 0 0;
  width: min(360px, 88vw);
  background: var(--panel);
  color: var(--panel-ink);
  border-right: 1px solid rgba(0, 0, 0, 0.12);
  box-shadow: 18px 0 50px rgba(0, 0, 0, 0.32);
  transform: translateX(-100%);
  transition: transform 180ms ease;
  z-index: 10;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
}

.drawer-open .thumbnail-drawer {
  transform: translateX(0);
}

.drawer-backdrop {
  position: fixed;
  inset: 0;
  display: none;
  border: 0;
  background: rgba(0, 0, 0, 0.34);
  z-index: 9;
}

.drawer-open .drawer-backdrop {
  display: block;
}

.drawer-head {
  min-height: 72px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px;
  border-bottom: 1px solid rgba(0, 0, 0, 0.1);
}

.drawer-head strong,
.drawer-head span {
  display: block;
}

.drawer-head span {
  margin-top: 4px;
  color: #746c60;
  font-size: 13px;
}

.thumbnail-list {
  min-height: 0;
  overflow: auto;
  overflow-x: hidden;
  padding: 14px;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  align-content: start;
  grid-auto-rows: max-content;
}

.thumb {
  appearance: none;
  min-width: 0;
  width: 100%;
  height: auto;
  min-height: calc(clamp(170px, 54vw, 226px) + 49px);
  display: grid;
  grid-template-rows: auto auto;
  gap: 7px;
  align-items: start;
  border: 1px solid rgba(0, 0, 0, 0.12);
  border-radius: 8px;
  padding: 8px;
  background: rgba(255, 255, 255, 0.62);
  color: var(--panel-ink);
  text-align: center;
  overflow: hidden;
}

.thumb:hover,
.thumb.active {
  outline: 2px solid rgba(47, 119, 123, 0.35);
  background: white;
}

.thumb-frame {
  position: relative;
  display: block;
  width: 100%;
  height: clamp(170px, 54vw, 226px);
  aspect-ratio: 0.71 / 1;
  overflow: hidden;
  background: white;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.16);
}

.thumb canvas,
.thumb img {
  display: block;
  width: 100%;
  max-width: 100%;
  height: auto;
  aspect-ratio: 0.71 / 1;
  object-fit: contain;
  background: white;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.16);
}

.thumb img {
  position: absolute;
  inset: 0;
  inline-size: 100%;
  block-size: 100%;
  box-shadow: none;
}

.thumb-label {
  display: block;
  font-size: 13px;
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

@media (max-width: 900px) {
  .toolbar {
    flex-wrap: wrap;
  }

  .book-title {
    flex: 1;
  }

  .toolbar-group.grow {
    order: 2;
    width: 100%;
    flex-basis: 100%;
  }

  .stage-wrap {
    padding: 16px 18px;
  }
}

@media (max-width: 720px) {
  body {
    overflow: hidden;
  }

  .app-shell,
  .reader {
    min-height: 100svh;
    height: 100svh;
  }

  .toolbar {
    min-height: 92px;
    padding-bottom: max(12px, env(safe-area-inset-bottom));
  }

  .stage-wrap {
    min-height: 0;
    padding: 10px 26px;
    align-items: center;
    justify-items: center;
  }

  .page-hotspot {
    width: var(--hotspot-width, 34vw);
  }
}
