/* ===== VARIABLES & RESET ===== */
:root {
    --primary-color: #3b82f6;
    --primary-dark: #1d4ed8;
    --secondary-color: #8b5cf6;
    --bg-color: #ffffff;
    --bg-secondary: #f8fafc;
    --text-color: #1e293b;
    --text-secondary: #64748b;
    --border-color: #e2e8f0;
    --card-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    --hover-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
    --radius: 12px;
    --radius-sm: 8px;
    --transition: all 0.3s ease;
}

[data-theme="dark"] {
    --bg-color: #0f172a;
    --bg-secondary: #1e293b;
    --text-color: #f1f5f9;
    --text-secondary: #94a3b8;
    --border-color: #334155;
    --card-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.3);
    --hover-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.4);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    font-size: 16px;
    scroll-behavior: smooth;
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    line-height: 1.6;
    transition: var(--transition);
    padding-bottom: 80px;
    min-height: 100vh;
    overflow-x: hidden;
}

.container {
    max-width: 1280px;
    margin: 0 auto;
    padding: 0 1rem;
}

/* ===== LOADER ===== */
.loader-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--bg-color);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 9999;
    transition: opacity 0.3s ease;
}

.spinner {
    width: 50px;
    height: 50px;
    border: 3px solid var(--border-color);
    border-top-color: var(--primary-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* ===== HEADER & NAVBAR ===== */
.top-header {
    position: sticky;
    top: 0;
    background: var(--bg-color);
    backdrop-filter: blur(10px);
    z-index: 100;
    border-bottom: 1px solid var(--border-color);
    padding: 1rem 0;
}

.logo {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--primary-color);
    text-decoration: none;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.logo span {
    color: var(--secondary-color);
}

.bottom-navbar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--bg-color);
    border-top: 1px solid var(--border-color);
    display: flex;
    justify-content: space-around;
    padding: 0.75rem 0;
    z-index: 90;
    backdrop-filter: blur(10px);
}

.nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-decoration: none;
    color: var(--text-secondary);
    transition: var(--transition);
    padding: 0.5rem;
    border-radius: var(--radius-sm);
    min-width: 60px;
    position: relative;
    outline: none;
}

.nav-item.active {
    color: var(--primary-color);
    background: var(--bg-secondary);
}

.nav-item:focus-visible {
    outline: 2px solid var(--primary-color);
    outline-offset: 2px;
}

.nav-item i {
    font-size: 1.25rem;
    margin-bottom: 0.25rem;
    position: relative;
}

.nav-item span:not(.history-count):not(.bookmark-count) {
    font-size: 0.75rem;
    font-weight: 500;
}

.history-count,
.bookmark-count {
    position: absolute;
    top: 0;
    right: 0;
    background: var(--primary-color);
    color: white;
    font-size: 0.6rem;
    min-width: 16px;
    height: 16px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 2px;
    font-weight: bold;
    transform: translate(25%, -25%);
    z-index: 1;
}

/* ===== CARDS ===== */
.novel-card {
    background: var(--bg-secondary);
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: var(--card-shadow);
    transition: var(--transition);
    height: 100%;
    text-decoration: none;
    color: inherit;
    display: block;
    outline: none;
}

.novel-card:hover,
.novel-card:focus {
    transform: translateY(-4px);
    box-shadow: var(--hover-shadow);
}

.novel-card:focus-visible {
    outline: 2px solid var(--primary-color);
    outline-offset: 2px;
}

.novel-card-image {
    width: 100%;
    aspect-ratio: 2/3;
    object-fit: cover;
    display: block;
}

.novel-card-content {
    padding: 0.75rem;
}

.novel-card-title {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-color);
    margin-bottom: 0.25rem;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    height: 2.5rem;
    line-height: 1.25;
}

