/* ============================================
   Amblyopia Reading Therapy - Styles
   ============================================ */

/* CSS Variables */
:root {
    --bg-primary: #1a1a1a;
    --bg-secondary: #2a2a2a;
    --bg-tertiary: #3a3a3a;
    --text-primary: #e0e0e0;
    --text-secondary: #a0a0a0;
    --accent-primary: #4a9eff;
    --accent-secondary: #3a7ecc;
    --error: #ff6b6b;
    --success: #4ecdc4;

    /* Dichoptic colors - calibratable */
    /* Left eye has blue lens (passes cyan, blocks red) */
    /* Right eye has red lens (passes red, blocks cyan) */
    --left-eye-color: #00ffff;
    --right-eye-color: #ff0000;

    --font-main: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    --font-reading: Georgia, 'Times New Roman', serif;
}

/* Reset & Base */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html, body {
    height: 100%;
    /* Prevent pull-to-refresh on mobile */
    overscroll-behavior: none;
}

body {
    font-family: var(--font-main);
    background-color: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    /* iOS safe areas */
    padding-top: env(safe-area-inset-top);
    padding-bottom: env(safe-area-inset-bottom);
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
    /* Prevent text size adjustment on orientation change */
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
    /* Smooth scrolling */
    -webkit-overflow-scrolling: touch;
}

#app {
    min-height: 100vh;
    min-height: -webkit-fill-available;
}

/* Screen Management */
.screen {
    display: none;
    min-height: 100vh;
    padding: 2rem;
}

.screen.active {
    display: block;
}

.container {
    max-width: 800px;
    margin: 0 auto;
}

/* Typography */
h1 {
    font-size: 2.5rem;
    margin-bottom: 0.5rem;
    color: var(--text-primary);
}

h2 {
    font-size: 1.5rem;
    margin-bottom: 1rem;
    color: var(--text-primary);
}

h3 {
    font-size: 1.25rem;
    margin-bottom: 0.75rem;
    color: var(--text-primary);
}

.subtitle {
    font-size: 1.25rem;
    color: var(--text-secondary);
    margin-bottom: 2rem;
}

/* Buttons */
.btn {
    display: inline-block;
    padding: 0.875rem 1.5rem;
    font-size: 1rem;
    font-weight: 500;
    border: none;
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.2s ease;
    text-decoration: none;
    /* Touch-friendly minimum size */
    min-height: 48px;
    /* Prevent double-tap zoom */
    touch-action: manipulation;
    /* Remove tap highlight on mobile */
    -webkit-tap-highlight-color: transparent;
}

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

.btn:active {
    transform: scale(0.98);
}

.btn-primary {
    background-color: var(--accent-primary);
    color: white;
}

.btn-primary:hover:not(:disabled) {
    background-color: var(--accent-secondary);
}

.btn-secondary {
    background-color: var(--bg-tertiary);
    color: var(--text-primary);
}

.btn-secondary:hover:not(:disabled) {
    background-color: #4a4a4a;
}

.btn-icon {
    padding: 0.5rem 0.75rem;
    font-size: 1.25rem;
    background: transparent;
    border: 1px solid var(--bg-tertiary);
}

.btn-icon:hover {
    background-color: var(--bg-tertiary);
}

.btn-group {
    display: flex;
    gap: 1rem;
    margin-top: 1.5rem;
}

/* Info Boxes */
.info-box {
    background-color: var(--bg-secondary);
    border-radius: 12px;
    padding: 1.5rem;
    margin-bottom: 1.5rem;
}

.info-box.warning {
    border-left: 4px solid #ffa500;
}

.info-box ul {
    margin-left: 1.5rem;
    margin-top: 0.5rem;
}

.info-box li {
    margin-bottom: 0.5rem;
}

/* Dichoptic Color Preview */
.red-text {
    color: #ff0000;
    font-weight: bold;
}

.cyan-text {
    color: #00ffff;
    font-weight: bold;
}

/* ============================================
   Calibration Screen
   ============================================ */

.calibration-step {
    text-align: center;
}

.calibration-step.hidden {
    display: none;
}

.test-display {
    background-color: #000;
    padding: 3rem;
    border-radius: 12px;
    margin: 2rem 0;
    min-height: 150px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.test-display.verification {
    gap: 3rem;
}

.test-word {
    font-size: 3rem;
    font-weight: bold;
    font-family: var(--font-reading);
}

.test-word.left-eye {
    color: var(--left-eye-color);
}

.test-word.right-eye {
    color: var(--right-eye-color);
}

/* Color Adjustment Panel */
#color-adjustment {
    background-color: var(--bg-secondary);
    padding: 1.5rem;
    border-radius: 12px;
    margin-top: 2rem;
}

