/* EAE Katalog — page-flip */
* { margin: 0; padding: 0; box-sizing: border-box; }

[hidden] { display: none !important; }

:root {
    --bg: #494949;
    --bg-light: #2e2e2e;
    --card: #505050;
    --text: #e8edf5;
    --text-dim: #b7b7b8;
    --accent: #e63329;
    --border: #6d6d6d;
}

body {
    font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
}

/* ---------- Katalog listesi (index) ---------- */
.site-header {
    text-align: center;
    padding: 48px 20px 32px;
}
.site-header h1 {
    font-size: 2rem;
    letter-spacing: 0.02em;
}
.site-header p { color: var(--text-dim); margin-top: 8px; }

.catalog-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 24px;
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 24px 64px;
}

.catalog-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 10px;
    overflow: hidden;
    text-decoration: none;
    color: var(--text);
    transition: transform .15s ease, box-shadow .15s ease;
}
.catalog-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 12px 28px rgba(0, 0, 0, .35);
}

.thumb {
    aspect-ratio: 3 / 4;
    background: var(--bg-light);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}
.thumb canvas { width: 100%; height: 100%; object-fit: cover; }
.thumb-error::after { content: "\1F4D5"; font-size: 3rem; }
.thumb-error canvas { display: none; }

.card-body { padding: 14px 16px; }
.card-body h2 {
    font-size: 0.95rem;
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.card-body .meta { font-size: 0.78rem; color: var(--text-dim); }

.empty-state {
    grid-column: 1 / -1;
    text-align: center;
    padding: 80px 20px;
    color: var(--text-dim);
}
.empty-state .hint { margin-top: 8px; font-size: 0.9rem; }
.empty-state code {
    background: var(--card);
    padding: 2px 8px;
    border-radius: 4px;
}

/* ---------- Görüntüleyici (viewer) ---------- */
.page-viewer {
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow: hidden;
}

.viewer-header {
    position: relative;
    z-index: 30; /* flipbook sarmalayıcısı stage'den taşabiliyor; tıklamalar üstte kalsın */
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 10px 16px;
    background: var(--bg-light);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}
.viewer-title {
    flex: 1;
    text-align: center;
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.header-actions { display: flex; gap: 8px; }

.btn {
    background: var(--card);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 8px 14px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.9rem;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    transition: background .15s ease;
}
.btn:hover { background: var(--border); }

.loading {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 18px;
    color: var(--text-dim);
}
.spinner {
    width: 42px;
    height: 42px;
    border: 4px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.progress-bar {
    width: 260px;
    height: 6px;
    background: var(--card);
    border-radius: 3px;
    overflow: hidden;
}
#progress-fill {
    height: 100%;
    width: 0;
    background: var(--accent);
    transition: width .2s ease;
}

.stage {
    position: relative;
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    min-height: 0;
}
#book { flex-shrink: 0; }
#book .stf__parent { margin: 0 auto; }
.pf-page {
    background: #fff;
    overflow: hidden;
    box-shadow: 0 2px 12px rgba(0, 0, 0, .3);
    container-type: size; /* metin katmanı cqh birimi sayfa boyutuna bağlansın */
    /* DİKKAT: buraya user-select:none koyma — Chromium'da metin katmanı seçimini tamamen kırıyor */
}

/* Seçilebilir metin katmanı: metnin üzerinde şeffaf span'lar */
.text-layer {
    position: absolute;
    inset: 0;
    z-index: 5;
    pointer-events: none; /* boş alanlardan sayfa çevirme çalışsın */
}
.text-layer span {
    position: absolute;
    color: transparent;
    pointer-events: auto;
    cursor: text;
    user-select: text;
    white-space: pre;
    transform-origin: 0 0;
    line-height: 1;
}
.text-layer span::selection {
    background: rgba(38, 128, 235, 0.4);
    color: transparent;
}

/* Cilt (sırt) kıvrımı: koyu gölge + ince parlama şeridi — sayfanın cilde bakan kenarında.
   StPageFlip sol/sağ sayfalara --left/--right sınıflarını kendisi ekliyor. */
.pf-page::after {
    content: '';
    position: absolute;
    inset: 0;
    z-index: 4;
    pointer-events: none;
}
.pf-page.--right::after {
    background: linear-gradient(to right,
        rgba(0, 0, 0, .30) 0%,
        rgba(0, 0, 0, .14) 1.2%,
        rgba(255, 255, 255, .16) 3%,
        rgba(0, 0, 0, .06) 5.5%,
        rgba(0, 0, 0, 0) 10%);
}
.pf-page.--left::after {
    background: linear-gradient(to left,
        rgba(0, 0, 0, .30) 0%,
        rgba(0, 0, 0, .14) 1.2%,
        rgba(255, 255, 255, .16) 3%,
        rgba(0, 0, 0, .06) 5.5%,
        rgba(0, 0, 0, 0) 10%);
}

/* Dış kenarda üst üste duran sayfa yaprakları izlenimi */
.pf-page.--left::before,
.pf-page.--right::before {
    content: '';
    position: absolute;
    top: 0;
    bottom: 0;
    width: 7px;
    z-index: 4;
    pointer-events: none;
}
.pf-page.--left::before {
    left: 0;
    background: repeating-linear-gradient(to right,
        rgba(0, 0, 0, .14) 0 1px, rgba(255, 255, 255, .25) 1px 2px, transparent 2px 3.5px);
}
.pf-page.--right::before {
    right: 0;
    background: repeating-linear-gradient(to left,
        rgba(0, 0, 0, .14) 0 1px, rgba(255, 255, 255, .25) 1px 2px, transparent 2px 3.5px);
}
.pf-page img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    user-select: none;
    -webkit-user-drag: none;
}
.search-highlight {
    position: absolute;
    z-index: 5;
    background: rgba(255, 213, 0, 0.55);
    mix-blend-mode: multiply;
    border-radius: 2px;
    pointer-events: none;
    animation: highlight-pulse 1s ease 2;
}
@keyframes highlight-pulse {
    50% { background: rgba(255, 145, 0, 0.75); }
}

.nav-arrow {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    z-index: 20;
    background: var(--card);
    border: 1px solid var(--border);
    color: var(--text);
    font-size: 1.8rem;
    line-height: 1;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    cursor: pointer;
    flex-shrink: 0;
    transition: background .15s ease;
}
.nav-prev { left: 12px; }
.nav-next { right: 12px; }
.nav-arrow:hover { background: var(--accent); border-color: var(--accent); }

.page-indicator {
    position: relative;
    z-index: 30; /* flipbook sarmalayıcısı stage'den taşabiliyor; tıklamalar üstte kalsın */
    text-align: center;
    padding: 10px;
    color: var(--text-dim);
    font-size: 0.9rem;
    background: var(--bg-light);
    border-top: 1px solid var(--border);
    flex-shrink: 0;
}
.page-input {
    width: 3.2em;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 5px;
    color: var(--text);
    font-weight: 600;
    font-size: 0.9rem;
    text-align: center;
    padding: 3px 4px;
    outline: none;
}
.page-input:focus { border-color: var(--accent); }

.page-link {
    position: absolute;
    z-index: 6;
    cursor: pointer;
    border-radius: 3px;
    transition: background .15s ease;
}
.page-link:hover {
    background: rgba(230, 51, 41, 0.15);
    outline: 1px solid rgba(230, 51, 41, 0.5);
}

.design-panel {
    position: absolute;
    top: 56px;
    left: 50%;
    transform: translateX(-50%);
    width: min(880px, calc(100vw - 32px));
    max-height: calc(100vh - 140px);
    background: var(--bg-light);
    border: 1px solid var(--border);
    border-radius: 10px;
    box-shadow: 0 16px 48px rgba(0, 0, 0, .5);
    z-index: 70;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}
.design-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 12px 14px;
    border-bottom: 1px solid var(--border);
}
.design-title { font-weight: 600; }
.design-tools { display: flex; gap: 8px; }

