/* =========================================================================
   VoxScript — dark centred theme
   ========================================================================= */

:root {
    --bg:            #0a0c10;
    --bg-elevated:   #11151c;
    --surface:       #151a23;
    --surface-2:     #1b2130;
    --surface-3:     #222a3a;
    --border:        #263041;
    --border-strong: #364358;

    --text:          #e7ecf3;
    --text-muted:    #98a3b6;
    --text-dim:      #6b7688;

    --accent:        #4f8cff;
    --accent-soft:   rgba(79, 140, 255, 0.14);
    --accent-ring:   rgba(79, 140, 255, 0.45);

    --good:          #2fd4a0;
    --good-soft:     rgba(47, 212, 160, 0.13);
    --warn:          #f5b544;
    --warn-soft:     rgba(245, 181, 68, 0.13);
    --danger:        #ff6b6b;
    --danger-soft:   rgba(255, 107, 107, 0.13);

    --radius-sm: 8px;
    --radius:    12px;
    --radius-lg: 18px;

    --shadow:    0 4px 24px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 24px 60px rgba(0, 0, 0, 0.55);

    --font: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
            "Helvetica Neue", Arial, sans-serif;
    --mono: "JetBrains Mono", "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
}

/* --------------------------------------------------------------------- */
/* Reset                                                                  */
/* --------------------------------------------------------------------- */

*, *::before, *::after { box-sizing: border-box; }

/* Components below set an explicit display, which would otherwise win over
   the browser default for [hidden]. Make hidden always mean hidden. */
[hidden] { display: none !important; }

html {
    /* Tells the browser to render native widgets — scrollbars, form controls,
       the caret — in their dark variants rather than flashing light ones. */
    color-scheme: dark;
    height: 100%;
}

html, body { height: 100%; }

body {
    margin: 0;
    font-family: var(--font);
    font-size: 15px;
    line-height: 1.55;
    color: var(--text);
    background: var(--bg);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
}

/* Ambient glow so the flat black does not feel dead. */
body::before {
    content: "";
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 0;
    background:
        radial-gradient(760px 480px at 18% -8%,  rgba(79, 140, 255, 0.13), transparent 62%),
        radial-gradient(660px 420px at 84% 4%,   rgba(47, 212, 160, 0.09), transparent 60%),
        radial-gradient(900px 600px at 50% 108%, rgba(124, 92, 255, 0.08), transparent 65%);
}

/* --------------------------------------------------------------------- */
/* Dark scrollbars — Firefox first, then the WebKit pseudo-elements      */
/* --------------------------------------------------------------------- */

* {
    scrollbar-width: thin;
    scrollbar-color: var(--border-strong) transparent;
}

*::-webkit-scrollbar { width: 11px; height: 11px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb {
    background: var(--border-strong);
    border: 3px solid transparent;
    border-radius: 999px;
    background-clip: content-box;
}
*::-webkit-scrollbar-thumb:hover { background: #4a5a76; background-clip: content-box; }
*::-webkit-scrollbar-corner { background: transparent; }

/* --------------------------------------------------------------------- */
/* Layout                                                                 */
/* --------------------------------------------------------------------- */

.shell {
    position: relative;
    z-index: 1;
    width: min(980px, 100%);
    margin: 0 auto;
    padding: 40px 20px 72px;
    display: flex;
    flex-direction: column;
    gap: 22px;
}

/* --------------------------------------------------------------------- */
/* Header                                                                 */
/* --------------------------------------------------------------------- */

.masthead {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 18px;
    flex-wrap: wrap;
}

.brand { display: flex; align-items: center; gap: 14px; }

.brand__mark {
    width: 46px;
    height: 46px;
    flex: none;
    display: grid;
    place-items: center;
    border-radius: 13px;
    background: linear-gradient(145deg, var(--accent), #7c5cff);
    box-shadow: 0 6px 20px rgba(79, 140, 255, 0.32);
    color: #fff;
}
.brand__mark svg { width: 24px; height: 24px; display: block; }

.brand__name {
    margin: 0;
    font-size: 20px;
    font-weight: 650;
    letter-spacing: -0.02em;
}
.brand__tagline {
    margin: 1px 0 0;
    font-size: 12.5px;
    color: var(--text-dim);
    letter-spacing: 0.01em;
}

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

.badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 5px 11px;
    font-size: 11.5px;
    font-weight: 500;
    letter-spacing: 0.02em;
    color: var(--text-muted);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 999px;
    white-space: nowrap;
}
.badge__dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--good);
    box-shadow: 0 0 0 3px var(--good-soft);
}

