/* Extracted and theme-aware styles for the game-master webapp. */

/* === Base === */

body {
    font-family: var(--font-body);
    font-size: 1.05rem;
    background-color: var(--bg-primary);
    color: var(--text-primary);
}

/* Subtle background texture */
body::before {
    content: '';
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 0;
    background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='1'/%3E%3C/svg%3E");
    opacity: var(--noise-opacity);
}

/* === Prose (markdown content) === */

.prose h1 { font-family: var(--font-display); font-size: 1.75rem; font-weight: 700; margin: 1rem 0 0.5rem; color: var(--text-primary); }
.prose h2 { font-family: var(--font-display); font-size: 1.4rem; font-weight: 600; margin: 0.75rem 0 0.5rem; color: var(--text-primary); }
.prose h3 { font-family: var(--font-display); font-size: 1.2rem; font-weight: 600; margin: 0.5rem 0 0.25rem; color: var(--text-primary); }
.prose p { margin: 0.5rem 0; }
.prose ul { list-style: disc; padding-left: 1.5rem; margin: 0.5rem 0; }
.prose ol { list-style: decimal; padding-left: 1.5rem; margin: 0.5rem 0; }
.prose li { margin: 0.15rem 0; }
.prose code {
    background: var(--accent-muted);
    padding: 0.1rem 0.3rem;
    border-radius: 0.25rem;
    font-size: 0.9em;
}
.prose pre {
    position: relative;
    background: var(--code-block-bg);
    color: var(--code-block-text);
    padding: 1rem;
    border-radius: 0.5rem;
    overflow-x: auto;
    margin: 0.75rem 0;
    border: 1px solid var(--border-primary);
}
.prose pre code {
    background: none;
    padding: 0;
    font-family: 'Courier New', monospace;
}
.prose blockquote {
    border-left: 3px solid var(--text-muted);
    padding-left: 1rem;
    margin: 0.5rem 0;
    color: var(--text-secondary);
}
.prose strong { font-weight: 600; }
.prose em { font-style: italic; }
.prose hr { border-color: var(--border-primary); margin: 1rem 0; }
.prose a { color: var(--accent-primary); text-decoration: underline; }
.prose table { border-collapse: collapse; margin: 0.5rem 0; }
.prose th, .prose td { border: 1px solid var(--border-primary); padding: 0.35rem 0.75rem; }
.prose th { background: var(--accent-muted); font-weight: 600; }

/* === Chat === */

.typing-cursor::after {
    content: "\25AE";
    animation: blink 0.8s step-end infinite;
    color: var(--text-muted);
    margin-left: 2px;
}
@keyframes blink { 50% { opacity: 0; } }

/* Textarea auto-expand */
#chat-input {
    min-height: 44px;
    max-height: 200px;
    resize: none;
    overflow-y: hidden;
    transition: height 0.1s ease;
    line-height: 1.5;
    font-family: var(--font-body);
}
#chat-input::placeholder {
    color: var(--text-muted);
}
#chat-input:focus {
    border-color: var(--accent-primary) !important;
    box-shadow: 0 0 0 2px var(--ring-color);
}

/* === Copy Buttons === */

.copy-msg-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 1.5rem;
    height: 1.5rem;
    cursor: pointer;
    background: none;
    color: var(--text-muted);
    border: none;
    border-radius: 0.25rem;
    padding: 0;
    opacity: 0.4;
    transition: opacity 0.15s ease, color 0.15s ease;
}
.copy-msg-btn:hover {
    opacity: 1;
    color: var(--accent-primary);
}
.copy-msg-btn svg {
    width: 0.875rem;
    height: 0.875rem;
}

.copy-code-btn {
    opacity: 0;
    transition: opacity 0.15s ease, background-color 0.15s ease;
    cursor: pointer;
    background: var(--bg-surface);
    color: var(--text-muted);
    border: 1px solid var(--border-primary);
    border-radius: 0.375rem;
    padding: 0.25rem 0.5rem;
    font-size: 0.75rem;
    line-height: 1;
}
.copy-code-btn:hover {
    opacity: 1 !important;
    color: var(--accent-primary);
    border-color: var(--accent-primary);
    box-shadow: var(--shadow-glow);
}

/* Show code copy button on hover */
.prose pre:hover .copy-code-btn {
    opacity: 0.7;
}

/* === Snip Float Button === */

