:root {
  color-scheme: dark;
  --bg: #08080d;
  --bg-deep: #050507;
  --surface: #111118;
  --surface-raised: #171720;
  --line: rgba(209, 211, 230, 0.13);
  --line-strong: rgba(209, 211, 230, 0.23);
  --text: #f5f5f8;
  --muted: #a6a6b5;
  --muted-strong: #c9c9d3;
  --magenta: #c71f75;
  --violet: #7835b5;
  --blue: #3e72be;
  --accent-gradient: linear-gradient(120deg, var(--magenta), var(--violet) 52%, var(--blue));
  --toolbar-height: 76px;
  font-family:
    Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-synthesis: none;
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  min-height: 100%;
  background: var(--bg-deep);
}

body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  overflow-x: hidden;
  color: var(--text);
  background:
    linear-gradient(rgba(255, 255, 255, 0.018) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.018) 1px, transparent 1px),
    radial-gradient(circle at 50% -20%, #1c1627 0%, var(--bg) 42%, var(--bg-deep) 100%);
  background-size: 64px 64px, 64px 64px, auto;
}

body.is-viewing {
  overflow: hidden;
}

button,
a,
input {
  font: inherit;
}

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

button:focus-visible,
a:focus-visible,
input:focus-visible {
  outline: 2px solid #9a63dc;
  outline-offset: 3px;
}

[hidden] {
  display: none !important;
}

.ambient-light {
  position: fixed;
  z-index: -1;
  width: 38rem;
  height: 38rem;
  border-radius: 50%;
  filter: blur(110px);
  pointer-events: none;
  opacity: 0.12;
}

.ambient-light--one {
  top: -24rem;
  right: -8rem;
  background: var(--violet);
}

.ambient-light--two {
  bottom: -27rem;
  left: -12rem;
  background: var(--blue);
}

.dashboard-shell {
  width: min(1180px, 100%);
  min-height: 100vh;
  margin: 0 auto;
  padding: 28px 32px 72px;
}

.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 56px;
  padding-bottom: 24px;
  border-bottom: 1px solid var(--line);
}

.brand {
  display: inline-flex;
  border-radius: 10px;
}

.logo-window {
  position: relative;
  display: block;
  overflow: hidden;
  flex: 0 0 auto;
  background: #000;
}

.logo-window img {
  position: absolute;
  top: 50%;
  left: 50%;
  display: block;
  width: 100%;
  height: auto;
  transform: translate(-50%, -50%);
  user-select: none;
}

.logo-window--dashboard {
  width: 174px;
  height: 46px;
  border-radius: 9px;
}

.logo-window--dashboard img {
  width: 190px;
}

.library-label {
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.hero {
  max-width: 790px;
  padding: clamp(66px, 11vw, 132px) 0 clamp(48px, 7vw, 82px);
}

.eyebrow {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0 0 18px;
  color: #bc91ec;
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.15em;
  text-transform: uppercase;
}

.eyebrow::before {
  width: 30px;
  height: 2px;
  content: "";
  background: var(--accent-gradient);
  border-radius: 999px;
}

.hero h1 {
  margin: 0;
  font-size: clamp(3.25rem, 8vw, 6.9rem);
  font-weight: 680;
  letter-spacing: -0.065em;
  line-height: 0.94;
}

.hero h1 span {
  color: transparent;
  background: var(--accent-gradient);
  background-clip: text;
  -webkit-background-clip: text;
}

.hero-copy {
  max-width: 650px;
  margin: 28px 0 0;
  color: var(--muted-strong);
  font-size: clamp(1rem, 2vw, 1.18rem);
  line-height: 1.65;
}

.library-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 22px;
}

