* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; font: 15px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; color: #222; background: #fafaf7; -webkit-text-size-adjust: 100%; }
body { padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left); }

header { display: flex; align-items: baseline; justify-content: space-between; padding: 14px 18px; border-bottom: 1px solid #e5e5e0; background: #fff; position: sticky; top: 0; z-index: 2; }
header h1 { margin: 0; font-size: 20px; font-weight: 600; }
.stats { color: #888; font-size: 13px; }

.search { padding: 12px 18px; background: #fff; border-bottom: 1px solid #e5e5e0; position: sticky; top: 49px; z-index: 1; }
.search input { width: 100%; padding: 11px 14px; font-size: 16px; border: 1px solid #d4d4cf; border-radius: 8px; background: #fafaf7; }
.search input:focus { outline: none; border-color: #888; background: #fff; }

ul.cards { list-style: none; margin: 0; padding: 0; }
ul.cards li { padding: 12px 18px; border-bottom: 1px solid #ececec; cursor: pointer; transition: background 80ms; }
ul.cards li:hover { background: #f0ede5; }
ul.cards li:active { background: #ece9e0; }

.card-composer { font-size: 12px; font-weight: 600; color: #888; text-transform: uppercase; letter-spacing: 0.04em; margin: 0 0 2px 0; }
.card-title { font-size: 16px; font-weight: 500; color: #222; margin: 0 0 4px 0; line-height: 1.3; word-break: break-word; }
.card-meta { font-size: 12px; color: #999; display: flex; gap: 8px; align-items: center; }
.badge { display: inline-block; padding: 1px 7px; border-radius: 9px; font-size: 10px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; }
.badge-avulso  { background: #e5e5e0; color: #666; }
.badge-coleção { background: #d5e3f5; color: #20538a; }
.badge-scan    { background: #f6e4b8; color: #7d5a00; }

@media (min-width: 720px) {
  ul.cards { max-width: 760px; margin: 0 auto; }
  ul.cards li { padding: 14px 20px; }
  .card-title { font-size: 17px; }
}

[hidden] { display: none !important; }
#viewer { position: fixed; inset: 0; background: #1a1a17; z-index: 10; display: flex; flex-direction: column; }
.viewer-bar { display: flex; gap: 8px; align-items: center; padding: 8px 12px; background: #2a2a26; color: #f5f5f0; border-bottom: 1px solid #1a1a17; flex-shrink: 0; padding-top: max(8px, env(safe-area-inset-top)); }
.viewer-bar .meta { flex: 1; min-width: 0; overflow: hidden; line-height: 1.2; }
.viewer-bar .meta strong { display: block; font-size: 14px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.viewer-bar .meta span { display: block; font-size: 11px; color: #b0b0a8; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.viewer-bar button { padding: 6px 10px; border: 1px solid #4a4a44; background: #3a3a34; color: #f5f5f0; border-radius: 6px; cursor: pointer; font-size: 14px; min-width: 36px; }
.viewer-bar button:active { background: #4a4a44; }
.viewer-bar #v-page { font-size: 11px; color: #b0b0a8; min-width: 50px; text-align: center; }
.viewer-bar #v-close { font-size: 22px; line-height: 1; padding: 2px 12px; }

.pages { flex: 1; overflow: hidden; display: flex; align-items: center; justify-content: center; padding: 8px; touch-action: none; user-select: none; -webkit-user-select: none; position: relative; }
.pages canvas { max-width: 100%; max-height: 100%; box-shadow: 0 4px 16px rgba(0,0,0,0.5); background: #fff; pointer-events: none; }
.pages.loading::before { content: "A carregar…"; color: #b0b0a8; font-size: 13px; position: absolute; }
.pages.error::before { content: attr(data-err); color: #f4a299; font-size: 13px; padding: 0 16px; text-align: center; position: absolute; }

@media (min-width: 720px) {
  .viewer-bar { padding: 10px 16px; }
  .viewer-bar .meta strong { font-size: 16px; }
  .viewer-bar .meta span { font-size: 12px; }
}
