/* =============================================
   Design System — CSS Custom Properties
   ============================================= */

:root {
    /* Matrix Theme Colors */
    --matrix-green: #00ff41;
    --matrix-green-glow: rgba(0, 255, 65, 0.5);
    --matrix-dark: #0d0208;
    --matrix-black: #000000;
    
    /* Typography */
    --font-family: 'JetBrains Mono', 'Courier Prime', monospace;
    --font-size-xs: 0.75rem;
    --font-size-sm: 0.875rem;
    --font-size-base: 1rem;
    --font-size-lg: 1.125rem;
    --font-size-xl: 1.5rem;
    --font-size-2xl: 2rem;

    /* Spacing */
    --space-1: 0.25rem;
    --space-2: 0.5rem;
    --space-3: 0.75rem;
    --space-4: 1rem;
    --space-5: 1.25rem;
    --space-6: 1.5rem;
    --space-8: 2rem;
    --space-10: 2.5rem;
    --space-12: 3rem;

    /* Radius */
    --radius-sm: 4px;
    --radius-md: 8px;
    --radius-lg: 12px;
    --radius-xl: 16px;
    --radius-full: 9999px;

    /* Transitions */
    --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
    --duration-fast: 150ms;
    --duration-normal: 300ms;
    --duration-slow: 500ms;

    /* Z-index */
    --z-base: 1;
    --z-elevated: 10;
    --z-overlay: 100;
}

/* =============================================
   Matrix Theme (Default & Only)
   ============================================= */
[data-theme="dark"], :root {
    --bg-base: var(--matrix-black);
    --bg-elevated: var(--matrix-dark);
    --bg-surface: rgba(13, 2, 8, 0.5);
    --bg-surface-hover: rgba(0, 255, 65, 0.05);
    
    /* Glassmorphism from portal */
    --bg-glass: rgba(13, 2, 8, 0.7);
    --bg-glass-border: rgba(0, 255, 65, 0.2);

    /* Text Colors */
    --text-primary: var(--matrix-green);
    --text-secondary: rgba(0, 255, 65, 0.7);
    --text-muted: rgba(0, 255, 65, 0.4);

    --border-subtle: rgba(0, 255, 65, 0.1);
    --border-default: rgba(0, 255, 65, 0.3);

    /* STT Accent mapping to Matrix Green */
    --accent: var(--matrix-green);
    --accent-hover: #00cc33;
    --accent-glow: var(--matrix-green-glow);
    --accent-subtle: rgba(0, 255, 65, 0.1);

    --recording: #ff003c;
    --recording-glow: rgba(255, 0, 60, 0.3);

    --success: var(--matrix-green);
    --success-subtle: rgba(0, 255, 65, 0.15);

    --shadow-sm: 0 0 10px rgba(0, 255, 65, 0.05);
    --shadow-md: 0 0 20px rgba(0, 255, 65, 0.1);
    --shadow-lg: 0 0 30px rgba(0, 255, 65, 0.15);
    --shadow-glow: 0 0 40px var(--accent-glow);

    /* Hide ambient glows since we have canvas rain */
    --ambient-1: transparent;
    --ambient-2: transparent;
}

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

html {
    font-size: 16px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    font-family: var(--font-family);
    background-color: var(--bg-base);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
    transition: background-color var(--duration-normal) var(--ease-out),
                color var(--duration-normal) var(--ease-out);
    overflow-x: hidden;
}

/* =============================================
   App Shell
   ============================================= */
.app-shell {
    max-width: 800px;
    margin: 0 auto;
    padding: var(--space-4);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    position: relative;
    z-index: var(--z-base);
    perspective: 1000px;
}

/* Mouse Responsive Glow */
#cursor-glow {
    position: fixed;
    width: 300px;
    height: 300px;
    background: radial-gradient(circle, rgba(0, 255, 65, 0.15) 0%, transparent 70%);
    border-radius: 50%;
    pointer-events: none;
    transform: translate(-50%, -50%);
    z-index: 10;
    mix-blend-mode: screen;
}

/* Matrix Background Canvas */
#matrix-rain {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: -1;
    opacity: 0.4;
    pointer-events: none;
}

/* =============================================
   Header
   ============================================= */
.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-bottom: var(--space-6);
    border-bottom: 1px solid var(--border-subtle);
    margin-bottom: var(--space-8);
    position: relative;
    z-index: var(--z-base);
}

