:root {
    --bg-primary: #000000;
    --bg-elevated: #0a0f14;
    --bg-card: rgba(10, 15, 20, 0.6);
    --text-primary: #ffffff;
    --text-secondary: rgba(255, 255, 255, 0.7);
    --text-muted: rgba(255, 255, 255, 0.4);
    --border-subtle: rgba(255, 255, 255, 0.06);
    --border-default: rgba(255, 255, 255, 0.1);

    --teal-400: #2dd4bf;
    --teal-500: #14b8a6;
    --purple-500: #a855f7;
    --accent-color: #2dd4bf;
    --accent-glow: rgba(45, 212, 191, 0.3);

    --font-inter: 'Inter', sans-serif;
    --font-mono: 'JetBrains Mono', monospace;

    --focus-guide-distance: 150px;
}

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

/* Generic hidden class */
.hidden {
    display: none !important;
}

body {
    font-family: var(--font-inter);
    background: var(--bg-primary);
    color: var(--text-primary);
    overflow: hidden;
    /* App-like feel */
    height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Backgrounds */
.bg-layer {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: -1;
}

.bg-grid {
    /* Minimal grid - only visible when not reading */
    background-image:
        linear-gradient(rgba(255, 255, 255, 0.015) 1px, transparent 1px),
        linear-gradient(90deg, rgba(255, 255, 255, 0.015) 1px, transparent 1px);
    background-size: 80px 80px;
    opacity: 0.5;
    transition: opacity 0.5s ease;
}

/* Hide grid during reading for zero distraction */
body.reading-mode .bg-grid {
    opacity: 0;
}

.bg-ambient {
    /* Very subtle ambient glow - creates depth without distraction */
    background:
        radial-gradient(ellipse 80% 50% at 50% 50%, rgba(20, 184, 166, 0.03) 0%, transparent 70%);
    transition: opacity 0.5s ease;
}

body.reading-mode .bg-ambient {
    opacity: 0.5;
}

.bg-particles {
    opacity: 0.6;
    transition: opacity 0.5s ease;
}

body.reading-mode .bg-particles {
    opacity: 0.3;
}

/* Layout */
.app-container {
    display: flex;
    flex-direction: column;
    height: 100%;
    position: relative;
    z-index: 1;
}

/* Header */
.app-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 2rem;
    padding-top: calc(1rem + env(safe-area-inset-top, 0px));
    border-bottom: 1px solid var(--border-subtle);
    background: rgba(0, 0, 0, 0.2);
    backdrop-filter: blur(10px);
}

.logo,
.logo:visited,
.logo:hover,
.logo:active {
    display: flex;
    align-items: baseline;
    gap: 16px;
    text-decoration: none;
    color: inherit;
}

.logo-brand {
    font-family: 'Montserrat', sans-serif;
    font-size: 1.1rem;
    font-weight: 500;
    color: var(--text-primary);
    letter-spacing: -0.02em;
}

.logo-subtitle {
    font-family: 'Montserrat', sans-serif;
    font-size: 1.1rem;
    font-weight: 300;
    color: var(--text-muted);
    letter-spacing: -0.02em;
}

/* Main Area */
.reader-area {
    flex: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
    padding: 2rem;
    overflow: hidden;
}

/* Vignette overlay to mask particles at edges */
.reader-area::before {
    content: '';
    position: absolute;
    inset: 0;
    pointer-events: none;
    z-index: 1;
    background:
        radial-gradient(ellipse 70% 60% at 50% 50%, transparent 30%, rgba(0, 0, 0, 0.8) 100%);
}

body.light-theme .reader-area::before {
    background:
        radial-gradient(ellipse 70% 60% at 50% 50%, transparent 30%, rgba(245, 245, 245, 0.9) 100%);
}

.view {
    width: 100%;
    max-width: 800px;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    transition: opacity 0.3s ease, transform 0.3s ease;
}

.view.hidden {
    display: none;
    opacity: 0;
    pointer-events: none;
}

.view.active {
    opacity: 1;
    transform: translateY(0);
}

@property --card-gradient-angle {
    syntax: '<angle>';
    initial-value: 0deg;
    inherits: false;
}

@keyframes card-border-spin {
    to {
        --card-gradient-angle: 360deg;
    }
}

/* Drop Zone / Setup */
.drop-zone {
    position: relative;
    width: 70vw;
    max-width: 900px;
    background: linear-gradient(#000, #000) padding-box,
        conic-gradient(from var(--card-gradient-angle),
            transparent 0%,
            var(--teal-500) 5%,
            var(--teal-400) 15%,
            var(--purple-500) 25%,
            var(--teal-500) 35%,
            transparent 45%) border-box;
    border: 2px solid transparent;
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.1);
    border-radius: 16px;
    padding: 3rem;
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
    overflow: hidden;
    animation: card-border-spin 6s linear infinite;
}

/* Bottom glow */
.drop-zone::before {
    content: '';
    pointer-events: none;
    position: absolute;
    inset: 0;
    background: radial-gradient(circle at 50% 120%, rgba(20, 184, 166, 0.15), transparent 60%);
    z-index: 0;
    border-radius: inherit;
}

