/* ============================================================
   Códigos da Harmonia Quântica — PWA
   Tema: "biblioteca cósmica" — chrome índigo profundo com acentos
   ciano-elétricos (capa do livro); leitura em papel quente (dia)
   ou espaço profundo (noite).
   ============================================================ */

@font-face {
  font-family: "Comfortaa";
  src: url("../fonts/comfortaa-latin.woff2") format("woff2");
  font-weight: 400 700;
  font-display: swap;
}

:root {
  --display: "Comfortaa", ui-rounded, system-ui, sans-serif;
  --serif: "Charter", "Iowan Old Style", "Palatino Linotype", "Book Antiqua", Georgia, serif;

  --cosmic-bg: #0b0a1a;
  --cosmic-fg: #eef0ff;
  --cyan: #5ee4ff;
  --violet: #7b6cff;

  --font-scale: 1;

  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

/* leitura: dia = papel quente / noite = espaço profundo */
:root[data-theme="light"] {
  --bg: #f6f1e7;
  --fg: #2b2620;
  --fg-soft: #6d6457;
  --chrome-bg: rgba(246, 241, 231, 0.92);
  --chrome-fg: #3d3428;
  --accent: #4a3f8f;
  --hairline: rgba(43, 38, 32, 0.14);
  --card: #fffdf8;
}
:root[data-theme="dark"] {
  --bg: #100e1e;
  --fg: #ded9cd;
  --fg-soft: #8f8aa3;
  --chrome-bg: rgba(16, 14, 30, 0.92);
  --chrome-fg: #cfd2ec;
  --accent: var(--cyan);
  --hairline: rgba(222, 217, 205, 0.14);
  --card: #191631;
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
body {
  font-family: var(--serif);
  background: var(--bg);
  color: var(--fg);
  overflow: hidden;
  overscroll-behavior: none;
}
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
[hidden] { display: none !important; }

/* ============================================================
   CAPA CÓSMICA (cadastro + guia iOS)
   ============================================================ */
.cosmic {
  position: fixed; inset: 0;
  display: grid; place-items: center;
  background:
    radial-gradient(120% 90% at 85% 100%, rgba(64, 89, 255, 0.35), transparent 55%),
    radial-gradient(100% 70% at 10% 90%, rgba(123, 108, 255, 0.28), transparent 50%),
    radial-gradient(80% 60% at 50% 0%, rgba(19, 16, 48, 0.9), transparent 70%),
    var(--cosmic-bg);
  color: var(--cosmic-fg);
  overflow-y: auto;
  padding: calc(var(--safe-top) + 24px) 20px calc(var(--safe-bottom) + 32px);
}
.stars {
  position: absolute; inset: 0; pointer-events: none;
  background-image:
    radial-gradient(1.5px 1.5px at 12% 22%, #ffffffcc, transparent),
    radial-gradient(1px 1px at 78% 12%, #9fd8ffb0, transparent),
    radial-gradient(1.5px 1.5px at 62% 38%, #ffffff90, transparent),
    radial-gradient(1px 1px at 32% 64%, #b7a8ff99, transparent),
    radial-gradient(2px 2px at 88% 72%, #7be8ff88, transparent),
    radial-gradient(1px 1px at 45% 85%, #ffffff70, transparent),
    radial-gradient(1.5px 1.5px at 8% 88%, #9fd8ff77, transparent);
  animation: twinkle 6s ease-in-out infinite alternate;
}
@keyframes twinkle { from { opacity: 0.5; } to { opacity: 1; } }
.mandala {
  position: absolute; width: 480px; height: 480px; top: 46%; left: 50%;
  translate: -50% -50%; pointer-events: none; opacity: 0.5;
  background:
    repeating-conic-gradient(from 0deg, rgba(94, 228, 255, 0.12) 0deg 2deg, transparent 2deg 30deg);
  -webkit-mask: radial-gradient(circle, transparent 18%, black 19%, black 34%, transparent 35%, transparent 42%, black 43%, black 44%, transparent 45%);
          mask: radial-gradient(circle, transparent 18%, black 19%, black 34%, transparent 35%, transparent 42%, black 43%, black 44%, transparent 45%);
  border-radius: 50%;
  animation: spin 90s linear infinite;
}
@keyframes spin { to { rotate: 360deg; } }

.welcome-inner {
  position: relative; width: min(430px, 100%);
  display: flex; flex-direction: column; gap: 18px; text-align: center;
  animation: rise 0.8s cubic-bezier(0.2, 0.8, 0.2, 1) both;
}
@keyframes rise { from { opacity: 0; transform: translateY(24px); } }
.welcome-kicker {
  font-family: var(--display); font-size: 12px; letter-spacing: 0.28em;
  text-transform: uppercase; color: var(--cyan); opacity: 0.9;
}
.welcome-title {
  font-family: var(--display); font-weight: 700;
  font-size: clamp(30px, 8.5vw, 42px); line-height: 1.15;
  text-shadow: 0 0 34px rgba(94, 228, 255, 0.35);
}
.welcome-title.small { font-size: clamp(26px, 7vw, 34px); }
.welcome-sub { font-size: 15px; color: #bfc4e8; max-width: 34ch; margin: 0 auto; }

.card {
  background: rgba(18, 16, 40, 0.72);
  border: 1px solid rgba(123, 108, 255, 0.35);
  border-radius: 18px;
  padding: 22px 20px;
  backdrop-filter: blur(10px);
  display: flex; flex-direction: column; gap: 14px;
  text-align: left;
  box-shadow: 0 18px 60px rgba(0, 0, 10, 0.5);
}
.card-lead { font-size: 15px; color: #d9dcf5; }
.card label { display: flex; flex-direction: column; gap: 6px; font-family: var(--display); font-size: 12px; letter-spacing: 0.06em; text-transform: uppercase; color: #9aa0d0; }
.card input[type="text"], .card input[type="email"], .card input[type="tel"] {
  font: 16px var(--serif); color: var(--cosmic-fg);
  background: rgba(8, 7, 20, 0.6);
  border: 1px solid rgba(123, 108, 255, 0.3);
  border-radius: 10px; padding: 12px 14px; outline: none;
}
.card input:focus { border-color: var(--cyan); box-shadow: 0 0 0 3px rgba(94, 228, 255, 0.15); }
.consent { flex-direction: row !important; align-items: flex-start; gap: 10px !important; text-transform: none !important; letter-spacing: 0 !important; font-family: var(--serif) !important; font-size: 13px !important; color: #b9bedf !important; }
.consent input { margin-top: 3px; accent-color: var(--cyan); }
.consent a { color: var(--cyan); }

.btn-primary {
  font-family: var(--display); font-weight: 700; font-size: 15px;
  padding: 14px 18px; border-radius: 12px;
  color: #071018;
  background: linear-gradient(120deg, var(--cyan), #8f7bff 130%);
  box-shadow: 0 8px 28px rgba(94, 228, 255, 0.35);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.btn-primary:active { transform: scale(0.97); box-shadow: 0 4px 14px rgba(94, 228, 255, 0.25); }
.btn-ghost {
  font-family: var(--display); font-size: 14px; padding: 12px 16px;
  color: var(--cyan); border: 1px solid rgba(94, 228, 255, 0.4); border-radius: 12px;
}
.card-links { text-align: center; font-size: 13px; }
.card-links a { color: var(--cyan); }
.form-error { color: #ff9c9c; font-size: 13px; text-align: center; min-height: 1em; }

.code-row { display: flex; gap: 8px; justify-content: center; }
.code-row input {
  width: 44px; height: 54px; text-align: center;
  font: 24px var(--display); color: var(--cosmic-fg);
  background: rgba(8, 7, 20, 0.6);
  border: 1px solid rgba(123, 108, 255, 0.3); border-radius: 10px; outline: none;
}
.code-row input:focus { border-color: var(--cyan); }
.waiting { display: flex; align-items: center; gap: 10px; color: #9aa0d0; font-size: 14px; }
.pulse { width: 10px; height: 10px; border-radius: 50%; background: var(--cyan); animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 0%, 100% { opacity: 0.25; transform: scale(0.8); } 50% { opacity: 1; transform: scale(1.15); } }

.ios-steps { list-style: none; display: flex; flex-direction: column; gap: 16px; text-align: left; margin: 8px 0; }
.ios-steps li { display: flex; align-items: center; gap: 12px; background: rgba(18, 16, 40, 0.72); border: 1px solid rgba(123, 108, 255, 0.3); border-radius: 14px; padding: 14px 16px; font-size: 15px; }
.ios-steps svg { vertical-align: -3px; color: var(--cyan); }
.step-n {
  font-family: var(--display); font-weight: 700; flex: none;
  width: 30px; height: 30px; border-radius: 50%;
  display: grid; place-items: center;
  color: #071018; background: var(--cyan);
}

/* ============================================================
   LEITOR
   ============================================================ */
#screen-reader { position: fixed; inset: 0; display: flex; flex-direction: column; }

#topbar {
  flex: none; display: flex; align-items: center; gap: 8px;
  padding: calc(var(--safe-top) + 8px) 10px 8px;
  background: var(--chrome-bg); color: var(--chrome-fg);
  border-bottom: 1px solid var(--hairline);
  backdrop-filter: blur(12px);
  z-index: 5;
}
#topbar button { padding: 8px; border-radius: 10px; display: grid; place-items: center; }
#topbar button:active { background: var(--hairline); }
#book-title {
  flex: 1; text-align: center;
  font-family: var(--display); font-size: 13px; font-weight: 700;
  letter-spacing: 0.04em;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

#book { position: relative; flex: 1; overflow: hidden; }
#pages {
  height: 100%;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-y: contain;
  padding: 22px 24px 36px;
  font-size: calc(17px * var(--font-scale));
  line-height: 1.65;
}
#pages.pages-enter { animation: pagesFadeIn 0.28s ease; }
@keyframes pagesFadeIn { from { opacity: 0.3; transform: translateY(6px); } }

#nav-hint {
  position: absolute; left: 14px; right: 14px; bottom: 14px; z-index: 6;
  display: flex; align-items: center; gap: 10px;
  background: var(--accent); color: var(--bg);
  border-radius: 14px; padding: 12px 14px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
  font-size: 13px; line-height: 1.4;
  animation: hintIn 0.35s cubic-bezier(0.2, 0.9, 0.3, 1.2) 0.4s both;
}
@keyframes hintIn { from { opacity: 0; transform: translateY(16px); } }
#nav-hint p { flex: 1; }
#nav-hint strong { font-family: var(--display); }
#nav-hint button {
  flex: none; font-family: var(--display); font-weight: 700; font-size: 12px;
  padding: 8px 12px; border-radius: 8px; background: rgba(0, 0, 0, 0.15); color: inherit;
}
#pages h2 {
  font-family: var(--display); font-weight: 700;
  font-size: calc(21px * var(--font-scale)); line-height: 1.3;
  color: var(--accent);
  margin: 0 0 14px;
}
#pages .unit-kicker {
  font-family: var(--display); font-size: calc(11px * var(--font-scale));
  letter-spacing: 0.22em; text-transform: uppercase; color: var(--fg-soft);
  margin-bottom: 6px;
}
#pages p { margin: 0 0 1em; text-align: justify; hyphens: auto; -webkit-hyphens: auto; }
#pages .rule {
  border: 0; height: 1px; margin: 18px auto;
  background: linear-gradient(90deg, transparent, var(--accent), transparent);
  opacity: 0.5; width: 60%;
}
.qr-figure { text-align: center; margin: 12px 0 20px; break-inside: avoid; }
.qr-figure img.qr-inline {
  width: min(200px, 58vw); border-radius: 12px;
  border: 1px solid var(--hairline);
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.18);
  cursor: pointer;
  background: #fff;
}
.qr-figure figcaption { font-family: var(--display); font-size: 11px; letter-spacing: 0.12em; text-transform: uppercase; color: var(--fg-soft); margin-top: 8px; }

.pdf-image { margin: 18px 0; text-align: center; break-inside: avoid; }
.pdf-image img {
  max-width: 100%; border-radius: 12px;
  border: 1px solid var(--hairline);
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.18);
}

.unit-nav {
  display: flex; gap: 12px; margin-top: 32px; padding-top: 20px;
  border-top: 1px solid var(--hairline);
}
.unit-nav button {
  flex: 1; font-family: var(--display); font-weight: 700; font-size: 14px;
  padding: 14px; border-radius: 12px; border: 1px solid var(--hairline);
  color: var(--accent); background: var(--card);
}
.unit-nav button:active { background: var(--hairline); }
.unit-nav button:disabled { opacity: 0.3; }

#toolbar {
  flex: none; display: flex; align-items: center; justify-content: space-around;
  padding: 8px 12px calc(var(--safe-bottom) + 10px);
  background: var(--chrome-bg); color: var(--chrome-fg);
  border-top: 1px solid var(--hairline);
  backdrop-filter: blur(12px);
  z-index: 5;
}
#toolbar button {
  padding: 9px 12px; border-radius: 12px;
  display: grid; place-items: center;
  transition: background 0.15s ease;
}
#toolbar button:active { background: var(--hairline); }
#toolbar .a-small { font-family: var(--display); font-weight: 700; font-size: 13px; }
#toolbar .a-big { font-family: var(--display); font-weight: 700; font-size: 19px; }
#btn-tts[aria-pressed="true"] { color: var(--accent); }
#page-ind { font-family: var(--display); font-size: 11px; letter-spacing: 0.08em; color: var(--fg-soft); min-width: 54px; text-align: center; }

/* ============================================================
   DIÁLOGOS
   ============================================================ */
dialog {
  border: 0; padding: 0;
  background: var(--card); color: var(--fg);
  width: min(440px, calc(100vw - 32px));
  max-height: min(72vh, 640px);
  border-radius: 20px;
  margin: auto;
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.45);
  overflow: hidden;
  display: none;
  flex-direction: column;
}
dialog[open] { display: flex; animation: dlgIn 0.22s cubic-bezier(0.2, 0.9, 0.3, 1.2); }
@keyframes dlgIn { from { opacity: 0; transform: translateY(14px) scale(0.98); } }
dialog::backdrop { background: rgba(5, 4, 14, 0.6); backdrop-filter: blur(3px); }
dialog header {
  flex: none; display: flex; align-items: center; gap: 10px;
  padding: 16px 18px; border-bottom: 1px solid var(--hairline);
}
dialog header h2 { font-family: var(--display); font-size: 16px; flex: 1; }
.dlg-close {
  position: absolute; top: 10px; right: 10px;
  width: 34px; height: 34px; border-radius: 50%;
  display: grid; place-items: center;
  color: var(--fg-soft); font-size: 15px;
}
dialog header .dlg-close { position: static; margin-left: auto; }
.dlg-close:active { background: var(--hairline); }

#dlg-menu nav { display: flex; flex-direction: column; padding: 18px 14px 14px; gap: 4px; }
.menu-item {
  display: flex; align-items: center; gap: 14px;
  font-family: var(--display); font-weight: 700; font-size: 16px;
  color: var(--fg); text-decoration: none;
  padding: 15px 14px; border-radius: 14px; text-align: left;
  transition: background 0.15s ease;
}
.menu-item:active { background: var(--hairline); }
.mi-icon { font-size: 20px; }

#list-body, #search-results { overflow-y: auto; padding: 8px 0 14px; }
.list-row {
  display: flex; align-items: baseline; gap: 12px; width: 100%;
  padding: 13px 20px; text-align: left; font-size: 15px;
  border-bottom: 1px solid var(--hairline);
}
.list-row:active { background: var(--hairline); }
.list-row .n { font-family: var(--display); font-size: 12px; color: var(--accent); min-width: 34px; }
.list-section {
  font-family: var(--display); font-size: 11px; letter-spacing: 0.2em;
  text-transform: uppercase; color: var(--fg-soft);
  padding: 16px 20px 6px;
}
.alpha-row { position: sticky; top: 0; background: var(--card); font-family: var(--display); font-weight: 700; color: var(--accent); padding: 10px 20px 4px; font-size: 13px; }

#search-input {
  flex: 1; font: 16px var(--serif); color: var(--fg);
  background: transparent; border: 0; outline: none;
}
.result-row { display: block; width: 100%; text-align: left; padding: 13px 20px; border-bottom: 1px solid var(--hairline); }
.result-row .rt { font-family: var(--display); font-size: 13px; font-weight: 700; color: var(--accent); margin-bottom: 4px; display: block; }
.result-row .rs { font-size: 14px; color: var(--fg-soft); }
.result-row mark { background: none; color: var(--accent); font-weight: 700; }
.search-empty { padding: 24px 20px; text-align: center; color: var(--fg-soft); font-size: 14px; }

/* ============================================================
   QR EM TELA CHEIA
   ============================================================ */
#qr-full {
  position: fixed; inset: 0; z-index: 50;
  background: #ffffff;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 18px;
  padding: 24px;
  cursor: pointer;
  animation: qrIn 0.2s ease-out;
}
@keyframes qrIn { from { opacity: 0; transform: scale(0.96); } }
#qr-full img { width: min(92vw, 78vh); image-rendering: pixelated; }
#qr-full-title { font-family: var(--display); font-weight: 700; font-size: 15px; color: #1a1a2e; text-align: center; }
.qr-hint { font-family: var(--display); font-size: 11px; letter-spacing: 0.2em; text-transform: uppercase; color: #9a9ab0; }

@media (prefers-reduced-motion: reduce) {
  #pages.pages-enter { animation: none; }
  .mandala, .stars { animation: none; }
}