.library-card {
  position: relative;
  display: flex;
  min-height: 342px;
  overflow: hidden;
  flex-direction: column;
  padding: 28px;
  color: var(--text);
  text-align: left;
  background: linear-gradient(145deg, rgba(25, 25, 35, 0.96), rgba(13, 13, 20, 0.98));
  border: 1px solid var(--line);
  border-radius: 22px;
  box-shadow: 0 28px 70px rgba(0, 0, 0, 0.22);
  cursor: pointer;
  transition:
    transform 220ms ease,
    border-color 220ms ease,
    box-shadow 220ms ease;
}

.library-card::before {
  position: absolute;
  inset: 0;
  content: "";
  background: radial-gradient(circle at 20% 0%, rgba(127, 58, 183, 0.16), transparent 44%);
  opacity: 0;
  pointer-events: none;
  transition: opacity 220ms ease;
}

.library-card::after {
  position: absolute;
  top: -1px;
  right: 10%;
  left: 10%;
  height: 1px;
  content: "";
  background: var(--accent-gradient);
  opacity: 0;
  filter: drop-shadow(0 0 12px rgba(143, 74, 203, 0.72));
  transition: opacity 220ms ease;
}

.library-card:hover {
  z-index: 1;
  transform: translateY(-5px);
  border-color: var(--line-strong);
  box-shadow: 0 34px 80px rgba(0, 0, 0, 0.36);
}

.library-card:hover::before,
.library-card:hover::after,
.library-card--primary::before,
.library-card--primary::after {
  opacity: 1;
}

.library-card--primary {
  border-color: rgba(141, 80, 194, 0.3);
}

.library-card:disabled {
  cursor: wait;
  opacity: 0.76;
}

.card-topline,
.card-action {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.card-icon {
  display: grid;
  width: 50px;
  height: 50px;
  color: #ded1ec;
  background: rgba(255, 255, 255, 0.045);
  border: 1px solid rgba(255, 255, 255, 0.09);
  border-radius: 15px;
  place-items: center;
}

.card-icon svg {
  width: 24px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.5;
}

.card-icon--book {
  color: #fff;
  background: linear-gradient(145deg, rgba(190, 31, 113, 0.28), rgba(63, 106, 184, 0.22));
  border-color: rgba(182, 100, 221, 0.25);
}

.card-badge,
.card-status {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 28px;
  padding: 6px 10px;
  color: var(--muted-strong);
  font-size: 0.72rem;
  font-weight: 750;
  letter-spacing: 0.04em;
  background: rgba(255, 255, 255, 0.035);
  border: 1px solid rgba(255, 255, 255, 0.075);
  border-radius: 999px;
}

.card-badge--active {
  color: #d8c2ee;
  background: rgba(112, 58, 153, 0.16);
  border-color: rgba(158, 96, 199, 0.23);
}

.card-badge[data-state="error"] {
  color: #ffb1bd;
  background: rgba(120, 36, 53, 0.15);
  border-color: rgba(255, 103, 126, 0.22);
}

.status-dot {
  width: 6px;
  height: 6px;
  background: #9292a1;
  border-radius: 50%;
  transition: background-color 180ms ease;
}

.card-status[data-state="converting"] .status-dot {
  background: #9d60d6;
  box-shadow: 0 0 0 4px rgba(157, 96, 214, 0.12);
  animation: status-pulse 1.2s ease-in-out infinite;
}

.card-status[data-state="ready"] .status-dot {
  background: #58c09b;
  box-shadow: 0 0 0 4px rgba(88, 192, 155, 0.1);
}

.card-status[data-state="error"] {
  color: #ffb1bd;
  border-color: rgba(255, 103, 126, 0.22);
}

.card-status[data-state="error"] .status-dot {
  background: #ff677e;
}

.card-body {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  flex-grow: 1;
  justify-content: flex-end;
  padding: 44px 0 34px;
}

.card-kicker {
  margin-bottom: 11px;
  color: var(--muted);
  font-size: 0.74rem;
  font-weight: 750;
  letter-spacing: 0.11em;
  text-transform: uppercase;
}

.card-body strong {
  max-width: 430px;
  font-size: clamp(1.38rem, 2.5vw, 1.72rem);
  font-weight: 680;
  letter-spacing: -0.03em;
  line-height: 1.15;
}

.card-description {
  max-width: 450px;
  margin-top: 13px;
  color: var(--muted);
  font-size: 0.94rem;
  line-height: 1.55;
}

.card-action {
  padding-top: 18px;
  color: #d7d7df;
  font-size: 0.84rem;
  font-weight: 700;
  border-top: 1px solid var(--line);
}

.card-action svg {
  width: 20px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.6;
  transition: transform 180ms ease;
}

.library-card:hover .card-action svg {
  transform: translateX(3px);
}

.viewer {
  position: fixed;
  z-index: 10;
  inset: 0;
  background: #09090e;
}

.viewer-toolbar {
  position: relative;
  z-index: 20;
  display: grid;
  height: var(--toolbar-height);
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: center;
  gap: 18px;
  padding: 0 22px;
  background: rgba(10, 10, 15, 0.92);
  border-bottom: 1px solid var(--line);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.25);
  backdrop-filter: blur(18px);
}