/* --------------------------------------------------------------------- */
/* Cards                                                                  */
/* --------------------------------------------------------------------- */

.card {
    background: linear-gradient(180deg, var(--surface), var(--bg-elevated));
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
}

.card__head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
}

.card__title {
    margin: 0;
    font-size: 13px;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--text-muted);
}

.card__body { padding: 20px; }

/* --------------------------------------------------------------------- */
/* Recorder                                                               */
/* --------------------------------------------------------------------- */

.recorder {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 26px;
    flex-wrap: wrap;
    padding: 26px 20px;
}

/* --- The mic button: a ring that pulses while listening --- */

.mic {
    position: relative;
    width: 104px;
    height: 104px;
    flex: none;
    border: 0;
    padding: 0;
    border-radius: 50%;
    cursor: pointer;
    background:
        radial-gradient(circle at 32% 28%, #6ea0ff, var(--accent) 46%, #2f6ae0 100%);
    color: #fff;
    box-shadow:
        0 10px 34px rgba(79, 140, 255, 0.34),
        inset 0 1px 0 rgba(255, 255, 255, 0.28);
    transition: transform 0.16s ease, box-shadow 0.22s ease, filter 0.2s ease;
    display: grid;
    place-items: center;
    -webkit-tap-highlight-color: transparent;
}
.mic:hover { transform: translateY(-2px); filter: brightness(1.06); }
.mic:active { transform: translateY(0) scale(0.97); }
.mic:focus-visible { outline: none; box-shadow: 0 0 0 4px var(--accent-ring), 0 10px 34px rgba(79, 140, 255, 0.34); }

.mic svg { width: 38px; height: 38px; display: block; margin-top: 2px; }

.mic__label {
    position: absolute;
    inset: auto 0 -34px 0;
    text-align: center;
    font-size: 12px;
    font-weight: 600;
    letter-spacing: 0.09em;
    text-transform: uppercase;
    color: var(--text-muted);
}

/* Live pulse rings, only rendered while recording. */
.mic__ring {
    position: absolute;
    inset: 0;
    border-radius: 50%;
    border: 2px solid var(--accent);
    opacity: 0;
    pointer-events: none;
}

.mic.is-live { background: radial-gradient(circle at 32% 28%, #ff8f8f, #ff5f5f 46%, #d63b3b 100%); }
.mic.is-live .mic__ring { animation: pulse 1.9s cubic-bezier(0.2, 0.6, 0.3, 1) infinite; }
.mic.is-live .mic__ring:nth-child(2) { animation-delay: 0.65s; }
.mic.is-live .mic__ring:nth-child(3) { animation-delay: 1.3s; }

@keyframes pulse {
    0%   { opacity: 0.65; transform: scale(1); }
    100% { opacity: 0;    transform: scale(1.75); }
}

.mic[disabled] { opacity: 0.5; cursor: not-allowed; transform: none; }

/* --- Side controls --- */

.recorder__side {
    display: flex;
    flex-direction: column;
    gap: 14px;
    min-width: 250px;
}

.field { display: flex; flex-direction: column; gap: 6px; }

.label {
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.07em;
    text-transform: uppercase;
    color: var(--text-dim);
}

select, .text-input {
    appearance: none;
    -webkit-appearance: none;
    width: 100%;
    padding: 9px 13px;
    font-family: inherit;
    font-size: 14px;
    color: var(--text);
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: border-color 0.16s ease, box-shadow 0.16s ease;
}
select {
    padding-right: 34px;
    background-image: url("data:image/svg+xml;charset=utf8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2398a3b6' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 10px center;
    background-size: 15px;
}
select:hover, .text-input:hover { border-color: var(--border-strong); }
select:focus-visible, .text-input:focus-visible {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-soft);
}
select option { background: var(--surface-2); color: var(--text); }

.switch {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 13.5px;
    color: var(--text-muted);
    cursor: pointer;
    user-select: none;
}
.switch input { position: absolute; opacity: 0; pointer-events: none; }
.switch__track {
    position: relative;
    width: 38px;
    height: 22px;
    flex: none;
    border-radius: 999px;
    background: var(--surface-3);
    border: 1px solid var(--border-strong);
    transition: background 0.18s ease, border-color 0.18s ease;
}
.switch__track::after {
    content: "";
    position: absolute;
    top: 2px;
    left: 2px;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--text-muted);
    transition: transform 0.18s cubic-bezier(0.3, 0.8, 0.4, 1), background 0.18s ease;
}
.switch input:checked + .switch__track { background: var(--accent-soft); border-color: var(--accent); }
.switch input:checked + .switch__track::after { transform: translateX(16px); background: var(--accent); }
.switch input:focus-visible + .switch__track { box-shadow: 0 0 0 3px var(--accent-ring); }

/* --- Level meter --- */

.meter {
    height: 6px;
    border-radius: 999px;
    background: var(--surface-3);
    overflow: hidden;
}
.meter__fill {
    height: 100%;
    width: 0%;
    border-radius: 999px;
    background: linear-gradient(90deg, var(--good), var(--accent));
    transition: width 0.08s linear;
}

/* --- Live transcript --- */

.live {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 13px 20px;
    border-top: 1px solid var(--border);
    font-size: 14.5px;
    color: var(--text-muted);
    min-height: 50px;
}
.live__icon {
    flex: none;
    width: 15px;
    height: 15px;
    margin-top: 4px;
    color: var(--accent);
    animation: blink 1.25s ease-in-out infinite;
}
@keyframes blink { 0%, 100% { opacity: 1; } 50% { opacity: 0.25; } }
.live__text { min-height: 1.5em; }
.live__text em { color: var(--text-dim); font-style: italic; }
.live[data-idle="true"] .live__icon { animation: none; opacity: 0.35; }

/* --- Engine status / model download progress --- */

.engine-status {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 11px 20px;
    border-top: 1px solid var(--border);
    background: rgba(79, 140, 255, 0.05);
    font-size: 12.5px;
    color: var(--text-muted);
}

.engine-status__bar {
    flex: 1 1 auto;
    height: 4px;
    min-width: 80px;
    border-radius: 999px;
    background: var(--surface-3);
    overflow: hidden;
}

.engine-status__fill {
    height: 100%;
    width: 0%;
    border-radius: 999px;
    background: linear-gradient(90deg, var(--accent), var(--good));
    transition: width 0.25s ease;
}

/* While the bar is a plain status line, hide the track. */
.engine-status[data-busy="false"] .engine-status__bar { display: none; }
.engine-status[data-busy="false"] .engine-status__text { flex: 1 1 auto; }

.engine-status__text { flex: none; max-width: 65%; }

.engine-status[data-kind="error"] {
    background: var(--danger-soft);
    color: var(--danger);
}
.engine-status[data-kind="good"] {
    background: var(--good-soft);
    color: var(--good);
}
.engine-status[data-kind="warn"] {
    background: var(--warn-soft);
    color: var(--warn);
}

/* Small explanatory line under an engine-related control */
.engine-note {
    padding: 8px 12px;
    font-size: 12.5px;
    line-height: 1.45;
    color: var(--text-muted);
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
}
.engine-note[data-state="good"] {
    color: var(--good);
    border-color: rgba(47, 212, 160, 0.32);
    background: var(--good-soft);
}
.engine-note[data-state="bad"] {
    color: var(--warn);
    border-color: rgba(245, 181, 68, 0.32);
    background: var(--warn-soft);
}
.engine-note code {
    font-family: var(--mono);
    font-size: 11.5px;
}

/* --------------------------------------------------------------------- */
/* Editor                                                                 */
/* --------------------------------------------------------------------- */

.editor { position: relative; }

#transcript {
    width: 100%;
    min-height: 270px;
    max-height: 60vh;
    padding: 18px 20px;
    font-family: var(--font);
    font-size: 16px;
    line-height: 1.68;
    color: var(--text);
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    resize: vertical;
    transition: border-color 0.16s ease, box-shadow 0.16s ease;
}
#transcript::placeholder { color: var(--text-dim); }
#transcript:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-soft);
}

