/* tkor-mic — AI-native redesign (v2.11)
 *
 * Design language: morphing capsule with glassy material, aurora gradient
 * ring during recording, gold spinning arc during processing. Inspired by
 * Wispr Flow + Apple Intelligence + ChatGPT voice mode.
 *
 * Selectors and DOM structure unchanged from v2.10 — this is a pure
 * visual upgrade. Existing JS continues to drive state via data-state
 * and existing class names.
 */

/* === Sidebar mic button (kept for noVNC sidebar fallback) === */

#tkor_mic_button {
    position: relative;
    cursor: pointer;
    user-select: none;
}

#tkor_mic_button .tkor-mic-icon {
    width: 28px;
    height: 28px;
    display: block;
    margin: 4px auto;
    color: #c0c0c0;
    transition: color 0.15s ease;
}

#tkor_mic_button[data-state="recording"] .tkor-mic-icon,
#tkor_mic_button[data-state="transcribing"] .tkor-mic-icon {
    display: none;
}

#tkor_mic_button[data-state="error"] .tkor-mic-icon {
    color: #ff4d8d;
    display: block;
}

#tkor_mic_button .tkor-mic-bars {
    display: none;
    align-items: center;
    justify-content: center;
    gap: 3px;
    width: 36px;
    height: 36px;
    margin: 0 auto;
}
#tkor_mic_button[data-state="recording"] .tkor-mic-bars,
#tkor_mic_button[data-state="transcribing"] .tkor-mic-bars {
    display: flex;
}
#tkor_mic_button .tkor-mic-bars span {
    display: block;
    width: 3px;
    height: 12px;
    border-radius: 2px;
    transition: height 80ms ease-out;
}
#tkor_mic_button[data-state="recording"] .tkor-mic-bars span {
    background: linear-gradient(180deg, #ff8aa8, #ff4d8d);
    box-shadow: 0 0 6px rgba(255, 77, 141, 0.6);
}
#tkor_mic_button[data-state="transcribing"] .tkor-mic-bars span {
    background: linear-gradient(180deg, #ffe88a, #ffb04d);
    box-shadow: 0 0 6px rgba(255, 176, 77, 0.55);
    animation: tkor-mic-process 1.05s ease-in-out infinite;
    transition: none;
}
#tkor_mic_button[data-state="transcribing"] .tkor-mic-bars span:nth-child(1) { animation-delay: 0.00s; }
#tkor_mic_button[data-state="transcribing"] .tkor-mic-bars span:nth-child(2) { animation-delay: 0.10s; }
#tkor_mic_button[data-state="transcribing"] .tkor-mic-bars span:nth-child(3) { animation-delay: 0.20s; }
#tkor_mic_button[data-state="transcribing"] .tkor-mic-bars span:nth-child(4) { animation-delay: 0.30s; }
#tkor_mic_button[data-state="transcribing"] .tkor-mic-bars span:nth-child(5) { animation-delay: 0.40s; }

@keyframes tkor-mic-process {
    0%, 100% { height: 10px; opacity: 0.55; }
    50%      { height: 28px; opacity: 1;    }
}

/* === Toast — glassy, with subtle gradient mark === */

#tkor_mic_toast {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%) translateY(8px);
    background: rgba(15, 18, 28, 0.92);
    color: #f5f5f7;
    padding: 12px 18px;
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 14px;
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    font: 14px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", "Inter", sans-serif;
    max-width: 60%;
    box-shadow: 0 8px 28px rgba(0,0,0,0.45);
    pointer-events: none;
    opacity: 0;
    transition: opacity 200ms ease, transform 220ms cubic-bezier(0.34, 1.56, 0.64, 1);
    z-index: 999999;
}
#tkor_mic_toast.visible {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

/* === Floating cluster: capsule + camera + gear === */

#tkor_mic_floating_wrap {
    position: fixed;
    top: 8px;
    right: 110px;
    display: flex;
    align-items: center;
    gap: 8px;
    z-index: 999998;
    font: 14px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", "Inter", sans-serif;
}

/* The morphing mic capsule. Idle = compact circle. Recording/transcribing
 * grow it into a horizontal pill. */
#tkor_mic_floating {
    position: relative;
    height: 40px;
    min-width: 40px;
    padding: 0;
    background: rgba(20, 22, 35, 0.78);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 999px;
    cursor: pointer;
    user-select: none;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 20px rgba(0,0,0,0.36),
                inset 0 1px 0 rgba(255,255,255,0.05);
    backdrop-filter: blur(18px);
    -webkit-backdrop-filter: blur(18px);
    color: #f5f5f7;
    transition: padding 220ms cubic-bezier(0.34, 1.56, 0.64, 1),
                min-width 220ms cubic-bezier(0.34, 1.56, 0.64, 1),
                background 220ms ease,
                box-shadow 220ms ease;
    overflow: visible;
    z-index: 1;  /* above the gradient ring pseudo-element */
}
#tkor_mic_floating:hover {
    background: rgba(40, 42, 60, 0.85);
}

