:root {
  color-scheme: dark;
  --bg: #0b0f14;
  --panel: #111821;
  --panel-2: #151f2a;
  --line: #263241;
  --text: #eef3f8;
  --muted: #8b9bae;
  --accent: #d7b56d;
  --accent-2: #78b7d9;
  --shadow: rgba(0, 0, 0, 0.42);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: radial-gradient(circle at top, #172231 0, var(--bg) 46rem);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

button,
a {
  -webkit-tap-highlight-color: transparent;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  min-height: 72px;
  padding: 0.75rem clamp(1rem, 4vw, 2rem);
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(11, 15, 20, 0.9);
  backdrop-filter: blur(18px);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.75rem;
  color: var(--text);
  text-decoration: none;
  min-width: 0;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border: 1px solid rgba(215, 181, 109, 0.45);
  border-radius: 8px;
  background: linear-gradient(135deg, #2d2414, #141b22);
  color: var(--accent);
  font-weight: 800;
}

.brand strong,
.brand small {
  display: block;
  white-space: nowrap;
}

.brand strong {
  font-size: 1rem;
}

.brand small {
  color: var(--muted);
  font-size: 0.78rem;
  margin-top: 0.1rem;
}

.actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.actions button,
.controls button,
.primary-action {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--text);
  min-height: 40px;
  padding: 0 0.9rem;
  font: inherit;
  font-size: 0.9rem;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.actions button {
  width: 42px;
  padding: 0;
}

.actions button:hover,
.controls button:hover,
.primary-action:hover {
  border-color: var(--accent);
}

.primary-action {
  background: var(--accent);
  color: #161007;
  border-color: var(--accent);
  font-weight: 700;
}

.icon-grid,
.icon-qr {
  width: 18px;
  height: 18px;
  display: inline-block;
  background: currentColor;
}

.icon-grid {
  mask: linear-gradient(#000 0 0) 0 0 / 7px 7px no-repeat,
    linear-gradient(#000 0 0) 11px 0 / 7px 7px no-repeat,
    linear-gradient(#000 0 0) 0 11px / 7px 7px no-repeat,
    linear-gradient(#000 0 0) 11px 11px / 7px 7px no-repeat;
}

.icon-qr {
  mask: radial-gradient(circle at 4px 4px, #000 0 3px, transparent 3.5px),
    radial-gradient(circle at 14px 4px, #000 0 3px, transparent 3.5px),
    radial-gradient(circle at 4px 14px, #000 0 3px, transparent 3.5px),
    linear-gradient(#000 0 0) 11px 11px / 7px 7px no-repeat,
    linear-gradient(#000 0 0) 8px 2px / 2px 14px no-repeat;
}

.viewer-shell {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  height: calc(100vh - 72px);
  min-height: 560px;
}

.thumb-rail {
  width: 132px;
  overflow: auto;
  padding: 1rem 0.75rem;
  border-right: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(9, 13, 18, 0.72);
}

.thumb-rail[hidden] {
  display: none;
}

.thumb-button {
  width: 100%;
  padding: 0;
  margin: 0 0 0.75rem;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}

.thumb-button img {
  display: block;
  width: 100%;
  border-radius: 7px;
  box-shadow: 0 8px 18px rgba(0, 0, 0, 0.26);
}

.thumb-button span {
  display: block;
  font-size: 0.72rem;
  padding: 0.35rem 0;
}

.thumb-button.active {
  border-color: var(--accent);
  color: var(--accent);
}

.viewer {
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  min-width: 0;
  padding: clamp(0.75rem, 2vw, 1.5rem);
}

.book-wrap {
  position: relative;
  display: grid;
  place-items: center;
  min-height: 0;
}

.book {
  position: relative;
  width: min(78vw, calc((100vh - 170px) * 0.72), 760px);
  aspect-ratio: 0.71;
  perspective: 1800px;
  outline: none;
}

.page-stack,
.page,
.flip-sheet {
  position: absolute;
  inset: 0;
}

.page,
.flip-sheet {
  border-radius: 6px;
  box-shadow: 0 28px 70px var(--shadow);
  background: #f7f7f5;
}

.page {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.page-under {
  transform: translateX(-7px) rotate(-0.7deg) scale(0.99);
  opacity: 0.45;
}

.page-next {
  transform: translateX(8px) rotate(0.7deg) scale(0.99);
  opacity: 0.55;
}

.page-current {
  z-index: 2;
}

.flip-sheet {
  z-index: 5;
  display: none;
  transform-style: preserve-3d;
  transform-origin: left center;
  overflow: hidden;
}

.flip-sheet img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
  backface-visibility: hidden;
}

.flip-sheet.forward {
  display: block;
  transform-origin: left center;
  animation: flipForward 620ms ease-in-out forwards;
}

.flip-sheet.backward {
  display: block;
  transform-origin: right center;
  animation: flipBackward 620ms ease-in-out forwards;
}

@keyframes flipForward {
  from {
    transform: rotateY(0deg);
    filter: brightness(1);
  }
  55% {
    filter: brightness(0.82);
  }
  to {
    transform: rotateY(-178deg);
    filter: brightness(0.92);
  }
}

@keyframes flipBackward {
  from {
    transform: rotateY(0deg);
    filter: brightness(1);
  }
  55% {
    filter: brightness(0.82);
  }
  to {
    transform: rotateY(178deg);
    filter: brightness(0.92);
  }
}

.nav-hit {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 32%;
  border: 0;
  background: transparent;
  cursor: pointer;
  z-index: 8;
}

.nav-prev {
  left: 0;
}

.nav-next {
  right: 0;
}

.controls {
  display: grid;
  grid-template-columns: auto auto minmax(0, 420px) auto;
  align-items: center;
  justify-content: center;
  gap: 0.9rem;
  padding: 1rem 0 0;
}

.page-status {
  display: grid;
  gap: 0.4rem;
  color: var(--muted);
  font-size: 0.86rem;
  text-align: center;
}

input[type="range"] {
  width: min(54vw, 420px);
  accent-color: var(--accent);
}

.qr-dialog,
.phone-dialog {
  width: min(92vw, 380px);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #101820;
  color: var(--text);
  padding: 1.25rem;
  text-align: center;
}

.qr-dialog::backdrop,
.phone-dialog::backdrop {
  background: rgba(0, 0, 0, 0.72);
}

.qr-dialog img {
  width: 240px;
  max-width: 100%;
  border-radius: 8px;
  background: white;
  padding: 0.75rem;
}

.qr-dialog p,
.muted {
  color: var(--muted);
}

.qr-dialog h2 {
  margin: 0.25rem 0 0.35rem;
  font-size: 1.45rem;
}

.qr-contact {
  margin: 0 0 0.9rem;
  color: var(--text);
  font-weight: 700;
}

.phone-dialog h2 {
  margin: 0.25rem 0 0.35rem;
  font-size: 1.35rem;
}

.lead-copy {
  margin: 0.4rem 0 0;
  color: var(--muted);
  line-height: 1.65;
  text-align: left;
}

.phone-form {
  display: grid;
  gap: 0.75rem;
  margin-top: 1rem;
  text-align: left;
}

.phone-form label {
  color: var(--muted);
  font-size: 0.88rem;
}

.phone-form input {
  width: 100%;
  min-height: 46px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
  color: #0f172a;
  padding: 0 0.9rem;
  font: inherit;
  font-size: 1rem;
}

.phone-form .primary-action {
  width: 100%;
}

.form-message {
  min-height: 1.2rem;
  margin: 0;
  color: var(--muted);
  font-size: 0.86rem;
  text-align: center;
}

.close {
  float: right;
  border: 0;
  background: transparent;
  color: var(--text);
  font-size: 1.5rem;
  cursor: pointer;
}

.stats-page {
  background: var(--bg);
}

iframe[src*="tawk.to"],
iframe[title*="chat" i],
iframe[title*="tawk" i],
div[id*="tawk" i],
div[class*="tawk" i],
button[class*="tawk" i] {
  display: none !important;
  visibility: hidden !important;
  opacity: 0 !important;
  pointer-events: none !important;
}

.stats-shell {
  width: min(1120px, calc(100vw - 2rem));
  margin: 0 auto;
  padding: 2rem 0;
}

.back-link {
  color: var(--accent);
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: 1rem;
}

.stat-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  padding: 1rem;
}

.stat-card h2 {
  margin: 0 0 0.75rem;
  font-size: 1rem;
}

.stat-card table {
  width: 100%;
  border-collapse: collapse;
}

.stat-card td {
  padding: 0.45rem 0;
  border-top: 1px solid rgba(255, 255, 255, 0.07);
  color: var(--muted);
}

.stat-card td:last-child {
  text-align: right;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

.lead-auth {
  display: flex;
  gap: 0.75rem;
  margin: 1rem 0;
}

.lead-auth input {
  min-height: 42px;
  width: min(360px, 100%);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
  color: #0f172a;
  padding: 0 0.9rem;
  font: inherit;
}

.lead-card {
  overflow: hidden;
}

.lead-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.lead-card-head button {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-2);
  color: var(--text);
  min-height: 36px;
  padding: 0 0.75rem;
  font: inherit;
  cursor: pointer;
}

.lead-table-wrap {
  overflow: auto;
}

.lead-table {
  min-width: 860px;
}

.lead-table th,
.lead-table td {
  padding: 0.55rem 0.65rem;
  border-top: 1px solid rgba(255, 255, 255, 0.07);
  text-align: left;
  vertical-align: top;
}

.lead-table th {
  color: var(--text);
  font-size: 0.86rem;
}

.lead-table td {
  color: var(--muted);
  font-size: 0.86rem;
}

.lead-table td:nth-child(2) {
  color: var(--text);
}

@media (max-width: 980px) {
  .topbar {
    min-height: 64px;
  }

  .brand small {
    display: none;
  }

  .primary-action {
    padding: 0 0.65rem;
    font-size: 0.82rem;
  }

  .viewer-shell {
    height: calc(100vh - 64px);
    min-height: 520px;
    display: block;
  }

  .thumb-rail {
    position: fixed;
    left: 0;
    right: 0;
    top: auto;
    bottom: 0;
    z-index: 18;
    display: flex;
    gap: 0.65rem;
    width: auto;
    height: 136px;
    padding: 0.7rem 0.75rem calc(0.7rem + env(safe-area-inset-bottom));
    overflow-x: auto;
    overflow-y: hidden;
    border-right: 0;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
    background: rgba(9, 13, 18, 0.94);
    box-shadow: 0 -18px 40px rgba(0, 0, 0, 0.32);
  }

  .thumb-rail[hidden] {
    display: none;
  }

  .thumb-button {
    flex: 0 0 82px;
    margin: 0;
  }

  .thumb-button span {
    padding: 0.24rem 0 0;
  }

  .viewer {
    height: calc(100vh - 64px);
    padding: 0.75rem;
  }

  .viewer-shell.thumbs-open .viewer {
    padding-bottom: 9rem;
  }

  .book {
    width: min(94vw, calc((100vh - 156px) * 0.7));
  }

  .controls {
    grid-template-columns: auto auto minmax(0, 1fr) auto;
    gap: 0.55rem;
  }

  .controls button {
    padding: 0 0.55rem;
    font-size: 0.82rem;
  }
}
