/* Global Styles */
:root {
    --bg-color: #121212;
    /* Deep Charcoal / Matte Black */
    --card-bg: #1e1e1e;
    /* Slightly lighter for cards */
    --text-primary: #f5f5f7;
    /* Off-white / Ivory */
    --text-secondary: #a0a0a0;
    --accent-color: #d4af37;
    /* Muted Gold / Bronze */
    --hover-color: #2c2c2c;
    --font-main: 'Inter', system-ui, -apple-system, sans-serif;
    --glass-border: 1px solid rgba(255, 255, 255, 0.08);
}

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

body {
    background-color: var(--bg-color);
    color: var(--text-primary);
    font-family: var(--font-main);
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
}

a {
    text-decoration: none;
    color: inherit;
    transition: color 0.2s;
}

a:hover {
    color: var(--accent-color);
}

/* Layout */
.container {
    max-width: 1400px;
    /* Wider for gallery feel */
    margin: 0 auto;
    padding: 20px;
}

header {
    display: flex;
    justify-content: center;
    /* Center logo for museum feel */
    align-items: center;
    padding: 30px 0;
    margin-bottom: 40px;
    border-bottom: var(--glass-border);
}

.logo {
    font-size: 1.8rem;
    font-weight: 300;
    /* Thinner, elegant font */
    letter-spacing: 1px;
    color: var(--text-primary);
    text-transform: uppercase;
}

/* Tab Navigation */
.tabs-container {
    margin-bottom: 30px;
}

.tabs {
    display: flex;
    gap: 10px;
    border-bottom: 2px solid #333;
    padding-bottom: 0;
}

.tab-button {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    padding: 12px 24px;
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
    border-bottom: 3px solid transparent;
    transition: color 0.2s, border-color 0.2s;
    position: relative;
    top: 2px;
}

.tab-button:hover {
    color: var(--text-primary);
}

.tab-button.active {
    color: var(--accent-color);
    border-bottom-color: var(--accent-color);
}

/* Grid Layout for Main Page */
/* Grid Layout for Main Page */
.manga-grid {
    display: grid;
    /* Mobile First: 2 columns */
    grid-template-columns: repeat(2, 1fr);
    gap: 16px;
    padding-bottom: 40px;
}

/* Tablet/Desktop: Adaptive */
@media (min-width: 600px) {
    .manga-grid {
        grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
        gap: 24px;
    }
}

.manga-card {
    background-color: transparent;
    /* Gallery style: minimal container */
    overflow: hidden;
    cursor: pointer;
    transition: transform 0.3s ease, opacity 0.3s;
    border: none;
    border-radius: 0;
    /* Sharp corners for "Art" feel, or minimal radius */
}

/* Hover Effect: Subtle lift */
.manga-card:hover {
    transform: translateY(-4px);
    opacity: 0.9;
    /* No heavy box-shadow, keep it clean */
}

.card-image {
    width: 100%;
    aspect-ratio: 2/3;
    /* Standard Manga Ratio */
    background-color: #2a2a2a;
    object-fit: cover;
    display: block;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.3);
    /* Soft shadow behind the "Canvas" */
    margin-bottom: 10px;
}

.card-info {
    padding: 4px 0;
    /* Minimal padding */
}

.card-title {
    font-size: 0.95rem;
    font-weight: 500;
    color: var(--text-primary);
    margin-bottom: 4px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    letter-spacing: 0.02em;
}

.card-author {
    font-size: 0.8rem;
    color: var(--text-secondary);
    font-weight: 300;
}

/* Series Page Styles */
.series-header {
    display: flex;
    gap: 40px;
    margin-bottom: 40px;
}

.series-cover {
    width: 240px;
    /* Slightly smaller for elegance */
    aspect-ratio: 2/3;
    /* Enforce standard ratio */
    object-fit: cover;
    /* Prevent stretching */
    border-radius: 4px;
    /* Minimal radius */
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
}

