/* ===== Reset & Base ===== */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

:root {
    --primary: #4f46e5;
    --primary-hover: #4338ca;
    --accent: #0891b2;
    --accent-hover: #0e7490;
    --bg: #f8fafc;
    --surface: #ffffff;
    --border: #e2e8f0;
    --text: #1e293b;
    --text-muted: #64748b;
    --success: #16a34a;
    --danger: #dc2626;
    --radius: 10px;
    --shadow: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.06);
    --shadow-lg: 0 4px 14px rgba(0,0,0,0.1);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    min-height: 100vh;
}

/* ===== Container ===== */
.container {
    max-width: 680px;
    margin: 0 auto;
    padding: 24px 16px;
}

/* ===== Header ===== */
header {
    text-align: center;
    margin-bottom: 28px;
}

header h1 {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--primary);
}

.subtitle {
    color: var(--text-muted);
    font-size: 0.95rem;
    margin-top: 4px;
}

/* ===== Input Section ===== */
.input-section {
    margin-bottom: 20px;
}

.input-section label {
    display: block;
    font-weight: 600;
    margin-bottom: 6px;
    font-size: 0.9rem;
}

textarea {
    width: 100%;
    padding: 12px 14px;
    border: 2px solid var(--border);
    border-radius: var(--radius);
    font-size: 1rem;
    font-family: inherit;
    resize: vertical;
    transition: border-color 0.2s;
    background: var(--surface);
}

textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}

.text-meta {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 6px;
    font-size: 0.82rem;
    color: var(--text-muted);
}

#charCount.char-warning {
    color: #d97706;
    font-weight: 600;
}

#charCount.char-danger {
    color: #dc2626;
    font-weight: 700;
}

/* ===== Controls Grid ===== */
.controls-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 14px;
    margin-bottom: 20px;
}

.control-group {
    display: flex;
    flex-direction: column;
}

.control-group label {
    font-weight: 600;
    font-size: 0.85rem;
    margin-bottom: 5px;
}

select, input[type="range"] {
    width: 100%;
    padding: 9px 12px;
    border: 2px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.9rem;
    font-family: inherit;
    background: var(--surface);
    cursor: pointer;
    transition: border-color 0.2s;
}

select:focus {
    outline: none;
    border-color: var(--primary);
}

input[type="range"] {
    padding: 4px 0;
    border: none;
    accent-color: var(--primary);
    height: 38px;
}

/* ===== Buttons ===== */
.action-buttons {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    margin-bottom: 16px;
}

.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 11px 20px;
    border: none;
    border-radius: var(--radius);
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s, transform 0.1s, opacity 0.2s;
    flex: 1;
    justify-content: center;
    min-width: 100px;
}

.btn:active {
    transform: scale(0.97);
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

.btn-primary {
    background: var(--primary);
    color: #fff;
}

.btn-primary:hover:not(:disabled) {
    background: var(--primary-hover);
}

.btn-secondary {
    background: var(--border);
    color: var(--text);
}

.btn-secondary:hover:not(:disabled) {
    background: #cbd5e1;
}

.btn-accent {
    background: var(--accent);
    color: #fff;
}

.btn-accent:hover:not(:disabled) {
    background: var(--accent-hover);
}

.btn-link {
    background: none;
    border: none;
    color: var(--primary);
    cursor: pointer;
    font-size: 0.85rem;
    font-weight: 600;
    padding: 0;
}

.btn-link:hover {
    text-decoration: underline;
}

.btn-icon {
    font-size: 0.85em;
}

/* ===== Status ===== */
.status {
    padding: 10px 14px;
    border-radius: var(--radius);
    font-size: 0.88rem;
    margin-bottom: 16px;
    font-weight: 500;
}

.status.info {
    background: #eff6ff;
    color: #1d4ed8;
    border: 1px solid #bfdbfe;
}

.status.success {
    background: #f0fdf4;
    color: var(--success);
    border: 1px solid #bbf7d0;
}

.status.error {
    background: #fef2f2;
    color: var(--danger);
    border: 1px solid #fecaca;
}

/* ===== Recent Section ===== */
.recent-section {
    margin-top: 24px;
    border-top: 1px solid var(--border);
    padding-top: 20px;
}

.recent-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
}

.recent-header h2 {
    font-size: 1.05rem;
    font-weight: 700;
}

.recent-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.empty-state {
    color: var(--text-muted);
    font-size: 0.9rem;
    text-align: center;
    padding: 20px 0;
}

.recent-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 10px 14px;
    gap: 10px;
    box-shadow: var(--shadow);
}

.recent-item-text {
    flex: 1;
    font-size: 0.88rem;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
    color: var(--text);
}

.recent-item-lang {
    font-size: 0.75rem;
    color: var(--text-muted);
    background: var(--bg);
    padding: 2px 8px;
    border-radius: 20px;
    white-space: nowrap;
}

.recent-item-play {
    background: var(--primary);
    color: #fff;
    border: none;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 0.75rem;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 0.2s;
}

.recent-item-play:hover {
    background: var(--primary-hover);
}

/* ===== Footer ===== */
footer {
    text-align: center;
    margin-top: 32px;
    padding-top: 16px;
    border-top: 1px solid var(--border);
    color: var(--text-muted);
    font-size: 0.8rem;
}

/* ===== Responsive ===== */
@media (max-width: 520px) {
    .container {
        padding: 16px 12px;
    }

    header h1 {
        font-size: 1.4rem;
    }

    .controls-grid {
        grid-template-columns: 1fr;
        gap: 10px;
    }

    .action-buttons {
        flex-direction: column;
    }

    .btn {
        flex: unset;
        width: 100%;
    }
}

/* ===== Speaking Animation ===== */
@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.6; }
}

.speaking .btn-icon {
    animation: pulse 1s infinite;
}