/* Animated dot pattern */
.drop-zone::after {
    content: '';
    pointer-events: none;
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    z-index: 0;
    width: calc(100% - 6px);
    height: calc(100% - 6px);
    background: radial-gradient(circle at 2px 2px, rgba(255, 255, 255, 0.3) 0.5px, transparent 0) padding-box;
    background-size: 4px 4px;
    background-repeat: space;
    -webkit-mask-image: conic-gradient(from calc(var(--card-gradient-angle) + 45deg),
            black,
            transparent 10% 90%,
            black);
    mask-image: conic-gradient(from calc(var(--card-gradient-angle) + 45deg),
            black,
            transparent 10% 90%,
            black);
    border-radius: inherit;
    opacity: 0.4;
}

.drop-zone:hover,
.drop-zone.drag-active {
    animation: card-border-spin 4s linear infinite;
}

.drop-zone:hover::after,
.drop-zone.drag-active::after {
    opacity: 0.6;
}

.drop-icon {
    width: 48px;
    height: 48px;
    color: var(--teal-400);
    margin-bottom: 1rem;
    position: relative;
    z-index: 1;
}

.drop-zone h2 {
    font-size: 1.5rem;
    font-weight: 600;
    position: relative;
    z-index: 1;
}

.drop-zone p {
    color: var(--text-secondary);
    position: relative;
    z-index: 1;
}

#text-input {
    position: relative;
    z-index: 1;
    width: 100%;
    height: 150px;
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid var(--border-default);
    border-radius: 8px;
    padding: 1rem;
    color: var(--text-primary);
    font-family: var(--font-inter);
    resize: none;
    margin-top: 1rem;
}

#text-input:focus {
    outline: none;
    border-color: var(--teal-400);
}

.input-actions {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    margin-top: 1.5rem;
    width: 100%;
    max-width: 400px;
    margin-left: auto;
    margin-right: auto;
    position: relative;
    z-index: 1;
}

.input-actions>.btn {
    width: 100%;
}

.input-actions .demo-selector {
    width: 100%;
}

/* Reader Display - Optimized for sustained focus */
.rsvp-display-container {
    position: relative;
    width: 100%;
    height: 400px;
    display: flex;
    align-items: center;
    justify-content: center;
    /* Subtle vignette effect to guide eyes to center - very gradual fade */
    background: radial-gradient(ellipse 80% 60% at 50% 50%, transparent 0%, transparent 60%, rgba(0, 0, 0, 0.1) 100%);
}

body.light-theme .rsvp-display-container {
    background: none;
}

.rsvp-word-container {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: baseline;
    width: 100%;
    max-width: 800px;
    padding: 0 1rem;
    box-sizing: border-box;
    /* Prevent overflow */
    overflow: hidden;
    /* Ensure text sits above focus indicators */
    position: relative;
    z-index: 2;
}

.rsvp-left {
    text-align: right;
    white-space: pre;
    overflow: hidden;
    text-overflow: clip;
    min-width: 0;
    /* Allow grid item to shrink */
}

.rsvp-pivot {
    color: var(--teal-400);
    /* Default accent, will be overridden by JS */
    text-align: center;
    transform: scale(1.1);
    /* Slight emphasis */
    font-weight: 700;
    flex-shrink: 0;
}

.rsvp-right {
    text-align: left;
    white-space: pre;
    overflow: hidden;
    text-overflow: clip;
    min-width: 0;
    /* Allow grid item to shrink */
}

.rsvp-word {
    /* Legacy class for fallback or general font styling inherittence */
    font-size: clamp(2rem, 8vw, 5rem);
    /* Responsive font sizing */
    font-weight: 500;
    color: var(--text-primary);
    line-height: 1.2;
    /* Extra space for descenders (y, g, p, q, j) */
    display: contents;
    /* Allows children to participate in the grid */
}

/* Focus Indicators - ORP guides for eye anchoring */
.focus-indicator-top,
.focus-indicator-bottom {
    position: absolute;
    width: 2px;
    height: 40px;
    opacity: 0.6;
    left: 50%;
    transform: translateX(-50%);
    z-index: 0;
    transition: opacity 0.3s ease;
}

.focus-indicator-top {
    top: var(--focus-guide-distance);
    background: linear-gradient(to bottom, transparent, var(--accent-color, var(--teal-400)));
}

.focus-indicator-bottom {
    bottom: var(--focus-guide-distance);
    background: linear-gradient(to top, transparent, var(--accent-color, var(--teal-400)));
}

/* More prominent during reading */
body.reading-mode .focus-indicator-top,
body.reading-mode .focus-indicator-bottom {
    opacity: 0.8;
}


/* Stats Display */
.stats-container {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    margin-top: 2rem;
    font-size: 0.85rem;
    color: var(--text-muted);
    font-family: var(--font-mono);
}

.stats-divider {
    opacity: 0.4;
}

#word-position,
#time-remaining {
    letter-spacing: 0.02em;
}

/* Progress Bar - Subtle, peripheral awareness */
.progress-container {
    width: 100%;
    max-width: 700px;
    height: 3px;
    background: rgba(255, 255, 255, 0.06);
    border-radius: 2px;
    margin-top: 1rem;
    position: relative;
}