.editor__meta {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 10px 4px 0;
    font-size: 12.5px;
    color: var(--text-dim);
    font-variant-numeric: tabular-nums;
}
.editor__counts { display: flex; gap: 14px; }
.editor__counts b { color: var(--text-muted); font-weight: 600; }

/* --------------------------------------------------------------------- */
/* Toolbar                                                                */
/* --------------------------------------------------------------------- */

.toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    padding: 18px 20px;
    border-top: 1px solid var(--border);
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 9px 15px;
    font-family: inherit;
    font-size: 13.5px;
    font-weight: 550;
    color: var(--text);
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    cursor: pointer;
    white-space: nowrap;
    transition: background 0.16s ease, border-color 0.16s ease,
                transform 0.12s ease, color 0.16s ease, opacity 0.16s ease;
    -webkit-tap-highlight-color: transparent;
}
.btn:hover:not(:disabled) { background: var(--surface-3); border-color: var(--border-strong); }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--accent-ring); }
.btn:disabled { opacity: 0.42; cursor: not-allowed; }

.btn svg { width: 16px; height: 16px; flex: none; }

.btn--primary {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
    box-shadow: 0 2px 10px rgba(79, 140, 255, 0.26);
}
.btn--primary:hover:not(:disabled) { background: #6a9dff; border-color: #6a9dff; }

.btn--ghost { background: transparent; }
.btn--ghost:hover:not(:disabled) { background: var(--surface-2); }

.btn--danger { color: var(--danger); }
.btn--danger:hover:not(:disabled) { background: var(--danger-soft); border-color: var(--danger); }

.btn--sm { padding: 6px 11px; font-size: 12.5px; }

.toolbar__spacer { flex: 1 1 auto; min-width: 0; }

/* Busy state */
.btn.is-busy { position: relative; color: transparent !important; pointer-events: none; }
.btn.is-busy::after {
    content: "";
    position: absolute;
    width: 15px;
    height: 15px;
    border: 2px solid rgba(255, 255, 255, 0.32);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* --------------------------------------------------------------------- */
/* Sections                                                               */
/* --------------------------------------------------------------------- */

.section { display: flex; flex-direction: column; gap: 14px; }

.section__head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
}
.section__title {
    margin: 0;
    font-size: 13px;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--text-muted);
}

