/* ============================================================
   AccentBuddy — The Bright Lab
   ============================================================

   A phonetic laboratory instrument on a clean, well-lit
   examination surface. Precise, clinical, unhurried.
   The human voice is the only warm thing that passes through.

   TWO TEMPERATURES
   Teal  — the instrument. Cool, clinical, always watching.
   Red   — the voice. Warm, human, alive.
   The entire UI tension lives between these two.

   FOUR VOICES
   Source Serif 4    — the specimen. Text being examined.
   Literata          — the verdict. Analysis in prose.
   Plus Jakarta Sans — the chrome. UI that stays quiet.
   JetBrains Mono    — the readout. The instrument speaks.

   ============================================================ */

@import url("https://fonts.googleapis.com/css2?family=Source+Serif+4:ital,opsz,wght@0,8..60,400;0,8..60,600;0,8..60,700;1,8..60,400&family=Literata:ital,wght@0,400;0,600;0,700;1,400&family=Plus+Jakarta+Sans:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500&display=swap");

[x-cloak] {
    display: none !important;
}

:root {
    --bg: #fafaf8;
    --surface: #ffffff;
    --surface-raised: #f2f2f0;
    --text: #1a1a1f;
    --text-secondary: #6b6b78;
    --text-tertiary: #9a9aaa;
    --border: rgba(0, 0, 0, 0.08);
    --border-light: rgba(0, 0, 0, 0.05);
    --accent: #e53528;
    --accent-hover: #d42e22;
    --accent-tint: rgba(229, 53, 40, 0.06);
    --accent-glow: rgba(229, 53, 40, 0.2);
    --cyan: #0097a7;
    --cyan-dim: rgba(0, 151, 167, 0.06);
    --cyan-border: rgba(0, 151, 167, 0.15);
    --record-active: #e53528;
    --record-glow: rgba(229, 53, 40, 0.2);
    --success: #00a854;
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.06);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.08);
    --shadow-lg: 0 8px 30px rgba(0, 0, 0, 0.1);
    --radius: 2px;
    --radius-sm: 2px;
    --font-display: "Source Serif 4", Georgia, serif;
    --font-serif: "Literata", Georgia, serif;
    --font-sans: "Plus Jakarta Sans", -apple-system, sans-serif;
    --font-mono: "JetBrains Mono", "SF Mono", monospace;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    background-color: var(--bg);
    background-image:
        linear-gradient(rgba(0, 151, 167, 0.04) 1px, transparent 1px),
        linear-gradient(90deg, rgba(0, 151, 167, 0.04) 1px, transparent 1px),
        radial-gradient(
            ellipse at 30% 0%,
            rgba(229, 53, 40, 0.03) 0%,
            transparent 50%
        ),
        radial-gradient(
            ellipse at 70% 100%,
            rgba(0, 151, 167, 0.03) 0%,
            transparent 50%
        );
    background-size:
        48px 48px,
        48px 48px,
        100% 100%,
        100% 100%;
    background-attachment: fixed;
    color: var(--text);
    font-family: var(--font-sans);
    font-size: 15px;
    line-height: 1.6;
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
}

/* Vignette — soft edge on the bright surface */
body::before {
    content: "";
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 9999;
    background: radial-gradient(
        ellipse at 50% 35%,
        transparent 50%,
        rgba(240, 240, 235, 0.4) 100%
    );
}

/* ---- Auth state toggles ---- */
.visitor .logged-in-only {
    display: none !important;
}
.logged-in .visitor-only {
    display: none !important;
}

/* ---- Page shell ---- */
.page {
    max-width: 640px;
    margin: 0 auto;
    padding: 0 1.5rem 3rem;
}

/* ---- Header ---- */
.top-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1.5rem 0;
    margin-bottom: 1rem;
    border-bottom: 1px solid var(--border);
}

.top-bar-left {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.logo {
    font-family: var(--font-mono);
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text);
    text-decoration: none;
    letter-spacing: 0.12em;
    text-transform: uppercase;
}

.auth-area {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.user-name {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    font-family: var(--font-mono);
    font-size: 0.8rem;
    font-weight: 400;
    color: var(--text-secondary);
}

.provider-icon {
    width: 14px;
    height: 14px;
    color: var(--text-secondary);
    flex-shrink: 0;
    display: none;
    padding-bottom: 2px;
}

body.provider-google .provider-google,
body.provider-telegram .provider-telegram {
    display: inline;
}

.btn-signin {
    font-family: var(--font-mono);
    font-size: 0.75rem;
    font-weight: 500;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: #fff;
    background: var(--accent);
    text-decoration: none;
    padding: 0.5rem 1rem;
    border-radius: var(--radius);
    transition:
        background 0.15s,
        box-shadow 0.15s;
}
.btn-signin:hover {
    background: var(--accent-hover);
    box-shadow: 0 4px 16px var(--accent-glow);
}

.btn-logout {
    font-family: var(--font-mono);
    font-size: 0.75rem;
    font-weight: 400;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--text-tertiary);
    text-decoration: none;
    transition: color 0.2s;
}
.btn-logout:hover {
    color: var(--text-secondary);
}

/* ---- Hero (visitors only) ---- */
.hero-section {
    text-align: left;
    padding: 3.5rem 0 3rem;
}

.hero-section h2 {
    font-family: var(--font-display);
    font-size: 2.8rem;
    font-weight: 400;
    color: var(--text);
    line-height: 1.15;
    letter-spacing: -0.02em;
    margin-bottom: 1rem;
}