.progress-bar {
    height: 100%;
    background: var(--accent-color);
    width: 0%;
    border-radius: 2px;
    transition: width 0.15s linear;
    box-shadow: 0 0 10px color-mix(in srgb, var(--accent-color) 35%, transparent);
}

/* Checkpoint Markers on Timeline */
.checkpoint-markers {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

.checkpoint-marker {
    position: absolute;
    top: 50%;
    transform: translate(-50%, -50%);
    width: 8px;
    height: 8px;
    background: var(--purple-500);
    border-radius: 50%;
    opacity: 0.8;
    box-shadow: 0 0 6px rgba(168, 85, 247, 0.5);
    transition: opacity 0.3s ease, transform 0.3s ease;
}

.checkpoint-marker.answered {
    background: var(--teal-400);
    box-shadow: 0 0 6px rgba(45, 212, 191, 0.5);
    opacity: 0.5;
}

.checkpoint-marker:hover {
    transform: translate(-50%, -50%) scale(1.3);
    opacity: 1;
}

/* Countdown Display - inline with word area */
.countdown-display {
    font-size: 6rem !important;
    font-weight: 700;
    font-family: var(--font-mono) !important;
    text-shadow: 0 0 40px rgba(45, 212, 191, 0.5);
    animation: countdownPulse 1s ease-in-out;
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

.countdown-number {
    font-size: 8rem;
    font-weight: 700;
    color: var(--teal-400);
    font-family: var(--font-mono);
    text-shadow: 0 0 40px rgba(45, 212, 191, 0.5);
    animation: countdownPulse 1s ease-in-out;
}

@keyframes countdownPulse {
    0% {
        transform: scale(1.2);
        opacity: 0;
    }

    20% {
        transform: scale(1);
        opacity: 1;
    }

    80% {
        transform: scale(1);
        opacity: 1;
    }

    100% {
        transform: scale(0.8);
        opacity: 0;
    }
}

.countdown-text {
    font-size: 1.2rem;
    color: var(--text-secondary);
    margin-top: 1rem;
}

/* Quiz Transition Overlay - smooth fade between reading and quiz */
.quiz-transition-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: #000;
    opacity: 0;
    z-index: 999;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

.quiz-transition-overlay.visible {
    opacity: 1;
}

#progress-text {
    position: absolute;
    right: 0;
    top: 10px;
    font-size: 0.75rem;
    color: var(--text-muted);
    font-family: var(--font-mono);
    letter-spacing: 0.05em;
    opacity: 0.6;
}

/* Control Bar - Minimal, unobtrusive design */
.control-bar {
    height: 100px;
    background: rgba(0, 0, 0, 0.4);
    border-top: 1px solid rgba(255, 255, 255, 0.04);
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 3rem;
    padding-bottom: env(safe-area-inset-bottom, 0px);
    backdrop-filter: blur(24px);
    transition: opacity 0.3s ease, transform 0.3s ease;
    /* Hidden by default, shown only in reading mode */
    opacity: 0;
    pointer-events: none;
    transform: translateY(100%);
}

/* Show control bar during reading */
body.reading-mode .control-bar {
    opacity: 1;
    pointer-events: auto;
    transform: translateY(0);
}

/* Fade control bar slightly during active reading */
body.reading-mode.is-playing .control-bar {
    opacity: 0.85;
}

body.reading-mode.is-playing .control-bar:hover {
    opacity: 1;
}

.control-group {
    display: flex;
    align-items: center;
    gap: 1rem;
    flex: 1;
}

.control-group.center {
    justify-content: center;
}

.control-group.right {
    justify-content: flex-end;
}

.control-group.left {
    justify-content: flex-start;
}

/* Buttons & Inputs */
.btn {
    border: none;
    border-radius: 8px;
    padding: 10px 20px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-family: var(--font-inter);
}

.btn--primary {
    position: relative;
    overflow: hidden;
    border-radius: 9999px;
    padding: 12px 24px;
    font-size: 1rem;
    font-weight: 500;
    color: #ffffff;
    justify-content: center;
    background: linear-gradient(#000000, #000000) padding-box,
        conic-gradient(from var(--card-gradient-angle),
            transparent 0%,
            var(--teal-500) 10%,
            var(--teal-400) 20%,
            var(--purple-500) 30%,
            var(--teal-500) 40%,
            transparent 50%) border-box;
    border: 2px solid transparent;
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.1);
    cursor: pointer;
    isolation: isolate;
    animation: card-border-spin 3s linear infinite;
}

.btn--primary::before {
    content: '';
    position: absolute;
    inset: 0;
    background: radial-gradient(circle at 50% 120%, rgba(20, 184, 166, 0.15), transparent 60%);
    pointer-events: none;
}

.btn--primary span,
.btn--primary i,
.btn--primary svg {
    position: relative;
    z-index: 2;
}

.btn--primary:hover {
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.15),
        0 0 30px rgba(20, 184, 166, 0.4);
}

.btn--primary:active {
    transform: translateY(1px);
}