.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }

.output {
    padding: 18px 20px;
    font-size: 15.5px;
    line-height: 1.68;
    color: var(--text);
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    min-height: 92px;
    max-height: 320px;
    overflow-y: auto;
    white-space: pre-wrap;
    word-break: break-word;
}
.output:empty::before {
    content: attr(data-placeholder);
    color: var(--text-dim);
}

/* Change list from the correction engine */
.changes {
    margin: 0;
    padding: 0;
    list-style: none;
    max-height: 210px;
    overflow-y: auto;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg-elevated);
}
.changes:empty { display: none; }
.changes li {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 14px;
    font-size: 13px;
    border-bottom: 1px solid var(--border);
}
.changes li:last-child { border-bottom: 0; }
.changes__type {
    flex: none;
    padding: 2px 8px;
    font-size: 10.5px;
    font-weight: 600;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    border-radius: 999px;
    background: var(--surface-3);
    color: var(--text-dim);
}
.changes__from { color: var(--danger); text-decoration: line-through; opacity: 0.85; }
.changes__arrow { color: var(--text-dim); flex: none; }
.changes__to { color: var(--good); font-weight: 550; }

/* --------------------------------------------------------------------- */
/* Notices                                                                */
/* --------------------------------------------------------------------- */

.notice {
    display: flex;
    align-items: flex-start;
    gap: 11px;
    padding: 13px 16px;
    font-size: 13.5px;
    line-height: 1.5;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text-muted);
}
.notice svg { width: 17px; height: 17px; flex: none; margin-top: 1px; }
.notice strong { color: var(--text); font-weight: 600; }
.notice--info   { border-color: rgba(79, 140, 255, 0.34);  background: var(--accent-soft); }
.notice--info svg { color: var(--accent); }
.notice--warn   { border-color: rgba(245, 181, 68, 0.34);  background: var(--warn-soft); }
.notice--warn svg { color: var(--warn); }
.notice--good   { border-color: rgba(47, 212, 160, 0.34);  background: var(--good-soft); }
.notice--good svg { color: var(--good); }
.notice[hidden] { display: none; }