.hero-section p {
    font-size: 1rem;
    color: var(--text-secondary);
    line-height: 1.7;
    margin: 0 0 2rem;
}

.btn-cta {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    font-family: var(--font-mono);
    font-size: 0.85rem;
    font-weight: 500;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: #fff;
    background: var(--accent);
    text-decoration: none;
    padding: 0.8rem 1.75rem;
    border-radius: var(--radius);
    border: none;
    cursor: pointer;
    transition: all 0.15s;
    box-shadow: 0 4px 20px var(--accent-glow);
}
.btn-cta:hover {
    background: var(--accent-hover);
    box-shadow:
        0 6px 30px var(--accent-glow),
        0 12px 50px rgba(229, 53, 40, 0.08);
    transform: translateY(-1px);
}

/* ---- Recorder section ---- */
.recorder-section {
    position: relative;
    margin-bottom: 2.5rem;
    isolation: isolate;
}

/* Safari mic-permission hint */
.safari-hint.is-hidden {
    display: none;
}

.safari-hint {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    background: var(--cyan-dim);
    border: 1px solid var(--cyan-border);
    border-radius: var(--radius);
    padding: 0.75rem 1rem;
    margin-bottom: 0.75rem;
    font-family: var(--font-sans);
    font-size: 0.82rem;
    color: var(--text);
    line-height: 1.5;
}

.safari-hint strong {
    color: var(--cyan);
}

.safari-hint .dismiss-hint {
    flex-shrink: 0;
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 1.2rem;
    cursor: pointer;
    padding: 0 0.25rem;
    line-height: 1;
}

.safari-hint .dismiss-hint:hover {
    color: var(--text);
}

/* Payment success banner */
.payment-success-banner {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    margin-top: 0.75rem;
    font-family: var(--font-mono);
    font-size: 0.72rem;
    letter-spacing: 0.03em;
    text-transform: uppercase;
    color: #2e7d32;
}

.payment-success-banner .dismiss-hint {
    flex-shrink: 0;
    background: none;
    border: none;
    color: var(--text-tertiary);
    font-size: 1rem;
    cursor: pointer;
    padding: 0 0.25rem;
    line-height: 1;
}

.payment-success-banner .dismiss-hint:hover {
    color: var(--text-secondary);
}

/* Balance readout */
.balance-banner {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0.6rem 1rem;
    margin-top: 0.75rem;
    font-family: var(--font-mono);
    font-size: 0.72rem;
    letter-spacing: 0.03em;
    color: var(--text-tertiary);
}

.balance-banner a {
    color: var(--text-tertiary);
    text-decoration: none;
    transition: color 0.15s;
}

.balance-banner a:hover,
.balance-banner .inline-form button:hover {
    color: var(--cyan);
}

.balance-banner .inline-form {
    display: inline;
}

.balance-banner .inline-form button {
    all: unset;
    color: var(--text-tertiary);
    cursor: pointer;
    transition: color 0.15s;
}

.recorder {
    background: var(--surface);
    border: 1px solid var(--border);
    border-top: 2px solid var(--cyan);
    border-radius: var(--radius);
    box-shadow: var(--shadow-md);
    padding: 1.5rem 2rem 1rem;
    text-align: center;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: all 0.3s;
}

/* Prompt: instrument activated — incoming signal */
.recorder.mcp-active:not(.is-recording) {
    box-shadow:
        0 0 0 1px rgba(0, 151, 167, 0.2),
        0 4px 20px rgba(0, 151, 167, 0.08),
        0 12px 40px -10px rgba(0, 151, 167, 0.1);
    background: linear-gradient(
            180deg,
            rgba(0, 151, 167, 0.04) 0%,
            transparent 40%
        )
        var(--surface);
    animation: prompt-breathe 3s ease-in-out infinite;
}

@keyframes prompt-breathe {
    0%,
    100% {
        box-shadow:
            0 0 0 1px rgba(0, 151, 167, 0.2),
            0 4px 20px rgba(0, 151, 167, 0.08),
            0 12px 40px -10px rgba(0, 151, 167, 0.1);
    }
    50% {
        box-shadow:
            0 0 0 1px rgba(0, 151, 167, 0.3),
            0 4px 30px rgba(0, 151, 167, 0.12),
            0 16px 50px -10px rgba(0, 151, 167, 0.15);
    }
}

/* Teal pool of light beneath the card */
.recorder-section:has(.mcp-active:not(.is-recording))::after {
    content: "";
    position: absolute;
    left: 5%;
    right: 5%;
    bottom: -10px;
    height: 80px;
    background: radial-gradient(
        ellipse 70% 100% at 50% 0%,
        rgba(0, 151, 167, 0.1),
        transparent 70%
    );
    pointer-events: none;
    z-index: -1;
    animation: prompt-underglow 3s ease-in-out infinite;
}

@keyframes prompt-underglow {
    0%,
    100% {
        opacity: 0.6;
    }
    50% {
        opacity: 1;
    }
}

.recorder.is-recording {
    border-top-color: var(--accent);
    box-shadow:
        0 0 0 1px rgba(229, 53, 40, 0.15),
        0 4px 20px rgba(229, 53, 40, 0.08);
    background: linear-gradient(
        180deg,
        rgba(229, 53, 40, 0.03) 0%,
        var(--surface) 40%
    );
}

