/* DM Roleplay System - Admin UI Styles */

:root {
    --primary: #6366f1;
    --primary-dark: #4f46e5;
    --secondary: #64748b;
    --success: #22c55e;
    --warning: #f59e0b;
    --danger: #ef4444;
    --bg-dark: #1e1e2e;
    --bg-card: #2a2a3e;
    --bg-input: #3a3a4e;
    --text-primary: #e2e8f0;
    --text-secondary: #94a3b8;
    --border: #404060;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    background: var(--bg-dark);
    color: var(--text-primary);
    min-height: 100vh;
}

/* Layout */
.container {
    max-width: 2200px;
    margin: 0 auto;
    padding: 20px 10px;
}

.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px;
    border-bottom: 1px solid var(--border);
    margin-bottom: 20px;
    gap: 15px;
}

.header h1 {
    font-size: 1.5rem;
    font-weight: 600;
}

/* Navigation Tabs */
.nav-tabs {
    display: flex;
    gap: 10px;
    margin-bottom: 20px;
    border-bottom: 1px solid var(--border);
    padding-bottom: 10px;
}

.nav-tab {
    padding: 10px 20px;
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 1rem;
    border-radius: 6px;
    transition: all 0.2s;
}

.nav-tab:hover {
    background: var(--bg-card);
    color: var(--text-primary);
}

.nav-tab.active {
    background: var(--primary);
    color: white;
}

/* Cards */
.card {
    background: var(--bg-card);
    border-radius: 12px;
    padding: 20px;
    margin-bottom: 20px;
    border: 1px solid var(--border);
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
}

.card-title {
    font-size: 1.1rem;
    font-weight: 600;
}

/* Grid */
.grid {
    display: grid;
    gap: 20px;
}

.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-4 { grid-template-columns: repeat(4, 1fr); }