.snip-float-btn {
    display: none;
    align-items: center;
    justify-content: center;
    position: fixed;
    width: 1.75rem;
    height: 1.75rem;
    border-radius: 0.375rem;
    border: 1px solid var(--border-primary);
    background: var(--bg-surface);
    color: var(--text-secondary);
    cursor: pointer;
    z-index: 50;
    padding: 0;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
    transition: color 0.15s ease, border-color 0.15s ease;
}
.snip-float-btn:hover {
    color: var(--accent-primary);
    border-color: var(--accent-primary);
}
.snip-float-btn svg {
    width: 0.875rem;
    height: 0.875rem;
}

/* === TTS Button === */

.tts-msg-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 1.5rem;
    height: 1.5rem;
    cursor: pointer;
    background: none;
    color: var(--text-muted);
    border: none;
    border-radius: 0.25rem;
    padding: 0;
    opacity: 0.4;
    transition: opacity 0.15s ease, color 0.15s ease;
}
.tts-msg-btn:hover {
    opacity: 1;
    color: var(--accent-primary);
}
.tts-msg-btn--active {
    opacity: 1;
    color: var(--accent-primary);
}
.tts-msg-btn svg {
    width: 0.875rem;
    height: 0.875rem;
}

/* === Tool Call Elements === */

.tool-call {
    margin: 0.5rem 0;
    border: 1px solid var(--border-primary);
    border-radius: 0.5rem;
    background: var(--code-block-bg);
    font-size: 0.85rem;
    overflow: hidden;
}

.tool-call--game {
    border-color: var(--accent-primary);
}

.tool-call--image {
    border-color: var(--accent-secondary, var(--text-muted));
}

.tool-call__summary {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.4rem 0.75rem;
    cursor: pointer;
    color: var(--text-secondary);
    list-style: none;
    user-select: none;
}

.tool-call__summary::-webkit-details-marker {
    display: none;
}

.tool-call__summary::before {
    content: "\25B6";
    font-size: 0.6em;
    transition: transform 0.15s ease;
    flex-shrink: 0;
}

.tool-call[open] > .tool-call__summary::before {
    transform: rotate(90deg);
}

.tool-call__label {
    font-weight: 600;
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
}

.tool-call--game .tool-call__label {
    color: var(--accent-primary);
}

.tool-call--image .tool-call__label {
    color: var(--accent-secondary, var(--text-muted));
}

.tool-call__name {
    font-family: 'Courier New', monospace;
    font-size: 0.85em;
    color: var(--text-primary);
    background: none;
    padding: 0;
}

.tool-call__params {
    padding: 0.4rem 0.75rem 0.5rem;
    border-top: 1px solid var(--border-primary);
}

.tool-call__param {
    display: flex;
    gap: 0.5rem;
    padding: 0.1rem 0;
    font-family: 'Courier New', monospace;
    font-size: 0.8em;
}

.tool-call__key {
    color: var(--text-muted);
    flex-shrink: 0;
}

.tool-call__key::after {
    content: ":";
}

.tool-call__val {
    color: var(--text-secondary);
    word-break: break-all;
}

.tool-call__result {
    padding: 0.4rem 0.75rem 0.5rem;
    border-top: 1px solid var(--border-primary);
    font-family: 'Courier New', monospace;
    font-size: 0.8em;
    white-space: pre-wrap;
    color: var(--text-muted);
}

.tool-call__image {
    padding: 0.25rem 0;
}

.tool-call__image img {
    max-width: 100%;
    border-radius: 0.375rem;
    display: block;
}

/* === Toast Notification === */

.toast {
    position: fixed;
    bottom: 5rem;
    left: 50%;
    transform: translateX(-50%) translateY(1rem);
    background: var(--toast-bg);
    color: var(--toast-text);
    border: 1px solid var(--toast-border);
    padding: 0.5rem 1rem;
    border-radius: 0.5rem;
    font-size: 0.85rem;
    box-shadow: var(--shadow-glow);
    opacity: 0;
    transition: opacity 0.2s ease, transform 0.2s ease;
    pointer-events: none;
    z-index: 50;
}
.toast.visible {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

/* === Processing Indicator === */

.processing-indicator {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    animation: fadeIn 0.3s ease;
}
.processing-spinner {
    width: 1.25rem;
    height: 1.25rem;
    border: 2px solid var(--border-primary);
    border-top-color: var(--accent-primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    flex-shrink: 0;
}
.processing-text {
    font-style: italic;
    color: var(--text-muted);
    font-size: 0.875rem;
}

@keyframes spin { to { transform: rotate(360deg); } }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

/* Drop overlay anchor — absolute-positioned overlay needs a positioned parent */
#main-content {
    position: relative;
}

/* === Attach Button === */

.attach-btn {
    width: 44px;
    height: 44px;
    flex-shrink: 0;
    background: var(--bg-surface);
    color: var(--text-secondary);
    border: 1px solid var(--border-primary);
    cursor: pointer;
    position: relative;
}
.attach-btn:hover {
    color: var(--accent-primary);
    border-color: var(--accent-primary);
    box-shadow: var(--shadow-glow);
}
.attach-btn.has-files {
    color: var(--accent-primary);
    border-color: var(--accent-primary);
}

/* === Attachment Chips === */

.attachment-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
    padding: 0.4rem 0;
    animation: fadeIn 0.2s ease;
}