.novel-card-chapter {
    font-size: 0.75rem;
    color: var(--text-secondary);
    display: -webkit-box;
    -webkit-line-clamp: 1;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.novel-card-rating {
    font-size: 0.75rem;
    color: #f59e0b;
    margin-top: 0.25rem;
}

/* ===== GENRE CARD ===== */
.genre-card {
    background: var(--bg-secondary);
    border-radius: var(--radius);
    padding: 1.25rem;
    text-align: center;
    text-decoration: none;
    color: var(--text-color);
    transition: var(--transition);
    border: 1px solid var(--border-color);
    outline: none;
}

.genre-card:hover,
.genre-card:focus {
    background: var(--primary-color);
    color: white;
    border-color: var(--primary-color);
    transform: translateY(-2px);
}

.genre-card:focus-visible {
    outline: 2px solid var(--primary-color);
    outline-offset: 2px;
}

.genre-name {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 0.25rem;
}

.genre-count {
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.genre-card:hover .genre-count,
.genre-card:focus .genre-count {
    color: rgba(255, 255, 255, 0.9);
}

/* ===== SLIDER/CAROUSEL ===== */
.slider-container {
    position: relative;
    border-radius: var(--radius);
    overflow: hidden;
    margin: 1rem 0;
    touch-action: pan-y;
}

.slider {
    display: flex;
    transition: transform 0.5s ease;
    height: 300px;
}

@media (max-width: 768px) {
    .slider {
        height: 200px;
    }
}

.slide {
    min-width: 100%;
    position: relative;
    flex-shrink: 0;
}

.slide-image {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.slide-overlay {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background: linear-gradient(transparent, rgba(0, 0, 0, 0.8));
    padding: 1rem;
    color: white;
    pointer-events: none;
}

.slide-title {
    font-size: 1.25rem;
    font-weight: 700;
    margin-bottom: 0.25rem;
    display: -webkit-box;
    -webkit-line-clamp: 1;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.slide-chapter {
    font-size: 0.875rem;
    opacity: 0.9;
}

.slider-nav {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    background: rgba(0, 0, 0, 0.5);
    color: white;
    border: none;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: var(--transition);
    z-index: 2;
    outline: none;
}

.slider-nav:hover {
    background: rgba(0, 0, 0, 0.8);
}

.slider-nav:focus-visible {
    outline: 2px solid white;
    outline-offset: 2px;
}

.slider-prev {
    left: 1rem;
}

.slider-next {
    right: 1rem;
}

.slider-dots {
    position: absolute;
    bottom: 1rem;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 0.5rem;
    z-index: 2;
}

.slider-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.5);
    border: none;
    cursor: pointer;
    transition: var(--transition);
    padding: 0;
    outline: none;
}

.slider-dot.active {
    background: white;
    transform: scale(1.2);
}

.slider-dot:focus-visible {
    outline: 2px solid white;
    outline-offset: 2px;
}

/* ===== HISTORY CARD ===== */
.history-card {
    background: var(--bg-secondary);
    border-radius: var(--radius-sm);
    padding: 0.75rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    text-decoration: none;
    color: var(--text-color);
    transition: var(--transition);
    border: 1px solid var(--border-color);
    outline: none;
}

.history-card:hover,
.history-card:focus {
    background: var(--primary-color);
    color: white;
    border-color: var(--primary-color);
    transform: translateY(-2px);
}

.history-card:focus-visible {
    outline: 2px solid var(--primary-color);
    outline-offset: 2px;
}

.history-card:hover .history-chapter,
.history-card:hover .history-date,
.history-card:focus .history-chapter,
.history-card:focus .history-date {
    color: rgba(255, 255, 255, 0.9);
}

.history-image {
    width: 50px;
    height: 50px;
    object-fit: cover;
    border-radius: 6px;
    flex-shrink: 0;
}

.history-content {
    flex: 1;
    min-width: 0;
}

.history-title {
    font-size: 0.875rem;
    font-weight: 600;
    margin-bottom: 0.25rem;
    display: -webkit-box;
    -webkit-line-clamp: 1;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.history-chapter {
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin-bottom: 0.125rem;
    display: -webkit-box;
    -webkit-line-clamp: 1;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.history-date {
    font-size: 0.7rem;
    color: var(--text-secondary);
    opacity: 0.8;
}

/* ===== BUTTONS & FORMS ===== */
.btn {
    padding: 0.5rem 1rem;
    border-radius: var(--radius-sm);
    border: none;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    font-size: 0.875rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    text-decoration: none;
    outline: none;
}

.btn-primary {
    background: var(--primary-color);
    color: white;
}

.btn-primary:hover,
.btn-primary:focus {
    background: var(--primary-dark);
    transform: translateY(-2px);
}

.btn-primary:focus-visible {
    outline: 2px solid var(--primary-dark);
    outline-offset: 2px;
}

.btn-secondary {
    background: var(--bg-secondary);
    color: var(--text-color);
    border: 1px solid var(--border-color);
}

.btn-secondary:hover,
.btn-secondary:focus {
    background: var(--border-color);
}

.btn-secondary:focus-visible {
    outline: 2px solid var(--primary-color);
    outline-offset: 2px;
}

.search-form {
    position: relative;
    margin: 1rem 0;
}

.search-input {
    width: 100%;
    padding: 0.75rem 1rem 0.75rem 3rem;
    border-radius: var(--radius);
    border: 1px solid var(--border-color);
    background: var(--bg-secondary);
    color: var(--text-color);
    font-size: 1rem;
    transition: var(--transition);
    -webkit-appearance: none;
    appearance: none;
}

.search-input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.search-icon {
    position: absolute;
    left: 1rem;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-secondary);
    pointer-events: none;
}

/* ===== SECTION STYLES ===== */
.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin: 2rem 0 1rem;
    padding-bottom: 0.5rem;
    border-bottom: 2px solid var(--primary-color);
}

.section-title {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--text-color);
}

.section-link {
    font-size: 0.875rem;
    color: var(--primary-color);
    text-decoration: none;
    font-weight: 600;
    transition: var(--transition);
    outline: none;
}

.section-link:hover {
    text-decoration: underline;
}

.section-link:focus-visible {
    outline: 2px solid var(--primary-color);
    outline-offset: 2px;
    border-radius: 2px;
}

.grid {
    display: grid;
    gap: 1rem;
}

.grid-2 {
    grid-template-columns: repeat(2, 1fr);
}

.grid-3 {
    grid-template-columns: repeat(3, 1fr);
}

.grid-4 {
    grid-template-columns: repeat(4, 1fr);
}

@media (max-width: 768px) {
    .grid-3, .grid-4 {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 480px) {
    .grid-2, .grid-3, .grid-4 {
        grid-template-columns: 1fr;
    }
}

/* ===== BOOKMARKS GRID ===== */
.bookmarks-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 1rem;
    margin-top: 1rem;
}

@media (max-width: 768px) {
    .bookmarks-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 480px) {
    .bookmarks-grid {
        grid-template-columns: 1fr;
    }
}

/* ===== TOAST NOTIFICATION ===== */
.toast-notification {
    position: fixed;
    bottom: 100px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--primary-color);
    color: white;
    padding: 0.75rem 1.5rem;
    border-radius: var(--radius);
    box-shadow: var(--hover-shadow);
    z-index: 9999;
    animation: slideUp 0.3s ease;
    max-width: 90%;
    text-align: center;
    font-weight: 500;
    pointer-events: none;
}

