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

        body {
            background: linear-gradient(135deg, #000000 0%, #1a1a1a 100%);
            color: #ffffff;
            font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
            min-height: 100vh;
            padding: 40px 20px;
            position: relative;
            overflow-x: hidden;
        }

        body::before {
            content: '';
            position: fixed;
            top: -50%;
            right: -50%;
            width: 200%;
            height: 200%;
            background: radial-gradient(circle, rgba(255,255,255,0.03) 1px, transparent 1px);
            background-size: 50px 50px;
            animation: drift 60s linear infinite;
            pointer-events: none;
            z-index: 0;
        }

        @keyframes drift {
            from { transform: rotate(0deg); }
            to { transform: rotate(360deg); }
        }

        .container {
            max-width: 980px;
            margin: 0 auto;
            position: relative;
            z-index: 1;
        }

        header {
            text-align: center;
            margin-bottom: 50px;
            animation: fadeInDown 0.8s ease-out;
        }

        h1 {
            font-size: 3em;
            font-weight: 700;
            letter-spacing: -1px;
            margin-bottom: 10px;
            background: linear-gradient(135deg, #ffffff 0%, #888888 100%);
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
            background-clip: text;
        }

        .subtitle {
            color: #888888;
            font-size: 1.1em;
            letter-spacing: 2px;
            text-transform: uppercase;
        }

        .chat-container {
            background: rgba(26, 26, 26, 0.8);
            backdrop-filter: blur(10px);
            border: 1px solid rgba(255, 255, 255, 0.1);
            border-radius: 20px;
            padding: 40px;
            box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
            animation: fadeInUp 0.8s ease-out;
        }

        .input-section {
            margin-bottom: 30px;
        }

        label {
            display: block;
            margin-bottom: 12px;
            font-size: 0.9em;
            font-weight: 600;
            text-transform: uppercase;
            letter-spacing: 1px;
            color: #aaaaaa;
        }

        .input-wrapper {
            position: relative;
        }

        textarea {
            width: 100%;
            background: rgba(0, 0, 0, 0.6);
            color: #ffffff;
            border: 2px solid rgba(255, 255, 255, 0.1);
            border-radius: 12px;
            padding: 20px;
            font-size: 16px;
            font-family: inherit;
            resize: vertical;
            transition: all 0.3s ease;
            line-height: 1.6;
        }

        textarea:focus {
            outline: none;
            border-color: rgba(255, 255, 255, 0.4);
            background: rgba(0, 0, 0, 0.8);
            box-shadow: 0 0 20px rgba(255, 255, 255, 0.1);
        }

        textarea::placeholder {
            color: #555555;
        }

        #question {
            min-height: 120px;
        }

        #answer {
            min-height: 200px;
            background: rgba(255, 255, 255, 0.05);
        }

        .button-container {
            display: flex;
            gap: 15px;
            margin-top: 20px;
        }

        button {
            flex: 1;
            background: linear-gradient(135deg, #ffffff 0%, #cccccc 100%);
            color: #000000;
            border: none;
            padding: 18px 40px;
            font-size: 16px;
            font-weight: 700;
            border-radius: 12px;
            cursor: pointer;
            transition: all 0.3s ease;
            text-transform: uppercase;
            letter-spacing: 1px;
            position: relative;
            overflow: hidden;
        }

        button::before {
            content: '';
            position: absolute;
            top: 50%;
            left: 50%;
            width: 0;
            height: 0;
            border-radius: 50%;
            background: rgba(0, 0, 0, 0.1);
            transform: translate(-50%, -50%);
            transition: width 0.6s, height 0.6s;
        }

        button:hover::before {
            width: 300px;
            height: 300px;
        }

        button:hover {
            transform: translateY(-2px);
            box-shadow: 0 10px 30px rgba(255, 255, 255, 0.2);
        }

        button:active {
            transform: translateY(0);
        }

        button:disabled {
            background: #333333;
            color: #666666;
            cursor: not-allowed;
            transform: none;
        }

        button:disabled:hover {
            box-shadow: none;
        }

        .clear-btn {
            flex: 0 0 auto;
            background: transparent;
            border: 2px solid rgba(255, 255, 255, 0.2);
            color: #ffffff;
            padding: 18px 30px;
        }

        .clear-btn:hover {
            background: rgba(255, 255, 255, 0.1);
            border-color: rgba(255, 255, 255, 0.4);
        }

        .status-bar {
            margin-top: 15px;
            min-height: 30px;
        }

        .loading {
            display: flex;
            align-items: center;
            justify-content: center;
            gap: 10px;
            color: #888888;
            font-size: 0.9em;
        }

        .loading-dots {
            display: flex;
            gap: 5px;
        }

        .loading-dot {
            width: 8px;
            height: 8px;
            border-radius: 50%;
            background: #ffffff;
            animation: pulse 1.4s infinite ease-in-out;
        }

        .loading-dot:nth-child(1) { animation-delay: -0.32s; }
        .loading-dot:nth-child(2) { animation-delay: -0.16s; }
        .loading-dot:nth-child(3) { animation-delay: 0s; }

        @keyframes pulse {
            0%, 80%, 100% { opacity: 0.3; transform: scale(0.8); }
            40% { opacity: 1; transform: scale(1); }
        }

        .error {
            background: rgba(255, 68, 68, 0.1);
            border: 1px solid rgba(255, 68, 68, 0.3);
            color: #ff4444;
            padding: 15px;
            border-radius: 8px;
            font-size: 0.9em;
            line-height: 1.6;
        }

        .metadata {
            margin-top: 20px;
            padding-top: 20px;
            border-top: 1px solid rgba(255, 255, 255, 0.1);
        }

        .meta-item {
            background: rgba(255, 255, 255, 0.05);
            border-left: 3px solid #ffffff;
            padding: 12px 15px;
            margin-bottom: 10px;
            border-radius: 6px;
            font-size: 0.9em;
        }

        .meta-label {
            font-weight: 700;
            text-transform: uppercase;
            letter-spacing: 1px;
            font-size: 0.85em;
            color: #aaaaaa;
            margin-bottom: 5px;
        }

        .meta-value {
            color: #ffffff;
            line-height: 1.6;
        }

        .source-list {
            margin: 6px 0 0 20px;
            padding: 0;
            color: #ffffff;
            line-height: 1.7;
        }

        .source-list li {
            margin-bottom: 6px;
            padding-left: 3px;
            word-break: break-word;
        }

        .source-list li:last-child {
            margin-bottom: 0;
        }

        .char-count {
            text-align: right;
            font-size: 0.85em;
            color: #666666;
            margin-top: 5px;
        }

        .success-indicator {
            color: #4CAF50;
            font-size: 0.9em;
            display: flex;
            align-items: center;
            gap: 8px;
        }

        .success-indicator::before {
            content: '✓';
            display: inline-block;
            width: 20px;
            height: 20px;
            background: #4CAF50;
            color: #000;
            border-radius: 50%;
            text-align: center;
            line-height: 20px;
            font-weight: bold;
        }

        .mode-badge {
            display: inline-block;
            padding: 6px 12px;
            border-radius: 999px;
            font-size: 0.8rem;
            font-weight: 700;
            letter-spacing: 1px;
            text-transform: uppercase;
        }

        .mode-badge.small_talk {
            background: rgba(0, 188, 212, 0.18);
            border: 1px solid rgba(0, 188, 212, 0.45);
            color: #80DEEA;
        }

        .mode-badge.faq {
            background: rgba(76, 175, 80, 0.18);
            border: 1px solid rgba(76, 175, 80, 0.45);
            color: #7CFF98;
        }

        .mode-badge.direct_term {
            background: rgba(156, 39, 176, 0.18);
            border: 1px solid rgba(156, 39, 176, 0.45);
            color: #E6A8FF;
        }

        .mode-badge.fallback {
            background: rgba(255, 193, 7, 0.18);
            border: 1px solid rgba(255, 193, 7, 0.45);
            color: #FFD86B;
        }

        .mode-badge.error {
            background: rgba(244, 67, 54, 0.18);
            border: 1px solid rgba(244, 67, 54, 0.45);
            color: #FF8A80;
        }

        .mode-badge.rag {
            background: rgba(33, 150, 243, 0.18);
            border: 1px solid rgba(33, 150, 243, 0.45);
            color: #7CCBFF;
        }

        .debug-grid {
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
            gap: 10px;
            margin-top: 12px;
        }

        .debug-item {
            background: rgba(255,255,255,0.04);
            border: 1px solid rgba(255,255,255,0.08);
            border-radius: 10px;
            padding: 10px 12px;
        }

        .debug-key {
            font-size: 0.75rem;
            color: #9aa4b1;
            text-transform: uppercase;
            letter-spacing: 1px;
            margin-bottom: 6px;
            font-weight: 700;
        }

        .debug-value {
            font-size: 0.9rem;
            color: #ffffff;
            word-break: break-word;
        }

        .reason-box {
            background: rgba(255,255,255,0.04);
            border: 1px solid rgba(255,255,255,0.08);
            border-radius: 10px;
            padding: 12px 14px;
            margin-top: 10px;
            color: #ffffff;
            line-height: 1.6;
        }

        /* ==========================================
           Final Answer Context Chunks
           ========================================== */

        .context-chunks {
            margin-top: 14px;
            border: 1px solid rgba(255,255,255,0.08);
            border-radius: 10px;
            overflow: hidden;
        }

        .context-chunks-heading {
            display: flex;
            align-items: center;
            justify-content: space-between;
            gap: 12px;

            padding: 14px;
            background: rgba(255,255,255,0.04);
        }

        .context-chunks-title {
            font-size: 13px;
            font-weight: 700;
        }

        .context-chunks-count {
            color: #aaa;
            font-size: 12px;
        }

        .context-chunk {
            padding: 14px;
            border-top: 1px solid rgba(255,255,255,0.08);
        }

        .context-chunk-header {
            display: flex;
            align-items: center;
            flex-wrap: wrap;
            gap: 8px;
            margin-bottom: 7px;
        }

        .context-chunk-number {
            font-size: 13px;
            font-weight: 700;
            color: #fff;
        }

        .context-chunk-badge {
            padding: 4px 8px;
            border-radius: 999px;
            background: rgba(76,175,80,0.14);
            border: 1px solid rgba(76,175,80,0.4);
            color: #96efaa;
            font-size: 10px;
            font-weight: 600;
        }

        .context-chunk-source {
            margin-bottom: 8px;
            color: #999;
            font-size: 11px;
            overflow-wrap: anywhere;
        }

        /*
         * Exactly one visual line by default.
         */
        .context-chunk-text {
            display: -webkit-box;
            -webkit-box-orient: vertical;
            -webkit-line-clamp: 1;
            line-clamp: 1;

            overflow: hidden;
            white-space: normal;
            overflow-wrap: anywhere;

            color: #ddd;
            font-size: 13px;
            line-height: 1.6;
        }

        /*
         * Full original chunk text after Read all.
         */
        .context-chunk.expanded .context-chunk-text {
            display: block;
            -webkit-line-clamp: unset;
            line-clamp: unset;

            overflow: visible;
            white-space: pre-wrap;
        }

        .context-chunk-toggle {
            display: inline-block;
            width: auto;
            flex: 0 0 auto;

            margin-top: 9px;
            padding: 5px 0;

            border: 0;
            border-radius: 0;
            background: transparent;
            box-shadow: none;

            color: #8bd6ff;
            font-size: 12px;
            font-weight: 600;
            text-transform: none;
            letter-spacing: normal;
        }

        .context-chunk-toggle::before {
            display: none;
        }

        .context-chunk-toggle:hover {
            color: #fff;
            background: transparent;
            box-shadow: none;
            transform: none;
            text-decoration: underline;
        }

        .context-chunks-empty,
        .context-chunks-note {
            padding: 12px 14px;
            color: #999;
            font-size: 12px;
            line-height: 1.6;
        }

        /* ==================================================
           Re-enterable scroll reveal
           The observed element never moves geometrically.
           Avoid viewport-edge feedback/flicker.
           ================================================== */
        .scroll-reveal {
            opacity: 0;
            transition: opacity 0.48s ease-out;
            transition-delay: var(--reveal-delay, 0ms);
        }

        .scroll-reveal.is-visible {
            opacity: 1;
        }

        @media (prefers-reduced-motion: reduce) {
            .scroll-reveal,
            .scroll-reveal.is-visible {
                opacity: 1;
                transition: none;
            }
        }

        @keyframes fadeInDown {
            from {
                opacity: 0;
                transform: translateY(-30px);
            }
            to {
                opacity: 1;
                transform: translateY(0);
            }
        }

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

        @keyframes slideInLeft {
            from {
                opacity: 0;
                transform: translateX(-20px);
            }
            to {
                opacity: 1;
                transform: translateX(0);
            }
        }

        @media (max-width: 768px) {
            h1 {
                font-size: 2em;
            }

            .chat-container {
                padding: 25px;
            }

            .button-container {
                flex-direction: column;
            }

            .clear-btn {
                flex: 1;
            }
        }

        /* ==================================================
           Original fixed desktop width + viewport-aware height.
           Small screens may shrink to prevent horizontal overflow.
           ================================================== */
        body {
            padding: clamp(12px, 2.2vh, 40px) 20px;
        }

        .container {
            width: 100%;
            max-width: 980px;
            margin: 0 auto;
        }

        header {
            margin-bottom: clamp(18px, 3vh, 48px);
        }

        h1 {
            font-size: 3em;
        }

        .chat-container {
            padding: 40px;
        }

        .input-section {
            margin-bottom: clamp(12px, 1.7vh, 26px);
        }

        #question {
            min-height: 96px;
            height: clamp(100px, 12vh, 154px);
            max-height: 36vh;
        }

        /* JS sizes this readonly answer box to the answer text. */
        #answer {
            display: block;
            min-height: 104px;
            max-height: min(45vh, 580px);
            height: 104px;
            overflow-y: auto;
            resize: vertical;
            padding: clamp(14px, 1.5vw, 20px);
        }

        .answer-generation-mode {
            margin-top: clamp(10px, 1.4vh, 20px);
        }

        .answer-generation-mode .meta-item {
            margin-bottom: 0;
        }

        /* Answer Generation Mode is always visible, never scroll-revealed. */
        #engineModeBox {
            margin-top: clamp(10px, 1.3vh, 20px);
            padding-top: clamp(10px, 1.3vh, 20px);
        }

        .debug-grid {
            grid-template-columns: repeat(auto-fit, minmax(min(100%, 190px), 1fr));
        }

        .context-chunk-source,
        .debug-value {
            overflow-wrap: anywhere;
        }

        @media (max-width: 768px) {
            h1 {
                font-size: 2em;
            }

            .container {
                width: 100%;
            }

            .chat-container {
                padding: 25px;
            }

            .debug-grid {
                grid-template-columns:
                    repeat(auto-fit, minmax(min(100%, 150px), 1fr));
            }

            #answer {
                min-height: 104px;
            }
        }
    
