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

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    color: #333;
}

.app-container {
    max-width: 900px;
    margin: 0 auto;
    padding: 20px;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.header {
    text-align: center;
    padding: 20px 0;
    color: white;
}

.logo {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    font-size: 28px;
    font-weight: bold;
    text-shadow: 2px 2px 4px rgba(0,0,0,0.2);
}

.logo i {
    font-size: 36px;
}

.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.input-section, .preview-section, .player-section {
    background: white;
    border-radius: 16px;
    padding: 24px;
    box-shadow: 0 10px 40px rgba(0,0,0,0.1);
}

.section-title {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 18px;
    font-weight: 600;
    color: #555;
    margin-bottom: 20px;
    padding-bottom: 10px;
    border-bottom: 2px solid #f0f0f0;
}

.section-title i {
    color: #667eea;
}

.input-controls {
    display: flex;
    gap: 12px;
    margin-bottom: 16px;
}

.btn {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 24px;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.3s ease;
}

.btn-primary {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 20px rgba(102, 126, 234, 0.4);
}

.btn-secondary {
    background: #f0f0f0;
    color: #666;
}

.btn-secondary:hover {
    background: #e0e0e0;
}

#textInput {
    width: 100%;
    height: 200px;
    padding: 16px;
    border: 2px solid #e0e0e0;
    border-radius: 12px;
    font-size: 15px;
    line-height: 1.6;
    resize: vertical;
    font-family: inherit;
    transition: border-color 0.3s ease;
}

#textInput:focus {
    outline: none;
    border-color: #667eea;
}

#textInput::placeholder {
    color: #aaa;
}

.toggle-switch {
    margin-left: auto;
    position: relative;
    display: inline-block;
    width: 50px;
    height: 28px;
}

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

.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: #ccc;
    transition: 0.4s;
    border-radius: 28px;
}

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

input:checked + .slider {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

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

.preview-area {
    background: #f8f9fa;
    border-radius: 12px;
    padding: 20px;
    height: 300px;
    overflow-y: auto;
    overflow-x: hidden;
    position: relative;
    scroll-behavior: smooth;
}

.preview-area::-webkit-scrollbar {
    width: 8px;
}

.preview-area::-webkit-scrollbar-track {
    background: #e9ecef;
    border-radius: 4px;
}

.preview-area::-webkit-scrollbar-thumb {
    background: #ced4da;
    border-radius: 4px;
}

.preview-area::-webkit-scrollbar-thumb:hover {
    background: #adb5bd;
}

.preview-content {
    font-size: 16px;
    line-height: 2;
    color: #333;
    transition: all 0.3s ease;
    white-space: pre-wrap;
    word-break: break-word;
}

.preview-content .placeholder {
    color: #999;
    font-style: italic;
}

.highlighted-text {
    background: linear-gradient(135deg, #ffecd2 0%, #fcb69f 100%);
    padding: 1px 3px;
    border-radius: 3px;
    color: #d63031;
    font-weight: 600;
    animation: pulse 1.5s infinite;
}

@keyframes pulse {
    0%, 100% {
        box-shadow: 0 0 0 0 rgba(252, 182, 159, 0.4);
    }
    50% {
        box-shadow: 0 0 0 4px rgba(252, 182, 159, 0);
    }
}

.voice-selector {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 12px;
    margin-bottom: 24px;
}

.voice-gender-tabs {
    display: flex;
    gap: 10px;
}

.voice-gender-tabs .voice-option {
    flex: 0 0 auto;
    min-width: 100px;
    padding: 12px 18px;
}

.voice-detail {
    flex: 1 1 220px;
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 180px;
}

.voice-label {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 14px;
    color: #555;
    font-weight: 500;
    white-space: nowrap;
}

.voice-select {
    flex: 1;
    padding: 10px 12px;
    border: 2px solid #e0e0e0;
    border-radius: 10px;
    font-size: 14px;
    color: #333;
    background: #f8f9fa;
    cursor: pointer;
    transition: border-color 0.3s ease, background 0.3s ease;
    outline: none;
    font-family: inherit;
}

.voice-select:focus {
    border-color: #667eea;
    background: #fff;
}

.engine-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
    background: #f0f0f0;
    color: #888;
    white-space: nowrap;
}

.engine-badge .dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #bbb;
    display: inline-block;
}