#color-adjustment.hidden {
    display: none;
}

#color-adjustment h4 {
    margin-top: 1.5rem;
    margin-bottom: 0.75rem;
    color: var(--text-secondary);
    font-size: 0.9rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

#color-adjustment h4:first-of-type {
    margin-top: 0.5rem;
}

.color-preview {
    width: 100%;
    height: 40px;
    border-radius: 6px;
    margin-bottom: 1rem;
    border: 2px solid var(--bg-tertiary);
}

.slider-group {
    margin-bottom: 1.5rem;
}

.slider-group label {
    display: block;
    margin-bottom: 0.5rem;
    color: var(--text-secondary);
}

.slider-group input[type="range"] {
    width: calc(100% - 60px);
    margin-right: 10px;
    vertical-align: middle;
    height: 24px;
    -webkit-appearance: none;
    appearance: none;
    background: transparent;
    cursor: pointer;
}

/* Slider track */
.slider-group input[type="range"]::-webkit-slider-runnable-track {
    height: 6px;
    background: var(--bg-tertiary);
    border-radius: 3px;
}

.slider-group input[type="range"]::-moz-range-track {
    height: 6px;
    background: var(--bg-tertiary);
    border-radius: 3px;
}

/* Slider thumb - larger for touch */
.slider-group input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 24px;
    height: 24px;
    background: var(--accent-primary);
    border-radius: 50%;
    margin-top: -9px;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
}

.slider-group input[type="range"]::-moz-range-thumb {
    width: 24px;
    height: 24px;
    background: var(--accent-primary);
    border-radius: 50%;
    border: none;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
}

.slider-group span {
    display: inline-block;
    width: 45px;
    text-align: right;
    color: var(--text-secondary);
}

/* ============================================
   Topic Selection Screen
   ============================================ */

.form-group {
    margin-bottom: 1.5rem;
}

.form-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 500;
}

.form-group input[type="text"],
.form-group input[type="password"],
.form-group select {
    width: 100%;
    padding: 0.875rem 1rem;
    font-size: 16px; /* Prevents iOS zoom on focus */
    background-color: var(--bg-secondary);
    border: 2px solid var(--bg-tertiary);
    border-radius: 12px;
    color: var(--text-primary);
    transition: border-color 0.2s ease;
    /* Touch-friendly minimum height */
    min-height: 48px;
    /* iOS styling reset */
    -webkit-appearance: none;
    appearance: none;
}

.form-group select {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23a0a0a0' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 1rem center;
    padding-right: 2.5rem;
}

.form-group input:focus,
.form-group select:focus {
    outline: none;
    border-color: var(--accent-primary);
}

.form-group small {
    display: block;
    margin-top: 0.5rem;
    color: var(--text-secondary);
    font-size: 0.875rem;
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}

#generation-status {
    text-align: center;
    padding: 2rem;
}

#generation-status.hidden {
    display: none;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 4px solid var(--bg-tertiary);
    border-top-color: var(--accent-primary);
    border-radius: 50%;
    margin: 0 auto 1rem;
    animation: spin 1s linear infinite;
}

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

.error-message {
    background-color: rgba(255, 107, 107, 0.1);
    border: 1px solid var(--error);
    color: var(--error);
    padding: 1rem;
    border-radius: 8px;
    margin-top: 1rem;
}

.error-message.hidden {
    display: none;
}

/* ============================================
   Reading Screen
   ============================================ */

#reading-screen {
    padding: 0;
    display: flex;
    flex-direction: column;
    background-color: #000;
    /* Full height on mobile */
    height: 100vh;
    height: 100dvh; /* Dynamic viewport height for mobile browsers */
}

#reading-screen.active {
    display: flex;
}

.reading-controls {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 1rem 2rem;
    background-color: var(--bg-secondary);
}

#session-timer {
    font-family: monospace;
    font-size: 1.25rem;
    color: var(--text-secondary);
    margin-left: auto;
    margin-right: 1rem;
}

#reading-content {
    flex: 1;
    padding: 3rem;
    overflow-y: auto;
    font-family: var(--font-reading);
    font-size: 24px;
    line-height: 2;
    word-spacing: 8px;
    max-width: 900px;
    margin: 0 auto;
    width: 100%;
}

#reading-content .word {
    display: inline;
}

#reading-content .word.left-eye {
    color: var(--left-eye-color);
}

#reading-content .word.right-eye {
    color: var(--right-eye-color);
}

#reading-content .sentence {
    display: inline;
}

#reading-content .sentence.left-eye {
    color: var(--left-eye-color);
}

#reading-content .sentence.right-eye {
    color: var(--right-eye-color);
}

