/**
 * Library styles - books grid, reader and translation panel.
 * Mobile-first responsive design.
 */

/* ---- Hero / page header --------------------------------------------- */
.library-hero {
    padding: 28px 24px;
    margin-bottom: 24px;
    background: linear-gradient(135deg, var(--glass-bg-strong), var(--glass-bg));
    border-radius: var(--radius-lg);
    border: 1px solid var(--glass-border);
}
.library-hero h1 {
    font-size: 2rem;
    font-weight: 800;
    margin: 0 0 6px;
    background: linear-gradient(135deg, var(--text-primary), var(--accent-red-light), var(--accent-cyan));
    -webkit-background-clip: text; background-clip: text; color: transparent;
}
.library-hero p {
    color: var(--text-secondary);
    font-size: 1rem;
    margin: 0 0 16px;
}
.library-toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    align-items: center;
    margin-top: 16px;
}
.library-search {
    flex: 1 1 240px;
    min-width: 0;
    display: flex;
    gap: 8px;
}
.library-search input {
    flex: 1 1 auto;
    min-width: 0;
}
.library-sort select {
    min-width: 140px;
}
.library-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

/* ---- Grid ------------------------------------------------------------ */
.library-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(min(200px, 100%), 1fr));
    gap: 20px;
}

/* ---- Book card ------------------------------------------------------- */
.book-card {
    display: flex;
    flex-direction: column;
    background: var(--glass-bg);
    backdrop-filter: blur(var(--glass-blur)) saturate(140%);
    -webkit-backdrop-filter: blur(var(--glass-blur)) saturate(140%);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-lg);
    overflow: hidden;
    box-shadow: var(--glass-shadow);
    transition: transform var(--transition-normal), box-shadow var(--transition-normal), border-color var(--transition-fast);
    height: 100%;
}
@media (hover: hover) {
    .book-card:hover {
        transform: translateY(-6px);
        box-shadow: var(--glass-glow), var(--glass-shadow);
        border-color: rgba(139, 92, 246, 0.45);
    }
}
.book-cover {
    position: relative;
    aspect-ratio: 3 / 4;
    background: linear-gradient(135deg, rgba(139,92,246,0.7), rgba(34,211,238,0.5));
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
}
.book-cover img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}
.book-cover .placeholder {
    color: #fff;
    opacity: 0.9;
    text-shadow: 0 2px 6px rgba(0, 0, 0, 0.35);
}
.book-cover .book-badge {
    position: absolute;
    top: 10px;
    left: 10px;
    padding: 4px 10px;
    border-radius: var(--radius-full);
    background: rgba(0,0,0,0.65);
    color: #fff;
    font-size: 0.7rem;
    font-weight: 600;
    letter-spacing: 0.02em;
    backdrop-filter: blur(4px);
}
.book-body {
    padding: 14px 16px 6px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    flex: 1 1 auto;
    min-width: 0;
}
.book-title {
    font-size: 1.02rem;
    font-weight: 700;
    margin: 0;
    color: var(--text-primary);
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    min-height: 2.6em;
    line-height: 1.3;
}
.book-author {
    color: var(--text-secondary);
    font-size: 0.88rem;
    margin: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.book-desc {
    color: var(--text-secondary);
    font-size: 0.82rem;
    margin: 4px 0 0;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
    line-height: 1.45;
    opacity: 0.85;
}
.book-meta {
    color: var(--text-secondary);
    font-size: 0.78rem;
    margin-top: auto;
    padding-top: 8px;
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    align-items: center;
}
.book-meta .dot { opacity: 0.5; }
.book-actions {
    display: flex;
    gap: 6px;
    padding: 8px 12px 14px;
    flex-wrap: wrap;
}
.book-actions .btn-small {
    flex: 1 1 auto;
    text-align: center;
    justify-content: center;
}

/* ---- Buttons small --------------------------------------------------- */
.btn-small {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    padding: 8px 12px;
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
    font-weight: 600;
    text-decoration: none;
    border: 1px solid var(--glass-border);
    background: var(--glass-bg-strong);
    color: var(--text-primary);
    cursor: pointer;
    font-family: inherit;
    transition: all var(--transition-fast);
    min-height: 36px;
}
.btn-small:hover {
    background: var(--yt-chip-hover);
    transform: translateY(-1px);
}
.btn-danger {
    color: var(--error-red);
    border-color: rgba(248, 113, 113, 0.4);
}
.btn-danger:hover {
    background: rgba(248, 113, 113, 0.12);
}

/* ---- Empty state ----------------------------------------------------- */
.empty-state {
    text-align: center;
    padding: 64px 20px;
    color: var(--text-secondary);
    background: var(--glass-bg);
    border: 1px dashed var(--glass-border);
    border-radius: var(--radius-lg);
}
.empty-icon {
    display: block;
    margin-bottom: 16px;
    opacity: 0.5;
}
.empty-state h2 {
    font-size: 1.2rem;
    margin: 0 0 8px;
    color: var(--text-primary);
}
.empty-state p {
    margin: 0 0 20px;
    max-width: 420px;
    margin-left: auto;
    margin-right: auto;
}

/* ---- Detail page ----------------------------------------------------- */
.book-detail-layout {
    display: grid;
    grid-template-columns: minmax(0, 260px) 1fr;
    gap: 28px;
    align-items: start;
}
.book-detail-cover {
    position: relative;
    aspect-ratio: 3 / 4;
    border-radius: var(--radius-lg);
    overflow: hidden;
    background: linear-gradient(135deg, rgba(139,92,246,0.7), rgba(34,211,238,0.5));
    box-shadow: var(--glass-shadow);
    border: 1px solid var(--glass-border);
}
.book-detail-cover img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}
.book-detail-cover .placeholder {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    opacity: 0.9;
    text-shadow: 0 2px 6px rgba(0, 0, 0, 0.35);
}
.book-detail-info h1 {
    font-size: 1.8rem;
    font-weight: 800;
    margin: 0 0 4px;
    line-height: 1.25;
}
.book-detail-author {
    color: var(--text-secondary);
    font-size: 1.05rem;
    margin: 0 0 16px;
}
.book-detail-desc {
    color: var(--text-primary);
    line-height: 1.7;
    white-space: pre-wrap;
    margin: 0 0 20px;
    opacity: 0.9;
}
.book-detail-meta {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 12px;
    margin: 20px 0;
}
.meta-card {
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-md);
    padding: 12px 14px;
}
.meta-card .label {
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-secondary);
    margin-bottom: 4px;
}
.meta-card .value {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text-primary);
    word-break: break-word;
}
.book-detail-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 20px;
}

