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

    :root { /* spine-font: Caveat */ /* cover-font: Lora */
      --bg:        #080810;
      --text:      #e8e8f0;
      --muted:     #7070a0;
      --dimmed:    #3a3a5a;
      --border:    rgba(255,255,255,0.07);
      --rose:      #f472b6;
      --violet:    #a78bfa;
      --paper:     #f4ede0;
      --ink:       #2a1f14;
      --ink-mid:   #5a4838;
      --ink-muted: #9a8878;
      --poem-font: 'Caveat', cursive;
      /* Dimensions used for DOM measurement pagination */
      --pg-w: 300px;
      --pg-h: 400px;
    }

    html, body { height: 100%; }
    body {
      background: var(--bg); color: var(--text);
      font-family: 'DM Sans', sans-serif; font-size: 15px; line-height: 1.6;
      min-height: 100vh; overflow-x: hidden;
    }
    body::before {
      content: ''; position: fixed; inset: 0;
      background-image: radial-gradient(circle, rgba(255,255,255,0.03) 1px, transparent 1px);
      background-size: 28px 28px; pointer-events: none; z-index: 0;
    }
    .glow { position: fixed; border-radius: 50%; filter: blur(140px); pointer-events: none; z-index: 0; opacity: 0.1; }
    .glow-1 { width: 600px; height: 600px; background: var(--rose);   top:-200px; right:-100px; }
    .glow-2 { width: 500px; height: 500px; background: var(--violet); bottom:-100px; left:-150px; }

    /* ── NAV ── */
    .topnav {
      position: relative; z-index: 10;
      display: flex; align-items: center; gap: 10px;
      padding: 1.6rem 2.5rem;
      font-family: 'DM Mono', monospace; font-size: 11px; letter-spacing: 0.1em; color: var(--dimmed);
    }
    .topnav a { color: var(--muted); text-decoration: none; transition: color 0.2s; }
    .topnav a:hover { color: var(--text); }

    /* ── HERO ── */
    .hero { position: relative; z-index: 1; max-width: 900px; margin: 0 auto; padding: 0 2.5rem; }
    .hero-eyebrow { font-family: 'DM Mono', monospace; font-size: 11px; letter-spacing: 0.18em; color: var(--muted); text-transform: uppercase; margin-bottom: 0.5rem; }
    .hero-title { font-family: 'Syne', sans-serif; font-size: clamp(2.4rem, 6vw, 4.5rem); font-weight: 800; line-height: 0.95; letter-spacing: -0.03em; color: #fff; }
    .hero-title span { background: linear-gradient(135deg, var(--rose) 0%, var(--violet) 70%); -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text; }

    /* ════════════════════════════════════
       BOOKSHELF
    ════════════════════════════════════ */
    .library { position: relative; z-index: 1; padding: 3rem 2.5rem 5rem; }

    .shelf {
      max-width: 1000px; margin: 0 auto; position: relative;
      padding: 3rem 3rem 0;
      display: flex; align-items: flex-end; gap: 10px;
      min-height: 340px;
    }
    .shelf::before { /* back wall */
      content: ''; position: absolute; inset: 0;
      background: linear-gradient(180deg, #07050a, #0d0807); border-radius: 4px;
    }
    .shelf::after { /* board */
      content: ''; position: absolute; bottom: 0; left: 0; right: 0; height: 30px;
      background: linear-gradient(180deg, #3d2b1a 0%, #2e1f0f 40%, #1e1208 100%);
      border-radius: 3px 3px 0 0;
      box-shadow: 0 6px 28px rgba(0,0,0,0.75), inset 0 1px 0 rgba(255,255,255,0.08);
    }

    .book-wrap {
      position: relative; z-index: 2; flex-shrink: 0; cursor: pointer;
      transition: transform 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
      transform-origin: bottom center;
    }
    .book-wrap:hover { transform: translateY(-30px) scale(1.03); }
    .book-wrap.extracting {
      transform: translateY(-70px) scale(1.08) rotateZ(-1.5deg);
      transition: transform 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
    }

    .book-spine {
      width: 60px; height: 320px; border-radius: 2px 0 0 2px; position: relative;
      display: flex; align-items: center; justify-content: center;
      box-shadow: 4px 0 10px rgba(0,0,0,0.5), inset -2px 0 4px rgba(0,0,0,0.25), inset 2px 0 4px rgba(255,255,255,0.06);
      transition: box-shadow 0.3s;
    }
    .book-wrap:hover .book-spine { box-shadow: 4px 0 18px rgba(0,0,0,0.65), -4px 0 30px rgba(255,200,80,0.08), inset -2px 0 5px rgba(0,0,0,0.3); }
    .book-spine::before { /* leather grain */
      content: ''; position: absolute; inset: 0; border-radius: inherit;
      background: repeating-linear-gradient(0deg, transparent, transparent 3px, rgba(0,0,0,0.07) 3px, rgba(0,0,0,0.07) 4px);
    }
    .book-spine::after { /* top/bottom bands */
      content: ''; position: absolute; left: 5px; right: 5px; top: 16px; bottom: 16px;
      border-top: 1px solid rgba(255,255,255,0.13); border-bottom: 1px solid rgba(255,255,255,0.13);
    }
    .book-title-spine {
      writing-mode: vertical-rl; transform: rotate(180deg);
      font-family: 'Caveat', cursive; font-size: 18px; font-style: italic; letter-spacing: 0.1em;
      color: rgba(255,220,140,0.92); text-shadow: 0 1px 3px rgba(0,0,0,0.7);
      position: relative; z-index: 1; width: 100%; height: 100%; display: flex; align-items: center; justify-content: center;
      overflow: hidden; white-space: normal; word-break: break-word; hyphens: auto; padding: 10px 10px; text-align: center;
    }
    .book-pages { display: none; }
    .shelf-loading { position: relative; z-index: 2; padding-bottom: 2rem; align-self: center; }

    /* ════════════════════════════════════
       OVERLAY
    ════════════════════════════════════ */
    .overlay {
      position: fixed; inset: 0; z-index: 200;
      display: flex; align-items: center; justify-content: center;
      background: rgba(4,3,10,0.94); backdrop-filter: blur(14px);
      opacity: 0; pointer-events: none;
      transition: opacity 0.45s ease;
    }
    .overlay.visible { opacity: 1; pointer-events: all; }

    .close-btn {
      position: absolute; top: 1.6rem; right: 1.6rem; z-index: 20;
      background: rgba(255,255,255,0.05); border: 1px solid rgba(255,255,255,0.1);
      color: var(--muted); font-family: 'DM Mono', monospace; font-size: 11px; letter-spacing: 0.1em;
      padding: 7px 14px; border-radius: 8px; cursor: pointer; transition: all 0.2s;
    }
    .close-btn:hover { background: rgba(255,255,255,0.1); color: var(--text); border-color: rgba(255,255,255,0.2); }

    /* ── CLOSED BOOK SCENE ── */
    .closed-scene {
      display: flex; flex-direction: column; align-items: center; gap: 1.4rem;
      transform: translateY(30px); opacity: 0;
      transition: transform 0.45s cubic-bezier(0.25, 0.46, 0.45, 0.94), opacity 0.4s ease;
    }
    .overlay.visible .closed-scene:not(.gone) { transform: translateY(0); opacity: 1; }
    .closed-scene.gone { opacity: 0 !important; transform: scale(0.94) translateY(-16px) !important; transition: all 0.3s ease !important; pointer-events: none; }

    .closed-book-3d {
      display: flex; cursor: pointer;
      filter: drop-shadow(0 32px 80px rgba(0,0,0,0.75));
      transition: transform 0.3s ease;
    }
    .closed-book-3d:hover { transform: translateY(-6px); }

    .closed-spine { display: none; }

    .closed-cover {
      width: min(63.64vh, 46vw); height: min(90vh, 920px); position: relative; overflow: hidden;
      display: flex; align-items: center; justify-content: center; padding: 2.6rem 2.4rem;
      border-radius: 2px 4px 4px 2px;
    }
    .closed-cover::before { /* leather grain */
      content: ''; position: absolute; inset: 0;
      background: repeating-linear-gradient(0deg, transparent, transparent 3px, rgba(0,0,0,0.06) 3px, rgba(0,0,0,0.06) 4px);
    }
    .closed-cover::after { /* vignette */
      content: ''; position: absolute; inset: 0;
      background: radial-gradient(ellipse at center, transparent 45%, rgba(0,0,0,0.35) 100%);
    }
    .cover-inner {
      position: relative; z-index: 1; width: 100%;
      border: 1px solid rgba(255,210,100,0.2); padding: 1.4rem 1rem; text-align: center;
    }
    .cover-inner::before { content: ''; position: absolute; inset: 5px; border: 1px solid rgba(255,210,100,0.1); }
    .cover-orn { display: block; font-size: 13px; color: rgba(255,210,100,0.45); letter-spacing: 0.25em; margin: 0.5rem 0; }
    .cover-title-text {
      font-family: 'Caveat', cursive; font-size: 26px; font-style: italic; font-weight: 500;
      color: rgba(255,220,140,0.92); text-shadow: 0 1px 6px rgba(0,0,0,0.6);
      line-height: 1.3; margin: 1rem 0; letter-spacing: 0.02em;
    }
    .cover-sub { font-family: 'DM Mono', monospace; font-size: 8px; letter-spacing: 0.2em; text-transform: uppercase; color: rgba(255,200,100,0.35); margin-top: 0.6rem; }

    .closed-pages-edge { display: none; }

    .open-hint {
      font-family: 'DM Mono', monospace; font-size: 10px; letter-spacing: 0.16em; text-transform: uppercase;
      color: var(--muted); animation: blink 2.5s ease-in-out infinite;
    }
    @keyframes blink { 0%,100%{opacity:0.4} 50%{opacity:0.9} }

    /* ── OPEN BOOK SCENE ── */
    .open-scene {
      display: none; flex-direction: column; align-items: center; gap: 0.7rem;
      transform: translateY(18px); opacity: 0;
      transition: transform 0.4s ease, opacity 0.35s ease;
    }
    .open-scene.ready { display: flex; }
    .open-scene.animated { transform: translateY(0); opacity: 1; }

    .open-book {
      display: flex;
      width: min(calc(127.28vh + 22px), 96vw);
      height: min(90vh, 920px);
      filter: drop-shadow(0 44px 88px rgba(0,0,0,0.75));
      position: relative;
    }

    /* ── BOOK PAGES ── */
    .bk-page {
      flex: 1; position: relative; overflow: hidden;
      padding: 2.5rem 2.6rem 2.2rem;
      cursor: pointer; user-select: none;
    }
    .open-book { align-items: stretch; }
    .bk-page { align-self: stretch; }
    .bk-page::before { /* paper grain */
      content: ''; position: absolute; inset: 0; z-index: 0; pointer-events: none; opacity: 0.03;
      background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 512 512' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='4' stitchTiles='stitch'/%3E%3CfeColorMatrix type='saturate' values='0'/%3E%3C/filter%3E%3Crect width='512' height='512' filter='url(%23n)'/%3E%3C/svg%3E");
      background-size: 200px 200px;
    }
    .bk-page-l {
      background: linear-gradient(90deg, #e2d8c8 0%, var(--paper) 10%);
      border-radius: 4px 0 0 4px;
    }
    .bk-page-l::after { content: ''; position: absolute; inset: 0; background: linear-gradient(90deg, transparent 80%, rgba(0,0,0,0.06) 100%); pointer-events: none; }
    .bk-page-r {
      background: linear-gradient(270deg, #e2d8c8 0%, var(--paper) 10%);
      border-radius: 0 4px 4px 0;
    }
    .bk-page-r::after { content: ''; position: absolute; inset: 0; background: linear-gradient(270deg, transparent 80%, rgba(0,0,0,0.06) 100%); pointer-events: none; }

    .bk-spine {
      width: 22px; flex-shrink: 0; z-index: 10;
      background: linear-gradient(90deg, #150a03 0%, #2e1c0a 45%, #150a03 100%);
      box-shadow: 0 0 28px rgba(0,0,0,0.9), inset 1px 0 2px rgba(255,255,255,0.04), inset -1px 0 2px rgba(255,255,255,0.04);
    }

    /* ── PAGE CONTENT WRAP ── */
    .pg-content {
      position: relative; z-index: 1; height: 100%;
      display: flex; flex-direction: column;
      overflow: hidden;
    }

    /* Spinner inside page */
    .pg-loading { flex: 1; display: flex; align-items: center; justify-content: center; }

    /* ── PAGE TYPES ── */

    /* VERSO (blank) */
    .pg-verso { flex: 1; }

    /* TITLE PAGE */
    .pg-title { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; }
    .pt-orn { font-size: 15px; color: var(--ink-muted); letter-spacing: 0.3em; margin: 0.7rem 0; }
    .pt-main { font-family: 'Caveat', cursive; font-size: clamp(18px, 2.2vw, 32px); font-weight: 500; font-style: italic; color: var(--ink); line-height: 1.2; margin: 0.4rem 0; }
    .pt-rule { width: 44px; height: 1px; background: var(--ink-muted); opacity: 0.4; margin: 0.8rem auto; }
    .pt-series { font-family: 'DM Mono', monospace; font-size: 9px; letter-spacing: 0.2em; text-transform: uppercase; color: var(--ink-muted); }
    .pt-author { font-family: 'Caveat', cursive; font-size: 12px; font-style: italic; color: var(--ink-mid); margin-top: 0.25rem; }

    /* TOC PAGE */
    .pg-toc { flex: 1; display: flex; flex-direction: column; justify-content: flex-start; min-height: 0; }
    .toc-hd { font-family: 'Caveat', cursive; font-size: clamp(10px, 1.1vw, 16px); font-style: italic; color: var(--ink-muted); letter-spacing: 0.08em; padding-bottom: 0.4rem; border-bottom: 1px solid rgba(42,31,20,0.14); margin-bottom: 0.5rem; flex-shrink: 0; }
    .toc-entries { min-height: 0; overflow: hidden; }
    .toc-row { display: flex; align-items: baseline; gap: 4px; padding: 0.15rem 0; border-bottom: 1px dotted rgba(42,31,20,0.06); cursor: pointer; transition: opacity 0.15s; flex-shrink: 0; }
    .toc-row:last-child { border-bottom: none; }
    .toc-row:hover { opacity: 0.65; }
    .toc-n { font-family: 'Caveat', cursive; font-size: clamp(9px, 1vw, 14px); color: var(--ink-muted); width: clamp(16px, 1.6vw, 26px); flex-shrink: 0; }
    .toc-t { font-family: 'Caveat', cursive; font-size: clamp(10px, 1.1vw, 16px); color: var(--ink-mid); flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; padding-right: 4px; }
    .toc-dots { flex: 0.5; border-bottom: 1px dotted rgba(42,31,20,0.2); margin: 0 4px; position: relative; top: -3px; min-width: 8px; }
    .toc-p { font-family: 'Caveat', cursive; font-size: 10px; color: var(--ink-muted); flex-shrink: 0; }

    /* PREFACE PAGE */
    .pg-preface { flex: 1; display: flex; flex-direction: column; }
    .pref-hd { font-family: 'Caveat', cursive; font-size: clamp(11px, 1.2vw, 17px); font-style: italic; color: var(--ink-muted); padding-bottom: 0.6rem; border-bottom: 1px solid rgba(42,31,20,0.12); margin-bottom: 0.8rem; }
    .pref-body { font-family: var(--poem-font); font-size: clamp(11px, 1.3vw, 18px); line-height: 1.85; color: var(--ink-mid); flex: 1; overflow: hidden; }
    .pref-body p { margin-bottom: 0.6em; }

    /* POEM PAGE */
    .pg-poem { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; }
    .poem-hd { font-family: 'Caveat', cursive; font-size: clamp(9px, 1.98vw, 22px); font-weight: 500; font-style: italic; color: var(--ink); text-align: center; line-height: 1.3; margin-bottom: 0.25rem; }
    .poem-rule { width: 26px; height: 1px; background: rgba(42,31,20,0.22); margin: 0.65rem 0 0.9rem; }
    .poem-cont-lbl { font-family: 'Caveat', cursive; font-size: clamp(9px, 0.9vw, 13px); font-style: italic; color: var(--ink-muted); text-align: center; margin-bottom: 0.8rem; }
    .poem-body {
      font-family: var(--poem-font); font-size: clamp(9px, 2.2vw, 16px); line-height: 1.75;
      color: var(--ink); text-align: center;
      font-feature-settings: 'rand' 1, 'calt' 1;
      overflow: hidden;
    }
    .poem-sbr { display: block; height: 0.85em; }

    /* PAGE NUMBER */
    .pg-num {
      font-family: 'Caveat', cursive; font-size: clamp(8px, 0.85vw, 12px); font-style: italic; color: var(--ink-muted);
      text-align: center; padding-top: 0.6rem; border-top: 1px solid rgba(42,31,20,0.1);
      margin-top: auto; flex-shrink: 0;
    }

    /* ════════════════════════════════════
       3-D PAGE FLIPPER
    ════════════════════════════════════ */
    .flipper {
      position: absolute; inset: 0; z-index: 30;
      transform-style: preserve-3d; display: none;
      pointer-events: none;
    }
    #flipR { transform-origin: left center; }
    #flipL { transform-origin: right center; }

    .flip-face {
      position: absolute; inset: 0;
      backface-visibility: hidden;
      padding: 2.5rem 2.6rem 2.2rem;
    }
    .flip-face.is-back { transform: rotateY(180deg); }

    /* right flipper faces */
    #flipR .flip-face         { background: linear-gradient(270deg, #e2d8c8 0%, var(--paper) 10%); }
    #flipR .flip-face.is-back { background: linear-gradient(90deg,  #e2d8c8 0%, var(--paper) 10%); }
    /* left flipper faces */
    #flipL .flip-face         { background: linear-gradient(90deg,  #e2d8c8 0%, var(--paper) 10%); }
    #flipL .flip-face.is-back { background: linear-gradient(270deg, #e2d8c8 0%, var(--paper) 10%); }

    /* shadow overlay on turning page for depth */
    .flipper::after {
      content: ''; position: absolute; inset: 0; z-index: 1; pointer-events: none;
      background: linear-gradient(90deg, rgba(0,0,0,0.12) 0%, transparent 30%);
      backface-visibility: hidden; opacity: 0;
      transition: opacity 0.65s ease;
    }
    .flipper.turning::after { opacity: 1; }

    /* ── BOOK NAVIGATION ── */
    .bk-nav { display: flex; align-items: center; gap: 14px; }
    .nav-btn {
      width: 36px; height: 36px; border-radius: 50%;
      background: rgba(255,255,255,0.05); border: 1px solid rgba(255,255,255,0.1);
      color: var(--muted); cursor: pointer; display: flex; align-items: center; justify-content: center;
      font-size: 14px; transition: all 0.2s;
    }
    .nav-btn:hover:not(:disabled) { background: rgba(255,255,255,0.1); color: var(--text); border-color: rgba(255,255,255,0.2); }
    .nav-btn:disabled { opacity: 0.22; cursor: default; }
    .pg-indicator {
      font-family: 'DM Mono', monospace; font-size: 10px; letter-spacing: 0.12em;
      color: var(--dimmed); min-width: 60px; text-align: center;
    }

    /* ── SPINNERS ── */
    .spin { width: 20px; height: 20px; border: 1.5px solid var(--border); border-top-color: var(--rose); border-radius: 50%; animation: rot 0.8s linear infinite; }
    .spin-sm { width: 14px; height: 14px; border-width: 1.5px; }
    @keyframes rot { to { transform: rotate(360deg); } }

    /* ── FOOTER ── */
    footer { position: relative; z-index: 1; text-align: center; padding: 2rem; font-family: 'DM Mono', monospace; font-size: 10px; letter-spacing: 0.1em; color: var(--dimmed); }

    /* ── RESPONSIVE ── */
    @media (max-width: 680px) {
      /* Kniha — jedna stránka, A-formát */
      .open-book {
        width: min(90vw, 420px);
        height: min(calc(90vw * 1.4142), calc(420px * 1.4142), 90vh);
        flex-direction: row; /* zachovat row, ale spine + jedna stránka skryté */
      }

      /* Hřbet skrýt */
      .bk-spine { display: none; }

      /* Na mobilu: levá skrytá, jen pravý slot se používá pro všechny stránky */
      .bk-page-l { display: none; }
      #flipL { display: none !important; }
      #flipR { display: none !important; }

      .bk-page-r {
        flex: 1;
        border-radius: 4px;
      }
      .pg-content { height: 100%; }
      .pg-toc { min-height: 0; overflow: hidden; }

      /* Police */
      .shelf { padding: 2rem 1.2rem 0; gap: 7px; }
      .book-spine { width: 42px; height: 190px; }

      /* Nav šipky větší na mobilu */
      .nav-btn { width: 44px; height: 44px; font-size: 18px; }

      /* Closed cover menší */
      .closed-cover {
        width: min(72vw, 320px);
        height: min(calc(72vw * 1.4142), calc(320px * 1.4142));
      }
    }