/**
 * Comic Reader - Base Styles
 */

/* Overlay Header - Young Jump Style */
body.kcr-reader-page .site-header {
    display: block !important;
    position: fixed !important;
    top: 0;
    left: 0;
    right: 0;
    z-index: 100000 !important;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
    background: rgba(26, 26, 26, 0.95) !important;
    backdrop-filter: blur(10px);
}

/* Show header when class is added */
body.kcr-reader-page.show-header .site-header {
    display: block !important;
    opacity: 1 !important;
    pointer-events: auto !important;
}

/* Override theme padding/margin on pages with reader */
.site-main:has(.kcr-reader-container) {
    padding-top: 0 !important;
    margin-top: 0 !important;
}

body.kcr-reader-page .site-main {
    padding-top: 0 !important;
    margin-top: 0 !important;
}

/* Override theme container padding on reader pages (exclude header) */
body.kcr-reader-page .site-main .container,
body.kcr-reader-page .site-main .container-wide {
    padding-left: 0 !important;
    padding-right: 0 !important;
    max-width: none !important;
}

.kcr-reader-container {
    position: relative;
    width: 100vw;
    margin-left: calc(50% - 50vw);
    margin-right: calc(50% - 50vw);
    margin-top: -80px;
    margin-bottom: 0;
    padding-top: 80px;
    padding-bottom: 0;
    background: #000;
    color: #fff;
    overflow: hidden;
}

/* Mobile: Use 100% width instead of viewport units to prevent horizontal scroll */
@media (max-width: 768px) {
    /* Remove ALL top spacing on mobile */
    .site-main:has(.kcr-reader-container) {
        padding-top: 0 !important;
        margin-top: 0 !important;
    }

    /* Override theme container padding on reader pages - mobile (exclude header) */
    body.kcr-reader-page .site-main .container,
    body.kcr-reader-page .site-main .container-wide {
        padding-left: 0 !important;
        padding-right: 0 !important;
        max-width: 100% !important;
    }

    .kcr-reader-container {
        width: 100%;
        margin-left: 0;
        margin-right: 0;
        margin-top: 0 !important;    /* Remove negative margin that clips content */
        padding-top: 0 !important;   /* Remove compensating padding */
        max-width: 100%;
        overflow: visible;           /* Allow content to show, don't clip */
    }

    .kcr-fullscreen-btn {
        display: inline-flex !important; /* Show fullscreen on mobile - forced landscape mode */
    }
}

/* iOS Pseudo-Fullscreen: prevent body scroll when reader is fullscreen */
body.kcr-pseudo-fullscreen {
    overflow: hidden !important;
    position: fixed !important;
    width: 100% !important;
    height: 100% !important;
}

/* Loading Overlay */
.kcr-loading-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
}

.kcr-spinner {
    border: 4px solid rgba(255, 255, 255, 0.3);
    border-top-color: #fff;
    border-radius: 50%;
    width: 50px;
    height: 50px;
    animation: kcr-spin 1s linear infinite;
}

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

/* Mature Warning Overlay */
.kcr-mature-warning-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.95);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10000;
}

.kcr-mature-warning-dialog {
    background: #1a1a1a;
    padding: 40px;
    border-radius: 8px;
    max-width: 500px;
    text-align: center;
    border: 2px solid #d63638;
}

.kcr-warning-icon {
    font-size: 48px;
    color: #d63638;
    margin-bottom: 20px;
}

.kcr-mature-warning-dialog h2 {
    color: #fff;
    margin-bottom: 20px;
}

.kcr-mature-warning-dialog p {
    color: #ccc;
    margin-bottom: 15px;
    font-size: 16px;
}

.kcr-warning-actions {
    display: flex;
    gap: 15px;
    justify-content: center;
    margin-top: 30px;
}

.kcr-warning-btn {
    padding: 12px 40px;
    font-size: 16px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.3s;
}

.kcr-warning-yes {
    background: #2ea44f;
    color: #fff;
}

.kcr-warning-yes:hover {
    background: #2c974b;
}

.kcr-warning-no {
    background: #d63638;
    color: #fff;
}

.kcr-warning-no:hover {
    background: #a02c2c;
}

/* Advertisement */
.kcr-advertisement {
    width: 100%;
    margin: 20px 0;
    text-align: center;
}