/* ---- Reader ---------------------------------------------------------- */
.reader-hero {
    margin-bottom: 16px;
}
.reader-hero h1 {
    font-size: 1.5rem;
    font-weight: 700;
    margin: 0 0 4px;
}
.reader-hero p {
    color: var(--text-secondary);
    margin: 0;
}
.reader-toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
    margin-bottom: 16px;
    padding: 10px 12px;
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-md);
}
.reader-toolbar .spacer { flex: 1 1 auto; }
.reader-tool-btn {
    padding: 8px 12px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--glass-border);
    background: var(--glass-bg-strong);
    color: var(--text-primary);
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    font-family: inherit;
    min-height: 36px;
}
.reader-tool-btn:hover { background: var(--yt-chip-hover); }
.reader-layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 360px;
    gap: 20px;
    align-items: start;
}
.reader-viewer {
    background: var(--glass-bg);
    backdrop-filter: blur(var(--glass-blur));
    -webkit-backdrop-filter: blur(var(--glass-blur));
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-lg);
    padding: 16px;
    box-shadow: var(--glass-shadow);
    min-width: 0;
}
.reader-viewer iframe {
    width: 100%;
    height: 70vh;
    border: 0;
    border-radius: var(--radius-md);
    background: #fff;
    display: block;
}
.reader-viewer:fullscreen,
.reader-viewer:-webkit-full-screen {
    background: #000;
    padding: 0;
    border: 0;
    border-radius: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}
.reader-viewer:fullscreen iframe,
.reader-viewer:-webkit-full-screen iframe {
    height: 100vh;
    width: 100vw;
    border-radius: 0;
}
.book-text {
    max-height: 60vh;
    overflow: auto;
    padding: 16px;
    background: var(--bg-secondary);
    border-radius: var(--radius-md);
    margin-bottom: 12px;
    white-space: pre-wrap;
    line-height: 1.7;
    font-size: 1rem;
    user-select: text;
}
.reader-hint {
    color: var(--text-secondary);
    font-size: 0.85rem;
    margin: 0 0 12px;
}
.reader-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 12px;
}
.reader-panel {
    background: var(--glass-bg);
    backdrop-filter: blur(var(--glass-blur));
    -webkit-backdrop-filter: blur(var(--glass-blur));
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-lg);
    padding: 20px;
    box-shadow: var(--glass-shadow);
    position: sticky;
    top: 80px;
    max-height: calc(100vh - 100px);
    overflow: auto;
}
.reader-panel h2 {
    margin: 0 0 8px;
    font-size: 1.15rem;
}
.reader-panel .section-subtitle {
    color: var(--text-secondary);
    font-size: 0.85rem;
    margin: 0 0 14px;
}
.lang-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}
.translate-btn-row {
    display: flex;
    gap: 8px;
    margin: 12px 0;
    flex-wrap: wrap;
}
.translate-btn-row .btn { flex: 1 1 auto; justify-content: center; }
.reader-panel select,
.reader-panel textarea {
    background: var(--bg-secondary) !important;
    color: var(--text-primary) !important;
    border: 1px solid var(--glass-border) !important;
    width: 100%;
}
.reader-panel select option {
    background: var(--bg-secondary);
    color: var(--text-primary);
}
.reader-panel textarea { resize: vertical; min-height: 90px; }

