:root {
    --bg-color: #0c0a15;
    --surface-color: rgba(255, 255, 255, 0.05);
    --border-color: rgba(255, 255, 255, 0.1);
    --text-primary: #ffffff;
    --text-secondary: rgba(255, 255, 255, 0.6);
    --accent-color: #7928CA;
    --accent-glow: #FF0080;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: 'Inter', 'Noto Sans Devanagari', sans-serif;
}

body {
    background-color: var(--bg-color);
    color: var(--text-primary);
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    overflow: hidden;
    gap: 30px;
}

/* Phone Mockup Frame */
#phone-frame {
    width: 100vw;
    height: 100vh;
    position: relative;
    background-color: #000;
    overflow: hidden;
}

@media (min-width: 600px) {
    #phone-frame {
        height: 90vh;
        max-height: 812px;
        aspect-ratio: 9 / 16;
        /* Wider than 375/812 */
        width: auto;
        min-width: 420px;
        border-radius: 40px;
        border: 8px solid #1a1a1a;
        box-shadow: 0 0 50px rgba(0, 0, 0, 0.5), 0 0 100px rgba(121, 40, 202, 0.2);
        z-index: 10;
    }
}

/* Side Panels for Facts (Desktop Only) */
.side-panel {
    display: none;
    flex: 1;
    min-width: 250px;
    max-width: 300px;
    height: 100vh;
    padding: 60px 20px;
    position: relative;
    overflow: visible;
    z-index: 1;
}

@media (min-width: 1150px) {
    .side-panel {
        display: flex;
        flex-direction: column;
        justify-content: center;
    }
}

.fact-card {
    background: rgba(255, 255, 255, 0.05);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 20px;
    padding: 30px;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5);
    transform: translateY(20px);
    opacity: 0;
    transition: opacity 0.6s ease, transform 0.6s cubic-bezier(0.16, 1, 0.3, 1), box-shadow 0.3s ease;
}

.fact-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 25px 60px rgba(121, 40, 202, 0.4);
    border-color: rgba(121, 40, 202, 0.5);
}

.fact-card.visible {
    opacity: 1;
    transform: translateY(0);
}

.fact-card h3 {
    font-family: 'Outfit', sans-serif;
    color: var(--accent-glow);
    font-size: 1.3rem;
    margin-bottom: 16px;
    display: flex;
    align-items: center;
    letter-spacing: -0.3px;
}

.learning-path {
    margin-top: 20px;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    padding-top: 20px;
}

.learning-path h4 {
    font-size: 1rem;
    color: var(--accent-glow);
    margin-bottom: 12px;
}

.related-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.related-topic-btn {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: white;
    padding: 8px 16px;
    border-radius: 20px;
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.2s ease;
}

.related-topic-btn:hover {
    background: var(--accent-color);
    border-color: var(--accent-glow);
}

.summary-body {
    padding: 20px 0;
    line-height: 1.6;
    color: rgba(255, 255, 255, 0.9);
    font-size: 1.1rem;
}

#summary-done-btn {
    width: 100%;
    margin-top: 10px;
}

/* Modal shared styles (ensure they are defined or update them) */
.modal {
    display: none;
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.85);
    backdrop-filter: blur(15px);
    z-index: 1000;
    padding: 30px;
    align-items: center;
    justify-content: center;
}

.modal.active {
    display: flex;
}

.fact-card p {
    color: rgba(255, 255, 255, 0.85);
    font-size: 1.05rem;
    line-height: 1.5;
    transition: opacity 0.3s ease;
}

.fact-card.updating p {
    opacity: 0;
}

/* Screens */
.screen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.5s ease-in-out, visibility 0.5s;
    z-index: 10;
}

.screen.active {
    opacity: 1;
    visibility: visible;
    z-index: 20;
}

/* --- Home Screen --- */
#home-screen {
    padding: 40px 24px;
    justify-content: center;
    background: radial-gradient(circle at top left, rgba(121, 40, 202, 0.2), transparent 50%),
        radial-gradient(circle at bottom right, rgba(255, 0, 128, 0.1), transparent 50%);
}