/* CTA card for visitors */
.recorder-cta {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    text-decoration: none;
    background: var(--surface);
    border: 1px solid var(--border);
    border-top: 2px solid var(--cyan);
    border-radius: var(--radius);
    box-shadow: var(--shadow-md);
    padding: 2.5rem 2rem;
    margin-bottom: 2.5rem;
    transition: all 0.2s;
}
.recorder-cta:hover {
    border-top-color: var(--accent);
    box-shadow: 0 4px 20px rgba(229, 53, 40, 0.08);
}

.recorder-cta-icon {
    width: 56px;
    height: 56px;
    border-radius: var(--radius);
    background: var(--cyan-dim);
    color: var(--cyan);
    border: 1px solid var(--cyan-border);
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 1.25rem;
}
.recorder-cta-icon svg {
    width: 24px;
    height: 24px;
}

.recorder-cta-title {
    font-family: var(--font-display);
    font-size: 1.4rem;
    font-weight: 400;
    color: var(--text);
    margin-bottom: 0.5rem;
}

.recorder-cta-hint {
    font-size: 0.88rem;
    color: var(--text-secondary);
    margin-bottom: 1.5rem;
}

.recorder-cta-btn {
    display: inline-flex;
    align-items: center;
    font-family: var(--font-mono);
    font-size: 0.8rem;
    font-weight: 500;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: #fff;
    background: var(--accent);
    padding: 0.6rem 1.25rem;
    border-radius: var(--radius);
    transition: background 0.15s;
}
.recorder-cta:hover .recorder-cta-btn {
    background: var(--accent-hover);
}

/* ---- Recorder states ---- */
.state {
    display: none;
}
.state.active {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    flex: 1;
}

.status {
    font-family: var(--font-mono);
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--text-tertiary);
    margin-bottom: 0.75rem;
    letter-spacing: 0.1em;
    text-transform: uppercase;
}

.phrase {
    font-family: var(--font-display);
    font-size: 1.5rem;
    font-weight: 400;
    color: var(--text);
    line-height: 1.4;
    margin-bottom: 1.25rem;
    padding: 0;
    background: var(--surface-raised);
    border: 1px solid var(--border);
    border-left: 3px solid rgba(0, 151, 167, 0.4);
    border-radius: 0 var(--radius) var(--radius) 0;
    align-self: stretch;
    min-height: calc(2 * 1.4em + 2rem);
    display: flex;
    align-items: stretch;
}

.phrase-text {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 1rem 1.25rem;
}

.btn-shuffle {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 42px;
    flex-shrink: 0;
    background: transparent;
    border: none;
    border-left: 1px solid var(--border);
    color: var(--text-tertiary);
    cursor: pointer;
    transition:
        color 0.15s,
        background 0.15s;
}

.btn-shuffle:hover:not(:disabled) {
    color: var(--cyan);
    background: rgba(0, 151, 167, 0.05);
}

.btn-shuffle:disabled {
    color: var(--border);
    cursor: default;
}

.btn-shuffle svg {
    width: 16px;
    height: 16px;
}

/* Icon toggle: cancel hidden by default, shown in prompt state */
.btn-shuffle .icon-cancel {
    display: none;
}

#state-rec.rec-prompt .btn-shuffle .icon-shuffle {
    display: none;
}

#state-rec.rec-prompt .btn-shuffle .icon-cancel {
    display: block;
}

#state-rec.rec-prompt .btn-shuffle:hover:not(:disabled) {
    color: var(--accent);
    background: var(--accent-tint);
}

.phrase-source {
    font-family: var(--font-mono);
    font-size: 0.7rem;
    font-weight: 500;
    color: var(--cyan);
    text-transform: uppercase;
    letter-spacing: 0.1em;
    margin-bottom: 0.5rem;
}

.hint {
    font-size: 0.82rem;
    color: var(--text-tertiary);
}
.hint-key {
    margin-top: 1.5rem;
}

kbd {
    display: inline-block;
    vertical-align: middle;
    background: var(--surface-raised);
    border: 1px solid var(--cyan-border);
    border-radius: var(--radius);
    padding: 0.1em 0.5em;
    font-family: var(--font-mono);
    font-size: 0.72em;
    font-weight: 500;
    color: var(--cyan);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

/* ---- Prompt source row (label + dismiss) ---- */
.prompt-source-row {
    display: flex;
    align-items: baseline;
    gap: 0.6rem;
    margin-bottom: 1rem;
}

.prompt-source-row .phrase-source {
    margin-bottom: 0;
}

.btn-cancel-prompt {
    font-family: var(--font-mono);
    font-size: 0.65rem;
    font-weight: 500;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--text-tertiary);
    background: none;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    cursor: pointer;
    padding: 0.2rem 0.5rem;
    line-height: 1;
    transition: all 0.15s;
}

.btn-cancel-prompt:hover {
    color: var(--accent);
    border-color: rgba(229, 53, 40, 0.2);
    background: var(--accent-tint);
}

/* ---- Record button — THE singular circle ---- */
.btn-record {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 80px;
    height: 80px;
    border-radius: 50%;
    border: none;
    background: var(--accent);
    color: #fff;
    cursor: pointer;
    transition: all 0.15s;
    box-shadow: 0 4px 20px var(--accent-glow);
    position: relative;
}
.btn-record:hover {
    background: var(--accent-hover);
    box-shadow:
        0 6px 30px var(--accent-glow),
        0 12px 50px rgba(229, 53, 40, 0.1);
    transform: scale(1.06);
}
.btn-record:active {
    transform: scale(0.92);
}