.attachment-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.25rem 0.5rem 0.25rem 0.6rem;
    font-size: 0.78rem;
    font-family: var(--font-body);
    color: var(--text-secondary);
    background: var(--bg-surface);
    border: 1px solid var(--border-primary);
    border-radius: 9999px;
    max-width: 220px;
    animation: fadeIn 0.2s ease;
}
.attachment-chip__name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.attachment-chip__size {
    font-size: 0.65rem;
    color: var(--text-muted);
    flex-shrink: 0;
}
.attachment-chip__remove {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 1rem;
    height: 1rem;
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    border-radius: 50%;
    flex-shrink: 0;
    padding: 0;
    font-size: 0.9rem;
    line-height: 1;
    transition: color 0.12s ease, background 0.12s ease;
}
.attachment-chip__remove:hover {
    color: var(--danger);
    background: rgba(239, 68, 68, 0.1);
}
.attachment-chip--uploading {
    opacity: 0.6;
}
.attachment-chip--error {
    border-color: var(--danger);
    color: var(--danger);
}

/* === Drop Zone Overlay === */

.drop-overlay {
    position: absolute;
    inset: 0;
    z-index: 30;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    border: 3px dashed var(--accent-primary);
    border-radius: 0.5rem;
    pointer-events: none;
    animation: fadeIn 0.15s ease;
}
.drop-overlay__content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.75rem;
    color: var(--accent-primary);
    font-family: var(--font-display);
    font-size: 1.1rem;
    font-weight: 600;
    letter-spacing: 0.03em;
}

/* === Send Button === */

#send-btn {
    width: 44px;
    height: 44px;
    flex-shrink: 0;
}
#send-btn:hover {
    background: var(--accent-hover) !important;
}

/* === Stop Button === */

.stop-btn {
    width: 44px;
    height: 44px;
    flex-shrink: 0;
    background: var(--danger);
    color: white;
    transition: background-color 0.15s ease;
}
.stop-btn:hover {
    background: var(--danger-hover);
}

/* === Mic Button === */

.mic-btn {
    width: 44px;
    height: 44px;
    flex-shrink: 0;
    background: var(--bg-surface);
    color: var(--text-secondary);
    border: 1px solid var(--border-primary);
    position: relative;
    cursor: pointer;
}
.mic-btn:hover {
    color: var(--accent-primary);
    border-color: var(--accent-primary);
    box-shadow: var(--shadow-glow);
}
.mic-btn.listening {
    color: #ef4444;
    border-color: #ef4444;
    background: rgba(239, 68, 68, 0.08);
    box-shadow: 0 0 16px rgba(239, 68, 68, 0.15);
}
.mic-btn.listening:hover {
    color: #f87171;
    border-color: #f87171;
}

.mic-recording-dot {
    position: absolute;
    top: 5px;
    right: 5px;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #ef4444;
    animation: micPulse 1.2s ease-in-out infinite;
}

@keyframes micPulse {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.4; transform: scale(1.4); }
}

/* === Realtime Capture === */

.realtime-bar {
    padding-top: 0.5rem;
}

.realtime-bar__inner {
    display: grid;
    grid-template-columns: 32px auto minmax(0, 1fr) auto;
    align-items: center;
    gap: 0.55rem;
    min-height: 36px;
    padding: 0.35rem 0.5rem;
    background: var(--bg-surface);
    border: 1px solid var(--border-primary);
    border-radius: 0.5rem;
}

