/**
 * Novel Reader - Main Styles
 * Dark mode theme with rounded card design
 */

/* CSS Custom Properties */
:root {
    --novel-bg-primary: #0b132b;
    --novel-bg-secondary: #1c2541;
    --novel-bg-card: #1c2541;
    --novel-bg-hover: #3a506b;
    --novel-text-primary: #ffffff;
    --novel-text-secondary: #c9d1d9;
    --novel-text-muted: #8b949e;
    --novel-accent: #5bc0be;
    --novel-accent-hover: #6fffe9;
    --novel-accent-light: rgba(91, 192, 190, 0.15);
    --novel-success: #6fffe9;
    --novel-warning: #f59e0b;
    --novel-error: #ef4444;
    --novel-border: #3a506b;
    --novel-border-light: #5bc0be;
    --novel-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
    --novel-shadow-lg: 0 8px 40px rgba(0, 0, 0, 0.6);
    --novel-radius: 12px;
    --novel-radius-sm: 8px;
    --novel-radius-lg: 16px;
    --novel-font-reading: 'Georgia', 'Times New Roman', serif;
    --novel-font-ui: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    --novel-sidebar-width: 280px;
}

/* Reset for plugin scope */
.novel-reader,
.novel-reader *,
.novel-dashboard,
.novel-dashboard *,
.novel-series-list,
.novel-series-list * {
    box-sizing: border-box;
}

/* ================================
   MAIN READER LAYOUT
   ================================ */

.novel-reader {
    display: flex;
    min-height: 100vh;
    background: var(--novel-bg-primary);
    color: var(--novel-text-primary);
    font-family: var(--novel-font-ui);
    position: relative;
}

/* Sidebar */
.novel-sidebar {
    width: var(--novel-sidebar-width);
    background: var(--novel-bg-secondary);
    border-right: 1px solid var(--novel-border);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    z-index: 100;
    transition: transform 0.3s ease;
}

/* Account for WordPress admin bar */
.admin-bar .novel-sidebar {
    top: 32px;
    height: calc(100vh - 32px);
}

@media screen and (max-width: 782px) {
    .admin-bar .novel-sidebar {
        top: 46px;
        height: calc(100vh - 46px);
    }
}

.novel-sidebar-header {
    padding: 20px;
    border-bottom: 1px solid var(--novel-border);
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
}

.novel-sidebar-title-wrap {
    flex: 1;
    min-width: 0;
}

.novel-series-title,
h2.novel-series-title {
    font-size: 18px !important;
    font-weight: 600 !important;
    margin: 0 0 8px 0 !important;
    color: var(--novel-text-primary) !important;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.novel-back-to-series {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    color: var(--novel-accent);
    text-decoration: none;
    transition: color 0.2s;
}

.novel-back-to-series:hover {
    color: var(--novel-accent-hover);
}

.novel-back-to-series svg {
    flex-shrink: 0;
}

.novel-sidebar-close {
    display: none;
    background: none;
    border: none;
    color: var(--novel-text-secondary);
    cursor: pointer;
    padding: 8px;
    border-radius: var(--novel-radius-sm);
    transition: background 0.2s, color 0.2s;
}

.novel-sidebar-close:hover {
    background: var(--novel-bg-hover);
    color: var(--novel-text-primary);
}

/* Chapter List */
.novel-chapter-list {
    flex: 1;
    overflow-y: auto;
    padding: 16px 0;
}

.novel-chapter-list h3 {
    font-size: 18px !important;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--novel-text-muted) !important;
    padding: 0 20px;
    margin: 0 0 12px 0 !important;
}

.novel-chapter-list ul {
    list-style: none;
    margin: 0;
    padding: 0;
}

.novel-chapter-list li {
    margin: 0;
}

.novel-chapter-list li a {
    display: flex;
    flex-direction: column;
    padding: 12px 20px;
    color: var(--novel-text-secondary);
    text-decoration: none;
    transition: background 0.2s, color 0.2s;
    border-left: 3px solid transparent;
}

.novel-chapter-list li a:hover {
    background: var(--novel-bg-hover);
    color: var(--novel-text-primary);
}

.novel-chapter-list li.current a {
    background: var(--novel-accent-light);
    color: var(--novel-accent);
    border-left-color: var(--novel-accent);
}

.novel-chapter-list .chapter-number {
    font-size: 11px;
    color: var(--novel-text-muted);
    margin-bottom: 2px;
}

