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

:root {
    --bg-deep: #0a0e27;
    --bg-mid: #111638;
    --bg-surface: #1a1f3a;
    --bg-elevated: #222850;
    --cyan: #00f7ff;
    --cyan-dim: rgba(0, 247, 255, 0.15);
    --cyan-glow: rgba(0, 247, 255, 0.4);
    --text-primary: #e8eaf6;
    --text-secondary: #8892b0;
    --text-dim: #5a6380;
    --user-bubble: #1e3a5f;
    --bot-bubble: #1a1f3a;
    --danger: #ff4757;
    --success: #00e676;
    --warning: #ffc107;
    --radius: 12px;
    --radius-sm: 8px;
    --font: 'SF Pro Text', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
    --font-mono: 'SF Mono', 'Fira Code', 'Consolas', monospace;
}

html, body {
    height: 100%;
    font-family: var(--font);
    background: linear-gradient(160deg, var(--bg-deep) 0%, var(--bg-mid) 50%, var(--bg-deep) 100%);
    color: var(--text-primary);
    overflow: hidden;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
}

.hidden { display: none !important; }

/* ── App Layout ───────────────────────────────────────────────────────── */
#app {
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: 100dvh;
    max-width: 600px;
    margin: 0 auto;
    position: relative;
}

/* ── Header ───────────────────────────────────────────────────────────── */
header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    flex-shrink: 0;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 10px;
}

header h1 {
    font-size: 18px;
    font-weight: 600;
    letter-spacing: 0.5px;
    color: var(--text-primary);
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--text-dim);
    flex-shrink: 0;
}

.status-dot.connecting {
    background: var(--warning);
    animation: blink 1s infinite;
}

.status-dot.connected {
    background: var(--success);
    box-shadow: 0 0 6px var(--success);
}

.status-dot.error {
    background: var(--danger);
}

.status-text {
    font-size: 12px;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 1px;
}

.icon-btn {
    background: none;
    border: 1px solid rgba(255,255,255,0.08);
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    cursor: pointer;
    padding: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.icon-btn:hover {
    color: var(--cyan);
    border-color: var(--cyan-dim);
    background: rgba(0, 247, 255, 0.05);
}

/* ── Transcript ───────────────────────────────────────────────────────── */
.transcript {
    flex: 1;
    overflow-y: auto;
    padding: 0 20px;
    mask-image: linear-gradient(to bottom, transparent 0%, black 5%, black 95%, transparent 100%);
    -webkit-mask-image: linear-gradient(to bottom, transparent 0%, black 5%, black 95%, transparent 100%);
}

.transcript-messages {
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 20px 0;
    min-height: 100%;
    justify-content: flex-end;
}

.message {
    max-width: 85%;
    padding: 10px 16px;
    border-radius: 16px;
    font-size: 14px;
    line-height: 1.5;
    animation: messageIn 0.3s ease-out;
    word-wrap: break-word;
}

.message.user {
    align-self: flex-end;
    background: var(--user-bubble);
    border-bottom-right-radius: 4px;
    color: var(--text-primary);
}

.message.bot {
    align-self: flex-start;
    background: var(--bot-bubble);
    border: 1px solid rgba(255,255,255,0.06);
    border-bottom-left-radius: 4px;
    color: var(--text-primary);
}

.message.bot .bot-label {
    font-size: 11px;
    color: var(--cyan);
    margin-bottom: 4px;
    font-weight: 500;
    letter-spacing: 0.5px;
}

.message.system {
    align-self: center;
    font-size: 12px;
    color: var(--text-dim);
    background: none;
    padding: 4px 0;
}

.message.partial {
    opacity: 0.6;
}

@keyframes messageIn {
    from {
        opacity: 0;
        transform: translateY(8px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ── Waveform ─────────────────────────────────────────────────────────── */
.waveform-container {
    padding: 8px 20px;
    flex-shrink: 0;
}

#waveform {
    width: 100%;
    height: 50px;
    border-radius: var(--radius-sm);
    opacity: 0.5;
    transition: opacity 0.3s;
}

#waveform.active {
    opacity: 1;
}

/* ── Mic Button ───────────────────────────────────────────────────────── */
.mic-area {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    padding: 16px 20px 12px;
    flex-shrink: 0;
}

.mic-button {
    width: 72px;
    height: 72px;
    border-radius: 50%;
    background: rgba(0, 247, 255, 0.06);
    border: 2px solid rgba(0, 247, 255, 0.25);
    color: var(--cyan);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    position: relative;
    -webkit-tap-highlight-color: transparent;
}

.mic-button:hover {
    background: rgba(0, 247, 255, 0.12);
    border-color: rgba(0, 247, 255, 0.4);
}

.mic-button:active {
    transform: scale(0.95);
}

.mic-button.active {
    background: rgba(0, 247, 255, 0.2);
    border-color: var(--cyan);
    box-shadow:
        0 0 20px rgba(0, 247, 255, 0.3),
        0 0 50px rgba(0, 247, 255, 0.15),
        inset 0 0 15px rgba(0, 247, 255, 0.1);
    animation: micPulse 2s ease-in-out infinite;
}

.mic-button.listening {
    animation: micPulse 1s ease-in-out infinite;
    box-shadow:
        0 0 30px rgba(0, 247, 255, 0.5),
        0 0 60px rgba(0, 247, 255, 0.2),
        inset 0 0 20px rgba(0, 247, 255, 0.15);
}

.mic-button.disconnected {
    border-color: rgba(255,255,255,0.1);
    color: var(--text-dim);
    background: rgba(255,255,255,0.03);
}

@keyframes micPulse {
    0%, 100% {
        box-shadow:
            0 0 20px rgba(0, 247, 255, 0.3),
            0 0 50px rgba(0, 247, 255, 0.15);
    }
    50% {
        box-shadow:
            0 0 35px rgba(0, 247, 255, 0.5),
            0 0 70px rgba(0, 247, 255, 0.25);
    }
}

@keyframes blink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.3; }
}