.header h1 {
    font-family: 'Outfit', sans-serif;
    font-size: 42px;
    font-weight: 800;
    line-height: 1.1;
    margin-bottom: 16px;
}

.gradient-text {
    background: linear-gradient(45deg, var(--accent-color), var(--accent-glow));
    background-clip: text;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.header p {
    color: var(--text-secondary);
    font-size: 16px;
    line-height: 1.5;
    margin-bottom: 40px;
}

.input-container {
    position: relative;
    margin-bottom: 30px;
}

input[type="text"] {
    width: 100%;
    background: var(--surface-color);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    padding: 20px 60px 20px 20px;
    border-radius: 16px;
    font-size: 16px;
    outline: none;
    transition: all 0.3s;
    backdrop-filter: blur(10px);
}

input[type="text"]:focus {
    border-color: var(--accent-color);
    box-shadow: 0 0 20px rgba(121, 40, 202, 0.3);
}

#generate-btn {
    position: absolute;
    right: 8px;
    top: 8px;
    bottom: 8px;
    width: 44px;
    border-radius: 12px;
    background: linear-gradient(135deg, var(--accent-color), var(--accent-glow));
    border: none;
    color: white;
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: transform 0.2s;
}

#generate-btn:hover {
    transform: scale(1.05);
}

.suggested-topics {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.badge {
    background: var(--surface-color);
    border: 1px solid var(--border-color);
    padding: 8px 16px;
    border-radius: 20px;
    font-size: 14px;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.2s;
}

.badge:hover {
    background: rgba(255, 255, 255, 0.1);
    color: white;
    border-color: rgba(255, 255, 255, 0.2);
}

/* Side Facts Containers Layout */
.side-facts-container {
    display: flex;
    flex-direction: column;
    gap: 30px;
    width: 100%;
    align-items: center;
}

.side-fact-card {
    position: relative;
    /* Switch to relative for transform-based scatter */
    background: rgba(255, 255, 255, 0.04);
    backdrop-filter: blur(25px);
    -webkit-backdrop-filter: blur(25px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 20px;
    padding: 16px 20px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.4);
    transition: all 0.8s cubic-bezier(0.16, 1, 0.3, 1);
    opacity: 0;
    pointer-events: auto;
    cursor: pointer;
    width: 220px;
}

/* Floating Animation */
@keyframes float {
    0% {
        transform: translate(var(--offset-x, 0), 0) rotate(var(--base-rotation));
    }

    50% {
        transform: translate(calc(var(--offset-x, 0) + var(--float-x, 5px)), var(--float-y, -10px)) rotate(calc(var(--base-rotation) + 2deg));
    }

    100% {
        transform: translate(var(--offset-x, 0), 0) rotate(var(--base-rotation));
    }
}

.side-fact-card.floating {
    animation: float var(--float-duration, 6s) ease-in-out infinite;
}

/* --- Quiz Screen --- */
#quiz-screen {
    padding: 40px 24px;
    justify-content: center;
    background: radial-gradient(circle at top right, rgba(121, 40, 202, 0.2), transparent 60%),
        radial-gradient(circle at bottom left, rgba(0, 212, 255, 0.1), transparent 60%);
}

.quiz-container {
    background: rgba(255, 255, 255, 0.03);
    backdrop-filter: blur(20px);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 24px;
    padding: 30px 20px;
    margin-bottom: 20px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
}

#quiz-question {
    font-size: 1.25rem;
    line-height: 1.4;
    margin-bottom: 24px;
    text-align: center;
    color: white;
}

.options-grid {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.quiz-option {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    padding: 16px 20px;
    border-radius: 16px;
    color: var(--text-primary);
    font-size: 1rem;
    cursor: pointer;
    transition: all 0.2s ease;
    text-align: left;
}

.quiz-option:hover {
    background: rgba(121, 40, 202, 0.1);
    border-color: rgba(121, 40, 202, 0.5);
    transform: translateX(5px);
}

.quiz-option.correct {
    background: rgba(0, 255, 128, 0.15);
    border-color: rgba(0, 255, 128, 0.6);
}

.quiz-option.wrong {
    background: rgba(255, 0, 85, 0.15);
    border-color: rgba(255, 0, 85, 0.6);
}

.quiz-footer {
    display: flex;
    justify-content: center;
}

#finish-quiz-btn,
#next-quiz-btn {
    background: linear-gradient(135deg, var(--accent-color), var(--accent-glow));
    border: none;
    color: white;
    padding: 14px 32px;
    border-radius: 20px;
    font-size: 1.05rem;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
    box-shadow: 0 5px 20px rgba(121, 40, 202, 0.4);
}