.novel-chapter-list .chapter-title {
    font-size: 14px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Sidebar Actions */
.novel-sidebar-actions {
    padding: 16px 12px;
    border-top: 1px solid var(--novel-border);
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.novel-action-btn {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 16px;
    background: var(--novel-bg-card);
    border: 1px solid var(--novel-border);
    border-radius: var(--novel-radius-sm);
    color: var(--novel-text-secondary);
    font-size: 14px;
    cursor: pointer;
    transition: all 0.2s;
}

.novel-action-btn:hover {
    background: var(--novel-bg-hover);
    border-color: var(--novel-border-light);
    color: var(--novel-text-primary);
}

.novel-action-btn.active {
    background: var(--novel-accent-light);
    border-color: var(--novel-accent);
    color: var(--novel-accent);
}

.novel-action-btn svg {
    flex-shrink: 0;
}

/* Mobile Menu Toggle */
.novel-mobile-menu-toggle {
    display: none;
    position: fixed;
    top: 16px;
    left: 16px;
    z-index: 9999;
    background: var(--novel-bg-card) !important;
    border: 1px solid var(--novel-border) !important;
    border-radius: var(--novel-radius-sm) !important;
    color: var(--novel-text-primary) !important;
    padding: 12px !important;
    cursor: pointer;
    box-shadow: var(--novel-shadow);
    -webkit-tap-highlight-color: transparent;
}

.novel-mobile-menu-toggle:hover,
.novel-mobile-menu-toggle:focus {
    background: var(--novel-bg-hover) !important;
    outline: none;
}

/* Admin bar offset for mobile toggle */
.admin-bar .novel-mobile-menu-toggle {
    top: 48px;
}

@media screen and (max-width: 782px) {
    .admin-bar .novel-mobile-menu-toggle {
        top: 62px;
    }
}

.novel-sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    z-index: 9998;
    opacity: 0;
    transition: opacity 0.3s;
}

.novel-sidebar-overlay.visible {
    opacity: 1;
}

/* Ensure sidebar is above overlay when open */
.novel-sidebar.open {
    z-index: 10000;
}

/* ================================
   MAIN CONTENT AREA
   ================================ */

.novel-content {
    flex: 1;
    margin-left: var(--novel-sidebar-width);
    padding: 40px;
    max-width: 800px;
    margin-right: auto;
}

/* Chapter Header */
.novel-chapter-header {
    margin-bottom: 32px;
    padding-bottom: 24px;
    border-bottom: 1px solid var(--novel-border);
}

.novel-chapter-header .chapter-meta {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 8px;
}

.novel-chapter-header .chapter-number {
    font-size: 14px;
    color: var(--novel-accent);
    font-weight: 500;
}

.adult-badge {
    display: inline-block;
    padding: 2px 8px;
    background: var(--novel-error);
    color: white;
    font-size: 11px;
    font-weight: 600;
    border-radius: 4px;
}

.novel-chapter-header .chapter-title {
    font-size: 28px;
    font-weight: 700;
    margin: 0;
    line-height: 1.3;
}

/* Chapter Summary */
.novel-chapter-summary {
    background: var(--novel-bg-card);
    border-radius: var(--novel-radius);
    padding: 20px;
    margin-bottom: 32px;
}

.novel-chapter-summary .summary-label {
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--novel-text-muted);
    margin-bottom: 8px;
}

.novel-chapter-summary .summary-content {
    font-size: 15px;
    color: var(--novel-text-secondary);
    line-height: 1.6;
}

/* Chapter Content */
.novel-chapter-content {
    font-family: var(--novel-font-reading);
    font-size: 18px;
    line-height: 1.8;
    color: var(--novel-text-primary);
    /* Allow text selection on mobile */
    -webkit-user-select: text;
    -moz-user-select: text;
    -ms-user-select: text;
    user-select: text;
    /* Allow touch actions for selection */
    -webkit-touch-callout: default;
}

.novel-chapter-content p {
    margin: 0 0 1.5em 0;
}

.novel-chapter-content img {
    max-width: 100%;
    height: auto;
    border-radius: var(--novel-radius-sm);
    margin: 24px 0;
}

.novel-chapter-content blockquote {
    border-left: 4px solid var(--novel-accent);
    padding-left: 20px;
    margin: 24px 0;
    color: var(--novel-text-secondary);
    font-style: italic;
}

.novel-chapter-content hr {
    border: none;
    height: 1px;
    background: var(--novel-border);
    margin: 32px 0;
}

/* Author Notes */
.novel-author-notes {
    background: var(--novel-bg-card);
    border-radius: var(--novel-radius);
    padding: 20px;
    margin-top: 40px;
}

.novel-author-notes .notes-label {
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--novel-accent);
    margin-bottom: 8px;
}

