:root {
    --bg-color: #0f1115;
    --header-bg: rgba(15, 17, 21, 0.9);
    --text-main: #ffffff;
    --text-muted: #9ca3af;
    --accent: #3b82f6;
    --accent-hover: #2563eb;
    --border-color: #2d3748;
    --control-bg: #1f2937;
    --control-hover: #374151;
}

body {
    margin: 0;
    background: var(--bg-color);
    color: var(--text-main);
    font-family: 'Outfit', sans-serif;
    overflow-x: hidden;
    -webkit-tap-highlight-color: transparent;
}

/* --- Header & Controls --- */
.reader-header {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 64px;
    background: var(--header-bg);
    backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border-color);
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1rem;
    box-sizing: border-box;
    transition: transform 0.3s ease;
}

.header-left,
.header-right {
    display: flex;
    align-items: center;
    gap: 1rem;
    flex: 1;
}

.header-right {
    justify-content: flex-end;
}

.header-center {
    flex: 2;
    display: flex;
    justify-content: center;
    align-items: center;
    text-align: center;
    overflow: hidden;
}

.back-btn {
    color: var(--text-main);
    font-size: 1.2rem;
    text-decoration: none;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: background 0.2s;
}

.back-btn:hover {
    background: var(--control-hover);
}

.manga-info {
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.manga-title {
    font-size: 1rem;
    font-weight: 500;
    color: var(--text-main);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
    padding: 0 1rem;
}

.chapter-current {
    font-size: 1rem;
    font-weight: 600;
    white-space: nowrap;
}

/* Controls */
.control-group {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    background: var(--control-bg);
    padding: 4px;
    border-radius: 8px;
    border: 1px solid var(--border-color);
}

.view-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    padding: 6px 12px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.9rem;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 6px;
}

.view-btn.active {
    background: var(--accent);
    color: white;
}

.view-btn:hover:not(.active) {
    color: var(--text-main);
    background: rgba(255, 255, 255, 0.05);
}

.chapter-select-wrapper {
    position: relative;
    min-width: 140px;
}

.chapter-select {
    appearance: none;
    background: var(--control-bg);
    border: 1px solid var(--border-color);
    color: var(--text-main);
    padding: 8px 32px 8px 12px;
    border-radius: 8px;
    font-family: inherit;
    font-size: 0.9rem;
    cursor: pointer;
    width: 100%;
    outline: none;
}

.chapter-select:focus {
    border-color: var(--accent);
}

.select-icon {
    position: absolute;
    right: 12px;
    top: 50%;
    transform: translateY(-50%);
    pointer-events: none;
    color: var(--text-muted);
    font-size: 0.8rem;
}

/* --- Reader Content --- */
.reader-container {
    padding-top: 64px;
    /* Header height */
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    position: relative;
}

/* Webtoon Mode Styles */
.mode-webtoon .page-image {
    display: block;
    max-width: 100%;
    width: auto;
    margin: 0 auto;
    height: auto;
}

.mode-webtoon .page-wrapper {
    width: 100%;
    max-width: 800px;
    /* Limit width for better reading on desktop */
    margin: 0 auto;
}

/* Single Page Mode Styles */
.mode-single {
    height: calc(100vh - 64px);
    justify-content: center;
    overflow: hidden;
    /* Prevent scrolling in single mode */
}

.mode-single .page-wrapper {
    height: 100%;
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
}

.mode-single .page-image {
    max-height: 100%;
    max-width: 100%;
    object-fit: contain;
    display: none;
    /* Hidden by default */
}

.mode-single .page-image.active {
    display: block;
}

/* Navigation Zones for Single Mode */
.nav-zone,
.center-zone {
    display: none;
    /* Hidden by default */
    position: absolute;
    top: 0;
    bottom: 0;
    z-index: 10;
    cursor: pointer;
}

.mode-single .nav-zone,
.mode-single .center-zone {
    display: block;
    /* Show only in single mode */
}

.nav-zone {
    width: 40%;
}

.nav-zone.left {
    left: 0;
}

.nav-zone.right {
    right: 0;
}

/* Center zone to toggle UI */
.center-zone {
    left: 40%;
    width: 20%;
    z-index: 11;
}

/* --- Footer Navigation --- */
.reader-footer {
    padding: 2rem 1rem;
    display: flex;
    justify-content: center;
    gap: 1rem;
    width: 100%;
    max-width: 800px;
    margin: 0 auto;
    box-sizing: border-box;
}

.nav-chapter-btn {
    background: var(--control-bg);
    color: var(--text-main);
    border: 1px solid var(--border-color);
    padding: 12px 24px;
    border-radius: 30px;
    text-decoration: none;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: all 0.2s;
}

.nav-chapter-btn:hover {
    background: var(--control-hover);
    border-color: var(--text-muted);
}

.nav-chapter-btn.disabled {
    opacity: 0.5;
    pointer-events: none;
}

/* UI Toggle State */
body.ui-hidden .reader-header {
    transform: translateY(-100%);
}

/* Comments Section */
.comments-section {
    width: 100%;
    max-width: 800px;
    margin: 2rem auto;
    padding: 1rem;
    background: var(--control-bg);
    border-radius: 12px;
    border: 1px solid var(--border-color);
}

