/* Design System & Reset */
:root {
    --bg-primary: var(--tg-theme-bg-color, #090c15);
    --bg-secondary: var(--tg-theme-secondary-bg-color, #111625);
    --bg-tertiary: var(--tg-theme-section-bg-color, #192035);
    --accent-indigo: var(--tg-theme-button-color, #6366f1);
    --accent-purple: var(--tg-theme-link-color, #8b5cf6);
    --accent-pink: #ec4899;
    --accent-gradient: linear-gradient(135deg, var(--accent-indigo) 0%, var(--accent-purple) 60%, var(--accent-pink) 100%);
    --text-primary: var(--tg-theme-text-color, #f3f4f6);
    --text-muted: var(--tg-theme-hint-color, #9ca3af);
    --text-dark: var(--tg-theme-subtitle-text-color, #6b7280);
    --border-color: var(--tg-theme-section-separator-color, rgba(255, 255, 255, 0.08));
    --glass-bg: rgba(17, 22, 37, 0.72);
    --glass-blur: blur(16px);
    --card-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
    --accent-glow: 0 0 20px rgba(99, 102, 241, 0.25);
    --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    --font-display: 'Outfit', var(--font-sans);
}

body.dark {
    --glass-bg: rgba(17, 22, 37, 0.72);
    --border-color: rgba(255, 255, 255, 0.08);
    --card-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
}

body.light {
    --glass-bg: rgba(255, 255, 255, 0.65);
    --border-color: rgba(0, 0, 0, 0.08);
    --card-shadow: 0 8px 24px rgba(0, 0, 0, 0.08);
    --accent-glow: 0 0 20px rgba(99, 102, 241, 0.15);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
}

body {
    background-color: var(--bg-primary);
    color: var(--text-primary);
    font-family: var(--font-sans);
    font-size: 15px;
    line-height: 1.5;
    overflow-x: hidden;
    height: 100vh;
    height: -webkit-fill-available;
    display: flex;
    flex-direction: column;
}

html {
    height: -webkit-fill-available;
}

/* App Container */
#app {
    display: flex;
    flex-direction: column;
    height: 100%;
    position: relative;
    padding-bottom: calc(65px + env(safe-area-inset-bottom));
}

/* Scrollbars */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}
::-webkit-scrollbar-track {
    background: var(--bg-primary);
}
::-webkit-scrollbar-thumb {
    background: var(--bg-tertiary);
    border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover {
    background: var(--accent-indigo);
}

/* Typography & Headers */
h1, h2, h3, h4 {
    font-family: var(--font-display);
    font-weight: 700;
}

/* Main Content Area */
#main-content {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    padding-top: calc(16px + env(safe-area-inset-top));
}

/* Bottom Navigation Bar */
#bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: calc(60px + env(safe-area-inset-bottom));
    background: var(--glass-bg);
    backdrop-filter: var(--glass-blur);
    -webkit-backdrop-filter: var(--glass-blur);
    border-top: 1px solid var(--border-color);
    display: flex;
    justify-content: space-around;
    align-items: center;
    padding-bottom: env(safe-area-inset-bottom);
    z-index: 100;
    box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.3);
}

.nav-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    font-size: 11px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    flex: 1;
    height: 100%;
    justify-content: center;
}

.nav-btn:hover, .nav-btn.active {
    color: var(--accent-indigo);
}

.nav-icon {
    width: 22px;
    height: 22px;
    stroke: currentColor;
    fill: none;
    transition: transform 0.3s ease;
}

.nav-btn.active .nav-icon {
    transform: translateY(-2px);
    filter: drop-shadow(0 2px 8px rgba(99, 102, 241, 0.5));
}

/* Catalog View styles */
.header-section {
    margin-bottom: 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.brand-title {
    font-size: 24px;
    background: var(--accent-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    font-weight: 800;
    letter-spacing: -0.5px;
}

.search-box {
    position: relative;
    margin-bottom: 16px;
}

.search-input {
    width: 100%;
    padding: 12px 16px 12px 42px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    color: var(--text-primary);
    font-family: var(--font-sans);
    font-size: 14px;
    outline: none;
    transition: all 0.3s ease;
}

.search-input:focus {
    border-color: var(--accent-indigo);
    box-shadow: var(--accent-glow);
}

.search-icon {
    position: absolute;
    left: 14px;
    top: 50%;
    transform: translateY(-50%);
    width: 18px;
    height: 18px;
    color: var(--text-muted);
    pointer-events: none;
}

/* Category Pills */
.categories-scroll {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    padding-bottom: 12px;
    margin-bottom: 16px;
    scrollbar-width: none;
}

.categories-scroll::-webkit-scrollbar {
    display: none;
}

.category-pill {
    padding: 8px 16px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 20px;
    color: var(--text-muted);
    font-size: 13px;
    font-weight: 500;
    white-space: nowrap;
    cursor: pointer;
    transition: all 0.2s ease;
}

.category-pill.active {
    background: var(--accent-gradient);
    color: white;
    border-color: transparent;
    box-shadow: var(--accent-glow);
}

/* Manga Grid */
.manga-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 16px;
    padding-bottom: 20px;
}

@media(min-width: 480px) {
    .manga-grid {
        grid-template-columns: repeat(3, 1fr);
    }
}

@media(min-width: 768px) {
    .manga-grid {
        grid-template-columns: repeat(4, 1fr);
    }
}

.manga-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 14px;
    overflow: hidden;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    flex-direction: column;
    box-shadow: var(--card-shadow);
}

.manga-card:hover {
    transform: translateY(-4px);
    border-color: var(--accent-indigo);
    box-shadow: var(--accent-glow);
}

.manga-cover-wrap {
    aspect-ratio: 2/3;
    overflow: hidden;
    position: relative;
    background: var(--bg-tertiary);
}

.manga-cover {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.5s ease;
}

.manga-card:hover .manga-cover {
    transform: scale(1.05);
}

.manga-badge {
    position: absolute;
    top: 8px;
    left: 8px;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(4px);
    padding: 2px 6px;
    border-radius: 6px;
    font-size: 10px;
    font-weight: 600;
    color: #fcd34d;
    display: flex;
    align-items: center;
    gap: 2px;
}

.manga-card-info {
    padding: 10px;
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
}

.manga-card-title {
    font-size: 13px;
    font-weight: 600;
    line-height: 1.3;
    margin-bottom: 6px;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    height: 34px;
}

.manga-card-meta {
    font-size: 11px;
    color: var(--text-muted);
}

/* Manga Profile View */
.back-row {
    margin-bottom: 16px;
}

.back-btn {
    background: none;
    border: none;
    color: var(--text-primary);
    font-size: 14px;
    font-weight: 500;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
}

.profile-header-banner {
    position: relative;
    margin: -16px -16px 20px -16px;
    height: 200px;
    overflow: hidden;
    display: flex;
    align-items: flex-end;
    padding: 20px;
}

.profile-banner-bg {
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    background-size: cover;
    background-position: center;
    filter: blur(15px) brightness(0.4);
    transform: scale(1.1);
    z-index: 1;
}

.profile-header-content {
    position: relative;
    z-index: 2;
    display: flex;
    gap: 16px;
    width: 100%;
}

.profile-cover-wrap {
    width: 90px;
    aspect-ratio: 2/3;
    border-radius: 8px;
    overflow: hidden;
    border: 2px solid white;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
    background: var(--bg-tertiary);
}

.profile-cover {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.profile-main-info {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
}

.profile-title {
    font-size: 20px;
    font-weight: 800;
    margin-bottom: 6px;
    line-height: 1.2;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.6);
}

.profile-rating {
    font-size: 13px;
    color: #fcd34d;
    display: flex;
    align-items: center;
    gap: 4px;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.6);
}

/* Actions Row */
.action-buttons {
    display: flex;
    gap: 10px;
    margin-bottom: 20px;
}

.btn-primary {
    flex: 1;
    background: var(--accent-gradient);
    border: none;
    border-radius: 10px;
    color: white;
    padding: 12px;
    font-weight: 600;
    font-size: 14px;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: var(--accent-glow);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.btn-primary:active {
    transform: scale(0.98);
    opacity: 0.9;
}

.btn-secondary {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    color: var(--text-primary);
    padding: 12px;
    font-weight: 600;
    font-size: 14px;
    cursor: pointer;
    transition: all 0.2s ease;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.btn-secondary.subscribed {
    background: rgba(139, 92, 246, 0.15);
    border-color: var(--accent-purple);
    color: var(--accent-purple);
}

.btn-icon-only {
    padding: 12px;
}

/* Description Block */
.profile-section {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 16px;
    margin-bottom: 20px;
}

.section-title {
    font-size: 15px;
    margin-bottom: 10px;
    color: var(--text-primary);
}

.description-text {
    font-size: 13px;
    color: var(--text-muted);
    line-height: 1.6;
}

/* Source Tabs */
.sources-tab-row {
    display: flex;
    border-bottom: 1px solid var(--border-color);
    margin-bottom: 12px;
}

.source-tab {
    padding: 10px 16px;
    color: var(--text-muted);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    border-bottom: 2px solid transparent;
    transition: all 0.2s ease;
}

.source-tab.active {
    color: var(--accent-indigo);
    border-bottom-color: var(--accent-indigo);
}

/* Chapters List */
.chapters-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.chapter-item {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    padding: 12px 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: pointer;
    transition: all 0.2s ease;
}

.chapter-item:hover {
    border-color: var(--accent-indigo);
    background: var(--bg-tertiary);
}

.chapter-item.read {
    opacity: 0.6;
}

.chapter-info {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.chapter-num {
    font-weight: 600;
    font-size: 14px;
}

.chapter-date {
    font-size: 11px;
    color: var(--text-dark);
}

.read-badge {
    font-size: 10px;
    background: rgba(99, 102, 241, 0.15);
    color: var(--accent-indigo);
    padding: 2px 6px;
    border-radius: 4px;
    font-weight: 600;
}

/* Fullscreen Immersive Reader Overlay */
#reader-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background-color: #05070a;
    z-index: 200;
    display: flex;
    flex-direction: column;
    transition: opacity 0.3s ease;
}

#reader-overlay.hidden {
    display: none;
    opacity: 0;
    pointer-events: none;
}

#reader-header, #reader-footer {
    position: fixed;
    left: 0; right: 0;
    background: rgba(5, 7, 10, 0.9);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border-color: rgba(255, 255, 255, 0.05);
    z-index: 210;
    transition: transform 0.3s ease;
}

#reader-header {
    top: 0;
    height: calc(55px + env(safe-area-inset-top));
    padding-top: env(safe-area-inset-top);
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding-left: 10px;
    padding-right: 10px;
}

#reader-header.hide-controls {
    transform: translateY(-100%);
}