.novel-author-notes .notes-content {
    font-size: 15px;
    color: var(--novel-text-secondary);
    line-height: 1.6;
}

/* Chapter Navigation */
.novel-chapter-nav {
    display: flex;
    justify-content: space-between;
    gap: 16px;
    margin-top: 48px;
    padding-top: 32px;
    border-top: 1px solid var(--novel-border);
}

.novel-chapter-nav a,
.novel-chapter-nav span {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 14px 20px;
    background: var(--novel-bg-card);
    border-radius: var(--novel-radius-sm);
    color: var(--novel-text-primary);
    text-decoration: none;
    font-weight: 500;
    transition: all 0.2s;
}

.novel-chapter-nav a:hover {
    background: var(--novel-accent);
}

.novel-chapter-nav .disabled {
    visibility: hidden;
}

/* ================================
   COMMENTS SECTION
   ================================ */

.novel-comments {
    margin-top: 64px;
    padding-top: 32px;
    border-top: 1px solid var(--novel-border);
}

.novel-comments h2 {
    font-size: 20px;
    margin: 0 0 24px 0;
}

/* Comment Form */
.novel-comment-form {
    margin-bottom: 32px;
}

.novel-comment-form textarea {
    width: 100%;
    min-height: 120px;
    padding: 16px;
    background: var(--novel-bg-card);
    border: 1px solid var(--novel-border);
    border-radius: var(--novel-radius);
    color: var(--novel-text-primary);
    font-family: var(--novel-font-ui);
    font-size: 15px;
    resize: vertical;
    margin-bottom: 12px;
}

.novel-comment-form textarea:focus {
    outline: none;
    border-color: var(--novel-accent);
}

.novel-comment-form textarea::placeholder {
    color: var(--novel-text-muted);
}

/* Quote Preview */
#quoted-text-preview,
#reply-to-preview {
    background: var(--novel-bg-card);
    border-radius: var(--novel-radius-sm);
    padding: 12px 16px;
    margin-bottom: 12px;
    display: flex;
    align-items: center;
    gap: 12px;
}

#quoted-text-preview .quote-label,
#reply-to-preview .reply-label {
    font-size: 12px;
    color: var(--novel-text-muted);
    flex-shrink: 0;
}

#quoted-text-preview .quote-content {
    flex: 1;
    font-size: 13px;
    color: var(--novel-accent);
    margin: 0;
    padding: 0;
    border: none;
    background: none;
}

#quoted-text-preview .remove-quote {
    font-size: 12px;
    padding: 4px 8px;
    border-radius: 4px;
    background: var(--novel-bg-hover);
}

#quoted-text-preview .remove-quote:hover {
    background: rgba(239, 68, 68, 0.2);
}

.remove-quote,
.cancel-reply {
    background: none;
    border: none;
    color: var(--novel-text-muted);
    cursor: pointer;
    font-size: 18px;
    padding: 0;
    line-height: 1;
}

.remove-quote:hover,
.cancel-reply:hover {
    color: var(--novel-error);
}

/* Comments List */
.novel-comments-list {
    margin-top: 24px;
}

.comment-thread {
    list-style: none;
    margin: 0;
    padding: 0;
}

.comment-thread.depth-1,
.comment-thread.depth-2 {
    margin-left: 40px;
    padding-left: 16px;
    border-left: 2px solid var(--novel-border);
}

.comment-item {
    margin-bottom: 16px;
}

.comment-body {
    background: var(--novel-bg-card);
    border-radius: var(--novel-radius);
    padding: 16px;
}

.comment-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
}

.comment-author {
    display: flex;
    align-items: center;
    gap: 10px;
}

.comment-author img {
    width: 32px;
    height: 32px;
    border-radius: 50%;
}

.comment-author .author-name {
    font-weight: 600;
    font-size: 14px;
}

.comment-date {
    font-size: 12px;
    color: var(--novel-text-muted);
}

.comment-quote {
    background: var(--novel-bg-hover);
    border-radius: var(--novel-radius-sm);
    padding: 12px;
    margin-bottom: 12px;
    font-style: italic;
    color: var(--novel-text-secondary);
    display: flex;
    gap: 8px;
}

.comment-quote svg {
    flex-shrink: 0;
    color: var(--novel-accent);
    opacity: 0.5;
}

/* Inline quotes within comment text */
.comment-text .comment-quote.inline-quote {
    margin: 12px 0;
    font-size: 14px;
}

.comment-text .comment-quote.inline-quote:first-child {
    margin-top: 0;
}