.realtime-capture-btn {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    flex-shrink: 0;
    color: var(--text-secondary);
    background: var(--bg-input);
    border: 1px solid var(--border-primary);
    border-radius: 0.45rem;
    cursor: pointer;
    transition: color 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}

.realtime-capture-btn:hover {
    color: var(--accent-primary);
    border-color: var(--accent-primary);
    box-shadow: var(--shadow-glow);
}

.realtime-capture-btn.capturing {
    color: #ef4444;
    border-color: #ef4444;
    background: rgba(239, 68, 68, 0.08);
}

.realtime-capture-btn.paused {
    color: var(--accent-primary);
    border-color: var(--accent-primary);
}

.realtime-capture-dot {
    position: absolute;
    top: 4px;
    right: 4px;
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #ef4444;
    animation: micPulse 1.2s ease-in-out infinite;
}

.realtime-status {
    min-width: 4.5rem;
    font-size: 0.78rem;
    color: var(--text-secondary);
    white-space: nowrap;
}

.realtime-preview {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 0.78rem;
    color: var(--text-muted);
}

.realtime-transcript-toggle {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    min-height: 28px;
    padding: 0 0.45rem;
    font-size: 0.78rem;
    color: var(--text-secondary);
    border: 1px solid var(--border-primary);
    border-radius: 0.45rem;
    cursor: pointer;
    white-space: nowrap;
}

.realtime-transcript-toggle:has(input:checked) {
    color: var(--accent-primary);
    border-color: var(--accent-primary);
    background: var(--accent-muted);
}

.realtime-transcript-toggle input {
    width: 0.9rem;
    height: 0.9rem;
    accent-color: var(--accent-primary);
}

@media (max-width: 640px) {
    .realtime-bar__inner {
        grid-template-columns: 32px auto 1fr;
    }

    .realtime-preview {
        display: none;
    }

    .realtime-transcript-toggle {
        grid-column: 1 / -1;
        width: fit-content;
    }
}

/* === Header Buttons === */

.new-chat-btn,
.export-btn {
    color: var(--text-muted);
    transition: color 0.15s ease;
    background: none;
    border: none;
    cursor: pointer;
    padding: 0.25rem;
    display: flex;
    align-items: center;
}
.new-chat-btn:hover,
.export-btn:hover {
    color: var(--accent-primary);
}

/* === Suggestion Chips === */

.suggestion-chip {
    padding: 0.5rem 1rem;
    font-size: 0.85rem;
    font-family: var(--font-body);
    color: var(--text-secondary);
    background: var(--bg-surface);
    border: 1px solid var(--border-primary);
    border-radius: 9999px;
    cursor: pointer;
    transition: all 0.15s ease;
}
.suggestion-chip:hover {
    color: var(--accent-primary);
    border-color: var(--accent-primary);
    background: var(--accent-muted);
    box-shadow: var(--shadow-glow);
    transform: translateY(-1px);
}
.suggestion-chip:active {
    transform: translateY(0) scale(0.98);
    transition-duration: 80ms;
}

/* Dynamic suggestion bar above the input */
.suggestions-bar {
    display: flex;
    justify-content: center;
    flex-wrap: wrap;
    gap: 0.5rem;
    padding: 0.5rem 0;
    animation: fadeIn 0.3s ease;
}

/* === Theme Picker === */

.theme-select {
    background: var(--bg-input);
    color: var(--text-secondary);
    border: 1px solid var(--border-input);
    border-radius: 0.375rem;
    padding: 0.25rem 0.5rem;
    font-size: 0.8rem;
    font-family: var(--font-body);
    cursor: pointer;
}
.theme-select:focus {
    outline: none;
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 2px var(--ring-color);
}

/* === Sidebar Toggle Button === */

.sidebar-toggle-btn {
    color: var(--text-muted);
    transition: color 0.15s ease;
    background: none;
    border: none;
    cursor: pointer;
    padding: 0.25rem;
    display: flex;
    align-items: center;
}
.sidebar-toggle-btn:hover {
    color: var(--accent-primary);
}

/* === Sidebar === */

.sidebar {
    --sidebar-w: 340px;
    width: var(--sidebar-w);
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    background: var(--sidebar-bg);
    border-right: 1px solid var(--border-primary);
    transition: margin-left 0.28s cubic-bezier(0.4, 0, 0.2, 1),
                opacity 0.28s ease;
    overflow: visible;
    z-index: 20;
    position: relative;
}