#tkor_mic_floating .tkor-mic-icon {
    width: 18px;
    height: 18px;
    color: rgba(245, 245, 247, 0.78);
    transition: color 150ms ease;
}
#tkor_mic_floating:hover .tkor-mic-icon {
    color: #f5f5f7;
}
#tkor_mic_floating[data-state="recording"] .tkor-mic-icon,
#tkor_mic_floating[data-state="transcribing"] .tkor-mic-icon {
    display: none;
}
#tkor_mic_floating[data-state="error"] .tkor-mic-icon {
    color: #ff4d8d;
    display: block;
}

/* Recording pill: padded out, with aurora ring + halo */
#tkor_mic_floating[data-state="recording"] {
    min-width: 0;
    padding: 0 16px;
    background: rgba(15, 18, 28, 0.92);
    box-shadow: 0 4px 26px rgba(255, 80, 120, 0.22),
                inset 0 1px 0 rgba(255,255,255,0.06);
}
#tkor_mic_floating[data-state="recording"]::before {
    /* Aurora gradient ring rotating around the capsule */
    content: '';
    position: absolute;
    inset: -2px;
    border-radius: 999px;
    padding: 2px;
    background: conic-gradient(from 0deg,
      #ff4d8d, #ffb04d, #ffd84d, #4dffa4, #4d8dff, #b14dff, #ff4d8d);
    -webkit-mask:
        linear-gradient(#000 0 0) content-box,
        linear-gradient(#000 0 0);
    mask:
        linear-gradient(#000 0 0) content-box,
        linear-gradient(#000 0 0);
    -webkit-mask-composite: xor;
    mask-composite: exclude;
    animation: tkor-aurora-spin 3.2s linear infinite;
    z-index: -1;
    pointer-events: none;
}
#tkor_mic_floating[data-state="recording"]::after {
    /* Soft halo glow, behind everything */
    content: '';
    position: absolute;
    inset: -10px;
    border-radius: 999px;
    background: conic-gradient(from 90deg,
      rgba(255,77,141,0.32), rgba(255,176,77,0.32),
      rgba(77,255,164,0.32), rgba(77,141,255,0.32),
      rgba(177,77,255,0.32), rgba(255,77,141,0.32));
    filter: blur(14px);
    opacity: 0.55;
    animation: tkor-aurora-spin 6s linear infinite reverse;
    z-index: -2;
    pointer-events: none;
}

/* Voice bars inside recording pill */
#tkor_mic_floating .tkor-mic-bars {
    display: none;
    align-items: center;
    gap: 3px;
    height: 24px;
}
#tkor_mic_floating[data-state="recording"] .tkor-mic-bars,
#tkor_mic_floating[data-state="transcribing"] .tkor-mic-bars {
    display: flex;
}
#tkor_mic_floating .tkor-mic-bars span {
    display: block;
    width: 3px;
    height: 10px;
    border-radius: 2px;
    transition: height 80ms ease-out;
}
#tkor_mic_floating[data-state="recording"] .tkor-mic-bars span {
    background: linear-gradient(180deg, #ff8aa8, #ff4d8d);
    box-shadow: 0 0 6px rgba(255, 77, 141, 0.6);
}
#tkor_mic_floating[data-state="transcribing"] .tkor-mic-bars span {
    background: linear-gradient(180deg, #ffe88a, #ffb04d);
    box-shadow: 0 0 6px rgba(255, 176, 77, 0.55);
    animation: tkor-mic-process 1.05s ease-in-out infinite;
    transition: none;
}
#tkor_mic_floating[data-state="transcribing"] .tkor-mic-bars span:nth-child(1) { animation-delay: 0.00s; }
#tkor_mic_floating[data-state="transcribing"] .tkor-mic-bars span:nth-child(2) { animation-delay: 0.10s; }
#tkor_mic_floating[data-state="transcribing"] .tkor-mic-bars span:nth-child(3) { animation-delay: 0.20s; }
#tkor_mic_floating[data-state="transcribing"] .tkor-mic-bars span:nth-child(4) { animation-delay: 0.30s; }
#tkor_mic_floating[data-state="transcribing"] .tkor-mic-bars span:nth-child(5) { animation-delay: 0.40s; }