.engine-badge.engine-edge { background: rgba(39, 174, 96, 0.12); color: #27ae60; }
.engine-badge.engine-edge .dot { background: #27ae60; }
.engine-badge.engine-fallback { background: rgba(230, 126, 34, 0.14); color: #e67e22; }
.engine-badge.engine-fallback .dot { background: #e67e22; }
.engine-badge.engine-loading { background: rgba(102, 126, 234, 0.12); color: #667eea; }
.engine-badge.engine-loading .dot { background: #667eea; animation: engine-pulse 1s infinite; }
.engine-badge.engine-idle { background: #f0f0f0; color: #888; }

@keyframes engine-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.25; }
}

.voice-option {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 16px;
    border: 2px solid #e0e0e0;
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.3s ease;
    background: #f8f9fa;
}

.voice-option:hover {
    border-color: #667eea;
    background: #fff;
}

.voice-option-active {
    border-color: #667eea;
    background: linear-gradient(135deg, rgba(102, 126, 234, 0.1) 0%, rgba(118, 75, 162, 0.1) 100%);
}

.voice-option-active i {
    color: #667eea;
}

.progress-container {
    margin-bottom: 24px;
}

.progress-bar-wrapper {
    padding: 10px 0;
}

.progress-bar {
    position: relative;
    height: 8px;
    background: #e0e0e0;
    border-radius: 4px;
    cursor: pointer;
}

.progress-fill {
    position: absolute;
    left: 0;
    top: 0;
    height: 100%;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border-radius: 4px;
    width: 0%;
    transition: width 0.1s linear;
}

.progress-handle {
    position: absolute;
    left: 0%;
    top: 50%;
    transform: translate(-50%, -50%);
    width: 20px;
    height: 20px;
    background: white;
    border: 3px solid #667eea;
    border-radius: 50%;
    cursor: grab;
    transition: left 0.1s linear;
    box-shadow: 0 2px 8px rgba(102, 126, 234, 0.4);
}

.progress-handle:active {
    cursor: grabbing;
}

.time-display {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 8px;
    font-size: 14px;
    color: #666;
    margin-top: 8px;
}

.control-buttons {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 16px;
    margin-bottom: 24px;
}

.control-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 50px;
    height: 50px;
    border: none;
    border-radius: 50%;
    background: #f0f0f0;
    color: #555;
    font-size: 20px;
    cursor: pointer;
    transition: all 0.3s ease;
}

.control-btn:hover {
    background: #e0e0e0;
    transform: scale(1.1);
}

.control-btn-play {
    width: 70px;
    height: 70px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    font-size: 28px;
}

.control-btn-play:hover {
    background: linear-gradient(135deg, #5a6fd6 0%, #6a4190 100%);
    transform: scale(1.15);
}

.speed-control {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
}

.speed-control label {
    font-size: 14px;
    color: #555;
    font-weight: 500;
}

#speedRange {
    width: 150px;
    height: 6px;
    -webkit-appearance: none;
    appearance: none;
    background: #e0e0e0;
    border-radius: 3px;
    outline: none;
}

#speedRange::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 18px;
    height: 18px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border-radius: 50%;
    cursor: pointer;
    box-shadow: 0 2px 6px rgba(102, 126, 234, 0.4);
}

#speedRange::-moz-range-thumb {
    width: 18px;
    height: 18px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border-radius: 50%;
    cursor: pointer;
    border: none;
    box-shadow: 0 2px 6px rgba(102, 126, 234, 0.4);
}

#speedValue {
    font-size: 14px;
    color: #667eea;
    font-weight: 600;
    min-width: 45px;
    text-align: right;
}

.footer {
    text-align: center;
    padding: 20px 0;
    color: rgba(255,255,255,0.8);
    font-size: 12px;
}

@media (max-width: 768px) {
    .app-container {
        padding: 10px;
    }
    
    .input-controls {
        flex-direction: column;
    }
    
    .btn {
        width: 100%;
        justify-content: center;
    }
    
    .voice-selector {
        flex-direction: column;
        align-items: stretch;
    }

    .voice-gender-tabs .voice-option {
        flex: 1 1 0;
        min-width: 0;
    }

    .voice-detail {
        flex: 1 1 auto;
    }

    .voice-select {
        width: 100%;
    }

    .engine-badge {
        align-self: flex-start;
    }
    
    .control-buttons {
        gap: 12px;
    }
    
    .control-btn {
        width: 45px;
        height: 45px;
        font-size: 18px;
    }
    
    .control-btn-play {
        width: 60px;
        height: 60px;
        font-size: 24px;
    }
    
    .preview-area {
        height: 250px;
    }
}

.download-btn {
    position: absolute;
    right: 20px;
    top: 50%;
    transform: translateY(-50%);
    background: rgba(255,255,255,0.2);
    border: 2px solid rgba(255,255,255,0.4);
    color: white;
    padding: 8px 16px;
    border-radius: 20px;
    font-size: 14px;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    gap: 6px;
}

.download-btn:hover {
    background: rgba(255,255,255,0.3);
    border-color: rgba(255,255,255,0.6);
}

.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.6);
    justify-content: center;
    align-items: center;
    z-index: 1000;
    backdrop-filter: blur(5px);
}

.modal.active {
    display: flex;
}

.modal-content {
    background: white;
    border-radius: 20px;
    width: 90%;
    max-width: 450px;
    max-height: 80vh;
    overflow-y: auto;
    box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 24px;
    border-bottom: 1px solid #eee;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border-radius: 20px 20px 0 0;
}

.modal-header h3 {
    font-size: 20px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.close-btn {
    background: rgba(255,255,255,0.2);
    border: none;
    color: white;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    font-size: 18px;
    cursor: pointer;
    transition: background 0.3s ease;
}

.close-btn:hover {
    background: rgba(255,255,255,0.3);
}

.modal-body {
    padding: 24px;
}

.qr-code-container {
    text-align: center;
    margin-bottom: 24px;
}

#qrcode {
    display: inline-block;
    margin: 0 auto;
    border: 4px solid #f0f0f0;
    border-radius: 12px;
    padding: 8px;
}

.qr-code-container p {
    margin-top: 12px;
    color: #666;
    font-size: 14px;
}

.download-info {
    background: #f8f9fa;
    border-radius: 12px;
    padding: 16px;
    margin-bottom: 20px;
}

.download-info p {
    margin-bottom: 12px;
    color: #333;
}

.download-info ol {
    margin-left: 20px;
    margin-bottom: 12px;
}

.download-info li {
    margin-bottom: 8px;
    color: #555;
    font-size: 14px;
}

.download-info .tip {
    color: #4a90d9 !important;
    font-size: 13px !important;
    font-style: italic;
}

.download-link {
    margin-top: 16px;
}

.download-link p {
    margin-bottom: 10px;
    color: #333;
}

.download-link input {
    width: 100%;
    padding: 12px;
    border: 2px solid #ddd;
    border-radius: 8px;
    font-size: 14px;
    margin-bottom: 12px;
    color: #666;
}

.download-link button {
    width: 100%;
}