.icon-btn {
    background: transparent;
    border: 1px solid var(--border-default);
    color: var(--text-secondary);
    width: 40px;
    height: 40px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}

.icon-btn:hover {
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-primary);
    border-color: var(--border-subtle);
}

.btn--circle {
    border-radius: 50%;
    padding: 0;
}

.icon-btn--large {
    width: 72px;
    height: 72px;
    background: #e5e5e5;
    color: #000;
    border: none;
    box-shadow: 0 4px 24px rgba(255, 255, 255, 0.15),
        0 0 0 1px rgba(255, 255, 255, 0.1);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.icon-btn--large svg {
    width: 28px;
    height: 28px;
    margin-left: 3px;
    /* Optical centering for play icon */
}

.icon-btn--large:hover {
    background: #ffffff;
    transform: scale(1.08);
    box-shadow: 0 6px 28px rgba(255, 255, 255, 0.2),
        0 0 0 1px rgba(255, 255, 255, 0.15);
}

.icon-btn--large:active {
    transform: scale(0.98);
    box-shadow: 0 2px 12px rgba(255, 255, 255, 0.15);
}

.wpm-control {
    display: flex;
    align-items: center;
    gap: 12px;
}

.wpm-label {
    font-size: 0.9rem;
    color: var(--text-secondary);
}

.wpm-value {
    font-family: var(--font-mono);
    width: 80px;
    text-align: right;
    font-size: 0.9rem;
}

/* Slider Styling */
input[type=range] {
    -webkit-appearance: none;
    appearance: none;
    width: 180px;
    background: transparent;
}

input[type=range]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    height: 16px;
    width: 16px;
    border-radius: 50%;
    background: var(--accent-color);
    cursor: pointer;
    margin-top: -6px;
}

input[type=range]::-webkit-slider-runnable-track {
    width: 100%;
    height: 4px;
    cursor: pointer;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 2px;
}

select {
    background: transparent;
    color: var(--text-primary);
    border: 1px solid var(--border-default);
    padding: 6px 12px;
    border-radius: 6px;
    cursor: pointer;
}

select:focus {
    outline: none;
    border-color: var(--teal-400);
}

/* Color Picker */
input[type="color"] {
    -webkit-appearance: none;
    appearance: none;
    border: none;
    width: 32px;
    height: 32px;
    background: none;
    cursor: pointer;
}

input[type="color"]::-webkit-color-swatch-wrapper {
    padding: 0;
}

input[type="color"]::-webkit-color-swatch {
    border: 1px solid var(--border-default);
    border-radius: 6px;
}

/* Animations */
@keyframes spin {
    100% {
        transform: rotate(360deg);
    }
}

.spin {
    animation: spin 1s linear infinite;
}

.setting-item {
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--text-secondary);
}

.setting-item svg {
    width: 18px;
    height: 18px;
}

/* SVG Icon Styling */
.icon-btn svg,
.btn svg {
    width: 20px;
    height: 20px;
}

.icon-btn--large svg {
    width: 24px;
    height: 24px;
}

.drop-icon svg {
    width: 48px;
    height: 48px;
}

#start-icon svg {
    width: 18px;
    height: 18px;
}

/* Responsive Design - Large Desktop */
@media (min-width: 1400px) {
    .rsvp-display-container {
        height: 500px;
    }

    .rsvp-word {
        font-size: 6rem;
    }

    .progress-container {
        max-width: 800px;
    }

    .icon-btn--large {
        width: 80px;
        height: 80px;
    }

    .icon-btn--large svg {
        width: 32px;
        height: 32px;
    }
}

/* Responsive Design - Tablet */
@media (max-width: 1024px) {
    .control-bar {
        padding: 0 2rem;
    }

    input[type=range] {
        width: 140px;
    }

    .focus-indicator-top {
        top: 18%;
        height: 30px;
    }

    .focus-indicator-bottom {
        bottom: 18%;
        height: 30px;
    }
}