.brand {
    display: flex;
    align-items: center;
    gap: var(--space-3);
}

.brand-icon {
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--accent-subtle);
    border-radius: var(--radius-md);
    color: var(--accent);
}

.brand-icon svg {
    width: 20px;
    height: 20px;
}

.brand-title {
    font-size: var(--font-size-xl);
    font-weight: 700;
    letter-spacing: -0.02em;
    color: var(--text-primary);
}

.brand-accent {
    background: linear-gradient(135deg, var(--accent), hsl(calc(var(--accent-h) + 40), var(--accent-s), 65%));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: var(--space-3);
}

/* Select control */
.select-control {
    padding: var(--space-2) var(--space-8) var(--space-2) var(--space-3);
    font-size: var(--font-size-sm);
    font-family: var(--font-family);
    font-weight: 500;
    border: 1px solid var(--border-default);
    border-radius: var(--radius-sm);
    background-color: var(--bg-surface);
    color: var(--text-primary);
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%238b8ba0' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.625rem center;
    transition: border-color var(--duration-fast), background-color var(--duration-fast);
}

.select-control:hover {
    border-color: var(--accent);
}

.select-control:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

/* Icon button */
.icon-btn {
    width: 40px;
    height: 40px;
    border: 1px solid var(--border-default);
    border-radius: var(--radius-sm);
    background: var(--bg-surface);
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--duration-fast);
    position: relative;
}

.icon-btn:hover {
    border-color: var(--accent);
    color: var(--accent);
    background: var(--accent-subtle);
}

.icon-btn svg {
    width: 18px;
    height: 18px;
    position: absolute;
    transition: opacity var(--duration-normal), transform var(--duration-normal);
}

.icon-sun {
    opacity: 0;
    transform: rotate(-90deg) scale(0.5);
}

.icon-moon {
    opacity: 1;
    transform: rotate(0) scale(1);
}

[data-theme="light"] .icon-sun {
    opacity: 1;
    transform: rotate(0) scale(1);
}

[data-theme="light"] .icon-moon {
    opacity: 0;
    transform: rotate(90deg) scale(0.5);
}

/* =============================================
   Main Content
   ============================================= */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--space-8);
    position: relative;
    z-index: var(--z-base);
}

/* =============================================
   Status Bar
   ============================================= */
.status-bar {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    font-size: var(--font-size-sm);
    color: var(--text-secondary);
    height: 1.5rem;
    transition: color var(--duration-fast);
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: var(--radius-full);
    background: var(--text-muted);
    transition: background-color var(--duration-fast), box-shadow var(--duration-fast);
}

.status-bar.recording .status-dot {
    background: var(--recording);
    box-shadow: 0 0 8px var(--recording-glow);
    animation: statusPulse 1.2s ease-in-out infinite;
}

.status-bar.recording .status-text {
    color: var(--recording);
}

.status-bar.processing .status-dot {
    background: var(--accent);
    box-shadow: 0 0 8px var(--accent-glow);
    animation: statusPulse 0.8s ease-in-out infinite;
}

.status-bar.processing .status-text {
    color: var(--accent);
}

@keyframes statusPulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.35; }
}

/* =============================================
   Mic Section
   ============================================= */
.mic-section {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--space-4);
}

