:root {
  color-scheme: dark;
  --ink: #0a303a;
  --ink-2: #174d58;
  --cream: #fff5d8;
  --paper: #fffaf0;
  --gold: #f7ae2b;
  --gold-light: #ffd66c;
  --coral: #c95e2c;
  --muted: #b9ced1;
  --shadow: 0 24px 70px rgba(0, 0, 0, .46);
}

* { box-sizing: border-box; }

/* Garante que o atributo HTML `hidden` prevaleça sobre regras de layout. */
[hidden] { display: none !important; }

html { min-height: 100%; background: #061d24; }

body {
  margin: 0;
  min-width: 280px;
  min-height: 100%;
  color: var(--cream);
  background:
    radial-gradient(circle at 50% 20%, rgba(39, 116, 128, .28), transparent 42%),
    linear-gradient(160deg, #061d24, #092f39 52%, #04171d);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button, a { font: inherit; }
button { color: inherit; }

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr auto;
}

.topbar {
  min-height: 76px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 12px clamp(18px, 4vw, 64px);
  border-bottom: 1px solid rgba(255, 214, 108, .22);
  background: rgba(4, 24, 30, .83);
  backdrop-filter: blur(18px);
  position: relative;
  z-index: 20;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  color: var(--cream);
  text-decoration: none;
}

.brand-mark {
  width: 46px;
  height: 46px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  color: var(--ink);
  background: linear-gradient(145deg, var(--gold-light), var(--gold));
  box-shadow: 0 8px 24px rgba(247, 174, 43, .22);
  font-size: 25px;
  font-weight: 900;
}

.brand strong, .brand small { display: block; }
.brand strong { font-size: 17px; letter-spacing: .08em; text-transform: uppercase; }
.brand small { margin-top: 2px; color: var(--muted); font-size: 12px; }

.top-actions { display: flex; gap: 8px; }

.icon-button {
  width: 43px;
  height: 43px;
  display: grid;
  place-items: center;
  border: 1px solid rgba(255, 245, 216, .28);
  border-radius: 13px;
  color: var(--cream);
  background: rgba(255, 255, 255, .07);
  cursor: pointer;
  transition: transform .18s ease, background .18s ease, border-color .18s ease;
  font-weight: 800;
  font-size: 19px;
}

.icon-button:hover, .icon-button:focus-visible {
  transform: translateY(-2px);
  border-color: var(--gold-light);
  background: rgba(247, 174, 43, .16);
  outline: none;
}

.sound-on { display: none; }
.icon-button[aria-pressed="true"] .sound-on { display: inline; }
.icon-button[aria-pressed="true"] .sound-off { display: none; }

.reader {
  width: min(1500px, 100%);
  margin-inline: auto;
  padding: clamp(20px, 3vw, 42px) clamp(14px, 3vw, 48px) 24px;
}

.intro {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 24px;
  margin: 0 auto 18px;
  width: min(1320px, 100%);
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--gold-light);
  font-size: 12px;
  font-weight: 900;
  letter-spacing: .2em;
  text-transform: uppercase;
}

.intro h1 {
  margin: 0;
  font-size: clamp(22px, 3vw, 38px);
  line-height: 1.08;
}

.download-link {
  flex: none;
  padding: 11px 17px;
  border: 1px solid rgba(255, 214, 108, .62);
  border-radius: 999px;
  color: var(--cream);
  background: rgba(247, 174, 43, .1);
  text-decoration: none;
  font-size: 14px;
  font-weight: 800;
  transition: background .18s ease, color .18s ease;
}

.download-link:hover, .download-link:focus-visible {
  color: var(--ink);
  background: var(--gold-light);
  outline: none;
}

.book-area {
  position: relative;
  width: min(1320px, 100%);
  min-height: min(74vw, 760px);
  margin-inline: auto;
  display: grid;
  place-items: center;
  overflow: hidden;
  border: 1px solid rgba(255, 214, 108, .22);
  border-radius: clamp(18px, 2vw, 32px);
  background:
    linear-gradient(rgba(3, 18, 23, .35), rgba(3, 18, 23, .76)),
    radial-gradient(circle at 50% 40%, #1a5f6c, #082932 68%, #061d24);
  box-shadow: var(--shadow);
  isolation: isolate;
}

.book-area::before {
  content: "";
  position: absolute;
  inset: 0;
  opacity: .22;
  background-image:
    radial-gradient(circle at 20% 40%, var(--gold-light) 0 1px, transparent 2px),
    radial-gradient(circle at 80% 30%, var(--gold-light) 0 1px, transparent 2px),
    radial-gradient(circle at 62% 72%, var(--gold-light) 0 1px, transparent 2px);
  background-size: 110px 110px, 170px 170px, 140px 140px;
  pointer-events: none;
}

.ambient-glow {
  position: absolute;
  z-index: -1;
  width: 62%;
  aspect-ratio: 1;
  border-radius: 50%;
  background: rgba(247, 174, 43, .17);
  filter: blur(90px);
}

.loading {
  display: grid;
  place-items: center;
  gap: 16px;
  color: var(--muted);
  font-weight: 700;
}

.spinner {
  width: 48px;
  height: 48px;
  border: 4px solid rgba(255, 255, 255, .12);
  border-top-color: var(--gold);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}

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

.book-stage {
  width: min(1220px, calc(100% - 26px));
  height: min(68vw, 690px);
  min-height: 260px;
  position: relative;
  filter: drop-shadow(0 24px 22px rgba(0, 0, 0, .42));
}

.book { width: 100%; height: 100%; }

.page {
  background: #f8eed5;
  overflow: hidden;
  box-shadow: inset 0 0 0 1px rgba(11, 48, 58, .16);
}

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

.controls {
  width: min(860px, 100%);
  margin: 22px auto 0;
  display: grid;
  grid-template-columns: 1fr minmax(170px, auto) 1fr;
  align-items: center;
  gap: 14px;
}

.nav-button {
  min-height: 48px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  border: 1px solid rgba(255, 245, 216, .28);
  border-radius: 15px;
  color: var(--cream);
  background: rgba(255, 255, 255, .07);
  cursor: pointer;
  font-weight: 850;
  transition: transform .18s ease, background .18s ease, opacity .18s ease;
}

.nav-button--primary {
  color: var(--ink);
  border-color: transparent;
  background: linear-gradient(145deg, var(--gold-light), var(--gold));
}

.nav-button:hover:not(:disabled), .nav-button:focus-visible:not(:disabled) {
  transform: translateY(-2px);
  outline: none;
}

.nav-button:disabled { opacity: .35; cursor: not-allowed; }

.page-status { text-align: center; }
.page-status > span { display: block; }
#page-label { font-size: 13px; font-weight: 800; }
.page-number { margin-top: 3px; color: var(--muted); font-size: 12px; }

.progress {
  width: min(860px, 100%);
  height: 5px;
  margin: 15px auto 0;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(255, 255, 255, .1);
}

.progress span {
  display: block;
  width: 12.5%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--coral), var(--gold-light));
  transition: width .35s ease;
}