@keyframes slideUp {
    from { 
        transform: translate(-50%, 100%); 
        opacity: 0; 
    }
    to { 
        transform: translate(-50%, 0); 
        opacity: 1; 
    }
}

@keyframes slideDown {
    from { 
        transform: translate(-50%, 0); 
        opacity: 1; 
    }
    to { 
        transform: translate(-50%, 100%); 
        opacity: 0; 
    }
}

/* ===== EMPTY STATE ===== */
.empty-state {
    text-align: center;
    padding: 2rem;
    color: var(--text-secondary);
}

.empty-state i {
    font-size: 2rem;
    margin-bottom: 1rem;
    opacity: 0.5;
}

/* ===== UTILITIES ===== */
.text-center { text-align: center; }
.text-right { text-align: right; }
.mt-1 { margin-top: 0.25rem; }
.mt-2 { margin-top: 0.5rem; }
.mt-3 { margin-top: 1rem; }
.mt-4 { margin-top: 1.5rem; }
.mb-1 { margin-bottom: 0.25rem; }
.mb-2 { margin-bottom: 0.5rem; }
.mb-3 { margin-bottom: 1rem; }
.mb-4 { margin-bottom: 1.5rem; }
.p-1 { padding: 0.25rem; }
.p-2 { padding: 0.5rem; }
.p-3 { padding: 1rem; }
.p-4 { padding: 1.5rem; }
.hidden { display: none !important; }
.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.fade-in {
    animation: fadeIn 0.5s ease;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ===== SKELETON LOADING ===== */
.skeleton {
    background: linear-gradient(
        90deg,
        var(--border-color) 25%,
        color-mix(in srgb, var(--border-color) 50%, transparent) 50%,
        var(--border-color) 75%
    );
    background-size: 200% 100%;
    animation: skeleton-loading 1.5s ease-in-out infinite;
    border-radius: var(--radius);
}

@keyframes skeleton-loading {
    0% {
        background-position: 200% 0;
    }
    100% {
        background-position: -200% 0;
    }
}

/* Skeleton untuk berbagai komponen */
.skeleton-text {
    height: 1em;
    width: 100%;
    border-radius: 4px;
}

.skeleton-image {
    width: 100%;
    aspect-ratio: 2/3;
    border-radius: var(--radius);
}

.skeleton-card {
    height: 300px;
    border-radius: var(--radius);
}

/* Smooth transition untuk skeleton */
.skeleton.fade-out {
    opacity: 0;
    transition: opacity 0.3s ease;
}

/* ===== CHAPTER NAVIGATION ===== */
.chapter-navigation {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem;
    background: var(--bg-secondary);
    border-radius: var(--radius);
    margin: 2rem 0;
    gap: 1rem;
}

.chapter-navigation > * {
    flex: 1;
    text-align: center;
}

.chapter-navigation > :first-child {
    text-align: left;
}

.chapter-navigation > :last-child {
    text-align: right;
}

/* ===== READER SETTINGS ===== */
.reader-settings {
    position: fixed;
    bottom: 120px;
    right: 1rem;
    z-index: 10;
}

.settings-btn {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    background: var(--primary-color);
    color: white;
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: var(--card-shadow);
    transition: var(--transition);
    outline: none;
}

.settings-btn:hover,
.settings-btn:focus {
    transform: scale(1.1);
}

.settings-btn:focus-visible {
    outline: 2px solid white;
    outline-offset: 2px;
}

.settings-panel {
    position: absolute;
    bottom: 60px;
    right: 0;
    background: var(--bg-color);
    border-radius: var(--radius);
    padding: 1rem;
    box-shadow: var(--hover-shadow);
    min-width: 200px;
    display: none;
    z-index: 11;
}

.settings-panel.show {
    display: block;
    animation: fadeIn 0.3s ease;
}

.setting-item {
    margin-bottom: 1rem;
}

.setting-item:last-child {
    margin-bottom: 0;
}

.setting-label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 500;
}