.sidebar--closed {
    margin-left: calc(-1 * var(--sidebar-w));
    opacity: 0;
    pointer-events: none;
}

/* Resize handle */
.sidebar__resize-handle {
    position: absolute;
    top: 0;
    right: -3px;
    bottom: 0;
    width: 6px;
    cursor: col-resize;
    z-index: 25;
    transition: background 0.15s ease;
    touch-action: none;
}
.sidebar__resize-handle:hover,
.sidebar__resize-handle--active {
    background: var(--accent-primary);
    opacity: 0.4;
}

.sidebar-backdrop {
    display: none;
}

/* Mobile: overlay mode */
@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        --sidebar-w: min(300px, 85vw);
        width: var(--sidebar-w);
        z-index: 50;
        margin-left: 0;
        transition: transform 0.28s cubic-bezier(0.4, 0, 0.2, 1),
                    opacity 0.28s ease;
    }
    .sidebar--closed {
        transform: translateX(-100%);
        margin-left: 0;
        opacity: 0;
    }
    .sidebar__resize-handle {
        display: none;
    }
    .sidebar-backdrop {
        display: block;
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, 0.5);
        z-index: 45;
        opacity: 0;
        pointer-events: none;
        transition: opacity 0.28s ease;
    }
    .sidebar-backdrop--visible {
        opacity: 1;
        pointer-events: auto;
    }
}

/* Sidebar header */
.sidebar__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 0.75rem;
    height: 3.5rem;
    flex-shrink: 0;
    background: var(--sidebar-header-bg);
    border-bottom: 1px solid var(--border-primary);
}

.sidebar__title {
    font-family: var(--font-display);
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--accent-primary);
    letter-spacing: 0.06em;
    text-transform: uppercase;
}

.sidebar__close-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 0.25rem;
    display: flex;
    align-items: center;
    transition: color 0.15s ease;
}
.sidebar__close-btn:hover {
    color: var(--text-primary);
}