.gesture-tip {
  margin: 12px 0 0;
  color: var(--muted);
  font-size: 12px;
  text-align: center;
}

.footer {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 18px clamp(18px, 4vw, 64px);
  color: #8fb0b5;
  border-top: 1px solid rgba(255, 255, 255, .08);
  font-size: 12px;
}

.help-dialog {
  width: min(520px, calc(100% - 28px));
  color: var(--ink);
  border: 3px solid var(--gold);
  border-radius: 28px;
  padding: 34px;
  background: var(--paper);
  box-shadow: var(--shadow);
}

.help-dialog::backdrop { background: rgba(0, 15, 20, .72); backdrop-filter: blur(8px); }
.help-dialog h2 { margin: 0 0 18px; font-size: 30px; }
.help-dialog ul { margin: 0; padding-left: 22px; line-height: 1.75; }
.help-dialog .eyebrow { color: var(--coral); }

.dialog-close {
  position: absolute;
  top: 14px;
  right: 14px;
  width: 38px;
  height: 38px;
  border: 0;
  border-radius: 50%;
  color: var(--ink);
  background: rgba(10, 48, 58, .09);
  cursor: pointer;
  font-size: 25px;
}

.fallback {
  width: 100%;
  max-height: 78vh;
  overflow: auto;
  padding: 28px;
  text-align: center;
}

.fallback-pages { display: grid; gap: 22px; }
.fallback-pages img { display: block; width: 100%; border-radius: 16px; box-shadow: var(--shadow); }

.noscript {
  position: fixed;
  inset: auto 20px 20px;
  z-index: 100;
  padding: 16px;
  color: #401c0d;
  border-radius: 12px;
  background: var(--gold-light);
  text-align: center;
  font-weight: 800;
}

:fullscreen .topbar, :fullscreen .footer, :fullscreen .intro { display: none; }
:fullscreen .reader { width: 100%; height: 100vh; padding: 14px; display: grid; grid-template-rows: 1fr auto auto auto; }
:fullscreen .book-area { width: 100%; min-height: 0; height: 100%; }
:fullscreen .book-stage { width: min(94vw, 1580px); height: min(84vh, 889px); }

@media (max-width: 720px) {
  .topbar { min-height: 64px; }
  .brand small { display: none; }
  .intro { align-items: center; }
  .intro h1 { max-width: 15ch; }
  .download-link { padding: 10px 13px; font-size: 12px; }
  .book-area { min-height: 65vw; }
  .book-stage { width: calc(100% - 10px); height: 62vw; min-height: 190px; }
  .controls { grid-template-columns: 1fr 1fr; }
  .page-status { grid-column: 1 / -1; grid-row: 1; margin-bottom: 2px; }
  .footer { display: none; }
}

@media (max-width: 440px) {
  .reader { padding-inline: 8px; }
  .top-actions { gap: 4px; }
  .icon-button { width: 39px; height: 39px; }
  .brand-mark { width: 40px; height: 40px; }
  .book-area { border-radius: 15px; }
  .nav-button { min-height: 45px; font-size: 13px; }
  .gesture-tip { padding-inline: 20px; }
}

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