:root {
    --font: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    --header-h: 60px;
    --radius: 8px;
    --transition: 0.2s ease;
}

[data-theme="dark"] {
    --bg-1: #0a0a0a;
    --bg-2: #141414;
    --bg-3: #1a1a1a;
    --bg-4: #242424;
    --border: #2a2a2a;
    --border-hover: #3a3a3a;
    --text-1: #fafafa;
    --text-2: #a0a0a0;
    --text-3: #666666;
    --accent: #3b82f6;
    --accent-hover: #2563eb;
    --accent-soft: rgba(59, 130, 246, 0.15);
    --card-bg: #141414;
    --card-hover: #1e1e1e;
    --highlight: #fbbf24;
}

[data-theme="light"] {
    --bg-1: #fafafa;
    --bg-2: #f0f0f0;
    --bg-3: #e8e8e8;
    --bg-4: #e0e0e0;
    --border: #d4d4d4;
    --border-hover: #a3a3a3;
    --text-1: #0a0a0a;
    --text-2: #525252;
    --text-3: #737373;
    --accent: #2563eb;
    --accent-hover: #1d4ed8;
    --accent-soft: rgba(37, 99, 235, 0.1);
    --card-bg: #ffffff;
    --card-hover: #f5f5f5;
    --highlight: #f59e0b;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    font-size: 16px;
    scroll-behavior: smooth;
}

body {
    font-family: var(--font);
    background: var(--bg-1);
    color: var(--text-1);
    line-height: 1.6;
    min-height: 100vh;
    transition: background var(--transition), color var(--transition);
}

.header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--header-h);
    background: var(--bg-2);
    border-bottom: 1px solid var(--border);
    z-index: 100;
}

.header-inner {
    max-width: 1200px;
    height: 100%;
    margin: 0 auto;
    padding: 0 20px;
    display: flex;
    align-items: center;
    gap: 20px;
}

.brand {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 700;
    font-size: 18px;
    color: var(--text-1);
    text-decoration: none;
    flex-shrink: 0;
}

.brand svg {
    color: var(--accent);
}

.header-nav {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
    overflow: hidden;
}

#storyPathNav {
    font-size: 13px;
    color: var(--text-3);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

#chapterTitleNav {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-1);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

#storyPathNav:not(:empty)::after {
    content: " / ";
    color: var(--text-3);
}

.header-actions {
    display: flex;
    gap: 8px;
    flex-shrink: 0;
}

.header-nav-buttons {
    display: none;
    gap: 8px;
}

.header-tools {
    display: flex;
    gap: 8px;
}

body.nav-in-header .header-nav-buttons {
    display: flex;
}

body.nav-in-header .header-tools {
    display: none;
}

.btn-icon {
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg-3);
    color: var(--text-2);
    cursor: pointer;
    transition: all var(--transition);
}

.btn-icon:hover {
    background: var(--bg-4);
    border-color: var(--border-hover);
    color: var(--text-1);
}

[data-theme="dark"] .icon-sun { display: block; }
[data-theme="dark"] .icon-moon { display: none; }
[data-theme="light"] .icon-sun { display: none; }
[data-theme="light"] .icon-moon { display: block; }

.search-bar {
    position: fixed;
    top: var(--header-h);
    left: 0;
    right: 0;
    background: var(--bg-2);
    border-bottom: 1px solid var(--border);
    padding: 12px 20px;
    z-index: 99;
    display: none;
}

.search-bar.open {
    display: block;
}

.search-bar-inner {
    max-width: 600px;
    margin: 0 auto;
    display: flex;
    gap: 10px;
}

.search {
    flex: 1;
    padding: 12px 16px;
    font-size: 15px;
    font-family: inherit;
    background: var(--bg-3);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-1);
    outline: none;
    transition: all var(--transition);
}

.search:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-soft);
}

.search::placeholder {
    color: var(--text-3);
}

.btn-close {
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    border-radius: var(--radius);
    background: transparent;
    color: var(--text-2);
    cursor: pointer;
}

.btn-close:hover {
    color: var(--text-1);
}

.main {
    max-width: 1200px;
    margin: 0 auto;
    padding: calc(var(--header-h) + 24px) 20px 40px;
}

.section {
    display: none;
}

.section.active {
    display: block;
}

.section-header {
    display: flex;
    align-items: center;
    gap: 16px;
    margin-bottom: 20px;
}

.section-header h2 {
    font-size: 24px;
    font-weight: 700;
}

.section-search {
    margin-bottom: 20px;
    max-width: 400px;
}

.count {
    font-size: 13px;
    color: var(--text-3);
    background: var(--bg-3);
    padding: 4px 10px;
    border-radius: 99px;
}

.btn-back {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    font-size: 14px;
    font-weight: 500;
    font-family: inherit;
    color: var(--text-2);
    background: var(--bg-3);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    cursor: pointer;
    transition: all var(--transition);
}

.btn-back:hover {
    color: var(--text-1);
    border-color: var(--border-hover);
}

.grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 16px;
}

.card {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    cursor: pointer;
    transition: all var(--transition);
}

.card:hover {
    background: var(--card-hover);
    border-color: var(--border-hover);
    transform: translateY(-2px);
}

