:root {
  color-scheme: dark;
  --bg: #111111;
  --panel: rgba(20, 20, 20, 0.82);
  --panel-solid: #1f1f1f;
  --line: rgba(255, 255, 255, 0.18);
  --text: #f7f2ea;
  --muted: #c9c2b8;
  --accent: #f0c35a;
  --accent-2: #61d394;
  --danger: #e96f5d;
  --reader-top: 74px;
  --reader-bottom: 112px;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: Arial, Helvetica, sans-serif;
}

button,
input {
  font: inherit;
}

.app-shell {
  position: relative;
  width: 100vw;
  height: 100dvh;
  min-height: 100vh;
  overflow: hidden;
  background:
    radial-gradient(circle at 12% 14%, rgba(97, 211, 148, 0.18), transparent 30%),
    linear-gradient(135deg, #111111 0%, #202020 54%, #15120d 100%);
}

.reader {
  position: absolute;
  top: max(var(--reader-top), calc(env(safe-area-inset-top) + 70px));
  right: 0;
  bottom: max(var(--reader-bottom), calc(env(safe-area-inset-bottom) + 112px));
  left: 0;
  display: grid;
  place-items: center;
  overflow: hidden;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

.pdf-canvas {
  display: block;
  max-width: none;
  max-height: none;
  background: #ffffff;
  box-shadow: 0 18px 60px rgba(0, 0, 0, 0.45);
  transform-origin: center center;
  will-change: transform;
}

.empty-state {
  width: min(520px, calc(100vw - 40px));
  padding: 28px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(18, 18, 18, 0.72);
  text-align: center;
  backdrop-filter: blur(16px);
}

.brand-mark {
  width: 82px;
  height: 82px;
  margin: 0 auto 18px;
  display: grid;
  place-items: center;
  border: 2px solid var(--accent);
  border-radius: 6px;
  color: var(--accent);
  font-weight: 700;
  letter-spacing: 0;
}

.empty-state h1 {
  margin: 0 0 10px;
  font-size: clamp(28px, 5vw, 44px);
  letter-spacing: 0;
}

.empty-state p {
  margin: 0 auto 22px;
  max-width: 38ch;
  color: var(--muted);
  line-height: 1.45;
}

.primary-button,
.control-button,
.small-button,
.page-panel-button {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--text);
  min-height: 44px;
  cursor: pointer;
  touch-action: manipulation;
}

.primary-button {
  padding: 0 22px;
  background: var(--accent);
  color: #19150b;
  border-color: transparent;
  font-weight: 700;
}

.control-button {
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  font-size: 22px;
  font-weight: 700;
  backdrop-filter: blur(14px);
}

.text-control {
  width: auto;
  padding: 0 14px;
  font-size: 15px;
}

.control-button:disabled {
  opacity: 0.35;
  cursor: default;
}

.control-button.is-active {
  border-color: var(--accent-2);
  color: var(--accent-2);
  box-shadow: 0 0 0 3px rgba(97, 211, 148, 0.16);
}

.top-controls {
  position: fixed;
  top: max(14px, env(safe-area-inset-top));
  left: max(14px, env(safe-area-inset-left));
  display: flex;
  gap: 10px;
  z-index: 20;
}

.bookmark-controls {
  position: fixed;
  left: max(14px, env(safe-area-inset-left));
  bottom: max(18px, calc(env(safe-area-inset-bottom) + 18px));
  display: flex;
  gap: 10px;
  z-index: 20;
}

.zoom-panel {
  position: fixed;
  top: max(76px, calc(env(safe-area-inset-top) + 76px));
  left: max(14px, env(safe-area-inset-left));
  z-index: 22;
  width: min(280px, calc(100vw - 28px));
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  backdrop-filter: blur(14px);
}

.zoom-panel label {
  display: flex;
  justify-content: space-between;
  margin-bottom: 10px;
  color: var(--muted);
}

input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
}

.page-panel {
  position: fixed;
  left: max(14px, env(safe-area-inset-left));
  right: max(14px, env(safe-area-inset-right));
  bottom: max(82px, calc(env(safe-area-inset-bottom) + 82px));
  z-index: 21;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  backdrop-filter: blur(14px);
}

.page-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 8px;
  color: var(--muted);
}

.small-button {
  min-height: 34px;
  padding: 0 12px;
}

.bookmark-track {
  position: relative;
  height: 18px;
  margin: 0 8px -4px;
}

.bookmark-marker {
  position: absolute;
  top: 2px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--accent-2);
  box-shadow: 0 0 0 3px rgba(97, 211, 148, 0.18);
  transform: translateX(-50%);
}

.page-panel-button {
  position: fixed;
  right: max(14px, env(safe-area-inset-right));
  bottom: max(18px, calc(env(safe-area-inset-bottom) + 18px));
  z-index: 20;
  padding: 0 14px;
  font-size: 15px;
}

.loading-state {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-radius: 8px;
  background: var(--panel-solid);
  color: var(--muted);
}

.loader {
  width: 18px;
  height: 18px;
  border: 3px solid rgba(255, 255, 255, 0.25);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: max(140px, calc(env(safe-area-inset-bottom) + 140px));
  z-index: 30;
  max-width: min(460px, calc(100vw - 28px));
  padding: 10px 14px;
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.86);
  color: var(--text);
  transform: translateX(-50%);
  box-shadow: 0 10px 34px rgba(0, 0, 0, 0.34);
}

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

@media (max-width: 640px) {
  :root {
    --reader-top: 82px;
    --reader-bottom: 128px;
  }

  .empty-state {
    padding: 22px;
  }

  .empty-state p {
    font-size: 15px;
  }

  .control-button {
    width: 46px;
    height: 46px;
  }

  .text-control {
    width: auto;
    min-width: 72px;
    padding: 0 16px;
  }

  .top-controls {
    right: max(14px, env(safe-area-inset-right));
    justify-content: space-between;
    gap: 24px;
  }
}