.mic-container {
    position: relative;
    width: 120px;
    height: 120px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.mic-btn {
    position: relative;
    z-index: var(--z-elevated);
    width: 80px;
    height: 80px;
    border-radius: var(--radius-full);
    border: none;
    background: linear-gradient(135deg, var(--accent), hsl(calc(var(--accent-h) + 30), var(--accent-s), 58%));
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: var(--shadow-md), 0 0 30px var(--accent-glow);
    transition: transform var(--duration-fast) var(--ease-out),
                box-shadow var(--duration-normal),
                background var(--duration-normal);
}

.mic-btn:hover {
    transform: scale(1.06);
    box-shadow: var(--shadow-lg), 0 0 50px var(--accent-glow);
}

.mic-btn:active {
    transform: scale(0.96);
}

.mic-icon {
    width: 30px;
    height: 30px;
    transition: opacity var(--duration-fast), transform var(--duration-fast);
}

.stop-icon {
    width: 24px;
    height: 24px;
    position: absolute;
    opacity: 0;
    transform: scale(0.5);
    transition: opacity var(--duration-fast), transform var(--duration-fast);
}

/* Recording state */
.mic-container.recording .mic-btn {
    background: linear-gradient(135deg, var(--recording), hsl(calc(var(--recording-h) + 15), 80%, 55%));
    box-shadow: var(--shadow-md), 0 0 40px var(--recording-glow);
}

.mic-container.recording .mic-icon {
    opacity: 0;
    transform: scale(0.5);
}

.mic-container.recording .stop-icon {
    opacity: 1;
    transform: scale(1);
}

/* Pulse rings */
.mic-ring {
    position: absolute;
    width: 80px;
    height: 80px;
    border-radius: var(--radius-full);
    border: 2px solid var(--accent);
    opacity: 0;
    pointer-events: none;
}

.mic-container.recording .mic-ring {
    border-color: var(--recording);
    animation: ringPulse 2s ease-out infinite;
}

.mic-container.recording .ring-2 {
    animation-delay: 0.5s;
}

.mic-container.recording .ring-3 {
    animation-delay: 1s;
}

@keyframes ringPulse {
    0% { transform: scale(1); opacity: 0.6; }
    100% { transform: scale(2.2); opacity: 0; }
}

.mic-hint {
    font-size: var(--font-size-xs);
    color: var(--text-muted);
    text-align: center;
}

.mic-hint kbd {
    display: inline-block;
    padding: 0.1em 0.5em;
    font-size: var(--font-size-xs);
    font-family: var(--font-family);
    background: var(--bg-surface);
    border: 1px solid var(--border-default);
    border-radius: 4px;
    box-shadow: 0 1px 0 var(--border-default);
}

/* =============================================
   Transcript Card (Glass)
   ============================================= */
.glass-card {
    background: var(--bg-glass);
    border: 1px solid var(--bg-glass-border);
    border-radius: var(--radius-lg);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    box-shadow: var(--shadow-sm);
    transition: background var(--duration-normal), border-color var(--duration-normal),
                box-shadow var(--duration-normal);
}

.glass-card {
    background: var(--bg-glass);
    backdrop-filter: blur(15px);
    -webkit-backdrop-filter: blur(15px);
    border: 1px solid var(--bg-glass-border);
    border-radius: var(--radius-lg);
    box-shadow: 0 0 30px rgba(0, 255, 65, 0.1);
    transform-style: preserve-3d;
    transition: transform 0.1s ease-out;
}

.transcript-card {
    width: 100%;
    display: flex;
    flex-direction: column;
    min-height: 200px;
    max-height: 420px;
}

.transcript-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--space-3) var(--space-4);
    border-bottom: 1px solid var(--border-subtle);
}

.transcript-label {
    font-size: var(--font-size-xs);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-muted);
}

.transcript-meta {
    font-size: var(--font-size-xs);
    color: var(--text-muted);
    font-variant-numeric: tabular-nums;
}

.transcript-header-right {
    display: flex;
    align-items: center;
    gap: var(--space-3);
}

/* Source indicator */
.source-indicator {
    font-size: var(--font-size-xs);
    font-weight: 500;
    letter-spacing: 0.02em;
    transition: color var(--duration-fast);
}

.source-indicator.source-browser {
    color: var(--text-muted);
}

.source-indicator.source-whisper {
    color: var(--accent);
}

.source-indicator.source-both {
    color: var(--accent);
}

.transcript-body {
    flex: 1;
    padding: var(--space-4);
    overflow-y: auto;
    position: relative;
}

.transcript-text {
    font-size: var(--font-size-base);
    line-height: 1.7;
    color: var(--text-primary);
    word-wrap: break-word;
}

/* ── Segment Styles ──────────────────────────── */

/* Refined — Whisper-verified text (solid, normal) */
.seg-refined {
    color: var(--text-primary);
    transition: color var(--duration-normal);
    animation: segRefine 600ms ease-out;
}

@keyframes segRefine {
    0% {
        background-color: var(--accent-subtle);
    }
    100% {
        background-color: transparent;
    }
}

/* Draft — browser-only text (lighter, italic) */
.seg-draft {
    color: var(--text-secondary);
    font-style: italic;
    transition: color var(--duration-normal), font-style var(--duration-normal);
}

/* Draft being processed by Whisper — shimmer */
.seg-draft.seg-processing {
    animation: segShimmer 1.5s ease-in-out infinite;
}