#reader-title-container {
    flex: 1;
    text-align: center;
    padding: 0 10px;
    overflow: hidden;
}

#reader-manga-title {
    font-size: 14px;
    font-weight: 700;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

#reader-chapter-title {
    font-size: 11px;
    color: var(--text-muted);
}

.icon-btn {
    background: none;
    border: none;
    color: var(--text-primary);
    width: 38px;
    height: 38px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}

.icon-btn:active {
    background: rgba(255, 255, 255, 0.1);
}

.btn-icon {
    width: 20px;
    height: 20px;
    stroke: currentColor;
    fill: none;
}

/* Reader Scroll Area */
#reader-pages-container {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    scroll-behavior: smooth;
    padding-top: calc(55px + env(safe-area-inset-top));
    padding-bottom: calc(50px + env(safe-area-inset-bottom));
    display: flex;
    flex-direction: column;
    align-items: center;
}

.reader-page-img {
    width: 100%;
    max-width: 768px;
    height: auto;
    display: block;
    margin-bottom: 0;
    background: #0d1117;
    object-fit: contain;
}

.reader-page-wrapper {
    position: relative;
    width: 100%;
    max-width: 768px;
    display: flex;
    flex-direction: column;
    align-items: center;
}

/* Reader Footer controls */
#reader-footer {
    bottom: 0;
    height: calc(50px + env(safe-area-inset-bottom));
    padding-bottom: env(safe-area-inset-bottom);
    border-top: 1px solid rgba(255, 255, 255, 0.05);
    display: flex;
    flex-direction: column;
    justify-content: space-between;
}

