/* ===== Variables ===== */
/* Light Theme */
:root {
    --bg-body: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    --bg-container: #ffffff;
    --bg-section: #ffffff;
    --bg-light: #f7fafc;
    --bg-modal: #ffffff;
    --bg-button-secondary: #ffffff;
    --bg-input: #ffffff;

    --text-primary: #2d3748;
    --text-secondary: #4a5568;
    --text-tertiary: #718096;
    --text-button-secondary: #667eea;

    --border-main: #e2e8f0;
    --border-input: #e2e8f0;

    --primary-color: #667eea;
    --primary-dark: #5568d3;
    --primary-gradient: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    --accent-primary: #667eea;
    --accent-hover: #5568d3;
    --accent-danger: #f56565;
    --accent-danger-hover: #e53e3e;

    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.1);
    --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 15px rgba(0, 0, 0, 0.1);
    --shadow-xl: 0 20px 25px rgba(0, 0, 0, 0.15);
    --modal-backdrop: rgba(0, 0, 0, 0.5);

    --radius-sm: 4px;
    --radius-md: 8px;
    --radius-lg: 12px;
    --radius-xl: 16px;
}

/* Dark Theme */
[data-theme="dark"] {
    --bg-body: #1a1a1a;
    --bg-container: #2a2a2a;
    --bg-section: #2a2a2a;
    --bg-light: #1a1a1a;
    --bg-modal: #2a2a2a;
    --bg-button-secondary: #3a3a3a;
    --bg-input: #1a1a1a;

    --text-primary: #ffd580;
    --text-secondary: #b8945f;
    --text-tertiary: #999999;
    --text-button-secondary: #ffffff;

    --border-main: #3a3a3a;
    --border-input: #3a3a3a;

    --primary-color: #c9a876;
    --primary-dark: #d4b586;
    --primary-gradient: linear-gradient(135deg, #c9a876 0%, #d4b586 100%);
    --accent-primary: #c9a876;
    --accent-hover: #d4b586;
    --accent-danger: #ff5252;
    --accent-danger-hover: #d32f2f;

    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.5);
    --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.5);
    --shadow-lg: 0 10px 15px rgba(0, 0, 0, 0.5);
    --shadow-xl: 0 20px 25px rgba(0, 0, 0, 0.5);
    --modal-backdrop: rgba(0, 0, 0, 0.8);
}

/* ===== Reset & Base ===== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: var(--bg-body);
    min-height: 100vh;
    padding: 20px;
    color: var(--text-primary);
}

/* ===== App Container ===== */
.app-container {
    max-width: 750px;
    margin: 0 auto;
    background: var(--bg-section);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-lg);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    border: 1px solid var(--border-main);
}