#finish-quiz-btn:hover,
#next-quiz-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 25px rgba(121, 40, 202, 0.6);
}

.side-fact-card.visible {
    opacity: 1;
    /* Base transforms will be set via JS: scale, rotate, translate */
}

.side-fact-card:hover {
    transform: scale(1.1) rotate(0deg) !important;
    z-index: 100 !important;
    box-shadow: 0 20px 50px rgba(121, 40, 202, 0.4);
    border-color: rgba(121, 40, 202, 0.6);
    background: rgba(255, 255, 255, 0.08);
}

.side-fact-card h4 {
    color: var(--accent-glow);
    font-size: 1.15rem;
    margin-bottom: 12px;
    font-family: 'Outfit', sans-serif;
    display: flex;
    align-items: center;
    gap: 8px;
}

.side-fact-card p {
    color: rgba(255, 255, 255, 0.85);
    font-size: 1.05rem;
    line-height: 1.5;
}

/* --- Loading Screen --- */
#loading-screen {
    justify-content: center;
    align-items: center;
    text-align: center;
    padding: 40px;
    background-color: var(--bg-color);
}

.spinner {
    width: 60px;
    height: 60px;
    border: 4px solid var(--surface-color);
    border-top: 4px solid var(--accent-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 30px;
}

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

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

#loading-screen h2 {
    font-family: 'Outfit', sans-serif;
    margin-bottom: 10px;
}

.sub-text {
    color: var(--text-secondary);
    font-size: 14px;
}

/* --- Player Screen --- */
#player-screen {
    background: black;
}

#video-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1;
}

#background-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: opacity 0.5s ease;
    opacity: 0;
    position: absolute;
    top: 0;
    left: 0;
    z-index: 0;
}

.overlay-gradient {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 60%;
    background: linear-gradient(to top, rgba(0, 0, 0, 0.9) 0%, rgba(0, 0, 0, 0) 100%);
}

/* --- Dynamic Visual Effects (Particles) --- */
.theme-particles {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 1;
    overflow: hidden;
    opacity: 0.6;
}

.particle {
    position: absolute;
    background: white;
    border-radius: 50%;
    opacity: 0.3;
    animation: float-particle var(--duration) linear infinite;
}

@keyframes float-particle {
    0% {
        transform: translateY(110vh) translateX(0);
    }

    100% {
        transform: translateY(-10vh) translateX(var(--drift));
    }
}

/* Theme Specifics */

/* Space Theme: Stars */
.space-theme .particle {
    background: #fff;
    box-shadow: 0 0 10px #fff;
    width: 2px;
    height: 2px;
}

/* Nature Theme: Leaves */
.nature-theme .particle {
    background: #4ade80;
    border-radius: 10% 80%;
    width: 8px;
    height: 12px;
}

/* Science Theme: Atoms/Dots */
.science-theme .particle {
    background: var(--accent-glow);
    width: 4px;
    height: 4px;
    box-shadow: 0 0 15px var(--accent-glow);
}

.ui-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 2;
    display: flex;
    flex-direction: column;
}

#progress-container {
    display: flex;
    gap: 4px;
    padding: 16px;
    padding-top: 40px;
    /* Safe area for mobile */
}

.progress-segment {
    flex: 1;
    height: 4px;
    background: rgba(255, 255, 255, 0.3);
    border-radius: 2px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    width: 0%;
    background: white;
    transition: width 0.1s linear;
}

#close-btn {
    position: absolute;
    top: 80px;
    right: 16px;
    background: rgba(0, 0, 0, 0.4);
    border: none;
    color: white;
    font-size: 24px;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    cursor: pointer;
    backdrop-filter: blur(10px);
    display: flex;
    justify-content: center;
    align-items: center;
}

