/* ═══════════════════════════════════════════════════════════════════════════
   TTS App — Custom styles
   Design: clean, professional, indigo accent (#6366f1)
   ═══════════════════════════════════════════════════════════════════════════ */

/* ── Reset & base ─────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --clr-bg:        #f1f5f9;
    --clr-surface:   #ffffff;
    --clr-border:    #e2e8f0;
    --clr-accent:    #6366f1;
    --clr-accent-h:  #4f46e5;
    --clr-text:      #1e293b;
    --clr-muted:     #64748b;
    --clr-error-bg:  #fef2f2;
    --clr-error:     #dc2626;
    --clr-success:   #16a34a;
    --clr-warn:      #d97706;
    --radius:        14px;
    --shadow:        0 2px 12px rgba(0,0,0,.07), 0 1px 3px rgba(0,0,0,.05);
    --transition:    .2s ease;
}

html, body {
    min-height: 100vh;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
                 "Helvetica Neue", Arial, sans-serif;
    font-size: 16px;
    line-height: 1.6;
    background: var(--clr-bg);
    color: var(--clr-text);
}

/* ── Layout container ─────────────────────────────────────────────────────── */
.tts-container {
    max-width: 780px;
    margin: 0 auto;
    padding: 2rem 1.25rem 4rem;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

/* ── Header ───────────────────────────────────────────────────────────────── */
.tts-header {
    text-align: center;
    padding: 1rem 0 .5rem;
}

.tts-header__icon {
    font-size: 3rem;
    line-height: 1;
    margin-bottom: .5rem;
}

.tts-header__title {
    font-size: 2rem;
    font-weight: 700;
    letter-spacing: -.02em;
    color: var(--clr-text);
}

.tts-header__subtitle {
    color: var(--clr-muted);
    margin-top: .25rem;
    font-size: .95rem;
}

/* ── Card ─────────────────────────────────────────────────────────────────── */
.tts-card {
    background: var(--clr-surface);
    border: 1px solid var(--clr-border);
    border-radius: var(--radius);
    padding: 1.75rem;
    box-shadow: var(--shadow);
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
}

.tts-card--progress {
    padding: 1.25rem 1.75rem;
}

.tts-card--error {
    background: var(--clr-error-bg);
    border-color: #fca5a5;
    flex-direction: row;
    align-items: flex-start;
    gap: 1rem;
}

.tts-card--result {
    border-color: #bbf7d0;
    background: #f0fdf4;
}

/* ── Form elements ────────────────────────────────────────────────────────── */
.form-field { display: flex; flex-direction: column; gap: .4rem; }

.form-field--inline { flex: 1 1 180px; }

.form-label {
    font-size: .85rem;
    font-weight: 600;
    color: var(--clr-muted);
    text-transform: uppercase;
    letter-spacing: .04em;
}

.form-textarea {
    width: 100%;
    padding: .875rem 1rem;
    border: 1.5px solid var(--clr-border);
    border-radius: 10px;
    font-size: .975rem;
    font-family: inherit;
    resize: vertical;
    min-height: 200px;
    transition: border-color var(--transition), box-shadow var(--transition);
    color: var(--clr-text);
    background: #fff;
    line-height: 1.6;
}

.form-textarea:focus {
    outline: none;
    border-color: var(--clr-accent);
    box-shadow: 0 0 0 3px rgba(99,102,241,.15);
}

.form-textarea--disabled,
.form-textarea:disabled {
    background: #f8fafc;
    color: var(--clr-muted);
    cursor: not-allowed;
}

.form-select {
    width: 100%;
    padding: .65rem .875rem;
    border: 1.5px solid var(--clr-border);
    border-radius: 10px;
    font-size: .95rem;
    font-family: inherit;
    background: #fff;
    color: var(--clr-text);
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%2364748b' stroke-width='1.8' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 1rem center;
    padding-right: 2.5rem;
    transition: border-color var(--transition);
}

.form-select:focus {
    outline: none;
    border-color: var(--clr-accent);
    box-shadow: 0 0 0 3px rgba(99,102,241,.15);
}

.form-select:disabled { background-color: #f8fafc; cursor: not-allowed; }

.options-row {
    display: flex;
    gap: 1rem;
    flex-wrap: wrap;
}

/* ── Text meta ────────────────────────────────────────────────────────────── */
.text-meta {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: .82rem;
    color: var(--clr-muted);
    flex-wrap: wrap;
    gap: .25rem;
}

.char-count { font-variant-numeric: tabular-nums; }

.char-count--warn { color: var(--clr-warn); font-weight: 600; }

.chunk-hint {
    margin-left: .35rem;
    color: var(--clr-accent);
    font-weight: 500;
}

.time-estimate { font-style: italic; }

/* ── Speed slider ─────────────────────────────────────────────────────────── */
.speed-badge {
    margin-left: .5rem;
    font-size: .78rem;
    font-weight: 600;
    color: var(--clr-accent);
    background: rgba(99,102,241,.1);
    padding: .1rem .5rem;
    border-radius: 99px;
    text-transform: none;
    letter-spacing: 0;
    vertical-align: middle;
}

.speed-row {
    display: flex;
    align-items: center;
    gap: .75rem;
}

.speed-edge { font-size: 1.15rem; flex-shrink: 0; }

.speed-slider {
    flex: 1;
    -webkit-appearance: none;
    appearance: none;
    height: 6px;
    border-radius: 99px;
    background: linear-gradient(
        to right,
        var(--clr-accent) 0%,
        var(--clr-accent) calc((var(--v, 2) - 1) / 4 * 100%),
        #e2e8f0 calc((var(--v, 2) - 1) / 4 * 100%),
        #e2e8f0 100%
    );
    outline: none;
    cursor: pointer;
    transition: opacity var(--transition);
}

.speed-slider:disabled { opacity: .45; cursor: not-allowed; }

.speed-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: var(--clr-accent);
    box-shadow: 0 1px 6px rgba(99,102,241,.5);
    cursor: pointer;
    transition: transform var(--transition), box-shadow var(--transition);
}

.speed-slider::-webkit-slider-thumb:hover {
    transform: scale(1.15);
    box-shadow: 0 2px 10px rgba(99,102,241,.6);
}

.speed-slider::-moz-range-thumb {
    width: 22px;
    height: 22px;
    border-radius: 50%;
    border: none;
    background: var(--clr-accent);
    box-shadow: 0 1px 6px rgba(99,102,241,.5);
    cursor: pointer;
}

.speed-ticks {
    display: flex;
    justify-content: space-between;
    padding: 0 11px; /* half thumb width to align under thumbs */
    margin-top: .2rem;
}

.speed-tick {
    font-size: .78rem;
    color: var(--clr-muted);
    width: 20px;
    text-align: center;
    transition: color var(--transition), font-weight var(--transition);
}

.speed-tick--active {
    color: var(--clr-accent);
    font-weight: 700;
}

/* ── Language hint ────────────────────────────────────────────────────────── */
.lang-hint {
    margin-left: .4rem;
    font-size: .75rem;
    color: var(--clr-warn);
    font-weight: 400;
    text-transform: none;
    letter-spacing: 0;
    cursor: help;
}

/* ── Buttons ──────────────────────────────────────────────────────────────── */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: .5rem;
    font-size: .95rem;
    font-weight: 600;
    font-family: inherit;
    border: none;
    border-radius: 10px;
    cursor: pointer;
    padding: .75rem 1.5rem;
    transition: background var(--transition), transform var(--transition),
                box-shadow var(--transition), opacity var(--transition);
    text-decoration: none;
    white-space: nowrap;
}