.btn-record svg {
    width: 28px;
    height: 28px;
    fill: currentColor;
    position: absolute;
    inset: 0;
    margin: auto;
    transition:
        opacity 0.15s,
        transform 0.15s;
}

.icon-stop {
    opacity: 0;
    transform: scale(0.5);
}

/* Recording pulse — used by rec-recording substate */

@keyframes record-pulse {
    0%,
    100% {
        box-shadow:
            0 0 0 0 var(--record-glow),
            0 4px 20px var(--record-glow);
    }
    50% {
        box-shadow:
            0 0 0 16px transparent,
            0 6px 30px var(--record-glow);
    }
}

/* ---- Rec state: shared layout for ready/prompt/getready/recording ---- */
/* Status row — status text + cancel button inline */
.rec-status-row {
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 1.25rem;
}

.rec-status-row .status {
    margin-bottom: 0;
}

/* Prompt: status and phrase intensify */
#state-rec.rec-prompt .status {
    color: var(--cyan);
}

#state-rec.rec-prompt .phrase {
    border-left-color: var(--cyan);
}

.rec-btn-wrap {
    position: relative;
}

.rec-footer {
    display: flex;
    flex-direction: column;
    align-items: center;
    margin-top: 0;
}

.rec-footer .record-timer {
    height: 1.4em;
    margin-bottom: 0.25rem;
    opacity: 0;
    transition: opacity 0.2s;
}

.rec-footer .hint {
    transition:
        opacity 0.2s,
        color 0.2s;
}

#state-rec.rec-getready .rec-footer .hint {
    opacity: 0;
}

/* Button icon crossfade — shared by is-leaving and rec-recording */

/* Phrase dims during recording */
#state-rec .phrase {
    transition:
        opacity 0.3s,
        border-left-color 0.3s;
}

#state-rec.rec-recording .phrase {
    border-left-color: rgba(229, 53, 40, 0.3);
}

/* Button transitions between states */
#state-rec .btn-record {
    transition:
        background 0.3s,
        box-shadow 0.3s,
        transform 0.15s,
        color 0.3s;
}

/* Getready: button dims, cyan pulses radiate immediately */
#state-rec.rec-getready .btn-record {
    background: rgba(229, 53, 40, 0.15);
    pointer-events: none;
    cursor: default;
    animation: getready-pulse 1.5s ease-in-out infinite;
}

@keyframes getready-pulse {
    0%,
    100% {
        box-shadow:
            0 0 0 0 rgba(229, 53, 40, 0.2),
            0 4px 16px rgba(229, 53, 40, 0.08);
    }
    50% {
        box-shadow:
            0 0 0 12px transparent,
            0 4px 24px rgba(229, 53, 40, 0.08);
    }
}

/* Getready OUT: icon crossfade — delayed 150ms into the release */
#state-rec.is-leaving .icon-mic {
    opacity: 0;
    transform: scale(0.5);
    transition-delay: 0.15s;
}

#state-rec.is-leaving .icon-stop {
    opacity: 1;
    transform: scale(1);
    transition-delay: 0.15s;
}

/* Getready OUT: button reignites, pulse stops */
#state-rec.is-leaving .btn-record {
    background: var(--accent);
    box-shadow:
        0 0 0 0 transparent,
        0 4px 20px var(--accent-glow);
    animation: none;
    transition:
        background 0.3s ease-out,
        box-shadow 0.3s ease-out;
}

/* Getready OUT: phrase border syncs with widget */
#state-rec.is-leaving .phrase {
    border-left-color: rgba(229, 53, 40, 0.3);
}

/* Getready OUT: widget border starts going red early */
.recorder:has(#state-rec.is-leaving) {
    border-top-color: var(--accent);
    box-shadow:
        0 0 0 1px rgba(229, 53, 40, 0.15),
        0 4px 20px rgba(229, 53, 40, 0.08);
}

/* Recording: icon stays as stop */
#state-rec.rec-recording .icon-mic {
    opacity: 0;
    transform: scale(0.5);
}

#state-rec.rec-recording .icon-stop {
    opacity: 1;
    transform: scale(1);
}

#state-rec.rec-recording .btn-record {
    background: var(--record-active);
    box-shadow:
        0 0 0 0 var(--record-glow),
        0 4px 20px var(--record-glow);
    animation: record-pulse 1.2s ease-in-out infinite;
}

#state-rec.rec-recording .rec-footer .record-timer {
    opacity: 1;
}

.record-timer {
    font-family: var(--font-mono);
    font-size: 1.15rem;
    font-weight: 500;
    color: var(--accent);
    letter-spacing: 0.08em;
}

/* ---- Generic action buttons ---- */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    font-family: var(--font-mono);
    font-size: 0.8rem;
    font-weight: 500;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    padding: 0.6rem 1.5rem;
    border-radius: var(--radius);
    border: none;
    cursor: pointer;
    transition: all 0.15s;
}

.btn-primary {
    background: var(--accent);
    color: #fff;
}
.btn-primary:hover {
    background: var(--accent-hover);
    box-shadow: 0 4px 16px var(--accent-glow);
}

.btn-ghost {
    background: transparent;
    color: var(--text-secondary);
    border: 1px solid var(--border);
}
.btn-ghost:hover {
    color: var(--text);
    border-color: rgba(0, 0, 0, 0.12);
}

/* ---- Results (audio + body used in history detail) ---- */
.results-audio {
    margin-bottom: 1.25rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--border);
}

.results-audio audio {
    width: 100%;
    height: 36px;
    border-radius: var(--radius);
    filter: none;
}