.kcr-ad-link {
    display: inline-block;
}

.kcr-ad-image {
    max-width: 100%;
    height: auto;
    display: block;
}

/* Controls Bar */
.kcr-controls-bar {
    background: rgba(26, 26, 26, 0.95);
    padding: 8px 0;
    border-top: 1px solid #333;
    opacity: 0;
    transform: translateY(10px);
    transition: opacity 0.3s ease, transform 0.3s ease;
    pointer-events: none;
    backdrop-filter: blur(10px);
    width: 100%;
}

.kcr-reader-container:hover .kcr-controls-bar,
.kcr-reader-container.controls-visible .kcr-controls-bar {
    opacity: 1;
    transform: translateY(0);
    pointer-events: auto;
}

.kcr-controls-wrapper {
    width: 100%;
    padding: 0 20px;
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: center;
    gap: 15px;
}

.kcr-controls-center {
    display: flex;
    align-items: center;
    gap: 12px;
    flex: 1;
    justify-content: center;
}

.kcr-control-btn {
    background: transparent;
    border: none;
    color: #fff;
    padding: 6px 8px;
    border-radius: 3px;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.kcr-control-btn .dashicons {
    font-family: dashicons !important;
    display: inline-block;
    font-size: 20px;
    width: 20px;
    height: 20px;
    line-height: 1;
    font-style: normal;
    font-weight: normal;
    speak: never;
    text-decoration: inherit;
    text-transform: none;
    text-rendering: auto;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* Explicit icon content fallback — renders icons even if dashicons CSS fails */
.kcr-control-btn .dashicons-fullscreen-alt:before {
    content: "\f211";
}
.kcr-control-btn .dashicons-admin-comments:before {
    content: "\f101";
}
.kcr-control-btn .dashicons-heart:before {
    content: "\f487";
}

/* Bookmark ribbon icon — dashicons-bookmark is NOT in the standard WordPress dashicons set,
   so we render a proper ribbon/tab SVG via CSS mask instead of a font glyph. */
.dashicons.dashicons-bookmark:before {
    content: '' !important;
    display: block;
    width: 100%;
    height: 100%;
    background: currentColor;
    -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M6 2C4.9 2 4 2.9 4 4v18l8-5 8 5V4c0-1.1-.9-2-2-2H6z'/%3E%3C/svg%3E") no-repeat center / contain;
    mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M6 2C4.9 2 4 2.9 4 4v18l8-5 8 5V4c0-1.1-.9-2-2-2H6z'/%3E%3C/svg%3E") no-repeat center / contain;
}

.kcr-control-btn:hover {
    background: rgba(0, 217, 255, 0.2);
    color: #00d9ff;
}

.kcr-control-btn:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

.kcr-control-btn:disabled:hover {
    background: transparent;
    color: #fff;
}

/* Bookmark Button */
.kcr-bookmark-btn .dashicons-bookmark.bookmarked {
    color: #ffcb05;
}

.kcr-bookmark-btn:hover .dashicons-bookmark.bookmarked {
    color: #ffd700;
}

/* Touch feedback for bookmark button */
.kcr-bookmark-btn.touch-active {
    background: rgba(0, 217, 255, 0.3);
    transform: scale(0.95);
}

/* Pulse animation for bookmark action */
@keyframes kcr-bookmark-pulse {
    0% { transform: scale(1); }
    50% { transform: scale(1.1); }
    100% { transform: scale(1); }
}

.kcr-bookmark-btn.active-pulse {
    animation: kcr-bookmark-pulse 0.3s ease-out;
}

/* Favorite Heart Button */
.kc-favorite-btn .dashicons {
    transition: color 0.2s;
}

.kc-favorite-btn.favorited .dashicons {
    color: #ff6b6b;
}

.kc-favorite-btn:hover .dashicons {
    color: #ff6b6b;
}

.kc-favorite-btn.favorited:hover .dashicons {
    color: #ff4444;
}

/* Comments Button (disabled placeholder) */
.kcr-comments-btn:disabled {
    opacity: 0.35;
    cursor: default;
}

.kcr-comments-btn:disabled:hover {
    background: transparent;
    color: #fff;
}

/* Bookmark Message */
.kcr-bookmark-message {
    position: fixed;
    bottom: 80px;
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    background: rgba(0, 217, 255, 0.95);
    color: #000;
    padding: 12px 24px;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 600;
    z-index: 10001;
    opacity: 0;
    transition: all 0.3s ease;
    pointer-events: none;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.kcr-bookmark-message.visible {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

/* Page Counter */
.kcr-page-counter {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 13px;
    color: #ccc;
    font-weight: 500;
}

/* Page Scrubber */
.kcr-page-scrubber-container {
    flex: 1;
    max-width: 500px;
    min-width: 150px;
}

.kcr-page-scrubber {
    width: 100%;
    height: 4px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 2px;
    outline: none;
    -webkit-appearance: none;
    cursor: pointer;
}

/* RTL Mode: Reverse scrubber direction */
.kcr-reading-rtl .kcr-page-scrubber {
    direction: rtl;
}

.kcr-page-scrubber::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 12px;
    height: 12px;
    background: #00d9ff;
    border-radius: 50%;
    cursor: pointer;
    transition: transform 0.2s;
}

.kcr-page-scrubber:hover::-webkit-slider-thumb {
    transform: scale(1.2);
}

.kcr-page-scrubber::-moz-range-thumb {
    width: 12px;
    height: 12px;
    background: #00d9ff;
    border-radius: 50%;
    cursor: pointer;
    border: none;
    transition: transform 0.2s;
}

.kcr-page-scrubber:hover::-moz-range-thumb {
    transform: scale(1.2);
}

/* Chapter Navigation */
.kcr-chapter-navigation {
    display: none;
}

/* Keyboard Shortcuts Help Box */
.kcr-help-overlay {
    position: absolute;
    bottom: 50px;
    left: 50%;
    transform: translateX(-50%);
    display: none;
    z-index: 100;
}

.kcr-help-dialog {
    background: rgba(26, 26, 26, 0.95);
    padding: 20px 25px;
    border-radius: 6px;
    position: relative;
    border: 1px solid #00d9ff;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(10px);
}

.kcr-help-close {
    position: absolute;
    top: 5px;
    right: 8px;
    background: transparent;
    border: none;
    color: #999;
    font-size: 20px;
    cursor: pointer;
    line-height: 1;
    padding: 0;
    width: 20px;
    height: 20px;
    transition: color 0.2s;
}

.kcr-help-close:hover {
    color: #00d9ff;
}

.kcr-help-dialog h2 {
    color: #fff;
    margin: 0 0 15px 0;
    font-size: 16px;
    text-align: center;
    font-weight: 600;
}

.kcr-help-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px 15px;
}

.kcr-help-item {
    display: flex;
    align-items: center;
    gap: 10px;
}

.kcr-help-item kbd {
    background: #2a2a2a;
    border: 1px solid #444;
    border-radius: 3px;
    padding: 4px 8px;
    font-family: monospace;
    font-size: 12px;
    color: #00d9ff;
    min-width: 45px;
    text-align: center;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
}

.kcr-help-item span {
    color: #ccc;
    font-size: 12px;
    white-space: nowrap;
}

/* Responsive */
@media (max-width: 768px) {
    /* Always show controls on mobile */
    .kcr-controls-bar {
        padding: 6px 0;  /* Remove horizontal padding for full width */
        opacity: 1 !important;
        transform: translateY(0) !important;
        pointer-events: auto !important;
    }

    .kcr-controls-wrapper {
        padding: 0 5px;  /* Minimal padding for edge protection */
    }

    .kcr-page-scrubber-container {
        min-width: 200px;  /* Ensure scrubber has minimum width */
    }

    .kcr-page-counter {
        font-size: 11px;
    }

    .kcr-control-btn {
        padding: 4px 6px;
    }

    .kcr-control-btn .dashicons {
        font-size: 16px;
    }

    .kcr-fullscreen-btn {
        display: inline-flex !important; /* Show fullscreen on mobile */
    }

    .kcr-help-overlay {
        bottom: 45px;
        left: 10px;
        right: 10px;
        transform: none;
    }

    .kcr-help-dialog {
        padding: 15px 20px;
    }

    .kcr-help-grid {
        grid-template-columns: 1fr;
        gap: 8px;
    }
}
