:root {
      --brand: #54bcc2;
      --brand-strong: #2c9fa7;
      --bg: #061012;
      --panel: rgba(12, 26, 29, .78);
      --panel-strong: rgba(11, 23, 26, .94);
      --line: rgba(255, 255, 255, .10);
      --text: #f4fbfb;
      --muted: #9db1b4;
      --shadow: 0 24px 70px rgba(0, 0, 0, .44);
      --radius: 22px;
    }

    * { box-sizing: border-box; }

    /* Proteção básica contra cópia e inspeção casual */
    html, body, body * {
      -webkit-user-select: none;
      user-select: none;
      -webkit-touch-callout: none;
    }

    img, canvas, svg, a {
      -webkit-user-drag: none;
      user-drag: none;
    }

    input {
      -webkit-user-select: text;
      user-select: text;
    }

    html, body {
      width: 100%;
      min-height: 100%;
      height: 100%;
      margin: 0;
      font-family: "Manrope", sans-serif;
      background:
        radial-gradient(circle at 10% 10%, rgba(84, 188, 194, .18), transparent 30%),
        radial-gradient(circle at 90% 85%, rgba(44, 159, 167, .12), transparent 34%),
        linear-gradient(145deg, #061012 0%, #0a1719 55%, #061012 100%);
      color: var(--text);
      overflow: hidden;
      -webkit-text-size-adjust: 100%;
    }

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

    .app {
      height: 100vh;
      height: 100dvh;
      min-height: 0;
      display: grid;
      grid-template-rows: auto 1fr auto;
      position: relative;
      isolation: isolate;
    }

    .app::before {
      content: "";
      position: fixed;
      inset: 0;
      z-index: -1;
      opacity: .22;
      pointer-events: none;
      background-image: linear-gradient(rgba(255,255,255,.02) 1px, transparent 1px), linear-gradient(90deg, rgba(255,255,255,.02) 1px, transparent 1px);
      background-size: 34px 34px;
      mask-image: radial-gradient(circle at center, #000, transparent 82%);
    }

    .topbar {
      display: flex;
      align-items: center;
      justify-content: space-between;
      gap: 18px;
      padding: max(12px, env(safe-area-inset-top)) clamp(14px, 3vw, 42px) 14px;
      border-bottom: 1px solid var(--line);
      background: rgba(5, 14, 16, .72);
      backdrop-filter: blur(18px);
      position: relative;
      z-index: 30;
    }

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

    .brand-mark {
      width: 42px;
      height: 42px;
      border-radius: 13px;
      display: grid;
      place-items: center;
      color: #062023;
      font-weight: 900;
      font-size: 13px;
      letter-spacing: -.03em;
      background: linear-gradient(135deg, #80d8dc, var(--brand));
      box-shadow: 0 12px 30px rgba(84, 188, 194, .28);
    }

    .brand-copy { min-width: 0; }
    .eyebrow { color: var(--brand); font-size: 10px; font-weight: 800; letter-spacing: .18em; text-transform: uppercase; }
    h1 { margin: 2px 0 0; font-size: clamp(14px, 1.4vw, 19px); line-height: 1.2; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

    .top-actions {
      display: flex;
      align-items: center;
      justify-content: flex-end;
      gap: 10px;
      min-width: 0;
      flex: 0 0 auto;
    }

    .zoom-controls {
      display: flex;
      align-items: center;
      gap: 6px;
      padding: 4px;
      border: 1px solid var(--line);
      border-radius: 15px;
      background: rgba(255,255,255,.035);
    }

    .zoom-controls .icon-btn {
      width: 34px;
      height: 34px;
      border-radius: 10px;
      border-color: transparent;
      background: transparent;
    }

    .zoom-controls .icon-btn:hover {
      border-color: rgba(84,188,194,.4);
      background: rgba(84,188,194,.14);
    }

    .zoom-level {
      min-width: 48px;
      padding: 0 4px;
      color: var(--muted);
      font-size: 11px;
      font-weight: 800;
      text-align: center;
      user-select: none;
    }

    .icon-btn:disabled {
      opacity: .35;
      cursor: not-allowed;
      transform: none !important;
    }

    .icon-btn, .control-btn {
      border: 1px solid var(--line);
      background: rgba(255,255,255,.055);
      cursor: pointer;
      transition: .2s ease;
      display: inline-grid;
      place-items: center;
    }

    .icon-btn {
      width: 42px;
      height: 42px;
      border-radius: 13px;
    }

    .icon-btn:hover, .control-btn:hover {
      border-color: rgba(84,188,194,.55);
      background: rgba(84,188,194,.13);
      transform: translateY(-1px);
    }

    .icon-btn svg, .control-btn svg { width: 19px; height: 19px; fill: none; stroke: currentColor; stroke-width: 1.8; }

    .viewer-shell {
      min-height: 0;
      position: relative;
      display: grid;
      place-items: center;
      padding: clamp(8px, 1.8vh, 18px) clamp(8px, 2.8vw, 38px) clamp(6px, 1.2vh, 12px);
      overflow: hidden;
    }

    .book-stage {
      width: 100%;
      height: 100%;
      min-width: 0;
      min-height: 0;
      position: relative;
      display: flex;
      align-items: center;
      justify-content: center;
      perspective: 2200px;
      overflow: hidden;
      overscroll-behavior: contain;
      scrollbar-width: thin;
      scrollbar-color: rgba(84,188,194,.45) transparent;
    }

    .book-stage.is-zoomed {
      overflow: auto;
      align-items: flex-start;
      justify-content: flex-start;
    }

    .book-stage::-webkit-scrollbar { width: 8px; height: 8px; }
    .book-stage::-webkit-scrollbar-track { background: transparent; }
    .book-stage::-webkit-scrollbar-thumb {
      border-radius: 99px;
      background: rgba(84,188,194,.38);
    }

    .zoom-surface {
      position: relative;
      flex: 0 0 auto;
      min-width: 1px;
      min-height: 1px;
      display: grid;
      place-items: center;
    }

    .zoom-content {
      position: relative;
      transform: scale(1);
      transform-origin: top left;
      transition: transform .18s ease;
      will-change: auto;
      backface-visibility: hidden;
      -webkit-backface-visibility: hidden;
    }

    .book-stage::after {
      content: "";
      position: absolute;
      width: min(70vw, 900px);
      height: 45px;
      bottom: 0;
      border-radius: 50%;
      background: rgba(0,0,0,.72);
      filter: blur(24px);
      z-index: -1;
    }

    #book {
      margin: 0;
      box-shadow:
        0 34px 54px rgba(0,0,0,.48),
        0 10px 20px rgba(0,0,0,.28);
      transform-style: preserve-3d;
      backface-visibility: hidden;
      -webkit-backface-visibility: hidden;
    }

    body.is-turning #book {
      box-shadow:
        0 34px 54px rgba(0,0,0,.48),
        0 10px 20px rgba(0,0,0,.28);
    }

    body.is-turning .book-stage::after {
      background: rgba(0,0,0,.76);
      filter: blur(24px);
      transform: none;
    }

    .page {
      background: #fff;
      overflow: hidden;
      position: relative;
      backface-visibility: hidden;
      transform-style: preserve-3d;
      -webkit-backface-visibility: hidden;
    }

    .page canvas {
      width: 100%;
      height: 100%;
      display: block;
      object-fit: fill;
      background: linear-gradient(110deg, #f3f3f3 8%, #ffffff 18%, #f3f3f3 33%);
      background-size: 200% 100%;
      animation: pageLoading 1.2s linear infinite;
    }

    .page.is-rendered canvas { animation: none; background: #fff; }
    @keyframes pageLoading { to { background-position-x: -200%; } }

    .page::after {
      content: "";
      position: absolute;
      inset: 0;
      pointer-events: none;
      box-shadow: inset 0 0 0 1px rgba(0,0,0,.06);
    }


    /* Evita cintilação sem sobrescrever as transformações internas do PageFlip. */
    #book .stf__item,
    #book .stf__block,
    #book .stf__wrapper {
      backface-visibility: hidden;
      -webkit-backface-visibility: hidden;
    }

    .loading-overlay {
      position: fixed;
      inset: 0;
      width: 100vw;
      width: 100dvw;
      height: 100vh;
      height: 100dvh;
      z-index: 1000;
      display: grid;
      place-items: center;
      background: rgba(5, 13, 15, .78);
      backdrop-filter: blur(14px);
      -webkit-backdrop-filter: blur(14px);
      transition: opacity .35s ease, visibility .35s ease;
      padding:
        max(16px, env(safe-area-inset-top))
        max(16px, env(safe-area-inset-right))
        max(16px, env(safe-area-inset-bottom))
        max(16px, env(safe-area-inset-left));
      overflow: hidden;
    }

    .loading-overlay.is-hidden { opacity: 0; visibility: hidden; pointer-events: none; }

    .loader-card {
      width: min(380px, calc(100vw - 32px));
      width: min(380px, calc(100dvw - 32px));
      max-width: 100%;
      margin: auto;
      padding: 28px 20px;
      border-radius: var(--radius);
      background: var(--panel-strong);
      border: 1px solid var(--line);
      box-shadow: var(--shadow);
      text-align: center;
    }

    .loader-logo {
      width: 64px;
      height: 64px;
      margin: 0 auto 18px;
      border-radius: 20px;
      display: grid;
      place-items: center;
      color: #062023;
      font-weight: 900;
      background: linear-gradient(135deg, #80d8dc, var(--brand));
      animation: float 1.8s ease-in-out infinite;
    }

    @keyframes float { 50% { transform: translateY(-6px) rotate(2deg); } }

    .loader-card h2 { margin: 0 0 8px; font-size: 18px; }
    .loader-card p { margin: 0; color: var(--muted); font-size: 13px; }

    .progress-track { height: 7px; margin-top: 22px; border-radius: 99px; overflow: hidden; background: rgba(255,255,255,.08); }
    .progress-bar { width: 5%; height: 100%; border-radius: inherit; background: linear-gradient(90deg, var(--brand-strong), #80d8dc); transition: width .22s ease; }

    .nav-arrow {
      position: absolute;
      top: 50%;
      transform: translateY(-50%);
      width: 54px;
      height: 54px;
      border-radius: 17px;
      border: 1px solid var(--line);
      background: rgba(7, 18, 20, .68);
      backdrop-filter: blur(14px);
      display: grid;
      place-items: center;
      cursor: pointer;
      z-index: 20;
      transition: .2s ease;
      box-shadow: 0 14px 35px rgba(0,0,0,.25);
    }

    .nav-arrow:hover { background: rgba(84,188,194,.18); border-color: rgba(84,188,194,.55); transform: translateY(-50%) scale(1.04); }
    .nav-arrow svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; }
    .nav-arrow.prev { left: clamp(8px, 2vw, 28px); }
    .nav-arrow.next { right: clamp(8px, 2vw, 28px); }

    .bottombar {
      display: grid;
      grid-template-columns: 1fr auto 1fr;
      align-items: center;
      gap: 16px;
      padding: 10px clamp(12px, 3vw, 42px) max(10px, env(safe-area-inset-bottom));
      border-top: 1px solid var(--line);
      background: rgba(5, 14, 16, .72);
      backdrop-filter: blur(18px);
      position: relative;
      z-index: 30;
    }

    .page-status { color: var(--muted); font-size: 12px; }
    .page-status strong { color: var(--text); }

    .controls {
      display: flex;
      align-items: center;
      gap: 8px;
      padding: 7px;
      border-radius: 17px;
      background: rgba(255,255,255,.045);
      border: 1px solid var(--line);
    }

    .control-btn { width: 38px; height: 38px; border-radius: 11px; }

    .page-jump {
      display: flex;
      align-items: center;
      gap: 7px;
      margin: 0 4px;
      color: var(--muted);
      font-size: 12px;
    }

    .page-jump input {
      width: 54px;
      height: 36px;
      text-align: center;
      color: var(--text);
      background: rgba(255,255,255,.06);
      border: 1px solid var(--line);
      border-radius: 10px;
      outline: none;
    }

    .page-jump input:focus { border-color: rgba(84,188,194,.65); box-shadow: 0 0 0 3px rgba(84,188,194,.1); }

    .hint { justify-self: end; color: var(--muted); font-size: 11px; text-align: right; }

    .thumbs-panel {
      position: fixed;
      top: 0;
      bottom: 0;
      left: 0;
      width: min(370px, 88vw);
      z-index: 50;
      transform: translateX(-102%);
      transition: transform .32s cubic-bezier(.2,.8,.2,1);
      background: rgba(5, 14, 16, .94);
      border-right: 1px solid var(--line);
      backdrop-filter: blur(22px);
      box-shadow: 25px 0 60px rgba(0,0,0,.35);
      display: grid;
      grid-template-rows: auto 1fr;
    }

    .thumbs-panel.is-open { transform: translateX(0); }
    .panel-head { display: flex; align-items: center; justify-content: space-between; padding: 20px; border-bottom: 1px solid var(--line); }
    .panel-head h3 { margin: 0; font-size: 15px; }
    .thumb-grid { overflow: auto; padding: 16px; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 13px; }
    .thumb {
      min-height: 40px;
      border: 1px solid var(--line);
      border-radius: 14px;
      overflow: hidden;
      padding: 0;
      background: rgba(255,255,255,.04);
      cursor: pointer;
      position: relative;
      transition: .2s ease;
    }
    .thumb:hover, .thumb.active { border-color: rgba(84,188,194,.8); transform: translateY(-2px); }
    .thumb canvas { width: 100%; height: auto; min-height: 40px; display: block; background: #fff; object-fit: cover; }
    .thumb span {
      position: absolute;
      top: 50%;
      right: 6px;
      bottom: auto;
      z-index: 2;
      min-width: 24px;
      height: 24px;
      padding: 0 6px;
      display: inline-flex;
      align-items: center;
      justify-content: center;
      transform: translateY(-50%);
      border-radius: 8px;
      box-sizing: border-box;
      color: #fff;
      font-size: 10px;
      font-weight: 800;
      line-height: 1;
      white-space: nowrap;
      background: rgba(5,14,16,.88);
      pointer-events: none;
    }

    .scrim { position: fixed; inset: 0; z-index: 45; opacity: 0; visibility: hidden; background: rgba(0,0,0,.48); transition: .25s ease; }
    .scrim.is-visible { opacity: 1; visibility: visible; }

    .error-box { padding: 22px; border-radius: 18px; background: rgba(80,20,20,.78); border: 1px solid rgba(255,110,110,.25); max-width: 520px; text-align: center; }

    /* CORREÇÃO DO LAYOUT DE ROLAGEM VERTICAL PARA CELULARES (RESPONSIVIDADE MÁXIMA) */
    body.is-mobile-scroll .viewer-shell {
      padding: 0 !important;
      display: block !important;
    }

    body.is-mobile-scroll .book-stage {
      overflow-y: auto !important;
      overflow-x: hidden !important;
      display: block !important;
      padding: 16px 12px !important;
      width: 100% !important;
      height: 100% !important;
    }

    body.is-mobile-scroll .zoom-surface,
    body.is-mobile-scroll .zoom-content {
      width: 100% !important;
      height: auto !important;
      transform: none !important;
      display: block !important;
    }

    body.is-mobile-scroll #book {
      display: flex !important;
      flex-direction: column !important;
      gap: 20px !important;
      width: 100% !important;
      max-width: 100% !important;
      margin: 0 auto !important;
      box-shadow: none !important;
      transform: none !important;
      position: relative !important;
    }

    body.is-mobile-scroll .page {
      content-visibility: auto;
      contain-intrinsic-size: 440px 622px;
      position: relative !important;
      top: auto !important;
      left: auto !important;
      display: block !important;
      width: 100% !important;
      max-width: 440px !important; /* Limite de conforto visual no mobile */
      margin: 0 auto !important;
      height: auto !important;
      aspect-ratio: 0.707 !important; /* Proporção perfeita A4 vertical */
      box-shadow: 0 6px 20px rgba(0, 0, 0, .4) !important;
      z-index: 1 !important;
      transform: none !important;
      border-radius: 8px;
    }

    body.is-mobile-scroll .nav-arrow,
    body.is-mobile-scroll .zoom-controls,
    body.is-mobile-scroll .bottombar,
    body.is-mobile-scroll .book-stage::after {
      display: none !important;
    }

    @media (max-width: 980px) {
      .topbar { gap: 12px; }
      .brand-mark { width: 38px; height: 38px; border-radius: 11px; }
      .top-actions { gap: 7px; }
      .icon-btn { width: 38px; height: 38px; border-radius: 11px; }
      .zoom-controls .icon-btn { width: 31px; height: 31px; }
      .bottombar { grid-template-columns: auto 1fr auto; gap: 10px; }
      .hint { max-width: 180px; }
    }

    @media (max-width: 760px) {
      .loading-overlay {
        left: 0 !important;
        right: 0 !important;
        top: 0 !important;
        bottom: 0 !important;
        transform: none !important;
        place-items: center !important;
      }

      .loader-card {
        width: calc(100vw - 32px);
        width: calc(100dvw - 32px);
        max-width: 380px;
        margin-inline: auto;
      }

      .topbar {
        padding: max(8px, env(safe-area-inset-top)) 12px 8px;
        gap: 8px;
      }
      .brand { gap: 8px; flex: 1 1 auto; overflow: hidden; }
      .brand-mark { width: 34px; height: 34px; font-size: 11px; flex: 0 0 auto; }
      .brand-copy { min-width: 0; flex: 1; }
      .eyebrow { font-size: 8px; letter-spacing: .13em; }
      h1 { max-width: 100%; font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
      
      .top-actions {
        max-width: auto;
        gap: 6px;
        flex: 0 0 auto;
      }
      .icon-btn { width: 34px; height: 34px; border-radius: 10px; flex: 0 0 auto; }
      .icon-btn svg, .control-btn svg { width: 17px; height: 17px; }
      .zoom-level { display: none; }
      .zoom-controls { gap: 1px; padding: 2px; flex: 0 0 auto; }
      .zoom-controls .icon-btn { width: 29px; height: 29px; }
      .viewer-shell { padding: 6px 4px 4px; }
      .book-stage { align-items: center; justify-content: center; }
      .book-stage::after { width: 80vw; height: 24px; filter: blur(14px); }
      .nav-arrow {
        top: auto;
        bottom: 8px;
        width: 40px;
        height: 40px;
        border-radius: 13px;
        transform: none;
      }
      .nav-arrow:hover { transform: scale(1.03); }
      .nav-arrow.prev { left: 8px; }
      .nav-arrow.next { right: 8px; }
      .bottombar {
        grid-template-columns: 1fr;
        justify-items: center;
        gap: 5px;
        padding: 7px 8px max(7px, env(safe-area-inset-bottom));
      }
      .page-status, .hint { display: none; }
      .controls {
        max-width: 100%;
        gap: 5px;
        padding: 5px;
        overflow-x: auto;
        scrollbar-width: none;
      }
      .controls::-webkit-scrollbar { display: none; }
      .control-btn { width: 34px; height: 34px; flex: 0 0 auto; }
      .page-jump { gap: 5px; margin: 0 2px; font-size: 11px; white-space: nowrap; }
      .page-jump input { width: 48px; height: 32px; }
      .thumbs-panel { width: min(330px, 92vw); }
      .thumb-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); padding: 12px; gap: 10px; }
    }

    @media (max-width: 430px) {
      .brand-copy .eyebrow { display: none; }
      h1 { font-size: 11px; max-width: 110px; }
      .thumb-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    }

    @media (max-height: 560px) and (orientation: landscape) {
      .topbar { padding-top: 6px; padding-bottom: 6px; }
      .brand-mark { width: 32px; height: 32px; }
      .icon-btn { width: 32px; height: 32px; }
      .bottombar { padding-top: 5px; padding-bottom: max(5px, env(safe-area-inset-bottom)); }
      .control-btn { width: 31px; height: 31px; }
      .page-jump input { height: 30px; }
      .nav-arrow { bottom: 4px; }
    }
