/* The hidden attribute must always win, even over display rules */
[hidden] { display: none !important; }

/* Basic CSS reset and dark mode theme */
        html, body {
            margin: 0; padding: 0; width: 100%; height: 100%;
            background-color: #121212; color: #e0e0e0;
            font-family: 'Georgia', 'Times New Roman', serif;
            overflow: hidden;
        }

        #canvas-container { 
            position: absolute; 
            top: 0; 
            left: 0; 
            width: 100%; 
            height: 100%; 
            z-index: 1; 
            transition: all 0.8s ease-in-out;
            border-radius: 0;
        }
        
        /* Elegant inner glow effect for OOP mode */
        #canvas-container.oop-mode {
            box-shadow: 
                inset 0 0 80px rgba(138, 43, 226, 0.4),
                inset 0 0 120px rgba(75, 0, 130, 0.3),
                inset 0 0 160px rgba(106, 90, 205, 0.25),
                inset 0 0 240px rgba(72, 61, 139, 0.2),
                inset 0 0 320px rgba(138, 43, 226, 0.15);
            background: 
                radial-gradient(ellipse at center, rgba(138, 43, 226, 0.12) 0%, transparent 50%),
                radial-gradient(ellipse at 25% 25%, rgba(75, 0, 130, 0.08) 0%, transparent 40%),
                radial-gradient(ellipse at 75% 75%, rgba(106, 90, 205, 0.08) 0%, transparent 40%);
        }
        
        /* Alternative pseudo-element glow overlay */
        #canvas-container.oop-mode::before {
            content: '';
            position: absolute;
            top: 0;
            left: 0;
            right: 0;
            bottom: 0;
            background: 
                radial-gradient(ellipse at center, rgba(138, 43, 226, 0.15) 0%, transparent 60%),
                radial-gradient(ellipse at 20% 20%, rgba(75, 0, 130, 0.1) 0%, transparent 50%),
                radial-gradient(ellipse at 80% 80%, rgba(106, 90, 205, 0.1) 0%, transparent 50%);
            box-shadow: 
                inset 0 0 100px rgba(138, 43, 226, 0.3),
                inset 0 0 200px rgba(75, 0, 130, 0.2);
            pointer-events: none;
            z-index: 1;
        }
        
        /* Additional subtle glow enhancement for p5.js canvas */
        #canvas-container.oop-mode canvas {
            filter: drop-shadow(0 0 25px rgba(138, 43, 226, 0.4)) brightness(1.05);
            position: relative;
            z-index: 2;
        }
        
        canvas { display: block; }
        
        /* Floating Panels General Styling */
        .floating-panel {
            position: absolute;
            background-color: rgba(26, 26, 26, 0.95);
            backdrop-filter: blur(10px);
            border: 1px solid #333;
            border-radius: 8px;
            box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.37);
            z-index: 10;
            min-width: 280px;
            min-height: 150px;
            resize: none; /* Handled by custom handle */
            display: flex;
            flex-direction: column;
            box-sizing: border-box; /* Fix for dragging size change */
        }
        .panel-header {
            display: flex; justify-content: space-between; align-items: center;
            padding: 0.5rem 1rem;
            cursor: grab;
            border-bottom: 1px solid #333;
            flex-shrink: 0;
            user-select: none;
        }
        .panel-header:active {
            cursor: grabbing;
        }
        .panel-header h1 {
            font-size: 1.2rem; 
            margin: 0; 
            font-weight: 300; 
            letter-spacing: 1px; 
            color: #aaa;
            display: flex;
            align-items: center;
            gap: 0.5rem;
        }
        .panel-controls button {
            background: none; border: 1px solid #555; color: #aaa; cursor: pointer;
            border-radius: 5px; padding: 0.25rem 0.5rem; margin-left: 0.5rem; transition: all 0.3s ease;
        }
        .panel-controls button:hover { background: #333; color: #fff; }

        /* Main Controls Panel */
        #controls-panel { top: 1rem; left: 1rem; max-width: 400px; width: 90%; min-height: 0; }
        .controls-content {
            display: flex; flex-direction: column; gap: 1rem; padding: 1rem;
            max-height: 500px; overflow: hidden;
            transition: max-height 0.5s ease-in-out, opacity 0.5s ease-in-out, padding 0.5s ease-in-out, border 0.5s;
        }
        .controls-content.collapsed { max-height: 0; opacity: 0; padding: 0 1rem; gap: 0; border-top: none; }
        #controls-panel.collapsed .panel-header { border-bottom: none; }

        /* Top-Right UI Container (Hidden) */
        #top-right-container {
            display: none; /* Hide character icons as requested */
            position: absolute;
            top: 1rem;
            right: 1rem;
            z-index: 20;
            display: flex;
            flex-direction: column;
            align-items: flex-end; 
            gap: 1rem;
        }
        
        /* Character Icon Container */
        #character-icon-container {
            display: flex;
            flex-direction: column;
            gap: 0.5rem;
        }
        .char-icon-wrapper {
            position: relative;
        }
        .char-icon {
            font-size: 2rem;
            cursor: pointer;
            padding: 0.5rem;
            background-color: rgba(26, 26, 26, 0.8);
            border: 1px solid #333;
            border-radius: 50%;
            width: 40px;
            height: 40px;
            display: flex;
            justify-content: center;
            align-items: center;
            transition: all 0.3s ease;
        }
        .char-icon:hover {
            background-color: #333;
            transform: scale(1.1);
        }
        #add-char-icon, #feeling-lucky-icon {
            font-size: 1.5rem;
            font-weight: bold;
            color: #888;
        }
        .remove-char-btn {
            position: absolute;
            top: -5px;
            right: -5px;
            width: 20px;
            height: 20px;
            background: #a04040;
            color: white;
            border: 1px solid #fff;
            border-radius: 50%;
            font-size: 12px;
            line-height: 18px;
            text-align: center;
            cursor: pointer;
            opacity: 0;
            transition: opacity 0.3s;
            pointer-events: none;
        }
        .char-icon-wrapper:hover .remove-char-btn {
            opacity: 0.8;
            pointer-events: all;
        }
        .remove-char-btn:hover {
            opacity: 1;
        }

        /* Character Chat Panels - compact & sleek */
        .chat-panel {
            display: none; /* Hidden by default */
            min-width: 300px;
            min-height: 320px;
            width: 340px;
            height: 380px;
        }

        .chat-panel .panel-header {
            padding: 0.4rem 0.75rem;
        }
        .chat-panel .panel-header h1 {
            font-size: 1rem;
            letter-spacing: 0.2px;
            color: #cfcfcf;
        }
        .chat-panel .panel-controls button {
            padding: 0.2rem 0.45rem;
            font-size: 0.8rem;
            border-radius: 4px;
        }

        .edit-char-btn {
            background: #4a5568;
            color: #e2e8f0;
            border: 1px solid #6b7280;
        }

        .edit-char-btn:hover {
            background: #2d3748;
            color: #f7fafc;
        }

        .chat-panel .controls-content {
            flex-grow: 1; /* Allow content to fill space */
            min-height: 0; /* Important for flex child */
            display: flex;
            flex-direction: column;
            padding: 0.75rem;
            gap: 0.6rem;
            max-height: 1000px; /* for collapse animation */
            overflow: hidden; /* hide during collapse */
            transition: max-height 300ms ease, opacity 200ms ease, padding 220ms ease;
        }
        .chat-panel .controls-content.collapsed {
            max-height: 0;
            opacity: 0;
            padding-top: 0;
            padding-bottom: 0;
        }
        
        .chat-log { 
            height: 100%; 
            overflow-y: auto; 
            padding: 0.75rem; 
            background: #181818; 
            border: 1px solid #2d2d2d;
            border-radius: 10px; 
            margin-bottom: 0.5rem; 
            font-size: 0.9rem; 
            flex-grow: 1; 
            line-height: 1.45;
            max-height: 260px; /* Ensure scrollable area */
        }
        
        /* Custom scrollbar for chat log */
        .chat-log::-webkit-scrollbar {
            width: 8px;
        }
        .chat-log::-webkit-scrollbar-track {
            background: #2a2a2a;
            border-radius: 4px;
        }
        .chat-log::-webkit-scrollbar-thumb {
            background: #555;
            border-radius: 4px;
        }
        .chat-log::-webkit-scrollbar-thumb:hover {
            background: #777;
        }
        .chat-log p { 
            margin: 0 0 0.5rem; 
            padding: 0.45rem 0.6rem;
            border-radius: 8px;
            line-height: 1.35;
            word-wrap: break-word;
            max-width: 100%;
        }
        .chat-log .user-msg { 
            color: #eef6ff; 
            background-color: rgba(17, 113, 201, 0.15);
            border-left: 2px solid #1171c9;
            font-weight: 500;
        }
        .chat-log .char-msg { 
            color: #e8e8e8; 
            background-color: rgba(40, 40, 40, 0.5);
            border-left: 2px solid #5d5d5d;
        }
        .chat-log .thinking-msg {
            color: #999;
            font-style: italic;
            background-color: rgba(128, 128, 128, 0.1);
            border-left: 3px solid #555;
        }

        /* Live voice caption: the line fills as the consultant speaks */
        .chat-log .live-line::after {
            content: '▍';
            margin-left: 2px;
            color: var(--accent, #00c8ff);
            animation: live-caret 0.9s steps(2, start) infinite;
        }
        @keyframes live-caret { 50% { opacity: 0; } }
        @media (prefers-reduced-motion: reduce) {
            .chat-log .live-line::after { animation: none; }
        }

        /* Typing effect styles */
        .typing-cursor {
            display: inline-block;
            width: 2px;
            height: 1.2em;
            background-color: #fff;
            margin-left: 2px;
            animation: blink 1s infinite;
            vertical-align: text-bottom;
        }

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

        .typing-message {
            position: relative;
            cursor: pointer;
            transition: background-color 0.2s ease;
        }

        .typing-message:hover {
            background-color: rgba(60, 60, 60, 0.7) !important;
        }

        .typing-message .typing-cursor {
            background-color: #e8e8e8;
        }

        .typing-message::after {
            content: "Click to skip typing";
            position: absolute;
            top: -25px;
            right: 10px;
            background: rgba(0, 0, 0, 0.8);
            color: #fff;
            padding: 4px 8px;
            border-radius: 4px;
            font-size: 11px;
            opacity: 0;
            pointer-events: none;
            transition: opacity 0.2s ease;
            white-space: nowrap;
            z-index: 1000;
        }

        .typing-message:hover::after {
            opacity: 1;
        }
        .chat-input-form { 
            display: flex; 
            gap: 0.6rem; 
            align-items: stretch;
            flex-shrink: 0;
        }
        .chat-input-form input { 
            flex-grow: 1; 
            background: #2b2b2b; 
            border: 2px solid #444; 
            color: #fff; 
            padding: 0.6rem; 
            border-radius: 6px; 
            font-size: 0.9rem;
            transition: border-color 0.2s ease, box-shadow 0.2s ease;
        }
        .chat-input-form input:focus {
            outline: none;
            border-color: #007bff;
            box-shadow: 0 0 0 2px rgba(0, 123, 255, 0.18);
        }
        .chat-input-form button { 
            padding: 0.6rem 0.9rem; 
            background: #007bff;
            color: white;
            border: none;
            border-radius: 6px;
            cursor: pointer;
            font-weight: 500;
            font-size: 0.9rem;
            transition: background-color 0.2s ease, transform 0.1s ease;
        }
        .chat-input-form button:hover {
            background: #0056b3;
        }
        .chat-input-form button:active {
            transform: translateY(1px);
        }
        .chat-input-form button:disabled {
            background: #555;
            cursor: not-allowed;
        }

    /* Group Discussion extras */
    #group-chat .participants-section { display: flex; flex-direction: column; gap: 0.35rem; }
    #group-chat .participants-label { font-size: 0.8rem; color: #9a9a9a; }
    .participants-list { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
    .participant-pill { display: inline-flex; align-items: center; gap: 6px; padding: 4px 8px; border-radius: 999px; background: #222; border: 1px solid #3a3a3a; color: #dcdcdc; font-size: 0.85rem; }
    .participant-pill .remove { background: none; border: none; color: #aaa; cursor: pointer; padding: 0 4px; }
    .participant-pill .remove:hover { color: #fff; }
    .participants-list .add-select { background: #2b2b2b; border: 1px solid #444; color: #ddd; border-radius: 6px; padding: 4px 8px; }
    .participants-list .add-btn { background: #1b5e20; border: 1px solid #2e7d32; color: #fff; padding: 6px 10px; border-radius: 6px; cursor: pointer; }
    .participants-list .add-btn:hover { background: #2e7d32; }
    .group-controls-row { display: flex; gap: 8px; align-items: stretch; }
    #group-topic-input { flex: 1; background: #2b2b2b; border: 2px solid #444; color: #fff; padding: 0.5rem 0.6rem; border-radius: 6px; font-size: 0.9rem; }
    #group-topic-input:focus { outline: none; border-color: #1171c9; box-shadow: 0 0 0 2px rgba(17,113,201,0.18); }
    /* Group discussion specific button styling */
    #group-seek-consensus { background: #2a2a4a; border-color: #a2a2ff; }

        /* Resizing Handle */
        .resize-handle {
            position: absolute;
            right: 0;
            bottom: 0;
            width: 15px;
            height: 15px;
            cursor: nwse-resize;
            border-right: 2px solid #555;
            border-bottom: 2px solid #555;
        }

        /* UI elements styling */
        textarea#story-input { width: 100%; height: 80px; background-color: #1f1f1f; color: #e0e0e0; border: 1px solid #333; border-radius: 8px; padding: 0.5rem; font-family: 'Georgia', serif; font-size: 0.9rem; resize: vertical; box-sizing: border-box; }
        textarea:focus { outline: none; border-color: #00c8ff; }
        .button-group { display: flex; justify-content: center; align-items: center; gap: 0.5rem; flex-wrap: wrap; }
        .button-group button#generate-btn { flex-grow: 1; }
        .icon-button { font-size: 1.2rem; padding: 0.5rem 0.8rem; }
        button { padding: 0.5rem 1rem; font-size: 0.9rem; background: linear-gradient(145deg, #2c2c2c, #1a1a1a); color: #00c8ff; border: 1px solid #00c8ff; border-radius: 8px; cursor: pointer; transition: all 0.3s ease; }
        button:hover:not(:disabled) { background: linear-gradient(145deg, #3a3a3a, #2b2b2b); color: white; }
        button:disabled { cursor: not-allowed; opacity: 0.5; }
        .tts-button { 
            font-size: 0.9rem; 
            padding: 0.25rem 0.5rem; 
            background: #333; 
            border: 1px solid #555; 
            color: #aaa; 
            flex-shrink: 0; 
            cursor: pointer;
            border-radius: 3px;
            transition: all 0.2s ease;
            margin-right: 0.5rem;
            min-width: 32px;
            text-align: center;
        }
        .tts-button:hover {
            background: #444;
            color: #fff;
            border-color: #666;
        }
        .tts-button.speaking {
            background: #d32f2f;
            color: #fff;
            border-color: #f44336;
            animation: pulse 1.5s infinite;
        }
        @keyframes pulse {
            0% { transform: scale(1); }
            50% { transform: scale(1.05); }
            100% { transform: scale(1); }
        }
        #unveil-story-btn { display: none; }
        #clear-btn { background: #4a2a2a; border-color: #ff8c8c; }
        #settings-btn { background: #2a2a4a; border-color: #a2a2ff; }
        .status-bar { width: 100%; background-color: transparent; border-radius: 8px; padding-top: 0.5rem; color: #aaa; font-style: italic; font-size: 0.9rem; transition: color 0.5s; text-align: left; box-sizing: border-box; }

        /* Technique hint — which Holmes method fits the entered case */
        .technique-hint {
            display: flex;
            align-items: flex-start;
            gap: 0.55rem;
            margin-top: 0.6rem;
            padding: 0.55rem 0.7rem;
            background: rgba(0, 200, 255, 0.07);
            border: 1px solid rgba(0, 200, 255, 0.35);
            border-left: 3px solid #00c8ff;
            border-radius: 8px;
            animation: technique-hint-in 0.35s ease;
        }
        @keyframes technique-hint-in {
            from { opacity: 0; transform: translateY(-6px); }
            to   { opacity: 1; transform: none; }
        }
        .technique-hint-icon { font-size: 1.05rem; line-height: 1.3; }
        .technique-hint-body { flex: 1; display: flex; flex-direction: column; gap: 0.15rem; min-width: 0; }
        .technique-hint-title { font-size: 0.85rem; color: #ccc; }
        .technique-hint-title a { color: #00c8ff; font-weight: bold; text-decoration: none; border-bottom: 1px dotted rgba(0, 200, 255, 0.6); }
        .technique-hint-title a:hover { border-bottom-style: solid; }
        .technique-hint-reason { font-size: 0.82rem; color: #9ab; line-height: 1.45; font-style: italic; }
        #technique-hint-close {
            background: none;
            border: none;
            color: #667;
            font-size: 1rem;
            line-height: 1;
            padding: 0.1rem 0.25rem;
            cursor: pointer;
        }
        #technique-hint-close:hover { color: #00c8ff; }
        @media (prefers-reduced-motion: reduce) { .technique-hint { animation: none; } }
        
        /* Timer Container for bottom-left positioning */
        #timer-container {
            position: absolute;
            bottom: 1rem;
            left: 1rem;
            z-index: 20;
        }

        /* Mode Indicator Styling */
        .mode-indicator {
            background-color: rgba(26, 26, 26, 0.9);
            border: 1px solid #444;
            border-radius: 6px;
            padding: 0.4rem 0.6rem;
            margin-bottom: 0.5rem;
            font-family: 'Courier New', Courier, monospace;
            font-size: 0.8rem;
            display: flex;
            align-items: center;
            gap: 0.5rem;
            min-width: 140px;
        }

        .mode-label {
            color: #888;
            font-weight: 500;
        }

        .mode-text {
            color: #00c8ff;
            font-weight: bold;
            text-transform: uppercase;
            letter-spacing: 0.5px;
        }

        .mode-text.object-oriented {
            color: #ff6b6b;
        }

        .mode-text.traditional {
            color: #00c8ff;
        }

        /* API Counter Styling */
        .api-counter {
            background-color: rgba(26, 26, 26, 0.9);
            border: 1px solid #444;
            border-radius: 6px;
            padding: 0.5rem;
            margin-bottom: 0.5rem;
            font-family: 'Courier New', Courier, monospace;
            font-size: 0.8rem;
            color: #00c8ff;
            min-width: 140px;
        }

        .counter-row {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-bottom: 0.2rem;
        }

        .counter-row:last-child {
            margin-bottom: 0;
        }

        .counter-label {
            color: #ccc;
        }

        #api-calls-count {
            color: #ff6b6b;
            font-weight: bold;
        }

        #token-estimate {
            color: #feca57;
            font-weight: bold;
        }

        /* Timer Display Styling */
        .timer-display {
            text-align: center; /* Center the text */
            font-family: 'Courier New', Courier, monospace;
            font-size: 1rem;
            color: #ccc; /* Default color */
            background-color: rgba(26, 26, 26, 0.8);
            padding: 0.25rem 0.75rem;
            border-radius: 6px;
            border: 1px solid #333;
            min-width: 130px; /* Ensure it doesn't jump around too much */
            transition: all 0.5s ease;
        }
        .timer-display.running {
            font-size: 1.5rem;
            color: #ffffff; /* Changed to white */
            animation: pulse-timer 1.5s infinite;
        }
        @keyframes pulse-timer {
            0% { text-shadow: 0 0 3px rgba(0, 200, 255, 0.7); } /* Adjusted glow for white text */
            50% { text-shadow: 0 0 12px rgba(0, 200, 255, 1); }
            100% { text-shadow: 0 0 3px rgba(0, 200, 255, 0.7); }
        }

        /* Modal & Tooltip */
        .modal-overlay { display: none; position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0, 0, 0, 0.7); backdrop-filter: blur(5px); z-index: 1000; align-items: center; justify-content: center; }
        .modal-content { background: #1a1a1a; border: 1px solid #444; border-radius: 8px; padding: 2rem; width: 90%; max-width: 600px; max-height: 80vh; box-shadow: 0 5px 25px rgba(0,0,0,0.5); position: relative; display: flex; flex-direction: column; }
        .modal-body { overflow-y: auto; padding-top: 0; }
        .modal-close { position: absolute; top: 1rem; right: 1rem; background: none; border: none; font-size: 1.5rem; color: #888; cursor: pointer; z-index: 10; }
        .modal-title { font-size: 1.5rem; margin-bottom: 1rem; color: #00c8ff; }
        .modal-footer { 
            margin-top: 1.5rem; 
            text-align: right; 
            display: flex;
            justify-content: flex-end;
            align-items: center;
            gap: 0.75rem;
        }
        .modal-footer .tts-button {
            margin-right: 0;
        }
        .image-gen-button {
            background: linear-gradient(45deg, #ff6b6b, #feca57);
            color: white;
            border: none;
            padding: 0.5rem 1rem;
            border-radius: 6px;
            cursor: pointer;
            font-size: 0.9rem;
            transition: all 0.3s ease;
            display: flex;
            align-items: center;
            gap: 0.5rem;
        }
        .image-gen-button:hover {
            background: linear-gradient(45deg, #ff5252, #feb47b);
            transform: translateY(-2px);
            box-shadow: 0 4px 12px rgba(255, 107, 107, 0.3);
        }
        .image-gen-button:disabled {
            background: #666;
            cursor: not-allowed;
            transform: none;
            box-shadow: none;
        }
        #conclusion-image-container {
            border-top: 1px solid #444;
            padding-top: 1rem;
            margin-top: 1rem;
        }
        #conclusion-image {
            box-shadow: 0 4px 12px rgba(0,0,0,0.5);
            transition: transform 0.3s ease;
        }
        #conclusion-image:hover {
            transform: scale(1.02);
        }
        #add-clue-modal textarea, #add-char-modal textarea { width: 100%; height: 60px; margin-bottom: 1rem; background-color: #2b2b2b; }
        
        /* Settings Modal UI improvements */
        .settings-modal {
            max-width: 700px !important;
            max-height: 85vh !important;
            padding: 0 !important;
        }
        
        .modal-header {
            background: linear-gradient(135deg, #2d3748, #4a5568);
            padding: 1rem 1.5rem;
            border-bottom: 1px solid #444;
            display: flex;
            justify-content: space-between;
            align-items: center;
            border-radius: 8px 8px 0 0;
        }
        
        .modal-header .modal-title {
            margin: 0;
            font-size: 1.3rem;
            color: #00c8ff;
            display: flex;
            align-items: center;
            gap: 0.5rem;
        }
        
        .modal-header .modal-close {
            position: static;
            background: rgba(255, 255, 255, 0.1);
            border: 1px solid rgba(255, 255, 255, 0.2);
            border-radius: 50%;
            width: 32px;
            height: 32px;
            display: flex;
            align-items: center;
            justify-content: center;
            transition: all 0.3s ease;
        }
        
        .modal-header .modal-close:hover {
            background: rgba(255, 107, 107, 0.2);
            border-color: #ff6b6b;
            color: #ff6b6b;
        }
        
        .settings-modal .modal-body {
            padding: 1.5rem;
            overflow-y: auto;
            max-height: calc(85vh - 80px);
        }
        
        .settings-group {
            padding-bottom: 0.75rem;
            margin-bottom: 1rem;
            border-bottom: 1px solid #333;
        }
        .settings-group:last-of-type {
            border-bottom: none;
            padding-bottom: 0;
            margin-bottom: 0;
        }
        .settings-group h3 {
            margin-top: 0;
            margin-bottom: 0.75rem;
            font-size: 0.85rem;
            color: #888;
            text-transform: uppercase;
            letter-spacing: 1px;
            font-weight: 600;
        }
        .settings-grid {
            display: grid;
            grid-template-columns: 1fr 1fr;
            gap: 1.5rem;
        }
        .settings-toggles {
            display: grid;
            grid-template-columns: 1fr 1fr;
            gap: 0.75rem;
            align-items: center;
        }
        .setting-item { 
            margin-bottom: 0.75rem; 
        }
        .setting-item:last-child { 
            margin-bottom: 0; 
        }
        .setting-item label { 
            display: block; 
            margin-bottom: 0.4rem; 
            font-size: 0.85rem;
            color: #ccc;
            font-weight: 500;
        }
        .setting-item input, .setting-item select, .setting-item textarea {
            width: 100%;
            background: #2b2b2b;
            color: #fff;
            border: 1px solid #444;
            padding: 0.4rem 0.6rem;
            border-radius: 4px;
            box-sizing: border-box;
            font-family: 'Georgia', serif;
            font-size: 0.9rem;
            transition: border-color 0.3s ease;
        }
        .setting-item input:focus, .setting-item select:focus, .setting-item textarea:focus {
            outline: none;
            border-color: #00c8ff;
            box-shadow: 0 0 0 2px rgba(0, 200, 255, 0.1);
        }
        .setting-item textarea { 
            resize: vertical; 
            min-height: 36px; 
        }
        .setting-item input[type="range"] { 
            padding: 0; 
            height: 6px;
            background: #444;
            border-radius: 3px;
        }
        .setting-item input[type="range"]::-webkit-slider-thumb {
            appearance: none;
            width: 16px;
            height: 16px;
            border-radius: 50%;
            background: #00c8ff;
            cursor: pointer;
            border: 2px solid #1a1a1a;
            box-shadow: 0 2px 4px rgba(0,0,0,0.3);
        }
        .setting-item .checkbox-label { 
            display: flex; 
            align-items: center; 
            gap: 0.5rem; 
            margin-bottom: 0.5rem;
            font-size: 0.85rem;
        }
        .setting-item .checkbox-label input { 
            width: auto; 
            margin: 0;
        }

        /* ==============================================================
           Smoothness pass: entrance animations, transitions, feedback
           ============================================================== */

        /* Every modal eases in each time it is shown (display: none -> flex
           restarts the animation, so no JS is needed). */
        @keyframes modal-pop {
            from { opacity: 0; transform: translateY(14px) scale(0.97); }
            to   { opacity: 1; transform: translateY(0) scale(1); }
        }
        .modal-content { animation: modal-pop 0.22s cubic-bezier(0.2, 0.8, 0.3, 1.1); }

        /* Overlay backdrop fades in with the modal */
        @keyframes overlay-fade {
            from { background: rgba(0, 0, 0, 0); backdrop-filter: blur(0); }
            to   { background: rgba(0, 0, 0, 0.7); backdrop-filter: blur(5px); }
        }
        .modal-overlay { animation: overlay-fade 0.2s ease; }

        /* Tooltips fade in instead of popping */
        @keyframes tooltip-in {
            from { opacity: 0; transform: translateY(4px); }
            to   { opacity: 1; transform: translateY(0); }
        }
        #clue-tooltip, #char-tooltip { animation: tooltip-in 0.15s ease; }

        /* Chat messages slide in gently */
        @keyframes msg-in {
            from { opacity: 0; transform: translateY(6px); }
            to   { opacity: 1; transform: translateY(0); }
        }
        .chat-log p { animation: msg-in 0.18s ease; }

        /* Toolbar and panel buttons: lift on hover, sink on press */
        #game-toolbar button,
        .button-group button,
        .panel-controls button,
        .chat-input-form button {
            transition: transform 0.12s ease, background-color 0.2s ease,
                        border-color 0.2s ease, box-shadow 0.2s ease, color 0.2s ease;
        }
        #game-toolbar button:active,
        .button-group button:active,
        .panel-controls button:active,
        .chat-input-form button:active { transform: scale(0.92); }

        /* Character icons get the same tactile feedback */
        .char-icon { transition: transform 0.15s ease, box-shadow 0.2s ease, border-color 0.2s ease; }
        .char-icon:hover { transform: translateY(-2px) scale(1.06); }
        .char-icon:active { transform: scale(0.94); }

        /* Floating panels: soft shadow lift while dragged */
        .floating-panel { transition: box-shadow 0.2s ease; }
        .floating-panel.panel-dragging {
            box-shadow: 0 14px 40px rgba(0, 0, 0, 0.65), 0 0 0 1px rgba(0, 200, 255, 0.25);
        }
        .floating-panel .panel-header { cursor: grab; }

        /* Inputs focus smoothly */
        .chat-input-form input, #story-input, #group-topic-input {
            transition: border-color 0.2s ease, box-shadow 0.2s ease;
        }

        /* ==============================================================
           Chat panel resize & minimize fixes
           ============================================================== */

        /* Resizing: let the content actually follow the panel size.
           The generic .controls-content rule caps height at 500px, which
           left dead space when a chat was resized taller than that. */
        .chat-panel .controls-content {
            max-height: none;
            animation: content-restore 0.18s ease;
        }
        @keyframes content-restore {
            from { opacity: 0; transform: translateY(-4px); }
            to   { opacity: 1; transform: translateY(0); }
        }

        /* The log flexes to fill whatever height the panel has; the input
           row keeps its natural height. The base .chat-log rule caps the
           log at 260px, which made resizing pointless — lift the cap here. */
        .chat-panel .chat-log {
            flex: 1 1 auto;
            height: auto;
            min-height: 0;
            max-height: none;
        }
        .chat-panel .chat-input-form { flex-shrink: 0; }

        /* Minimize: collapse the whole panel to its title bar. The
           !important lets it win over the inline height set by resizing,
           and the stored inline height returns intact on restore. */
        .chat-panel.collapsed {
            height: auto !important;
            min-height: 0 !important;
        }
        .chat-panel.collapsed .controls-content { display: none; }
        .chat-panel.collapsed .resize-handle { display: none; }
        .chat-panel.collapsed .panel-header { border-bottom: none; }

        /* Respect users who prefer less motion */
        @media (prefers-reduced-motion: reduce) {
            .modal-content, .modal-overlay, #clue-tooltip, #char-tooltip, .chat-log p,
            .chat-panel .controls-content {
                animation: none;
            }
            #game-toolbar button, .button-group button, .panel-controls button,
            .chat-input-form button, .char-icon, .floating-panel {
                transition: none;
            }
        }

        /* Case titles can be long: keep the board header on one tidy line */
        #controls-panel .panel-header h1 {
            display: block;
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
            min-width: 0;
        }

        /* ==============================================================
           Voice calls (Gemini Live)
           ============================================================== */
        #call-card {
            position: fixed;
            bottom: 60px;
            right: 16px;
            z-index: 1200;
            display: flex;
            align-items: center;
            gap: 0.9rem;
            width: min(380px, calc(100vw - 32px));
            background: rgba(14, 18, 24, 0.97);
            border: 1px solid #00c8ff;
            border-radius: 16px;
            padding: 0.9rem 1rem;
            box-shadow: 0 12px 44px rgba(0, 0, 0, 0.7), 0 0 30px rgba(0, 200, 255, 0.15);
            animation: modal-pop 0.25s ease;
        }
        .call-avatar {
            width: 54px;
            height: 54px;
            border-radius: 50%;
            background: #1c2733;
            border: 2px solid #2f4254;
            display: flex;
            align-items: center;
            justify-content: center;
            font-size: 1.7rem;
            transition: border-color 0.2s ease;
        }
        .call-avatar.speaking {
            border-color: #00c8ff;
            animation: call-pulse 1.1s ease-in-out infinite;
        }
        @keyframes call-pulse {
            0%, 100% { box-shadow: 0 0 0 0 rgba(0, 200, 255, 0.45); }
            50% { box-shadow: 0 0 0 12px rgba(0, 200, 255, 0); }
        }
        .call-info { flex: 1; min-width: 0; }
        .call-name { font-weight: bold; }
        .call-status { color: #8aa0b0; font-size: 0.8rem; }
        .call-status.warn { color: #ffb454; }
        .call-transcript {
            color: #6d7f8c;
            font-size: 0.75rem;
            font-style: italic;
            margin-top: 0.25rem;
            max-height: 2.6em;
            overflow: hidden;
        }
        .call-controls { display: flex; flex-direction: column; align-items: center; gap: 0.4rem; }
        .call-timer { color: #8aa0b0; font-size: 0.72rem; font-variant-numeric: tabular-nums; }
        .call-controls button {
            width: 40px;
            height: 40px;
            border-radius: 50%;
            border: 1px solid #2f4254;
            background: #1c2733;
            font-size: 1.05rem;
            cursor: pointer;
            transition: all 0.15s ease;
        }
        .call-controls button:hover { border-color: #00c8ff; transform: translateY(-1px); }
        #call-end:hover { border-color: #ff6b6b; background: rgba(255, 107, 107, 0.15); }
        #call-mute.muted { border-color: #ffb454; background: rgba(255, 180, 84, 0.12); }
        .call-note { color: #7ddf8a; font-style: italic; font-size: 0.85rem; }

        /* ==============================================================
           Neural mind-space (Devil's Daughter board feel)
           ============================================================== */
        body.board-theme-mind-space #canvas-container::after {
            content: '';
            position: fixed;
            inset: 0;
            pointer-events: none;
            z-index: 5;
            background:
                radial-gradient(1200px 700px at 30% 20%, rgba(30, 90, 140, 0.10), transparent 60%),
                radial-gradient(1000px 600px at 75% 80%, rgba(90, 40, 150, 0.08), transparent 60%),
                radial-gradient(closest-side at 50% 50%, transparent 62%, rgba(0, 0, 8, 0.55) 100%);
        }
        body.board-theme-noir #canvas-container::after {
            content: '';
            position: fixed;
            inset: 0;
            pointer-events: none;
            z-index: 5;
            background: radial-gradient(closest-side at 50% 45%, transparent 55%, rgba(0, 0, 0, 0.7) 100%);
        }
        /* Parchment: light canvas needs readable floating UI text over it */
        body.board-theme-parchment #timer-container,
        body.board-theme-parchment #mode-indicator { filter: drop-shadow(0 1px 2px rgba(0,0,0,0.5)); }

        /* AI configuration controls */
        .api-key-row {
            display: flex;
            gap: 0.5rem;
            align-items: stretch;
        }
        .api-key-row input {
            flex: 1;
            font-family: monospace;
            letter-spacing: 0.5px;
        }
        .api-key-row button {
            background: #2b2b2b;
            color: #fff;
            border: 1px solid #444;
            border-radius: 4px;
            padding: 0 0.6rem;
            cursor: pointer;
            font-size: 0.9rem;
            transition: border-color 0.3s ease;
        }
        .api-key-row button:hover {
            border-color: #00c8ff;
        }
        .setting-hint {
            font-size: 0.75rem;
            color: #888;
            margin: 0.35rem 0 0;
            line-height: 1.4;
        }
        .setting-hint a {
            color: #00c8ff;
            text-decoration: none;
        }
        .setting-hint a:hover {
            text-decoration: underline;
        }
        .setting-status {
            font-size: 0.8rem;
            margin: 0.4rem 0 0;
        }
        .setting-status.ok {
            color: #7ddf8a;
        }
        .setting-status.warn {
            color: #ffb454;
        }

        /* Premium section styling */
        .premium-section {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            border-radius: 8px;
            padding: 1rem;
            margin: 1rem 0;
            color: white;
            box-shadow: 0 4px 16px rgba(102, 126, 234, 0.2);
            border: 1px solid rgba(255, 255, 255, 0.1);
        }

        .premium-section h3 {
            margin: 0 0 0.75rem 0 !important;
            color: white !important;
            border-bottom: 1px solid rgba(255, 255, 255, 0.2) !important;
            padding-bottom: 0.5rem;
            display: flex;
            align-items: center;
            gap: 8px;
            text-transform: none !important;
            letter-spacing: normal !important;
            font-size: 1rem !important;
        }

        .premium-badge {
            background: linear-gradient(45deg, #FFD700, #FFA500);
            color: #333;
            font-size: 9px;
            font-weight: bold;
            padding: 2px 6px;
            border-radius: 10px;
            box-shadow: 0 2px 6px rgba(255, 215, 0, 0.2);
            text-transform: uppercase;
            letter-spacing: 0.5px;
        }

        .premium-feature {
            background: rgba(255, 255, 255, 0.1);
            border-radius: 6px;
            padding: 0.75rem;
            backdrop-filter: blur(10px);
            border: 1px solid rgba(255, 255, 255, 0.1);
        }

        .premium-toggle-container {
            display: flex;
            flex-direction: column;
            gap: 0.5rem;
        }

        .premium-checkbox-label {
            display: flex;
            align-items: center;
            gap: 0.75rem;
            font-size: 0.95rem;
            font-weight: 500;
            cursor: pointer;
            color: white;
        }

        .premium-checkbox-label input[type="checkbox"] {
            width: 18px;
            height: 18px;
            cursor: pointer;
            accent-color: #FFD700;
        }

        .premium-feature-name {
            font-weight: 600;
            text-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
        }

        .premium-description {
            color: rgba(255, 255, 255, 0.9);
            font-size: 0.8rem;
            line-height: 1.4;
            margin-left: 2rem;
            margin-top: 0.5rem;
            font-style: italic;
            text-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
        }

        #clue-tooltip, #char-tooltip { position: absolute; display: none; background-color: rgba(10, 10, 10, 0.9); color: #e0e0e0; border: 1px solid #555; border-radius: 6px; padding: 0.75rem; font-size: 0.9rem; max-width: 250px; pointer-events: none; z-index: 1001; box-shadow: 0 4px 12px rgba(0,0,0,0.5); }
        #char-tooltip b { color: #00c8ff; }
        .confirmation-buttons { display: flex; gap: 1rem; justify-content: flex-end; }
        
        /* Suggestion Modal UI Improvements */
        #suggestion-list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 1rem; }
        .suggestion-card { background: #2a2a2a; border-left: 4px solid #00c8ff; padding: 1rem; border-radius: 6px; display: flex; flex-direction: column; gap: 0.5rem; }
        .suggestion-card h3 { margin: 0; font-size: 1.1rem; color: #e0e0e0; }
        .suggestion-card p { margin: 0; font-size: 0.9rem; color: #aaa; line-height: 1.4; }
        .suggestion-card .add-btn { align-self: flex-end; padding: 0.4rem 0.8rem; font-size: 0.8rem; }
        .suggestion-card .add-btn:disabled { background: #3a9a3a; border-color: #3a9a3a; color: #fff; }

        /* Animated Loader for Suggestions */
        .suggestion-loader { display: none; flex-direction: column; align-items: center; justify-content: center; gap: 1rem; margin: 2rem 0; }
        .magnifying-glass { width: 60px; height: 60px; border: 5px solid #555; border-radius: 50%; position: relative; animation: scan 2s linear infinite; }
        .magnifying-glass::after { content: ''; position: absolute; bottom: -25px; right: -25px; width: 35px; height: 5px; background: #555; transform: rotate(-45deg); }
        @keyframes scan { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } }
        .suggestion-loader p { font-style: italic; color: #aaa; }

        /* Sleek modal enter animation for Suggestions */
        #suggestion-modal .modal-content { max-width: 720px; }
        #suggestion-modal .modal-content.animate-in {
            animation: modal-pop-in 220ms ease-out;
        }
        @keyframes modal-pop-in {
            0% { opacity: 0; transform: translateY(6px) scale(0.98); }
            100% { opacity: 1; transform: translateY(0) scale(1); }
        }

        /* Suggestions grid and smoother cards */
        #suggestion-list {
            display: grid;
            grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
            gap: 12px;
            max-height: 60vh;
            overflow-y: auto;
            padding-right: 6px;
        }
        .suggestion-card {
            background: linear-gradient(180deg, rgba(42,42,42,0.95), rgba(32,32,32,0.95));
            border: 1px solid #333;
            border-left: 4px solid #00c8ff;
            border-radius: 10px;
            padding: 0.9rem 1rem;
            transition: transform 160ms ease, box-shadow 160ms ease, border-color 160ms ease;
        }
        .suggestion-card:hover {
            transform: translateY(-2px);
            box-shadow: 0 8px 24px rgba(0,0,0,0.35);
            border-left-color: #35d1ff;
        }
        .suggestion-card h3 { font-weight: 600; letter-spacing: 0.2px; }
        .suggestion-card p { color: #b8b8b8; }
        .suggestion-card .add-btn {
            align-self: flex-end;
            padding: 0.45rem 0.9rem;
            font-size: 0.85rem;
            background: #0b5aa0;
            border: 1px solid #1f78c1;
            color: #fff;
            border-radius: 6px;
            transition: transform 120ms ease, background-color 160ms ease, box-shadow 160ms ease;
        }
        .suggestion-card .add-btn:hover:not(:disabled) {
            background: #1171c9;
            box-shadow: 0 4px 14px rgba(17, 113, 201, 0.35);
            transform: translateY(-1px);
        }
        .suggestion-card .add-btn:active:not(:disabled) {
            transform: translateY(0);
        }
        #suggestion-list::-webkit-scrollbar { width: 8px; }
        #suggestion-list::-webkit-scrollbar-track { background: #202020; border-radius: 4px; }
        #suggestion-list::-webkit-scrollbar-thumb { background: #3e3e3e; border-radius: 4px; }
        #suggestion-list::-webkit-scrollbar-thumb:hover { background: #4e4e4e; }
        
        /* Game Toolbar */
        #game-toolbar {
            position: absolute;
            bottom: 20px;
            left: 50%;
            transform: translateX(-50%);
            background: rgba(10, 10, 10, 0.8);
            backdrop-filter: blur(10px);
            border: 1px solid #333;
            border-radius: 12px;
            padding: 8px;
            display: flex;
            gap: 8px;
            z-index: 100;
        }
        #game-toolbar button {
            background: #2b2b2b;
            border: 1px solid #444;
            color: #ccc;
            font-size: 1.5rem;
            width: 50px;
            height: 50px;
            border-radius: 8px;
            transition: all 0.2s ease;
            display: flex;
            align-items: center;
            justify-content: center;
        }
        #game-toolbar button:hover {
            transform: scale(1.1);
            background: #3c3c3c;
            color: #fff;
            border-color: #00c8ff;
        }
        
        /* Thinking Visualization Button States */
        .thinking-viz-btn.active {
            background: #4a4a4a !important;
            border-color: #9c27b0 !important;
            color: #e1bee7 !important;
            box-shadow: 0 0 10px rgba(156, 39, 176, 0.3);
        }
        
        .thinking-viz-btn.inactive {
            background: #2b2b2b !important;
            border-color: #555 !important;
            color: #888 !important;
            opacity: 0.6;
        }
        
        .thinking-viz-btn.active:hover {
            background: #5a3a7a !important;
            border-color: #ba68c8 !important;
            box-shadow: 0 0 15px rgba(156, 39, 176, 0.5);
        }
        
        .thinking-viz-btn.inactive:hover {
            background: #3c3c3c !important;
            border-color: #777 !important;
            opacity: 0.8;
        }

        /* Communication Log Window */
        #comm-log-panel {
            min-width: 400px;
            min-height: 300px;
            max-width: 90vw;
            max-height: 80vh;
        }

        .comm-log-content {
            flex: 1;
            display: flex;
            flex-direction: column;
            padding: 1rem;
            overflow: hidden;
        }

        .comm-log-tabs {
            display: flex;
            border-bottom: 2px solid #333;
            margin-bottom: 1rem;
        }

        .comm-tab-button {
            background: #2b2b2b;
            border: none;
            color: #aaa;
            padding: 0.8rem 1.2rem;
            cursor: pointer;
            border-radius: 8px 8px 0 0;
            margin-right: 4px;
            transition: all 0.3s ease;
            font-size: 0.9rem;
            border-bottom: 2px solid transparent;
        }

        .comm-tab-button:hover {
            background: #3c3c3c;
            color: #fff;
        }

        .comm-tab-button.active {
            background: #4a4a4a;
            color: #e1bee7;
            border-bottom: 2px solid #9c27b0;
        }

        .comm-tab-content {
            display: none;
            flex: 1;
            flex-direction: column;
            overflow: hidden;
        }

        .comm-tab-content.active {
            display: flex;
        }

        .log-header {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-bottom: 0.8rem;
            padding-bottom: 0.5rem;
            border-bottom: 1px solid #444;
        }

        .log-title {
            font-weight: bold;
            color: #e0e0e0;
            font-size: 1rem;
        }

        .log-controls {
            display: flex;
            gap: 1rem;
            align-items: center;
        }

        .log-controls label {
            display: flex;
            align-items: center;
            gap: 0.5rem;
            color: #aaa;
            font-size: 0.85rem;
        }

        .log-controls input[type="checkbox"] {
            accent-color: #9c27b0;
        }

        .log-controls button {
            background: #2b2b2b;
            border: 1px solid #555;
            color: #aaa;
            padding: 0.3rem 0.8rem;
            border-radius: 4px;
            cursor: pointer;
            font-size: 0.8rem;
            transition: all 0.3s ease;
        }

        .log-controls button:hover {
            background: #3c3c3c;
            color: #fff;
            border-color: #9c27b0;
        }

        .log-container {
            flex: 1;
            background: #1a1a1a;
            border: 1px solid #333;
            border-radius: 6px;
            padding: 1rem;
            overflow-y: auto;
            font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
            font-size: 0.85rem;
            line-height: 1.4;
        }

        .log-placeholder {
            color: #666;
            font-style: italic;
            text-align: center;
            margin-top: 2rem;
        }

        .log-entry {
            margin-bottom: 1rem;
            padding: 0.8rem;
            border-radius: 6px;
            border-left: 4px solid #555;
        }

        .log-entry.message {
            background: rgba(138, 43, 226, 0.1);
            border-left-color: #9c27b0;
        }

        .log-entry.api-request {
            background: rgba(0, 150, 255, 0.1);
            border-left-color: #0096ff;
        }

        .log-entry.api-response {
            background: rgba(0, 200, 100, 0.1);
            border-left-color: #00c864;
        }

        .log-entry.error {
            background: rgba(255, 69, 0, 0.1);
            border-left-color: #ff4500;
        }

        .log-timestamp {
            font-size: 0.75rem;
            color: #888;
            margin-bottom: 0.3rem;
        }

        .log-content {
            color: #e0e0e0;
        }

        .log-content pre {
            background: #0d0d0d;
            padding: 0.5rem;
            border-radius: 4px;
            overflow-x: auto;
            margin: 0.5rem 0;
            font-size: 0.8rem;
        }

        .log-object-id {
            color: #9c27b0;
            font-weight: bold;
        }

        .log-api-method {
            color: #0096ff;
            font-weight: bold;
        }

        .log-status-code {
            color: #00c864;
            font-weight: bold;
        }

        .log-error-code {
            color: #ff4500;
            font-weight: bold;
        }

        /* Resize handle for communication log */
        .resize-handle {
            position: absolute;
            bottom: 0;
            right: 0;
            width: 20px;
            height: 20px;
            background: linear-gradient(-45deg, transparent 30%, #555 30%, #555 40%, transparent 40%, transparent 60%, #555 60%, #555 70%, transparent 70%);
            cursor: nw-resize;
            border-bottom-right-radius: 8px;
        }

        .resize-handle:hover {
            background: linear-gradient(-45deg, transparent 30%, #9c27b0 30%, #9c27b0 40%, transparent 40%, transparent 60%, #9c27b0 60%, #9c27b0 70%, transparent 70%);
        }

        /* Character Edit Modal Styles */
        #character-edit-modal .modal-content {
            max-width: 500px;
        }

        #character-edit-modal .setting-item {
            margin-bottom: 1.2rem;
        }

        #character-edit-modal .setting-item label {
            display: block;
            margin-bottom: 0.5rem;
            font-weight: 600;
            color: #e2e8f0;
        }

        #character-edit-modal .setting-item input,
        #character-edit-modal .setting-item textarea {
            width: 100%;
            padding: 0.6rem;
            background: #2d3748;
            border: 1px solid #4a5568;
            border-radius: 6px;
            color: #e2e8f0;
            font-size: 0.95rem;
            resize: vertical;
        }

        #character-edit-modal .setting-item input:focus,
        #character-edit-modal .setting-item textarea:focus {
            outline: none;
            border-color: #63b3ed;
            box-shadow: 0 0 0 2px rgba(99, 179, 237, 0.2);
        }

        #character-edit-modal .modal-footer {
            display: flex;
            gap: 1rem;
            justify-content: flex-end;
            padding-top: 1.5rem;
            border-top: 1px solid #4a5568;
        }

        .primary-button {
            background: #3182ce;
            color: white;
            border: none;
            padding: 0.75rem 1.5rem;
            border-radius: 6px;
            font-weight: 600;
            cursor: pointer;
            transition: background 0.2s ease;
        }

        .primary-button:hover {
            background: #2c5282;
        }

        .secondary-button {
            background: #4a5568;
            color: #e2e8f0;
            border: 1px solid #6b7280;
            padding: 0.75rem 1.5rem;
            border-radius: 6px;
            font-weight: 600;
            cursor: pointer;
            transition: all 0.2s ease;
        }

        .secondary-button:hover {
            background: #2d3748;
            border-color: #9ca3af;
        }

        /* Help Modal Styles */
        .help-modal {
            max-width: 900px;
            max-height: 80vh;
            width: 90vw;
        }

        .help-tabs {
            display: flex;
            border-bottom: 2px solid #333;
            margin-bottom: 1.5rem;
            overflow-x: auto;
        }

        .help-tab {
            background: transparent;
            border: none;
            color: #e0e0e0;
            padding: 0.75rem 1.5rem;
            cursor: pointer;
            border-bottom: 3px solid transparent;
            transition: all 0.3s ease;
            white-space: nowrap;
            font-size: 0.9rem;
        }

        .help-tab.active,
        .help-tab:hover {
            color: #4a90e2;
            border-bottom-color: #4a90e2;
            background: rgba(74, 144, 226, 0.1);
        }

        .help-content {
            max-height: 60vh;
            overflow-y: auto;
            padding-right: 10px;
        }

        .help-tab-content {
            display: none;
        }

        .help-tab-content.active {
            display: block;
        }

        .help-tab-content h3 {
            color: #4a90e2;
            margin-bottom: 1rem;
            font-size: 1.5rem;
        }

        .help-tab-content h4 {
            color: #e0e0e0;
            margin: 1.5rem 0 0.75rem 0;
            font-size: 1.2rem;
        }

        .help-tab-content h5 {
            color: #b0b0b0;
            margin: 1rem 0 0.5rem 0;
            font-size: 1rem;
        }

        .help-feature-grid {
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
            gap: 1.5rem;
            margin: 1.5rem 0;
        }

        .help-feature {
            background: rgba(74, 144, 226, 0.1);
            border: 1px solid #4a90e2;
            border-radius: 8px;
            padding: 1.5rem;
            text-align: center;
        }

        .help-icon {
            font-size: 2rem;
            margin-bottom: 0.75rem;
        }

        .help-feature h4 {
            color: #4a90e2;
            margin: 0.5rem 0;
            font-size: 1.1rem;
        }

        .help-feature p {
            color: #c0c0c0;
            font-size: 0.9rem;
            line-height: 1.4;
        }

        .help-step {
            display: flex;
            margin: 2rem 0;
            gap: 1rem;
        }

        .help-step-number {
            background: #4a90e2;
            color: white;
            width: 2rem;
            height: 2rem;
            border-radius: 50%;
            display: flex;
            align-items: center;
            justify-content: center;
            font-weight: bold;
            flex-shrink: 0;
        }

        .help-step-content h4 {
            margin-top: 0;
            color: #e0e0e0;
        }

        .help-example {
            background: rgba(255, 255, 255, 0.05);
            border-left: 4px solid #4a90e2;
            padding: 1rem;
            margin: 1rem 0;
            border-radius: 4px;
        }

        .help-toolbar-guide {
            margin: 1.5rem 0;
        }

        .help-toolbar-item {
            display: flex;
            align-items: center;
            gap: 1rem;
            padding: 0.75rem 0;
            border-bottom: 1px solid #333;
        }

        .help-toolbar-icon {
            background: #4a90e2;
            padding: 0.5rem;
            border-radius: 6px;
            font-size: 1.1rem;
            width: 2rem;
            height: 2rem;
            display: flex;
            align-items: center;
            justify-content: center;
        }

        .help-interactions ul,
        .help-ai-features ul,
        .help-tips ul {
            list-style: none;
            padding: 0;
        }

        .help-interactions li,
        .help-ai-features li,
        .help-tips li {
            background: rgba(255, 255, 255, 0.05);
            padding: 0.75rem;
            margin: 0.5rem 0;
            border-radius: 6px;
            border-left: 3px solid #4a90e2;
        }

        .help-system-comparison {
            display: grid;
            grid-template-columns: 1fr 1fr;
            gap: 2rem;
            margin: 2rem 0;
        }

        .help-system {
            background: rgba(255, 255, 255, 0.05);
            border-radius: 8px;
            padding: 1.5rem;
            border: 1px solid #333;
        }

        .traditional-system {
            border-left: 4px solid #28a745;
        }

        .oo-system {
            border-left: 4px solid #4a90e2;
        }

        .system-pros ul {
            list-style: none;
            padding: 0;
        }

        .system-pros li {
            padding: 0.25rem 0;
            color: #c0c0c0;
        }

        .system-description {
            margin-top: 1rem;
            padding-top: 1rem;
            border-top: 1px solid #333;
        }

        .help-when-to-use {
            margin: 2rem 0;
        }

        .help-usage-guide {
            display: grid;
            grid-template-columns: 1fr 1fr;
            gap: 2rem;
        }

        .usage-scenario {
            background: rgba(255, 255, 255, 0.05);
            padding: 1.5rem;
            border-radius: 8px;
            border: 1px solid #333;
        }

        .usage-scenario strong {
            color: #4a90e2;
            display: block;
            margin-bottom: 0.75rem;
            font-size: 1.1rem;
        }

        .usage-scenario ul {
            list-style: none;
            padding: 0;
        }

        .usage-scenario li {
            padding: 0.25rem 0;
            color: #c0c0c0;
        }

        .help-faq {
            margin: 1.5rem 0;
        }

        .faq-item {
            background: rgba(255, 255, 255, 0.05);
            border-radius: 8px;
            padding: 1.5rem;
            margin: 1rem 0;
            border: 1px solid #333;
        }

        .faq-item h4 {
            color: #4a90e2;
            margin-top: 0;
        }

        .faq-item ul {
            list-style: none;
            padding: 0;
        }

        .faq-item li {
            padding: 0.25rem 0;
            color: #c0c0c0;
        }

        .help-tips {
            background: rgba(74, 144, 226, 0.1);
            border: 1px solid #4a90e2;
            border-radius: 8px;
            padding: 1.5rem;
            margin: 1.5rem 0;
        }

        .help-tips h4 {
            color: #4a90e2;
            margin-top: 0;
        }

        /* Mobile responsiveness for help modal */
        @media (max-width: 768px) {
            .help-modal {
                width: 95vw;
                max-height: 90vh;
            }

            .help-tabs {
                flex-wrap: wrap;
            }

            .help-tab {
                padding: 0.5rem 1rem;
                font-size: 0.8rem;
            }

            .help-feature-grid {
                grid-template-columns: 1fr;
            }

            .help-system-comparison {
                grid-template-columns: 1fr;
            }

            .help-usage-guide {
                grid-template-columns: 1fr;
            }

            .help-step {
                flex-direction: column;
            }

            .help-step-number {
                align-self: flex-start;
            }
        }

/* State Modal Styles */
.state-modal-content {
    width: 90%;
    max-width: 800px;
    max-height: 90vh;
    overflow-y: auto;
}

.state-tabs {
    display: flex;
    margin-bottom: 1rem;
    border-bottom: 1px solid #444;
}

.state-tab-btn {
    padding: 0.75rem 1.5rem;
    background: none;
    border: none;
    color: #aaa;
    cursor: pointer;
    transition: all 0.3s ease;
    border-bottom: 2px solid transparent;
    font-family: inherit;
    font-size: 0.9rem;
}

.state-tab-btn:hover {
    color: #fff;
    background: rgba(255, 255, 255, 0.1);
}

.state-tab-btn.active {
    color: #4CAF50;
    border-bottom-color: #4CAF50;
    background: rgba(76, 175, 80, 0.1);
}

.state-tab-content {
    display: none;
}

.state-tab-content.active {
    display: block;
}

.state-section {
    margin-bottom: 1.5rem;
    padding: 1rem;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 8px;
    border-left: 3px solid #4CAF50;
}

.state-section h4 {
    margin: 0 0 1rem 0;
    color: #4CAF50;
    font-size: 1.1rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.state-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 0.75rem;
}

.state-item {
    padding: 0.5rem;
    background: rgba(255, 255, 255, 0.03);
    border-radius: 4px;
    font-size: 0.9rem;
}

.state-item strong {
    color: #fff;
}

.state-description {
    padding: 1rem;
    background: rgba(255, 255, 255, 0.03);
    border-radius: 4px;
    line-height: 1.6;
    font-size: 0.95rem;
}

.state-description > div {
    margin-bottom: 0.75rem;
}

.state-description > div:last-child {
    margin-bottom: 0;
}

.state-relationships, .state-evidence {
    background: rgba(255, 255, 255, 0.03);
    border-radius: 4px;
    padding: 1rem;
}

.relationships-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.relationship-item {
    padding: 0.5rem;
    background: rgba(76, 175, 80, 0.1);
    border-radius: 4px;
    border-left: 3px solid #4CAF50;
    font-size: 0.9rem;
}

.state-insights {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.insight-item {
    padding: 0.75rem;
    background: rgba(255, 255, 255, 0.03);
    border-radius: 4px;
    border-left: 3px solid #FF9800;
}

.insight-type {
    font-weight: bold;
    color: #FF9800;
    font-size: 0.8rem;
    text-transform: uppercase;
    margin-bottom: 0.25rem;
}

.insight-content {
    font-size: 0.9rem;
    line-height: 1.5;
    margin-bottom: 0.25rem;
}

.insight-confidence {
    font-size: 0.8rem;
    color: #aaa;
}

.reasoning-chain {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.reasoning-step {
    padding: 0.75rem;
    background: rgba(255, 255, 255, 0.03);
    border-radius: 4px;
    border-left: 3px solid #2196F3;
    font-size: 0.9rem;
    line-height: 1.5;
}

.reasoning-step strong {
    color: #2196F3;
    display: block;
    margin-bottom: 0.5rem;
}

.comm-log {
    max-height: 400px;
    overflow-y: auto;
    background: rgba(0, 0, 0, 0.3);
    border-radius: 4px;
    padding: 1rem;
}

.comm-entry {
    margin-bottom: 0.75rem;
    padding: 0.5rem;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 4px;
    border-left: 3px solid #9C27B0;
}

.comm-timestamp {
    font-size: 0.7rem;
    color: #aaa;
    margin-bottom: 0.25rem;
}

.comm-message {
    font-size: 0.85rem;
    line-height: 1.4;
}

.state-empty {
    text-align: center;
    color: #666;
    font-style: italic;
    padding: 1rem;
    background: rgba(255, 255, 255, 0.02);
    border-radius: 4px;
}

/* Responsive adjustments for state modal */
@media (max-width: 768px) {
    .state-modal-content {
        width: 95%;
        max-height: 95vh;
    }
    
    .state-grid {
        grid-template-columns: 1fr;
    }
    
    .state-tabs {
        flex-wrap: wrap;
    }
    
    .state-tab-btn {
        padding: 0.5rem 1rem;
        font-size: 0.8rem;
    }
}
/* ==============================================================
   Board Extras — optional features (all off by default)
   ============================================================== */

/* Corkboard theme: cork texture + soft vignette overlay */
body.board-theme-corkboard #canvas-container::after {
    content: '';
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 5;
    background:
        radial-gradient(3px 3px at 12% 30%, rgba(60, 40, 20, 0.18), transparent 60%),
        radial-gradient(3px 3px at 44% 68%, rgba(60, 40, 20, 0.16), transparent 60%),
        radial-gradient(3px 3px at 78% 22%, rgba(60, 40, 20, 0.18), transparent 60%),
        radial-gradient(3px 3px at 63% 84%, rgba(60, 40, 20, 0.15), transparent 60%),
        radial-gradient(3px 3px at 28% 55%, rgba(60, 40, 20, 0.14), transparent 60%),
        radial-gradient(closest-side at 50% 45%, transparent 60%, rgba(30, 18, 6, 0.45) 100%);
}
body.board-theme-corkboard #timer-container,
body.board-theme-corkboard #mode-indicator { filter: drop-shadow(0 1px 2px rgba(0,0,0,0.5)); }

/* Settings: feature toggle grid */
.extras-quick { display: flex; gap: 0.5rem; margin-bottom: 0.7rem; }
.extras-quick button {
    background: rgba(0, 200, 255, 0.08);
    border: 1px solid #2a4a5a;
    color: #9fd8ee;
    border-radius: 8px;
    padding: 0.32rem 0.8rem;
    font-family: inherit;
    font-size: 0.82rem;
    cursor: pointer;
    transition: all 0.2s ease;
}
.extras-quick button:hover { border-color: #00c8ff; color: #00c8ff; }
.extras-toggle-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(215px, 1fr));
    gap: 0.35rem 0.9rem;
}
.extras-toggle {
    display: flex;
    align-items: center;
    gap: 0.45rem;
    font-size: 0.86rem;
    color: #cfd6de;
    cursor: pointer;
    padding: 0.22rem 0.3rem;
    border-radius: 6px;
    transition: background 0.15s ease;
}
.extras-toggle:hover { background: rgba(0, 200, 255, 0.07); }
.extras-toggle input { accent-color: #00c8ff; }

/* Actions row inside the controls panel */
#extras-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
    margin-top: 0.55rem;
    padding-top: 0.55rem;
    border-top: 1px dashed rgba(150, 150, 150, 0.25);
}
#extras-actions[hidden] { display: none; }
.extras-btn {
    background: rgba(20, 24, 32, 0.85);
    border: 1px solid #3a4250;
    color: #c8d2dc;
    border-radius: 8px;
    padding: 0.3rem 0.65rem;
    font-family: inherit;
    font-size: 0.78rem;
    cursor: pointer;
    transition: all 0.2s ease;
}
.extras-btn:hover { border-color: #00c8ff; color: #00c8ff; }
.extras-btn.armed {
    border-color: #ffd166;
    color: #ffd166;
    box-shadow: 0 0 10px rgba(255, 209, 102, 0.25);
}
body.board-theme-parchment .extras-btn,
body.board-theme-corkboard .extras-btn { background: rgba(30, 24, 14, 0.85); }

/* Shared extras modal content */
#extras-modal .modal-content { max-width: min(620px, 92vw); }
#extras-modal .modal-body p { line-height: 1.6; }
.extras-note { color: #8fa0b0; font-style: italic; font-size: 0.88rem; }
.extras-conflict { color: #ff7b6b; }
.extras-grade { font-size: 1.15rem; color: #ffd166; }
.extras-modal-btn {
    display: inline-block;
    background: #00c8ff;
    color: #001018;
    border: none;
    border-radius: 8px;
    padding: 0.45rem 1rem;
    margin: 0.25rem 0.4rem 0.8rem 0;
    font-family: inherit;
    font-size: 0.88rem;
    font-weight: bold;
    cursor: pointer;
    transition: filter 0.2s ease;
}
.extras-modal-btn:hover { filter: brightness(1.15); }
.extras-modal-btn.secondary {
    background: transparent;
    color: #9fd8ee;
    border: 1px solid #2a4a5a;
    font-weight: normal;
}
.extras-modal-btn.secondary:hover { border-color: #00c8ff; color: #00c8ff; filter: none; }

/* Suspect cards */
.suspect-sheet {
    border: 1px solid #3a4250;
    border-radius: 10px;
    padding: 0.7rem 0.9rem;
    margin-bottom: 0.7rem;
    background: rgba(16, 19, 28, 0.6);
}
.suspect-sheet h3 { margin: 0 0 0.35rem; font-size: 1rem; color: #ffd166; }
.suspect-sheet p { margin: 0.15rem 0; font-size: 0.86rem; color: #c8d2dc; }

/* Case cabinet rows */
.cabinet-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap;
    border-bottom: 1px dashed rgba(150, 150, 150, 0.2);
    padding: 0.4rem 0;
    font-size: 0.88rem;
}
.cabinet-row span { flex: 1; min-width: 200px; }
.cabinet-row .extras-modal-btn { margin: 0; }

/* Red-herring drawer */
#herring-drawer {
    position: fixed;
    bottom: 12px;
    left: 12px;
    z-index: 30;
    max-width: min(520px, 70vw);
    background: rgba(14, 12, 8, 0.92);
    border: 1px solid #57503f;
    border-radius: 12px;
    padding: 0.45rem 0.7rem;
    display: flex;
    align-items: center;
    gap: 0.45rem;
    flex-wrap: wrap;
}
#herring-drawer[hidden] { display: none; }
.herring-title { color: #d9c58a; font-size: 0.8rem; }
.herring-chip {
    background: rgba(60, 50, 30, 0.7);
    border: 1px solid #7a6a45;
    color: #e8dcc0;
    border-radius: 999px;
    padding: 0.18rem 0.6rem;
    font-family: inherit;
    font-size: 0.75rem;
    cursor: pointer;
    transition: all 0.2s ease;
}
.herring-chip:hover { border-color: #ffd166; color: #ffd166; }

/* Pipe smoke while the board thinks */
#pipe-smoke {
    position: fixed;
    bottom: 18px;
    right: 54px;
    z-index: 28;
    pointer-events: none;
    width: 60px;
    height: 120px;
}
#pipe-smoke[hidden] { display: none; }
#pipe-smoke .pipe { position: absolute; bottom: 0; right: 6px; font-size: 1.5rem; opacity: 0.85; }
#pipe-smoke .puff {
    position: absolute;
    bottom: 26px;
    right: 12px;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: radial-gradient(circle, rgba(220, 220, 230, 0.5), rgba(220, 220, 230, 0));
    animation: puff-rise 3.2s ease-out infinite;
}
#pipe-smoke .p2 { animation-delay: 1.05s; }
#pipe-smoke .p3 { animation-delay: 2.1s; }
@keyframes puff-rise {
    0%   { transform: translate(0, 0) scale(0.6); opacity: 0; }
    18%  { opacity: 0.75; }
    100% { transform: translate(-16px, -86px) scale(2.4); opacity: 0; }
}
@media (prefers-reduced-motion: reduce) {
    #pipe-smoke .puff { animation: none; opacity: 0.4; }
}

/* ==============================================================
   Board chrome — title bar and status bar
   ============================================================== */

#board-titlebar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 42px;
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0 0.9rem;
    background: rgba(12, 12, 14, 0.92);
    border-bottom: 1px solid #2e2e33;
    backdrop-filter: blur(10px);
    z-index: 500;
    font-size: 0.9rem;
    box-sizing: border-box;
}
.tb-brand { color: #e8dcc0; white-space: nowrap; letter-spacing: 0.3px; }
.tb-brand strong { font-weight: bold; }
.tb-menus { display: flex; align-items: center; gap: 0.1rem; min-width: 0; }
.tb-menu { position: relative; }
.tb-menu-btn {
    background: none;
    border: none;
    color: #b8c0ca;
    font-family: inherit;
    font-size: 0.88rem;
    padding: 0.35rem 0.7rem;
    border-radius: 6px;
    cursor: pointer;
    transition: background 0.15s ease, color 0.15s ease;
}
.tb-menu-btn:hover, .tb-menu.open .tb-menu-btn { background: rgba(0, 200, 255, 0.12); color: #dff2fa; }
.tb-dropdown {
    display: none;
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    min-width: 230px;
    background: rgba(16, 18, 24, 0.98);
    border: 1px solid #3a4250;
    border-radius: 10px;
    padding: 0.35rem;
    box-shadow: 0 12px 34px rgba(0, 0, 0, 0.55);
    z-index: 10;
}
.tb-menu.open .tb-dropdown { display: block; animation: tb-drop 0.14s ease; }
@keyframes tb-drop {
    from { opacity: 0; transform: translateY(-5px); }
    to   { opacity: 1; transform: none; }
}
.tb-dropdown button, .tb-dropdown a {
    display: block;
    width: 100%;
    text-align: left;
    background: none;
    border: none;
    color: #cfd6de;
    font-family: inherit;
    font-size: 0.86rem;
    padding: 0.42rem 0.7rem;
    border-radius: 6px;
    cursor: pointer;
    text-decoration: none;
    box-sizing: border-box;
    white-space: nowrap;
}
.tb-dropdown button:hover, .tb-dropdown a:hover { background: rgba(0, 200, 255, 0.13); color: #eaf7fd; }
.tb-dropdown hr { border: none; border-top: 1px solid #2e3540; margin: 0.3rem 0.4rem; }
.tb-right { margin-left: auto; display: flex; align-items: center; gap: 0.5rem; }
#tb-settings {
    background: none;
    border: 1px solid #3a4250;
    border-radius: 8px;
    color: #b8c0ca;
    font-size: 1rem;
    padding: 0.2rem 0.55rem;
    cursor: pointer;
    transition: all 0.2s ease;
}
#tb-settings:hover { border-color: #00c8ff; color: #00c8ff; }
#tb-exit {
    color: #9a9a9a;
    text-decoration: none;
    font-size: 0.85rem;
    border: 1px solid #3a4250;
    border-radius: 8px;
    padding: 0.28rem 0.7rem;
    transition: all 0.2s ease;
    white-space: nowrap;
}
#tb-exit:hover { color: #00c8ff; border-color: #00c8ff; }

#board-statusbar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 30px;
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0 0.9rem;
    background: rgba(12, 12, 14, 0.92);
    border-top: 1px solid #2e2e33;
    backdrop-filter: blur(10px);
    z-index: 500;
    box-sizing: border-box;
}
/* The live message inherits .status-bar; compact it for the bar */
#board-statusbar .status-bar {
    width: auto;
    flex: 1;
    min-width: 0;
    padding-top: 0;
    font-size: 0.8rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.sb-segments {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    flex-shrink: 0;
}
.sb-seg {
    color: #8c96a2;
    font-size: 0.76rem;
    padding: 0.14rem 0.55rem;
    border-left: 1px solid #2e2e33;
    white-space: nowrap;
}
.sb-seg.busy { color: #ffd166; }
/* Relocated indicators, compacted to fit the bar */
#board-statusbar .mode-indicator {
    background: none;
    border: none;
    border-left: 1px solid #2e2e33;
    border-radius: 0;
    margin: 0;
    padding: 0.14rem 0.55rem;
    font-size: 0.76rem;
    min-width: 0;
    color: #8c96a2;
}
#board-statusbar .timer-display {
    background: none !important;
    border: none !important;
    border-left: 1px solid #2e2e33 !important;
    border-radius: 0 !important;
    margin: 0 !important;
    padding: 0.14rem 0.1rem 0.14rem 0.55rem !important;
    font-size: 0.76rem !important;
    color: #8c96a2 !important;
    box-shadow: none !important;
}

/* Make room for the bars */
#controls-panel { top: calc(42px + 0.75rem); }
#top-right-container { top: calc(42px + 0.75rem); }
#game-toolbar { bottom: 44px; }
#timer-container { bottom: 44px; }
#herring-drawer { bottom: 40px; }
#pipe-smoke { bottom: 44px; }

/* Light board themes: keep the dark bars legible as-is (they float above) */

@media (max-width: 760px) {
    #board-titlebar { padding: 0 0.5rem; gap: 0.3rem; }
    .tb-brand strong { display: none; }
    #tb-exit span { display: none; }
    .tb-menu-btn { padding: 0.35rem 0.5rem; }
    #sb-theme, #sb-zoom, #board-statusbar .mode-indicator { display: none; }
}

/* ==============================================================
   Deduction Space — the three-tier neural layer
   ============================================================== */

body.deduction-space-on #canvas-container::after {
    content: '';
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 4;
    background:
        radial-gradient(900px 600px at 50% 40%, rgba(0, 90, 140, 0.10), transparent 65%),
        radial-gradient(closest-side at 50% 50%, transparent 55%, rgba(0, 4, 10, 0.6) 100%);
}

#ds-panel {
    position: fixed;
    top: calc(42px + 0.75rem);
    right: 12px;
    width: min(340px, calc(100vw - 24px));
    max-height: calc(100vh - 110px);
    overflow-y: auto;
    background: rgba(10, 14, 20, 0.94);
    border: 1px solid #2a4a5a;
    border-radius: 14px;
    padding: 0.9rem 1rem 1.1rem;
    z-index: 45;
    backdrop-filter: blur(10px);
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5);
}
#ds-panel[hidden] { display: none; }
.ds-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 0.4rem; }
.ds-head strong { color: #dff2fa; font-size: 0.98rem; }
.ds-close {
    background: none; border: none; color: #8c96a2;
    font-size: 1.3rem; line-height: 1; cursor: pointer; padding: 0 0.2rem;
}
.ds-close:hover { color: #ff6b6b; }
.ds-note { color: #8fa0b0; font-size: 0.8rem; line-height: 1.5; margin: 0 0 0.7rem; }
.ds-actions { display: flex; gap: 0.4rem; margin-bottom: 0.8rem; flex-wrap: wrap; }

.ds-verdict {
    border: 1px solid rgba(255, 196, 92, 0.5);
    background: rgba(255, 196, 92, 0.08);
    border-radius: 12px;
    padding: 0.7rem 0.85rem;
    margin-bottom: 0.9rem;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}
.ds-verdict[hidden] { display: none; }
.ds-verdict-label {
    font-size: 0.68rem; letter-spacing: 0.09em; text-transform: uppercase; color: #ffc45c;
}
.ds-verdict strong { color: #ffd98a; font-size: 1.02rem; line-height: 1.35; }
.ds-coherence { font-size: 0.74rem; color: #8fa0b0; }

.ds-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 0.5rem; }
.ds-item {
    border-left: 3px solid #2a4a5a;
    background: rgba(255, 255, 255, 0.035);
    border-radius: 0 10px 10px 0;
    padding: 0.55rem 0.7rem;
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
}
.ds-item.ok { border-left-color: #00d2ff; }
.ds-item.weak { border-left-color: #ff4678; }
.ds-item strong { font-size: 0.9rem; color: #e6eef5; line-height: 1.35; }
.ds-why { font-size: 0.78rem; color: #8fa0b0; line-height: 1.5; }
.ds-switch { align-self: flex-start; font-size: 0.72rem !important; padding: 0.2rem 0.55rem !important; }

@media (max-width: 760px) {
    #ds-panel { top: auto; bottom: 44px; right: 6px; left: 6px; width: auto; max-height: 46vh; }
}

/* Right-click context menu — dark, high-contrast, readable */
#board-context-menu {
    position: fixed;
    z-index: 900;
    min-width: 210px;
    background: #10151d;
    border: 1px solid #3a4a5c;
    border-radius: 12px;
    padding: 0.3rem;
    box-shadow: 0 14px 44px rgba(0, 0, 0, 0.65);
    animation: ctx-in 0.12s ease;
}
#board-context-menu button {
    display: flex;
    align-items: center;
    gap: 0.55rem;
    width: 100%;
    background: none;
    border: none;
    color: #e8eef4;               /* 13.9:1 on #10151d */
    font-family: Georgia, serif;
    font-size: 0.92rem;
    text-align: left;
    padding: 0.5rem 0.7rem;
    border-radius: 8px;
    cursor: pointer;
}
#board-context-menu button:hover,
#board-context-menu button:focus-visible {
    background: rgba(0, 200, 255, 0.16);
    color: #ffffff;
    outline: none;
}
#board-context-menu button span { width: 1.2rem; text-align: center; }
@keyframes ctx-in { from { opacity: 0; transform: scale(0.96); } to { opacity: 1; } }
@media (prefers-reduced-motion: reduce) { #board-context-menu { animation: none; } }

/* ==============================================================
   Dialog contrast fixes (WCAG AA sweep, 2026-07-26)
   Every override lifts a measured failure to 4.5:1 or better.
   ============================================================== */
.panel-controls button { color: #c8d2dc; }               /* was #667 · 3.1:1 */
.panel-controls button:hover { color: #ffffff; }
.chat-input-form button {
    background: #00c8ff;                                  /* white-on-blue was 3.9:1 */
    color: #001018;                                       /* now 8.6:1 */
    font-weight: bold;
}
.premium-badge {
    background: #ffd166;                                  /* dark-on-dark was 1.4:1 */
    color: #2b2013;                                       /* now 9.7:1 */
}
.primary-button { background: #00c8ff; color: #001018; font-weight: bold; }
.help-step-number { background: #00c8ff; color: #001018; }
.help-toolbar-icon { color: #ffffff; }
.log-placeholder { color: #9aa3b2; }                      /* was #666 · 3.0:1 */
#technique-hint-close { color: #b8c2cc; }                 /* was #667 · 3.1:1 */
#technique-hint-close:hover { color: #ffffff; }
.help-toolbar-icon { background: #1d4f8a; }               /* #4a90e2 chip washed out white text */
.state-empty { color: #9aa3b2; }                          /* was #666 */

/* Title-bar theme menu (🎨 before Settings) */
.tb-dropdown-right { left: auto; right: 0; min-width: 170px; }
.tb-theme-menu .tb-menu-btn { font-size: 1rem; padding: 0.3rem 0.55rem; }
.tb-dropdown [data-theme]::before {
    content: '';
    display: inline-block;
    width: 1.1rem;
}
.tb-dropdown [data-theme].is-current::before { content: '✓'; color: #00c8ff; }

/* Tooltips yield to the context menu — even if a mousemove re-shows them */
body.ctx-menu-open #clue-tooltip,
body.ctx-menu-open #char-tooltip { display: none !important; }

/* ==============================================================
   Modal revamp — one dialog language for every board window.
   Dark surface, clear hierarchy, explicit input colors (no more
   black-on-gray), visible focus. Overrides the older per-modal
   styling by arriving later in the sheet.
   ============================================================== */

.modal-overlay { background: rgba(2, 4, 8, 0.72); backdrop-filter: blur(6px); }

.modal-content {
    background: linear-gradient(180deg, #161b24 0%, #10141c 100%);
    border: 1px solid #34404f;
    border-radius: 16px;
    box-shadow: 0 24px 70px rgba(0, 0, 0, 0.65), 0 0 0 1px rgba(0, 200, 255, 0.06);
    color: #e6ecf2;                               /* base text: 12.9:1 */
}
.modal-content h2, .modal-content .modal-title {
    color: #f2f6fa;
    letter-spacing: 0.01em;
}
.modal-content h3 { color: #dfe7ee; }
.modal-content p, .modal-content li, .modal-content label { color: #cfd8e0; }  /* 9.9:1 */
.modal-content .setting-hint, .modal-content small { color: #9fabb8; }         /* 5.6:1 */

/* Inputs: explicit surface + ink, never inherited grays */
.modal-content input[type="text"],
.modal-content input[type="password"],
.modal-content input[type="number"],
.modal-content input[type="search"],
.modal-content textarea,
.modal-content select {
    background: #0b0f15;
    color: #eef3f7;                                /* 15.4:1 on the field */
    border: 1px solid #3a4756;
    border-radius: 10px;
    padding: 0.55rem 0.75rem;
    font-family: inherit;
    font-size: 0.95rem;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.modal-content input::placeholder,
.modal-content textarea::placeholder { color: #8b97a4; opacity: 1; }  /* 4.6:1 */
.modal-content input:focus,
.modal-content textarea:focus,
.modal-content select:focus {
    outline: none;
    border-color: #00c8ff;
    box-shadow: 0 0 0 3px rgba(0, 200, 255, 0.22);
}
.modal-content select option { background: #0b0f15; color: #eef3f7; }

/* Buttons: one primary voice, one quiet voice */
.modal-content button:not(.modal-close):not(.tts-button):not(.extras-btn):not(.ds-switch) {
    border-radius: 10px;
    font-family: inherit;
    cursor: pointer;
    transition: filter 0.15s ease, border-color 0.15s ease;
}
.modal-content .primary-button,
.modal-content button[type="submit"],
.modal-content .add-btn {
    background: #00c8ff;
    color: #001018;
    border: none;
    font-weight: 700;
    padding: 0.55rem 1.2rem;
}
.modal-content .primary-button:hover,
.modal-content .add-btn:hover { filter: brightness(1.12); }
.modal-content .modal-close {
    color: #b7c2cc;
    font-size: 1.5rem;
    transition: color 0.15s ease, transform 0.15s ease;
}
.modal-content .modal-close:hover { color: #ffffff; transform: scale(1.12); }

/* Section rhythm inside dialogs */
.modal-content .modal-body { line-height: 1.6; }
.modal-content .settings-group {
    border: 1px solid #2a3542;
    border-radius: 12px;
    padding: 0.9rem 1.1rem;
    margin-bottom: 1rem;
    background: rgba(255, 255, 255, 0.02);
}
.modal-content .settings-group h3 { margin-top: 0; }

/* The premium gradient panel: readable ink on its light gradient */
.premium-section { color: #10141c; }
.premium-section h3, .premium-section .premium-feature-name { color: #0c1016; }
.premium-section .premium-description { color: #1d2531; }

/* Suggestion cards (Feeling Lucky) and character editors share the surface */
.suggestion-card {
    background: #0e131b;
    border: 1px solid #34404f;
    border-radius: 12px;
    color: #e6ecf2;
}
.suggestion-card h3 { color: #f2f6fa; }
.suggestion-card p { color: #cfd8e0; }

/* Premium gradient section: rows sit on their own dark cards */
.premium-section h3 { color: #ffffff; text-shadow: 0 1px 3px rgba(0,0,0,0.55); }
.premium-section .premium-feature {
    background: rgba(10, 14, 20, 0.82);
    border-radius: 10px;
    padding: 0.6rem 0.8rem;
    margin-bottom: 0.6rem;
}
.premium-section .premium-feature-name { color: #f2f6fa; }
.premium-section .premium-description { color: #c6d0da; }

/* ==========================================================================
   Case Files, Reasoning panel, Evidence editor, Sketch layer
   ========================================================================== */

/* Menu keyboard hints */
.tb-dropdown .tb-key { margin-left: auto; padding-left: 1.2rem; opacity: 0.5; font-size: 0.72rem; }
.tb-dropdown button[disabled] { opacity: 0.4; cursor: default; }

/* --------------------------- Case Files dialog -------------------------- */
.casefiles-modal { width: min(680px, 94vw); max-height: 84vh; display: flex; flex-direction: column; }
.casefiles-body { overflow-y: auto; }
.cf-tabs { display: flex; gap: 0.4rem; margin-bottom: 0.9rem; }
.cf-tab {
    background: none; border: 1px solid var(--panel-border, #333); color: inherit;
    border-radius: 8px; padding: 0.4rem 0.9rem; cursor: pointer; font: inherit; opacity: 0.75;
}
.cf-tab.active { border-color: #00c8ff; color: #00c8ff; opacity: 1; }
.cf-actionbar { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-bottom: 1rem; }
.cf-btn {
    background: rgba(0, 200, 255, 0.12); border: 1px solid #00c8ff; color: #9fe4ff;
    border-radius: 8px; padding: 0.38rem 0.8rem; cursor: pointer; font: inherit; font-size: 0.86rem;
}
.cf-btn:hover { background: rgba(0, 200, 255, 0.22); }
.cf-btn.primary { background: #00c8ff; color: #04121a; font-weight: bold; }
.cf-btn.ghost { background: none; border-color: #3a4652; color: #aab8c5; }
.cf-btn.ghost:hover { border-color: #00c8ff; color: #00c8ff; background: none; }
.cf-btn.ghost.danger:hover { border-color: #ff6b6b; color: #ff6b6b; }
.cf-empty { color: #93a1af; font-style: italic; }
.cf-row {
    display: flex; align-items: center; gap: 0.8rem;
    border: 1px solid #2b3540; border-radius: 10px; padding: 0.55rem 0.7rem; margin-bottom: 0.55rem;
    background: rgba(255, 255, 255, 0.02);
}
.cf-row.current { border-color: #00c8ff; }
.cf-thumb {
    flex: none; width: 76px; height: 48px; border-radius: 6px; overflow: hidden;
    background: #10161d; display: flex; align-items: center; justify-content: center; font-size: 1.3rem;
}
.cf-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.cf-info { min-width: 0; flex: 1; display: flex; flex-direction: column; gap: 0.1rem; }
.cf-info strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cf-meta { color: #8fa0af; font-size: 0.76rem; }
.cf-rowactions { display: flex; gap: 0.35rem; flex: none; }
.cf-daily {
    border: 1px solid #ffd166; border-radius: 12px; padding: 0.8rem 1rem; margin-bottom: 1rem;
    background: rgba(255, 209, 102, 0.07); display: flex; flex-direction: column; gap: 0.35rem;
    align-items: flex-start;
}
.cf-daily-label { color: #ffd166; font-size: 0.7rem; letter-spacing: 2px; }
.cf-daily p { margin: 0; color: #c9d4dd; font-size: 0.9rem; }
.cf-share-url {
    width: 100%; box-sizing: border-box; margin: 0.6rem 0;
    background: #10161d; border: 1px solid #2b3540; color: #d7e2ea;
    border-radius: 8px; padding: 0.55rem 0.7rem; font-family: monospace; font-size: 0.85rem;
}

/* ------------------------- Reasoning / tension panel --------------------- */
#reason-panel {
    position: fixed; top: 64px; right: 14px; z-index: 320;
    width: min(360px, calc(100vw - 28px)); max-height: calc(100vh - 120px);
    background: rgba(16, 22, 29, 0.97); border: 1px solid #2b3540; border-radius: 12px;
    display: flex; flex-direction: column; box-shadow: 0 18px 50px rgba(0, 0, 0, 0.55);
    color: #dbe5ec;
}
.reason-head {
    display: flex; align-items: center; justify-content: space-between;
    padding: 0.65rem 0.9rem; border-bottom: 1px solid #2b3540; color: #ffd166;
}
.reason-close { background: none; border: 1px solid #3a4652; color: #aab8c5; border-radius: 6px; cursor: pointer; padding: 0.15rem 0.5rem; }
.reason-close:hover { color: #ff6b6b; border-color: #ff6b6b; }
.reason-body { padding: 0.8rem 0.95rem; overflow-y: auto; }
.reason-verdict { margin: 0 0 0.7rem; font-weight: bold; line-height: 1.5; }
.reason-steps { margin: 0; padding-left: 1.25rem; display: flex; flex-direction: column; gap: 0.55rem; }
.reason-steps li { line-height: 1.5; cursor: default; border-radius: 6px; padding: 0.2rem 0.35rem; font-size: 0.92rem; }
.reason-steps li:hover { background: rgba(255, 209, 102, 0.1); }
.reason-refs { display: block; color: #ffd166; font-size: 0.74rem; letter-spacing: 1px; margin-top: 0.15rem; }
.reason-hint, .reason-weights { color: #93a1af; font-size: 0.8rem; font-style: italic; margin: 0.8rem 0 0; }
.reason-fallback { line-height: 1.6; color: #c9d4dd; }
.tension-card {
    border: 1px solid rgba(255, 107, 107, 0.5); border-radius: 10px;
    padding: 0.6rem 0.75rem; margin-bottom: 0.7rem; background: rgba(255, 107, 107, 0.06);
}
.tension-card strong { display: block; margin-bottom: 0.3rem; color: #ffb0a0; font-size: 0.9rem; }
.tension-card p { margin: 0 0 0.4rem; font-size: 0.86rem; line-height: 1.5; }
.tension-resolution { color: #93a1af; font-style: italic; }
.tension-actions { display: flex; flex-wrap: wrap; gap: 0.35rem; }

/* --------------------------- Evidence editor ---------------------------- */
.evidence-modal { width: min(430px, 92vw); }
.evidence-clue { color: #c9d4dd; margin: 0.2rem 0 0.9rem; font-style: italic; }
.evidence-kinds { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0.45rem; margin-bottom: 1rem; }
.evidence-kind {
    background: rgba(255, 255, 255, 0.03); border: 1px solid #2b3540; color: #c9d4dd;
    border-radius: 9px; padding: 0.5rem 0.3rem; cursor: pointer; font: inherit; font-size: 0.8rem;
    display: flex; flex-direction: column; align-items: center; gap: 0.2rem;
}
.evidence-kind span { font-size: 1.15rem; }
.evidence-kind:hover { border-color: #00c8ff; }
.evidence-kind.active { border-color: #00c8ff; background: rgba(0, 200, 255, 0.14); color: #9fe4ff; }
.evidence-weights { display: flex; align-items: center; flex-wrap: wrap; gap: 0.45rem; margin-bottom: 0.8rem; color: #93a1af; font-size: 0.85rem; }
.evidence-weight {
    background: none; border: 1px solid #2b3540; color: #c9d4dd; border-radius: 8px;
    padding: 0.32rem 0.6rem; cursor: pointer; font: inherit; font-size: 0.8rem;
}
.evidence-weight:hover { border-color: #ffd166; }
.evidence-weight.active { border-color: #ffd166; color: #ffd166; background: rgba(255, 209, 102, 0.1); }
.evidence-note { color: #8fa0af; font-size: 0.78rem; font-style: italic; margin: 0; }

/* ----------------------------- Note editor ------------------------------ */
#note-editor {
    position: fixed; z-index: 340; width: 220px;
    background: #f6e27a; border: 1px solid #c9b23e; border-radius: 8px;
    box-shadow: 0 14px 34px rgba(0, 0, 0, 0.45); padding: 8px;
}
#note-editor textarea {
    width: 100%; box-sizing: border-box; height: 74px; resize: none;
    background: transparent; border: none; outline: none; color: #33270a;
    font-family: inherit; font-size: 0.85rem; line-height: 1.4;
}
.note-editor-row { display: flex; gap: 0.3rem; justify-content: flex-end; }
.note-editor-row button {
    background: #33270a; color: #f6e27a; border: none; border-radius: 6px;
    padding: 0.25rem 0.6rem; cursor: pointer; font: inherit; font-size: 0.76rem;
}
.note-editor-row button.ghost { background: none; color: #6b5a1e; }
.note-editor-row button.danger { background: #a33b20; color: #fdf0e0; }