/* ---- Upload / edit forms -------------------------------------------- */
.library-form-card {
    max-width: 720px;
    margin: 0 auto;
    padding: 24px;
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-lg);
    box-shadow: var(--glass-shadow);
}
.library-form-card h1 {
    font-size: 1.5rem;
    font-weight: 700;
    margin: 0 0 6px;
}
.library-form-card .subtitle {
    color: var(--text-secondary);
    margin: 0 0 20px;
    font-size: 0.95rem;
}
.library-form-card .auth-form {
    display: flex;
    flex-direction: column;
    gap: 16px;
}
.drop-zone {
    border: 2px dashed var(--glass-border);
    border-radius: var(--radius-md);
    padding: 24px 16px;
    text-align: center;
    color: var(--text-secondary);
    background: var(--bg-secondary);
    cursor: pointer;
    transition: border-color var(--transition-fast), background var(--transition-fast);
}
.drop-zone:hover, .drop-zone:focus {
    border-color: var(--accent-red);
    background: var(--glass-bg-strong);
}
.drop-zone input[type="file"] {
    display: block;
    width: 100%;
    margin-top: 8px;
}
.drop-zone .drop-icon {
    font-size: 2rem;
    display: block;
    margin-bottom: 6px;
    opacity: 0.7;
}
.form-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 8px;
}
.form-actions .btn { flex: 1 1 auto; justify-content: center; }

/* ---- Responsive ------------------------------------------------------ */
@media (max-width: 1024px) {
    .book-detail-layout {
        grid-template-columns: minmax(0, 220px) 1fr;
        gap: 20px;
    }
}
@media (max-width: 900px) {
    .reader-layout {
        grid-template-columns: 1fr;
    }
    .reader-panel {
        position: static;
        max-height: none;
    }
    .book-detail-layout {
        grid-template-columns: 1fr;
    }
    .book-detail-cover {
        max-width: 260px;
        margin: 0 auto;
    }
}
@media (max-width: 768px) {
    .library-hero { padding: 20px 18px; }
    .library-hero h1 { font-size: 1.6rem; }
    .library-grid {
        grid-template-columns: repeat(auto-fill, minmax(min(160px, 100%), 1fr));
        gap: 14px;
    }
    .book-title { font-size: 0.95rem; }
    .book-actions { padding: 6px 10px 12px; }
    .book-actions .btn-small { font-size: 0.8rem; padding: 7px 10px; }
    .book-detail-info h1 { font-size: 1.45rem; }
    .reader-viewer iframe { height: 55vh; }
    .book-text { max-height: 50vh; }
    .lang-row { grid-template-columns: 1fr; }
    .translate-btn-row .btn { flex: 1 1 100%; }
}
@media (max-width: 480px) {
    .library-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 10px;
    }
    .book-cover { aspect-ratio: 2 / 3; }
    .book-body { padding: 10px 10px 4px; }
    .book-title { font-size: 0.85rem; min-height: 2.4em; }
    .book-author { font-size: 0.78rem; }
    .book-desc { display: none; }
    .book-meta { font-size: 0.72rem; }
    .book-actions { flex-direction: column; }
    .book-actions .btn-small { width: 100%; }
    .library-toolbar { flex-direction: column; align-items: stretch; }
    .library-search { flex: 1 1 auto; }
    .library-sort select { width: 100%; }
    .library-form-card { padding: 18px 14px; }
    .reader-viewer { padding: 10px; }
    .reader-viewer iframe { height: 50vh; }
    .reader-toolbar { padding: 8px; }
}
@media (max-width: 360px) {
    .library-grid { grid-template-columns: 1fr; }
    .book-cover { aspect-ratio: 16 / 9; max-height: 180px; }
}