.mic-label {
    font-size: 12px;
    color: var(--text-dim);
    letter-spacing: 0.5px;
}

/* ── Footer ───────────────────────────────────────────────────────────── */
footer {
    display: flex;
    justify-content: center;
    gap: 24px;
    padding: 12px 20px 20px;
    flex-shrink: 0;
}

.footer-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
}

.footer-label {
    font-size: 10px;
    color: var(--text-dim);
    text-transform: uppercase;
    letter-spacing: 1px;
}

.footer-value {
    font-size: 12px;
    color: var(--text-secondary);
    font-family: var(--font-mono);
}

/* ── Settings Panel ───────────────────────────────────────────────────── */
.settings-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 100;
    opacity: 0;
    transition: opacity 0.3s;
}

.settings-overlay:not(.hidden) {
    opacity: 1;
}

.settings-panel {
    position: fixed;
    top: 0;
    right: -320px;
    width: 300px;
    height: 100%;
    background: var(--bg-surface);
    border-left: 1px solid rgba(255,255,255,0.08);
    z-index: 101;
    transition: right 0.3s ease;
    display: flex;
    flex-direction: column;
}

.settings-panel.open {
    right: 0;
}

.settings-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid rgba(255,255,255,0.06);
}

.settings-header h2 {
    font-size: 16px;
    font-weight: 600;
}

.settings-body {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

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

.setting-group label {
    font-size: 12px;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.setting-group input,
.setting-group select {
    background: var(--bg-elevated);
    border: 1px solid rgba(255,255,255,0.08);
    border-radius: var(--radius-sm);
    padding: 10px 12px;
    color: var(--text-primary);
    font-size: 13px;
    font-family: var(--font-mono);
    outline: none;
    transition: border-color 0.2s;
}

.setting-group input:focus,
.setting-group select:focus {
    border-color: var(--cyan);
}

.setting-group select {
    cursor: pointer;
}

.setting-group select option {
    background: var(--bg-surface);
    color: var(--text-primary);
}

/* ── Header Actions ───────────────────────────────────────────────────── */
.header-actions {
    display: flex;
    gap: 6px;
}

/* ── Keyboard Shortcuts Overlay ──────────────────────────────────────── */
.shortcuts-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    z-index: 200;
    display: flex;
    align-items: center;
    justify-content: center;
    animation: fadeIn 0.2s ease;
}

.shortcuts-panel {
    background: var(--bg-surface);
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: var(--radius);
    width: 320px;
    max-width: 90vw;
    box-shadow: 0 20px 60px rgba(0,0,0,0.5);
}

.shortcuts-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid rgba(255,255,255,0.06);
}

.shortcuts-header h2 {
    font-size: 15px;
    font-weight: 600;
}

.shortcuts-body {
    padding: 12px 20px 20px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.shortcut-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.shortcut-row kbd {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 32px;
    padding: 4px 10px;
    background: var(--bg-elevated);
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 6px;
    font-family: var(--font-mono);
    font-size: 12px;
    color: var(--cyan);
    box-shadow: 0 1px 2px rgba(0,0,0,0.3);
}

.shortcut-row span {
    font-size: 13px;
    color: var(--text-secondary);
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* ── Scrollbar ────────────────────────────────────────────────────────── */
::-webkit-scrollbar {
    width: 4px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: rgba(255,255,255,0.1);
    border-radius: 2px;
}

::-webkit-scrollbar-thumb:hover {
    background: rgba(255,255,255,0.2);
}

/* ── Mobile ───────────────────────────────────────────────────────────── */
@media (max-width: 480px) {
    header { padding: 12px 16px; }
    .transcript { padding: 0 16px; }
    .waveform-container { padding: 6px 16px; }
    .mic-area { padding: 12px 16px 8px; }
    footer { padding: 8px 16px 16px; gap: 16px; }

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

    .settings-panel {
        width: 100%;
        right: -100%;
    }
}

/* ── Safe area (notch phones) ─────────────────────────────────────────── */
@supports (padding-top: env(safe-area-inset-top)) {
    header { padding-top: max(16px, env(safe-area-inset-top)); }
    footer { padding-bottom: max(20px, env(safe-area-inset-bottom)); }
}
