/* PGMF Digital Booklet Library — Firebase Frontend v1.6.0 */
:root {
      --primary: #093d57;
      --accent: #e2b049;
      --soft: #d9eceb;
      --bg: #fff9cd;
      --text: #10232f;
      --muted: #667985;
      --card: #ffffff;
      --line: rgba(9, 61, 87, 0.16);
      --shadow: 0 16px 40px rgba(9, 61, 87, 0.14);
      --font: Helvetica, Arial, sans-serif;
    }

    * { box-sizing: border-box; }

    html, body {
      margin: 0;
      padding: 0;
      min-height: 100%;
      font-family: var(--font);
      color: var(--text);
      background: linear-gradient(135deg, rgba(255,249,205,0.82), rgba(217,236,235,0.9));
    }

    body.modal-open { overflow: hidden; }

    .app {
      width: 100%;
      max-width: 1180px;
      margin: 0 auto;
      padding: 28px 18px 44px;
    }

    .hero {
      display: grid;
      grid-template-columns: 1fr auto;
      gap: 20px;
      align-items: end;
      padding: 28px;
      border: 1px solid var(--line);
      border-radius: 28px;
      background: rgba(255,255,255,0.72);
      box-shadow: var(--shadow);
      backdrop-filter: blur(10px);
    }

    .eyebrow {
      display: inline-flex;
      align-items: center;
      gap: 8px;
      width: fit-content;
      padding: 7px 12px;
      border-radius: 999px;
      color: var(--primary);
      background: rgba(226,176,73,0.18);
      font-size: 12px;
      font-weight: 700;
      letter-spacing: .08em;
      text-transform: uppercase;
    }

    h1 {
      margin: 14px 0 8px;
      color: var(--primary);
      font-size: clamp(28px, 4vw, 52px);
      line-height: 1.02;
      letter-spacing: -0.045em;
    }

    .subtitle {
      margin: 0;
      max-width: 720px;
      color: var(--muted);
      font-size: 16px;
      line-height: 1.55;
    }

    .guide {
      display: flex;
      align-items: center;
      gap: 12px;
      min-width: 230px;
      padding: 16px 18px;
      border-radius: 22px;
      background: var(--primary);
      color: white;
      box-shadow: 0 14px 34px rgba(9, 61, 87, 0.25);
    }

    .guide-icon {
      display: grid;
      place-items: center;
      flex: 0 0 42px;
      height: 42px;
      border-radius: 50%;
      background: var(--accent);
      color: var(--primary);
      font-weight: 900;
      font-size: 22px;
    }

    .guide strong {
      display: block;
      font-size: 14px;
      line-height: 1.2;
    }

    .guide span {
      display: block;
      margin-top: 2px;
      font-size: 12px;
      opacity: .82;
    }

    .toolbar {
      display: grid;
      grid-template-columns: minmax(220px, 1fr) repeat(3, minmax(140px, 180px));
      gap: 10px;
      margin: 18px 0 16px;
    }

    .control {
      width: 100%;
      border: 1px solid var(--line);
      border-radius: 16px;
      padding: 12px 14px;
      background: rgba(255,255,255,0.88);
      color: var(--text);
      font: inherit;
      outline: none;
    }

    .control:focus {
      border-color: var(--accent);
      box-shadow: 0 0 0 4px rgba(226,176,73,0.2);
    }

    .meta-row {
      display: flex;
      justify-content: space-between;
      align-items: center;
      gap: 12px;
      margin: 10px 2px 20px;
      color: var(--muted);
      font-size: 13px;
    }

    .clear-btn {
      border: 0;
      border-radius: 999px;
      padding: 9px 12px;
      background: rgba(9,61,87,0.08);
      color: var(--primary);
      cursor: pointer;
      font-weight: 700;
    }

    .clear-btn:hover { background: rgba(9,61,87,0.14); }

    .featured-section {
      margin: 18px 0 22px;
      padding: 14px;
      border: 1px solid rgba(226,176,73,0.34);
      border-radius: 26px;
      background: rgba(255,255,255,0.62);
      box-shadow: 0 12px 34px rgba(9,61,87,0.09);
    }

    .section-heading {
      display: flex;
      align-items: center;
      justify-content: space-between;
      gap: 12px;
      margin: 0 0 14px;
    }

    .section-heading h2 {
      margin: 0;
      color: var(--primary);
      font-size: 20px;
      letter-spacing: -0.025em;
    }

    .section-heading span {
      color: var(--muted);
      font-size: 12px;
      font-weight: 700;
    }

    .featured-grid {
      display: grid;
      grid-template-columns: 1fr;
      gap: 14px;
    }

    .grid {
      display: grid;
      grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
      gap: 18px;
    }

    .card {
      position: relative;
      display: flex;
      flex-direction: column;
      min-height: 100%;
      overflow: hidden;
      border: 1px solid var(--line);
      border-radius: 24px;
      background: var(--card);
      box-shadow: 0 12px 30px rgba(9, 61, 87, 0.1);
      cursor: pointer;
      transition: transform .18s ease, box-shadow .18s ease, border-color .18s ease;
    }

    .card.featured {
      border-color: rgba(226,176,73,0.62);
      box-shadow: 0 18px 46px rgba(9,61,87,0.16);
    }

    .card.featured.featured-card {
      display: grid;
      grid-template-columns: minmax(230px, 330px) minmax(0, 1fr);
      min-height: 0;
      max-height: 380px;
    }

    .card.featured.featured-card .cover-wrap {
      aspect-ratio: 3 / 4;
      height: 100%;
      min-height: 280px;
      max-height: 380px;
      border-right: 1px solid var(--line);
      background: linear-gradient(135deg, rgba(217,236,235,0.72), rgba(255,255,255,0.92));
    }

    .card.featured.featured-card .cover {
      object-fit: contain;
      background: white;
    }

    .card.featured.featured-card .card-body {
      justify-content: center;
      padding: 22px 24px;
      overflow: auto;
    }

    .card.featured.featured-card.description-expanded {
      max-height: none;
    }

    .card.featured.featured-card.description-expanded .card-body {
      overflow: visible;
    }

    .card.featured.featured-card .title {
      font-size: clamp(20px, 2.2vw, 28px);
      line-height: 1.12;
    }

    .card:hover,
    .card:focus-visible {
      transform: translateY(-4px);
      border-color: rgba(226,176,73,0.7);
      box-shadow: 0 18px 44px rgba(9, 61, 87, 0.18);
      outline: none;
    }

    .cover-wrap {
      position: relative;
      aspect-ratio: 3 / 4;
      overflow: hidden;
      background: linear-gradient(135deg, var(--soft), white);
    }

    .cover {
      width: 100%;
      height: 100%;
      object-fit: cover;
      display: block;
      transition: transform .25s ease;
    }

    .card:hover .cover { transform: scale(1.025); }

    .read-badge {
      position: absolute;
      left: 12px;
      bottom: 12px;
      display: inline-flex;
      align-items: center;
      gap: 8px;
      padding: 9px 11px;
      border-radius: 999px;
      background: rgba(9,61,87,0.92);
      color: white;
      font-size: 12px;
      font-weight: 800;
      letter-spacing: .01em;
    }

    .read-badge::after {
      content: '→';
      display: inline-grid;
      place-items: center;
      width: 18px;
      height: 18px;
      border-radius: 50%;
      background: var(--accent);
      color: var(--primary);
      font-weight: 900;
    }

    .card-body {
      display: flex;
      flex-direction: column;
      gap: 10px;
      padding: 16px;
    }

    .title {
      margin: 0;
      color: var(--primary);
      font-size: 17px;
      line-height: 1.25;
      letter-spacing: -0.02em;
    }

    .details {
      display: flex;
      flex-wrap: wrap;
      gap: 8px;
      color: var(--muted);
      font-size: 12px;
    }

    .card-meta-line {
      display: flex;
      align-items: center;
      justify-content: space-between;
      gap: 8px;
      color: var(--muted);
      font-size: 11px;
      font-weight: 700;
    }

    .reader-mode {
      color: var(--primary);
      opacity: .8;
    }

    .pill {
      display: inline-flex;
      align-items: center;
      max-width: 100%;
      padding: 5px 8px;
      border-radius: 999px;
      background: rgba(217,236,235,0.72);
      color: var(--primary);
      font-size: 11px;
      font-weight: 700;
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
    }

    .description {
      margin: 0;
      color: var(--muted);
      font-size: 13px;
      line-height: 1.45;
      display: -webkit-box;
      -webkit-line-clamp: 3;
      -webkit-box-orient: vertical;
      overflow: hidden;
    }

    .card.featured.featured-card .description {
      font-size: 14px;
      line-height: 1.55;
      -webkit-line-clamp: 4;
    }

    .description.expanded,
    .card.featured.featured-card .description.expanded {
      display: block;
      -webkit-line-clamp: unset;
      -webkit-box-orient: unset;
      overflow: visible;
    }

    .description-toggle {
      align-self: flex-start;
      margin: -4px 0 0;
      border: 0;
      border-radius: 999px;
      padding: 6px 9px;
      background: rgba(9,61,87,0.08);
      color: var(--primary);
      cursor: pointer;
      font: inherit;
      font-size: 12px;
      font-weight: 800;
    }

    .description-toggle:hover,
    .description-toggle:focus-visible {
      background: rgba(226,176,73,0.22);
      outline: none;
    }

    .tags {
      display: flex;
      flex-wrap: wrap;
      gap: 6px;
      margin-top: auto;
    }

    .tag {
      padding: 4px 7px;
      border-radius: 8px;
      background: rgba(226,176,73,0.16);
      color: var(--primary);
      font-size: 11px;
      font-weight: 700;
    }

    .state {
      display: grid;
      place-items: center;
      min-height: 280px;
      border: 1px dashed var(--line);
      border-radius: 24px;
      background: rgba(255,255,255,0.55);
      color: var(--muted);
      text-align: center;
      padding: 28px;
    }

    .state strong {
      display: block;
      margin-bottom: 6px;
      color: var(--primary);
      font-size: 20px;
    }

    .reader-modal {
      position: fixed;
      inset: 0;
      z-index: 9999;
      display: none;
      background: rgba(6, 22, 32, 0.72);
      backdrop-filter: blur(8px);
    }

    .reader-modal.open { display: grid; }

    .reader-panel {
      display: grid;
      grid-template-rows: auto 1fr;
      width: min(1180px, calc(100vw - 22px));
      height: min(920px, calc(100vh - 22px));
      margin: auto;
      overflow: hidden;
      border-radius: 24px;
      background: white;
      box-shadow: 0 24px 80px rgba(0,0,0,0.35);
    }

    .reader-header {
      display: grid;
      grid-template-columns: 1fr auto;
      gap: 12px;
      align-items: center;
      padding: 14px 16px;
      border-bottom: 1px solid var(--line);
      background: linear-gradient(90deg, white, rgba(217,236,235,0.72));
    }

    .reader-title {
      min-width: 0;
    }

    .reader-title h2 {
      margin: 0;
      color: var(--primary);
      font-size: 17px;
      line-height: 1.25;
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
    }

    .reader-title p {
      margin: 4px 0 0;
      color: var(--muted);
      font-size: 12px;
    }

    .close-btn {
      border: 0;
      border-radius: 999px;
      padding: 10px 14px;
      background: var(--primary);
      color: white;
      cursor: pointer;
      font-weight: 800;
    }

    .close-btn:hover { background: #062c40; }

    .reader-frame {
      width: 100%;
      height: 100%;
      border: 0;
      background: #f4f6f7;
    }

    .reader-status {
      display: grid;
      place-items: center;
      min-height: 100%;
      padding: 28px;
      background: #f4f6f7;
      color: var(--primary);
      text-align: center;
    }

    .reader-status[hidden] { display: none; }

    .reader-status strong {
      display: block;
      margin-bottom: 8px;
      font-size: 18px;
    }

    .reader-status span {
      display: block;
      color: var(--muted);
      line-height: 1.45;
    }

    .book-reader {
      display: grid;
      grid-template-rows: 1fr auto;
      min-height: 0;
      background: radial-gradient(circle at 50% 10%, rgba(217,236,235,0.8), #122936 70%);
    }

    .book-reader[hidden] { display: none; }

    .book-stage {
      position: relative;
      min-height: 0;
      overflow: hidden;
      display: grid;
      place-items: center;
      padding: 18px;
    }

    .book-root {
      width: min(96%, 980px);
      height: min(100%, 720px);
      display: grid;
      place-items: center;
    }

    .book-pages {
      display: none;
    }

    .book-page {
      background: #fff;
      border-radius: 3px;
      overflow: hidden;
      box-shadow: inset 0 0 0 1px rgba(0,0,0,0.04);
    }

    .book-page .page-placeholder,
    .book-page img {
      width: 100%;
      height: 100%;
      display: grid;
      place-items: center;
      object-fit: contain;
      background: #fff;
      color: var(--muted);
      font-size: 13px;
      text-align: center;
      padding: 12px;
    }

    .book-root.simple-spread {
      display: grid;
      grid-template-columns: repeat(2, minmax(240px, 1fr));
      gap: 18px;
      width: min(94vw, 980px);
      margin: 0 auto;
      align-items: start;
    }

    .book-root.simple-spread .book-page {
      position: relative;
      min-height: 320px;
      border-radius: 14px;
      overflow: hidden;
      box-shadow: 0 14px 36px rgba(9,61,87,.18);
      display: flex;
      align-items: center;
      justify-content: center;
    }

    .book-root.simple-spread .book-page img {
      max-width: 100%;
      max-height: 76vh;
      object-fit: contain;
      display: block;
    }

    .book-root.simple-spread .book-page.single {
      grid-column: 1 / -1;
      max-width: 520px;
      justify-self: center;
    }

    .book-error-note {
      color: #7a1f1f;
      font-weight: 800;
      font-size: 13px;
      text-align: center;
      padding: 18px;
    }

    .book-controls {
      display: flex;
      gap: 10px;
      align-items: center;
      justify-content: center;
      flex-wrap: wrap;
      padding: 12px;
      border-top: 1px solid rgba(255,255,255,0.16);
      background: rgba(6,22,32,0.82);
      color: white;
    }

    .book-controls button {
      border: 0;
      border-radius: 999px;
      padding: 9px 13px;
      background: white;
      color: var(--primary);
      cursor: pointer;
      font-weight: 900;
    }

    .book-controls button.secondary {
      background: rgba(255,255,255,0.15);
      color: white;
      border: 1px solid rgba(255,255,255,0.32);
    }

    .book-page-counter {
      min-width: 88px;
      text-align: center;
      font-size: 12px;
      font-weight: 800;
      letter-spacing: .03em;
    }


    .footer {
      margin-top: 26px;
      color: var(--muted);
      font-size: 11px;
      text-align: center;
    }

    .sr-only {
      position: absolute;
      width: 1px;
      height: 1px;
      padding: 0;
      margin: -1px;
      overflow: hidden;
      clip: rect(0, 0, 0, 0);
      white-space: nowrap;
      border: 0;
    }

    @media (max-width: 760px) {
      .app { padding: 16px 12px 28px; }
      .hero {
        grid-template-columns: 1fr;
        padding: 20px;
        border-radius: 22px;
      }
      .guide { min-width: 0; }
      .toolbar { grid-template-columns: 1fr; }
      .featured-section { padding: 12px; border-radius: 22px; }
      .featured-grid { grid-template-columns: 1fr; }
      .card.featured.featured-card {
        grid-template-columns: 1fr;
        max-height: none;
      }
      .card.featured.featured-card .cover-wrap {
        height: auto;
        min-height: 0;
        max-height: none;
        border-right: 0;
        border-bottom: 1px solid var(--line);
      }
      .card.featured.featured-card .card-body {
        padding: 16px;
        overflow: visible;
      }
      .grid { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 12px; }
      .card { border-radius: 18px; }
      .card-body { padding: 13px; }
      .reader-panel {
        width: 100vw;
        height: 100vh;
        border-radius: 0;
      }
      .reader-header { padding: 12px; }
    }
