/* CSS Custom Properties for Theming */
:root {
    --primary-color: #3b82f6;
    --primary-hover: #2563eb;
    --success-color: #10b981;
    --error-color: #ef4444;
    --warning-color: #f59e0b;
    
    /* Light Theme */
    --bg-color: #ffffff;
    --surface-color: #f8fafc;
    --border-color: #e2e8f0;
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --shadow: 0 1px 3px 0 rgb(0 0 0 / 0.1), 0 1px 2px -1px rgb(0 0 0 / 0.1);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
}

[data-theme="dark"] {
    --bg-color: #0f172a;
    --surface-color: #1e293b;
    --border-color: #334155;
    --text-primary: #f1f5f9;
    --text-secondary: #94a3b8;
    --shadow: 0 1px 3px 0 rgb(0 0 0 / 0.3), 0 1px 2px -1px rgb(0 0 0 / 0.3);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.3), 0 4px 6px -4px rgb(0 0 0 / 0.3);
}

/* Reset and Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-primary);
    line-height: 1.6;
    transition: background-color 0.3s ease, color 0.3s ease;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 20px 20px 20px;
    min-height: 100vh;
}

/* Header */
.header {
    text-align: center;
    margin-bottom: 40px;
    padding: 0 0 30px 0;
    border-bottom: 1px solid var(--border-color);
}

.logo {
    font-size: 2.5rem;
    font-weight: 700;
    background: linear-gradient(135deg, var(--primary-color), var(--success-color));
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    margin: 0 auto 16px auto;
    display: flex;
    justify-content: center;
    align-items: center;
}

.logo img {
    width: 100%;
    max-width: none;
    height: auto;
    display: block;
    margin: 0 auto;
}

.description {
    color: var(--text-secondary);
    max-width: 600px;
    margin: 0 auto 24px;
    font-size: 1.1rem;
}

.donate-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 12px 24px;
    background: var(--warning-color);
    color: white;
    text-decoration: none;
    border-radius: 8px;
    font-weight: 600;
    transition: all 0.3s ease;
}

.donate-btn:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

/* Settings Panel */
.settings-panel {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 20px;
    background: var(--surface-color);
    padding: 24px;
    border-radius: 12px;
    box-shadow: var(--shadow);
    margin-bottom: 32px;
    border: 1px solid var(--border-color);
}

.setting-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.setting-group label {
    font-weight: 600;
    color: var(--text-secondary);
    font-size: 0.9rem;
}

/* Country Select */
.country-select {
    position: relative;
}

.selected-country {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    background: var(--bg-color);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s ease;
    font-size: 14px;
    height: 48px;
    min-height: 48px;
}

.selected-country:hover {
    border-color: var(--primary-color);
}

.selected-country img {
    width: 24px;
    height: 16px;
    object-fit: cover;
    border-radius: 2px;
}

.country-dropdown {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: var(--bg-color);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    box-shadow: var(--shadow-lg);
    z-index: 1000;
    max-height: 300px;
    overflow: hidden;
    opacity: 0;
    visibility: hidden;
    transform: translateY(-10px);
    transition: all 0.3s ease;
}

.country-dropdown.open {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.country-dropdown input {
    width: 100%;
    padding: 12px 16px;
    border: none;
    border-bottom: 1px solid var(--border-color);
    background: transparent;
    color: var(--text-primary);
    outline: none;
    font-size: 14px;
    height: 48px;
    font-family: inherit;
}

.country-list {
    max-height: 250px;
    overflow-y: auto;
}

.country-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    cursor: pointer;
    transition: background-color 0.2s ease;
}

.country-item:hover {
    background: var(--surface-color);
}

.country-item img {
    width: 24px;
    height: 16px;
    object-fit: cover;
    border-radius: 2px;
}

/* API Key Button */
.api-key-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 16px;
    background: var(--bg-color);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s ease;
    color: var(--text-primary);
    font-size: 14px;
    height: 48px;
    font-family: inherit;
}

.api-key-btn:hover {
    border-color: var(--primary-color);
}

.api-key-btn .fa-key {
    color: var(--error-color);
    transition: color 0.3s ease;
}

.api-key-btn.valid .fa-key {
    color: var(--success-color);
}

/* Voice Select */
.voice-select {
    padding: 12px 16px;
    background: var(--bg-color);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    color: var(--text-primary);
    cursor: pointer;
    transition: border-color 0.3s ease;
    font-size: 14px;
    height: 48px;
    font-family: inherit;
}

.voice-select:hover, .voice-select:focus {
    border-color: var(--primary-color);
    outline: none;
}

/* Speed Control */
.speed-control {
    display: flex;
    align-items: center;
    gap: 12px;
    height: 48px;
    min-height: 48px;
}