/* Transcribing pill: gold/amber spinning arc + thinking dots */
#tkor_mic_floating[data-state="transcribing"] {
    min-width: 0;
    padding: 0 16px;
    background: rgba(15, 18, 28, 0.92);
    box-shadow: 0 4px 22px rgba(255, 176, 77, 0.18),
                inset 0 1px 0 rgba(255,255,255,0.06);
}
#tkor_mic_floating[data-state="transcribing"]::before {
    content: '';
    position: absolute;
    inset: -2px;
    border-radius: 999px;
    padding: 2px;
    background: conic-gradient(from 0deg,
      transparent 0%, transparent 35%,
      #ffd84d 50%, #ffb04d 65%,
      transparent 80%, transparent 100%);
    -webkit-mask:
        linear-gradient(#000 0 0) content-box,
        linear-gradient(#000 0 0);
    mask:
        linear-gradient(#000 0 0) content-box,
        linear-gradient(#000 0 0);
    -webkit-mask-composite: xor;
    mask-composite: exclude;
    animation: tkor-aurora-spin 1.6s linear infinite;
    z-index: -1;
    pointer-events: none;
}

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

/* === Camera + gear (peer buttons next to capsule) === */

#tkor_mic_camera,
#tkor_mic_gear {
    width: 40px;
    height: 40px;
    cursor: pointer;
    user-select: none;
    color: rgba(245, 245, 247, 0.78);
    background: rgba(20, 22, 35, 0.78);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 999px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.36),
                inset 0 1px 0 rgba(255,255,255,0.05);
    backdrop-filter: blur(18px);
    -webkit-backdrop-filter: blur(18px);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: color 150ms ease, background 150ms ease, transform 150ms ease;
}
#tkor_mic_camera svg,
#tkor_mic_gear svg {
    width: 18px;
    height: 18px;
}
#tkor_mic_camera:hover,
#tkor_mic_gear:hover {
    color: #f5f5f7;
    background: rgba(40, 42, 60, 0.85);
    transform: scale(1.04);
}

/* === Settings popover — same glass material as the capsule === */

#tkor_mic_settings {
    position: fixed;
    top: 60px;
    right: 110px;
    width: 320px;
    background: rgba(15, 18, 28, 0.94);
    color: #f5f5f7;
    padding: 18px;
    border: 1px solid rgba(255, 255, 255, 0.07);
    border-radius: 16px;
    backdrop-filter: blur(24px);
    -webkit-backdrop-filter: blur(24px);
    box-shadow: 0 14px 48px rgba(0,0,0,0.55);
    font: 14px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", "Inter", sans-serif;
    z-index: 999998;
}
#tkor_mic_settings .tkor-mic-settings-title {
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 14px;
    letter-spacing: 0.01em;
    color: #f5f5f7;
}
#tkor_mic_settings .tkor-mic-settings-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 10px 0;
    border-bottom: 1px solid rgba(255,255,255,0.05);
}
#tkor_mic_settings .tkor-mic-settings-row:last-of-type {
    border-bottom: 0;
}
#tkor_mic_settings .tkor-mic-settings-row label {
    color: rgba(245, 245, 247, 0.62);
    font-size: 13px;
    flex: 0 0 auto;
}
#tkor_mic_settings .tkor-mic-hotkey-capture {
    flex: 0 0 auto;
    background: rgba(255,255,255,0.06);
    color: #f5f5f7;
    border: 1px solid rgba(255,255,255,0.08);
    border-radius: 8px;
    padding: 5px 10px;
    font-family: ui-monospace, "SF Mono", "Cascadia Mono", Menlo, monospace;
    font-size: 12px;
    text-align: center;
    cursor: pointer;
    transition: background 150ms ease, border-color 150ms ease;
}
#tkor_mic_settings .tkor-mic-hotkey-capture:hover {
    background: rgba(255,255,255,0.10);
    border-color: rgba(255,255,255,0.18);
}
#tkor_mic_settings .tkor-mic-hotkey-capture.capturing {
    background: rgba(255, 77, 141, 0.18);
    border-color: rgba(255, 77, 141, 0.55);
    color: #ffaecb;
    animation: tkor-mic-capture-blink 1.1s ease-in-out infinite;
}
@keyframes tkor-mic-capture-blink {
    0%, 100% { box-shadow: 0 0 0 0 rgba(255, 77, 141, 0.45); }
    50%      { box-shadow: 0 0 0 5px rgba(255, 77, 141, 0.0); }
}
#tkor_mic_settings .tkor-mic-settings-hint {
    margin-top: 12px;
    font-size: 11px;
    color: rgba(245, 245, 247, 0.42);
    line-height: 1.45;
}
#tkor_mic_settings .tkor-mic-settings-done {
    width: 100%;
    margin-top: 14px;
    padding: 9px 12px;
    background: linear-gradient(135deg, #5a8dff 0%, #b14dff 100%);
    color: #ffffff;
    border: 0;
    border-radius: 10px;
    cursor: pointer;
    font: inherit;
    font-weight: 600;
    font-size: 13px;
    letter-spacing: 0.02em;
    box-shadow: 0 4px 14px rgba(90, 141, 255, 0.32);
    transition: transform 120ms ease, box-shadow 120ms ease;
}
#tkor_mic_settings .tkor-mic-settings-done:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 18px rgba(177, 77, 255, 0.42);
}