.card-title {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-1);
    margin-bottom: 8px;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.card-meta {
    display: flex;
    align-items: center;
    gap: 8px;
}

.badge {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    padding: 4px 8px;
    border-radius: 4px;
    background: var(--accent-soft);
    color: var(--accent);
}

.list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 18px;
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    cursor: pointer;
    transition: all var(--transition);
}

.item:hover {
    background: var(--card-hover);
    border-color: var(--border-hover);
}

.item.active {
    background: var(--accent-soft);
    border-color: var(--accent);
}

.item-title {
    font-size: 15px;
    font-weight: 500;
    color: var(--text-1);
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.item .badge {
    flex-shrink: 0;
}

.item-meta {
    display: flex;
    align-items: center;
    gap: 8px;
}

.cached-icon {
    color: #22c55e;
    font-size: 14px;
}

.preload-status {
    display: none;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    background: var(--bg-3);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 16px;
}

.preload-status.ready {
    background: rgba(34, 197, 94, 0.1);
    border-color: rgba(34, 197, 94, 0.3);
    color: #22c55e;
}

.preload-bar {
    flex: 1;
    height: 6px;
    background: var(--bg-4);
    border-radius: 99px;
    overflow: hidden;
}

.preload-fill {
    height: 100%;
    background: var(--accent);
    border-radius: 99px;
    transition: width 0.3s ease;
}

.preload-text {
    font-size: 13px;
    color: var(--text-2);
    white-space: nowrap;
}

.preload-status.ready .preload-text {
    color: #22c55e;
}

.highlight {
    background: var(--highlight);
    color: #000;
    padding: 0 2px;
    border-radius: 2px;
}

.empty {
    padding: 40px 20px;
    text-align: center;
    color: var(--text-3);
    font-size: 15px;
}

.loading {
    opacity: 0.5;
    pointer-events: none;
}

.reader-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 20px;
    flex-wrap: wrap;
}

.reader-nav {
    display: flex;
    align-items: center;
    gap: 8px;
}

.reader-progress {
    font-size: 13px;
    color: var(--text-3);
    min-width: 80px;
    text-align: center;
}

.section-reader .content {
    margin-bottom: 80px;
}

.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 10px 18px;
    font-size: 14px;
    font-weight: 500;
    font-family: inherit;
    color: var(--text-1);
    background: var(--bg-3);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    cursor: pointer;
    transition: all var(--transition);
}

.btn:hover:not(:disabled) {
    background: var(--bg-4);
    border-color: var(--border-hover);
}

.btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.content {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 40px;
    font-size: 18px;
    line-height: 1.8;
    white-space: pre-wrap;
    word-wrap: break-word;
    min-height: 300px;
}

::-webkit-scrollbar {
    width: 10px;
    height: 10px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 99px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--border-hover);
}

@media (max-width: 768px) {
    .header-nav {
        display: none;
    }

    .brand span {
        display: none;
    }

    .grid {
        grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
        gap: 12px;
    }

    .card {
        padding: 16px;
    }

    .card-title {
        font-size: 14px;
    }

    .section-header h2 {
        font-size: 20px;
    }

    .content {
        padding: 24px 18px;
        font-size: 16px;
    }

    .reader-nav {
        padding: 10px 16px;
        gap: 12px;
    }

    .reader-nav .btn {
        flex: 1;
        justify-content: center;
        padding: 10px 12px;
    }

    .reader-nav .btn span {
        display: none;
    }

    .reader-progress {
        display: none;
    }
}

@media (max-width: 480px) {
    .main {
        padding-left: 12px;
        padding-right: 12px;
    }

    .grid {
        grid-template-columns: 1fr 1fr;
        gap: 10px;
    }

    .card {
        padding: 14px;
    }

    .content {
        padding: 20px 14px;
        font-size: 15px;
        line-height: 1.75;
    }

    .section-search {
        max-width: 100%;
    }
}

/* Uçan giriş/üyelik butonu — yalnızca anasayfada (kütüphane) görünür */
.register-fab {
    position: fixed;
    top: calc(var(--header-h) + 16px);
    right: 22px;
    z-index: 90;
    width: 58px;
    height: 58px;
    display: none;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background: #fff;
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.18), 0 2px 6px rgba(0, 0, 0, 0.10);
    transition: box-shadow var(--transition), transform var(--transition);
    animation: fab-float 3.4s ease-in-out infinite;
}

.register-fab.show {
    display: flex;
}

.register-fab img {
    width: 66%;
    height: 66%;
    object-fit: contain;
    display: block;
    pointer-events: none;
}

.register-fab:hover {
    box-shadow: 0 12px 26px rgba(0, 0, 0, 0.24), 0 3px 8px rgba(0, 0, 0, 0.14);
    transform: translateY(-3px) scale(1.07);
    animation-play-state: paused;
}

.register-fab:active {
    transform: translateY(-1px) scale(0.98);
    animation-play-state: paused;
}

@keyframes fab-float {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-6px); }
}

@media (prefers-reduced-motion: reduce) {
    .register-fab { animation: none; }
}

@media (max-width: 768px) {
    .register-fab {
        top: auto;
        bottom: 22px;
        right: 18px;
        width: 50px;
        height: 50px;
    }
}