/**
 * Chat Challenge Popover - Isolated Styles
 * ALL classes prefixed with .chat-* to avoid conflicts
 * NO global selectors - completely self-contained
 */

/* ===== SHIMMER BUTTON FRAMEWORK ===== */
:root {
    --shimmer-glow-hue: 222deg;
    --shimmer-shadow-hue: 180deg;
    --overlay-color: 0, 0, 0;
    --overlay-opacity: 0;
    --text-color: #ffffff;
    --border-color: rgba(255, 255, 255, 0.2);
    --shimmer-spring-easing: linear(
    0, 0.002, 0.01 0.9%, 0.038 1.8%, 0.156, 0.312 5.8%, 0.789 11.1%, 1.015 14.2%,
    1.096, 1.157, 1.199, 1.224 20.3%, 1.231, 1.231, 1.226, 1.214 24.6%,
    1.176 26.9%, 1.057 32.6%, 1.007 35.5%, 0.984, 0.968, 0.956, 0.949 42%,
    0.946 44.1%, 0.95 46.5%, 0.998 57.2%, 1.007, 1.011 63.3%, 1.012 68.3%,
    0.998 84%, 1
  );
    --shimmer-spring-duration: 1.33s;
    --fallback-spring-easing: cubic-bezier(0.175, 0.885, 0.32, 1.275);
    --fallback-spring-duration: 0.6s;
}

@property --shimmer-shimmer {
    syntax: "<angle>";
    inherits: false;
    initial-value: 33deg;
}

@keyframes shimmer-shimmer {
    0% {
        --shimmer-shimmer: 0deg;
    }
    100% {
        --shimmer-shimmer: 360deg;
    }
}

@keyframes shimmer-shine {
    0% {
        opacity: 0;
    }
    15% {
        opacity: 1;
    }
    55% {
        opacity: 1;
    }
    100% {
        opacity: 0;
    }
}

@keyframes shimmer-text {
    0% {
        background-position: 100% center;
    }
    100% {
        background-position: -100% center;
    }
}

/* Shimmer overlay */
.shimmer-shimmer {
    position: absolute;
    inset: calc(var(--inset, 40px) * -1);
    border-radius: inherit;
    pointer-events: none;
    mask-image: conic-gradient(
        from var(--shimmer-shimmer, 0deg),
        transparent 0%,
        transparent 20%,
        black 36%,
        black 45%,
        transparent 50%,
        transparent 70%,
        black 85%,
        black 95%,
        transparent 100%
    );
    mask-size: cover;
    mix-blend-mode: plus-lighter;
    animation: shimmer-shimmer 1s linear infinite both;
}

.chat-tab:hover .shimmer-shimmer::before,
.chat-tab:hover .shimmer-shimmer::after,
.chat-tab.active .shimmer-shimmer::before,
.chat-tab.active .shimmer-shimmer::after,
.chat-action-btn:hover .shimmer-shimmer::before,
.chat-action-btn:hover .shimmer-shimmer::after {
    opacity: 1;
    animation: shimmer-shine 1.2s ease-in 1 forwards;
}

.shimmer-shimmer::before,
.shimmer-shimmer::after {
    transition: all 0.5s ease;
    opacity: 0;
    content: "";
    border-radius: inherit;
    position: absolute;
    mix-blend-mode: color;
    inset: var(--inset, 40px);
    pointer-events: none;
}

.shimmer-shimmer::before {
    box-shadow: 0 0 calc(var(--inset, 40px) * 0.1)  2px hsl(var(--shimmer-glow-hue) 20% 95%),
        0 0 calc(var(--inset, 40px) * 0.18)  4px hsl(var(--shimmer-glow-hue) 20% 80%),
        0 0 calc(var(--inset, 40px) * 0.33)  4px hsl(var(--shimmer-glow-hue) 50% 70%),
        0 0 calc(var(--inset, 40px) * 0.66) 5px hsl(var(--shimmer-glow-hue) 100% 70%);
    z-index: -1;
}