.speed-control input[type="range"] {
    flex: 1;
    height: 6px;
    background: var(--border-color);
    border-radius: 3px;
    outline: none;
    appearance: none;
    margin: 0;
}

.speed-control input[type="range"]::-webkit-slider-thumb {
    appearance: none;
    width: 18px;
    height: 18px;
    background: var(--primary-color);
    border-radius: 50%;
    cursor: pointer;
}

.speed-control input[type="range"]::-moz-range-thumb {
    width: 18px;
    height: 18px;
    background: var(--primary-color);
    border-radius: 50%;
    cursor: pointer;
    border: none;
}

#speedValue {
    font-weight: 600;
    color: var(--primary-color);
    min-width: 40px;
}

/* Theme Toggle */
.theme-toggle {
    padding: 12px 16px;
    background: var(--bg-color);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s ease;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    height: 48px;
    font-family: inherit;
}

.theme-toggle:hover {
    border-color: var(--primary-color);
}

/* Content Area */
.content {
    animation: fadeIn 0.5s ease-in-out;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.input-section {
    background: var(--surface-color);
    padding: 24px;
    border-radius: 12px;
    margin-bottom: 24px;
    border: 1px solid var(--border-color);
}

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

.section-header h3 {
    font-size: 1.25rem;
    font-weight: 600;
}

.generate-btn {
    padding: 8px 12px;
    background: var(--primary-color);
    color: white;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    gap: 6px;
}

.generate-btn:hover {
    background: var(--primary-hover);
    transform: translateY(-1px);
}

.generate-btn:disabled {
    background: var(--primary-color);
    color: white;
    cursor: not-allowed;
    transform: none;
    opacity: 0.4;
}

.instruction {
    color: var(--text-secondary);
    margin-bottom: 16px;
    font-size: 0.95rem;
}

textarea {
    width: 100%;
    min-height: 120px;
    padding: 16px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background: var(--bg-color);
    color: var(--text-primary);
    resize: vertical;
    font-family: inherit;
    line-height: 1.5;
    transition: border-color 0.3s ease;
}

textarea:focus {
    outline: none;
    border-color: var(--primary-color);
}

/* Generate Dialogue Button */
.generate-dialogue-btn {
    width: 100%;
    padding: 16px 24px;
    background: var(--primary-color);
    color: white;
    border: none;
    border-radius: 12px;
    font-size: 1.1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    margin-bottom: 32px;
}

.generate-dialogue-btn:hover:not(.disabled) {
    background: var(--primary-hover);
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

.generate-dialogue-btn.disabled {
    background: var(--primary-color);
    cursor: not-allowed;
    color: white;
    opacity: 0.4;
}

.generate-dialogue-btn:disabled {
    background: var(--primary-color);
    cursor: not-allowed;
    color: white;
    opacity: 0.4;
    transform: none;
}

/* Dialogue Section */
.dialogue-section {
    background: var(--surface-color);
    border-radius: 12px;
    padding: 24px;
    border: 1px solid var(--border-color);
}

.dialogue-line {
    display: flex;
    align-items: flex-start;
    gap: 16px;
    padding: 16px;
    background: var(--bg-color);
    border-radius: 8px;
    margin-bottom: 12px;
    border: 1px solid var(--border-color);
    transition: all 0.3s ease;
}

.dialogue-line:hover {
    transform: translateX(4px);
    box-shadow: var(--shadow);
}

.speaker-name {
    font-weight: 600;
    color: var(--text-primary);
    min-width: 80px;
    font-size: 1.25rem;
    user-select: none;
}

.dialogue-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.dialogue-text {
    padding: 8px 12px;
    background: var(--surface-color);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    font-style: italic;
    color: var(--text-secondary);
    font-size: 0.9rem;
    user-select: none;
}

.sentences-container {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.sentence-btn {
    padding: 8px 12px;
    background: var(--bg-color);
    border: 2px solid var(--primary-color);
    border-radius: 6px;
    color: var(--primary-color);
    cursor: pointer;
    transition: all 0.3s ease;
    font-size: 0.95rem;
    font-weight: 500;
    position: relative;
    overflow: hidden;
    user-select: none;
}

.sentence-btn:hover {
    background: var(--primary-color);
    color: white;
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(59, 130, 246, 0.3);
}

.sentence-btn:disabled {
    background: var(--bg-color);
    color: var(--primary-color);
    border-color: var(--primary-color);
    cursor: not-allowed;
    transform: none;
    opacity: 0.4;
    box-shadow: none;
}

.dialogue-controls {
    display: flex;
    gap: 8px;
    align-self: flex-start;
    margin-top: 8px;
}

.control-btn {
    width: 40px;
    height: 40px;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    font-size: 16px;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    -khtml-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
    touch-action: manipulation;
}

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

.play-btn:hover {
    background: var(--primary-hover);
    transform: scale(1.1);
}

.play-btn:disabled {
    background: var(--primary-color);
    color: white;
    cursor: not-allowed;
    transform: none;
    opacity: 0.4;
}

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

.record-btn:hover {
    background: var(--primary-hover);
    transform: scale(1.1);
}

.record-btn.recording {
    background: var(--error-color);
    animation: pulse 1.5s infinite;
}

.record-btn.recording:hover {
    background: #dc2626;
    transform: scale(1.1);
}

.replay-btn {
    background: var(--success-color);
    color: white;
}

.replay-btn:hover {
    background: #059669;
    transform: scale(1.1);
}

.replay-btn:disabled {
    background: var(--success-color);
    color: white;
    cursor: not-allowed;
    transform: none;
    opacity: 0.4;
}

@keyframes pulse {
    0%, 100% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.1);
    }
}

/* Modal Styles */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10000;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
}