.series-info h1 {
    font-size: 2.5rem;
    margin-bottom: 10px;
}

.chapter-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.chapter-item {
    padding: 15px;
    background-color: var(--card-bg);
    border-radius: 8px;
    display: flex;
    justify-content: space-between;
    transition: background-color 0.2s;
}

.chapter-item:hover {
    background-color: var(--hover-color);
}

/* Reader Page Styles */
.reader-container {
    width: 100vw;
    height: 100vh;
    background-color: black;
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
    overflow: hidden;
}

.reader-page-wrapper {
    height: 100%;
    width: auto;
    position: relative;
    /* Adjust this to fit the image properly */
    display: flex;
    justify-content: center;
}

.manga-page {
    max-height: 100vh;
    max-width: 100vw;
    object-fit: contain;
    user-select: none;
}

.ocr-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

.ocr-layer .ocr-box {
    pointer-events: auto;
}

/* Overlay / OCR Styles */
.ocr-box {
    position: absolute;
    border: 2px solid rgba(255, 71, 87, 0.5);
    /* Semi-transparent border */
    background-color: rgba(255, 255, 255, 0.1);
    cursor: help;
    transition: background-color 0.2s, border-color 0.2s;
    z-index: 20;
    /* Ensure clicks are captured above navigation (z-index: 10) */
}

.ocr-box:hover {
    background-color: rgba(255, 255, 255, 0.2);
    border-color: var(--accent-color);
}

/* Popover */
.popover {
    position: absolute;
    background: white;
    color: #333;
    padding: 15px;
    border-radius: 8px;
    width: 300px;
    box-shadow: 0 5px 20px rgba(0, 0, 0, 0.5);
    z-index: 1000;
    pointer-events: none;
    /* Let clicks pass through if needed, or make it interactive */
    opacity: 0;
    transform: translateY(10px);
    transition: opacity 0.2s, transform 0.2s;
}

.popover.visible {
    opacity: 1;
    transform: translateY(0);
    pointer-events: auto;
}

.popover-controls {
    margin-bottom: 10px;
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 8px;
}

.popover-toggle {
    background: #f0f0f0;
    border: 1px solid #ccc;
    border-radius: 4px;
    padding: 4px 8px;
    font-size: 0.85rem;
    cursor: pointer;
    transition: background-color 0.2s;
}

.popover-toggle:hover {
    background: #e0e0e0;
}

.popover-japanese {
    font-size: 1.2rem;
    font-weight: bold;
    margin-bottom: 10px;
    display: block;
    line-height: 2;
}

/* Ruby annotation styles */
ruby {
    ruby-align: center;
    font-size: 1em;
    margin: 0 2px;
}

rt {
    font-size: 0.5em;
    color: #666;
    font-weight: normal;
    line-height: 1.2;
}

/* Word tokens */
.popover-japanese span {
    display: inline-block;
    margin: 0 2px;
}

.speaker-icon {
    display: inline-block;
    width: 24px;
    height: 24px;
    margin-right: 4px;
    vertical-align: middle;
    cursor: pointer;
    opacity: 0.8;
    transition: opacity 0.2s, transform 0.1s;
    background-repeat: no-repeat;
    background-position: center;
    background-size: contain;
    border-radius: 50%;
    border: 1px solid rgba(255, 255, 255, 0.2);
    background-color: rgba(255, 255, 255, 0.1);
}

.speaker-icon.female {
    /* Pinkish tint for Female */
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='%23ff9ff3'%3E%3Cpath d='M3 9v6h4l5 5V4L7 9H3zm13.5 3c0-1.77-1.02-3.29-2.5-4.03v8.05c1.48-.73 2.5-2.25 2.5-4.02zM14 3.23v2.06c2.89.86 5 3.54 5 6.71s-2.11 5.85-5 6.71v2.06c4.01-.91 7-4.49 7-8.77s-2.99-7.86-7-8.77z'/%3E%3C/svg%3E");
    border-color: rgba(255, 159, 243, 0.3);
}