/* Campaign info */
.sidebar__campaign {
    padding: 0.6rem 0.75rem;
    border-bottom: 1px solid var(--sidebar-divider);
    flex-shrink: 0;
}
.sidebar__campaign-name {
    font-family: var(--font-display);
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text-primary);
    line-height: 1.3;
}
.sidebar__campaign-ruleset {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 0.1rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}
.sidebar__no-campaign {
    font-size: 0.85rem;
    color: var(--text-muted);
    font-style: italic;
}
.sidebar__mode {
    padding: 0.35rem 0.75rem;
    border-bottom: 1px solid var(--sidebar-divider);
}
.sidebar__mode-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}
.sidebar__mode-label {
    font-size: 0.7rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    flex-shrink: 0;
}
.sidebar__mode-select {
    background: var(--bg-input);
    color: var(--text-secondary);
    border: 1px solid var(--border-input);
    border-radius: 0.375rem;
    padding: 0.15rem 0.35rem;
    font-size: 0.75rem;
    font-family: var(--font-body);
    cursor: pointer;
    flex: 1;
    min-width: 0;
}
.sidebar__mode-select:focus {
    outline: none;
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 2px var(--ring-color);
}
.sidebar__mode-toggles {
    display: flex;
    gap: 0.75rem;
    margin-top: 0.3rem;
}
.sidebar__toggle {
    font-size: 0.7rem;
    color: var(--text-muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.25rem;
}
.sidebar__toggle input {
    cursor: pointer;
}

/* Scrollable body (tree + viewer) */
.sidebar__body {
    flex: 1;
    overflow-y: auto;
    min-height: 0;
}

/* Tree */
.sidebar__tree {
    padding: 0.4rem 0;
}
.sidebar__tree-empty {
    padding: 1rem 0.75rem;
    font-size: 0.8rem;
    color: var(--text-muted);
    font-style: italic;
}
.sidebar__dir > div {
    /* children container */
}
.sidebar__node {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    width: 100%;
    padding: 0.3rem 0.75rem;
    font-size: 0.8rem;
    font-family: var(--font-body);
    color: var(--text-secondary);
    background: none;
    border: none;
    cursor: pointer;
    text-align: left;
    transition: background 0.12s ease, color 0.12s ease;
    line-height: 1.35;
}
.sidebar__node:hover {
    background: var(--sidebar-node-hover);
    color: var(--text-primary);
}
.sidebar__node--active {
    background: var(--sidebar-node-active);
    color: var(--accent-primary);
}
.sidebar__node--dir {
    list-style: none;
    user-select: none;
    font-weight: 600;
    color: var(--text-primary);
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}
.sidebar__node--dir::-webkit-details-marker {
    display: none;
}
.sidebar__dir-arrow {
    display: inline-block;
    font-size: 0.55em;
    transition: transform 0.15s ease;
    flex-shrink: 0;
    color: var(--text-muted);
}
.sidebar__dir-arrow::before {
    content: "\25B6";
}
.sidebar__dir[open] > .sidebar__node--dir .sidebar__dir-arrow {
    transform: rotate(90deg);
}
.sidebar__node-label {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.sidebar__node-time {
    margin-left: auto;
    flex-shrink: 0;
    font-size: 0.65rem;
    color: var(--text-muted);
    font-weight: 400;
    text-transform: none;
    letter-spacing: normal;
}

/* Viewer */
.sidebar__viewer {
    border-top: 1px solid var(--sidebar-divider);
}
.sidebar__viewer-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.4rem 0.75rem;
    border-bottom: 1px solid var(--sidebar-divider);
    background: var(--sidebar-header-bg);
    position: sticky;
    top: 0;
    z-index: 2;
}
.sidebar__viewer-name {
    font-family: 'Courier New', monospace;
    font-size: 0.75rem;
    color: var(--accent-primary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.sidebar__viewer-actions {
    display: flex;
    gap: 0.25rem;
    flex-shrink: 0;
}
.sidebar__small-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 0.2rem;
    display: flex;
    align-items: center;
    border-radius: 0.25rem;
    transition: color 0.12s ease, background 0.12s ease;
}
.sidebar__small-btn:hover {
    color: var(--accent-primary);
    background: var(--accent-muted);
}
.sidebar__small-btn--active {
    color: var(--accent-primary);
    background: var(--accent-muted);
}
.sidebar__viewer-content {
    padding: 0.6rem 0.75rem;
    font-size: 0.85rem;
    line-height: 1.5;
}
.sidebar__viewer-content .prose {
    font-size: 0.85rem;
}
.sidebar__viewer-content .prose h1 { font-size: 1.3rem; }
.sidebar__viewer-content .prose h2 { font-size: 1.1rem; }
.sidebar__viewer-content .prose h3 { font-size: 0.95rem; }
.sidebar__loading,
.sidebar__load-error {
    color: var(--text-muted);
    font-style: italic;
    font-size: 0.8rem;
    padding: 0.5rem 0;
}
.sidebar__editor {
    width: 100%;
    min-height: 200px;
    max-height: 50vh;
    padding: 0.6rem 0.75rem;
    background: var(--bg-input);
    color: var(--text-primary);
    border: none;
    border-top: 1px solid var(--sidebar-divider);
    font-family: 'Courier New', monospace;
    font-size: 0.78rem;
    line-height: 1.5;
    resize: vertical;
    outline: none;
}
.sidebar__editor:focus {
    box-shadow: inset 0 0 0 1px var(--accent-primary);
}
.sidebar__editor-bar {
    display: flex;
    gap: 0.4rem;
    padding: 0.4rem 0.75rem;
    border-top: 1px solid var(--sidebar-divider);
    background: var(--sidebar-header-bg);
}
.sidebar__save-btn {
    padding: 0.25rem 0.75rem;
    font-size: 0.75rem;
    font-family: var(--font-body);
    background: var(--accent-primary);
    color: var(--bg-primary);
    border: none;
    border-radius: 0.3rem;
    cursor: pointer;
    font-weight: 600;
    transition: background 0.12s ease;
}
.sidebar__save-btn:hover {
    background: var(--accent-hover);
}
.sidebar__cancel-btn {
    padding: 0.25rem 0.75rem;
    font-size: 0.75rem;
    font-family: var(--font-body);
    background: none;
    color: var(--text-muted);
    border: 1px solid var(--border-primary);
    border-radius: 0.3rem;
    cursor: pointer;
    transition: color 0.12s ease, border-color 0.12s ease;
}
.sidebar__cancel-btn:hover {
    color: var(--text-primary);
    border-color: var(--text-muted);
}

/* === Dice Roller === */

.sidebar__dice {
    flex-shrink: 0;
    border-top: 1px solid var(--border-primary);
    padding: 0.6rem 0.75rem 0.75rem;
    background: var(--sidebar-header-bg);
}
.sidebar__dice-label {
    font-family: var(--font-display);
    font-size: 0.7rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    margin-bottom: 0.4rem;
}
.sidebar__dice-presets {
    display: flex;
    flex-wrap: wrap;
    gap: 0.3rem;
    margin-bottom: 0.5rem;
}
.sidebar__dice-chip {
    padding: 0.15rem 0.45rem;
    font-size: 0.7rem;
    font-family: 'Courier New', monospace;
    color: var(--text-secondary);
    background: none;
    border: 1px solid var(--border-primary);
    border-radius: 0.25rem;
    cursor: pointer;
    transition: all 0.12s ease;
}
.sidebar__dice-chip:hover {
    color: var(--accent-primary);
    border-color: var(--accent-primary);
    background: var(--accent-muted);
}
.sidebar__dice-form {
    display: flex;
    gap: 0.35rem;
}
.sidebar__dice-input {
    flex: 1;
    padding: 0.3rem 0.5rem;
    font-size: 0.8rem;
    font-family: 'Courier New', monospace;
    background: var(--bg-input);
    color: var(--text-primary);
    border: 1px solid var(--border-input);
    border-radius: 0.3rem;
    outline: none;
    min-width: 0;
}
.sidebar__dice-input:focus {
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 2px var(--ring-color);
}
.sidebar__dice-input::placeholder {
    color: var(--text-muted);
}
.sidebar__dice-btn {
    padding: 0.3rem 0.7rem;
    font-size: 0.78rem;
    font-family: var(--font-display);
    font-weight: 600;
    background: var(--accent-primary);
    color: var(--bg-primary);
    border: none;
    border-radius: 0.3rem;
    cursor: pointer;
    transition: background 0.12s ease;
    letter-spacing: 0.03em;
}
.sidebar__dice-btn:hover {
    background: var(--accent-hover);
}

/* Dice result */
.sidebar__dice-result {
    margin-top: 0.5rem;
    padding: 0.5rem;
    border-radius: 0.35rem;
    background: var(--bg-surface);
    border: 1px solid var(--border-primary);
    text-align: center;
    animation: diceReveal 0.3s ease;
}
.sidebar__dice-result--pop {
    animation: diceReveal 0.3s ease;
}
@keyframes diceReveal {
    0% { transform: scale(0.92); opacity: 0.5; }
    60% { transform: scale(1.02); }
    100% { transform: scale(1); opacity: 1; }
}
.sidebar__dice-expr {
    font-family: 'Courier New', monospace;
    font-size: 0.72rem;
    color: var(--text-muted);
    margin-bottom: 0.3rem;
}
.sidebar__dice-rolls {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.3rem;
    flex-wrap: wrap;
    margin-bottom: 0.25rem;
}
.sidebar__die {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 1.6rem;
    height: 1.6rem;
    padding: 0 0.3rem;
    font-family: 'Courier New', monospace;
    font-size: 0.85rem;
    font-weight: 700;
    color: var(--accent-primary);
    background: var(--sidebar-die-bg);
    border: 1px solid var(--sidebar-die-border);
    border-radius: 0.25rem;
}
.sidebar__die--fate {
    font-size: 1rem;
}
.sidebar__dice-mod {
    font-family: 'Courier New', monospace;
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-left: 0.15rem;
}
.sidebar__dice-total {
    font-family: var(--font-display);
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-primary);
    line-height: 1.2;
}
.sidebar__dice-rolling {
    font-style: italic;
    color: var(--text-muted);
    font-size: 0.8rem;
}
.sidebar__dice-error {
    color: var(--danger);
    font-size: 0.8rem;
}

/* Dice history */
.sidebar__dice-history {
    margin-top: 0.4rem;
    max-height: 5rem;
    overflow-y: auto;
}
.sidebar__dice-hist-row {
    display: flex;
    justify-content: space-between;
    padding: 0.1rem 0;
    font-size: 0.7rem;
    color: var(--text-muted);
    font-family: 'Courier New', monospace;
}
.sidebar__dice-hist-expr {
    opacity: 0.7;
}
.sidebar__dice-hist-total {
    font-weight: 600;
    color: var(--text-secondary);
}

/* Send roll to chat button */
.sidebar__dice-send {
    display: block;
    margin: 0.35rem auto 0;
    padding: 0.15rem 0.6rem;
    font-size: 0.68rem;
    font-family: var(--font-body);
    color: var(--text-muted);
    background: none;
    border: 1px solid var(--border-primary);
    border-radius: 0.25rem;
    cursor: pointer;
    transition: all 0.12s ease;
}
.sidebar__dice-send:hover {
    color: var(--accent-primary);
    border-color: var(--accent-primary);
}

/* === TTS Sidebar Settings === */

.sidebar__tts {
    flex-shrink: 0;
    border-top: 1px solid var(--border-primary);
    padding: 0.6rem 0.75rem;
    background: var(--sidebar-header-bg);
}
.sidebar__tts-label {
    font-family: var(--font-display);
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-muted);
    margin-bottom: 0.4rem;
}
.sidebar__tts-controls {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}
.sidebar__tts-field {
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
    font-size: 0.72rem;
    color: var(--text-secondary);
}
.sidebar__tts-select {
    width: 100%;
    padding: 0.25rem 0.4rem;
    font-size: 0.72rem;
    background: var(--bg-input);
    color: var(--text-primary);
    border: 1px solid var(--border-input);
    border-radius: 0.3rem;
}
.sidebar__tts-range {
    width: 100%;
    accent-color: var(--accent-primary);
}
.sidebar__tts-test {
    padding: 0.25rem 0.5rem;
    font-size: 0.72rem;
    background: transparent;
    color: var(--text-muted);
    border: 1px solid var(--border-primary);
    border-radius: 0.3rem;
    cursor: pointer;
    transition: all 0.12s ease;
    align-self: flex-start;
}
.sidebar__tts-test:hover {
    color: var(--accent-primary);
    border-color: var(--accent-primary);
}