@media (max-width: 1024px) {
    .grid-3, .grid-4 { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 640px) {
    .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
}

/* Buttons */
.btn {
    padding: 10px 20px;
    border: none;
    border-radius: 6px;
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.2s;
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.btn-primary {
    background: var(--primary);
    color: white;
}

.btn-primary:hover {
    background: var(--primary-dark);
}

.btn-secondary {
    background: var(--bg-input);
    color: var(--text-primary);
}

.btn-secondary:hover {
    background: var(--border);
}

.btn-success {
    background: var(--success);
    color: white;
    font-weight: 700;
    text-shadow: 0 1px 2px rgba(0,0,0,0.5);
    box-shadow: 0 4px 12px rgba(34, 197, 94, 0.4), 0 2px 4px rgba(0,0,0,0.2);
}

.btn-warning {
    background: var(--warning);
    color: black;
}

.btn-danger {
    background: var(--danger);
    color: white;
}

.btn-info {
    background: #3b82f6;
    color: white;
}

.btn-info:hover {
    background: #2563eb;
}

.btn-sm {
    padding: 6px 12px;
    font-size: 0.8rem;
}

.btn-icon {
    width: 36px;
    height: 36px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Split Button */
.split-btn-group {
    display: inline-flex;
    border-radius: 6px;
    overflow: hidden;
}

.split-btn-left {
    border-radius: 6px 0 0 6px;
}

.split-btn-right {
    border-radius: 0 6px 6px 0;
    border-left: 1px solid rgba(0,0,0,0.25);
    padding: 10px 12px;
    font-size: 0.8rem;
}

/* Forms */
.form-group {
    margin-bottom: 15px;
}

.form-label {
    display: block;
    margin-bottom: 5px;
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.form-input, .form-textarea, .form-select {
    width: 100%;
    padding: 10px 15px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text-primary);
    font-size: 1rem;
}

.form-input:focus, .form-textarea:focus, .form-select:focus {
    outline: none;
    border-color: var(--primary);
}

.form-textarea {
    min-height: 100px;
    resize: vertical;
}

.form-hint {
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-top: 5px;
}

/* Tables */
.table {
    width: 100%;
    border-collapse: collapse;
}

.table th, .table td {
    padding: 12px;
    text-align: left;
    border-bottom: 1px solid var(--border);
}

.table th {
    color: var(--text-secondary);
    font-weight: 500;
    font-size: 0.9rem;
}

.table tr:hover {
    background: var(--bg-input);
}

/* Status badges */
.badge {
    display: inline-block;
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 0.8rem;
    font-weight: 500;
}

.badge-active { background: var(--success); color: white; }
.badge-suspended { background: var(--warning); color: black; }
.badge-completed { background: var(--secondary); color: white; }
.badge-awaitinghuman { background: #f97316; color: white; }
.badge-ai { background: var(--primary); color: white; }
.badge-human { background: #8b5cf6; color: white; }

/* Modal */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.modal {
    background: var(--bg-card);
    border-radius: 12px;
    width: 90%;
    max-width: 600px;
    max-height: 90vh;
    overflow-y: auto;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px;
    border-bottom: 1px solid var(--border);
}

.modal-title {
    font-size: 1.2rem;
    font-weight: 600;
}

.modal-close {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 1.5rem;
    cursor: pointer;
}

.modal-body {
    padding: 20px;
}

/* Character Sheet Modal - fixed top/bottom, scrollable middle */
.character-sheet-modal {
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.character-sheet-modal form {
    display: flex;
    flex-direction: column;
    min-height: 0;
    flex: 1;
}

.character-sheet-top {
    flex-shrink: 0;
}

.character-sheet-body {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    min-height: 0;
}

.character-sheet-modal .modal-footer {
    flex-shrink: 0;
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    padding: 20px;
    border-top: 1px solid var(--border);
}

.confirm-modal {
    max-width: 420px;
}

.confirm-modal-header {
    border-bottom-color: var(--warning);
}

.confirm-modal .modal-body p {
    color: var(--text-secondary);
    line-height: 1.6;
    margin: 0;
}

.btn-warning {
    background: var(--warning);
    color: #1a1a2e;
    border: none;
    padding: 8px 20px;
    border-radius: 6px;
    cursor: pointer;
    font-weight: 600;
    transition: all 0.2s;
}

.btn-warning:hover {
    background: #d97706;
}

/* Live Session Layout */
.live-layout {
    display: grid;
    grid-template-columns: 1fr 750px;
    grid-template-rows: 1fr minmax(280px, auto);
    grid-template-areas:
        "main sidebar"
        "controls sidebar";
    gap: 20px;
    height: calc(100vh - 140px);
    max-width: 100%;
    margin: 0 auto;
}

@media (max-width: 1024px) {
    .live-layout {
        grid-template-columns: 1fr;
        grid-template-areas: "main" "controls" "sidebar";
        grid-template-rows: auto;
        height: auto;
    }
}

.live-main {
    grid-area: main;
    display: flex;
    flex-direction: column;
    gap: 20px;
    overflow-y: auto;
}

.live-controls {
    grid-area: controls;
    display: flex;
    flex-direction: column;
    gap: 20px;
    overflow-y: auto;
}

.live-sidebar {
    grid-area: sidebar;
    display: flex;
    flex-direction: column;
    gap: 20px;
    overflow-y: auto;
}

/* Ultrawide Layout */
.ultrawide .container {
    max-width: 3450px;
}

.ultrawide .live-layout {
    max-width: 100%;
}

/* 3-column layout only when viewport is wide enough */
@media (min-width: 2500px) {
    .ultrawide .live-layout {
        grid-template-columns: 1fr 0.85fr 0.65fr;
        grid-template-rows: 1fr;
        grid-template-areas: "main controls sidebar";
        max-width: 3400px;
        height: calc(100vh - 140px);
    }

    .ultrawide .live-main {
        min-height: 0;
    }
}

/* Narration Row: 3-column per entry (character, thoughts, text) */
.narration-row {
    display: flex;
    gap: 15px;
    padding: 12px 0;
    border-bottom: 1px solid var(--border);
}

.narration-row-left {
    width: 100px;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    text-align: center;
}

.narration-row-middle {
    width: 180px;
    flex-shrink: 0;
    min-height: 0;
}

.narration-row-img {
    width: 64px;
    height: 64px;
    border-radius: 8px;
    object-fit: cover;
}

.narration-row-img-placeholder {
    background: var(--bg-dark);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 1.2rem;
    color: var(--text-secondary);
}

.narration-row-name {
    font-weight: 700;
    font-size: 0.85rem;
    color: var(--text-primary);
}

.narration-row-role {
    font-size: 0.7rem;
    padding: 1px 7px;
    border-radius: 10px;
    background: rgba(217, 119, 6, 0.15);
    color: #d97706;
    border: 1px solid rgba(217, 119, 6, 0.3);
}

.narration-row-thought {
    font-size: 0.75rem;
    color: #c4b5fd;
    font-style: italic;
    line-height: 1.4;
    max-height: 120px;
    overflow-y: auto;
    cursor: pointer;
    padding: 6px 8px;
    border-radius: 4px;
    background: rgba(139, 92, 246, 0.1);
    border: 1px solid rgba(139, 92, 246, 0.2);
    width: 100%;
}

.narration-row-thought:hover {
    background: rgba(139, 92, 246, 0.2);
}

.narration-row-thought-empty {
    font-size: 0.7rem;
    color: var(--text-secondary);
    font-style: italic;
    opacity: 0.4;
    padding: 6px 8px;
}

.btn-visualize {
    padding: 4px 10px;
    font-size: 0.7rem;
    border: 1px solid #cbd5e1;
    background: transparent;
    color: #cbd5e1;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s;
    margin-top: 4px;
    white-space: nowrap;
}

.btn-visualize:hover {
    background: var(--primary);
    color: white;
}

.btn-rewind {
    padding: 4px 10px;
    font-size: 0.7rem;
    border: 1px solid var(--warning);
    background: transparent;
    color: var(--warning);
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s;
    margin-top: 2px;
    white-space: nowrap;
}

.btn-rewind:hover {
    background: var(--warning);
    color: white;
}

.btn-visualize:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-visualize.loading {
    background: var(--primary);
    color: white;
    opacity: 0.7;
}

.btn-edit-turn, .btn-reroll-turn {
    padding: 4px 10px;
    font-size: 0.7rem;
    border: 1px solid var(--border);
    background: transparent;
    color: var(--text-secondary);
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s;
    margin-top: 2px;
    white-space: nowrap;
}

.btn-edit-turn:hover {
    border-color: var(--primary);
    color: var(--primary);
}

.btn-reroll-turn:hover {
    border-color: var(--warning);
    color: var(--warning);
}

.interactive-toggle {
    padding: 4px 12px;
    font-size: 0.8rem;
    border-radius: 6px;
    border: 1px solid var(--border);
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.2s;
}

.interactive-toggle.active {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

.btn-edit-turn-player, .btn-reroll-turn-player {
    padding: 2px 8px;
    font-size: 0.75rem;
    border: 1px solid var(--border);
    background: transparent;
    color: var(--text-secondary);
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-edit-turn-player:hover {
    border-color: var(--primary);
    color: var(--primary);
}

.btn-reroll-turn-player:hover {
    border-color: var(--warning);
    color: var(--warning);
}

.interactive-buttons {
    display: inline-flex;
    gap: 4px;
    margin-top: 4px;
}

#edit-turn-modal .modal-dialog {
    max-width: 600px;
    margin: 15vh auto;
    background: var(--bg-card);
    border-radius: 12px;
    padding: 20px;
    border: 1px solid var(--border);
}

#edit-turn-modal textarea {
    width: 100%;
    background: var(--bg-dark);
    color: var(--text-primary);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 10px;
    font-family: inherit;
    font-size: 0.9rem;
    resize: vertical;
}

#edit-turn-modal .modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    margin-top: 12px;
}

.narration-row-right {
    flex: 1;
    min-width: 0;
}

.narration-row-right .narration-entry {
    padding: 0;
}

.ultrawide .characters-grid {
    grid-template-columns: repeat(3, 1fr);
}

.ultrawide .character-card {
    min-height: 100px;
}

.ultrawide #character-modal .modal {
    max-width: 1300px !important;
}

.ultrawide #character-image-preview {
    width: 156px !important;
    height: 156px !important;
}

.ultrawide #character-image-preview > img {
    width: 156px !important;
    height: 156px !important;
}

/* Character image stack — alternate images peeking behind active */
.char-image-stack {
    position: relative;
}

.char-image-stack .char-stack-alt {
    position: absolute;
    top: 0;
    left: 0;
    border-radius: 8px;
    object-fit: cover;
    pointer-events: none;
    opacity: 0.5;
    border: 1px solid var(--border);
}

.char-image-stack .char-stack-active {
    position: relative;
    z-index: 10;
    border-radius: 8px;
    object-fit: cover;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
}

/* Ultrawide: Edit Scenario modal */
.ultrawide #scenario-modal .modal {
    max-width: 1900px !important;
}

.ultrawide #scenario-modal .modal-body {
    grid-template-columns: 1.75fr 1.5fr !important;
    max-height: 82vh;
    overflow-y: auto;
}