/* Markdown content — the human voice in analysis */
.results-body {
    font-family: var(--font-serif);
    font-size: 0.95rem;
    line-height: 1.8;
    color: var(--text);
}

.results-body h1,
.results-body h2,
.results-body h3 {
    font-family: var(--font-sans);
    font-weight: 700;
    color: var(--text);
    margin-top: 1.5rem;
    margin-bottom: 0.5rem;
}

.results-body h1 {
    font-size: 1.15rem;
}
.results-body h2 {
    font-size: 1rem;
}
.results-body h3 {
    font-size: 0.92rem;
}

.results-body p {
    margin-bottom: 0.75rem;
}

.results-body ul,
.results-body ol {
    margin-bottom: 0.75rem;
    padding-left: 1.5rem;
}

.results-body li {
    margin-bottom: 0.4rem;
}

.results-body strong {
    font-weight: 700;
    color: var(--text);
}

.results-body em {
    font-style: italic;
}

.results-body code {
    font-family: var(--font-mono);
    font-size: 0.85em;
    background: var(--surface-raised);
    border: 1px solid var(--border);
    padding: 0.15em 0.4em;
    border-radius: var(--radius);
}

.results-body pre {
    background: var(--surface-raised);
    border: 1px solid var(--border);
    border-left: 3px solid rgba(0, 151, 167, 0.3);
    border-radius: 0 var(--radius) var(--radius) 0;
    padding: 1rem;
    overflow-x: auto;
    margin-bottom: 0.75rem;
    font-family: var(--font-mono);
    font-size: 0.82rem;
    line-height: 1.5;
}

/* ---- Spinner ---- */
.spinner {
    width: 36px;
    height: 36px;
    border: 2px solid rgba(0, 151, 167, 0.15);
    border-top-color: var(--cyan);
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
    margin: 1.5rem auto;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* ---- Controls & action zone ---- */
.rec-controls {
    display: flex;
    flex-direction: column;
    align-items: center;
    height: 140px;
}

.rec-action-zone {
    display: none;
    height: 140px;
    position: relative;
    align-self: stretch;
    margin-left: -2rem;
    margin-right: -2rem;
}

.action-submitting,
.action-error {
    display: none;
}

/* Submitting state */
#state-rec.rec-submitting .rec-controls {
    display: none;
}
#state-rec.rec-submitting .rec-action-zone {
    display: block;
}
#state-rec.rec-submitting .action-submitting {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    position: relative;
}

#state-rec.rec-submitting .status {
    color: var(--cyan);
    letter-spacing: 0.12em;
}

#state-rec.rec-submitting .btn-shuffle {
    pointer-events: none;
    color: var(--border);
}

.recorder:has(#state-rec.rec-submitting) {
    border-top-color: var(--cyan);
    box-shadow:
        0 0 0 1px rgba(0, 151, 167, 0.15),
        0 4px 20px rgba(0, 151, 167, 0.08);
}

/* Error state */
#state-rec.rec-error .rec-controls {
    display: none;
}
#state-rec.rec-error .rec-action-zone {
    display: block;
}
#state-rec.rec-error .action-error {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
}

#state-rec.rec-error .status {
    color: var(--accent);
}

#state-rec.rec-error .btn-shuffle {
    pointer-events: none;
    color: var(--border);
}

.btn-retry {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    font-family: var(--font-mono);
    font-size: 0.8rem;
    font-weight: 500;
    letter-spacing: 0.06em;
    color: var(--text-secondary);
    background: var(--surface-raised);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.5rem 1.25rem;
    cursor: pointer;
    transition:
        color 0.15s,
        border-color 0.15s,
        background 0.15s;
}

.btn-retry:hover {
    color: var(--text);
    border-color: var(--text-tertiary);
    background: var(--surface);
}

/* ---- Scanning beam (analysis state) ---- */

/* The beam — a teal line sweeping the action zone */
#state-rec.rec-submitting .action-submitting::before {
    content: "";
    position: absolute;
    left: 0;
    right: 0;
    height: 2px;
    background: var(--cyan);
    box-shadow:
        0 0 4px 1px rgba(0, 151, 167, 0.3),
        0 0 10px 2px rgba(0, 151, 167, 0.1);
    mix-blend-mode: multiply;
    animation: scan-beam 2.5s ease-in-out infinite;
    z-index: 2;
    pointer-events: none;
}

/* Analysis grid — materializes during scan */
#state-rec.rec-submitting .action-submitting::after {
    content: "";
    position: absolute;
    inset: 0;
    background-image:
        linear-gradient(rgba(0, 151, 167, 0.04) 1px, transparent 1px),
        linear-gradient(90deg, rgba(0, 151, 167, 0.04) 1px, transparent 1px);
    background-size: 24px 24px;
    z-index: 0;
    opacity: 0;
    animation: grid-reveal 2.5s ease-in-out infinite;
    pointer-events: none;
}

@keyframes scan-beam {
    0%,
    100% {
        top: 0%;
        opacity: 0.5;
    }
    50% {
        top: 100%;
        opacity: 0.7;
    }
}

@keyframes grid-reveal {
    0%,
    100% {
        opacity: 0;
    }
    25%,
    75% {
        opacity: 1;
    }
}

/* Waveform histogram — real voice amplitude for the beam to scan */
.waveform {
    position: absolute;
    top: 0;
    bottom: 0;
    left: 0;
    right: 0;
    display: flex;
    align-items: center;
    gap: 2px;
    padding: 0 1rem;
    z-index: 1;
    pointer-events: none;
    opacity: 0;
    animation: waveform-in 0.8s ease-out 0.2s forwards;
}