#reader-footer.hide-controls {
    transform: translateY(100%);
}

.progress-bar-container {
    width: 100%;
    height: 3px;
    background: rgba(255, 255, 255, 0.1);
}

#reader-progress-bar {
    height: 100%;
    background: var(--accent-gradient);
    transition: width 0.1s ease;
}

.reader-nav-row {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
}

.text-btn {
    background: none;
    border: none;
    color: var(--text-primary);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    padding: 6px 12px;
    border-radius: 6px;
}

.text-btn:active {
    background: rgba(255, 255, 255, 0.05);
}

#reader-page-indicator {
    font-size: 12px;
    color: var(--text-muted);
}

/* Skeleton Screens & Loading states */
.skeleton-card {
    background: linear-gradient(90deg, rgba(25, 32, 53, 0.45) 25%, rgba(37, 47, 77, 0.75) 50%, rgba(25, 32, 53, 0.45) 75%);
    background-size: 200% 100%;
    animation: shimmer 1.6s infinite linear;
    border: 1px solid var(--border-color);
    border-radius: 14px;
    overflow: hidden;
    height: 250px;
    display: flex;
    flex-direction: column;
}

.skeleton-cover {
    flex: 2;
    background: linear-gradient(90deg, rgba(25, 32, 53, 0.4) 25%, rgba(37, 47, 77, 0.6) 50%, rgba(25, 32, 53, 0.4) 75%);
    background-size: 200% 100%;
    animation: shimmer 1.6s infinite linear;
}