.shimmer-shimmer::after {
    box-shadow: inset 0 0 0 1px hsl(var(--shimmer-glow-hue) 70% 95%),
        inset 0 0 2px 1px hsl(var(--shimmer-glow-hue) 100% 80%),
        inset 0 0 5px 2px hsl(var(--shimmer-glow-hue) 100% 70%);
    z-index: 2;
}

/* Shimmer text effect */
.shimmer-text {
    background-clip: text;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-color: var(--text-color);
    background-image: linear-gradient(120deg, var(--text-color), rgba(255, 255, 255, 1) 40%, rgba(230, 230, 255, 1) 50%, var(--text-color) 52%);
    background-repeat: no-repeat;
    background-size: 300% 300%;
    background-position: 0% center;
    transition: background-color 0.3s ease, background-image 0.3s ease;
}

.chat-tab:hover .shimmer-text,
.chat-tab.active .shimmer-text,
.chat-action-btn:hover .shimmer-text {
    animation: shimmer-text .66s ease-in 1 both;
}

/* ===== Popover Container ===== */
.chat-popover {
    position: fixed;
    inset: 0;
    z-index: 10000;
    display: grid;
    place-items: center;
    padding: 1rem;
    opacity: 1;
    visibility: visible;
    transition: opacity 0.3s ease, visibility 0.3s ease;
}

.chat-popover.hidden {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}

/* ===== Backdrop ===== */
.chat-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
}

/* ===== Popover Content ===== */
.chat-content {
    position: relative;
    width: min(90vw, 56.25rem);
    max-height: 90vh;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 1.5rem;
    border: 0.0625rem solid var(--border-color);
    overflow: hidden;
    box-shadow: 0 1.5625rem 3.125rem -0.75rem rgba(0, 0, 0, 0.5),
                inset 0 0.0625rem 0 rgba(255, 255, 255, 0.3);
    display: flex;
    flex-direction: column;
    z-index: 2;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
}

.chat-content::before {
    content: '';
    position: absolute;
    inset: 0;
    background: rgba(var(--overlay-color), var(--overlay-opacity));
    pointer-events: none;
    z-index: 1000;
    transition: background 0.3s ease;
    border-radius: 1.5rem;
}

/* ===== Header ===== */
.chat-header {
    padding: 1.5rem 2rem;
    border-bottom: 1px solid var(--border-color);
    background: rgba(255, 255, 255, 0.05);
    position: relative;
    z-index: 1001;
    text-align: center;
}

.chat-close-btn {
    position: absolute;
    top: 1.5rem;
    right: 2rem;
    width: 2.5rem;
    height: 2.5rem;
    border: none;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
    color: var(--text-color);
}

.chat-close-btn:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: scale(1.1);
}

.chat-challenge-title {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--text-color);
    margin: 0 0 0.5rem;
    font-family: Georgia, serif;
    transition: color 0.3s ease;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}

.chat-scenario {
    font-size: 0.95rem;
    color: var(--text-color);
    opacity: 0.85;
    margin: 0;
    transition: color 0.3s ease;
    font-style: italic;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}

/* ===== Tab Navigation ===== */
.chat-tabs {
    display: flex;
    gap: 0.5rem;
    padding: 1rem 2rem 0;
    background: rgba(255, 255, 255, 0.05);
    position: relative;
    z-index: 1001;
}

.chat-tab {
    --inset: 40px;
    position: relative;
    isolation: isolate;
    padding: 0.75rem 1.5rem;
    border: none;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid var(--border-color);
    border-bottom: none;
    border-radius: 0.66em 0.66em 0 0;
    font-size: 0.95rem;
    font-weight: 500;
    cursor: pointer;
    color: var(--text-color);
    opacity: 0.8;
    font-family: system-ui, -apple-system, sans-serif;
    transition: all var(--shimmer-spring-duration) var(--shimmer-spring-easing);
}