.design-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
    gap: 12px;
    padding: 14px;
    overflow-y: auto;
}
.design-item {
    position: relative;
    cursor: pointer;
    border: 2px solid var(--border);
    border-radius: 6px;
    overflow: hidden;
    background: #fff;
    transition: border-color .15s ease, transform .1s ease;
}
.design-item:hover { transform: translateY(-2px); }
.design-item.selected { border-color: var(--accent); }
.design-item img { width: 100%; display: block; }
.design-item input[type=checkbox] {
    position: absolute;
    top: 6px;
    left: 6px;
    width: 18px;
    height: 18px;
    accent-color: var(--accent);
    cursor: pointer;
}
.design-item.locked {
    cursor: default;
    border-style: dashed;
    opacity: 0.85;
}
.design-item.locked:hover { transform: none; }
.design-item.locked input[type=checkbox] {
    cursor: default;
    opacity: 1; /* pasif ama tik net görünsün */
}

.design-num {
    position: absolute;
    bottom: 4px;
    right: 6px;
    background: rgba(26, 35, 50, 0.85);
    color: var(--text);
    font-size: 0.72rem;
    font-weight: 600;
    padding: 1px 7px;
    border-radius: 4px;
}

.design-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 12px 14px;
    border-top: 1px solid var(--border);
}
#design-count { color: var(--text-dim); font-size: 0.9rem; }

