/* Philosopher's Quest - Modern AI-Driven Design */

:root {
    --bg-primary: #0f0f0f;
    --bg-secondary: #1a1a1a;
    --bg-tertiary: #242424;
    --bg-hover: #2a2a2a;
    --bg-active: #333;
    --text-primary: #ffffff;
    --text-secondary: #a0a0a0;
    --text-muted: #666;
    --accent: #1a73e8;
    --accent-hover: #4a9afa;
    --accent-glow: rgba(26, 115, 232, 0.25);
    --success: #22c55e;
    --warning: #f59e0b;
    --danger: #ef4444;
    --border: #2a2a2a;
    --border-light: #333;
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 16px;
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.3);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.4);
    --shadow-lg: 0 8px 24px rgba(0,0,0,0.5);
    --sidebar-width: 280px;
    --transition: 0.2s ease;
}

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

body {
    font-family: 'Google Sans', 'Google Sans Text', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    overflow: hidden;
    line-height: 1.5;
}

.app { display: flex; height: 100vh; }

/* ---- Sidebar ---- */
.sidebar {
    width: var(--sidebar-width);
    background: var(--bg-secondary);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    flex-shrink: 0;
}

.game-stats {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
}

/* ---- Stat Card ---- */

.stat-card {
    background: var(--bg-tertiary);
    border-radius: var(--radius-md);
    padding: 12px;
    text-align: center;
}

.stat-label {
    display: block;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
    margin-bottom: 4px;
}

.stat-value {
    font-size: 24px;
    font-weight: 700;
    color: var(--accent);
}

.section-label {
    display: block;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
    margin-bottom: 8px;
}

.collapsible-toggle {
    cursor: pointer;
    user-select: none;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.collapsible-toggle:hover {
    color: var(--text-secondary);
}

.toggle-arrow {
    font-size: 10px;
    transition: transform 0.2s ease;
}

.collapsible-toggle.collapsed .toggle-arrow {
    transform: rotate(-90deg);
}

.collapsible-toggle.collapsed + .inventory-grid,
.collapsible-toggle.collapsed + .objects-grid {
    display: none;
}

.item-counter { color: var(--text-secondary); }

/* ---- Inventory & Objects ---- */
.inventory-section {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
}

.inventory-grid,
.objects-grid {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.inventory-item,
.object-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    background: var(--bg-tertiary);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: var(--transition);
    font-size: 14px;
    border: 1px solid transparent;
}

.inventory-item:hover,
.object-item:hover {
    background: var(--bg-hover);
    border-color: var(--border-light);
}

.item-icon { font-size: 18px; }

.inventory-item.treasure {
    background: linear-gradient(135deg, rgba(251,191,36,0.12), transparent);
    border: 1px solid rgba(251,191,36,0.25);
}

.inventory-item.magic {
    background: linear-gradient(135deg, rgba(26,115,232,0.12), transparent);
    border: 1px solid rgba(26,115,232,0.25);
}

.lamp-toggle {
    margin-left: auto;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    border: 1px solid var(--border);
    background: transparent;
    cursor: pointer;
    font-size: 14px;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    flex-shrink: 0;
}
.lamp-toggle.lamp-on {
    color: #22c55e;
    border-color: #22c55e;
    text-shadow: 0 0 6px rgba(34,197,94,0.6);
}
.lamp-toggle.lamp-on:hover {
    background: rgba(34,197,94,0.15);
}
.lamp-toggle.lamp-off {
    color: #ef4444;
    border-color: #ef4444;
}
.lamp-toggle.lamp-off:hover {
    background: rgba(239,68,68,0.15);
    color: #f87171;
    border-color: #f87171;
}
.lamp-toggle.lamp-dead {
    color: var(--text-muted);
    opacity: 0.4;
    cursor: default;
}

.empty-state {
    color: var(--text-muted);
    font-size: 13px;
    font-style: italic;
    padding: 8px 0;
}

/* ---- Status ---- */
.status-section {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
}

.status-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 13px;
    color: var(--text-secondary);
    margin-bottom: 10px;
}

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

.status-indicator { font-weight: 500; }
.status-indicator.active { color: var(--success); }

.mini-bar {
    width: 80px;
    height: 6px;
    background: var(--bg-primary);
    border-radius: 3px;
    overflow: hidden;
}