.toolbar-start,
.toolbar-actions {
  display: flex;
  min-width: 0;
  align-items: center;
}

.toolbar-actions {
  justify-content: flex-end;
  gap: 8px;
}

.logo-window--viewer {
  width: 126px;
  height: 38px;
  border-radius: 7px;
}

.logo-window--viewer img {
  width: 138px;
}

.toolbar-button {
  display: inline-flex;
  min-height: 42px;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 0 13px;
  color: #e9e9ee;
  text-decoration: none;
  background: rgba(255, 255, 255, 0.035);
  border: 1px solid var(--line);
  border-radius: 11px;
  cursor: pointer;
  transition:
    color 180ms ease,
    background-color 180ms ease,
    border-color 180ms ease,
    transform 180ms ease;
}

.toolbar-button:hover:not(:disabled) {
  color: #fff;
  background: rgba(255, 255, 255, 0.075);
  border-color: var(--line-strong);
}

.toolbar-button:active:not(:disabled) {
  transform: translateY(1px);
}

.toolbar-button:disabled {
  color: #555560;
  cursor: not-allowed;
  opacity: 0.55;
}

.toolbar-button svg {
  width: 19px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.7;
}

.toolbar-button--icon {
  width: 42px;
  padding: 0;
}

.toolbar-button--zoom {
  min-width: 104px;
  font-size: 0.79rem;
  font-weight: 750;
}

.toolbar-button--zoom.is-active {
  color: #fff;
  background: linear-gradient(120deg, rgba(157, 35, 112, 0.34), rgba(73, 76, 164, 0.4));
  border-color: rgba(190, 127, 219, 0.48);
  box-shadow: 0 0 0 3px rgba(139, 76, 190, 0.1);
}

.toolbar-button--back {
  padding-right: 16px;
  font-size: 0.82rem;
  font-weight: 700;
}

.toolbar-button--download {
  color: #fff;
  font-size: 0.79rem;
  font-weight: 750;
  background: linear-gradient(120deg, rgba(157, 35, 112, 0.74), rgba(73, 76, 164, 0.78));
  border-color: rgba(190, 127, 219, 0.26);
}

.toolbar-button--download:hover {
  background: linear-gradient(120deg, rgba(181, 39, 128, 0.83), rgba(68, 91, 181, 0.86));
}

.fullscreen-exit {
  display: none;
}

.viewer:fullscreen .fullscreen-enter {
  display: none;
}

.viewer:fullscreen .fullscreen-exit {
  display: block;
}