/* Responsive Design - Mobile */
@media (max-width: 640px) {
    .app-header {
        padding: 1rem 1.25rem;
    }

    .logo {
        gap: 12px;
    }

    .logo-brand {
        font-size: 1.2rem;
    }

    .logo-subtitle {
        font-size: 1.2rem;
    }

    .reader-area {
        padding: 1rem;
    }

    .drop-zone {
        padding: 2rem 1.5rem;
        margin: 0;
        border-radius: 12px;
    }

    .drop-zone h2 {
        font-size: 1.25rem;
    }

    #text-input {
        height: 120px;
        font-size: 16px;
        /* Prevents zoom on iOS */
    }

    .rsvp-display-container {
        height: 220px;
        padding: 0 0.5rem;
    }

    .rsvp-word {
        font-size: clamp(1.8rem, 10vw, 3rem);
    }

    .rsvp-word-container {
        width: 100%;
        padding: 0 0.75rem;
        max-width: 100%;
    }

    .rsvp-left,
    .rsvp-right {
        max-width: 45vw;
    }

    .focus-indicator-top {
        top: 15%;
        height: 20px;
    }

    .focus-indicator-bottom {
        bottom: 15%;
        height: 20px;
    }

    .stats-container {
        font-size: 0.75rem;
        gap: 8px;
        margin-top: 1.5rem;
    }

    .progress-container {
        max-width: 100%;
        margin-top: 0.75rem;
    }

    #progress-text {
        font-size: 0.65rem;
    }

    .control-bar {
        height: auto;
        flex-direction: column;
        padding: 1.25rem 1rem;
        padding-bottom: calc(1.25rem + env(safe-area-inset-bottom, 0px));
        gap: 1rem;
    }

    .control-group {
        width: 100%;
        justify-content: center !important;
    }

    .control-group.left {
        display: none;
        /* Hide back button on mobile - can use swipe */
    }

    .control-group.center {
        order: -1;
    }

    .icon-btn--large {
        width: 64px;
        height: 64px;
    }

    .icon-btn--large svg {
        width: 24px;
        height: 24px;
    }

    .wpm-control {
        width: 100%;
        justify-content: center;
        gap: 10px;
    }

    .wpm-label {
        font-size: 0.85rem;
    }

    .wpm-value {
        font-size: 0.85rem;
        width: 70px;
    }

    input[type=range] {
        flex: 1;
        max-width: 160px;
        width: auto;
    }

    .settings-panel {
        left: 10px;
        right: 10px;
        width: auto;
        top: 55px;
    }
}

/* Responsive Design - Small Mobile */
@media (max-width: 480px) {
    .logo-subtitle {
        display: none;
    }

    .rsvp-word {
        font-size: 2.5rem;
    }

    .icon-btn--large {
        width: 56px;
        height: 56px;
    }

    .wpm-label {
        display: none;
    }
}

/* Responsive Design - Very Small Mobile */
@media (max-width: 360px) {
    .logo-brand {
        font-size: 1rem;
    }

    .app-header {
        padding: 0.75rem 1rem;
    }

    .drop-zone {
        padding: 1.5rem 1rem;
    }

    .drop-zone h2 {
        font-size: 1.1rem;
    }

    .rsvp-word {
        font-size: 2rem;
    }

    .rsvp-display-container {
        height: 180px;
    }

    .focus-indicator-top {
        top: 12%;
        height: 15px;
    }

    .focus-indicator-bottom {
        bottom: 12%;
        height: 15px;
    }

    .icon-btn--large {
        width: 48px;
        height: 48px;
    }

    .icon-btn--large svg {
        width: 20px;
        height: 20px;
    }

    .stats-container {
        font-size: 0.65rem;
        flex-wrap: wrap;
        justify-content: center;
    }

    .control-bar {
        padding: 1rem 0.75rem;
    }

    input[type=range] {
        max-width: 120px;
    }
}

/* Light Theme */
body.light-theme {
    --bg-primary: #f5f5f5;
    --bg-elevated: #ffffff;
    --bg-card: rgba(255, 255, 255, 0.9);
    --text-primary: #1a1a1a;
    --text-secondary: rgba(0, 0, 0, 0.65);
    --text-muted: rgba(0, 0, 0, 0.4);
    --border-subtle: rgba(0, 0, 0, 0.06);
    --border-default: rgba(0, 0, 0, 0.12);
}

body.light-theme .bg-grid {
    background-image:
        linear-gradient(rgba(0, 0, 0, 0.02) 1px, transparent 1px),
        linear-gradient(90deg, rgba(0, 0, 0, 0.02) 1px, transparent 1px);
}

body.light-theme .bg-ambient {
    background:
        radial-gradient(ellipse 80% 50% at 50% 50%, rgba(20, 184, 166, 0.04) 0%, transparent 70%);
}

body.light-theme .app-header {
    background: rgba(255, 255, 255, 0.8);
}

body.light-theme #text-input {
    background: rgba(0, 0, 0, 0.03);
}

body.light-theme .icon-btn--large {
    background: #d4d4d4;
    color: #000;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1),
        0 0 0 1px rgba(0, 0, 0, 0.05);
}

body.light-theme .icon-btn--large:hover {
    background: #c4c4c4;
    box-shadow: 0 6px 28px rgba(0, 0, 0, 0.15),
        0 0 0 1px rgba(0, 0, 0, 0.08);
}

body.light-theme input[type=range]::-webkit-slider-runnable-track {
    background: rgba(0, 0, 0, 0.15);
}

body.light-theme .progress-container {
    background: rgba(0, 0, 0, 0.1);
}

body.light-theme select {
    background: #fff;
}

body.light-theme .drop-zone {
    background: linear-gradient(#fff, #fff) padding-box,
        conic-gradient(from var(--card-gradient-angle),
            transparent 0%,
            var(--teal-500) 5%,
            var(--teal-400) 15%,
            var(--purple-500) 25%,
            var(--teal-500) 35%,
            transparent 45%) border-box;
    box-shadow:
        inset 0 0 0 1px rgba(0, 0, 0, 0.06),
        0 4px 24px rgba(0, 0, 0, 0.08);
}

body.light-theme .drop-zone::before {
    background: radial-gradient(circle at 50% 120%, rgba(20, 184, 166, 0.1), transparent 60%);
}

body.light-theme .drop-zone::after {
    background: radial-gradient(circle at 2px 2px, rgba(0, 0, 0, 0.15) 0.5px, transparent 0) padding-box;
    background-size: 4px 4px;
    background-repeat: space;
}

/* Settings Panel */
.settings-panel {
    position: fixed;
    top: 60px;
    right: 20px;
    width: 320px;
    background: var(--bg-elevated);
    border: 1px solid var(--border-default);
    border-radius: 16px;
    padding: 20px;
    z-index: 100;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(20px);
    transition: opacity 0.2s ease, transform 0.2s ease;
}

.settings-panel.hidden {
    opacity: 0;
    pointer-events: none;
    transform: translateY(-10px);
}

.settings-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--border-subtle);
}

