:root {
  color-scheme: dark;
  --orange: #ff6a00;
  --ink: #111;
  --paper: #fff;
  --safe-bottom: max(22px, env(safe-area-inset-bottom));
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  width: 100%;
  max-width: 100%;
  min-height: 100%;
  background: #171717;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

body { overflow-x: hidden; }

#viewer { min-height: 100dvh; }

#pages {
  width: 100%;
  min-height: 100dvh;
  padding: 0;
}

.pdf-page {
  position: relative;
  width: 100%;
  margin: 0 auto 3px;
  background: var(--paper);
  box-shadow: 0 1px 10px #0008;
}

.pdf-page canvas {
  display: block;
  width: 100%;
  height: auto;
}

.empty-state {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  min-height: 100dvh;
  padding: 24px;
  background:
    radial-gradient(circle at 85% 10%, #ff6a0033, transparent 34%),
    linear-gradient(150deg, #191919, #0b0b0b 70%);
}

.empty-state.hidden { display: none; }

.picker-card {
  width: min(100%, 430px);
  min-width: 0;
  overflow: hidden;
  padding: 28px 24px 24px;
  border: 1px solid #ffffff17;
  border-radius: 28px;
  background: #202020e8;
  box-shadow: 0 24px 80px #0009;
  backdrop-filter: blur(18px);
}

.eyebrow {
  margin: 0 0 12px;
  color: var(--orange);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: .16em;
}

h1 {
  margin: 0;
  color: #fff;
  font-size: clamp(34px, 9vw, 50px);
  line-height: .98;
  letter-spacing: -.045em;
}

.intro {
  margin: 18px 0 24px;
  color: #bdbdbd;
  font-size: 15px;
  line-height: 1.5;
}

.file-choice {
  position: relative;
  display: flex;
  align-items: center;
  gap: 14px;
  min-height: 74px;
  margin-top: 12px;
  padding: 12px;
  border: 1px solid #ffffff18;
  border-radius: 18px;
  color: white;
  background: #2a2a2a;
  font: inherit;
  text-align: left;
  width: 100%;
  min-width: 0;
  max-width: 100%;
  overflow: hidden;
  cursor: pointer;
}

.file-choice:active { transform: scale(.99); }
.fallback-input { position: absolute; inset: 0; z-index: 2; width: 100%; height: 100%; opacity: 0; cursor: pointer; }
.file-details { display: block; min-width: 0; flex: 1; overflow: hidden; }
.upload-progress { display: none; width: 100%; height: 4px; margin-top: 9px; overflow: hidden; border-radius: 99px; background: #ffffff1a; }
.upload-progress.visible { display: block; }
.upload-progress i { display: block; width: 0; height: 100%; border-radius: inherit; background: var(--orange); transition: width .15s linear; }
.file-choice span:nth-child(2) { min-width: 0; }
.file-choice strong, .file-choice small { display: block; }
.file-choice strong { font-size: 15px; }
.file-choice small { overflow: hidden; margin-top: 4px; color: #9d9d9d; text-overflow: ellipsis; white-space: nowrap; }

.file-badge {
  display: grid;
  flex: 0 0 48px;
  place-items: center;
  height: 48px;
  border-radius: 14px;
  color: white;
  background: #e04935;
  font-size: 11px;
  font-weight: 900;
}

.file-badge.audio { background: var(--orange); }

.open-button {
  width: 100%;
  min-height: 54px;
  margin-top: 20px;
  border: 0;
  border-radius: 17px;
  color: white;
  background: var(--orange);
  font-size: 16px;
  font-weight: 800;
}

.open-button:disabled { color: #777; background: #303030; }
.storage-note { margin: 14px 0 0; color: #777; font-size: 12px; text-align: center; }

.audio-controls {
  position: fixed;
  right: max(18px, env(safe-area-inset-right));
  bottom: var(--safe-bottom);
  z-index: 8;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

.audio-button {
  display: grid;
  width: 62px;
  height: 62px;
  place-items: center;
  border: 0;
  border-radius: 50%;
  color: white;
  background: var(--orange);
  box-shadow: 0 12px 35px #0008, 0 0 0 1px #ffffff24 inset;
  cursor: pointer;
  transition: transform .15s ease, opacity .2s ease;
}

.audio-button:active { transform: scale(.92); }
.audio-button:disabled { opacity: 0; pointer-events: none; }
.play-icon { width: 0; height: 0; margin-left: 5px; border-top: 10px solid transparent; border-bottom: 10px solid transparent; border-left: 16px solid white; }
.pause-icon { display: none; gap: 5px; }
.pause-icon i { display: block; width: 6px; height: 21px; border-radius: 2px; background: white; }
.audio-button.playing .play-icon { display: none; }
.audio-button.playing .pause-icon { display: flex; }
.close-icon { display: none; width: 27px; height: 27px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; }
.audio-button.menu-open .play-icon,
.audio-button.menu-open .pause-icon { display: none; }
.audio-button.menu-open .close-icon { display: block; }

.audio-menu {
  display: flex;
  flex-direction: column;
  gap: 10px;
  opacity: 0;
  pointer-events: none;
  transform: translateY(18px) scale(.9);
  transform-origin: bottom;
  transition: opacity .16s ease, transform .16s ease;
}

.audio-menu.open { opacity: 1; pointer-events: auto; transform: none; }

.audio-action {
  display: grid;
  width: 50px;
  height: 50px;
  place-items: center;
  border: 1px solid #ffffff20;
  border-radius: 50%;
  color: white;
  background: #26211f;
  box-shadow: 0 8px 22px #0007;
}

.audio-action:active { transform: scale(.92); }
.audio-action svg { width: 25px; height: 25px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }

.duration-dialog {
  position: fixed;
  inset: 0;
  z-index: 30;
  background: #0008;
  backdrop-filter: blur(4px);
}

.duration-dialog[hidden] { display: none; }
.duration-sheet { position: absolute; inset: auto 0 0; padding: 22px max(20px, env(safe-area-inset-right)) calc(22px + env(safe-area-inset-bottom)) max(20px, env(safe-area-inset-left)); border-radius: 26px 26px 0 0; color: white; background: #201c1a; }
.duration-sheet h2 { margin: 0 0 22px; font-size: 19px; line-height: 1.2; text-align: center; letter-spacing: 0; }
.duration-fields { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.duration-fields label span { display: block; margin-bottom: 7px; color: #aaa; font-size: 10px; font-weight: 800; letter-spacing: .12em; text-align: center; }
.duration-fields select { width: 100%; height: 58px; padding: 0 10px; border: 1px solid #ffffff20; border-radius: 15px; color: white; background: #111; font: 750 24px/1 Inter, system-ui, sans-serif; text-align: center; }
.duration-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 20px; }
.duration-actions button { min-height: 50px; border: 1px solid #ffffff20; border-radius: 15px; color: white; background: transparent; font-family: inherit; font-size: 15px; font-weight: 750; }
.duration-actions #durationGo { border-color: var(--orange); background: var(--orange); }

.status { position: fixed; left: 50%; bottom: calc(var(--safe-bottom) + 76px); z-index: 20; max-width: calc(100% - 40px); padding: 9px 13px; border-radius: 99px; color: white; background: #111e; font-size: 13px; opacity: 0; pointer-events: none; transform: translate(-50%, 8px); transition: .2s ease; white-space: nowrap; }
.status.visible { opacity: 1; transform: translate(-50%, 0); }

@media (orientation: landscape) {
  .pdf-page { width: min(100%, 1200px); }
  .audio-button { width: 56px; height: 56px; }
}

@media (min-width: 900px) {
  #pages { padding: 12px 0; }
  .pdf-page { width: min(94%, 1100px); margin-bottom: 12px; }
}
