/* Base Viewer Styles */
body,
html {
    margin: 0;
    padding: 0;
    /* Background handled by ThemeEngine */
    background: transparent;
    height: 100%;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    color: var(--text-color, #fff);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

.viewer-container {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    z-index: 10;
    overflow: hidden;
    perspective: 1500px;
    width: 100%;
}

.viewer-container.zoomed {
    align-items: flex-start;
    /* Start from top to allow scrolling down */
    justify-content: center;
}

/* Scene holds the pages */
.page-scene {
    position: relative;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    transform-style: preserve-3d;
}

.page-wrapper {
    position: absolute;
    max-height: 90vh;
    max-width: 90vw;
    box-shadow: 0 0 40px rgba(0, 0, 0, 0.5);
    transition: transform 0.1s ease-out;
    transform-origin: center center;
    backface-visibility: hidden;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
}

/* Flipbook Viewport wrapper for Zoom/Pan */
.flipbook-viewport {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    /* Default hidden */
}

/* When zoomed, we override overflow via JS inline styles, but let's prep CSS */
.viewer-container.zoomed .flipbook-viewport {
    overflow: auto;
    /* Enable native scrollbars */
    display: block;
    /* Block layout for scrolling content */
    text-align: center;
    /* Center the flipbook horizontally */
}

/* Ensure scene centers content if blocked */
.viewer-container.zoomed .flipbook-viewport .container {
    display: inline-block;
    padding: 20px;
    /* buffer */
    min-height: 100%;
    vertical-align: middle;
}

.page-image {
    display: block;
    max-height: 90vh;
    max-width: 90vw;
    height: auto;
    width: auto;
    user-select: none;
    -webkit-user-drag: none;
}

/* --- Interaction Layers --- */

.interactions-layer {
    pointer-events: none;
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 10;
}

.interaction-hotspot {
    pointer-events: auto;
    position: absolute;
    cursor: pointer;
    transition: all 0.2s ease;
    /* Border radius matches most icons/buttons */
    border-radius: 4px;
}

/* Interaction Hint Animation */
.interaction-hint-anim {
    animation: interactionPulse 2s ease-out forwards;
    animation-delay: 0.5s;
}

@keyframes interactionPulse {
    0% {
        box-shadow: 0 0 0 0 rgba(255, 255, 255, 0.7);
        background-color: rgba(255, 255, 255, 0.2);
    }

    70% {
        box-shadow: 0 0 0 15px rgba(255, 255, 255, 0);
        background-color: rgba(255, 255, 255, 0);
    }

    100% {
        box-shadow: 0 0 0 0 rgba(255, 255, 255, 0);
        background-color: transparent;
    }
}

.interaction-hotspot:hover {
    transform: scale(1.02);
    z-index: 11;
    box-shadow: 0 0 8px rgba(0, 0, 0, 0.2);
}

.interaction-hotspot:focus-visible {
    outline: 2px solid white;
    outline-offset: 2px;
}

/* --- Interaction Containers --- */

/* Modal Overlay (Generic) */
.interaction-modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.85);
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.3s ease;
    pointer-events: none;
}

.interaction-modal-overlay.active {
    opacity: 1;
    pointer-events: auto;
}

.interaction-modal-content {
    position: relative;
    background: transparent;
    max-width: 90%;
    max-height: 90%;
    border-radius: 8px;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5);
    transform: scale(0.95);
    transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.interaction-modal-overlay.active .interaction-modal-content {
    transform: scale(1);
}

.interaction-close-btn {
    position: absolute;
    top: 10px;
    right: 10px;
    color: white;
    font-size: 30px;
    cursor: pointer;
    background: transparent;
    border: none;
    opacity: 0.8;
    transition: opacity 0.2s;
    z-index: 10002;
}

.interaction-close-btn:hover {
    opacity: 1;
    transform: scale(1.1);
}

/* Mini Audio Player */
.interaction-audio-player {
    position: absolute;
    bottom: 80px;
    /* Above controls */
    right: 20px;
    background: rgba(28, 28, 30, 0.95);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 12px;
    padding: 15px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
    z-index: 9000;
    transform: translateY(20px);
    opacity: 0;
    transition: all 0.3s ease;
    width: 300px;
}

.interaction-audio-player.active {
    transform: translateY(0);
    opacity: 1;
}

.audio-header {
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
    color: #fff;
    font-size: 14px;
    font-weight: 600;
}

.audio-close-btn {
    background: none;
    border: none;
    color: #aaa;
    cursor: pointer;
    font-size: 16px;
}

.audio-close-btn:hover {
    color: #fff;
}

/* Generic Lightbox (Image) */
.interaction-lightbox-img {
    max-width: 90vw;
    max-height: 90vh;
    object-fit: contain;
    border-radius: 4px;
    background: black;
}