.viewer-stage {
  position: relative;
  display: grid;
  height: calc(100dvh - var(--toolbar-height));
  min-height: 0;
  overflow: hidden;
  padding: clamp(14px, 2vw, 28px);
  background:
    radial-gradient(circle at 50% 38%, rgba(58, 48, 75, 0.38), transparent 42%),
    linear-gradient(145deg, #0d0d13, #07070b 72%);
  isolation: isolate;
  place-items: center;
}

.viewer-stage::after {
  position: absolute;
  z-index: -1;
  right: 12%;
  bottom: 5%;
  left: 12%;
  height: 18%;
  content: "";
  background: rgba(0, 0, 0, 0.56);
  border-radius: 50%;
  filter: blur(48px);
  opacity: 0.7;
  transform: perspective(600px) rotateX(68deg);
}

.book-viewport,
.zoom-layer,
.flipbook-host,
.flipbook {
  width: 100%;
  height: 100%;
  min-width: 0;
  min-height: 0;
}

.book-viewport,
.zoom-layer,
.flipbook-host {
  display: grid;
  place-items: center;
}

.book-viewport {
  overflow: hidden;
  overscroll-behavior: contain;
}

.zoom-layer {
  transform: translate3d(0, 0, 0) scale(1);
  transform-origin: center center;
  will-change: transform;
}

.viewer.is-zoom-mode .book-viewport {
  cursor: zoom-in;
  touch-action: none;
}

.viewer.is-zoom-mode.has-zoom .book-viewport {
  cursor: grab;
}

.viewer.is-zoom-mode.is-panning .book-viewport {
  cursor: grabbing;
}

.viewer.is-zoom-mode .flipbook-host {
  pointer-events: none;
}

.flipbook {
  opacity: 0;
  transition: opacity 280ms ease;
}

.flipbook.is-ready {
  opacity: 1;
}

.book-page {
  position: relative;
  box-sizing: border-box;
  overflow: hidden;
  padding: 0;
  margin: 0;
  background: #f7f6f3;
  border: 0;
  outline: 0;
  box-shadow: none;
  isolation: isolate;
}

.flipbook .stf__block,
.flipbook .stf__item {
  padding: 0 !important;
  margin: 0 !important;
  gap: 0 !important;
}

/*
 * StPageFlip anima las páginas hard con top: 0. La hoja inferior puede conservar
 * la clase --soft aunque se dibuje temporalmente como hard (backface-visibility),
 * así que ambas caras deben reutilizar el mismo top real del libro.
 */
.flipbook .stf__item.--hard:not(.--simple),
.flipbook .stf__item.--soft:not(.--simple)[style*="backface-visibility"],
.flipbook .stf__hardShadow,
.flipbook .stf__hardInnerShadow {
  top: var(--book-page-top, 0px) !important;
}

.book-page img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #fff;
  pointer-events: none;
  user-select: none;
  -webkit-user-drag: none;
}

.hard-cover::after {
  position: absolute;
  z-index: 2;
  top: 0;
  bottom: 0;
  width: 5px;
  content: "";
  pointer-events: none;
}

.hard-cover {
  background: #fbfaf7;
  outline: 1px solid rgba(0, 0, 0, 0.42);
  outline-offset: -1px;
  box-shadow:
    inset 0 0 0 2px rgba(255, 255, 255, 0.18),
    inset 0 0 14px rgba(34, 26, 31, 0.12),
    0 0 34px rgba(0, 0, 0, 0.4);
}

.hard-cover img {
  filter: saturate(1.035) contrast(1.015);
}

.front-cover::after {
  right: 0;
  background: linear-gradient(90deg, transparent, rgba(24, 17, 22, 0.44));
  box-shadow: 3px 0 0 rgba(20, 15, 18, 0.22);
}

.back-cover::after {
  left: 0;
  background: linear-gradient(90deg, rgba(24, 17, 22, 0.44), transparent);
  box-shadow: -3px 0 0 rgba(20, 15, 18, 0.22);
}