.modal.open {
    opacity: 1;
    visibility: visible;
}

.modal-content {
    background: var(--bg-color);
    border-radius: 12px;
    width: 90%;
    max-width: 400px;
    max-height: 80vh;
    overflow-y: auto;
    transform: scale(0.9);
    transition: transform 0.3s ease;
}

.modal.open .modal-content {
    transform: scale(1);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 24px;
    border-bottom: 1px solid var(--border-color);
}

.modal-header h3 {
    font-size: 1rem;
    font-weight: 600;
}

.close-btn {
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    color: var(--text-secondary);
    padding: 4px;
    border-radius: 4px;
    transition: all 0.3s ease;
}

.close-btn:hover {
    background: var(--surface-color);
    color: var(--text-primary);
}

.modal-body {
    padding: 20px;
    font-size: 0.8rem;
    line-height: 1.3;
}

.api-guide {
    margin-bottom: 16px;
}

.api-guide h4 {
    margin-bottom: 8px;
    color: var(--text-primary);
    font-size: 0.9rem;
    line-height: 1.2;
}

.api-guide ol {
    margin-left: 16px;
    margin-bottom: 12px;
}

.api-guide ul {
    margin-left: 16px;
    margin-bottom: 12px;
}

.api-guide li {
    margin-bottom: 4px;
    color: var(--text-secondary);
    font-size: 0.8rem;
    line-height: 1.3;
}

.api-guide p {
    margin-bottom: 8px;
    font-size: 0.8rem;
    line-height: 1.3;
}

.api-guide a {
    color: var(--primary-color);
    text-decoration: none;
}

.api-guide a:hover {
    text-decoration: underline;
}

.api-input-group {
    display: flex;
    gap: 8px;
    margin-bottom: 20px;
}

.api-input-group input {
    flex: 1;
    padding: 12px 16px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background: var(--surface-color);
    color: var(--text-primary);
    font-family: monospace;
}

.api-input-group input:focus {
    outline: none;
    border-color: var(--primary-color);
}

.paste-btn {
    padding: 12px 16px;
    background: var(--surface-color);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    cursor: pointer;
    color: var(--text-primary);
    transition: all 0.3s ease;
}

.paste-btn:hover {
    background: var(--border-color);
}

.save-btn {
    width: 100%;
    padding: 12px 24px;
    background: var(--primary-color);
    color: white;
    border: none;
    border-radius: 8px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
}

.save-btn:hover {
    background: var(--primary-hover);
}

/* Utility Classes */
.hidden {
    display: none !important;
}

.fade-in {
    animation: fadeIn 0.5s ease-in-out;
}

/* Responsive Design */
@media (max-width: 768px) {
    .container {
        padding: 16px;
    }
    
    .settings-panel {
        grid-template-columns: 1fr;
        gap: 16px;
        padding: 20px;
    }
    
    .logo {
        font-size: 2rem;
    }
    
    .dialogue-line {
        flex-direction: column;
        align-items: stretch;
        gap: 12px;
    }
    
    .dialogue-controls {
        justify-content: center;
    }
    
    .speaker-name {
        min-width: auto;
        text-align: center;
    }
    
    .sentences-container {
        gap: 6px;
    }
    
    .sentence-btn {
        font-size: 0.9rem;
        padding: 6px 10px;
    }
}

@media (max-width: 480px) {
    .modal-content {
        width: 95%;
        margin: 20px;
    }
    
    .modal-body {
        padding: 20px;
    }
    
    .api-input-group {
        flex-direction: column;
    }
    
    .sentence-btn {
        font-size: 0.85rem;
        padding: 5px 8px;
    }
    
    .sentences-container {
        gap: 4px;
    }
}