.speaker-icon.male {
    /* Blueish tint for Male */
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='%2354a0ff'%3E%3Cpath d='M3 9v6h4l5 5V4L7 9H3zm13.5 3c0-1.77-1.02-3.29-2.5-4.03v8.05c1.48-.73 2.5-2.25 2.5-4.02zM14 3.23v2.06c2.89.86 5 3.54 5 6.71s-2.11 5.85-5 6.71v2.06c4.01-.91 7-4.49 7-8.77s-2.99-7.86-7-8.77z'/%3E%3C/svg%3E");
    border-color: rgba(84, 160, 255, 0.3);
}

.speaker-icon:hover {
    opacity: 1;
    transform: scale(1.1);
}

.speaker-icon:active {
    transform: scale(0.95);
}

.word-segment {
    display: inline-block;
    vertical-align: top;
    margin: 0 3px;
    cursor: pointer;
    position: relative;
    border-bottom: 1px dotted rgba(255, 255, 255, 0.3);
    transition: background-color 0.2s, border-color 0.2s;
    border-radius: 4px;
    padding: 0 2px;
}

.word-segment:hover,
.word-segment.active {
    background-color: rgba(255, 255, 255, 0.1);
    border-bottom-color: var(--accent-color);
}

/* Tooltip for Gloss */
.gloss-tooltip {
    position: absolute;
    /* Default position setup for "below" */
    top: 0;
    left: 0;
    transform: translateX(-50%);
    /* Center horizontally */
    background-color: #222;
    /* Slightly darker/solid */
    color: #fff;
    padding: 10px 14px;
    border-radius: 8px;
    font-size: 0.95rem;
    /* Slightly larger for readability */
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.8);
    /* Stronger shadow */
    z-index: 2000;
    /* Ensure it's on top of everything */
    width: max-content;
    max-width: 250px;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.15s, transform 0.15s;
    text-align: center;
    border: 2px solid #555;
    /* Solid border for visibility */
}

.gloss-tooltip.visible {
    opacity: 1;
    pointer-events: auto;
    /* transform is handled in JS or just relies on left/top */
}

/* Arrow defaults to pointing UP (for tooltip below word) */
.gloss-tooltip::after {
    content: '';
    position: absolute;
    bottom: 100%;
    /* At the top of the tooltip */
    left: 50%;
    margin-left: -8px;
    /* Slightly larger */
    border-width: 8px;
    border-style: solid;
    border-color: transparent transparent #555 transparent;
    /* Points up, matches border color */
}

/* Optional: Inner arrow to match background if we want border effect, 
   but simplistic solid arrow is fine for "no transparent" request */


.gloss-content {
    display: block;
    margin-bottom: 4px;
    line-height: 1.4;
}

.gloss-pos {
    display: block;
    font-size: 0.75rem;
    color: var(--accent-color);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.popover-translation {
    font-size: 1rem;
    margin-bottom: 10px;
    padding-bottom: 10px;
    border-bottom: 1px solid #eee;
}

.popover-grammar {
    font-size: 0.9rem;
    background: #f5f5f5;
    padding: 10px;
    border-radius: 4px;
}

.popover-words {
    font-size: 0.85rem;
    color: var(--text-secondary, #666);
    margin-bottom: 10px;
    padding-bottom: 10px;
    border-bottom: 1px solid #eee;
}

.popover-words:empty {
    display: none;
}

/* Reader progress bar and episode controls */
.reader-controls {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 20;
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 12px 20px 16px;
    background: linear-gradient(to top, rgba(0, 0, 0, 0.9), transparent);
    pointer-events: none;
}

.reader-controls>* {
    pointer-events: auto;
}

.episode-nav {
    flex-shrink: 0;
    background: rgba(255, 255, 255, 0.15);
    border: 1px solid rgba(255, 255, 255, 0.3);
    color: white;
    padding: 8px 14px;
    border-radius: 6px;
    font-size: 0.9rem;
    cursor: pointer;
    transition: background 0.2s, border-color 0.2s;
}

.episode-nav:hover:not(:disabled) {
    background: rgba(255, 255, 255, 0.25);
    border-color: var(--accent-color);
}

.episode-nav:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.progress-group {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
}

#page-progress {
    flex: 1;
    min-width: 80px;
    height: 6px;
    -webkit-appearance: none;
    appearance: none;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 3px;
}

#page-progress::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--accent-color);
    cursor: pointer;
    transition: transform 0.15s;
}