@keyframes segShimmer {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.55; }
}

/* Interim — actively being spoken (faint, cursor blink) */
.seg-interim {
    color: var(--text-muted);
    font-style: italic;
    border-right: 2px solid var(--accent);
    padding-right: 2px;
    animation: cursorBlink 0.8s ease-in-out infinite;
}

@keyframes cursorBlink {
    0%, 100% { border-color: var(--accent); }
    50% { border-color: transparent; }
}

.transcript-placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: var(--space-3);
    padding: var(--space-12) 0;
    color: var(--text-muted);
    text-align: center;
}

.transcript-placeholder svg {
    width: 32px;
    height: 32px;
    opacity: 0.4;
}

.transcript-placeholder p {
    font-size: var(--font-size-sm);
    font-style: italic;
}

.transcript-placeholder.hidden {
    display: none;
}

/* Fade out animation */
.transcript-text.fading {
    animation: fadeOut 300ms ease-out forwards;
}

@keyframes fadeOut {
    to { opacity: 0; transform: translateY(-4px); }
}

/* Processing shimmer on transcript card border */
.transcript-card.processing {
    border-color: var(--accent);
    box-shadow: var(--shadow-sm), 0 0 12px var(--accent-glow);
    animation: cardShimmer 2s ease-in-out infinite;
}

@keyframes cardShimmer {
    0%, 100% { border-color: var(--accent); box-shadow: var(--shadow-sm), 0 0 12px var(--accent-glow); }
    50% { border-color: var(--bg-glass-border); box-shadow: var(--shadow-sm); }
}

/* Custom scrollbar for transcript */
.transcript-body::-webkit-scrollbar {
    width: 6px;
}

.transcript-body::-webkit-scrollbar-track {
    background: transparent;
}

.transcript-body::-webkit-scrollbar-thumb {
    background: var(--border-default);
    border-radius: 3px;
}

.transcript-body::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

/* =============================================
   Action Bar
   ============================================= */
.action-bar {
    display: flex;
    gap: var(--space-3);
    flex-wrap: wrap;
    justify-content: center;
}

.action-btn {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-2) var(--space-4);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-sm);
    background: var(--bg-surface);
    color: var(--text-secondary);
    font-size: var(--font-size-sm);
    font-family: var(--font-family);
    font-weight: 500;
    cursor: pointer;
    transition: all var(--duration-fast);
}

.action-btn svg {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
}

.action-btn:hover:not(:disabled) {
    border-color: var(--accent);
    color: var(--accent);
    background: var(--accent-subtle);
    transform: translateY(-1px);
}

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

.action-btn:disabled {
    opacity: 0.35;
    cursor: not-allowed;
}

.btn-success-label {
    display: none;
    color: var(--success);
}

.action-btn.copied .btn-label:first-of-type {
    display: none;
}

.action-btn.copied .btn-success-label {
    display: inline;
}

.action-btn.copied {
    border-color: var(--success);
    background: var(--success-subtle);
    color: var(--success);
}

/* =============================================
   Footer
   ============================================= */
.footer {
    text-align: center;
    padding-top: var(--space-8);
    margin-top: auto;
    font-size: var(--font-size-xs);
    color: var(--text-muted);
    position: relative;
    z-index: var(--z-base);
}

.footer strong {
    font-weight: 600;
    color: var(--text-secondary);
}

/* =============================================
   Responsive
   ============================================= */
@media (max-width: 640px) {
    .app-shell {
        padding: var(--space-4);
    }

    .header {
        flex-wrap: wrap;
        gap: var(--space-3);
    }

    .brand-title {
        font-size: var(--font-size-lg);
    }

    .mic-container {
        width: 100px;
        height: 100px;
    }

    .mic-btn {
        width: 68px;
        height: 68px;
    }

    .mic-ring {
        width: 68px;
        height: 68px;
    }

    .mic-icon {
        width: 26px;
        height: 26px;
    }

    .transcript-card {
        min-height: 160px;
        max-height: 320px;
    }

    .action-bar {
        width: 100%;
    }

    .action-btn {
        flex: 1;
        justify-content: center;
        min-width: 90px;
    }
}

@media (max-width: 380px) {
    .header-actions {
        width: 100%;
        justify-content: space-between;
    }

    .select-control {
        flex: 1;
    }
}