#reading-content .letter {
    display: inline;
}

#reading-content .letter.left-eye {
    color: var(--left-eye-color);
}

#reading-content .letter.right-eye {
    color: var(--right-eye-color);
}

/* Reading Settings Panel */
#reading-settings {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background-color: var(--bg-secondary);
    padding: 2rem;
    border-radius: 12px;
    min-width: 350px;
    z-index: 100;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
}

#reading-settings.hidden {
    display: none;
}

#reading-settings .slider-group input[type="range"] {
    width: calc(100% - 70px);
}

#reading-settings .form-group {
    margin-bottom: 1rem;
}

#reading-settings .form-group select {
    width: 100%;
}

#reading-settings .btn {
    width: 100%;
    margin-top: 0.5rem;
}

/* Session Complete Overlay */
#session-complete {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background-color: var(--bg-secondary);
    padding: 2.5rem;
    border-radius: 12px;
    text-align: center;
    z-index: 100;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
}

#session-complete.hidden {
    display: none;
}

#session-complete h2 {
    color: var(--success);
    margin-bottom: 1rem;
}

/* ============================================
   Utility Classes
   ============================================ */

.hidden {
    display: none !important;
}

.text-center {
    text-align: center;
}

/* ============================================
   Responsive Design
   ============================================ */

@media (max-width: 768px) {
    .screen {
        padding: 1rem;
        padding-top: calc(1rem + env(safe-area-inset-top));
        padding-bottom: calc(1rem + env(safe-area-inset-bottom));
    }

    h1 {
        font-size: 1.75rem;
    }

    h2 {
        font-size: 1.25rem;
    }

    .subtitle {
        font-size: 1rem;
    }

    .form-row {
        grid-template-columns: 1fr;
    }

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

    .test-display {
        padding: 2rem;
        min-height: 120px;
    }

    .test-display.verification {
        flex-direction: row;
        gap: 1rem;
    }

    .test-display.verification .test-word {
        font-size: 1.5rem;
    }

    #reading-content {
        padding: 1.25rem;
        padding-bottom: calc(1.25rem + env(safe-area-inset-bottom));
        font-size: 18px;
        line-height: 1.8;
    }

    .reading-controls {
        flex-wrap: wrap;
        padding: 0.75rem 1rem;
        padding-top: calc(0.75rem + env(safe-area-inset-top));
        gap: 0.5rem;
    }

    #reading-settings {
        min-width: auto;
        width: 92%;
        max-width: 350px;
        max-height: 85vh;
        overflow-y: auto;
        padding: 1.5rem;
    }

    #session-complete {
        width: 90%;
        max-width: 320px;
        padding: 1.5rem;
    }

    .info-box {
        padding: 1rem;
    }

    .slider-group input[type="range"] {
        width: calc(100% - 50px);
    }
}

@media (max-width: 480px) {
    .screen {
        padding: 0.75rem;
        padding-top: calc(0.75rem + env(safe-area-inset-top));
        padding-bottom: calc(0.75rem + env(safe-area-inset-bottom));
    }

    h1 {
        font-size: 1.5rem;
    }

    .btn-group {
        flex-direction: column;
    }

    .btn {
        width: 100%;
        text-align: center;
    }

    .container {
        padding: 0;
    }

    #reading-content {
        padding: 1rem;
        font-size: 16px;
        word-spacing: 4px;
    }

    .test-word {
        font-size: 1.5rem;
    }

    .test-display.verification .test-word {
        font-size: 1.25rem;
    }

    #color-adjustment h4 {
        font-size: 0.8rem;
    }

    .color-preview {
        height: 30px;
    }
}

/* iPhone specific - Dynamic Island / Notch handling */
@media (max-width: 430px) {
    .reading-controls {
        justify-content: space-between;
    }

    #session-timer {
        margin-left: 0;
        margin-right: 0;
        font-size: 1rem;
    }

    #back-to-topics-btn {
        font-size: 0.875rem;
        padding: 0.625rem 1rem;
    }
}

/* Landscape mode on mobile */
@media (max-height: 500px) and (orientation: landscape) {
    .screen {
        padding: 0.5rem 1rem;
    }

    h1 {
        font-size: 1.25rem;
        margin-bottom: 0.25rem;
    }

    .subtitle {
        margin-bottom: 1rem;
    }

    .info-box {
        padding: 0.75rem;
        margin-bottom: 0.75rem;
    }

    .test-display {
        padding: 1rem;
        min-height: 80px;
    }

    .test-word {
        font-size: 1.5rem;
    }

    #reading-content {
        padding: 0.5rem 1rem;
    }

    #reading-settings {
        max-height: 90vh;
    }
}