.mini-bar-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--warning), var(--success));
    border-radius: 3px;
    transition: width 0.5s ease;
}
.mini-bar-fill.torch {
    background: linear-gradient(90deg, #e74c3c, #e67e22);
}
.mini-bar-fill.fatigue {
    background: linear-gradient(90deg, #2ecc71, #e74c3c);
    border-radius: 3px;
}

/* ---- Mechanics Panel ---- */
.mechanics-section {
    padding: 12px 20px;
    border-bottom: 1px solid var(--border);
}
.mechanics-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 12px;
    color: var(--text-secondary);
    margin-bottom: 6px;
    gap: 6px;
}
.mechanics-row:last-child { margin-bottom: 0; }
.mechanics-row .mech-label {
    display: flex;
    align-items: center;
    gap: 4px;
    white-space: nowrap;
}
.mechanics-row .mech-value {
    font-weight: 600;
    color: var(--text-primary);
    text-align: right;
    white-space: nowrap;
}
.mech-value.danger { color: var(--danger, #e74c3c); }
.mech-value.success { color: var(--success, #2ecc71); }
.mech-value.warning { color: var(--warning, #f39c12); }

/* ---- Room Help Button ---- */
.help-btn {
    position: absolute;
    top: 12px;
    right: 12px;
    z-index: 20;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: 2px solid var(--accent, #5b9dd9);
    background: var(--bg-secondary, #1e1e1e);
    color: var(--accent, #5b9dd9);
    font-size: 18px;
    font-weight: 700;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    box-shadow: 0 2px 8px rgba(0,0,0,0.3);
    opacity: 0.85;
}
.help-btn:hover {
    background: var(--accent, #5b9dd9);
    color: var(--bg-primary, #121212);
    opacity: 1;
    transform: scale(1.1);
}
.help-btn.hidden { display: none; }

.voice-btn {
    position: absolute;
    top: 12px;
    right: 56px;
    z-index: 20;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: 2px solid var(--accent, #5b9dd9);
    background: var(--bg-secondary, #1e1e1e);
    color: var(--accent, #5b9dd9);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    box-shadow: 0 2px 8px rgba(0,0,0,0.3);
    opacity: 0.85;
}
.voice-btn:hover {
    background: var(--accent, #5b9dd9);
    color: var(--bg-primary, #121212);
    opacity: 1;
    transform: scale(1.1);
}
.voice-btn.tts-muted {
    opacity: 0.35;
    border-color: var(--border);
    color: var(--text-secondary);
}
.voice-btn.tts-muted:hover {
    opacity: 0.7;
    border-color: var(--accent, #5b9dd9);
    color: var(--accent, #5b9dd9);
    background: var(--bg-secondary, #1e1e1e);
}

.fullscreen-btn {
    position: absolute;
    top: 12px;
    right: 100px;
    z-index: 20;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: 2px solid var(--accent, #5b9dd9);
    background: var(--bg-secondary, #1e1e1e);
    color: var(--accent, #5b9dd9);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    box-shadow: 0 2px 8px rgba(0,0,0,0.3);
    opacity: 0.85;
}
.fullscreen-btn:hover {
    background: var(--accent, #5b9dd9);
    color: var(--bg-primary, #121212);
    opacity: 1;
    transform: scale(1.1);
}
.fullscreen-btn .hidden { display: none; }

.scene-view { position: relative; }

/* ---- Undo/Redo Bar ---- */
.undo-redo-bar {
    position: absolute;
    bottom: 8px;
    right: 8px;
    display: flex;
    gap: 4px;
    z-index: 20;
}
.undo-btn, .redo-btn {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: 1px solid var(--border);
    background: var(--bg-secondary);
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s, color 0.2s, opacity 0.2s;
    opacity: 0.7;
    padding: 0;
}
.undo-btn:hover, .redo-btn:hover, .save-slot-btn:hover, .load-slot-btn:hover {
    background: var(--accent);
    color: #fff;
    opacity: 1;
}
.bar-sep {
    width: 1px;
    height: 20px;
    background: var(--border);
    opacity: 0.5;
    align-self: center;
}
.save-slot-btn, .load-slot-btn {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: 1px solid var(--border);
    background: var(--bg-secondary);
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s, color 0.2s, opacity 0.2s;
    opacity: 0.7;
    padding: 0;
}

/* ---- Sidebar Footer ---- */
.sidebar-footer {
    margin-top: auto;
    padding: 16px 20px;
    display: flex;
    gap: 10px;
    border-top: 1px solid var(--border);
}

.sidebar-btn {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    font-size: 13px;
    font-family: inherit;
    cursor: pointer;
    transition: var(--transition);
}

.sidebar-btn:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

#settings-btn {
    flex: 0;
    padding: 10px 12px;
}

/* ---- Main Content ---- */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.chat-container {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
}

/* ---- Welcome Screen ---- */
.welcome-screen {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100%;
    padding: 40px;
}

.welcome-content {
    max-width: 480px;
    text-align: center;
}

.welcome-icon { font-size: 64px; margin-bottom: 24px; }

.welcome-icon-img {
    width: 120px;
    height: auto;
    border-radius: var(--radius-md);
    margin-bottom: 24px;
    box-shadow: var(--shadow-md);
}

.welcome-content h1 {
    font-size: 32px;
    font-weight: 700;
    margin-bottom: 8px;
    background: linear-gradient(135deg, var(--text-primary), var(--accent));
    background-clip: text;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.welcome-subtitle {
    font-size: 16px;
    color: var(--accent);
    margin-bottom: 20px;
}

.welcome-desc {
    font-size: 15px;
    color: var(--text-secondary);
    line-height: 1.7;
    margin-bottom: 32px;
}

.api-setup { text-align: left; }

.api-setup label {
    display: block;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 8px;
}

.api-input-group { display: flex; gap: 10px; }

.api-input-group input {
    flex: 1;
    padding: 14px 16px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-size: 14px;
    font-family: inherit;
    outline: none;
    transition: var(--transition);
}

.api-input-group input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

.api-hint {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 12px;
}

/* ---- Buttons ---- */
.btn-primary {
    padding: 14px 24px;
    background: var(--accent);
    border: none;
    border-radius: var(--radius-md);
    color: white;
    font-size: 14px;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: var(--transition);
    white-space: nowrap;
}

.btn-primary:hover { background: var(--accent-hover); transform: translateY(-1px); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

.btn-secondary {
    padding: 14px 24px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-size: 14px;
    font-weight: 500;
    font-family: inherit;
    cursor: pointer;
    transition: var(--transition);
}

.btn-secondary:hover { background: var(--bg-hover); }

.btn-danger {
    padding: 12px 20px;
    background: transparent;
    border: 1px solid var(--danger);
    border-radius: var(--radius-md);
    color: var(--danger);
    font-size: 13px;
    font-weight: 500;
    font-family: inherit;
    cursor: pointer;
    transition: var(--transition);
    width: 100%;
}

.btn-danger:hover { background: var(--danger); color: white; }

/* ---- Chat Messages ---- */
.chat-messages {
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.message {
    max-width: 85%;
    animation: messageIn 0.3s ease;
}

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

.message.user { align-self: flex-end; }
.message.ai { align-self: flex-start; }

.message-content {
    padding: 16px 20px;
    border-radius: var(--radius-lg);
    font-size: 15px;
    line-height: 1.7;
    white-space: pre-wrap;
    word-wrap: break-word;
}

.message.user .message-content {
    background: var(--accent);
    color: white;
    border-bottom-right-radius: 4px;
}

.message.ai .message-content {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-bottom-left-radius: 4px;
}

.message.system .message-content {
    background: transparent;
    border: 1px dashed var(--border);
    color: var(--text-muted);
    font-style: italic;
    text-align: center;
}

/* ---- Scene View ---- */
.scene-view {
    display: flex;
    flex-direction: column;
    padding: 0;
    position: relative;
    height: 100%;
    overflow: hidden;
}

.scene-image-wrap {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--bg-primary);
}

.scene-image {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    animation: fadeIn 0.6s ease;
}

.scene-image-wrap::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 100%;
    background:
        linear-gradient(to bottom, rgba(0,0,0,0.88) 0%, rgba(0,0,0,0.55) 25%, rgba(0,0,0,0.10) 45%, rgba(0,0,0,0.10) 55%, rgba(0,0,0,0.55) 75%, rgba(0,0,0,0.88) 100%);
    pointer-events: none;
}

/* ---- Manuscript Panel ---- */
.manuscript-panel {
    position: absolute;
    top: 20px;
    right: 20px;
    z-index: 15;
    max-width: 320px;
    min-width: 200px;
    animation: manuscriptSlide 0.6s ease;
}

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

/* ---- Objects Here Panel (bottom-right of scene) ---- */
.objects-panel {
    display: flex;
    justify-content: flex-end;
    margin-bottom: 8px;
}

.objects-panel .objects-grid {
    display: grid;
    grid-template-columns: repeat(5, auto);
    gap: 5px;
    direction: rtl;
}

.objects-panel .objects-grid > * {
    direction: ltr;
}

.objects-panel .objects-grid:empty,
.objects-panel .objects-grid:has(> .empty-state:only-child) {
    display: none;
}

.objects-panel .empty-state {
    display: none;
}

.objects-panel .object-item {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 4px 10px;
    border-radius: 14px;
    font-size: 12px;
    color: rgba(255, 255, 255, 0.88);
    background: rgba(0, 0, 0, 0.55);
    border: 1px solid rgba(255, 255, 255, 0.15);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    cursor: pointer;
    transition: background 0.15s ease;
    white-space: nowrap;
}

.objects-panel .object-item:hover {
    background: rgba(0, 0, 0, 0.75);
    border-color: rgba(255, 255, 255, 0.3);
}

.manuscript-inner {
    background:
        linear-gradient(135deg, #f5e6c8 0%, #e8d5a8 25%, #f0ddb8 50%, #e2c896 75%, #ecdbb0 100%);
    border: none;
    border-radius: 3px;
    padding: 22px 24px 20px;
    box-shadow:
        0 2px 20px rgba(0,0,0,0.5),
        inset 0 0 40px rgba(139,109,56,0.12),
        inset 0 1px 0 rgba(255,255,255,0.3);
    position: relative;
    overflow: hidden;
}

/* Aged paper texture overlay */
.manuscript-inner::before {
    content: '';
    position: absolute;
    inset: 0;
    background:
        radial-gradient(ellipse at 20% 80%, rgba(139,90,43,0.08) 0%, transparent 50%),
        radial-gradient(ellipse at 80% 20%, rgba(139,90,43,0.06) 0%, transparent 50%),
        radial-gradient(ellipse at 50% 50%, rgba(160,120,60,0.04) 0%, transparent 70%);
    pointer-events: none;
}

/* Torn/deckled edge effect */
.manuscript-inner::after {
    content: '';
    position: absolute;
    top: -1px;
    left: -1px;
    right: -1px;
    bottom: -1px;
    border: 2px solid rgba(139,109,56,0.25);
    border-radius: 3px;
    pointer-events: none;
}

.manuscript-label {
    font-family: 'Georgia', 'Times New Roman', serif;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 2.5px;
    color: #6b4e2a;
    margin-bottom: 10px;
    padding-bottom: 8px;
    border-bottom: 1px solid rgba(107,78,42,0.25);
    position: relative;
    z-index: 1;
}

.manuscript-body {
    font-family: 'Georgia', 'Times New Roman', serif;
    font-size: 14px;
    line-height: 1.75;
    color: #3d2b14;
    position: relative;
    z-index: 1;
    font-style: italic;
}

/* Warning-type manuscript */
.manuscript-panel[data-type="warning"] .manuscript-inner {
    background:
        linear-gradient(135deg, #f5e0c0 0%, #ecd0a0 25%, #f0d8b0 50%, #e8c898 75%, #ecdbb0 100%);
    border-left: 4px solid #8b4513;
}

.manuscript-panel[data-type="warning"] .manuscript-label {
    color: #8b2500;
}

.manuscript-panel[data-type="warning"] .manuscript-body {
    color: #4a1c0a;
    font-weight: 500;
}

/* Inscription-type manuscript */
.manuscript-panel[data-type="inscription"] .manuscript-body {
    text-align: center;
    font-size: 16px;
    font-weight: 600;
    letter-spacing: 1px;
}

/* ---- Sidebar Tooltip ---- */
.sidebar-tooltip {
    display: none;
    position: fixed;
    z-index: 9999;
    max-width: 280px;
    padding: 10px 14px;
    background: #1a1a1a;
    border: 1px solid rgba(255,255,255,0.15);
    border-radius: 8px;
    box-shadow: 0 4px 16px rgba(0,0,0,0.6);
    font-size: 12px;
    line-height: 1.5;
    color: rgba(255,255,255,0.88);
    font-style: italic;
    font-family: 'Google Sans', 'Google Sans Text', -apple-system, BlinkMacSystemFont, sans-serif;
    pointer-events: none;
    animation: tooltipFade 0.15s ease;
}

@keyframes tooltipFade {
    from { opacity: 0; }
    to { opacity: 1; }
}

.scene-text-overlay {
    position: relative;
    z-index: 10;
    display: flex;
    flex-direction: column;
    height: 100%;
    padding: 0 48px;
    overflow: hidden;
}

.scene-top-content {
    flex: 1 1 auto;
    overflow: hidden;
    padding-top: 24px;
}

.scene-bottom-content {
    flex-shrink: 0;
    padding-bottom: 12px;
}

.scene-room-desc {
    padding: 0 0 12px;
    font-size: 18px;
    line-height: 1.5;
    color: rgba(255,255,255,0.92);
    font-style: italic;
    font-weight: 500;
    border-bottom: 1px solid rgba(255,255,255,0.12);
    margin: 0 0 14px;
    text-shadow: 0 1px 8px rgba(0,0,0,0.8);
}

.scene-narrative {
    padding: 0;
    font-size: 15px;
    line-height: 1.7;
    color: rgba(255,255,255,0.92);
    word-wrap: break-word;
    animation: fadeIn 0.4s ease;
    text-shadow: 0 1px 4px rgba(0,0,0,0.6);
    display: flex;
    flex-direction: column;
    gap: 12px;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* ---- Narrative Block Components ---- */

/* Description block — main room text */
.narr-desc {
    font-size: 18px;
    line-height: 1.7;
    color: rgba(255,255,255,0.90);
}

/* Sign / inscription / notice block */
.narr-sign {
    background: rgba(255,255,255,0.06);
    border: 1px solid rgba(255,255,255,0.12);
    border-radius: 8px;
    padding: 12px 16px;
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    position: relative;
}

.narr-sign-label {
    display: block;
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    color: rgba(255,255,255,0.40);
    margin-bottom: 6px;
    font-weight: 600;
}

.narr-sign-body {
    font-size: 14px;
    line-height: 1.6;
    color: rgba(255,255,255,0.88);
    font-style: italic;
}

/* Warning block */
.narr-warning {
    background: rgba(239,68,68,0.08);
    border: 1px solid rgba(239,68,68,0.25);
    border-left: 3px solid rgba(239,68,68,0.6);
    border-radius: 8px;
    padding: 10px 14px;
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
}

.narr-warning-label {
    display: block;
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    color: rgba(239,68,68,0.7);
    margin-bottom: 4px;
    font-weight: 700;
}

.narr-warning-body {
    font-size: 14px;
    line-height: 1.5;
    color: rgba(255,255,255,0.88);
}

/* Items / objects listing */
.narr-items {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    align-items: center;
}

.narr-items-label {
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 1.2px;
    color: rgba(255,255,255,0.40);
    font-weight: 600;
    margin-right: 4px;
    white-space: nowrap;
}

.narr-item-chip {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 4px 10px;
    background: rgba(255,255,255,0.07);
    border: 1px solid rgba(255,255,255,0.12);
    border-radius: 16px;
    font-size: 13px;
    color: rgba(255,255,255,0.85);
    white-space: nowrap;
}

.narr-item-chip .chip-icon {
    font-size: 14px;
}

/* Hint / system note block */
.narr-hint {
    background: rgba(26,115,232,0.08);
    border: 1px solid rgba(26,115,232,0.20);
    border-radius: 8px;
    padding: 8px 14px;
    font-size: 13px;
    line-height: 1.5;
    color: rgba(255,255,255,0.75);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
}

/* Object descriptions seen in room */
.narr-objects {
    display: flex;
    flex-direction: column;
    gap: 4px;
    font-size: 14px;
    line-height: 1.5;
    color: rgba(255,255,255,0.78);
    font-style: italic;
}

/* Welcome / system message block */
.narr-welcome {
    font-size: 13px;
    line-height: 1.5;
    color: rgba(255,255,255,0.55);
}

/* Inscription / carved text */
.narr-inscription {
    background: rgba(255,255,255,0.04);
    border: 1px solid rgba(255,255,255,0.08);
    border-radius: 6px;
    padding: 8px 14px;
    font-style: italic;
    font-size: 14px;
    line-height: 1.5;
    color: rgba(255,255,255,0.75);
    text-align: center;
}

/* ---- Directions in Scene View ---- */
.scene-directions {
    padding: 8px 0 0;
    flex-shrink: 0;
}

/* ---- AI / Action Response Area ---- */
.ai-response-area {
    margin-bottom: 8px;
    padding: 12px 16px;
    background: rgba(0, 0, 0, 0.55);
    border: 1px solid rgba(255,255,255,0.10);
    border-radius: 10px;
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    font-size: 14px;
    line-height: 1.6;
    color: rgba(255,255,255,0.88);
    font-style: italic;
    text-shadow: 0 1px 4px rgba(0,0,0,0.6);
    animation: fadeIn 0.3s ease;
}

.ai-response-area .response-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    cursor: pointer;
    user-select: none;
    padding: 2px 0;
}

.ai-response-area .response-header:hover .response-label,
.ai-response-area .response-header:hover .response-chevron {
    color: rgba(255,255,255,0.7);
}

.ai-response-area .response-chevron {
    font-size: 10px;
    color: rgba(255,255,255,0.35);
    transition: color 0.2s;
}

.ai-response-area .response-label {
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    color: rgba(255,255,255,0.45);
    font-style: normal;
}

.ai-response-area .response-text {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-top: 4px;
    transition: max-height 0.3s ease, opacity 0.2s ease;
    max-height: 500px;
    opacity: 1;
    overflow: hidden;
}

.ai-response-area .response-text.collapsed {
    max-height: 0;
    opacity: 0;
    margin-top: 0;
}

.directions-display {
    margin-top: 0;
    padding-top: 0;
}

.directions-label {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
    margin-bottom: 10px;
}

.directions-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.direction-btn {
    padding: 8px 16px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: 20px;
    color: var(--text-secondary);
    font-size: 13px;
    font-family: inherit;
    cursor: pointer;
    transition: var(--transition);
    white-space: nowrap;
}

.direction-btn:hover {
    background: var(--accent);
    border-color: var(--accent);
    color: white;
}

/* ---- Input Container ---- */
.input-container {
    padding: 20px 24px;
    background: var(--bg-secondary);
    border-top: 1px solid var(--border);
}

.input-wrapper {
    display: flex;
    gap: 12px;
    margin-bottom: 12px;
}

.input-wrapper input {
    flex: 1;
    padding: 16px 20px;
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    color: var(--text-primary);
    font-size: 15px;
    font-family: inherit;
    outline: none;
    transition: var(--transition);
}

.input-wrapper input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

.input-wrapper input:disabled { opacity: 0.5; }

.send-btn {
    width: 52px;
    height: 52px;
    background: var(--accent);
    border: none;
    border-radius: var(--radius-lg);
    color: white;
    cursor: pointer;
    transition: var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.send-btn:hover:not(:disabled) {
    background: var(--accent-hover);
    transform: scale(1.05);
}

.send-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

/* ---- Quick Actions ---- */
.quick-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    align-items: center;
}

.quick-stats {
    margin-left: auto;
    display: flex;
    gap: 14px;
    align-items: center;
}

.quick-stat {
    font-size: 13px;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    gap: 5px;
}

.quick-stat-label {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
}

.quick-btn {
    padding: 8px 16px;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 20px;
    color: var(--text-secondary);
    font-size: 13px;
    font-family: inherit;
    cursor: pointer;
    transition: var(--transition);
}

.quick-btn:hover {
    border-color: var(--accent);
    color: var(--accent);
}

.mic-btn {
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 50%;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--text-secondary);
    transition: var(--transition);
    flex-shrink: 0;
    margin-top: 4px;
}
.mic-btn:hover {
    border-color: var(--accent);
    color: var(--accent);
}
.mic-btn.mic-active {
    background: rgba(239, 68, 68, 0.15);
    border-color: #ef4444;
    color: #ef4444;
    animation: mic-pulse 1.5s ease-in-out infinite;
}
.mic-btn.mic-disabled {
    opacity: 0.3;
    pointer-events: none;
    animation: none;
}
@keyframes mic-pulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.3); }
    50% { box-shadow: 0 0 0 6px rgba(239, 68, 68, 0); }
}
.stt-interim {
    color: var(--text-secondary) !important;
    font-style: italic !important;
}

/* ---- End Screen ---- */
.end-screen-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
    transition: background 1s ease;
    backdrop-filter: blur(0);
}

.end-screen-overlay.visible {
    background: rgba(0, 0, 0, 0.85);
    backdrop-filter: blur(12px);
}

.end-screen {
    text-align: center;
    max-width: 728px;
    padding: 48px 40px;
    opacity: 0;
    transform: translateY(30px) scale(0.95);
    transition: opacity 1s ease 0.3s, transform 1s ease 0.3s;
}

.end-screen-overlay.visible .end-screen {
    opacity: 1;
    transform: translateY(0) scale(1);
}

.end-icon {
    font-size: 64px;
    margin-bottom: 20px;
}

.end-title {
    font-size: 36px;
    font-weight: 600;
    color: #fff;
    margin-bottom: 20px;
    letter-spacing: 1px;
}

.end-narrative {
    font-size: 17px;
    line-height: 1.8;
    color: rgba(255,255,255,0.8);
    margin-bottom: 32px;
    font-style: italic;
}

.end-stats {
    display: flex;
    justify-content: center;
    gap: 40px;
    margin-bottom: 36px;
}

.end-stat {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.end-stat-val {
    font-size: 32px;
    font-weight: 700;
    color: var(--accent-hover, #4a9afa);
}

.end-stat-label {
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: rgba(255,255,255,0.5);
    margin-top: 4px;
}

.end-new-game {
    padding: 14px 32px;
    font-size: 16px;
    border-radius: var(--radius-lg);
    cursor: pointer;
    border: none;
    background: var(--accent);
    color: #fff;
    font-family: inherit;
    font-weight: 500;
    transition: background 0.2s;
}

.end-new-game:hover {
    background: var(--accent-hover);
}

.end-retry {
    padding: 14px 32px;
    font-size: 16px;
    border-radius: var(--radius-lg);
    cursor: pointer;
    border: 2px solid var(--accent);
    background: transparent;
    color: var(--accent);
    font-family: inherit;
    font-weight: 500;
    transition: background 0.2s, color 0.2s;
    margin-bottom: 8px;
}

.end-retry:hover {
    background: var(--accent);
    color: #fff;
}

/* ---- Modal ---- */
/* ---- Confirm Dialog ---- */
.confirm-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
    backdrop-filter: blur(0);
    transition: background 0.2s, backdrop-filter 0.2s;
}
.confirm-overlay.visible {
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(6px);
}
.confirm-dialog {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    width: 90%;
    max-width: 380px;
    box-shadow: var(--shadow-lg);
    transform: scale(0.92) translateY(10px);
    opacity: 0;
    transition: transform 0.2s ease-out, opacity 0.2s;
}
.confirm-overlay.visible .confirm-dialog {
    transform: scale(1) translateY(0);
    opacity: 1;
}
.confirm-header {
    padding: 20px 24px 0;
    font-size: 17px;
    font-weight: 600;
    color: var(--text-primary);
}
.confirm-body {
    padding: 12px 24px 24px;
    font-size: 14px;
    color: var(--text-secondary);
    line-height: 1.5;
}
.confirm-actions {
    display: flex;
    gap: 10px;
    padding: 0 24px 20px;
    justify-content: flex-end;
}
.confirm-btn-cancel,
.confirm-btn-primary,
.confirm-btn-danger {
    padding: 10px 20px;
    font-size: 14px;
    font-family: inherit;
    font-weight: 500;
    border-radius: var(--radius-md, 8px);
    cursor: pointer;
    border: none;
    transition: background 0.15s, transform 0.1s;
}
.confirm-btn-cancel {
    background: var(--bg-hover, #2a2a2a);
    color: var(--text-secondary);
}
.confirm-btn-cancel:hover {
    background: var(--border);
    color: var(--text-primary);
}
.confirm-btn-primary {
    background: var(--accent);
    color: #fff;
}
.confirm-btn-primary:hover {
    background: var(--accent-hover);
    transform: scale(1.02);
}
.confirm-btn-danger {
    background: #d33;
    color: #fff;
}
.confirm-btn-danger:hover {
    background: #e44;
    transform: scale(1.02);
}

/* ---- Settings Modal ---- */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    backdrop-filter: blur(4px);
}

.modal {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    width: 90%;
    max-width: 440px;
    box-shadow: var(--shadow-lg);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 24px;
    border-bottom: 1px solid var(--border);
}

.modal-header h3 { font-size: 18px; font-weight: 600; }

.modal-close {
    width: 32px;
    height: 32px;
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 24px;
    cursor: pointer;
    border-radius: var(--radius-sm);
    transition: var(--transition);
}

.modal-close:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.modal-body { padding: 24px; }

.setting-group { margin-bottom: 20px; }
.setting-group:last-child { margin-bottom: 0; }

.setting-group label {
    display: block;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 8px;
}

.setting-group input,
.setting-group select {
    width: 100%;
    padding: 12px 14px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 14px;
    font-family: inherit;
    outline: none;
    transition: var(--transition);
}

.setting-group input:focus,
.setting-group select:focus {
    border-color: var(--accent);
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    padding: 16px 24px;
    border-top: 1px solid var(--border);
}

/* ---- Cheat Panel ---- */
.cheat-row {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 16px;
    border-bottom: 1px solid var(--border);
    font-size: 13px;
}
.cheat-row:last-child { border-bottom: none; }
.cheat-held { background: rgba(76, 175, 80, 0.08); }
.cheat-icon { font-size: 16px; width: 24px; text-align: center; flex-shrink: 0; }
.cheat-name { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cheat-loc { font-size: 11px; opacity: 0.5; width: 70px; text-align: right; flex-shrink: 0; overflow: hidden; text-overflow: ellipsis; }
.cheat-btn-add, .cheat-btn-remove {
    padding: 2px 10px;
    border: 1px solid var(--border);
    border-radius: 4px;
    background: var(--bg-secondary);
    color: var(--text-primary);
    cursor: pointer;
    font-size: 11px;
    flex-shrink: 0;
}
.cheat-btn-add:hover { background: var(--accent); color: #fff; }
.cheat-btn-remove:hover { background: #c62828; color: #fff; }

/* ---- Thinking Indicator ---- */
.thinking-indicator {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 20px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 24px;
    box-shadow: var(--shadow-md);
    z-index: 100;
}

.thinking-dots { display: flex; gap: 4px; }

.thinking-dots span {
    width: 8px;
    height: 8px;
    background: var(--accent);
    border-radius: 50%;
    animation: bounce 1.4s infinite ease-in-out both;
}

.thinking-dots span:nth-child(1) { animation-delay: -0.32s; }
.thinking-dots span:nth-child(2) { animation-delay: -0.16s; }

@keyframes bounce {
    0%, 80%, 100% { transform: scale(0); }
    40% { transform: scale(1); }
}

.thinking-text {
    font-size: 13px;
    color: var(--text-secondary);
}

.speech-indicator {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 18px;
    background: var(--bg-secondary);
    border: 1px solid var(--accent);
    border-radius: 24px;
    box-shadow: 0 0 16px rgba(99, 102, 241, 0.25);
    z-index: 100;
}

.speech-bars { display: flex; gap: 3px; align-items: center; }

.speech-bars span {
    width: 3px;
    background: var(--accent);
    border-radius: 2px;
    animation: speech-bar 1s ease-in-out infinite;
}
.speech-bars span:nth-child(1) { height: 12px; animation-delay: 0s; }
.speech-bars span:nth-child(2) { height: 18px; animation-delay: 0.15s; }
.speech-bars span:nth-child(3) { height: 10px; animation-delay: 0.3s; }
.speech-bars span:nth-child(4) { height: 16px; animation-delay: 0.45s; }

@keyframes speech-bar {
    0%, 100% { transform: scaleY(0.4); opacity: 0.5; }
    50% { transform: scaleY(1); opacity: 1; }
}

.speech-text {
    font-size: 13px;
    color: var(--accent);
    white-space: nowrap;
}

.speech-interrupt {
    display: inline-block;
    padding: 2px 8px;
    margin-left: 8px;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid var(--border-light);
    border-radius: 4px;
    font-family: inherit;
    font-size: 11px;
    font-weight: 600;
    color: var(--text-secondary);
    letter-spacing: 0.5px;
}

.speech-interrupt-label {
    font-size: 11px;
    color: var(--text-secondary);
    margin-left: 4px;
}

/* ---- Utility ---- */
.hidden { display: none !important; }

/* ---- Scrollbar ---- */
::-webkit-scrollbar { width: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--border-light); }

/* ---- Responsive ---- */
@media (max-width: 768px) {
    .sidebar { display: none; }
    .main-content { width: 100%; }
}

/* ---- 3D Map Overlay ---- */
/* ===== MAP OVERLAY ===== */

.map-overlay {
    position: fixed;
    inset: 0;
    z-index: 900;
    background: rgba(10, 10, 10, 0.97);
    display: flex;
    flex-direction: column;
    backdrop-filter: blur(8px);
}

.map-header {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 12px 24px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.map-header h3 {
    font-size: 16px;
    font-weight: 600;
    margin-right: auto;
}

.map-close-btn {
    width: 36px;
    height: 36px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    font-size: 20px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
}
.map-close-btn:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.map-container {
    flex: 1;
    position: relative;
    overflow: hidden;
}

/* --- Map Viewer (tube map canvas) --- */

.map-viewer {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    position: relative;
}

.map-ctrl-btn {
    width: 36px;
    height: 36px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 20px;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
    line-height: 1;
}
.map-ctrl-btn:hover {
    background: var(--bg-hover);
}
.map-ctrl-fit {
    font-size: 12px;
    font-weight: 500;
}