.chat-tab:hover {
    transition-duration: calc(var(--shimmer-spring-duration)*0.5);
    background: rgba(255, 255, 255, 0.2);
}

.chat-tab.active {
    background: rgba(255, 255, 255, 0.25);
    color: var(--text-color);
    opacity: 1;
    font-weight: 600;
    border-bottom: 1px solid var(--border-color);
}

/* ===== Tab Content ===== */
.chat-tab-content {
    flex: 1;
    overflow-y: auto;
    padding: 2rem;
    background: rgba(255, 255, 255, 0.02);
    border-top: 1px solid var(--border-color);
    /* Hide scrollbar for all browsers */
    -ms-overflow-style: none;
    scrollbar-width: none;
    position: relative;
    z-index: 1001;
}

/* Hide scrollbar for WebKit browsers (Chrome, Safari, Edge) */
.chat-tab-content::-webkit-scrollbar {
    width: 0;
    height: 0;
    display: none;
}

.chat-panel {
    display: none;
}

.chat-panel.active {
    display: block;
}

/* ===== Dot Controls ===== */
.chat-dot-controls-grid {
    display: flex;
    gap: 1rem;
    justify-content: center;
    margin-bottom: 2rem;
}

.chat-dot-control-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 1rem;
    border: 2px solid var(--border-color);
    border-radius: 0.5rem;
    background: rgba(255, 255, 255, 0.05);
}

.chat-dot-control {
    position: relative;
    width: 3em;
    height: 6em;
    margin: 0;
    cursor: pointer;
}

.chat-dot-control canvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}

.chat-dot-control-label {
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-top: 0.16rem;
    color: var(--text-color);
    opacity: 0.9;
    font-size: 0.9rem;
    transition: color 0.3s ease;
}

.chat-dot-control-value {
    margin-top: 0.04rem;
    color: #4a90e2;
    font-size: 1.2rem;
    font-weight: 600;
}

/* ===== Context Image ===== */
.chat-context-image {
    margin-bottom: 1.5rem;
    border-radius: 0.75rem;
    overflow: hidden;
    border: 2px solid var(--border-color);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.chat-context-image img {
    width: 100%;
    height: auto;
    display: block;
}

/* ===== YouTube Video ===== */
.chat-youtube-video {
    margin-bottom: 1.5rem;
    border-radius: 0.75rem;
    overflow: hidden;
    border: 2px solid var(--border-color);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    position: relative;
    padding-bottom: 56.25%; /* 16:9 aspect ratio */
    height: 0;
}

.chat-youtube-video iframe {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}

/* ===== Chat Messages Container ===== */
.chat-messages-container {
    min-height: 20rem;
    max-height: 30rem;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 2rem;
    background: rgba(255, 255, 255, 0.08);
    border-radius: 0.5rem;
    border: 1px solid var(--border-color);
    margin-bottom: 1.5rem;
    position: relative;
    /* Hide scrollbar for all browsers */
    -ms-overflow-style: none;
    scrollbar-width: none;
}

/* Hide scrollbar for WebKit browsers (Chrome, Safari, Edge) */
.chat-messages-container::-webkit-scrollbar {
    width: 0;
    height: 0;
    display: none;
}

.chat-messages {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

/* ===== Chat Message Bubbles ===== */
.chat-message {
    display: flex;
    flex-direction: column;
    max-width: 80%;
    animation: messageSlideIn 0.3s ease-out;
}

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

.chat-message.from-partner {
    align-self: flex-start;
}

.chat-message.from-user {
    align-self: flex-end;
}

.chat-message-sender {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-color);
    opacity: 0.7;
    margin-bottom: 0.25rem;
    padding: 0 0.75rem;
    transition: color 0.3s ease;
}

.chat-message-bubble {
    padding: 0.875rem 1.125rem;
    border-radius: 1.125rem;
    font-size: 1rem;
    line-height: 1.5;
    color: var(--text-color);
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
    transition: color 0.3s ease;
}

.chat-message.from-partner .chat-message-bubble {
    background: rgba(74, 144, 226, 0.25);
    border: 1px solid rgba(74, 144, 226, 0.4);
    border-bottom-left-radius: 0.25rem;
}

.chat-message.from-user .chat-message-bubble {
    background: rgba(76, 175, 80, 0.25);
    border: 1px solid rgba(76, 175, 80, 0.4);
    border-bottom-right-radius: 0.25rem;
}

.chat-message-time {
    font-size: 0.75rem;
    color: var(--text-color);
    opacity: 0.5;
    margin-top: 0.25rem;
    padding: 0 0.75rem;
    transition: color 0.3s ease;
}

/* ===== Mad Libs Response Area ===== */
.chat-madlibs-area {
    margin-top: 1.5rem;
    padding: 1.5rem;
    background: rgba(76, 175, 80, 0.15);
    border: 2px solid rgba(76, 175, 80, 0.3);
    border-radius: 0.75rem;
}

.chat-madlibs-prompt {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-color);
    margin-bottom: 1rem;
    padding-bottom: 0.75rem;
    border-bottom: 1px solid var(--border-color);
    transition: color 0.3s ease;
}