.ultrawide #scenario-modal #scenario-char-picker-grid {
    grid-template-columns: repeat(4, 1fr) !important;
    max-height: 820px;
}

.ultrawide #scenario-modal #scenario-char-picker-grid .character-card {
    padding: 3px !important;
}

.ultrawide #scenario-modal #scenario-char-picker-grid .character-card img,
.ultrawide #scenario-modal #scenario-char-picker-grid .character-card > div:first-child {
    width: 100px !important;
    height: 100px !important;
}

/* Narration Display */
.narration-box {
    background: var(--bg-input);
    border-radius: 8px;
    padding: 15px;
    font-style: italic;
    line-height: 1.6;
    flex: 1;
    min-height: 200px;
    overflow-y: auto;
}

.narration-entry {
    padding: 15px 0;
}

.narration-separator {
    display: flex;
    flex-direction: column;
    margin: 15px 0;
    gap: 6px;
}

.separator-line {
    width: 100%;
    height: 2px;
    background: #ffffff;
}

.separator-name {
    color: #ffffff;
    font-weight: 600;
    font-size: 14px;
}

/* Turn Order */
.turn-order-list {
    list-style: none;
}

.turn-order-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px;
    background: var(--bg-input);
    border-radius: 6px;
    margin-bottom: 8px;
    cursor: grab;
    white-space: nowrap;
}

.turn-order-item.current {
    border: 2px solid var(--primary);
}

.turn-order-item.next-turn {
    border-left: 3px solid var(--success);
    background: rgba(34, 197, 94, 0.1);
}

.turn-order-item.awaiting-input {
    border-left: 3px solid #f97316;
    background: rgba(249, 115, 22, 0.15);
    animation: pulse-bg 2s ease-in-out infinite;
}

@keyframes pulse-bg {
    0%, 100% { background: rgba(249, 115, 22, 0.15); }
    50% { background: rgba(249, 115, 22, 0.25); }
}

.turn-order-item.skipped {
    opacity: 0.5;
}

.turn-order-item.turn-queue-disabled {
    opacity: 0.5;
    background: rgba(100, 100, 100, 0.2);
    border-left: 3px solid var(--secondary);
}

/* Turn status indicators */
.turn-status {
    display: inline-block;
    margin-right: 6px;
    font-size: 0.8rem;
}

.turn-status-next {
    color: var(--success);
}

.turn-status-waiting {
    color: #f97316;
    animation: pulse-icon 1.5s ease-in-out infinite;
}

@keyframes pulse-icon {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.4; }
}

.turn-order-handle {
    color: var(--text-secondary);
    cursor: grab;
}

.turn-order-name {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 6px;
    min-width: 0;
}

.turn-order-controls {
    display: flex;
    gap: 5px;
}

/* Character Grid */
.characters-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
}

/* Session card layout */
.session-card-layout {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 12px;
}

.session-card-main {
    flex: 1;
    min-width: 0;
}

.session-card-actions {
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 8px;
}

@media (max-width: 768px) {
    .characters-grid {
        grid-template-columns: 1fr;
    }
    .session-card-actions .flex {
        flex-direction: column;
    }
    .session-card-actions .btn {
        width: 100%;
        justify-content: center;
    }
    .recent-sessions-table {
        display: none;
    }
    .recent-sessions-cards {
        display: block !important;
    }
}

/* Character Cards */
.character-card {
    background: var(--bg-input);
    border-radius: 8px;
    padding: 0;
    overflow: hidden;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    flex-direction: row;
    align-items: stretch;
}

.character-card:hover {
    background: var(--border);
}

.character-card-thumb {
    width: 120px;
    min-height: 120px;
    object-fit: cover;
    flex-shrink: 0;
    border-radius: 8px 0 0 8px;
    align-self: stretch;
}

.character-card-thumb-placeholder {
    width: 120px;
    min-height: 120px;
    border-radius: 8px 0 0 8px;
    background: var(--bg-dark);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.8rem;
    font-weight: 700;
    color: var(--text-secondary);
    flex-shrink: 0;
    align-self: stretch;
}

.character-card-thumb-wrapper {
    position: relative;
    flex-shrink: 0;
}

.character-ephemeral-badge {
    position: absolute;
    top: 4px;
    left: 4px;
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 0.7rem;
    font-weight: 600;
    background: rgba(245, 158, 11, 0.85);
    color: white;
    pointer-events: none;
    z-index: 1;
}

.character-card-info {
    flex: 1;
    min-width: 0;
    padding: 10px 12px;
}

.character-card-name {
    font-weight: 700;
    margin-bottom: 2px;
}

.character-card-header-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 2px;
}

.character-card-roles {
    display: flex;
    gap: 4px;
    flex-wrap: wrap;
    justify-content: flex-end;
    flex-shrink: 0;
}

.character-role-tag {
    font-size: 0.7rem;
    padding: 1px 7px;
    border-radius: 10px;
    background: rgba(99, 102, 241, 0.15);
    color: #a5b4fc;
    border: 1px solid rgba(99, 102, 241, 0.3);
    white-space: nowrap;
}

.character-card-desc {
    font-size: 0.85rem;
    color: var(--text-secondary);
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 4;
    -webkit-box-orient: vertical;
    line-height: 1.3;
}

.character-card-extras {
    display: block;
    margin-top: 4px;
}