.skeleton-text {
    margin: 10px;
    height: 12px;
    background: linear-gradient(90deg, rgba(25, 32, 53, 0.4) 25%, rgba(37, 47, 77, 0.6) 50%, rgba(25, 32, 53, 0.4) 75%);
    background-size: 200% 100%;
    animation: shimmer 1.6s infinite linear;
    border-radius: 4px;
}

.skeleton-text.short {
    width: 60%;
}

@keyframes shimmer {
    0% { background-position: -200% 0; }
    100% { background-position: 200% 0; }
}

/* Alert Notification Banner */
.error-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px 20px;
    text-align: center;
    color: var(--text-muted);
}

.error-icon {
    width: 48px;
    height: 48px;
    color: var(--accent-pink);
    margin-bottom: 16px;
}

.error-title {
    font-size: 16px;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 8px;
}

.error-text {
    font-size: 13px;
}

/* Genres and Tags layout */
.genres-list {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 4px;
    margin-bottom: 12px;
}

.genre-tag {
    font-size: 11px;
    font-weight: 500;
    padding: 4px 10px;
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 12px;
    color: var(--text-muted);
    transition: all 0.2s ease;
}

.genre-tag:hover {
    background: rgba(99, 102, 241, 0.15);
    border-color: rgba(99, 102, 241, 0.3);
    color: var(--accent-indigo);
}

/* End of Chapter Navigation Buttons */
.reader-end-actions {
    width: 100%;
    max-width: 768px;
    padding: 60px 16px 80px 16px;
    background: #05070a;
    display: flex;
    flex-direction: column;
    align-items: center;
    border-top: 1px solid rgba(255, 255, 255, 0.05);
}

.reader-actions-row {
    display: flex;
    flex-direction: column;
    gap: 12px;
    width: 100%;
    max-width: 320px;
}

@media(min-width: 480px) {
    .reader-actions-row {
        flex-direction: row;
        max-width: 500px;
    }
    .reader-actions-row button {
        flex: 1;
    }
}