.settings-header h3 {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary);
}

.settings-group {
    margin-bottom: 20px;
}

.settings-group:last-child {
    margin-bottom: 0;
}

.settings-group label {
    display: block;
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-bottom: 8px;
    font-weight: 500;
}

.settings-group select {
    width: 100%;
    padding: 10px 12px;
    font-size: 0.9rem;
}

.settings-group optgroup {
    font-weight: 600;
    color: var(--text-muted);
}

.slider-control {
    display: flex;
    align-items: center;
    gap: 12px;
}

.slider-control input[type="range"] {
    flex: 1;
}

.slider-control span {
    min-width: 60px;
    text-align: right;
    font-family: var(--font-mono);
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.color-control {
    display: flex;
    align-items: center;
    gap: 12px;
}

.color-control input[type="color"] {
    width: 40px;
    height: 40px;
}

.color-control span {
    font-family: var(--font-mono);
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.icon-btn--small {
    width: 32px;
    height: 32px;
}

.icon-btn--small svg {
    width: 16px;
    height: 16px;
}

.header-controls {
    display: flex;
    align-items: center;
    gap: 8px;
}

/* Light theme settings panel */
body.light-theme .settings-panel {
    background: rgba(255, 255, 255, 0.95);
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.15);
}

/* Keyboard Shortcuts Overlay */
.shortcuts-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(8px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 200;
    transition: opacity 0.2s ease;
}

.shortcuts-overlay.hidden {
    opacity: 0;
    pointer-events: none;
}

.shortcuts-panel {
    background: var(--bg-elevated);
    border: 1px solid var(--border-default);
    border-radius: 16px;
    padding: 24px 32px;
    max-width: 480px;
    width: 90%;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}

.shortcuts-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--border-subtle);
}

.shortcuts-header h3 {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text-primary);
}

.shortcuts-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px 24px;
}

.shortcut-item {
    display: flex;
    align-items: center;
    gap: 12px;
}

.shortcut-item kbd {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 32px;
    height: 28px;
    padding: 0 8px;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid var(--border-default);
    border-radius: 6px;
    font-family: var(--font-mono);
    font-size: 0.8rem;
    color: var(--text-primary);
}

.shortcut-item span {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.shortcuts-tip {
    margin-top: 20px;
    padding-top: 16px;
    border-top: 1px solid var(--border-subtle);
    font-size: 0.8rem;
    color: var(--text-muted);
    text-align: center;
}

/* Light theme shortcuts */
body.light-theme .shortcuts-overlay {
    background: rgba(255, 255, 255, 0.85);
}

body.light-theme .shortcuts-panel {
    background: #fff;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.2);
}

body.light-theme .shortcut-item kbd {
    background: rgba(0, 0, 0, 0.05);
}

/* Mobile shortcuts */
@media (max-width: 480px) {
    .shortcuts-panel {
        padding: 20px;
    }

    .shortcuts-grid {
        grid-template-columns: 1fr;
        gap: 10px;
    }

    .shortcut-item kbd {
        min-width: 40px;
    }
}

/* Quiz Prompt */
.quiz-prompt {
    margin-top: 2rem;
    padding: 2rem 2.5rem;
    background: rgba(10, 15, 20, 0.8);
    backdrop-filter: blur(20px);
    border: 1px solid rgba(168, 85, 247, 0.3);
    border-radius: 16px;
    text-align: center;
    animation: slideUp 0.3s ease, quizCardPulse 3s ease-in-out infinite;
}

.quiz-prompt.hidden {
    display: none;
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }

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

@keyframes quizCardPulse {

    0%,
    100% {
        box-shadow: 0 0 0 0 rgba(168, 85, 247, 0.3);
    }

    50% {
        box-shadow: 0 0 20px 4px rgba(168, 85, 247, 0.2);
    }
}

.quiz-prompt p {
    font-size: 1.2rem;
    color: var(--text-primary);
    margin-bottom: 1.5rem;
    font-weight: 500;
}

.quiz-prompt-actions {
    display: flex;
    gap: 16px;
    justify-content: center;
}

/* Final Score Display (shown at end of reading) */
.final-score-display {
    margin-bottom: 1.5rem;
}

.final-score-display h3 {
    font-size: 1.5rem;
    color: var(--teal-400);
    margin-bottom: 1rem;
    font-weight: 600;
}

.final-score-display .score-number {
    font-size: 3rem;
    font-weight: 700;
    color: var(--text-primary);
    font-family: var(--font-mono);
}

.final-score-display .score-percentage {
    font-size: 1.5rem;
    color: var(--teal-400);
    margin: 0.5rem 0;
    font-weight: 500;
}

.final-score-display .score-message {
    font-size: 1rem;
    color: var(--text-secondary);
    margin-top: 0.5rem;
}

.btn--secondary {
    background: transparent;
    border: 1px solid var(--border-default);
    color: var(--text-secondary);
}

.btn--secondary:hover {
    background: rgba(255, 255, 255, 0.05);
    border-color: var(--text-muted);
}

/* Demo Selector */
.demo-selector {
    display: flex;
    flex-direction: column;
    gap: 10px;
    align-items: stretch;
}

.demo-select {
    padding: 12px 16px;
    background: var(--bg-elevated);
    border: 1px solid var(--border-default);
    border-radius: 8px;
    color: var(--text-primary);
    font-size: 0.9rem;
    font-family: inherit;
    cursor: pointer;
    width: 100%;
    text-align: center;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2394a3b8' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 36px;
}

.demo-select:hover {
    border-color: var(--text-muted);
}

.demo-select:focus {
    outline: none;
    border-color: var(--teal-400);
}

.demo-select option {
    background: var(--bg-elevated);
    color: var(--text-primary);
    padding: 8px;
}

.demo-selector .btn {
    width: 100%;
}

/* Quiz Container */
.quiz-container {
    width: 100%;
    max-width: 700px;
    padding: 2rem;
    position: relative;
    animation: quizFadeIn 0.4s ease-out;
}

@keyframes quizFadeIn {
    from {
        opacity: 0;
        transform: scale(0.95) translateY(10px);
    }

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

/* Quiz Progress Bar */
.quiz-progress {
    width: 100%;
    height: 6px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 3px;
    margin-bottom: 2rem;
    overflow: hidden;
}

.quiz-progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--purple-500), var(--teal-400));
    border-radius: 3px;
    transition: width 0.3s ease;
}