.character-card-extra {
    font-size: 0.75rem;
    color: var(--text-secondary);
    line-height: 1.4;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.character-card-label {
    color: #94a3b8;
    font-weight: 600;
}

/* Character Picker View Toggle */
.picker-view-toggle {
    background: none;
    border: 1px solid var(--border);
    border-radius: 4px;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 3px 5px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s;
}

.picker-view-toggle:hover {
    color: var(--text-primary);
    border-color: var(--text-secondary);
}

/* Character picker list view */
.picker-list-view {
    display: flex !important;
    flex-direction: column !important;
    gap: 0 !important;
}

.picker-list-view .picker-list-item {
    display: flex;
    align-items: stretch;
    min-height: 130px;
    cursor: pointer;
    border-bottom: 1px solid var(--border);
    transition: background 0.15s;
    background: var(--bg-input);
    overflow: hidden;
}

.picker-list-view .picker-list-item:first-child {
    border-radius: 6px 6px 0 0;
}

.picker-list-view .picker-list-item:last-child {
    border-bottom: none;
    border-radius: 0 0 6px 6px;
}

.picker-list-view .picker-list-item:first-child:last-child {
    border-radius: 6px;
}

.picker-list-view .picker-list-item:hover {
    background: var(--border);
}

.picker-list-view .picker-list-item.selected {
    background: rgba(79, 70, 229, 0.1);
}

.picker-list-item-img {
    width: 130px;
    min-height: 130px;
    object-fit: cover;
    flex-shrink: 0;
    align-self: stretch;
}

.picker-list-item-img-placeholder {
    width: 130px;
    min-height: 130px;
    background: var(--bg-dark);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 1.6rem;
    color: var(--text-secondary);
    flex-shrink: 0;
    align-self: stretch;
}

.picker-list-item-info {
    flex: 1;
    min-width: 0;
    padding: 6px 10px;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.picker-list-item-name {
    font-weight: 700;
    font-size: 0.85rem;
}

.picker-list-item-desc {
    font-size: 0.75rem;
    color: var(--text-secondary);
    line-height: 1.4;
    display: -webkit-box;
    -webkit-line-clamp: 5;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.picker-list-item-check {
    display: flex;
    align-items: center;
    padding: 0 10px;
    font-size: 1.2rem;
    flex-shrink: 0;
}

/* Scenario Cards */
.scenario-card {
    background: var(--bg-input);
    border-radius: 8px;
    padding: 15px;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    flex-direction: column;
}

.scenario-card:hover {
    background: var(--border);
}

.scenario-card-name {
    font-weight: 700;
    margin-bottom: 4px;
}

.scenario-card-desc {
    font-size: 0.85rem;
    color: var(--text-secondary);
    line-height: 1.4;
}

.character-session-link {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 6px 10px;
    background: var(--bg-input);
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.85rem;
    transition: background 0.15s;
}

.character-session-link:hover {
    background: var(--border);
}

/* Character Pagination */
.characters-pagination {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 8px;
    margin-top: 16px;
}

.characters-pagination .btn {
    min-width: 36px;
}

.characters-pagination .page-info {
    color: var(--text-secondary);
    font-size: 0.9rem;
}

/* DM Controls */
.dm-instruction-box {
    background: var(--bg-input);
    border-radius: 8px;
    padding: 15px;
}

.dm-instruction-box textarea {
    margin-bottom: 10px;
}

.dm-actions {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

/* Player View */
.player-header {
    text-align: center;
    padding: 20px;
    border-bottom: 1px solid var(--border);
}

.player-character-name {
    font-size: 2rem;
    font-weight: 700;
}

.player-scene {
    padding: 20px;
    background: var(--bg-card);
    border-radius: 8px;
    margin-bottom: 20px;
}

.player-turn-alert {
    background: var(--warning);
    color: black;
    padding: 15px;
    border-radius: 8px;
    text-align: center;
    margin-bottom: 20px;
}

.player-action-input {
    min-height: 150px;
}

/* Utility classes */
.hidden { display: none !important; }
.text-center { text-align: center; }
.text-right { text-align: right; }
.text-muted { color: var(--text-secondary); }
.mb-0 { margin-bottom: 0; }
.mb-1 { margin-bottom: 10px; }
.mb-2 { margin-bottom: 20px; }
.mt-1 { margin-top: 10px; }
.mt-2 { margin-top: 20px; }
.flex { display: flex; }
.flex-between { justify-content: space-between; }
.flex-center { align-items: center; }
.gap-1 { gap: 10px; }
.gap-2 { gap: 20px; }

/* Loading spinner */
.spinner {
    width: 40px;
    height: 40px;
    border: 4px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
}

/* Photostory — Scene Thumbnails */
.scene-thumbnails {
    display: flex;
    gap: 8px;
    padding: 8px 0;
    flex-wrap: wrap;
    align-items: center;
}

.scene-thumb {
    width: 48px;
    height: 48px;
    border-radius: 6px;
    object-fit: cover;
    cursor: pointer;
    border: 2px solid var(--border);
    transition: border-color 0.2s, transform 0.15s;
}

.scene-thumb:hover {
    border-color: var(--primary);
    transform: scale(1.1);
}

/* Photo Album Modal */
.photo-album-container {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 12px;
    width: 95%;
    max-width: 900px;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 8px 32px rgba(0,0,0,0.5);
}

.photo-album-cycle {
    margin-bottom: 24px;
}

.photo-album-cycle-header {
    font-weight: 600;
    color: var(--text-secondary);
    font-size: 0.85rem;
    margin-bottom: 8px;
    padding-bottom: 4px;
    border-bottom: 1px solid var(--border);
}

.photo-album-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
}

.photo-album-img {
    width: 100%;
    border-radius: 8px;
    cursor: pointer;
    border: 2px solid transparent;
    transition: border-color 0.2s;
}

.photo-album-img:hover {
    border-color: var(--primary);
}

.photo-album-caption {
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin-top: 4px;
    text-align: center;
}

.photo-album-item {
    position: relative;
}

.photo-album-delete {
    position: absolute;
    top: 6px;
    right: 6px;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: rgba(239, 68, 68, 0.85);
    color: white;
    border: none;
    font-size: 14px;
    font-weight: 700;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.15s;
    z-index: 1;
}

.photo-album-item:hover .photo-album-delete,
.photo-album-item:hover .photo-album-info {
    opacity: 1;
}

.photo-album-info {
    position: absolute;
    top: 6px;
    left: 6px;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: rgba(59, 130, 246, 0.85);
    color: white;
    border: none;
    font-size: 13px;
    font-weight: 700;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.15s;
    z-index: 1;
    font-style: italic;
    font-family: Georgia, serif;
}

.photo-album-info:hover {
    background: #2563eb;
}

.photo-album-info-popup {
    position: absolute;
    top: 34px;
    left: 6px;
    right: 6px;
    background: rgba(20, 20, 35, 0.95);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 10px;
    font-size: 0.72rem;
    color: var(--text-primary);
    z-index: 10;
    max-height: 200px;
    overflow-y: auto;
    line-height: 1.4;
    display: none;
}

.photo-album-info-popup.visible {
    display: block;
}

.photo-album-info-label {
    color: #94a3b8;
    font-weight: 600;
    font-size: 0.68rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    margin-top: 6px;
}

.photo-album-info-label:first-child {
    margin-top: 0;
}

.photo-album-info-value {
    color: var(--text-primary);
    word-break: break-word;
}

.photo-album-delete:hover {
    background: var(--danger);
    transform: scale(1.15);
}

/* Backfill Dialog */
.backfill-dialog-container {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 12px;
    width: 90%;
    max-width: 450px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.5);
}

/* Gallery Modal */
.gallery-container {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 12px;
    width: 96%;
    max-width: 1400px;
    height: 92vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 8px 32px rgba(0,0,0,0.5);
}

.gallery-header {
    padding: 15px 20px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 16px;
    flex-shrink: 0;
}

.gallery-filters {
    display: flex;
    gap: 8px;
    flex: 1;
}

.gallery-filters select {
    padding: 4px 8px;
    border-radius: 6px;
    border: 1px solid var(--border);
    background: var(--bg-main, var(--bg-dark));
    color: var(--text-primary);
    font-size: 0.85rem;
}

.gallery-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 12px;
}

.gallery-item {
    position: relative;
    border-radius: 8px;
    overflow: hidden;
    border: 2px solid transparent;
    transition: border-color 0.2s;
}

.gallery-item:hover {
    border-color: var(--primary);
}

.gallery-item img {
    width: 100%;
    display: block;
    cursor: pointer;
}

.gallery-item-badge {
    position: absolute;
    top: 6px;
    left: 6px;
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 0.7rem;
    font-weight: 600;
    pointer-events: none;
}

.gallery-badge-profile { background: rgba(59,130,246,0.85); color: white; }
.gallery-badge-storybook { background: rgba(168,85,247,0.85); color: white; }
.gallery-badge-active { background: rgba(34,197,94,0.85); color: white; }

.gallery-item-overlay {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 6px 8px;
    background: linear-gradient(transparent, rgba(0,0,0,0.8));
    color: white;
    font-size: 0.75rem;
    pointer-events: none;
}

.gallery-item-actions {
    position: absolute;
    top: 6px;
    right: 6px;
    display: flex;
    gap: 4px;
    opacity: 0;
    transition: opacity 0.15s;
}

.gallery-item:hover .gallery-item-actions { opacity: 1; }

.gallery-item-delete {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: rgba(239,68,68,0.85);
    color: white;
    border: none;
    cursor: pointer;
    font-size: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.gallery-item-delete:hover {
    background: var(--danger);
    transform: scale(1.15);
}

.gallery-item-info-btn {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: rgba(59,130,246,0.85);
    color: white;
    border: none;
    cursor: pointer;
    font-size: 12px;
    font-weight: bold;
    display: flex;
    align-items: center;
    justify-content: center;
    font-style: italic;
    font-family: Georgia, serif;
}

.gallery-item-info-btn:hover {
    background: #2563eb;
}

.gallery-item-info-popup {
    position: absolute;
    top: 34px;
    left: 6px;
    right: 6px;
    background: rgba(20, 20, 35, 0.95);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 10px;
    font-size: 0.72rem;
    color: var(--text-primary);
    z-index: 10;
    max-height: 200px;
    overflow-y: auto;
    line-height: 1.4;
    display: none;
}

.gallery-item-info-popup.visible {
    display: block;
}

.ultrawide .gallery-container {
    max-width: 1800px;
}

.ultrawide .gallery-grid {
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
}

/* Scene Image Progress Strip */
.scene-progress-strip {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    margin: 6px 0;
    background: rgba(99, 102, 241, 0.1);
    border: 1px solid rgba(99, 102, 241, 0.25);
    border-radius: 6px;
    font-size: 0.8rem;
    color: #a5b4fc;
}

.scene-progress-strip.scene-progress-warn {
    background: rgba(245, 158, 11, 0.1);
    border-color: rgba(245, 158, 11, 0.3);
    color: #fbbf24;
}

.scene-progress-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--primary);
    animation: progress-pulse 1.2s ease-in-out infinite;
    flex-shrink: 0;
}

