:root {
  --bg: #0b162c;
  --bg-deep: #081120;
  --bg-soft: #13284d;
  --gold: #e0a94f;
  --gold-bright: #f3d28a;
  --gold-soft: rgba(224, 169, 79, 0.35);
  --cream: #f5ebdc;
  --muted: #b9c3d8;
  --surface: rgba(255, 255, 255, 0.06);
  --surface-strong: rgba(255, 255, 255, 0.12);
  --danger: #f1b3a6;
  --radius: 14px;
  --shadow: 0 24px 80px rgba(0, 0, 0, 0.45);
  --ui-font: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  --book-font: "EB Garamond", Georgia, "Times New Roman", serif;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  height: 100vh;
  min-height: 0;
  display: flex;
  flex-direction: column;
  color: var(--cream);
  font-family: var(--ui-font);
  background:
    radial-gradient(circle at 14% 8%, rgba(224, 169, 79, 0.1), transparent 34%),
    radial-gradient(circle at 86% 92%, rgba(64, 110, 180, 0.18), transparent 42%),
    linear-gradient(160deg, var(--bg), var(--bg-soft) 55%, var(--bg-deep));
  overflow: hidden;
}

.is-hidden {
  display: none !important;
}

.skip-link {
  position: absolute;
  top: 0.75rem;
  left: 0.75rem;
  z-index: 100;
  padding: 0.55rem 0.9rem;
  color: var(--bg-deep);
  background: var(--gold);
  border-radius: 999px;
  font-size: 0.85rem;
  text-decoration: none;
  transform: translateY(-200%);
  transition: transform 0.2s ease;
}

.skip-link:focus {
  transform: translateY(0);
}

.topbar {
  position: relative;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  padding: 0.9rem 1.25rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(11, 22, 44, 0.72);
  backdrop-filter: blur(14px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  min-width: 0;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 2.4rem;
  height: 2.4rem;
  color: var(--gold);
  border: 1px solid var(--gold-soft);
  border-radius: 50%;
  font-size: 1rem;
  box-shadow: inset 0 0 18px rgba(224, 169, 79, 0.12);
}

.brand-text {
  min-width: 0;
}

.brand-title {
  margin: 0;
  font-family: var(--book-font);
  font-size: 1.45rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  line-height: 1.05;
  white-space: nowrap;
}

.brand-subtitle {
  margin: 0.2rem 0 0;
  color: var(--gold);
  font-family: var(--book-font);
  font-size: 0.95rem;
  font-style: italic;
  letter-spacing: 0.03em;
}

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

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  min-height: 2.4rem;
  padding: 0.5rem 0.9rem;
  color: var(--cream);
  background: var(--surface);
  border: 1px solid var(--gold-soft);
  border-radius: 999px;
  font-family: var(--ui-font);
  font-size: 0.84rem;
  font-weight: 500;
  line-height: 1;
  text-decoration: none;
  cursor: pointer;
  transition:
    background-color 0.2s ease,
    border-color 0.2s ease,
    color 0.2s ease,
    transform 0.2s ease;
}

.button:hover {
  background: var(--surface-strong);
  border-color: var(--gold);
}

.button:active {
  transform: translateY(1px);
}

.button:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 3px;
}

.button:disabled {
  opacity: 0.35;
  cursor: not-allowed;
  transform: none;
}

.button--ghost {
  background: transparent;
}

.button--icon {
  width: 2.75rem;
  height: 2.75rem;
  padding: 0;
  border-radius: 50%;
  font-size: 1.3rem;
}

.stage {
  position: relative;
  flex: 1 1 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
  padding: 1rem 1rem 0.5rem;
  overflow: hidden;
}

.book-shell {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  min-height: 0;
}

.book {
  width: 100%;
  height: 100%;
  max-width: 1200px;
  max-height: 100%;
}

.book .page {
  background: #fbf7ef;
  overflow: hidden;
}

.book .page img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  user-select: none;
  -webkit-user-drag: none;
}

.loader,
.error {
  position: absolute;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  padding: 1rem;
  background: rgba(8, 17, 32, 0.72);
  backdrop-filter: blur(8px);
}

.loader-inner,
.error-inner {
  width: min(100%, 26rem);
  padding: 2rem 1.5rem;
  text-align: center;
  background: rgba(11, 22, 44, 0.92);
  border: 1px solid var(--gold-soft);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.loader-mark {
  color: var(--gold);
  font-size: 1.6rem;
  animation: pulse 1.6s ease-in-out infinite;
}

.loader-text {
  margin: 0.8rem 0 1rem;
  color: var(--cream);
  font-size: 0.95rem;
  letter-spacing: 0.02em;
}

.loader-track,
.render-status-track {
  position: relative;
  width: 100%;
  height: 4px;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.12);
  border-radius: 999px;
}

.loader-bar,
.render-status-bar {
  display: block;
  width: 0;
  height: 100%;
  background: linear-gradient(90deg, var(--gold), var(--gold-bright));
  border-radius: inherit;
  transition: width 0.2s ease;
}

.error-title {
  margin: 0 0 0.6rem;
  font-family: var(--book-font);
  font-size: 1.45rem;
  font-weight: 600;
}

.error-text {
  margin: 0 0 1.1rem;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.55;
}

.error-actions {
  display: flex;
  justify-content: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.render-status {
  position: absolute;
  bottom: 0.4rem;
  left: 50%;
  width: min(20rem, 80%);
  text-align: center;
  transform: translateX(-50%);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}

.render-status.is-visible {
  opacity: 1;
}

.render-status-text {
  display: block;
  margin-bottom: 0.3rem;
  color: var(--muted);
  font-size: 0.74rem;
  letter-spacing: 0.04em;
}

.controls {
  position: relative;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  padding: 0.8rem 1rem 1.2rem;
}

.page-indicator {
  min-width: 7rem;
  margin: 0;
  color: var(--muted);
  font-family: var(--ui-font);
  font-size: 0.86rem;
  letter-spacing: 0.06em;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.noscript {
  margin: 0;
  padding: 1rem;
  color: var(--danger);
  text-align: center;
}

@keyframes pulse {
  0%,
  100% {
    opacity: 0.5;
    transform: scale(0.92);
  }
  50% {
    opacity: 1;
    transform: scale(1.08);
  }
}

@media (max-width: 680px) {
  .topbar {
    padding: 0.65rem 0.75rem;
    gap: 0.6rem;
  }

  .brand-mark {
    width: 2rem;
    height: 2rem;
    font-size: 0.85rem;
  }

  .brand-title {
    font-size: 1.1rem;
  }

  .brand-subtitle {
    font-size: 0.8rem;
  }

  .button {
    min-height: 2.15rem;
    padding: 0.4rem 0.7rem;
    font-size: 0.76rem;
  }

  .button--icon {
    width: 2.5rem;
    height: 2.5rem;
  }

  .stage {
    padding: 0.5rem 0.5rem 0.25rem;
  }

  .controls {
    gap: 0.65rem;
    padding: 0.55rem 0.5rem 0.9rem;
  }

  .page-indicator {
    min-width: 5.5rem;
    font-size: 0.78rem;
  }
}

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