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

/* iOS Safari viewport height fix */
:root {
    --vh: 1vh;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, #1a1a2e 0%, #16213e 50%, #0f3460 100%);
    min-height: 100vh;
    min-height: calc(var(--vh, 1vh) * 100);
    min-height: -webkit-fill-available;
    color: #fff;
    /* Prevent iOS Safari from zooming on input focus */
    -webkit-text-size-adjust: 100%;
    /* Improve touch scrolling on iOS */
    -webkit-overflow-scrolling: touch;
}

.container {
    max-width: 900px;
    margin: 0 auto;
    padding: 20px;
    padding-top: calc(20px + env(safe-area-inset-top));
    padding-bottom: calc(20px + env(safe-area-inset-bottom));
    padding-left: calc(20px + env(safe-area-inset-left));
    padding-right: calc(20px + env(safe-area-inset-right));
    min-height: 100vh;
    min-height: calc(var(--vh, 1vh) * 100);
    min-height: -webkit-fill-available;
}

header {
    text-align: center;
    padding: 40px 0;
}

header h1 {
    font-size: 2.5rem;
    margin-bottom: 10px;
    background: linear-gradient(90deg, #e94560, #f39c12);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.subtitle {
    color: #a0a0a0;
    font-size: 1.1rem;
}

.section {
    margin: 20px 0;
}

.hidden {
    display: none !important;
}

/* Upload Section */
.upload-area {
    border: 3px dashed #e94560;
    border-radius: 20px;
    padding: 60px 40px;
    text-align: center;
    background: rgba(255, 255, 255, 0.05);
    transition: all 0.3s ease;
    cursor: pointer;
    /* iOS Safari: Improve touch responsiveness */
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

.upload-area:hover, .upload-area.dragover {
    background: rgba(233, 69, 96, 0.1);
    border-color: #f39c12;
    transform: scale(1.02);
}

/* iOS Safari: Add active state for touch feedback */
.upload-area:active {
    background: rgba(233, 69, 96, 0.15);
    transform: scale(0.98);
}

.upload-icon {
    font-size: 4rem;
    margin-bottom: 20px;
}

.upload-area h2 {
    margin-bottom: 10px;
    color: #fff;
}

.upload-area p {
    color: #888;
    margin: 10px 0;
}

.upload-btn {
    display: inline-block;
    background: linear-gradient(90deg, #e94560, #f39c12);
    color: #fff;
    padding: 15px 40px;
    border-radius: 30px;
    font-size: 1.1rem;
    cursor: pointer;
    transition: transform 0.3s ease, box-shadow 0.3s ease;
    margin-top: 10px;
    /* iOS Safari: Improve touch responsiveness */
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

.upload-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 10px 30px rgba(233, 69, 96, 0.4);
}

/* iOS Safari: Add active state for touch feedback */
.upload-btn:active {
    transform: scale(0.95);
}

.file-info {
    font-size: 0.9rem;
    margin-top: 20px;
}

/* Reader Section */
.book-info {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px 20px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 10px;
    margin-bottom: 20px;
}

.book-name {
    font-weight: 600;
    color: #f39c12;
}

.change-book-btn {
    background: transparent;
    border: 1px solid #e94560;
    color: #e94560;
    padding: 8px 20px;
    border-radius: 20px;
    cursor: pointer;
    transition: all 0.3s ease;
}

.change-book-btn:hover {
    background: #e94560;
    color: #fff;
}

/* Progress Section */
.progress-section {
    margin-bottom: 20px;
}

.progress-bar {
    height: 8px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 4px;
    overflow: hidden;
    cursor: pointer;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, #e94560, #f39c12);
    width: 0%;
    transition: width 0.3s ease;
}

.progress-info {
    display: flex;
    justify-content: space-between;
    margin-top: 10px;
    font-size: 0.9rem;
    color: #888;
}

/* Text Display */
.text-display {
    background: rgba(255, 255, 255, 0.05);
    border-radius: 15px;
    padding: 30px;
    min-height: 200px;
    max-height: 400px;
    overflow-y: auto;
    margin-bottom: 30px;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.text-display p {
    line-height: 1.8;
    font-size: 1.1rem;
    color: #e0e0e0;
}

.text-display .highlight {
    background: rgba(233, 69, 96, 0.3);
    padding: 2px 5px;
    border-radius: 3px;
}

.text-display .dialogue {
    color: #f39c12;
    font-style: italic;
}

/* Controls */
.controls {
    display: flex;
    justify-content: center;
    gap: 20px;
    margin-bottom: 30px;
}

.control-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    background: rgba(255, 255, 255, 0.1);
    border: none;
    border-radius: 15px;
    padding: 20px 30px;
    cursor: pointer;
    transition: all 0.3s ease;
    color: #fff;
    /* iOS Safari: Improve touch responsiveness */
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
    /* iOS Safari: Prevent text selection on double-tap */
    -webkit-user-select: none;
    user-select: none;
}

.control-btn:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: translateY(-3px);
}

/* iOS Safari: Add active state for touch feedback */
.control-btn:active {
    transform: scale(0.95);
    background: rgba(255, 255, 255, 0.25);
}

.control-btn.play-btn {
    background: linear-gradient(135deg, #e94560, #f39c12);
    padding: 25px 40px;
}

.control-btn.play-btn:hover {
    box-shadow: 0 10px 30px rgba(233, 69, 96, 0.4);
}

/* iOS Safari: Add active state for play button */
.control-btn.play-btn:active {
    transform: scale(0.95);
}

.control-icon {
    font-size: 1.8rem;
    margin-bottom: 5px;
}

.control-label {
    font-size: 0.9rem;
}

/* Settings */
.settings {
    background: rgba(255, 255, 255, 0.05);
    border-radius: 15px;
    padding: 25px;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.setting-group {
    display: flex;
    align-items: center;
    gap: 15px;
    margin-bottom: 15px;
    flex-wrap: wrap;
}

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

.setting-group label {
    min-width: 120px;
    color: #ccc;
}

.setting-group input[type="range"] {
    flex: 1;
    min-width: 150px;
    height: 6px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 3px;
    -webkit-appearance: none;
}

.setting-group input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 18px;
    height: 18px;
    background: #e94560;
    border-radius: 50%;
    cursor: pointer;
}

.setting-group select {
    flex: 1;
    min-width: 150px;
    padding: 10px 15px;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 8px;
    color: #fff;
    cursor: pointer;
}

.setting-group select option {
    background: #1a1a2e;
    color: #fff;
}

.setting-group input[type="checkbox"] {
    width: 20px;
    height: 20px;
    cursor: pointer;
}

.tooltip {
    position: relative;
    display: inline-block;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 50%;
    width: 20px;
    height: 20px;
    text-align: center;
    line-height: 20px;
    font-size: 0.8rem;
    cursor: help;
}

.tooltip-text {
    visibility: hidden;
    width: 200px;
    background-color: #333;
    color: #fff;
    text-align: center;
    border-radius: 6px;
    padding: 10px;
    position: absolute;
    z-index: 1;
    bottom: 125%;
    left: 50%;
    margin-left: -100px;
    opacity: 0;
    transition: opacity 0.3s;
    font-size: 0.8rem;
}

.tooltip:hover .tooltip-text {
    visibility: visible;
    opacity: 1;
}

/* Loading Overlay */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.loader {
    width: 60px;
    height: 60px;
    border: 4px solid rgba(255, 255, 255, 0.3);
    border-top-color: #e94560;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 20px;
}

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

/* Scrollbar */
::-webkit-scrollbar {
    width: 8px;
}

::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb {
    background: #e94560;
    border-radius: 4px;
}

/* Responsive */
@media (max-width: 600px) {
    header h1 {
        font-size: 1.8rem;
    }

    .upload-area {
        padding: 40px 20px;
    }

    .controls {
        gap: 10px;
    }

    .control-btn {
        padding: 15px 20px;
        /* iOS Safari: Larger touch targets on mobile */
        min-width: 70px;
        min-height: 70px;
    }

    .control-btn.play-btn {
        padding: 20px 30px;
        min-width: 90px;
        min-height: 90px;
    }

    .setting-group {
        flex-direction: column;
        align-items: flex-start;
    }

    .setting-group label {
        min-width: auto;
    }
    
    /* iOS Safari: Larger select dropdowns for easier touch */
    .setting-group select {
        min-height: 44px;
        font-size: 16px; /* Prevents iOS Safari zoom on focus */
    }
    
    /* iOS Safari: Larger slider for easier touch */
    .setting-group input[type="range"] {
        height: 20px;
    }
}

/* iOS Safari specific styles */
@supports (-webkit-touch-callout: none) {
    body {
        /* Use -webkit-fill-available for iOS Safari */
        min-height: -webkit-fill-available;
    }
    
    .container {
        min-height: -webkit-fill-available;
    }
    
    /* Ensure buttons have proper touch areas */
    .control-btn,
    .upload-btn,
    .change-book-btn {
        /* Minimum 44x44px touch target as per Apple guidelines */
        min-width: 44px;
        min-height: 44px;
    }
    
    /* Prevent iOS rubber-banding issues */
    .text-display {
        -webkit-overflow-scrolling: touch;
    }
}

/* Additional iOS Safari fixes for buttons */
button, .upload-btn, .control-btn {
    /* Prevent iOS Safari button styling issues */
    -webkit-appearance: none;
    appearance: none;
    /* Ensure buttons are tappable */
    cursor: pointer;
    /* Prevent double-tap zoom */
    touch-action: manipulation;
    /* Remove default tap highlight */
    -webkit-tap-highlight-color: rgba(0,0,0,0);
}

/* Ensure file input is hidden properly but still accessible */
#file-input {
    display: none !important;
    visibility: hidden !important;
    position: absolute;
    left: -9999px;
}