.btn-primary {
    background: var(--accent);
    border-color: var(--accent);
    font-weight: 600;
}
.btn-primary:hover:not(:disabled) { background: #c92a21; }
.btn-primary:disabled { opacity: 0.45; cursor: not-allowed; }

.toc-panel {
    position: absolute;
    top: 56px;
    left: 16px;
    width: 320px;
    max-width: calc(100vw - 32px);
    background: var(--bg-light);
    border: 1px solid var(--border);
    border-radius: 10px;
    box-shadow: 0 12px 32px rgba(0, 0, 0, .45);
    z-index: 60;
    display: flex;
    flex-direction: column;
    max-height: min(60vh, 480px);
    overflow: hidden;
}
.toc-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 10px 10px 14px;
    border-bottom: 1px solid var(--border);
    font-weight: 600;
}
.toc-list {
    list-style: none;
    overflow-y: auto;
}
.toc-list li {
    display: flex;
    align-items: baseline;
    gap: 10px;
    padding: 10px 14px;
    cursor: pointer;
    border-bottom: 1px solid var(--border);
    font-size: 0.88rem;
}
.toc-list li:last-child { border-bottom: none; }
.toc-list li:hover { background: var(--card); }
.toc-title { flex: 1; }
.toc-num { color: var(--accent); font-weight: 600; font-size: 0.8rem; }

.search-panel {
    position: absolute;
    top: 56px;
    right: 16px;
    width: 360px;
    max-width: calc(100vw - 32px);
    background: var(--bg-light);
    border: 1px solid var(--border);
    border-radius: 10px;
    box-shadow: 0 12px 32px rgba(0, 0, 0, .45);
    z-index: 60;
    display: flex;
    flex-direction: column;
    max-height: min(60vh, 480px);
    overflow: hidden;
}
.search-row {
    display: flex;
    gap: 8px;
    padding: 10px;
    border-bottom: 1px solid var(--border);
}
.search-row input {
    flex: 1;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text);
    padding: 8px 10px;
    font-size: 0.9rem;
    outline: none;
}
.search-row input:focus { border-color: var(--accent); }

.search-count {
    padding: 6px 12px;
    font-size: 0.78rem;
    color: var(--text-dim);
    border-bottom: 1px solid var(--border);
}

.search-results {
    list-style: none;
    overflow-y: auto;
}
.search-results li {
    padding: 10px 12px;
    cursor: pointer;
    border-bottom: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.search-results li:last-child { border-bottom: none; }
.search-results li:hover { background: var(--card); }
.search-results li.active { background: var(--card); box-shadow: inset 3px 0 0 var(--accent); }

.result-page {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--accent);
}
.result-snippet {
    font-size: 0.82rem;
    color: var(--text-dim);
    line-height: 1.4;
}
.result-snippet mark {
    background: var(--accent);
    color: #fff;
    border-radius: 2px;
    padding: 0 2px;
}

.error-box {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 20px;
    color: var(--text-dim);
    padding: 20px;
    text-align: center;
}

/* ---------- Mobil ---------- */
@media (max-width: 640px) {
    .nav-arrow { display: none; }
    /* Tek sayfa modunda cilt yok; kıvrım ve kenar efektleri kapalı */
    .pf-page::before, .pf-page::after { display: none; }
    #book { max-width: 100%; }
    .viewer-header { gap: 8px; padding: 8px 10px; }
    .btn { padding: 6px 10px; font-size: 0.8rem; }
    .catalog-grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 14px; }
}