.scene-progress-warn .scene-progress-dot {
    background: var(--warning);
}

@keyframes progress-pulse {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.4; transform: scale(0.75); }
}

/* Stream narration toggle active state */
.btn-stream-active {
    background: var(--success) !important;
    color: #fff !important;
}

/* Streaming cursor animation */
.streaming-cursor {
    display: inline-block;
    width: 2px;
    height: 1.1em;
    background: var(--primary);
    margin-left: 1px;
    vertical-align: text-bottom;
    animation: cursor-blink 0.8s step-end infinite;
}
@keyframes cursor-blink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0; }
}
.narration-row.streaming {
    animation: stream-in 0.3s ease-out;
}
@keyframes stream-in {
    from { opacity: 0; transform: translateY(4px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Photostory toggle active state */
.btn-photostory-active {
    background: var(--success) !important;
    color: #fff !important;
}

/* Token dashboard */
.token-stat-card {
    background: var(--bg-dark);
    border-radius: 8px;
    padding: 15px;
    text-align: center;
}

.token-stat-value {
    font-size: 1.6rem;
    font-weight: 700;
    color: var(--primary);
}

.token-stat-label {
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-top: 4px;
}

.token-table {
    font-size: 0.85rem;
}

.token-table th {
    font-size: 0.75rem;
    text-transform: uppercase;
    color: var(--text-secondary);
}

/* Emotion badge */
.emotion-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 0.65rem;
    padding: 1px 8px;
    border-radius: 10px;
    background: color-mix(in srgb, var(--emotion-color, #9ca3af) 20%, transparent);
    color: var(--emotion-color, #9ca3af);
    border: 1px solid color-mix(in srgb, var(--emotion-color, #9ca3af) 40%, transparent);
    font-weight: 600;
    text-transform: capitalize;
    vertical-align: middle;
}

.emotion-slot {
    display: inline;
}

/* Typing indicator (admin view) */
.typing-dots {
    display: inline-flex;
    gap: 3px;
}

.typing-dots span {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--primary);
    animation: typing-bounce 1.4s infinite ease-in-out both;
}

.typing-dots span:nth-child(2) { animation-delay: 0.16s; }
.typing-dots span:nth-child(3) { animation-delay: 0.32s; }

@keyframes typing-bounce {
    0%, 80%, 100% { transform: scale(0); opacity: 0.4; }
    40% { transform: scale(1); opacity: 1; }
}

/* Responsive narration rows */
@media (max-width: 1200px) {
    .narration-row-left {
        width: 70px;
    }
    .narration-row-middle {
        width: 140px;
    }
    .narration-row-img {
        width: 48px;
        height: 48px;
    }
}

@media (max-width: 900px) {
    .narration-row {
        flex-wrap: wrap;
    }
    .narration-row-left {
        width: auto;
        flex-direction: row;
        gap: 8px;
    }
    .narration-row-middle {
        width: 100%;
        order: 3;
    }
    .narration-row-right {
        width: 100%;
        order: 2;
    }
    .narration-row-img {
        width: 36px;
        height: 36px;
    }
}

/* Collapsible caret */
.caret.open { transform: rotate(90deg); }

#full-auto-progress {
    animation: fullAutoPulse 2s ease-in-out infinite;
}
@keyframes fullAutoPulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.6; }
}

/* Character disposition/alignment sliders */
.char-slider { width: 100%; cursor: pointer; accent-color: var(--primary); }
.slider-range-labels { display: flex; justify-content: space-between; font-size: 0.7rem; color: var(--text-secondary); margin-top: 2px; }

/* Character Filter Bar */
.char-filter-row {
    display: flex;
    gap: 16px;
    flex-wrap: wrap;
}

.char-filter-group {
    min-width: 160px;
    flex: 1;
}

.char-filter-search {
    flex: 2;
    min-width: 200px;
}

/* Dual-range slider */
.dual-range-wrap {
    position: relative;
    height: 28px;
}

.dual-range {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 28px;
    -webkit-appearance: none;
    appearance: none;
    background: transparent;
    pointer-events: none;
    margin: 0;
}

.dual-range::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--primary);
    border: 2px solid #1e1e2e;
    cursor: pointer;
    pointer-events: auto;
    position: relative;
    z-index: 1;
}

.dual-range::-moz-range-thumb {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--primary);
    border: 2px solid #1e1e2e;
    cursor: pointer;
    pointer-events: auto;
}