.waveform-bar {
    flex: 1;
    background: rgba(229, 53, 40, 0.35);
    border-radius: 1px;
    min-height: 1%;
}

@keyframes waveform-in {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

/* ---- Example preview (visitor) ---- */
.example-section {
    margin-bottom: 2.5rem;
}

.example-label {
    font-family: var(--font-mono);
    font-size: 0.7rem;
    font-weight: 500;
    color: var(--text-tertiary);
    text-transform: uppercase;
    letter-spacing: 0.12em;
    margin-bottom: 0.75rem;
    text-align: left;
}

.example-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-left: 3px solid rgba(0, 151, 167, 0.3);
    border-radius: 0 var(--radius) var(--radius) 0;
    box-shadow: var(--shadow-sm);
    padding: 1.5rem;
    font-family: var(--font-serif);
    font-size: 0.88rem;
    line-height: 1.7;
    color: var(--text-secondary);
    position: relative;
    max-height: 320px;
    overflow: hidden;
}

.example-card::after {
    content: "";
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 80px;
    background: linear-gradient(transparent, var(--surface));
    pointer-events: none;
}

.example-card p {
    margin-bottom: 0.5rem;
}
.example-card strong {
    color: var(--text);
}

/* ---- The practice loop ---- */
.loop-section {
    margin-bottom: 2.5rem;
}

.loop-strip {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
    gap: 0.5rem 1.25rem;
}

.loop-step {
    text-align: center;
}

.loop-actor {
    display: block;
    font-family: var(--font-mono);
    font-size: 0.65rem;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-tertiary);
    margin-bottom: 0.15rem;
}

.loop-title {
    display: block;
    font-family: var(--font-sans);
    font-weight: 700;
    font-size: 1.8rem;
    text-transform: uppercase;
    letter-spacing: 0.01em;
    line-height: 1.1;
}

.loop-color-record { color: var(--accent); }
.loop-color-analyze { color: var(--cyan); }
.loop-color-guide { color: #d97757; }

.loop-sub {
    display: block;
    font-family: var(--font-sans);
    font-size: 0.78rem;
    color: var(--text-secondary);
    margin-top: 0.15rem;
}

.loop-sep {
    font-size: 1.2rem;
    color: var(--text-tertiary);
    flex-shrink: 0;
    padding-bottom: 0.5rem;
}


/* ---- MCP / setup section ---- */
.setup-section {
    margin-bottom: 2rem;
}

.setup-section h3 {
    font-family: var(--font-display);
    font-size: 1.3rem;
    font-weight: 400;
    color: var(--text);
    margin-bottom: 0.5rem;
}

.setup-section p {
    font-size: 0.88rem;
    color: var(--text-secondary);
    margin-bottom: 0.75rem;
}

.url-copy-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    background: var(--surface-raised);
    border: 1px solid var(--border);
    border-left: 3px solid rgba(0, 151, 167, 0.3);
    border-radius: 0 var(--radius) var(--radius) 0;
    padding: 0.6rem 0.75rem;
    margin-bottom: 0.75rem;
}

.url-copy-row code {
    flex: 1;
    font-family: var(--font-mono);
    font-size: 0.85rem;
    color: var(--text);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.btn-copy {
    flex-shrink: 0;
    font-family: var(--font-mono);
    background: transparent;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.3rem 0.6rem;
    cursor: pointer;
    font-size: 0.7rem;
    font-weight: 500;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--text-secondary);
    transition: all 0.15s;
}
.btn-copy:hover {
    color: var(--text);
    border-color: rgba(0, 0, 0, 0.12);
}
.btn-copy.copied {
    color: var(--success);
    border-color: var(--success);
}

/* Collapsible details */
.setup-details summary {
    font-family: var(--font-mono);
    font-size: 0.78rem;
    font-weight: 500;
    letter-spacing: 0.04em;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 0.25rem 0;
    transition: color 0.2s;
}
.setup-details summary:hover {
    color: var(--text);
}

.setup-guide {
    margin-top: 0.75rem;
}

.setup-guide h4 {
    font-family: var(--font-display);
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--text);
    margin: 0 0 0.4rem 0;
}

.setup-guide h4:not(:first-child) {
    margin-top: 1rem;
}

.setup-steps {
    margin: 0 0 0.25rem 0;
    padding-left: 1.4rem;
    font-size: 0.85rem;
    line-height: 1.7;
    color: var(--text-secondary);
}

.setup-steps strong {
    color: var(--text);
    font-weight: 500;
}

.setup-note {
    font-size: 0.78rem;
    color: var(--text-tertiary);
    margin: 0.25rem 0 0 0;
}

.setup-details pre {
    background: var(--surface-raised);
    border: 1px solid var(--border);
    border-left: 3px solid rgba(0, 151, 167, 0.2);
    border-radius: 0 var(--radius) var(--radius) 0;
    padding: 1rem;
    margin-top: 0.5rem;
    overflow-x: auto;
    font-family: var(--font-mono);
    font-size: 0.8rem;
    line-height: 1.5;
    color: var(--text);
}

/* ---- Footer ---- */
.footer {
    text-align: center;
    padding: 1.5rem 0;
    border-top: 1px solid var(--border);
    font-size: 0.78rem;
    color: var(--text-tertiary);
}