#page-progress::-webkit-slider-thumb:hover {
    transform: scale(1.1);
}

#page-progress::-moz-range-thumb {
    width: 16px;
    height: 16px;
    border: none;
    border-radius: 50%;
    background: var(--accent-color);
    cursor: pointer;
}

.page-indicator {
    flex-shrink: 0;
    color: rgba(255, 255, 255, 0.9);
    font-size: 0.9rem;
    min-width: 4ch;
}

/* Immersive Mode - Toggle Controls */
.ui-hidden #back-button,
.ui-hidden .reader-controls {
    opacity: 0 !important;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

/* Nav buttons fade out but remain clickable */
.ui-hidden #nav-prev,
.ui-hidden #nav-next {
    opacity: 0;
    pointer-events: auto;
    /* Enable clicks even when invisible */
    transition: opacity 0.3s ease;
}

#back-button,
.reader-controls,
#nav-prev,
#nav-next {
    transition: opacity 0.3s ease;
}
#nav-prev,
#nav-next {
    transition: opacity 0.3s ease;
}

/* ===================================
   Word Alignment Highlighting Styles
   =================================== */

/* English word segments in translation */
.en-word {
    transition: background-color 0.2s ease;
    padding: 0 2px;
    border-radius: 2px;
    display: inline;
}

.en-word.highlight {
    background-color: rgba(255, 215, 0, 0.5);  /* Gold highlight */
}

/* Japanese word segments - clickable indicator */
.word-segment {
    cursor: pointer;
    transition: background-color 0.2s ease;
}

.word-segment:hover {
    background-color: rgba(100, 149, 237, 0.2);  /* Light cornflower blue on hover */
}

.word-segment.active {
    background-color: rgba(100, 149, 237, 0.4);  /* Cornflower blue for active */
    border-radius: 2px;
}

/* Age Verification Modal */
.age-verification-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.85);
    backdrop-filter: blur(5px);
    z-index: 2000;
    display: flex;
    justify-content: center;
    align-items: center;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
}

.age-verification-overlay.visible {
    opacity: 1;
    visibility: visible;
}

.age-verification-modal {
    background: #1e1e1e;
    border: 1px solid rgba(212, 175, 55, 0.5);
    border-radius: 12px;
    padding: 30px;
    text-align: center;
    max-width: 400px;
    width: 90%;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
    transform: scale(0.9);
    transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.age-verification-overlay.visible .age-verification-modal {
    transform: scale(1);
}

.age-verification-title {
    color: #d4af37;
    font-family: 'Cinzel', serif;
    font-size: 1.5rem;
    margin-bottom: 15px;
}

.age-verification-text {
    color: #e0e0e0;
    margin-bottom: 25px;
    line-height: 1.5;
}

.age-verification-actions {
    display: flex;
    justify-content: center;
    gap: 15px;
}

.btn-verify {
    padding: 10px 25px;
    border-radius: 6px;
    border: none;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.2s;
    font-family: 'Roboto', sans-serif;
}

.btn-verify-yes {
    background: linear-gradient(135deg, #d4af37, #b48f1f);
    color: #000;
}

.btn-verify-yes:hover {
    filter: brightness(1.1);
    transform: translateY(-2px);
}

.btn-verify-no {
    background: #444;
    color: #fff;
}

.btn-verify-no:hover {
    background: #555;
    transform: translateY(-2px);
}