.comment-text .comment-quote.inline-quote:last-child {
    margin-bottom: 0;
}

/* Multiple quotes spacing */
.comment-text .comment-quote.inline-quote + .comment-quote.inline-quote {
    margin-top: 8px;
}

.comment-text {
    font-size: 15px;
    line-height: 1.6;
}

.comment-text p {
    margin: 0 0 8px 0;
}

.comment-text p:last-child {
    margin-bottom: 0;
}

.comment-actions {
    display: flex;
    gap: 12px;
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid var(--novel-border);
}

.comment-reply-btn,
.comment-delete-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    background: none;
    border: none;
    color: var(--novel-text-muted);
    font-size: 13px;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 4px;
    transition: all 0.2s;
}

.comment-reply-btn:hover {
    color: var(--novel-accent);
    background: var(--novel-accent-light);
}

.comment-delete-btn:hover {
    color: var(--novel-error);
    background: rgba(239, 68, 68, 0.1);
}

.no-comments {
    text-align: center;
    color: var(--novel-text-muted);
    padding: 40px 20px;
}

/* Login Prompt */
.novel-login-prompt,
.novel-login-required {
    text-align: center;
    padding: 40px 20px;
    background: var(--novel-bg-card);
    border-radius: var(--novel-radius);
}

.novel-login-prompt p,
.novel-login-required p {
    margin: 0 0 16px 0;
    color: var(--novel-text-secondary);
}

/* ================================
   TEXT SELECTION POPUP
   ================================ */

#selection-popup {
    position: absolute;
    background: var(--novel-bg-card);
    border: 1px solid var(--novel-border);
    border-radius: var(--novel-radius-sm);
    box-shadow: var(--novel-shadow-lg);
    z-index: 1000;
    padding: 4px;
}

#selection-popup .selection-action {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 12px;
    background: none;
    border: none;
    color: var(--novel-text-primary);
    font-size: 13px;
    cursor: pointer;
    border-radius: 4px;
    white-space: nowrap;
    transition: background 0.2s;
}

#selection-popup .selection-action:hover {
    background: var(--novel-accent);
}

/* Mobile selection popup */
@media (max-width: 768px) {
    #selection-popup {
        padding: 6px;
    }

    #selection-popup .selection-action {
        padding: 10px 14px;
        font-size: 14px;
    }
}

/* ================================
   LOCKED CONTENT
   ================================ */

.novel-reader-locked {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 60vh;
    background: var(--novel-bg-primary);
}

.locked-content-card {
    text-align: center;
    background: var(--novel-bg-card);
    padding: 48px;
    border-radius: var(--novel-radius-lg);
    max-width: 400px;
    box-shadow: var(--novel-shadow-lg);
}

.locked-content-card .lock-icon {
    color: var(--novel-accent);
    margin-bottom: 24px;
}

.locked-content-card h3 {
    font-size: 24px;
    margin: 0 0 12px 0;
}

.locked-content-card p {
    color: var(--novel-text-secondary);
    margin: 0 0 24px 0;
}

/* ================================
   BUTTONS
   ================================ */

.novel-btn,
.novel-reader .novel-btn,
.novel-reader button.novel-btn {
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    gap: 8px !important;
    padding: 12px 24px !important;
    background: var(--novel-bg-hover) !important;
    border: 1px solid var(--novel-border) !important;
    border-radius: var(--novel-radius-sm) !important;
    color: var(--novel-text-primary) !important;
    font-family: var(--novel-font-ui) !important;
    font-size: 14px !important;
    font-weight: 500 !important;
    text-decoration: none !important;
    cursor: pointer !important;
    transition: all 0.2s !important;
}

.novel-btn:hover,
.novel-reader .novel-btn:hover,
.novel-reader button.novel-btn:hover {
    background: var(--novel-accent) !important;
    border-color: var(--novel-accent) !important;
    color: #0b132b !important;
}

.novel-btn-primary,
.novel-reader .novel-btn-primary,
.novel-reader button.novel-btn-primary {
    background: var(--novel-accent) !important;
    border-color: var(--novel-accent) !important;
    color: #0b132b !important;
    font-weight: 600 !important;
}

.novel-btn-primary:hover,
.novel-reader .novel-btn-primary:hover,
.novel-reader button.novel-btn-primary:hover {
    background: var(--novel-accent-hover) !important;
    border-color: var(--novel-accent-hover) !important;
    color: #0b132b !important;
}

.novel-btn-small {
    padding: 8px 16px !important;
    font-size: 13px !important;
}

/* ================================
   TOAST NOTIFICATIONS
   ================================ */