.chat-madlibs-response {
    font-size: 1.05rem;
    line-height: 2;
    color: var(--text-color);
    transition: color 0.3s ease;
}

.chat-madlibs-response .chat-madlibs-input {
    display: inline-block;
    min-width: 8rem;
    padding: 0.35rem 0.75rem;
    margin: 0 0.25rem;
    background: rgba(255, 255, 255, 0.2);
    border: 2px solid var(--border-color);
    border-radius: 0.35rem;
    color: var(--text-color);
    font-family: system-ui, -apple-system, sans-serif;
    font-size: 0.95rem;
    font-weight: 500;
    text-align: center;
    transition: all 0.2s ease;
}

.chat-madlibs-response .chat-madlibs-input::placeholder {
    color: var(--text-color);
    opacity: 0.6;
    font-style: italic;
    font-size: 0.85rem;
}

.chat-madlibs-response .chat-madlibs-input:focus {
    outline: none;
    border-color: rgba(74, 144, 226, 0.7);
    background: rgba(255, 255, 255, 0.3);
    transform: scale(1.02);
}

.chat-madlibs-response .chat-madlibs-input.correct {
    background: rgba(76, 175, 80, 0.3);
    border-color: rgba(76, 175, 80, 0.7);
}

.chat-madlibs-response .chat-madlibs-input.incorrect {
    background: rgba(244, 67, 54, 0.3);
    border-color: rgba(244, 67, 54, 0.7);
    animation: shake 0.3s ease;
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-5px); }
    75% { transform: translateX(5px); }
}

/* ===== Model Answer Panel ===== */
.chat-model-answer {
    max-width: 700px;
    margin: 0 auto;
}

.chat-model-title {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-color);
    transition: color 0.3s ease;
    margin: 0 0 0.5rem;
    font-family: system-ui, -apple-system, sans-serif;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}

.chat-model-subtitle {
    font-size: 0.95rem;
    color: var(--text-color);
    opacity: 0.8;
    margin: 0 0 2rem;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}

/* ===== Curator's Insight Panel ===== */
.chat-insight {
    max-width: 700px;
    margin: 0 auto;
}

.chat-insight-title {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-color);
    transition: color 0.3s ease;
    margin: 0 0 0.5rem;
    font-family: system-ui, -apple-system, sans-serif;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}

.chat-insight-subtitle {
    font-size: 0.95rem;
    color: var(--text-color);
    opacity: 0.8;
    margin: 0 0 2rem;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}

.chat-insight-content {
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid var(--border-color);
    border-radius: 0.75rem;
    padding: 1.5rem;
}