.reader-end-actions button {
    padding: 14px 20px;
    font-size: 13px;
    font-weight: 600;
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.2s ease;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.reader-end-actions .btn-success {
    background: linear-gradient(135deg, #10b981 0%, #059669 100%);
    border: none;
    color: white;
    box-shadow: 0 4px 12px rgba(16, 185, 129, 0.2);
}

.reader-end-actions .btn-success:active {
    transform: scale(0.98);
    opacity: 0.9;
}

/* Toggle Switch & Segment Controls */
.switch-container {
    position: relative;
    display: inline-block;
    width: 44px;
    height: 24px;
}

.switch-container input {
    opacity: 0;
    width: 0;
    height: 0;
}

.switch-slider {
    position: absolute;
    cursor: pointer;
    top: 0; left: 0; right: 0; bottom: 0;
    background-color: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    transition: .3s cubic-bezier(0.4, 0, 0.2, 1);
    border-radius: 24px;
}

.switch-slider:before {
    position: absolute;
    content: "";
    height: 16px;
    width: 16px;
    left: 3px;
    bottom: 3px;
    background-color: var(--text-muted);
    transition: .3s cubic-bezier(0.4, 0, 0.2, 1);
    border-radius: 50%;
}

.switch-container input:checked + .switch-slider {
    background: var(--accent-gradient);
    border-color: transparent;
    box-shadow: var(--accent-glow);
}

.switch-container input:checked + .switch-slider:before {
    transform: translateX(20px);
    background-color: white;
}

.segment-control {
    display: flex;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 2px;
}

.segment-btn {
    background: none;
    border: none;
    padding: 6px 12px;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-muted);
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.segment-btn.active {
    background: var(--accent-indigo);
    color: white;
    box-shadow: 0 2px 8px rgba(99, 102, 241, 0.4);
}

/* Metadata Grid styling */
.manga-metadata-grid .metadata-item {
    display: flex;
    flex-direction: column;
}

.hidden {
    display: none !important;
}

/* Background Spheres for Glassmorphism */
.bg-sphere {
    position: fixed;
    border-radius: 50%;
    filter: blur(80px);
    opacity: 0.14;
    z-index: -1;
    pointer-events: none;
    animation: float-spheres 25s infinite alternate ease-in-out;
}

body.light .bg-sphere {
    opacity: 0.06;
}

.sphere-1 {
    width: 260px;
    height: 260px;
    background: var(--accent-indigo);
    top: 15%;
    left: -60px;
}

.sphere-2 {
    width: 320px;
    height: 320px;
    background: var(--accent-purple);
    bottom: 25%;
    right: -100px;
    animation-delay: -7s;
    animation-duration: 32s;
}

@keyframes float-spheres {
    0% {
        transform: translate(0, 0) scale(1);
    }
    50% {
        transform: translate(30px, -45px) scale(1.1);
    }
    100% {
        transform: translate(-20px, 20px) scale(0.95);
    }
}

/* Page fade-in transition */
.page-fade-in {
    animation: fadeInUp 0.38s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(12px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Catalog Filter and Sort styling */
.filter-row {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: 8px;
    margin-bottom: 16px;
    padding: 0 4px;
}

.filter-label {
    font-size: 12px;
    color: var(--text-muted);
    font-weight: 500;
}

.sort-select {
    background: var(--bg-secondary);
    backdrop-filter: var(--glass-blur);
    -webkit-backdrop-filter: var(--glass-blur);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    color: var(--text-primary);
    padding: 6px 12px;
    font-size: 12px;
    font-weight: 600;
    outline: none;
    cursor: pointer;
    transition: all 0.25s ease;
}

.sort-select:focus {
    border-color: var(--accent-indigo);
    box-shadow: var(--accent-glow);
}

/* Icon Button variations */
.btn-icon-only {
    width: 45px;
    height: 45px;
    padding: 0 !important;
    flex: 0 0 45px !important;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}