.comments-title {
    font-size: 1.2rem;
    margin-bottom: 1rem;
    color: var(--text-main);
}

.comment-form textarea {
    width: 100%;
    background: var(--bg-color);
    border: 1px solid var(--border-color);
    color: var(--text-main);
    padding: 0.75rem;
    border-radius: 8px;
    resize: vertical;
    margin-bottom: 0.5rem;
    font-family: inherit;
}

.comment-form button {
    background: var(--accent);
    color: white;
    border: none;
    padding: 0.5rem 1rem;
    border-radius: 6px;
    cursor: pointer;
    font-weight: 500;
    transition: background 0.2s;
}

.comment-form button:hover {
    background: var(--accent-hover);
}

.login-prompt {
    text-align: center;
    padding: 1rem;
    background: var(--bg-color);
    border-radius: 8px;
    margin-bottom: 1rem;
    color: var(--text-muted);
}

.login-prompt a {
    color: var(--accent);
    text-decoration: none;
}

.comments-list {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    margin-top: 1.5rem;
}

.comment-item {
    background: var(--bg-color);
    padding: 1rem;
    border-radius: 8px;
    border: 1px solid var(--border-color);
    position: relative;
}

.comment-item.pinned-comment {
    border: 2px solid var(--accent);
    background: rgba(59, 130, 246, 0.1);
    box-shadow: 0 0 10px rgba(59, 130, 246, 0.2);
}

.comment-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 0.5rem;
    font-size: 0.9rem;
}

.comment-user {
    font-weight: 600;
    color: var(--text-main);
}

.admin-badge {
    display: inline-block;
    background: var(--accent);
    color: white;
    font-size: 0.7rem;
    padding: 2px 6px;
    border-radius: 4px;
    margin-left: 0.5rem;
    font-weight: 600;
    text-transform: uppercase;
}

.pinned-badge {
    display: inline-block;
    background: rgba(251, 191, 36, 0.2);
    color: #fbbf24;
    font-size: 0.7rem;
    padding: 2px 6px;
    border-radius: 4px;
    margin-left: 0.5rem;
    font-weight: 600;
}

.reply-context {
    background: rgba(255, 255, 255, 0.05);
    padding: 0.5rem;
    border-radius: 6px;
    margin-bottom: 0.75rem;
    font-size: 0.85rem;
    color: var(--text-muted);
    border-left: 3px solid var(--accent);
}

.reply-context i {
    margin-right: 0.5rem;
    color: var(--accent);
}

.reply-context .context-text {
    font-style: italic;
    opacity: 0.8;
}

.comment-date {
    color: var(--text-muted);
    font-size: 0.8rem;
}

.comment-content {
    color: #d1d5db;
    line-height: 1.5;
}

.pinned-reply {
    border: 2px solid var(--accent) !important;
    background: rgba(59, 130, 246, 0.15) !important;
    box-shadow: 0 0 8px rgba(59, 130, 246, 0.3);
}

.comment-actions {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-top: 0.5rem;
}

.reply-btn,
.pin-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 0.8rem;
    cursor: pointer;
    padding: 0;
}

.reply-btn:hover,
.pin-btn:hover {
    color: var(--accent);
    text-decoration: underline;
}

.pin-btn.pinned {
    color: var(--accent);
}

.reaction-group {
    display: flex;
    gap: 0.5rem;
}

.reaction-btn {
    background: transparent;
    border: none;
    cursor: pointer;
    font-size: 0.9rem;
    padding: 2px 6px;
    border-radius: 4px;
    transition: background 0.2s;
    color: var(--text-muted);
}

.reaction-btn:hover {
    background: rgba(255, 255, 255, 0.1);
}

/* Hide comments in single page mode */
body.mode-single .comments-section {
    display: none;
}

/* Single Mode Controls */
.single-controls {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--control-bg);
    border: 1px solid var(--border-color);
    padding: 8px 16px;
    border-radius: 50px;
    display: none;
    /* Hidden by default */
    align-items: center;
    gap: 16px;
    z-index: 101;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    transition: transform 0.3s ease, opacity 0.3s ease;
}

.control-btn {
    background: transparent;
    border: none;
    color: var(--text-main);
    width: 32px;
    height: 32px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}

.control-btn:hover {
    background: var(--control-hover);
}

.page-indicator {
    font-variant-numeric: tabular-nums;
    font-size: 0.9rem;
    color: var(--text-muted);
    min-width: 60px;
    text-align: center;
}

/* Hide single controls when UI is hidden */
body.ui-hidden .single-controls {
    transform: translate(-50%, 150%);
    /* Slide down */
    opacity: 0;
}

/* Mobile Adjustments */
@media (max-width: 768px) {
    .manga-title {
        display: none;
    }

    .view-text {
        display: none;
    }

    .reader-header {
        padding: 0 0.5rem;
    }

    .chapter-select-wrapper {
        min-width: 100px;
    }

    .control-group {
        gap: 0;
    }

    .view-btn {
        padding: 8px;
    }
}