.dual-range::-webkit-slider-runnable-track {
    height: 4px;
    background: transparent;
}

.dual-range::-moz-range-track {
    height: 4px;
    background: transparent;
}

.dual-range-max {
    z-index: 1;
}

.dual-range-track {
    position: absolute;
    top: 12px;
    left: 0;
    right: 0;
    height: 4px;
    background: var(--bg-dark);
    border-radius: 2px;
    pointer-events: none;
}

.dual-range-fill {
    position: absolute;
    top: 0;
    height: 100%;
    background: var(--primary);
    border-radius: 2px;
}

/* Filter summary badge */
#char-filter-summary:not(:empty) {
    padding: 2px 10px;
    border-radius: 10px;
    background: rgba(99, 102, 241, 0.15);
    color: #a5b4fc;
    border: 1px solid rgba(99, 102, 241, 0.3);
    font-weight: 500;
}

/* ============================================
   Gen Image Popup — 2x2 grid
   ============================================ */
.gen-popup-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    padding: 8px 0;
}
.gen-popup-slot {
    position: relative;
    aspect-ratio: 1;
    background: var(--bg-dark);
    border-radius: 8px;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px solid transparent;
}
.gen-popup-slot img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}
.gen-popup-slot.marked-delete {
    border-color: #ef4444;
    opacity: 0.45;
}
.gen-popup-slot.marked-primary {
    border-color: #22c55e;
}
.gen-popup-slot .slot-overlay {
    position: absolute;
    inset: 0;
    display: flex;
    opacity: 0;
    transition: opacity 0.15s;
}
.gen-popup-slot:hover .slot-overlay,
.gen-popup-slot.marked-delete .slot-overlay,
.gen-popup-slot.marked-primary .slot-overlay {
    opacity: 1;
}
.gen-popup-slot .slot-btn-delete {
    position: absolute;
    top: 6px;
    right: 6px;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: rgba(239, 68, 68, 0.85);
    color: #fff;
    border: none;
    font-size: 16px;
    line-height: 28px;
    text-align: center;
    cursor: pointer;
    z-index: 2;
}
.gen-popup-slot .slot-btn-primary {
    position: absolute;
    bottom: 6px;
    right: 6px;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: rgba(34, 197, 94, 0.85);
    color: #fff;
    border: none;
    font-size: 16px;
    line-height: 28px;
    text-align: center;
    cursor: pointer;
    z-index: 2;
}

/* ============================================
   Lightbox
   ============================================ */
.lightbox-overlay {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 10001;
}
.lightbox-overlay img {
    max-width: 90vw;
    max-height: 85vh;
    object-fit: contain;
    border-radius: 8px;
}
.lightbox-close {
    position: absolute;
    top: 16px;
    right: 24px;
    background: none;
    border: none;
    color: #fff;
    font-size: 2.5rem;
    cursor: pointer;
    z-index: 10002;
    line-height: 1;
}
.lightbox-info {
    margin-top: 8px;
    color: rgba(255,255,255,0.7);
    font-size: 0.85rem;
    text-align: center;
}

/* ============================================
   Character Gallery Grid
   ============================================ */