/* --- Captions/Subtitles --- */
.caption-container {
    margin-top: auto;
    padding: 60px 20px;
    text-align: center;
    background: linear-gradient(to top, rgba(0, 0, 0, 0.9) 0%, transparent 100%);
    z-index: 10;
    pointer-events: none;
}

#caption-text {
    font-family: 'Outfit', 'Noto Sans Devanagari', sans-serif;
    font-size: 24px;
    font-weight: 700;
    line-height: 1.4;
    color: #fff;
    text-shadow: 0 2px 10px rgba(0, 0, 0, 0.5);
    display: inline-block;
    padding: 12px 24px;
    background: rgba(0, 0, 0, 0.75);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-radius: 16px;
    border: 1px solid rgba(255, 255, 255, 0.2);
    max-width: 85%;
    margin-bottom: 30px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
    word-wrap: break-word;
    white-space: pre-wrap;
    text-align: center;
}

/* --- Settings & Icons --- */
.top-nav {
    display: flex;
    justify-content: flex-end;
    margin-bottom: 10px;
}

.icon-btn {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--border-color);
    color: white;
    width: 44px;
    height: 44px;
    border-radius: 12px;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    transition: all 0.2s;
}

.icon-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    transform: scale(1.05);
}

/* --- Modal Overlay --- */
.modal-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(8px);
    z-index: 100;
    display: none;
    justify-content: center;
    align-items: center;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.modal-overlay.active {
    display: flex;
    opacity: 1;
}

.modal-content {
    background: var(--surface-color);
    border: 1px solid var(--border-color);
    border-radius: 24px;
    width: 90%;
    max-width: 340px;
    padding: 24px;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5);
    transform: translateY(20px);
    transition: transform 0.3s ease;
}

.modal-overlay.active .modal-content {
    transform: translateY(0);
}

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

.modal-header h3 {
    font-family: 'Outfit', sans-serif;
    font-size: 20px;
    margin: 0;
}

.setting-item {
    margin-bottom: 24px;
}

.setting-item label {
    display: block;
    font-size: 14px;
    color: var(--text-secondary);
    margin-bottom: 10px;
    font-weight: 500;
}

.custom-select,
.custom-input {
    width: 100%;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--border-color);
    color: white;
    padding: 12px;
    border-radius: 12px;
    font-size: 14px;
    outline: none;
    cursor: pointer;
}

.custom-input {
    cursor: text;
}

.custom-input:focus {
    border-color: var(--accent-color);
    background: rgba(255, 255, 255, 0.08);
}

.setting-hint {
    font-size: 12px;
    color: var(--text-secondary);
    margin-top: 8px;
}

.setting-hint a {
    color: var(--accent-color);
    text-decoration: none;
}

.setting-hint a:hover {
    text-decoration: underline;
}

.speed-controls {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
}

.speed-btn {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    padding: 10px 0;
    border-radius: 10px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.speed-btn:hover {
    background: rgba(255, 255, 255, 0.1);
}

.speed-btn.active {
    background: var(--accent-color);
    border-color: var(--accent-glow);
    color: white;
    box-shadow: 0 0 15px rgba(121, 40, 202, 0.3);
}

.flex-between {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

/* --- Toggle Switch --- */
.switch {
    position: relative;
    display: inline-block;
    width: 44px;
    height: 24px;
}

.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(255, 255, 255, 0.1);
    transition: .4s;
    border-radius: 24px;
    border: 1px solid var(--border-color);
}

.slider:before {
    position: absolute;
    content: "";
    height: 16px;
    width: 16px;
    left: 3px;
    bottom: 3px;
    background-color: white;
    transition: .4s;
    border-radius: 50%;
}

input:checked+.slider {
    background-color: var(--accent-color);
    border-color: var(--accent-glow);
}

input:focus+.slider {
    box-shadow: 0 0 1px var(--accent-color);
}

input:checked+.slider:before {
    transform: translateX(20px);
}

/* Animations added by JS */
.fade-in {
    animation: fadeIn 0.5s forwards;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}