.font-size-controls {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.font-size-btn {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    outline: none;
}

.font-size-btn.active {
    background: var(--primary-color);
    color: white;
    border-color: var(--primary-color);
}

.font-size-btn:focus-visible {
    outline: 2px solid var(--primary-color);
    outline-offset: 2px;
}

.theme-select {
    display: flex;
    gap: 0.5rem;
}

.theme-option {
    flex: 1;
    padding: 0.5rem;
    border-radius: var(--radius-sm);
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    text-align: center;
    cursor: pointer;
    outline: none;
}

.theme-option.active {
    background: var(--primary-color);
    color: white;
    border-color: var(--primary-color);
}

.theme-option:focus-visible {
    outline: 2px solid var(--primary-color);
    outline-offset: 2px;
}

/* ===== PROGRESS BAR ===== */
.progress-bar {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 3px;
    background: var(--border-color);
    z-index: 100;
}

.progress-fill {
    height: 100%;
    background: var(--primary-color);
    width: 0%;
    transition: width 0.3s ease;
}

/* ===== ACCESSIBILITY IMPROVEMENTS ===== */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}

/* ===== PRINT STYLES ===== */
@media print {
    .bottom-navbar,
    .top-header,
    .reader-settings,
    .progress-bar {
        display: none !important;
    }
    
    body {
        padding-bottom: 0;
    }
    
    .chapter-content {
        max-width: none;
        font-size: 12pt;
    }
}

/* ===== HIGH CONTRAST MODE SUPPORT ===== */
@media (prefers-contrast: high) {
    :root {
        --primary-color: #0056b3;
        --primary-dark: #003d82;
        --secondary-color: #6a0dad;
        --border-color: #000000;
    }
    
    [data-theme="dark"] {
        --border-color: #ffffff;
    }
}

/* ===== DARK MODE AUTO DETECTION ===== */
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --bg-color: #0f172a;
        --bg-secondary: #1e293b;
        --text-color: #f1f5f9;
        --text-secondary: #94a3b8;
        --border-color: #334155;
        --card-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.3);
        --hover-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.4);
    }
}

/* ===== SCROLLBAR STYLING ===== */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: var(--bg-secondary);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--primary-color);
}

/* ===== IMAGE LOADING STATES ===== */
img:not([src]),
img[src=""] {
    opacity: 0;
}

img.loading {
    opacity: 0;
    transition: opacity 0.3s ease;
}

img.loaded {
    opacity: 1;
}

/* ===== FOCUS MANAGEMENT ===== */
.skip-to-content {
    position: absolute;
    top: -40px;
    left: 0;
    background: var(--primary-color);
    color: white;
    padding: 0.5rem 1rem;
    border-radius: var(--radius-sm);
    text-decoration: none;
    z-index: 999;
}

.skip-to-content:focus {
    top: 1rem;
    left: 1rem;
}