.char-gallery-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 12px;
}
.char-gallery-item {
    position: relative;
    border-radius: 8px;
    overflow: hidden;
    background: var(--bg-dark);
    cursor: pointer;
}
.char-gallery-item img {
    width: 100%;
    aspect-ratio: 1;
    object-fit: cover;
    display: block;
}
.char-gallery-item .gallery-badge {
    position: absolute;
    top: 6px;
    left: 6px;
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 0.7rem;
    font-weight: 600;
    background: rgba(34, 197, 94, 0.9);
    color: #fff;
}
.char-gallery-item .gallery-info {
    padding: 4px 6px;
    font-size: 0.7rem;
    color: var(--text-muted);
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.char-gallery-item .gallery-actions {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    opacity: 0;
    background: rgba(0,0,0,0.4);
    transition: opacity 0.15s;
}
.char-gallery-item:hover .gallery-actions {
    opacity: 1;
}
.char-gallery-item .gallery-actions button {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: none;
    font-size: 18px;
    line-height: 36px;
    text-align: center;
    cursor: pointer;
    color: #fff;
}
.char-gallery-item .gallery-actions .ga-activate {
    background: rgba(34, 197, 94, 0.9);
}
.char-gallery-item .gallery-actions .ga-delete {
    background: rgba(239, 68, 68, 0.9);
}
.char-gallery-item.gallery-fade-out {
    transition: opacity 0.3s, transform 0.3s;
    opacity: 0;
    transform: scale(0.9);
}

/* Player online/offline status dot */
.player-status-dot {
    display: inline-block;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    margin-right: 4px;
    vertical-align: middle;
    flex-shrink: 0;
    border: 1px solid rgba(0, 0, 0, 0.3);
}
.player-status-dot.online {
    background: #22c55e;
    box-shadow: 0 0 6px rgba(34, 197, 94, 0.7);
}
.player-status-dot.offline {
    background: #6b7280;
    opacity: 0.6;
}

/* Connection status banner (player.html) */
.connection-banner {
    padding: 6px 12px;
    text-align: center;
    font-size: 0.8rem;
    font-weight: 600;
    transition: all 0.3s;
}
.connection-banner.connected { background: #166534; color: #bbf7d0; }
.connection-banner.reconnecting { background: #92400e; color: #fef08a; }
.connection-banner.disconnected { background: #991b1b; color: #fecaca; }

/* Join code display */
.join-code-display {
    font-family: monospace;
    font-size: 1.6rem;
    font-weight: 700;
    letter-spacing: 0.3em;
    color: var(--primary);
    background: var(--bg-dark);
    padding: 8px 16px;
    border-radius: 8px;
    display: inline-block;
    user-select: all;
}

/* Toast Notifications */
#toast-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 10000;
    display: flex;
    flex-direction: column;
    gap: 8px;
    pointer-events: none;
}

.toast {
    pointer-events: auto;
    min-width: 280px;
    max-width: 420px;
    padding: 12px 40px 12px 16px;
    border-radius: 8px;
    font-size: 0.9rem;
    line-height: 1.4;
    color: #fff;
    box-shadow: 0 4px 12px rgba(0,0,0,0.4);
    animation: toastSlideIn 0.3s ease-out;
    position: relative;
}

.toast-success { background: #059669; border-left: 4px solid #34d399; }
.toast-error   { background: #b91c1c; border-left: 4px solid #f87171; }
.toast-info    { background: #1e40af; border-left: 4px solid #60a5fa; }

.toast-close {
    position: absolute;
    top: 8px;
    right: 10px;
    background: none;
    border: none;
    color: rgba(255,255,255,0.7);
    font-size: 1.1rem;
    cursor: pointer;
    padding: 0 4px;
    line-height: 1;
}
.toast-close:hover { color: #fff; }

.toast-fade-out {
    animation: toastFadeOut 0.3s ease-in forwards;
}

@keyframes toastSlideIn {
    from { opacity: 0; transform: translateX(40px); }
    to   { opacity: 1; transform: translateX(0); }
}
@keyframes toastFadeOut {
    from { opacity: 1; transform: translateX(0); }
    to   { opacity: 0; transform: translateX(40px); }
}

/* Global Settings toggle button groups — uniform height */
.gd-toggle-group {
    display: flex;
    gap: 6px;
}
.gd-toggle-group .btn {
    flex: 1;
    text-align: center;
    min-height: 36px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

/* Behavioral System info icon */
.btn-behavioral-info {
    background: none;
    border: 1px solid var(--border);
    color: var(--primary);
    width: 24px;
    height: 24px;
    border-radius: 50%;
    font-size: 1rem;
    line-height: 1;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    transition: all 0.2s;
}
.btn-behavioral-info:hover {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

/* Character Sheet - Behavioral Panel styles */

.behavioral-section {
    margin-bottom: 16px;
}

.behavioral-section-title {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 8px;
    display: flex;
    align-items: center;
    gap: 6px;
}

/* Trait bars */
.trait-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 5px;
}

.trait-label {
    width: 120px;
    font-size: 0.8rem;
    color: var(--text-secondary);
    text-align: right;
    flex-shrink: 0;
}

.trait-bar-bg {
    flex: 1;
    height: 14px;
    background: var(--bg-input);
    border-radius: 7px;
    overflow: hidden;
    position: relative;
}

.trait-bar-fill {
    height: 100%;
    border-radius: 7px;
    transition: width 0.4s ease;
}

.trait-value {
    width: 32px;
    font-size: 0.75rem;
    color: var(--text-primary);
    text-align: right;
    flex-shrink: 0;
    margin-right: 25px;
    font-weight: 500;
}

/* Structured items (goals/fears/taboos) */
.structured-item {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    padding: 6px 8px;
    background: var(--bg-card);
    border-radius: 6px;
    margin-bottom: 4px;
    font-size: 0.82rem;
}

.structured-item-text {
    flex: 1;
    color: var(--text-primary);
}

.structured-item-meta {
    font-size: 0.7rem;
    color: var(--text-secondary);
    white-space: nowrap;
}

.priority-badge {
    display: inline-block;
    padding: 1px 6px;
    border-radius: 9999px;
    font-size: 0.65rem;
    font-weight: 600;
    text-transform: uppercase;
}

.priority-low { background: #334155; color: #94a3b8; }
.priority-medium { background: #1e3a5f; color: #60a5fa; }
.priority-high { background: #7c2d12; color: #fb923c; }
.priority-critical { background: #7f1d1d; color: #f87171; }

/* Severity bar (inline small) */
.severity-bar {
    display: inline-block;
    width: 50px;
    height: 6px;
    background: var(--bg-input);
    border-radius: 3px;
    overflow: hidden;
    vertical-align: middle;
}

.severity-fill {
    height: 100%;
    border-radius: 3px;
}

/* Relationship cards */
.relationship-card {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 10px;
    background: var(--bg-card);
    border-radius: 6px;
    margin-bottom: 4px;
}

.relationship-name {
    font-size: 0.82rem;
    font-weight: 500;
    color: var(--text-primary);
    min-width: 80px;
}

.relationship-scores {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    flex: 1;
}

.relationship-score {
    font-size: 0.7rem;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    gap: 3px;
}

.relationship-score-val {
    font-weight: 600;
    color: var(--text-primary);
}

.relationship-stance {
    font-size: 0.7rem;
    padding: 1px 6px;
    border-radius: 9999px;
    background: var(--bg-input);
    color: var(--text-secondary);
}

.behavioral-empty {
    color: var(--text-secondary);
    font-style: italic;
    font-size: 0.8rem;
    padding: 12px 0;
    text-align: center;
}

/* ── Spiderweb two-column layout ── */

.behavioral-two-col {
    display: flex;
    gap: 24px;
}

.behavioral-col-left {
    flex: 0 0 520px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.behavioral-col-right {
    flex: 1;
    min-width: 0;
    overflow-x: hidden;
    overflow-y: auto;
    max-height: 72vh;
}

#spiderweb-container {
    width: 500px;
    height: 500px;
    background: var(--bg-card);
    border-radius: 12px;
    border: 1px solid var(--border);
    position: relative;
}

#spiderweb-container svg {
    width: 100%;
    height: 100%;
}

/* Ring circles */
.spiderweb-ring {
    fill: none;
    stroke: var(--border);
    stroke-width: 0.5;
    stroke-dasharray: 2 3;
}

.spiderweb-ring-label {
    font-size: 9px;
    fill: var(--text-secondary);
    opacity: 0.5;
}

/* Coupling edges */
.coupling-edge {
    stroke-width: 1.2;
    fill: none;
    opacity: 0.25;
    transition: opacity 0.2s;
}

.coupling-edge.positive { stroke: #22c55e; }
.coupling-edge.negative { stroke: #ef4444; }
.coupling-edge.highlighted { opacity: 0.7; stroke-width: 2; }

/* Trait nodes */
.trait-node {
    cursor: grab;
    transition: r 0.15s;
}

.trait-node:hover { filter: brightness(1.3); }
.trait-node.locked { cursor: not-allowed; opacity: 0.5; }
.trait-node.dragging { cursor: grabbing; }
.trait-node.changed { stroke: #f59e0b; stroke-width: 2; }

.trait-node-label {
    font-size: 9px;
    fill: var(--text-secondary);
    text-anchor: middle;
    pointer-events: none;
    user-select: none;
}

.trait-node-value {
    font-size: 7px;
    fill: var(--text-primary);
    text-anchor: middle;
    pointer-events: none;
    font-weight: 600;
}

.lock-icon {
    font-size: 8px;
    fill: var(--text-secondary);
    pointer-events: none;
}

/* Spiderweb controls */
.spiderweb-controls {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 0 4px;
}

.spiderweb-slider-label {
    font-size: 0.75rem;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    gap: 6px;
}

.spiderweb-slider-label input[type="range"] {
    width: 120px;
    accent-color: var(--primary);
}

/* Diff preview table */
.spiderweb-diff {
    max-height: 180px;
    overflow-y: auto;
}

.spiderweb-diff table {
    width: 100%;
    font-size: 0.75rem;
    border-collapse: collapse;
}

.spiderweb-diff th {
    text-align: left;
    color: var(--text-secondary);
    font-weight: 500;
    padding: 3px 6px;
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    background: var(--bg-card);
}

.spiderweb-diff td {
    padding: 3px 6px;
    color: var(--text-primary);
}

.spiderweb-diff .delta-positive { color: #22c55e; }
.spiderweb-diff .delta-negative { color: #ef4444; }

.spiderweb-actions {
    display: flex;
    gap: 8px;
    padding: 0 4px;
}

/* ── Turn Inspector (debug log) ── */

.turn-inspector {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 12px;
    margin-top: 8px;
}

.turn-inspector-header {
    display: flex;
    gap: 8px;
    align-items: center;
    margin-bottom: 12px;
    flex-wrap: wrap;
}

.turn-inspector-section {
    margin-bottom: 12px;
}

.turn-inspector-section-title {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 4px;
}

.turn-inspector table {
    width: 100%;
    font-size: 0.75rem;
    border-collapse: collapse;
}

.turn-inspector th {
    text-align: left;
    color: var(--text-secondary);
    font-weight: 500;
    padding: 3px 6px;
    border-bottom: 1px solid var(--border);
}

.turn-inspector td {
    padding: 3px 6px;
    color: var(--text-primary);
}

/* ── Compare replay report ── */

.compare-report {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 16px;
}

.compare-turn-row {
    display: grid;
    grid-template-columns: 50px 1fr 1fr;
    gap: 8px;
    padding: 8px 0;
    border-bottom: 1px solid var(--border);
    font-size: 0.8rem;
}

.compare-turn-row.divergent {
    background: rgba(239, 68, 68, 0.08);
}

.compare-turn-num {
    font-weight: 600;
    color: var(--text-secondary);
    text-align: center;
}

.compare-metrics {
    display: flex;
    gap: 16px;
    margin-bottom: 12px;
    flex-wrap: wrap;
}

.compare-metric {
    background: var(--bg-input);
    border-radius: 8px;
    padding: 8px 16px;
    text-align: center;
}

.compare-metric-val {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-primary);
}

.compare-metric-label {
    font-size: 0.7rem;
    color: var(--text-secondary);
}

/* ── Compare viewer popup styles ── */

.compare-viewer-header {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    align-items: center;
    margin-bottom: 12px;
}

.compare-viewer-header h2 {
    font-size: 1.1rem;
    font-weight: 700;
    flex: 1;
}

.compare-viewer-progress {
    background: var(--bg-input);
    border-radius: 8px;
    height: 24px;
    margin-bottom: 12px;
    overflow: hidden;
    position: relative;
}

.compare-viewer-progress-bar {
    height: 100%;
    background: linear-gradient(90deg, var(--accent), #6366f1);
    border-radius: 8px;
    transition: width 0.4s ease;
}

.compare-viewer-controls {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: center;
    margin-bottom: 12px;
    padding: 8px 12px;
    background: var(--bg-card);
    border-radius: 8px;
    border: 1px solid var(--border);
}

.compare-viewer-controls label {
    font-size: 0.75rem;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    gap: 4px;
    cursor: pointer;
}

.compare-viewer-turn-pair {
    display: grid;
    grid-template-columns: 60px 1fr 1fr;
    gap: 8px;
    padding: 10px 8px;
    border-bottom: 1px solid var(--border);
    font-size: 0.82rem;
    border-left: 3px solid transparent;
}

.compare-viewer-turn-pair.divergent {
    border-left-color: var(--accent-danger, #ef4444);
    background: rgba(239, 68, 68, 0.06);
}

.compare-viewer-turn-pair.unaligned {
    border-left-color: #f59e0b;
    background: rgba(245, 158, 11, 0.06);
}

.compare-viewer-divbar {
    height: 4px;
    background: var(--bg-input);
    border-radius: 2px;
    margin-top: 6px;
    overflow: hidden;
}

.compare-viewer-divbar-fill {
    height: 100%;
    border-radius: 2px;
    transition: width 0.3s;
}

.compare-viewer-state-delta {
    margin-top: 6px;
    padding: 6px 8px;
    background: var(--bg-input);
    border-radius: 4px;
    font-size: 0.72rem;
}

@media (max-width: 900px) {
    .behavioral-two-col { flex-direction: column; }
    .behavioral-col-left { flex: none; width: 100%; }
    .behavioral-col-right { max-height: none; }
    #spiderweb-container { width: 100%; height: 400px; }
}

/* Mobile live-session tab bar — hidden on desktop */
.mobile-live-tabs { display: none; }