/* Quiz Style Overrides */
.quiz-container {
    background: #fff;
    padding: 30px;
    border-radius: 12px;
    width: 100%;
    max-width: 500px;
    text-align: center;
    color: #333;
}

.quiz-title {
    margin-top: 0;
    color: #1a1a1a;
    font-size: 24px;
    margin-bottom: 10px;
}

.quiz-question {
    font-size: 18px;
    color: #555;
    margin-bottom: 25px;
    line-height: 1.5;
}

.quiz-options {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-bottom: 25px;
    text-align: left;
}


.quiz-option-label {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    border: 2px solid #e0e0e0;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
}

.quiz-option-label:hover {
    border-color: #007bff;
    background: #f8f9fa;
}

.quiz-option-label input:checked+span {
    font-weight: 600;
    color: #007bff;
}

.quiz-option-label:has(input:checked) {
    border-color: #007bff;
    background: #e7f1ff;
}

.quiz-submit-btn {
    background: #007bff;
    color: white;
    border: none;
    padding: 12px 30px;
    font-size: 16px;
    font-weight: 600;
    border-radius: 50px;
    cursor: pointer;
    transition: background 0.2s;
    width: 100%;
}

.quiz-submit-btn:hover {
    background: #0056b3;
}

.quiz-submit-btn:disabled {
    background: #ccc;
    cursor: not-allowed;
}

.quiz-feedback {
    margin-top: 20px;
    padding: 15px;
    border-radius: 8px;
    font-size: 15px;
    text-align: left;
    display: none;
    line-height: 1.5;
}

/* --- Animations for Pages --- */

.page-wrapper.hidden {
    display: none;
}

.anim-fade-out {
    animation: fadeOut var(--anim-duration, 0.4s) forwards;
}

.anim-fade-in {
    animation: fadeIn var(--anim-duration, 0.4s) forwards;
}