/* ===== Header ===== */
.app-header {
    padding: 30px;
    border-bottom: 2px solid var(--border-main);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.app-header h1 {
    font-size: 2.2rem;
    color: var(--text-primary);
    flex: 1;
    text-align: center;
}

.header-actions {
    display: flex;
    gap: 10px;
}

.btn-icon {
    background: var(--bg-light);
    border: 1px solid var(--border-main);
    border-radius: var(--radius-md);
    width: 40px;
    height: 40px;
    font-size: 1.3rem;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.btn-icon:hover {
    background: var(--primary-color);
    border-color: var(--primary-color);
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.btn-icon-sm {
    background: var(--bg-light);
    border: 1px solid var(--border-main);
    border-radius: var(--radius-sm);
    width: 36px;
    height: 36px;
    font-size: 1rem;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.btn-icon-sm:hover {
    background: var(--accent-primary);
    border-color: var(--accent-primary);
}

/* ===== Main Content ===== */
.main-content {
    padding: 30px;
    display: flex;
    flex-direction: column;
    gap: 25px;
}

/* ===== Input Section ===== */
.input-section {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.textarea-wrapper {
    position: relative;
}

.text-input {
    width: 100%;
    min-height: 200px;
    padding: 15px;
    border: 2px solid var(--border-main);
    border-radius: var(--radius-lg);
    font-size: 1rem;
    font-family: inherit;
    line-height: 1.6;
    resize: vertical;
    background: var(--bg-input);
    color: var(--text-primary);
    transition: border-color 0.2s;
}

.text-input:focus {
    outline: none;
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 3px rgba(201, 168, 118, 0.15);
}

.text-input::placeholder {
    color: var(--text-tertiary);
}

/* ===== Controls Row ===== */
.controls-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 15px;
    flex-wrap: wrap;
}

.voice-selector {
    display: flex;
    align-items: center;
    gap: 10px;
    flex: 1;
    min-width: 200px;
}

.voice-selector label {
    color: var(--text-secondary);
    font-weight: 600;
    white-space: nowrap;
}

.voice-select {
    flex: 1;
    padding: 10px 12px;
    border: 2px solid var(--border-main);
    border-radius: var(--radius-md);
    font-size: 0.95rem;
    background: var(--bg-input);
    color: var(--text-primary);
    cursor: pointer;
    transition: border-color 0.2s;
}

.voice-select:focus {
    outline: none;
    border-color: var(--accent-primary);
}

.char-count {
    color: var(--text-tertiary);
    font-size: 0.9rem;
    white-space: nowrap;
    flex-shrink: 0;
}

.char-count.near-limit {
    color: #f59e0b;
    font-weight: 600;
}

.char-count.at-limit {
    color: var(--accent-danger);
    font-weight: 600;
}

/* ===== Generate Button ===== */
.generate-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    margin-top: 5px;
}

.btn-primary {
    background: var(--primary-gradient);
    color: white;
    border: none;
    border-radius: var(--radius-lg);
    padding: 15px 50px;
    font-size: 1.1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s;
    box-shadow: var(--shadow-md);
    display: flex;
    align-items: center;
    gap: 10px;
}

.btn-primary:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

.btn-primary:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

.btn-secondary {
    background: var(--bg-section);
    color: var(--primary-color);
    border: 2px solid var(--primary-color);
    border-radius: var(--radius-lg);
    padding: 10px 20px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.btn-secondary:hover {
    background: var(--primary-color);
    color: white;
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.btn-danger {
    background: transparent;
    color: var(--accent-danger);
    border: 2px solid var(--accent-danger);
    border-radius: var(--radius-lg);
    padding: 10px 20px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-danger:hover {
    background: var(--accent-danger);
    color: white;
    transform: translateY(-2px);
}

/* ===== Spinner ===== */
.spinner {
    width: 20px;
    height: 20px;
    border: 3px solid rgba(255, 255, 255, 0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* ===== No-Key Hint ===== */
.no-key-hint {
    font-size: 0.88rem;
    color: var(--primary);
    text-align: center;
    margin-top: 10px;
    visibility: hidden;
}

.no-key-hint.visible {
    visibility: visible;
}

/* ===== Privacy Notice ===== */
.privacy-notice {
    font-size: 0.82rem;
    color: var(--text-tertiary);
    line-height: 1.5;
    text-align: center;
    padding: 10px 15px;
    background: var(--bg-light);
    border-radius: var(--radius-md);
    border: 1px solid var(--border-main);
}

/* ===== Audio Section ===== */
.audio-section {
    border-top: 2px solid var(--border-main);
    padding-top: 25px;
}

.audio-player-wrapper {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 15px;
}

.audio-player-wrapper h3 {
    color: var(--text-primary);
    font-size: 1.1rem;
}

.audio-player {
    width: 100%;
    max-width: 500px;
    border-radius: var(--radius-md);
    accent-color: var(--accent-primary);
}

.audio-actions {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
    justify-content: center;
}

/* ===== Settings Modal - extra styles ===== */
.setup-intro {
    background: var(--bg-light);
    border: 1px solid var(--border-main);
    border-radius: var(--radius-md);
    padding: 15px 20px;
    margin-bottom: 20px;
}

.setup-intro h3 {
    margin-top: 0 !important;
    margin-bottom: 8px !important;
}

.setup-intro ol {
    margin-left: 20px;
    color: var(--text-secondary);
    line-height: 1.9;
}

.input-with-toggle {
    display: flex;
    gap: 8px;
    align-items: center;
}

.input-with-toggle input {
    flex: 1;
    padding: 10px 12px;
    border: 2px solid var(--border-main);
    border-radius: var(--radius-md);
    font-size: 1rem;
    background: var(--bg-input);
    color: var(--text-primary);
    transition: border-color 0.2s;
}

.input-with-toggle input:focus {
    outline: none;
    border-color: var(--accent-primary);
}

.credentials-status {
    padding: 12px 15px;
    border-radius: var(--radius-md);
    font-size: 0.9rem;
    font-weight: 500;
    margin-bottom: 10px;
}

.credentials-status.success {
    background: rgba(102, 187, 106, 0.15);
    border: 1px solid #66bb6a;
    color: #66bb6a;
}

.credentials-status.error {
    background: rgba(255, 82, 82, 0.15);
    border: 1px solid var(--accent-danger);
    color: var(--accent-danger);
}

.settings-actions {
    display: flex;
    gap: 12px;
    justify-content: flex-start;
    flex-wrap: wrap;
    margin-top: 5px;
}

/* ===== Modal ===== */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--modal-backdrop);
    z-index: 1000;
    backdrop-filter: blur(4px);
}

.modal.active {
    display: flex;
    align-items: center;
    justify-content: center;
    animation: fadeIn 0.2s;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.modal-content {
    background: var(--bg-section);
    border-radius: var(--radius-xl);
    max-width: 600px;
    width: 90%;
    max-height: 85vh;
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow-xl);
    animation: slideUp 0.3s;
    border: 1px solid var(--border-main);
}

@keyframes slideUp {
    from {
        transform: translateY(30px);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.modal-header {
    padding: 25px 30px;
    border-bottom: 2px solid var(--border-main);
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
}

.modal-header h2 {
    color: var(--text-primary);
    font-size: 1.4rem;
}

.modal-close {
    background: none;
    border: none;
    font-size: 2rem;
    color: var(--text-tertiary);
    cursor: pointer;
    transition: color 0.2s;
    line-height: 1;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-close:hover {
    color: var(--text-primary);
}

.modal-body {
    padding: 25px 30px;
    overflow-y: auto;
    flex: 1;
}

.modal-body h3 {
    color: var(--text-primary);
    margin-top: 20px;
    margin-bottom: 10px;
    font-size: 1.1rem;
}

.modal-body h3:first-child {
    margin-top: 0;
}

.modal-body ul,
.modal-body ol {
    margin-left: 20px;
    color: var(--text-secondary);
    line-height: 1.8;
}

.modal-body p {
    color: var(--text-secondary);
    line-height: 1.8;
    margin-bottom: 10px;
}

.modal-body a {
    color: var(--primary-color);
    text-decoration: none;
    font-weight: 600;
}

.modal-body a:hover {
    text-decoration: underline;
}

.option-group {
    margin-bottom: 20px;
}

.option-group label {
    color: var(--text-primary);
    font-weight: 600;
    display: block;
    margin-bottom: 8px;
    font-size: 0.95rem;
}

.option-help {
    color: var(--text-tertiary);
    font-size: 0.83rem;
    margin-top: 6px;
    line-height: 1.4;
}

/* Shortcuts list */
.shortcuts-list {
    list-style: none !important;
    margin-left: 0 !important;
}

.shortcuts-list li {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 0;
    border-bottom: 1px solid var(--border-main);
    color: var(--text-secondary);
}

.shortcuts-list li:last-child {
    border-bottom: none;
}

kbd {
    background: var(--bg-light);
    border: 1px solid var(--border-main);
    border-radius: var(--radius-sm);
    padding: 3px 8px;
    font-family: monospace;
    font-size: 0.85rem;
    box-shadow: var(--shadow-sm);
    color: var(--text-primary);
}

.support-link {
    display: inline-block;
    background: var(--bg-light);
    color: var(--primary-color);
    padding: 10px 20px;
    border-radius: var(--radius-md);
    text-decoration: none;
    margin-top: 5px;
    transition: all 0.2s;
    font-weight: 600;
    box-shadow: var(--shadow-md);
    border: 1px solid var(--border-main);
}

.support-link:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
    text-decoration: none !important;
}

.version {
    margin-top: 20px;
    color: var(--text-tertiary);
    font-size: 0.85rem;
    text-align: center;
}

/* Alert Modal */
.alert-modal .modal-content {
    max-width: 450px;
}

.alert-message {
    color: var(--text-secondary);
    line-height: 1.6;
    margin-bottom: 20px;
    white-space: pre-wrap;
}

.alert-actions {
    display: flex;
    justify-content: flex-end;
}

.btn-alert-ok {
    background: var(--accent-primary);
    color: white;
    border: none;
    border-radius: var(--radius-md);
    padding: 10px 24px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-alert-ok:hover {
    background: var(--accent-hover);
}

/* ===== Footer ===== */
.app-footer {
    padding: 20px;
    text-align: center;
    border-top: 2px solid var(--border-main);
    color: var(--text-secondary);
}

.app-footer a {
    color: var(--accent-primary);
    text-decoration: none;
    transition: color 0.2s;
}

.app-footer a:hover {
    color: var(--accent-hover);
    text-decoration: underline;
}

.footer-separator {
    color: var(--text-tertiary);
    margin: 0 8px;
}

/* ===== Utility ===== */
.hidden {
    display: none !important;
}

/* ===== Responsive ===== */
@media (max-width: 600px) {
    body {
        padding: 10px;
    }

    .app-header {
        padding: 20px;
    }

    .app-header h1 {
        font-size: 1.7rem;
    }

    .main-content {
        padding: 20px;
    }

    .controls-row {
        flex-direction: column;
        align-items: stretch;
    }

    .voice-selector {
        min-width: unset;
    }

    .char-count {
        text-align: right;
    }

    .btn-primary {
        width: 100%;
        justify-content: center;
        padding: 14px 30px;
    }

    .audio-actions {
        flex-direction: column;
        width: 100%;
    }

    .audio-actions a,
    .audio-actions button {
        width: 100%;
        justify-content: center;
    }

    .modal-content {
        width: 95%;
        max-height: 90vh;
    }

    .modal-header,
    .modal-body {
        padding: 20px;
    }

    .settings-actions {
        flex-direction: column;
    }

    .settings-actions button {
        width: 100%;
    }
}