.novel-toast {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    background: var(--novel-bg-card);
    border: 1px solid var(--novel-border);
    padding: 12px 24px;
    border-radius: var(--novel-radius-sm);
    box-shadow: var(--novel-shadow-lg);
    z-index: 9999;
    opacity: 0;
    transition: all 0.3s ease;
    color: var(--novel-text-primary);
    font-family: var(--novel-font-ui);
    font-size: 14px;
}

.novel-toast.visible {
    transform: translateX(-50%) translateY(0);
    opacity: 1;
}

.novel-toast-success {
    border-color: var(--novel-success);
}

.novel-toast-error {
    border-color: var(--novel-error);
}

.novel-toast-warning {
    border-color: var(--novel-warning);
}

/* ================================
   ERROR STATE
   ================================ */

.novel-reader-error {
    text-align: center;
    padding: 60px 20px;
    background: var(--novel-bg-secondary);
    color: var(--novel-text-secondary);
    border-radius: var(--novel-radius);
}

/* ================================
   MOBILE HEADER BAR
   ================================ */

.novel-mobile-header {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 56px;
    background: var(--novel-bg-secondary);
    border-bottom: 1px solid var(--novel-border);
    z-index: 9999;
    padding: 0 12px;
    align-items: center;
    justify-content: space-between;
}

/* Admin bar offset for mobile header */
.admin-bar .novel-mobile-header {
    top: 32px;
}

@media screen and (max-width: 782px) {
    .admin-bar .novel-mobile-header {
        top: 46px;
    }
}

.mobile-header-back {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    color: var(--novel-text-secondary);
    text-decoration: none;
    border-radius: var(--novel-radius-sm);
    transition: all 0.2s;
}

.mobile-header-back:hover {
    background: var(--novel-bg-hover);
    color: var(--novel-text-primary);
}

.mobile-header-actions {
    display: flex;
    align-items: center;
    gap: 4px;
}

.mobile-action-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    min-width: 40px;
    height: 40px;
    padding: 0 10px;
    background: transparent;
    border: none;
    color: var(--novel-text-secondary);
    border-radius: var(--novel-radius-sm);
    cursor: pointer;
    transition: all 0.2s;
    -webkit-tap-highlight-color: transparent;
}

.mobile-action-btn:hover,
.mobile-action-btn:focus {
    background: var(--novel-bg-hover);
    color: var(--novel-text-primary);
    outline: none;
}

.mobile-action-btn.active {
    color: var(--novel-accent);
}

.mobile-action-btn.active svg {
    fill: currentColor;
}

.mobile-kudo-count {
    font-size: 12px;
    font-weight: 600;
    color: inherit;
}

/* Mobile header menu toggle specific styles */
.novel-mobile-header .novel-mobile-menu-toggle {
    position: static;
    box-shadow: none;
    background: transparent !important;
    border: none !important;
    padding: 0 !important;
    min-width: 40px;
    height: 40px;
}

.novel-mobile-header .novel-mobile-menu-toggle:hover,
.novel-mobile-header .novel-mobile-menu-toggle:focus {
    background: var(--novel-bg-hover) !important;
}

/* ================================
   MOBILE RESPONSIVE
   ================================ */

@media (max-width: 768px) {
    /* Show mobile header bar */
    .novel-mobile-header {
        display: flex;
    }

    /* Hide the standalone mobile menu toggle (old one outside header) */
    .novel-reader > .novel-mobile-menu-toggle {
        display: none !important;
    }

    .novel-sidebar {
        transform: translateX(-100%);
    }

    .novel-sidebar.open {
        transform: translateX(0);
    }

    .novel-sidebar-close {
        display: block;
    }

    .novel-sidebar-overlay {
        display: block;
    }

    .novel-content {
        margin-left: 0;
        padding: 72px 20px 40px;
    }

    /* Admin bar offset for content on mobile */
    .admin-bar .novel-content {
        padding-top: 104px;
    }

    .novel-chapter-header .chapter-title {
        font-size: 22px;
    }

    .novel-chapter-content {
        font-size: 16px;
    }

    .novel-chapter-nav {
        flex-direction: column;
    }

    .novel-chapter-nav .disabled {
        display: none;
    }

    .comment-thread.depth-1,
    .comment-thread.depth-2 {
        margin-left: 20px;
    }
}

@media (max-width: 480px) {
    .novel-content {
        padding: 70px 16px 32px;
    }

    .novel-chapter-header .chapter-title {
        font-size: 20px;
    }

    .locked-content-card {
        padding: 32px 24px;
        margin: 16px;
    }
}