@keyframes fadeOut {
    to {
        opacity: 0;
    }
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

.anim-slide-out-left {
    animation: slideOutLeft var(--anim-duration, 0.5s) forwards;
}

.anim-slide-in-right {
    animation: slideInRight var(--anim-duration, 0.5s) forwards;
}

.anim-slide-out-right {
    animation: slideOutRight var(--anim-duration, 0.5s) forwards;
}

.anim-slide-in-left {
    animation: slideInLeft var(--anim-duration, 0.5s) forwards;
}

@keyframes slideOutLeft {
    to {
        transform: translate(-150%, -50%);
        opacity: 0;
    }
}

@keyframes slideInRight {
    from {
        transform: translate(50%, -50%);
        opacity: 0;
    }

    to {
        transform: translate(-50%, -50%);
        opacity: 1;
    }
}

@keyframes slideOutRight {
    to {
        transform: translate(50%, -50%);
        opacity: 0;
    }
}

@keyframes slideInLeft {
    from {
        transform: translate(-150%, -50%);
        opacity: 0;
    }

    to {
        transform: translate(-50%, -50%);
        opacity: 1;
    }
}

.anim-flip-out-left {
    animation: flipOutLeft var(--anim-duration, 0.6s) ease-in forwards;
    transform-origin: left center;
}

.anim-flip-in-right {
    animation: flipInRight var(--anim-duration, 0.6s) ease-out forwards;
    transform-origin: right center;
}

.anim-flip-out-right {
    animation: flipOutRight var(--anim-duration, 0.6s) ease-in forwards;
    transform-origin: right center;
}

.anim-flip-in-left {
    animation: flipInLeft var(--anim-duration, 0.6s) ease-out forwards;
    transform-origin: left center;
}

@keyframes flipOutLeft {
    to {
        transform: translate(-50%, -50%) rotateY(-90deg);
        opacity: 0.5;
    }
}

@keyframes flipInRight {
    from {
        transform: translate(-50%, -50%) rotateY(90deg);
        opacity: 0.5;
    }

    to {
        transform: translate(-50%, -50%) rotateY(0);
        opacity: 1;
    }
}

@keyframes flipOutRight {
    to {
        transform: translate(-50%, -50%) rotateY(90deg);
        opacity: 0.5;
    }
}

@keyframes flipInLeft {
    from {
        transform: translate(-50%, -50%) rotateY(-90deg);
        opacity: 0.5;
    }

    to {
        transform: translate(-50%, -50%) rotateY(0);
        opacity: 1;
    }
}

/* Controls */
.controls {
    height: 60px;
    background: var(--toolbar-bg, #222);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    color: var(--toolbar-text, white);
    border-top: 1px solid var(--sidebar-border, rgba(255, 255, 255, 0.1));
    z-index: 100;
    padding: 0 20px;
    /* Ensure no text selection or shrinking breaks UI */
    flex-shrink: 0;
}

@media (max-width: 768px) {
    .controls {
        justify-content: flex-start;
        overflow-x: auto;
        /* Custom scrollbar hiding if needed later */
    }

    /* Hide some less critical buttons on smaller screens to keep it simple */
    #btnFirst,
    #btnLast,
    #btnHome {
        display: none;
    }
}

@media (max-width: 480px) {

    /* Hide separators on very small screens to save space */
    .controls .separator {
        display: none;
    }
}

.controls button {
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    background: rgba(255, 255, 255, 0.05);
    border: none;
    color: inherit;
    border-radius: 4px;
    transition: background 0.2s, transform 0.1s;
    font-size: 16px;
    flex-shrink: 0;
    /* Prevents buttons from squishing when scrolling */
}

.controls button:hover {
    background: rgba(255, 255, 255, 0.2);
}

.controls button:active,
.controls button.active {
    transform: scale(0.95);
    background: rgba(255, 255, 255, 0.3);
    color: #4facfe;
    /* Highlight color */
    box-shadow: inset 0 0 10px rgba(0, 0, 0, 0.2);
}

.page-control {
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 0 10px;
    font-weight: 500;
    min-width: 110px;
    flex-shrink: 0;
}

.page-control input {
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: white;
    padding: 5px;
    border-radius: 4px;
    width: 50px;
    text-align: center;
    font-size: 14px;
}

.separator {
    width: 1px;
    height: 24px;
    background: rgba(255, 255, 255, 0.2);
    margin: 0 10px;
    flex-shrink: 0;
}

/* Theme Layouts */
[data-theme="active"] .controls {
    position: absolute;
    bottom: 30px;
    left: 50%;
    transform: translateX(-50%);
    width: auto;
    height: auto;
    padding: 10px 20px;
    background: rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(10px);
    border-radius: 50px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
    gap: 8px;
    max-width: 90%;
}

[data-theme="active"] .controls {
    overflow-x: auto;
    justify-content: flex-start;
}

[data-theme="active"] .viewer-container {
    height: 100%;
}

[data-theme="refined"] body {
    flex-direction: column-reverse;
}

[data-theme="refined"] .controls {
    border-top: none;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    background: var(--toolbar-bg, #1a1a1a);
}

[data-theme="handy"] .controls {
    position: absolute;
    top: 50%;
    right: 20px;
    transform: translateY(-50%);
    width: auto;
    height: auto;
    flex-direction: column;
    background: transparent;
    border: none;
    gap: 8px;
    padding: 0;
    overflow-x: visible;
    /* Don't scroll vertically placed buttons horizontally */
    overflow-y: auto;
    max-height: 90vh;
}

@media (max-width: 768px) {
    [data-theme="handy"] .controls {
        right: 10px;
        /* Bring it closer to edge on mobile */
    }
}

[data-theme="handy"] .controls button {
    background: rgba(0, 0, 0, 0.6);
    border-radius: 50%;
    width: 44px;
    height: 44px;
    backdrop-filter: blur(4px);
}

[data-theme="handy"] .page-control,
[data-theme="handy"] .separator {
    display: none;
}

[data-theme="handy"] .viewer-container {
    height: 100%;
}

/* --- Viewer Sidebars (Thumbnails & TOC) --- */
.viewer-sidebar {
    position: absolute;
    top: 0;
    left: 0;
    height: calc(100% - 60px);
    /* Subtract toolbar height */
    width: 250px;
    background: rgba(28, 28, 30, 0.95);
    backdrop-filter: blur(10px);
    border-right: 1px solid rgba(255, 255, 255, 0.1);
    z-index: 90;
    /* Below controls (100) */
    transform: translateX(-100%);
    transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    display: flex;
    flex-direction: column;
}

.viewer-sidebar.active {
    transform: translateX(0);
}

.viewer-sidebar.hidden {
    display: flex;
    /* Override general hidden class to keep layout but handle vis with transform */
    transform: translateX(-100%);
    pointer-events: none;
}

/* Ensure it actually hides off-screen */
.viewer-sidebar:not(.active) {
    pointer-events: none;
}

.sidebar-header {
    padding: 15px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    display: flex;
    justify-content: space-between;
    align-items: center;
    color: #fff;
    flex-shrink: 0;
}

.sidebar-header h3 {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
}

.sidebar-close-btn {
    background: none;
    border: none;
    color: #aaa;
    cursor: pointer;
    font-size: 16px;
    padding: 5px;
}

.sidebar-close-btn:hover {
    color: #fff;
}

/* Thumbnails Grid */
.thumbnails-grid {
    flex: 1;
    overflow-y: auto;
    padding: 10px;
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
    align-content: start;
}

.thumbnail-item {
    cursor: pointer;
    border-radius: 4px;
    /* overflow: hidden; */
    position: relative;
    border: 2px solid transparent;
    transition: all 0.2s;
    background: rgba(255, 255, 255, 0.05);
}

.thumbnail-item:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.3);
}