/* === Popout Viewer === */

.popout-viewer {
    position: fixed;
    width: 420px;
    max-height: 70vh;
    background: var(--sidebar-bg);
    border: 1px solid var(--border-primary);
    border-radius: 0.5rem;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.35), 0 0 0 1px rgba(0,0,0,0.1);
    z-index: 35;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    resize: both;
    min-width: 280px;
    min-height: 200px;
    animation: popoutReveal 0.2s ease;
}
.popout-viewer--maximized {
    max-height: none;
}
@keyframes popoutReveal {
    from { opacity: 0; transform: scale(0.95) translateY(8px); }
    to { opacity: 1; transform: scale(1) translateY(0); }
}

.popout-viewer__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.45rem 0.6rem;
    background: var(--sidebar-header-bg);
    border-bottom: 1px solid var(--border-primary);
    cursor: grab;
    flex-shrink: 0;
    user-select: none;
    touch-action: none;
}
.popout-viewer__header:active {
    cursor: grabbing;
}
.popout-viewer__name {
    font-family: 'Courier New', monospace;
    font-size: 0.75rem;
    color: var(--accent-primary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.popout-viewer__actions {
    display: flex;
    gap: 0.25rem;
    flex-shrink: 0;
}
.popout-viewer__content {
    flex: 1;
    overflow-y: auto;
    padding: 0.6rem 0.75rem;
    font-size: 0.85rem;
    line-height: 1.5;
    min-height: 0;
}
.popout-viewer__content .prose {
    font-size: 0.85rem;
}
.popout-viewer__content .prose h1 { font-size: 1.3rem; }
.popout-viewer__content .prose h2 { font-size: 1.1rem; }
.popout-viewer__content .prose h3 { font-size: 0.95rem; }
.popout-viewer__editor {
    flex: 1;
    width: 100%;
    min-height: 120px;
    padding: 0.6rem 0.75rem;
    background: var(--bg-input);
    color: var(--text-primary);
    border: none;
    border-top: 1px solid var(--sidebar-divider);
    font-family: 'Courier New', monospace;
    font-size: 0.78rem;
    line-height: 1.5;
    resize: none;
    outline: none;
}
.popout-viewer__editor:focus {
    box-shadow: inset 0 0 0 1px var(--accent-primary);
}
.popout-viewer__editor-bar {
    display: flex;
    gap: 0.4rem;
    padding: 0.4rem 0.6rem;
    border-top: 1px solid var(--sidebar-divider);
    background: var(--sidebar-header-bg);
    flex-shrink: 0;
}

/* Mobile: popout becomes near-fullscreen */
@media (max-width: 768px) {
    .popout-viewer {
        top: 2rem !important;
        left: 0.5rem !important;
        right: 0.5rem !important;
        width: auto !important;
        max-height: calc(100dvh - 4rem);
        resize: none;
        border-radius: 0.75rem;
    }
}