.footer a {
    color: var(--cyan);
    text-decoration: none;
    transition: color 0.2s;
}
.footer a:hover {
    color: var(--text);
}

/* ---- Language picker ---- */
.lang-picker {
    position: relative;
}
.lang-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    background: none;
    border: none;
    border-radius: 4px;
    padding: 0.2rem 0.35rem;
    font-size: 0.7rem;
    font-weight: 500;
    color: var(--text-tertiary);
    cursor: pointer;
    font-family: var(--font-ui);
    letter-spacing: 0.04em;
    transition: color 0.15s;
}
.lang-globe {
    width: 13px;
    height: 13px;
    stroke: currentColor;
    flex-shrink: 0;
}
.lang-btn:hover {
    color: var(--text-secondary);
}
.lang-dropdown {
    position: absolute;
    left: 0;
    top: calc(100% + 4px);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 0.25rem;
    min-width: 120px;
    box-shadow: var(--shadow-md);
    z-index: 100;
}
.lang-option {
    display: block;
    width: 100%;
    text-align: left;
    background: none;
    border: none;
    padding: 0.5rem 0.75rem;
    font-size: 0.85rem;
    cursor: pointer;
    border-radius: 4px;
    color: var(--text-primary);
    font-family: var(--font-ui);
}
.lang-option:hover {
    background: var(--bg);
}
.lang-option.active {
    font-weight: 600;
    color: var(--accent);
}

/* ---- Login page ---- */
.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem;
}

.login-container {
    max-width: 380px;
    width: 100%;
    text-align: center;
}

.login-container .logo {
    font-size: 1.1rem;
    margin-bottom: 0.75rem;
    display: block;
}

.login-container .subtitle {
    color: var(--text-secondary);
    font-size: 0.9rem;
    margin-bottom: 2.5rem;
}

.login-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-top: 2px solid var(--cyan);
    border-radius: var(--radius);
    box-shadow: var(--shadow-md);
    padding: 2rem;
}

.login-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.6rem;
    width: 100%;
    padding: 0.75rem 1.25rem;
    margin-bottom: 0.75rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-family: var(--font-sans);
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    text-align: center;
    transition: all 0.15s;
}
.login-btn:last-child {
    margin-bottom: 0;
}

.login-btn-google {
    background: rgba(0, 0, 0, 0.03);
    color: var(--text);
}
.login-btn-google:hover {
    background: rgba(0, 0, 0, 0.06);
    border-color: rgba(0, 0, 0, 0.12);
}

.login-btn-telegram {
    background: #2aabee;
    color: #fff;
    border-color: #2aabee;
}
.login-btn-telegram:hover {
    background: #1c96d5;
    border-color: #1c96d5;
}

.login-btn svg {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
}

.login-divider {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin: 1rem 0;
    color: var(--text-tertiary);
    font-family: var(--font-mono);
    font-size: 0.72rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}
.login-divider::before,
.login-divider::after {
    content: "";
    flex: 1;
    height: 1px;
    background: var(--border);
}

/* Telegram auth section */
.telegram-auth-section {
    padding: 1.5rem;
    text-align: center;
}

.telegram-auth-section p {
    font-size: 0.88rem;
    color: var(--text-secondary);
    margin-bottom: 0.5rem;
}

.telegram-deep-link {
    color: var(--cyan);
    font-size: 0.85rem;
    word-break: break-all;
}

.telegram-short-code {
    font-family: var(--font-mono);
    font-size: 2rem;
    font-weight: 700;
    letter-spacing: 0.2em;
    color: var(--accent);
    margin: 0.75rem 0;
}

.poll-status {
    font-family: var(--font-mono);
    font-size: 0.75rem;
    letter-spacing: 0.04em;
    color: var(--text-tertiary);
}

/* ---- Error ---- */
.error-text {
    color: var(--accent);
}

/* ---- Responsive ---- */
@media (max-width: 520px) {
    .page {
        padding: 0 1rem 2rem;
    }

    .hero-section h2 {
        font-size: 2rem;
    }

    .loop-strip {
        flex-direction: column;
        gap: 0.4rem;
    }

    .loop-sep {
        transform: rotate(90deg);
    }


    .recorder {
        padding: 1.5rem 1.25rem 1rem;
    }

    .setup-compact {
        flex-direction: column;
        align-items: stretch;
        gap: 0.5rem;
    }
}

/* ---- History / Lab Journal ---- */
.history-section {
    margin-bottom: 2.5rem;
}

.history-header {
    margin-bottom: 1rem;
}

.history-title {
    font-family: var(--font-mono);
    font-size: 0.75rem;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--text-tertiary);
}

.history-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-left: 3px solid rgba(0, 151, 167, 0.3);
    border-radius: 0 var(--radius) var(--radius) 0;
    padding: 1rem 1.25rem;
    margin-bottom: 0.5rem;
    transition: all 0.2s;
}

.history-card:not(.is-expanded):hover {
    border-left-color: var(--cyan);
    background: var(--surface-raised);
}

.history-card.is-expanded {
    border-left-color: var(--cyan);
    box-shadow: var(--shadow-md);
}

.history-card-summary {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    cursor: pointer;
}