/* --------------------------------------------------------------------- */
/* Toasts                                                                 */
/* --------------------------------------------------------------------- */

.toasts {
    position: fixed;
    right: 20px;
    bottom: 20px;
    z-index: 60;
    display: flex;
    flex-direction: column;
    gap: 9px;
    pointer-events: none;
}

.toast {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 16px;
    min-width: 220px;
    max-width: min(380px, calc(100vw - 40px));
    font-size: 13.5px;
    color: var(--text);
    background: var(--surface-2);
    border: 1px solid var(--border-strong);
    border-left: 3px solid var(--accent);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-lg);
    animation: toast-in 0.24s cubic-bezier(0.2, 0.8, 0.3, 1);
}
.toast svg { width: 17px; height: 17px; flex: none; color: var(--accent); }
.toast--good   { border-left-color: var(--good); }
.toast--good svg { color: var(--good); }
.toast--warn   { border-left-color: var(--warn); }
.toast--warn svg { color: var(--warn); }
.toast--danger { border-left-color: var(--danger); }
.toast--danger svg { color: var(--danger); }
.toast.is-leaving { animation: toast-out 0.2s ease forwards; }

@keyframes toast-in  { from { opacity: 0; transform: translateY(10px) scale(0.97); } }
@keyframes toast-out { to   { opacity: 0; transform: translateY(6px)  scale(0.97); } }

/* --------------------------------------------------------------------- */
/* Footer                                                                 */
/* --------------------------------------------------------------------- */

.footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    flex-wrap: wrap;
    padding: 4px 6px;
    font-size: 12px;
    color: var(--text-dim);
}
.footer a { color: var(--text-muted); text-decoration: none; border-bottom: 1px solid transparent; }
.footer a:hover { color: var(--accent); border-bottom-color: var(--accent); }

/* --------------------------------------------------------------------- */
/* Shortcuts hint                                                         */
/* --------------------------------------------------------------------- */

kbd {
    display: inline-block;
    padding: 1px 6px;
    font-family: var(--mono);
    font-size: 11px;
    color: var(--text-muted);
    background: var(--surface-2);
    border: 1px solid var(--border-strong);
    border-bottom-width: 2px;
    border-radius: 5px;
}

/* --------------------------------------------------------------------- */
/* Responsive                                                             */
/* --------------------------------------------------------------------- */

@media (max-width: 720px) {
    .shell { padding: 24px 14px 48px; gap: 18px; }
    .recorder { gap: 34px; padding: 22px 16px; }
    .recorder__side { min-width: 0; width: 100%; }
    .toolbar { padding: 14px 16px; }
    .toolbar .btn { flex: 1 1 auto; }
    #transcript { min-height: 200px; font-size: 16px; }
    .toasts { left: 14px; right: 14px; bottom: 14px; }
    .toast { max-width: none; }
}

@media (max-width: 420px) {
    .mic { width: 88px; height: 88px; }
    .mic svg { width: 32px; height: 32px; }
    .masthead { justify-content: center; text-align: center; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}