.viewer-status {
  position: absolute;
  z-index: 15;
  display: flex;
  min-width: min(310px, calc(100% - 40px));
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 15px 18px;
  color: var(--muted-strong);
  background: rgba(19, 19, 27, 0.94);
  border: 1px solid var(--line);
  border-radius: 13px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.42);
  transition:
    opacity 180ms ease,
    visibility 180ms ease;
}

.viewer-status.is-hidden {
  visibility: hidden;
  opacity: 0;
}

.viewer-status.is-error {
  color: #ffc0c9;
  border-color: rgba(255, 103, 126, 0.25);
}

.viewer-status p {
  margin: 0;
  font-size: 0.88rem;
  font-weight: 650;
}

.viewer-status.is-error .loader {
  display: none;
}

.viewer-status.is-ready .loader {
  width: 10px;
  height: 10px;
  background: #58c09b;
  border: 0;
  box-shadow: 0 0 0 5px rgba(88, 192, 155, 0.1);
  animation: none;
}

.loader {
  width: 17px;
  height: 17px;
  border: 2px solid rgba(255, 255, 255, 0.16);
  border-top-color: #9f68dc;
  border-radius: 50%;
  animation: spin 0.75s linear infinite;
}

.visually-hidden {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  overflow: hidden !important;
  padding: 0 !important;
  margin: -1px !important;
  white-space: nowrap !important;
  border: 0 !important;
  clip: rect(0 0 0 0) !important;
  clip-path: inset(50%) !important;
}

.noscript-message {
  position: fixed;
  right: 18px;
  bottom: 18px;
  left: 18px;
  z-index: 30;
  margin: 0;
  padding: 14px 18px;
  color: #ffc0c9;
  text-align: center;
  background: #211119;
  border: 1px solid #663040;
  border-radius: 12px;
}

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

@keyframes status-pulse {
  50% {
    opacity: 0.48;
  }
}

@media (max-width: 820px) {
  :root {
    --toolbar-height: 66px;
  }

  .dashboard-shell {
    padding: 22px 20px 52px;
  }

  .hero {
    padding-top: 70px;
  }

  .library-grid {
    grid-template-columns: 1fr;
  }

  .library-card {
    min-height: 310px;
  }

  .viewer-toolbar {
    gap: 8px;
    padding: 0 10px;
  }

  .toolbar-actions {
    gap: 5px;
  }

  .toolbar-button--back span,
  .toolbar-button--download span,
  .toolbar-button--zoom span {
    display: none;
  }

  .toolbar-button--back,
  .toolbar-button--download,
  .toolbar-button--zoom {
    width: 42px;
    min-width: 42px;
    padding: 0;
  }

  .logo-window--viewer {
    width: 105px;
    height: 34px;
  }

  .logo-window--viewer img {
    width: 116px;
  }

  .viewer-stage {
    padding: 10px;
  }
}

@media (max-width: 520px) {
  .site-header {
    padding-bottom: 18px;
  }

  .logo-window--dashboard {
    width: 146px;
    height: 42px;
  }

  .logo-window--dashboard img {
    width: 160px;
  }

  .library-label {
    display: none;
  }

  .hero h1 {
    font-size: clamp(3rem, 15vw, 4.4rem);
  }

  .hero-copy {
    margin-top: 22px;
  }

  .library-card {
    min-height: 330px;
    padding: 23px;
    border-radius: 19px;
  }

  .viewer-toolbar {
    grid-template-columns: 34px minmax(48px, 1fr) auto;
    gap: 4px;
    padding: 0 6px;
  }

  .toolbar-button,
  .toolbar-button--icon,
  .toolbar-button--back,
  .toolbar-button--download,
  .toolbar-button--zoom {
    width: 34px;
    min-width: 34px;
    min-height: 34px;
  }

  .toolbar-actions {
    gap: 2px;
  }

  .logo-window--viewer {
    width: min(76px, 100%);
    height: 28px;
    justify-self: center;
  }

  .logo-window--viewer img {
    width: 84px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