.chat-insight-content p {
    font-size: 1.05rem;
    line-height: 1.8;
    color: var(--text-color);
    margin: 0 0 1rem;
    transition: color 0.3s ease;
}

.chat-insight-content p:last-child {
    margin-bottom: 0;
}

.chat-insight-content strong {
    color: rgba(74, 144, 226, 0.9);
    font-weight: 700;
}

/* ===== Action Buttons ===== */
.chat-actions {
    padding: 1.5rem 2rem;
    background: rgba(255, 255, 255, 0.05);
    border-top: 1px solid var(--border-color);
    text-align: center;
    position: relative;
    z-index: 1001;
}

.chat-action-btns {
    display: flex;
    gap: 1rem;
    justify-content: center;
}

.chat-action-btn {
    --inset: 40px;
    position: relative;
    isolation: isolate;
    padding: 0.75rem 2rem;
    background: #4a90e2;
    color: #ffffff;
    border: 1px solid var(--border-color);
    border-radius: 0.66em;
    font-size: 1rem;
    font-weight: 600;
    font-family: system-ui, -apple-system, sans-serif;
    cursor: pointer;
    transition: all var(--shimmer-spring-duration) var(--shimmer-spring-easing);
    box-shadow: 0 4px 12px rgba(74, 144, 226, 0.3),
                0 2px 4px rgba(0, 0, 0, 0.1),
                inset 0 1px 0 rgba(255, 255, 255, 0.3);
}

.chat-action-btn:hover {
    transition-duration: calc(var(--shimmer-spring-duration)*0.5);
    background: #357abd;
    box-shadow: 0 8px 20px rgba(74, 144, 226, 0.5),
                0 4px 8px rgba(0, 0, 0, 0.15),
                inset 0 1px 0 rgba(255, 255, 255, 0.4);
}

/* ===== Utility Classes ===== */
.chat-popover .hidden {
    display: none !important;
}

/* ===== Traditional Controls (Mobile) ===== */
.chat-traditional-controls {
    display: none;
    flex-direction: column;
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.chat-traditional-control {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    padding: 1rem;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid var(--border-color);
    border-radius: 0.5rem;
}

.chat-traditional-control label {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-color);
    opacity: 0.9;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.chat-traditional-control input[type="range"] {
    width: 100%;
    height: 8px;
    -webkit-appearance: none;
    appearance: none;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 4px;
    outline: none;
}

.chat-traditional-control input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 20px;
    height: 20px;
    background: #4a90e2;
    border-radius: 50%;
    cursor: pointer;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}

.chat-traditional-control input[type="range"]::-moz-range-thumb {
    width: 20px;
    height: 20px;
    background: #4a90e2;
    border-radius: 50%;
    cursor: pointer;
    border: none;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}

.chat-traditional-control span {
    font-size: 1.1rem;
    font-weight: 600;
    color: #4a90e2;
    text-align: center;
}

/* ===== Responsive Design ===== */
@media (max-width: 768px) {
    /* Hide dot controls on mobile */
    .chat-dot-controls-grid {
        display: none !important;
    }

    /* Show traditional controls on mobile */
    .chat-traditional-controls {
        display: flex;
    }

    .chat-content {
        width: 95vw;
        max-height: 95vh;
    }

    .chat-header {
        padding: 1rem 1.5rem;
    }

    .chat-challenge-title {
        font-size: 1.1rem;
    }

    .chat-tabs {
        padding: 0.75rem 1rem;
        gap: 0.25rem;
        flex-wrap: wrap;
    }

    .chat-tab {
        padding: 0.5rem 0.75rem;
        font-size: 0.8rem;
    }

    .chat-tab-content {
        padding: 1.5rem 1rem;
    }

    .chat-message {
        max-width: 90%;
    }

    .chat-action-btns {
        flex-direction: column;
    }

    .chat-action-btn {
        width: 100%;
    }
}