.quiz-header {
    margin-bottom: 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

#question-counter {
    font-family: var(--font-mono);
    font-size: 0.9rem;
    color: var(--text-muted);
    letter-spacing: 0.05em;
}

/* Question Card with Pulsing Border */
.quiz-question {
    margin-bottom: 2rem;
    padding: 2rem;
    background: rgba(10, 15, 20, 0.8);
    backdrop-filter: blur(20px);
    border: 1px solid rgba(168, 85, 247, 0.3);
    border-radius: 16px;
    animation: quizCardPulse 3s ease-in-out infinite;
}

#question-text {
    font-size: 1.3rem;
    line-height: 1.7;
    color: var(--text-primary);
    font-weight: 500;
}

/* Quiz Options */
.quiz-options {
    display: flex;
    flex-direction: column;
    gap: 14px;
    margin-bottom: 1.5rem;
}

.quiz-option {
    width: 100%;
    padding: 1.25rem 1.5rem;
    background: rgba(15, 20, 30, 0.6);
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 12px;
    font-size: 1.05rem;
    color: var(--text-primary);
    text-align: left;
    cursor: pointer;
    transition: all 0.25s ease;
    position: relative;
    overflow: hidden;
}

.quiz-option .option-letter {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    background: rgba(45, 212, 191, 0.2);
    border: 1px solid var(--teal-400);
    border-radius: 6px;
    font-weight: 700;
    font-size: 0.9rem;
    color: var(--teal-400);
    margin-right: 1rem;
    font-family: var(--font-mono);
    transition: all 0.2s ease;
}

.quiz-option:hover:not(:disabled) .option-letter {
    background: var(--teal-400);
    color: #000;
    transform: scale(1.1);
}

.quiz-option.correct .option-letter {
    background: #22c55e;
    border-color: #22c55e;
    color: #000;
}

.quiz-option.incorrect .option-letter {
    background: #ef4444;
    border-color: #ef4444;
    color: #fff;
}

.quiz-option::before {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: 12px;
    padding: 2px;
    background: linear-gradient(135deg, transparent, transparent);
    -webkit-mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
    mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
    -webkit-mask-composite: xor;
    mask-composite: exclude;
    opacity: 0;
    transition: opacity 0.25s ease;
}

.quiz-option:hover:not(:disabled) {
    background: rgba(45, 212, 191, 0.1);
    border-color: var(--teal-400);
    transform: translateY(-2px);
    box-shadow: 0 4px 20px rgba(45, 212, 191, 0.15);
}

.quiz-option:hover:not(:disabled)::before {
    background: linear-gradient(135deg, var(--teal-400), var(--purple-500));
    opacity: 1;
}

.quiz-option:disabled {
    cursor: default;
}

.quiz-option.correct {
    background: rgba(34, 197, 94, 0.2);
    border-color: #22c55e;
    color: #22c55e;
    box-shadow: 0 0 20px rgba(34, 197, 94, 0.3);
    animation: correctPop 0.4s ease;
}

@keyframes correctPop {
    0% {
        transform: scale(1);
    }

    50% {
        transform: scale(1.02);
    }

    100% {
        transform: scale(1);
    }
}