.btn--primary {
    background: var(--clr-accent);
    color: #fff;
    box-shadow: 0 2px 8px rgba(99,102,241,.35);
}

.btn--primary:hover:not(:disabled) {
    background: var(--clr-accent-h);
    box-shadow: 0 4px 14px rgba(99,102,241,.4);
    transform: translateY(-1px);
}

.btn--primary:active:not(:disabled) { transform: translateY(0); }

.btn--primary:disabled {
    opacity: .55;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

.btn--ghost {
    background: transparent;
    color: var(--clr-muted);
    border: 1.5px solid var(--clr-border);
}

.btn--ghost:hover {
    background: #f1f5f9;
    color: var(--clr-text);
}

/* ── Spinner ──────────────────────────────────────────────────────────────── */
@keyframes spin { to { transform: rotate(360deg); } }

.spinner {
    display: inline-block;
    width: 1.1em;
    height: 1.1em;
    border: 2.5px solid rgba(255,255,255,.35);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin .65s linear infinite;
    flex-shrink: 0;
}

/* ── Progress ─────────────────────────────────────────────────────────────── */
.progress-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: .9rem;
    margin-bottom: .5rem;
}

.progress-status { font-weight: 500; color: var(--clr-text); }

.progress-counter {
    font-variant-numeric: tabular-nums;
    color: var(--clr-muted);
    font-size: .85rem;
}