.history-card-transcript {
    font-family: var(--font-serif);
    font-size: 0.95rem;
    color: var(--text);
    line-height: 1.5;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.history-card.is-expanded .history-card-transcript {
    white-space: normal;
}

.history-card-ipa {
    font-family: var(--font-mono);
    font-size: 0.82rem;
    color: var(--text-secondary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.history-card.is-expanded .history-card-ipa {
    white-space: normal;
}

.history-card-meta {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-top: 0.25rem;
}

.history-card-time {
    font-family: var(--font-mono);
    font-size: 0.7rem;
    color: var(--text-tertiary);
    letter-spacing: 0.04em;
}

.history-card-badge {
    font-family: var(--font-mono);
    font-size: 0.65rem;
    font-weight: 500;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    padding: 0.15em 0.5em;
    border-radius: 2px;
    background: var(--cyan-dim);
    color: var(--cyan);
    border: 1px solid var(--cyan-border);
}

.badge-mcp {
    background: var(--cyan-dim);
    color: var(--cyan);
    border-color: var(--cyan-border);
}

.badge-comparison {
    background: rgba(168, 130, 255, 0.1);
    color: #a882ff;
    border-color: rgba(168, 130, 255, 0.25);
}


.comparison-focus {
    font-style: italic;
}

.comparison-recordings {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    margin-bottom: 1rem;
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.comparison-recording {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    padding: 0.5rem 0.65rem;
    border-radius: var(--radius);
    background: rgba(168, 130, 255, 0.04);
    border: 1px solid rgba(168, 130, 255, 0.12);
}

.comparison-recording-header {
    display: flex;
    align-items: baseline;
    gap: 0.25rem;
}

.comparison-recording audio {
    width: 100%;
    height: 32px;
    border-radius: var(--radius);
}

.comparison-label {
    font-weight: 600;
    color: #a882ff;
    flex-shrink: 0;
}

.history-card-detail {
    display: none;
    margin-top: 1rem;
    padding-top: 1rem;
    border-top: 1px solid var(--border);
}

.history-card.is-expanded .history-card-detail {
    display: block;
}

.history-card-detail .results-body {
    font-family: var(--font-serif);
    font-size: 0.92rem;
    line-height: 1.75;
    color: var(--text);
}

.history-card-detail .results-audio {
    margin-bottom: 1rem;
}

.history-card-detail .results-audio audio {
    width: 100%;
    height: 36px;
    border-radius: var(--radius);
    filter: none;
}

.history-card-detail .prosody-section {
    margin-top: 0.75rem;
    padding: 0.6rem 0.75rem;
    border-top: 1px solid var(--border);
    font-family: var(--font-mono);
    font-size: 0.78rem;
    color: var(--text-secondary);
    line-height: 1.6;
}

.prosody-section .prosody-label {
    color: var(--text-tertiary);
    font-size: 0.7rem;
    margin-bottom: 0.25rem;
}

.prosody-section .prosody-word-map {
    margin-top: 0.35rem;
    word-spacing: 0.15em;
}

/* ---- Specimen Strip — per-word analysis ---- */
.specimen-strip {
    padding: 0.75rem 0;
    border-bottom: 1px solid var(--border);
    margin-bottom: 1rem;
}

.specimen-words {
    display: flex;
    flex-wrap: wrap;
    gap: 0.15rem 0.4rem;
    align-items: flex-end;
    margin-bottom: 0.6rem;
}

.specimen-w {
    position: relative;
    padding-top: 16px;
}

.specimen-contour {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 16px;
    color: var(--cyan);
}

.specimen-contour-spacer {
    display: none;
}

.specimen-word-text {
    font-family: var(--font-display);
    font-size: 1.1rem;
    color: var(--text);
    line-height: 1.3;
}

.specimen-w.has-issues .specimen-word-text {
    color: var(--accent);
}

.specimen-pause {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 0 0.1rem;
}

/* Invisible spacer matching word-text height — pushes dots up to contour level */
.specimen-pause::after {
    content: '';
    height: calc(1.1rem * 1.3);
}

.specimen-pause-dots {
    font-family: var(--font-mono);
    font-size: 0.75rem;
    color: var(--cyan);
    letter-spacing: 0.2em;
    line-height: 1;
}

.specimen-pause-label {
    font-family: var(--font-mono);
    font-size: 0.55rem;
    color: var(--text-tertiary);
    line-height: 1;
    margin-top: 2px;
}

.specimen-issue-line {
    font-family: var(--font-serif);
    font-size: 0.92rem;
    color: var(--text);
    line-height: 1.75;
}

.specimen-issue-line strong {
    font-weight: 700;
}

.specimen-no-issues {
    font-family: var(--font-serif);
    font-size: 0.92rem;
    color: var(--text-tertiary);
    line-height: 1.75;
}

.history-card-detail .detail-meta {
    margin-top: 0.75rem;
    padding-top: 0.75rem;
    border-top: 1px solid var(--border);
    font-family: var(--font-mono);
    font-size: 0.7rem;
    color: var(--text-tertiary);
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem 1rem;
}

.history-detail-spinner {
    display: flex;
    justify-content: center;
    padding: 1rem 0;
}

.history-empty {
    text-align: center;
    padding: 2rem 1rem;
    color: var(--text-tertiary);
    font-size: 0.88rem;
}

.history-loading {
    display: flex;
    justify-content: center;
    padding: 1.5rem 0;
}

.history-load-more {
    display: block;
    width: 100%;
    margin-top: 0.5rem;
    text-align: center;
}

.is-hidden {
    display: none !important;
}

@media (max-width: 520px) {
    .history-card-transcript,
    .history-card-ipa {
        white-space: normal;
    }

    .history-card {
        padding: 0.85rem 1rem;
    }
}

/* ---- Animations ---- */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(12px) scale(0.98);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

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