.thumbnail-item.current {
    border-color: #007bff;
    box-shadow: 0 0 0 2px rgba(0, 123, 255, 0.3);
}

.thumbnail-img {
    width: 100%;
    height: auto;
    display: block;
    aspect-ratio: 210/297;
    /* A4 Ratio assumption, will adjust */
    object-fit: cover;
    background: #000;
}

.thumbnail-number {
    position: absolute;
    bottom: 5px;
    right: 5px;
    background: rgba(0, 0, 0, 0.7);
    color: #fff;
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 10px;
    font-weight: bold;
}

/* TOC List */
.toc-list {
    flex: 1;
    overflow-y: auto;
    padding: 10px;
}

.toc-item {
    padding: 10px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    cursor: pointer;
    color: #ddd;
    font-size: 14px;
    transition: background 0.2s;
    border-radius: 4px;
}

.toc-item:hover {
    background: rgba(255, 255, 255, 0.05);
    color: #fff;
}

.toc-item.active {
    background: rgba(0, 123, 255, 0.2);
    color: #007bff;
    font-weight: 500;
}

/* Volume Control */
.volume-control-group {
    display: flex;
    align-items: center;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 4px;
    padding-right: 10px;
    transition: background 0.2s;
}

.volume-control-group:hover {
    background: rgba(255, 255, 255, 0.1);
}

.volume-slider-wrapper {
    width: 0;
    overflow: hidden;
    transition: width 0.3s ease;
    display: flex;
    align-items: center;
}

.volume-control-group:hover .volume-slider-wrapper,
.volume-control-group:focus-within .volume-slider-wrapper {
    width: 80px;
}

#volumeSlider {
    width: 70px;
    height: 4px;
    /* -webkit-appearance: none; appearance: none; */
    /* Keep default for simplicity or style fully */
    cursor: pointer;
    margin-left: 5px;
}

/* Mobile / Responsive Styles */
@media (max-width: 768px) {
    .viewer-sidebar {
        width: 100%;
        height: 50%;
        /* Bottom sheet half height */
        top: auto;
        bottom: 60px;
        /* Above toolbar */
        left: 0;
        border-right: none;
        border-top: 1px solid rgba(255, 255, 255, 0.1);
        transform: translateY(110%);
        border-radius: 12px 12px 0 0;
    }

    .viewer-sidebar.active {
        transform: translateY(0);
    }

    .viewer-sidebar.hidden {
        transform: translateY(110%);
    }



    /* Thumbnails larger on mobile */
    .thumbnails-grid {
        grid-template-columns: repeat(3, 1fr);
    }

    /* Hide volume slider on mobile to save space, maybe just use device volume? 
       Or keep it but condensed. */
    .volume-control-group:hover .volume-slider-wrapper {
        width: 60px;
    }
}

/* Turn.js Flipbook Styles */
.flipbook-viewport {
    overflow: hidden;
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
}

.flipbook-viewport .container {
    position: relative;
    /* Ensure turn.js has a container to center in if needed */
}

.flipbook {
    transition: margin-left 0.25s ease-out;
    -webkit-transition: margin-left 0.25s ease-out;
}

.flipbook .page {
    -webkit-box-shadow: 0 0 20px rgba(0, 0, 0, 0.2);
    -moz-box-shadow: 0 0 20px rgba(0, 0, 0, 0.2);
    -ms-box-shadow: 0 0 20px rgba(0, 0, 0, 0.2);
    -o-box-shadow: 0 0 20px rgba(0, 0, 0, 0.2);
    box-shadow: 0 0 20px rgba(0, 0, 0, 0.2);
    background-color: white;
}

.flipbook .page img.page-content {
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    -khtml-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
    margin: 0;
}

.flipbook .shadow {
    -webkit-box-shadow: 0 0 20px #ccc;
    -moz-box-shadow: 0 0 20px #ccc;
    box-shadow: 0 0 20px #ccc;
}