.progress-track {
    width: 100%;
    height: 8px;
    background: #e2e8f0;
    border-radius: 99px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--clr-accent), #818cf8);
    border-radius: 99px;
    transition: width .4s ease;
}

.progress-pct {
    text-align: right;
    font-size: .8rem;
    color: var(--clr-muted);
    margin-top: .3rem;
}

/* ── Error card ───────────────────────────────────────────────────────────── */
.error-icon { font-size: 1.5rem; flex-shrink: 0; }

.error-body { flex: 1; }

.error-body strong { color: var(--clr-error); font-size: .95rem; }

.error-body p { font-size: .9rem; color: var(--clr-text); margin-top: .25rem; }

/* ── Result card ──────────────────────────────────────────────────────────── */
.result-header {
    display: flex;
    align-items: center;
    gap: .75rem;
}

.result-icon { font-size: 1.75rem; }

.result-header strong { font-size: 1.05rem; color: var(--clr-success); }

.result-size {
    display: block;
    font-size: .8rem;
    color: var(--clr-muted);
}

.audio-player {
    width: 100%;
    border-radius: 10px;
    outline: none;
}

.result-tip {
    font-size: .85rem;
    color: #166534;
    background: rgba(22,163,74,.08);
    border-radius: 8px;
    padding: .6rem .9rem;
    line-height: 1.5;
}

.result-actions {
    display: flex;
    gap: .75rem;
    flex-wrap: wrap;
}

/* ── Buy Me a Coffee ─────────────────────────────────────────────────────── */
.tts-coffee {
    display: flex;
    align-items: center;
    gap: 1rem;
    background: #fffbeb;
    border: 1px solid #fde68a;
    border-radius: var(--radius);
    padding: 1.25rem 1.75rem;
    margin-top: .5rem;
    flex-wrap: wrap;
}

.coffee-icon {
    font-size: 2rem;
    flex-shrink: 0;
}

.coffee-text {
    flex: 1;
    min-width: 180px;
}

.coffee-text p {
    font-size: .9rem;
    color: #92400e;
    line-height: 1.5;
}

.btn-coffee {
    display: inline-flex;
    align-items: center;
    gap: .4rem;
    background: #FFDD00;
    color: #1a1a1a;
    font-weight: 700;
    font-size: .9rem;
    font-family: inherit;
    padding: .6rem 1.25rem;
    border-radius: 10px;
    text-decoration: none;
    white-space: nowrap;
    flex-shrink: 0;
    transition: transform var(--transition), box-shadow var(--transition);
    box-shadow: 0 2px 8px rgba(0,0,0,.12);
}

.btn-coffee:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 14px rgba(0,0,0,.18);
}

@media (max-width: 540px) {
    .tts-coffee { flex-direction: column; text-align: center; }
    .btn-coffee  { width: 100%; justify-content: center; }
}

/* ── Blazor error UI ──────────────────────────────────────────────────────── */
#blazor-error-ui {
    display: none;
    position: fixed;
    bottom: 1rem;
    left: 50%;
    transform: translateX(-50%);
    background: #fef2f2;
    border: 1px solid #fca5a5;
    color: #991b1b;
    border-radius: 10px;
    padding: .75rem 1.25rem;
    font-size: .875rem;
    z-index: 1000;
    box-shadow: var(--shadow);
    white-space: nowrap;
    gap: .75rem;
    align-items: center;
}

.reload { color: var(--clr-accent); margin-left: .5rem; }
.dismiss { cursor: pointer; margin-left: .75rem; }

/* ── Responsive ───────────────────────────────────────────────────────────── */
@media (max-width: 540px) {
    .tts-container { padding: 1rem .875rem 3rem; gap: 1rem; }
    .tts-header__title { font-size: 1.6rem; }
    .tts-card { padding: 1.25rem; }
    .options-row { flex-direction: column; }
    .btn { width: 100%; }
    .result-actions { flex-direction: column; }
}