.quiz-option.incorrect {
    background: rgba(239, 68, 68, 0.2);
    border-color: #ef4444;
    color: #ef4444;
    animation: incorrectShake 0.4s ease;
}

@keyframes incorrectShake {

    0%,
    100% {
        transform: translateX(0);
    }

    25% {
        transform: translateX(-5px);
    }

    75% {
        transform: translateX(5px);
    }
}

/* Quiz Feedback */
.quiz-feedback {
    padding: 1.25rem 1.5rem;
    border-radius: 12px;
    margin-bottom: 1.5rem;
    backdrop-filter: blur(10px);
}

.quiz-feedback.correct {
    background: rgba(34, 197, 94, 0.15);
    border: 1px solid rgba(34, 197, 94, 0.4);
}

.quiz-feedback.correct strong {
    color: #22c55e;
    font-size: 1.1rem;
}

.quiz-feedback.incorrect {
    background: rgba(239, 68, 68, 0.15);
    border: 1px solid rgba(239, 68, 68, 0.4);
}

.quiz-feedback.incorrect strong {
    color: #ef4444;
    font-size: 1.1rem;
}

.quiz-feedback p {
    margin-top: 0.75rem;
    font-size: 0.95rem;
    color: var(--text-secondary);
    line-height: 1.6;
}

/* Quiz Loading */
.quiz-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 3rem;
    gap: 1rem;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid rgba(255, 255, 255, 0.1);
    border-top-color: var(--teal-400);
    border-right-color: var(--purple-500);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

.quiz-loading-text {
    color: var(--text-muted);
    font-size: 0.9rem;
}

.quiz-error {
    color: #ef4444;
    text-align: center;
    padding: 1.5rem;
    background: rgba(239, 68, 68, 0.1);
    border-radius: 12px;
    border: 1px solid rgba(239, 68, 68, 0.3);
}

/* Quiz Results */
.quiz-results {
    text-align: center;
    padding: 3rem 2rem;
}

.quiz-results.hidden,
.quiz-feedback.hidden,
#quiz-question-view.hidden {
    display: none;
}

.quiz-results h2 {
    font-size: 1.75rem;
    margin-bottom: 2rem;
    color: var(--text-primary);
    font-weight: 600;
}

.quiz-score {
    margin-bottom: 2.5rem;
    padding: 2rem;
    background: rgba(10, 15, 20, 0.6);
    backdrop-filter: blur(20px);
    border-radius: 16px;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.score-number {
    font-size: 4.5rem;
    font-weight: 700;
    background: linear-gradient(135deg, var(--teal-400), var(--purple-500));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    font-family: var(--font-mono);
}

.score-percentage {
    font-size: 1.75rem;
    color: var(--text-secondary);
    margin-bottom: 0.75rem;
}

.score-message {
    font-size: 1.1rem;
    color: var(--text-muted);
}

.quiz-results-actions {
    display: flex;
    gap: 16px;
    justify-content: center;
}

/* Particle effects container */
.quiz-particle {
    position: fixed;
    pointer-events: none;
    z-index: 9999;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    animation: particleBurst 0.8s ease-out forwards;
}

@keyframes particleBurst {
    0% {
        opacity: 1;
        transform: translate(0, 0) scale(1);
    }

    100% {
        opacity: 0;
        transform: translate(var(--tx), var(--ty)) scale(0);
    }
}

/* Light theme quiz */
body.light-theme .quiz-prompt {
    background: rgba(255, 255, 255, 0.9);
    border-color: rgba(168, 85, 247, 0.3);
}

body.light-theme .quiz-question {
    background: rgba(255, 255, 255, 0.9);
}

body.light-theme .quiz-option {
    background: rgba(255, 255, 255, 0.8);
}

body.light-theme .quiz-option:hover:not(:disabled) {
    background: rgba(20, 184, 166, 0.1);
}

body.light-theme .quiz-score {
    background: rgba(255, 255, 255, 0.8);
}

body.light-theme .btn--secondary {
    background: transparent;
    border-color: var(--border-default);
    color: var(--text-secondary);
}

body.light-theme .btn--secondary:hover {
    background: rgba(0, 0, 0, 0.05);
}

/* Mobile quiz */
@media (max-width: 640px) {
    .quiz-container {
        padding: 1rem;
    }

    .quiz-question {
        padding: 1.5rem;
    }

    #question-text {
        font-size: 1.15rem;
    }

    .quiz-option {
        padding: 1rem 1.25rem;
        font-size: 1rem;
    }

    .score-number {
        font-size: 3.5rem;
    }

    .quiz-results-actions {
        flex-direction: column;
    }
}

/* Very small mobile quiz */
@media (max-width: 360px) {
    .quiz-question {
        padding: 1rem;
    }

    #question-text {
        font-size: 1rem;
    }

    .quiz-option {
        padding: 0.875rem 1rem;
        font-size: 0.9rem;
    }

    .quiz-option .option-letter {
        width: 24px;
        height: 24px;
        font-size: 0.8rem;
        margin-right: 0.75rem;
    }

    .score-number {
        font-size: 2.5rem;
    }
}