/* Loader in page */
.flipbook .loader {
    width: 22px;
    height: 22px;
    position: absolute;
    top: 50%;
    left: 50%;
    margin-left: -11px;
    margin-top: -11px;
    border: 2px solid rgba(0, 0, 0, 0.1);
    border-top: 2px solid #555;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

.jumble-slots {
    display: flex;
    justify-content: space-around;
}

@keyframes spin {
    0% {
        transform: rotate(0deg);
    }

    100% {
        transform: rotate(360deg);
    }
}

.flipbook .even {
    background: -webkit-gradient(linear, left top, right top, color-stop(0.95, #fff), color-stop(1, #dadada));
    background-image: -webkit-linear-gradient(left, #fff 95%, #dadada 100%);
    background-image: -moz-linear-gradient(left, #fff 95%, #dadada 100%);
    background-image: -ms-linear-gradient(left, #fff 95%, #dadada 100%);
    background-image: -o-linear-gradient(left, #fff 95%, #dadada 100%);
    background-image: linear-gradient(left, #fff 95%, #dadada 100%);
}

.flipbook .odd {
    background: -webkit-gradient(linear, right top, left top, color-stop(0.95, #fff), color-stop(1, #dadada));
    background-image: -webkit-linear-gradient(right, #fff 95%, #dadada 100%);
    background-image: -moz-linear-gradient(right, #fff 95%, #dadada 100%);
    background-image: -ms-linear-gradient(right, #fff 95%, #dadada 100%);
    background-image: -o-linear-gradient(right, #fff 95%, #dadada 100%);
    background-image: linear-gradient(right, #fff 95%, #dadada 100%);
}

/* --- NEW QUIZ VIEWER STYLES (Unified View) --- */

.quiz-overlay-container {
    background: #f5f7fa;
    width: 100%;
    height: 100%;
    max-width: 900px;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: relative;
    font-family: 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
    color: #333;
    /* Ensure flex child shrinks properly */
    min-height: 0;
}

.quiz-header {
    background: #fff;
    padding: 15px 20px;
    border-bottom: 1px solid #e0e0e0;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.05);
    z-index: 10;
    padding-right: 40px;
    /* Make space for the close button */
}

@media (max-width: 480px) {
    .quiz-header {
        padding: 10px 15px;
        padding-right: 40px;
        flex-direction: column;
        align-items: flex-start;
        gap: 5px;
    }
}

.quiz-header h3 {
    margin: 0;
    font-size: 18px;
    font-weight: 600;
    color: #2c3e50;
}

.quiz-header .quiz-meta {
    font-size: 14px;
    color: #7f8c8d;
}

.quiz-scroll-area {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    scroll-behavior: smooth;
    -webkit-overflow-scrolling: touch;
    /* Ensure flex child scrolls */
    min-height: 0;
}

/* Custom Scrollbar for Quiz */
.quiz-scroll-area::-webkit-scrollbar {
    width: 12px;
}

.quiz-scroll-area::-webkit-scrollbar-track {
    background: #f5f7fa;
    border-left: 1px solid #e0e0e0;
}

.quiz-scroll-area::-webkit-scrollbar-thumb {
    background: #bdc3c7;
    border-radius: 6px;
    border: 3px solid #f5f7fa;
    /* Padding effect */
}

.quiz-scroll-area::-webkit-scrollbar-thumb:hover {
    background: #95a5a6;
}

.quiz-card {
    background: #fff;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
    padding: 20px;
    margin-bottom: 20px;
    border: 1px solid #ecf0f1;
    position: relative;
    transition: transform 0.2s, box-shadow 0.2s;
}

.quiz-card:hover {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
}

.quiz-card.has-error {
    border-color: #e74c3c;
    background-color: #fdf5f5;
}

.quiz-card.is-correct {
    border-color: #27ae60;
    background-color: #f0fcf4;
}

@media (max-width: 480px) {
    .quiz-card {
        padding: 15px;
    }
}

.quiz-question-header {
    display: flex;
    gap: 12px;
    margin-bottom: 15px;
}

.quiz-badge {
    background: #eef2f7;
    color: #5d6d7e;
    font-weight: bold;
    /* font-size: 14px; */
    padding: 4px 10px;
    border-radius: 4px;
    height: fit-content;
    white-space: nowrap;
}

.quiz-question-text {
    /* font-size: 16px; */
    line-height: 1.5;
    font-weight: 500;
    color: #2c3e50;
    flex: 1;
}

.quiz-media {
    margin: 10px 0 20px 0;
    text-align: center;
}

.quiz-media img {
    max-width: 100%;
    border-radius: 6px;
    border: 1px solid #eee;
}

/* Options / Inputs */
.quiz-options-list {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.quiz-option {
    display: flex;
    align-items: flex-start;
    padding: 12px 15px;
    border: 1px solid #dce1e6;
    border-radius: 6px;
    cursor: pointer;
    background: #fff;
    transition: all 0.2s;
}

.quiz-option:hover {
    background-color: #f8f9fa;
    border-color: #bdc3c7;
}

.quiz-option.selected {
    background-color: #e8f4fc;
    border-color: #3498db;
    box-shadow: 0 0 0 1px #3498db inset;
}

/* Match & Jumble Styles */
.match-col {
    background: #fff;
}

.match-item,
.jumble-tile,
.odd-item {
    background: #fff;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    padding: 10px 20px;
}

.quiz-match-container {
    display: flex;
    justify-content: space-between;
}

/* Footer */
.quiz-footer-fixed {
    background: #fff;
    border-top: 1px solid #e0e0e0;
    padding: 15px 20px;
    display: flex;
    gap: 10px;
    justify-content: flex-end;
    box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.05);
    z-index: 20;
    flex-wrap: wrap;
    /* allow wrapping on small screens */
}

@media (max-width: 480px) {
    .quiz-footer-fixed {
        padding: 10px 15px;
        justify-content: center;
    }

    .quiz-footer-fixed button {
        flex: 1;
        /* expand buttons fully */
        font-size: 18px;
        /* Slightly smaller text */
        padding: 10px;
    }
}

.quiz-footer-fixed button {
    padding: 10px 20px;
    border-radius: 6px;
    font-weight: 600;
    font-size: 24px;
    cursor: pointer;
    border: none;
    transition: all 0.2s;
}

.btn-reset {
    background: #f1f3f5;
    color: #495057;
}

.btn-reset:hover {
    background: #e9ecef;
}

.btn-reset:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-answers {
    background: #e3f2fd;
    color: #1976d2;
}

.btn-answers:hover {
    background: #bbdefb;
}

.btn-answers:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    filter: grayscale(1);
}

.btn-submit {
    background: #27ae60;
    color: white;
    min-width: 100px;
    box-shadow: 0 2px 5px rgba(39, 174, 96, 0.3);
}

.btn-submit:hover {
    background: #219150;
    transform: translateY(-1px);
}

.btn-submit:disabled {
    background: #95a5a6;
    cursor: not-allowed;
    box-shadow: none;
    transform: none;
}

/* Inline Feedback */
.quiz-feedback-inline {
    margin-top: 15px;
    padding: 12px;
    border-radius: 6px;
    font-size: 24px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.quiz-feedback-inline.correct {
    background: #d4edda;
    color: #155724;
    border: 1px solid #c3e6cb;
}

.quiz-feedback-inline.incorrect {
    background: #f8d7da;
    color: #721c24;
    border: 1px solid #f5c6cb;
}

.quiz-feedback-inline.hidden {
    display: none;
}

/* Jumbled Sentence Support & Answer Reveal */
.jumble-tile.jumble-word {
    width: auto;
    min-width: 40px;
    padding: 8px 15px;
    border-radius: 4px;
    font-weight: 500;
}

.reveal-correct {
    border: 2px solid #27ae60 !important;
    background-color: #d4edda !important;
    color: #155724 !important;
    position: relative;
}

.reveal-correct::after {
    content: "\f00c";
    /* FontAwesome check */
    font-family: "Font Awesome 6 Free";
    font-weight: 900;
    position: absolute;
    top: -8px;
    right: -8px;
    background: #27ae60;
    color: white;
    border-radius: 50%;
    width: 20px;
    height: 20px;
    font-size: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}

/* Jumbled Word Drag & Drop Styles (Global) */
.jumble-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 15px;
    margin-top: 20px;
}

.jumble-slots {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    justify-content: center;
}

.jumble-tile {
    cursor: grab;
    user-select: none;
    transition: all 0.2s;
}

.jumble-tile:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
}

.jumble-tile:active {
    cursor: grabbing;
}

.jumble-tile.dragging {
    opacity: 0.5;
    background: #e3f2fd;
    border-color: #2196f3;
    transform: scale(0.95);
    cursor: grabbing;
    border-style: dashed;
}

.jumble-tile.drag-over {
    border-color: #4caf50;
    background: #e8f5e9;
    transform: scale(1.05);
    border-style: solid;
}

/* =========================================
   Modern Child-Friendly Quiz UI (Refactor)
   ========================================= */

:root {
    --quiz-primary: #4CAF50;
    /* Soft Green */
    --quiz-primary-dark: #388E3C;
    --quiz-secondary: #26A69A;
    /* Muted Teal */
    --quiz-neutral-bg: #F5F5F5;
    --quiz-text: #37474F;
    --quiz-border: #E0E0E0;
    --quiz-focus: #81C784;
}

/* --- Container: Modern Card Overlay --- */

.quiz-modern-overlay {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    box-sizing: border-box;
}

.quiz-modern-card {
    background: white;
    width: 100%;
    max-width: 600px;
    /* Optimal reading width */
    max-height: 90vh;
    /* Prevent overflow on small screens */
    border-radius: 20px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: popIn 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes popIn {
    from {
        opacity: 0;
        transform: scale(0.9);
    }

    to {
        opacity: 1;
        transform: scale(1);
    }
}

/* --- Header --- */

.quiz-header-modern {
    background: var(--quiz-primary);
    padding: 20px;
    color: white;
    text-align: center;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    z-index: 2;
}

.quiz-header-modern h3 {
    margin: 0;
    font-size: 1.5rem;
    font-weight: 700;
}

/* --- Scrollable Content Area --- */

.quiz-scroll-area {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    background: #FAFAFA;
}

/* --- Question Card --- */

.quiz-card-modern {
    background: white;
    border-radius: 15px;
    padding: 20px;
    margin-bottom: 25px;
    border: 1px solid white;
    /* Invisible border for layout stability */
    transition: all 0.3s ease;
}

.quiz-card-modern:last-child {
    margin-bottom: 50px;
    /* Space for scrolling past last item */
}

/* Visual Feedback States */
.quiz-card-modern.is-correct {
    border: 2px solid var(--quiz-primary);
    background: #E8F5E9;
}

.quiz-card-modern.has-error {
    border: 2px solid #e57373;
    background: #FFEBEE;
}

.quiz-question-text-modern {
    font-size: 1.15rem;
    color: var(--quiz-text);
    font-weight: 600;
    margin-bottom: 15px;
    line-height: 1.5;
}

.quiz-media img {
    border-radius: 12px;
    margin-bottom: 15px;
    max-height: 200px;
    width: auto;
    display: block;
    margin-left: auto;
    margin-right: auto;
}

/* --- Options Grid --- */

.quiz-options-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

@media (max-width: 600px) {
    .quiz-options-grid {
        grid-template-columns: 1fr;
        /* Stack on mobile */
    }
}

/* --- Option Styling --- */

.quiz-option-modern {
    display: flex;
    cursor: pointer;
    border: 2px solid var(--quiz-border);
    border-radius: 12px;
    padding: 12px;
    background: white;
    transition: all 0.2s cubic-bezier(0.25, 0.8, 0.25, 1);
    position: relative;
    overflow: hidden;
}

.quiz-option-modern:hover {
    border-color: var(--quiz-primary-focus, #81C784);
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.05);
}

.quiz-option-modern.selected {
    border-color: var(--quiz-primary);
    background: #E8F5E9;
    /* Very light green */
}

/* Hide actual input */
.quiz-option-modern input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.opt-content {
    width: 100%;
}

.opt-row {
    display: flex;
    align-items: center;
    gap: 10px;
}

.opt-text {
    /* font-size: 1rem; */
    color: #455A64;
    font-weight: 500;
}

.quiz-option-modern.selected .opt-text {
    color: var(--quiz-primary-dark);
    font-weight: 700;
}

/* Custom Check/Radio Indicators */
.custom-check-indicator {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    /* Default to circle (radio look) */
    border: 2px solid #BDBDBD;
    display: flex;
    align-items: center;
    justify-content: center;
    background: white;
    flex-shrink: 0;
    transition: all 0.2s;
}

/* Square for checkbox if needed, or keep circle for child-friendliness. 
   Let's distinguish slightly or just use check icon for everything for simplicity?
   Req says "rounded rectangular option containers". Interaction-viewer uses check icon or radio dot. */

/* When Selected */
.quiz-option-modern.selected .custom-check-indicator {
    background: var(--quiz-primary);
    border-color: var(--quiz-primary);
    color: white;
}

.radio-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: white;
    transform: scale(0);
    transition: transform 0.2s;
}

.quiz-option-modern.selected .radio-dot {
    transform: scale(1);
}

/* --- Footer --- */

.quiz-footer-modern {
    padding: 15px 20px;
    background: white;
    border-top: 1px solid #EEE;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    z-index: 2;
}

.btn-pill {
    flex: 1;
    border: none;
    border-radius: 50px;
    padding: 12px 0;
    font-size: 1rem;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.btn-pill:active {
    transform: scale(0.96);
}

.btn-pill:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    background: #E0E0E0 !important;
    color: #9E9E9E !important;
}

.btn-reset {
    background: #ECEFF1;
    color: #546E7A;
    flex: 0.5;
    /* Smaller */
}

.btn-secondary {
    background: var(--quiz-secondary);
    color: white;
}

.btn-primary {
    background: var(--quiz-primary);
    color: white;
    box-shadow: 0 4px 10px rgba(76, 175, 80, 0.3);
}

.btn-primary:hover:not(:disabled) {
    background: var(--quiz-primary-dark);
}

/* --- Feedback Inline --- */
.quiz-feedback-inline {
    margin-top: 15px;
    padding: 10px;
    border-radius: 8px;
    font-size: 24px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.quiz-feedback-inline.correct {
    color: var(--quiz-primary-dark);
    background: rgba(76, 175, 80, 0.1);
}

.quiz-feedback-inline.incorrect {
    color: #c62828;
    background: rgba(244, 67, 54, 0.1);
}

/* --- Jumble & Match Tweaks --- */
.jumble-tile {
    background: white;
    border: 2px solid var(--quiz-border);
    border-radius: 8px;
    padding: 10px 15px;
    margin: 5px;
    font-weight: bold;
    color: var(--quiz-text);
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.05);
}

.jumble-tile.dragging {
    opacity: 0.5;
    border-color: var(--quiz-primary);
}

.match-item {
    background: white;
    border: 2px solid var(--quiz-border);
    border-radius: 8px;
    padding: 10px;
    margin: 8px 0;
    transition: all 0.2s;
    display: flex;
    flex-direction: column;
}

.match-item.active {
    border-color: var(--quiz-secondary);
    background: #E0F2F1;
}

.match-item.matched {
    border-color: var(--quiz-primary);
    background: #E8F5E9;
    opacity: 0.8;
}

/* Update for Checkbox vs Radio distinction */

.custom-check-indicator.is-radio {
    border-radius: 50%;
}

.custom-check-indicator.is-checkbox {
    border-radius: 6px;
    /* Soft rounded square */
}

/* Fix Icon centering in checkbox */
.custom-check-indicator.is-checkbox i {
    font-size: 14px;
    color: white;
    transform: scale(0);
    transition: transform 0.2s;
}

.quiz-option-modern.selected .custom-check-indicator.is-checkbox i {
    transform: scale(1);
}

input.quiz-blank-input {
    padding: 10px;
    font-size: 24px;
}

.quiz-overlay-container {
    font-size: 24px;
}

.odd-grid {
    display: flex;
}

.odd-grid .odd-item {
    margin-right: 15px;
}

.odd-item.selected {
    background: #27ae60;
    color: #fff;
}

input {
    font-size: 24px
}

/* =========================================
   Modern Quiz Input Overrides (Integration)
   ========================================= */

/* Override the legacy .quiz-option to match .quiz-option-modern */
.quiz-option {
    display: flex !important;
    align-items: center !important;
    padding: 12px 16px !important;
    border: 2px solid #e0e0e0;
    /* var(--quiz-border) */
    border-radius: 12px;
    background: white;
    cursor: pointer !important;
    transition: all 0.2s ease;
    margin-bottom: 10px;
    position: relative;
}

.quiz-option:hover {
    background: #fafafa !important;
    border-color: #81C784 !important;
    /* var(--quiz-primary-focus) */
}

.quiz-option.selected {
    background-color: #e0f2e3 !important;
    /* var(--quiz-primary-light) */
    border-color: #37b34a !important;
    /* var(--quiz-primary) */
}

/* Hide default radio/checkbox appearance and create custom UI */
.quiz-option input[type="radio"],
.quiz-option input[type="checkbox"] {
    appearance: none !important;
    -webkit-appearance: none !important;
    width: 24px !important;
    height: 24px !important;
    border: 2px solid #bdbdbd !important;
    background-color: white !important;
    margin-right: 15px !important;
    margin-top: 0 !important;
    /* Override inline style */
    cursor: pointer !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    position: relative !important;
    flex-shrink: 0 !important;
}

/* Radio Shape */
.quiz-option input[type="radio"] {
    border-radius: 50% !important;
}

/* Checkbox Shape */
.quiz-option input[type="checkbox"] {
    border-radius: 6px !important;
}

/* Checked State - Container */
.quiz-option input[type="radio"]:checked,
.quiz-option input[type="checkbox"]:checked {
    background-color: #37b34a !important;
    /* var(--quiz-primary) */
    border-color: #37b34a !important;
}

/* Radio Indicator (Dot) */
.quiz-option input[type="radio"]::after {
    content: '' !important;
    display: block !important;
    width: 10px !important;
    height: 10px !important;
    background: white !important;
    border-radius: 50% !important;
    transform: scale(0) !important;
    transition: transform 0.2s cubic-bezier(0.4, 0.0, 0.2, 1) !important;
}

.quiz-option input[type="radio"]:checked::after {
    transform: scale(1) !important;
}

/* Checkbox Indicator (Checkmark) */
.quiz-option input[type="checkbox"]::after {
    content: '' !important;
    display: block !important;
    width: 6px !important;
    height: 10px !important;
    border: solid white !important;
    border-width: 0 2px 2px 0 !important;
    transform: rotate(45deg) scale(0) !important;
    margin-top: -2px !important;
    /* Adjust visual center */
    transition: transform 0.2s cubic-bezier(0.4, 0.0, 0.2, 1) !important;
}

.quiz-option input[type="checkbox"]:checked::after {
    transform: rotate(45deg) scale(1) !important;
}

@import 'quiz-modern-styles.css';