:root {
    /* D&D Reference Design - Strict Red/Gold Theme */
    --fang-bg-color: #fdfbf7;
    /* Parchment Light */
    --fang-text-color: #1a1a1a;
    --fang-card-bg: #ffffff;
    --fang-nav-bg: #f4f1ea;
    --fang-border-color: #dcd6cc;

    /* Strict Theme Colors */
    --fang-primary-red: #8B0000;
    /* Dark D&D Red */
    --fang-accent-gold: #D4AF37;
    /* Metallic Gold */
    --fang-header-text: #ffffff;
    --fang-canvas-bg: #fbf9f4;
    /* Slightly darker parchment for canvas */

    --fang-font-main: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    --fang-shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.1);
    --fang-shadow-md: 0 4px 6px rgba(0, 0, 0, 0.1);
}

.fang-app-window .fang-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    /* Added to prevent canvas overflow */
}

/* --- Container Frame --- */
.fang-app-container .container {
    display: flex;
    flex: 1;
    overflow: hidden;
    height: 100%;
}

/* Sidebar Styling */
.fang-app-container .sidebar-base {
    width: 300px;
    background: var(--fang-bg-color);
    font-family: var(--fang-font-main);
    color: var(--fang-text-color);
}

.fang-app-window .window-content {
    padding: 0;
    overflow: hidden;
    background: var(--fang-bg-color);
}

.fang-app-container {
    display: flex;
    height: 100%;
    width: 100%;
    margin: 0;
    padding: 0;
    background: var(--fang-bg-color);
    font-family: var(--fang-font-main);
    color: var(--fang-text-color);
}

.fang-app-container * {
    box-sizing: border-box;
}

/* GM Only Elements */
body.role-player .fang-app-container .gm-only {
    display: none !important;
}

/* Sidebar Styling */
.fang-app-container .sidebar {
    width: 340px;
    background-color: var(--fang-nav-bg);
    border-right: 2px solid var(--fang-primary-red);
    box-shadow: var(--fang-shadow-sm);
    display: flex;
    flex-direction: column;
    z-index: 10;
    overflow-y: auto;
}

.fang-app-container .sidebar-header {
    background-color: var(--fang-primary-red);
    color: var(--fang-header-text);
    padding: 15px 20px;
    border-bottom: 2px solid var(--fang-accent-gold);
}

.fang-app-container .sidebar-header h1 {
    font-size: 1.4rem;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 0px;
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--fang-header-text);
    border: none;
}

/* --- Edit Lock Banner --- */
.fang-app-container .lock-banner {
    padding: 8px 12px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: #e9e4d9;
    border-bottom: 1px solid var(--fang-border-color);
    font-size: 0.9rem;
    transition: all 0.3s ease;
}

.fang-app-container .lock-banner.no-editor {
    border-left: 4px solid #aaa;
}

.fang-app-container .lock-banner.i-am-editor {
    background: rgba(139, 0, 0, 0.05);
    border-left: 4px solid var(--fang-primary-red);
}

.fang-app-container .lock-banner.someone-else-editing {
    background: #eee;
    border-left: 4px solid var(--fang-accent-gold);
    animation: pulse-border 2s infinite;
}

@keyframes pulse-border {
    0% {
        border-left-color: var(--fang-accent-gold);
    }

    50% {
        border-left-color: #f3e5ab;
    }

    100% {
        border-left-color: var(--fang-accent-gold);
    }
}

.fang-app-container .lock-info {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 600;
    color: #444;
}

.fang-lock-btn {
    background: var(--fang-primary-red);
    color: white;
    border: 1px solid var(--fang-accent-gold);
    border-radius: 4px;
    padding: 4px 10px;
    font-size: 0.8rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 5px;
    font-family: var(--fang-font-main);
    transition: background 0.2s;
}

.fang-lock-btn:hover {
    background: #a00;
}

.fang-lock-btn.active {
    background: var(--fang-accent-gold);
    color: var(--fang-primary-red);
}

/* Disabled UI State */
.fang-app-container .sidebar-locked .control-group,
.fang-app-container .tab-locked .control-group {
    opacity: 0.6;
    pointer-events: none;
    filter: grayscale(0.5);
    position: relative;
}

.fang-app-container .sidebar-locked .control-group::after,
.fang-app-container .tab-locked .control-group::after {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 100;
}

/* --- Canvas Lock Indicator --- */
.fang-app-container .canvas-lock-indicator {
    position: absolute;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 1000;
    background: rgba(253, 251, 247, 0.9);
    padding: 8px 20px;
    border-radius: 30px;
    border: 2px solid var(--fang-accent-gold);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
    display: flex;
    align-items: center;
    gap: 12px;
    font-weight: 700;
    font-size: 1.1rem;
    color: var(--fang-primary-red);
    pointer-events: none;
    animation: slide-down 0.4s cubic-bezier(0.18, 0.89, 0.32, 1.28);
}

@keyframes slide-down {
    from {
        transform: translate(-50%, -100%);
        opacity: 0;
    }

    to {
        transform: translate(-50%, 0);
        opacity: 1;
    }
}

.fang-app-container .canvas-lock-indicator i {
    font-size: 1.2rem;
    color: var(--fang-accent-gold);
}

.fang-app-container .canvas-lock-indicator.hidden,
.fang-app-container .hidden {
    display: none !important;
}

/* Add a gold accent line */
.fang-app-container .sidebar-header h1::before {
    content: "";
    display: block;
    width: 12px;
    height: 24px;
    background-color: var(--fang-accent-gold);
    border-radius: 4px;
}

.fang-app-container .sidebar-header p {
    font-size: 0.85rem;
    color: #ffd;
    font-style: italic;
    margin-top: 5px;
    margin-bottom: 0;
}

/* Tabs Navigation */
.fang-app-container .tabs-nav {
    display: flex;
    background-color: var(--fang-card-bg);
    border-bottom: 2px solid var(--fang-border-color);
}

.fang-app-container .tab-btn {
    flex: 1;
    padding: 10px 5px;
    text-align: center;
    cursor: pointer;
    font-weight: 700;
    font-size: 0.85rem;
    color: #666;
    border-bottom: 3px solid transparent;
    transition: all 0.2s ease;
    text-transform: uppercase;
}

.fang-app-container .tab-btn:hover {
    color: var(--fang-primary-red);
    background-color: rgba(139, 0, 0, 0.05);
}

.fang-app-container .tab-btn.active {
    color: var(--fang-primary-red);
    border-bottom-color: var(--fang-primary-red);
    background-color: var(--fang-nav-bg);
}

.fang-app-container .tab-btn.active i {
    color: var(--fang-accent-gold);
    text-shadow: 0 0 8px rgba(212, 175, 55, 0.8), 0 0 15px rgba(212, 175, 55, 0.4);
    animation: fangPulseGlow 2s infinite;
}

@keyframes fangPulseGlow {
    0% {
        text-shadow: 0 0 5px rgba(212, 175, 55, 0.5);
    }

    50% {
        text-shadow: 0 0 10px rgba(212, 175, 55, 0.9), 0 0 20px rgba(212, 175, 55, 0.5);
    }

    100% {
        text-shadow: 0 0 5px rgba(212, 175, 55, 0.5);
    }
}

.fang-app-container .tabs-container {
    flex: 1;
    overflow-y: auto;
}

.fang-app-container .tab-content {
    display: none;
    animation: fangFadeIn 0.3s ease;
}

.fang-app-container .tab-content.active {
    display: block;
}

@keyframes fangFadeIn {
    from {
        opacity: 0;
        transform: translateY(-5px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.fang-app-container .control-group {
    display: flex;
    flex-direction: column;
    padding: 15px 20px;
    background-color: var(--fang-card-bg);
    border-bottom: 1px solid var(--fang-border-color);
    gap: 12px;
}

.fang-app-container .control-group h3 {
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--fang-primary-red);
    text-transform: uppercase;
    margin-bottom: 4px;
    border: none;
}

/* Inputs & Selects */
.fang-app-container input[type="text"],
.fang-app-container select {
    width: 100%;
    padding: 10px 12px;
    background-color: #fff;
    border: 1px solid var(--fang-border-color);
    border-radius: 2px;
    color: var(--fang-text-color);
    font-family: var(--fang-font-main);
    font-size: 0.95rem;
    transition: all 0.2s;
    outline: none;
    height: auto;
}

.fang-app-container input[type="text"]:focus,
.fang-app-container select:focus {
    border-color: var(--fang-accent-gold);
    box-shadow: 0 0 0 2px rgba(212, 175, 55, 0.2);
}

.fang-app-container .input-row {
    display: flex;
    gap: 8px;
    align-items: stretch;
}

.fang-app-container .input-row input {
    flex: 1;
}

.fang-app-container .input-stack {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

/* Buttons */
.fang-app-container .btn {
    padding: 10px 15px;
    border: none;
    border-radius: 2px;
    font-family: var(--fang-font-main);
    font-size: 0.95rem;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s;
    text-align: center;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    box-shadow: var(--fang-shadow-sm);
    border-bottom: 2px solid rgba(0, 0, 0, 0.2);
    line-height: normal;
}

.fang-app-container .btn:active {
    transform: translateY(2px);
    border-bottom-width: 0px;
    margin-top: 2px;
}

/* Filled Button */
.fang-app-container .primary-btn {
    background-color: var(--fang-primary-red);
    color: var(--fang-header-text);
}

.fang-app-container .primary-btn:hover {
    background-color: #600000;
    box-shadow: none;
}

/* Base Buttons */
.fang-app-container .secondary-btn {
    background-color: var(--fang-nav-bg);
    color: var(--fang-text-color);
    border: 1px solid var(--fang-border-color);
    border-bottom: 2px solid rgba(0, 0, 0, 0.1);
    width: 100%;
    margin-top: 4px;
}

.fang-app-container .secondary-btn:hover {
    background-color: #ebe5dc;
    color: var(--fang-primary-red);
    box-shadow: none;
}

.fang-app-container .button-row {
    display: flex;
    gap: 8px;
    margin-top: 4px;
}

.fang-app-container .actions-group .button-row {
    display: flex;
    gap: 4px;
}

.fang-app-container .actions-group .btn {
    flex: 1;
    font-size: 0.8rem;
    padding: 8px 10px;
    height: 36px;
    white-space: nowrap;
}

/* Elevated Action Buttons */
.fang-app-container .action-btn {
    flex: 1;
    background-color: var(--fang-nav-bg);
    color: var(--fang-text-color);
    border: 1px solid var(--fang-border-color);
    border-bottom: 2px solid rgba(0, 0, 0, 0.1);
}

.fang-app-container .action-btn:hover {
    background-color: #ebe5dc;
    box-shadow: none;
}

.fang-app-container .file-label {
    margin: 0;
}

/* Canvas Area */
.fang-app-container .canvas-container {
    flex: 1;
    position: relative;
    overflow: hidden;
    background-color: #fdfbf7;
    /* Soft antique paper texture */
    background-image:
        radial-gradient(at 0% 0%, rgba(212, 175, 55, 0.03) 0px, transparent 50%),
        radial-gradient(at 100% 100%, rgba(139, 0, 0, 0.02) 0px, transparent 50%),
        radial-gradient(at 50% 50%, rgba(0, 0, 0, 0.01) 0px, transparent 100%);
    box-shadow: inset 0 0 50px rgba(220, 214, 204, 0.3);
}

.fang-app-container #graphCanvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    cursor: grab;
    display: block;
    /* Fix inline-block baseline descender gap causing scrollbars */
}

.fang-app-container #graphCanvas:active {
    cursor: grabbing;
}

.fang-app-container .fang-search-floating {
    position: absolute;
    top: 14px;
    right: 14px;
    z-index: 901;
    background: rgba(253, 251, 247, 0.9);
    border: 1px solid rgba(212, 175, 55, 0.45);
    border-radius: 8px;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.2);
    backdrop-filter: blur(2px);
    padding: 6px 8px;
}

.fang-app-container .fang-search-row {
    display: flex;
    align-items: center;
    gap: 8px;
}

.fang-app-container .fang-search-row > i {
    color: #7a2b2b;
    font-size: 0.9rem;
}

.fang-app-container #fangSearchInput {
    width: clamp(180px, 24vw, 320px);
    margin: 0;
    padding: 6px 8px;
    height: 32px;
    background: rgba(255, 255, 255, 0.92);
}

.fang-app-container .fang-search-isolate-wrap {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 0.8rem;
    color: #2e2b29;
    user-select: none;
    white-space: nowrap;
    cursor: pointer;
}

.fang-app-container .fang-search-isolate-wrap input {
    width: auto;
    margin: 0;
}

.fang-app-container #fangSearchClear {
    flex: 0 0 auto;
    width: 32px;
    min-width: 32px;
    height: 32px;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

body.fang-monitor .fang-app-container .fang-search-floating {
    display: none !important;
}

@media (max-width: 980px) {
    .fang-app-container .fang-search-floating {
        left: 14px;
        right: 14px;
    }

    .fang-app-container #fangSearchInput {
        width: 100%;
        min-width: 0;
    }

    .fang-app-container .fang-search-isolate-wrap span {
        display: none;
    }
}

/* Custom Scrollbar */
.fang-app-container .sidebar::-webkit-scrollbar {
    width: 8px;
}

.fang-app-container .sidebar::-webkit-scrollbar-track {
    background: var(--fang-nav-bg);
}

.fang-app-container .sidebar::-webkit-scrollbar-thumb {
    background-color: var(--fang-border-color);
    border-radius: 4px;
}

.fang-app-container .sidebar::-webkit-scrollbar-thumb:hover {
    background-color: #aaa;
}

/* Fullscreen Override for Players */
body #fang-app.fang-app-window.fang-fullscreen-player {
    display: flex !important;
    visibility: visible !important;
    opacity: 1 !important;
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    width: 100vw !important;
    height: 100vh !important;
    margin: 0 !important;
    padding: 0 !important;
    border: none !important;
    box-shadow: none !important;
    border-radius: 0 !important;
    z-index: 2147483647 !important;
    /* Maximum possible z-index to cover Monk's Display */
    overflow: hidden !important;
}

body #fang-app.fang-app-window.fang-fullscreen-player .sidebar {
    display: none !important;
}

/* Hide the Foundry Window Header when in fullscreen mode */
body #fang-app.fang-app-window.fang-fullscreen-player .window-header {
    display: none !important;
}

body #fang-app.fang-app-window.fang-fullscreen-player .window-content {
    background: var(--fang-bg-color) !important;
    border-radius: 0 !important;
    padding: 0 !important;
    margin: 0 !important;
    flex: 1;
    display: flex;
    flex-direction: column;
    height: 100% !important;
    width: 100% !important;
    max-height: 100vh !important;
    overflow: hidden !important;
}

body #fang-app.fang-app-window.fang-fullscreen-player .fang-app-container {
    height: 100% !important;
    width: 100% !important;
    overflow: hidden !important;
}

/* === MONITOR FULLSCREEN: Body-Level Resets === */
body.fang-monitor {
    padding: 0 !important;
    margin: 0 !important;
    overflow: hidden !important;
}

/* Hyper-specific override for Monitor Fullscreen */
html body.fang-monitor div#fang-app.fang-app-window.fang-fullscreen-player {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    inset: 0 !important;
    width: 100vw !important;
    height: 100vh !important;
    max-height: none !important;
    max-width: none !important;
    min-height: 100vh !important;
    min-width: 100vw !important;
    margin: 0 !important;
    padding: 0 !important;
    z-index: 200000 !important;
    display: flex !important;
    flex-direction: column;
    border: none !important;
    box-shadow: none !important;
}

/* Force window-content to fill in monitor mode */
html body.fang-monitor div#fang-app .window-content {
    height: 100% !important;
    max-height: none !important;
    min-height: 100% !important;
    padding: 0 !important;
    margin: 0 !important;
    overflow: hidden !important;
    flex: 1 !important;
}

body.fang-monitor #ui-bottom,
body.fang-monitor #hotbar,
body.fang-monitor #players,
body.fang-monitor #ui-top,
body.fang-monitor #ui-left,
body.fang-monitor #ui-right,
body.fang-monitor #navigation,
body.fang-monitor #controls,
body.fang-monitor #sidebar {
    display: none !important;
}

body.fang-monitor #fang-app.fang-app-window {
    top: 0 !important;
    bottom: 0 !important;
    left: 0 !important;
    right: 0 !important;
    height: 100vh !important;
    width: 100vw !important;
    max-height: none !important;
    max-width: none !important;
    min-height: 100vh !important;
    min-width: 100vw !important;
    margin: 0 !important;
    padding: 0 !important;
    position: fixed !important;
    z-index: 200000 !important;
    display: flex !important;
    border: none !important;
    box-shadow: none !important;
}

/* === MONITOR: Spotlight Readability (TV distance) === */
body.fang-monitor .fang-app-container .narrative-card {
    width: 96%;
    max-width: 1200px;
    max-height: 92%;
    padding: 46px;
    gap: 46px;
}

body.fang-monitor .fang-app-container .narrative-left-side {
    width: 300px;
    gap: 18px;
}

body.fang-monitor .fang-app-container .narrative-portrait-container {
    width: 230px;
    height: 230px;
}

body.fang-monitor .fang-app-container .narrative-content h2 {
    font-size: 3.1rem;
    margin-bottom: 18px;
}

body.fang-monitor #narrative-subtitle {
    font-size: 1.35rem;
    margin-bottom: 14px;
}

body.fang-monitor #narrative-text,
body.fang-monitor #edge-narrative-text,
body.fang-monitor #quest-spotlight-text {
    font-size: 1.55rem;
    line-height: 1.85;
}

body.fang-monitor .fang-app-container #narrative-quests-container {
    padding-top: 18px;
}

body.fang-monitor .fang-app-container .narrative-quests-header {
    font-size: 1.35rem;
    margin-bottom: 14px;
}

body.fang-monitor .fang-app-container .narrative-quest-item {
    font-size: 1.1rem;
    padding: 10px 12px;
    margin-bottom: 8px;
}

body.fang-monitor .fang-app-container .narrative-close {
    top: 22px;
    right: 22px;
    font-size: 2rem;
}

/* Custom D&D Dialog Styling */
.fang-dialog.window-app {
    font-family: var(--fang-font-main);
    border: 1px solid var(--fang-accent-gold);
    border-radius: 4px;
}

.fang-dialog,
.fang-dialog * {
    box-sizing: border-box;
}

.fang-dialog .window-header {
    background-color: var(--fang-primary-red);
    color: var(--fang-header-text);
    border-bottom: 2px solid var(--fang-accent-gold);
    border-radius: 4px 4px 0 0;
}

.fang-dialog .window-content {
    background: var(--fang-bg-color);
    color: var(--fang-text-color);
    padding: 0;
    font-size: 0.95rem;
    word-break: break-word;
    overflow-wrap: break-word;
    display: flex;
    flex-direction: column;
    max-height: 75vh;
}

.fang-dialog .dialog-content {
    padding: 15px;
    overflow-y: auto;
    flex: 1 1 auto;
    min-height: 0;
}

.fang-dialog .dialog-content .btn,
.fang-dialog .dialog-content button,
.fang-dialog .dialog-content input,
.fang-dialog .dialog-content select,
.fang-dialog .dialog-content textarea {
    max-width: 100%;
}

.fang-dialog .dialog-content .btn {
    display: block;
    width: 100%;
}

.fang-dialog hr {
    border: 0;
    border-top: 1px solid var(--fang-border-color);
    margin: 12px 0;
}

.fang-dialog .fang-dialog-section {
    margin-top: 15px;
    padding-top: 10px;
    border-top: 1px solid var(--fang-border-color);
}

.fang-dialog .fang-drop-zone {
    border: 2px dashed rgba(0, 0, 0, 0.35);
    padding: 10px;
    text-align: center;
    border-radius: 4px;
    cursor: pointer;
    position: relative;
    background: rgba(255, 255, 255, 0.6);
}

.fang-dialog .fang-drop-zone:hover {
    border-color: var(--fang-accent-gold);
}

.fang-dialog .fang-drop-zone.has-link {
    border-color: var(--fang-accent-gold);
}

.fang-dialog .fang-drop-zone-add {
    padding: 8px;
}

.fang-dialog .fang-drop-remove {
    position: absolute;
    right: 5px;
    top: 5px;
    padding: 2px 6px;
    width: auto;
}

.fang-dialog .fang-quest-item {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px;
    background: rgba(0, 0, 0, 0.02);
    border: 1px solid var(--fang-border-color);
    border-radius: 4px;
    margin-bottom: 5px;
}

.fang-dialog .dialog-buttons {
    flex-shrink: 0;
    display: flex;
    gap: 8px;
    padding: 8px 15px;
    border-top: 1px solid var(--fang-border-color);
    background: var(--fang-bg-color);
}


.fang-dialog input[type="text"] {
    width: 100%;
    padding: 8px 10px;
    background-color: #fff;
    border: 1px solid var(--fang-border-color);
    border-radius: 2px;
    color: var(--fang-text-color);
    font-family: var(--fang-font-main);
    outline: none;
    transition: all 0.2s;
    height: auto;
}

.fang-dialog input[type="text"]:focus {
    border-color: var(--fang-accent-gold);
    box-shadow: 0 0 0 2px rgba(212, 175, 55, 0.2);
}

.fang-dialog .dialog-buttons button {
    height: 34px !important;
    padding: 0 14px !important;
    font-size: 0.88rem !important;
    line-height: 34px !important;
    flex: 1;
    background-color: var(--fang-primary-red);
    color: var(--fang-header-text);
    border: none;
    border-bottom: 2px solid rgba(0, 0, 0, 0.2);
    border-radius: 2px;
    font-family: var(--fang-font-main);
    font-weight: bold;
    cursor: pointer;
    transition: background-color 0.2s;
}

.fang-dialog .dialog-buttons button:hover {
    background-color: #600000;
    box-shadow: none;
}

.fang-dialog .dialog-buttons button.cancel {
    background-color: var(--fang-nav-bg);
    color: var(--fang-primary-red);
    border: 1px solid var(--fang-border-color);
    border-bottom: 2px solid rgba(0, 0, 0, 0.1);
}

.fang-dialog .dialog-buttons button.cancel:hover {
    background-color: #ebe5dc;
}

/* --- Floating Context Menu --- */
#fang-context-menu,
#fang-edge-context-menu {
    position: absolute;
    z-index: 1000;
    width: 200px;
    background: var(--fang-card-bg);
    border: 1px solid var(--fang-border-color);
    border-radius: 6px;
    box-shadow: 0 8px 16px rgba(0, 0, 0, 0.15), 0 0 8px rgba(212, 175, 55, 0.1);
    font-family: var(--fang-font-main);
    color: var(--fang-text-color);
    overflow: hidden;
    transition: opacity 0.15s ease-in-out, transform 0.1s ease-out;
    transform: scale(0.95);
    opacity: 0;
    pointer-events: none;
    /* Ignore clicks while fading out */
}

#fang-context-menu:not(.hidden),
#fang-edge-context-menu:not(.hidden) {
    opacity: 1;
    transform: scale(1);
    pointer-events: auto;
}

#fang-context-menu ul,
#fang-edge-context-menu ul {
    list-style: none;
    margin: 0;
    padding: 5px 0;
}

.fang-app-container .ctx-item {
    padding: 10px 15px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 0.9rem;
    transition: background 0.15s, color 0.15s;
    border-left: 3px solid transparent;
}

.fang-app-container .ctx-item i {
    width: 16px;
    text-align: center;
    color: var(--fang-accent-gold);
}

.fang-app-container .ctx-item:hover {
    background: var(--fang-nav-bg);
    border-left-color: var(--fang-primary-red);
    color: var(--fang-primary-red);
}

.fang-app-container .ctx-item.danger:hover {
    background: #ffe6e6;
    border-left-color: var(--fang-primary-red);
    color: var(--fang-primary-red);
}

.fang-app-container .ctx-item.danger i {
    color: #ff4d4d;
}

/* --- Floating Hover Lore Tooltip --- */
#fang-tooltip {
    position: absolute;
    z-index: 999;
    background: rgba(255, 255, 255, 0.96);
    backdrop-filter: blur(4px);
    border: 1px solid var(--fang-accent-gold);
    border-radius: 4px;
    padding: 12px 15px;
    color: var(--fang-text-color);
    font-family: var(--fang-font-main);
    font-size: 0.95rem;
    line-height: 1.4;
    max-width: 320px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    pointer-events: none;
    /* Clicks fall through to the canvas */
    transition: opacity 0.2s ease-in-out, transform 0.2s ease-out;
    transform: translateY(10px);
    opacity: 0;
    /* Optional: A subtle glow */
    box-shadow: 0 0 15px rgba(212, 175, 55, 0.1);
    /* Prevent text overflow */
    word-break: break-word;
    overflow-wrap: break-word;
    overflow: hidden;
}

#fang-tooltip:not(.hidden) {
    opacity: 1;
    transform: translateY(0);
}

/* When lore is empty, force hidden even if JS gets confused */
#fang-tooltip:empty {
    display: none !important;
}

/* --- Narrative Spotlight Overlay --- */
.fang-narrative-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 2000;
    background: rgba(0, 0, 0, 0.2);
    backdrop-filter: blur(2px);
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 1;
    transition: opacity 0.5s ease;
}

.fang-narrative-overlay.hidden {
    opacity: 0;
    pointer-events: none;
    display: none !important;
}

.fang-app-container .narrative-card {
    background: #fdfbf7;
    border: 2px solid var(--fang-accent-gold);
    border-radius: 8px;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5), 0 0 20px rgba(212, 175, 55, 0.2);
    width: 90%;
    max-width: 850px;
    max-height: 85%;
    position: relative;
    display: flex;
    flex-direction: row;
    padding: 35px;
    gap: 35px;
    animation: fangCinemaEnter 0.6s cubic-bezier(0.16, 1, 0.3, 1);
    overflow-y: auto;
    overflow-x: hidden;
}

@keyframes fangCinemaEnter {
    from {
        opacity: 0;
        transform: scale(0.8) translateY(20px);
    }

    to {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

.fang-app-container .narrative-left-side {
    flex: 0 0 220px;
    display: flex;
    flex-direction: column;
    gap: 20px;
    align-items: center;
}

.fang-app-container .narrative-portrait-container {
    width: 180px;
    height: 180px;
    border-radius: 50%;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3), 0 0 0 2px var(--fang-accent-gold);
    overflow: hidden;
    background: white;
    flex-shrink: 0;
}

.fang-app-container .narrative-portrait-container.hidden {
    display: none;
}

.fang-app-container .narrative-portrait-container img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.fang-app-container .narrative-content {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.fang-app-container .narrative-content h2 {
    font-size: 2.2rem;
    color: var(--fang-primary-red);
    margin: 0 0 15px 0;
    border-bottom: 2px solid var(--fang-accent-gold);
    padding-bottom: 5px;
    font-weight: 800;
    text-transform: uppercase;
    word-break: break-word;
    overflow-wrap: break-word;
}

#narrative-subtitle {
    font-size: 1.1rem;
    color: var(--fang-accent-gold);
    font-style: italic;
    margin-bottom: 10px;
    font-weight: 600;
    word-break: break-word;
    overflow-wrap: break-word;
}

#narrative-text,
#edge-narrative-text {
    font-family: var(--fang-font-main);
    font-size: 1.25rem;
    line-height: 1.7;
    color: #222;
    font-style: italic;
    white-space: pre-wrap;
    word-break: break-word;
    overflow-wrap: break-word;
    margin-top: 10px;
}

.fang-app-container #narrative-quests-container {
    flex: 0 0 auto;
    width: 100%;
    border-top: 1px solid var(--fang-accent-gold);
    padding-top: 15px;
    display: flex;
    flex-direction: column;
}

.fang-app-container #narrative-quests-container.hidden {
    display: none;
}

.fang-app-container .narrative-quests-header {
    font-size: 1.25rem;
    font-weight: 800;
    text-transform: uppercase;
    color: var(--fang-primary-red);
    margin-bottom: 15px;
    border-bottom: 1px solid rgba(0, 0, 0, 0.1);
    padding-bottom: 6px;
    letter-spacing: 0.5px;
}

.fang-app-container #narrative-quests-list {
    list-style: none;
    margin: 0;
    padding: 0;
}

.fang-app-container .narrative-quest-item {
    font-family: var(--fang-font-main);
    font-size: 1.05rem;
    padding: 8px 12px;
    margin-bottom: 6px;
    background: rgba(0, 0, 0, 0.03);
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    gap: 10px;
    border-left: 3px solid transparent;
}

.fang-app-container .narrative-quest-item:hover {
    background: rgba(212, 175, 55, 0.08);
    border-left-color: var(--fang-primary-red);
    transform: translateX(4px);
    color: var(--fang-primary-red);
}

.fang-app-container .narrative-quest-item i {
    color: var(--fang-accent-gold);
}

/* --- Edge Specific Override for Spotlight --- */
.fang-app-container .edge-spotlight-card {
    max-width: 900px;
    /* Wider for dual portraits */
    justify-content: space-between;
    align-items: center;
}

.fang-app-container .edge-spotlight-card .edge-content {
    text-align: center;
    padding: 0 20px;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.fang-app-container .edge-spotlight-card h2#edge-narrative-title {
    font-size: 2rem;
    color: var(--fang-primary-red);
    margin: 0 0 15px 0;
    border-bottom: 2px solid var(--fang-accent-gold);
    padding-bottom: 5px;
    font-weight: 800;
    display: inline-block;
    align-self: center;
    text-align: center;
    word-break: break-word;
    overflow-wrap: break-word;
}

.fang-app-container .narrative-close {
    position: absolute;
    top: 15px;
    right: 15px;
    color: #888;
    cursor: pointer;
    font-size: 1.4rem;
    transition: color 0.2s;
    z-index: 10;
}

.fang-app-container .narrative-close:hover {
    color: var(--fang-primary-red);
}

/* Spectator Mode Indicator */
.fang-app-container .spectator-active-indicator {
    position: absolute;
    bottom: 20px;
    right: 20px;
    background: rgba(139, 0, 0, 0.85);
    color: white;
    padding: 8px 20px;
    border-radius: 25px;
    font-size: 0.85rem;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 1.2px;
    z-index: 1500;
    pointer-events: none;
    display: none;
    /* Shown via JS */
    align-items: center;
    gap: 10px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.4), 0 0 10px rgba(139, 0, 0, 0.4);
    border: 1px solid var(--fang-accent-gold);
}

.fang-app-container .spectator-active-indicator.active {
    display: flex;
    animation: fangFadeIn 0.3s ease;
}

.fang-app-container .spectator-active-indicator i {
    animation: fangPulseIndicator 1.5s linear infinite;
    color: #ff4d4d;
}

@keyframes fangPulseIndicator {
    0% {
        opacity: 1;
    }

    50% {
        opacity: 0.3;
    }

    100% {
        opacity: 1;
    }
}

/* --- UI Button Grouping Nest --- */
.fang-app-container .button-group-nest {
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 8px 10px;
    background: rgba(0, 0, 0, 0.03);
    border: 1px solid var(--fang-border-color);
    border-left: 3px solid var(--fang-accent-gold);
    border-radius: 4px;
    margin-bottom: 8px;
    transition: all 0.2s ease;
}

.fang-app-container .button-group-nest:hover {
    background: rgba(0, 0, 0, 0.05);
    border-color: #c0b9ae;
}

.fang-app-container .button-group-nest h4 {
    font-size: 0.7rem;
    font-weight: 800;
    text-transform: uppercase;
    color: #888;
    margin: 0 0 6px 0;
    letter-spacing: 0.8px;
    border-bottom: 1px solid rgba(0, 0, 0, 0.05);
    font-style: italic;
    margin-bottom: 10px;
    font-weight: 600;
    word-break: break-word;
    overflow-wrap: break-word;
}

#narrative-text,
#edge-narrative-text {
    font-family: var(--fang-font-main);
    font-size: 1.25rem;
    line-height: 1.7;
    color: #222;
    font-style: italic;
    white-space: pre-wrap;
    word-break: break-word;
    overflow-wrap: break-word;
    margin-top: 10px;
}

.fang-app-container #narrative-quests-container {
    flex: 0 0 auto;
    width: 100%;
    border-top: 1px solid var(--fang-accent-gold);
    padding-top: 15px;
    display: flex;
    flex-direction: column;
}

.fang-app-container #narrative-quests-container.hidden {
    display: none;
}

.fang-app-container .narrative-quests-header {
    font-size: 1.25rem;
    font-weight: 800;
    text-transform: uppercase;
    color: var(--fang-primary-red);
    margin-bottom: 15px;
    border-bottom: 1px solid rgba(0, 0, 0, 0.1);
    padding-bottom: 6px;
    letter-spacing: 0.5px;
}

.fang-app-container #narrative-quests-list {
    list-style: none;
    margin: 0;
    padding: 0;
}

.fang-app-container .narrative-quest-item {
    font-family: var(--fang-font-main);
    font-size: 1.05rem;
    padding: 8px 12px;
    margin-bottom: 6px;
    background: rgba(0, 0, 0, 0.03);
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    gap: 10px;
    border-left: 3px solid transparent;
}

.fang-app-container .narrative-quest-item:hover {
    background: rgba(212, 175, 55, 0.08);
    border-left-color: var(--fang-primary-red);
    transform: translateX(4px);
    color: var(--fang-primary-red);
}

.fang-app-container .narrative-quest-item i {
    color: var(--fang-accent-gold);
}

/* --- Edge Specific Override for Spotlight --- */
.fang-app-container .edge-spotlight-card {
    max-width: 900px;
    /* Wider for dual portraits */
    justify-content: space-between;
    align-items: center;
}

.fang-app-container .edge-spotlight-card .edge-content {
    text-align: center;
    padding: 0 20px;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.fang-app-container .edge-spotlight-card h2#edge-narrative-title {
    font-size: 2rem;
    color: var(--fang-primary-red);
    margin: 0 0 15px 0;
    border-bottom: 2px solid var(--fang-accent-gold);
    padding-bottom: 5px;
    font-weight: 800;
    display: inline-block;
    align-self: center;
    text-align: center;
    word-break: break-word;
    overflow-wrap: break-word;
}

.fang-app-container .narrative-close {
    position: absolute;
    top: 15px;
    right: 15px;
    color: #888;
    cursor: pointer;
    font-size: 1.4rem;
    transition: color 0.2s;
    z-index: 10;
}

.fang-app-container .narrative-close:hover {
    color: var(--fang-primary-red);
}

/* Spectator Mode Indicator */
.fang-app-container .spectator-active-indicator {
    position: absolute;
    bottom: 20px;
    right: 20px;
    background: rgba(139, 0, 0, 0.85);
    color: white;
    padding: 8px 20px;
    border-radius: 25px;
    font-size: 0.85rem;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 1.2px;
    z-index: 1500;
    pointer-events: none;
    display: none;
    /* Shown via JS */
    align-items: center;
    gap: 10px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.4), 0 0 10px rgba(139, 0, 0, 0.4);
    border: 1px solid var(--fang-accent-gold);
}

.fang-app-container .spectator-active-indicator.active {
    display: flex;
    animation: fangFadeIn 0.3s ease;
}

.fang-app-container .spectator-active-indicator i {
    animation: fangPulseIndicator 1.5s linear infinite;
    color: #ff4d4d;
}

@keyframes fangPulseIndicator {
    0% {
        opacity: 1;
    }

    50% {
        opacity: 0.3;
    }

    100% {
        opacity: 1;
    }
}

/* --- UI Button Grouping Nest --- */
.fang-app-container .button-group-nest {
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 8px 10px;
    background: rgba(0, 0, 0, 0.03);
    border: 1px solid var(--fang-border-color);
    border-left: 3px solid var(--fang-accent-gold);
    border-radius: 4px;
    margin-bottom: 8px;
    transition: all 0.2s ease;
}

.fang-app-container .button-group-nest:hover {
    background: rgba(0, 0, 0, 0.05);
    border-color: #c0b9ae;
}

.fang-app-container .button-group-nest h4 {
    font-size: 0.7rem;
    font-weight: 800;
    text-transform: uppercase;
    color: #888;
    margin: 0 0 6px 0;
    letter-spacing: 0.8px;
    border-bottom: 1px solid rgba(0, 0, 0, 0.05);
    padding-bottom: 2px;
}

.fang-app-container .button-group-nest .btn {
    width: 100%;
}

/* === Only-Sheet: Actor Panel Open — shift actor sheet left to make room === */
/* Applied when FANG injects the actor directory panel on the right side.     */
body.fang-actor-panel-open .window-app:not(.sidebar-popout):not(.fang-app-window):not(.fang-dialog),
body.fang-actor-panel-open .application:not(.sidebar-popout):not(.fang-app-window):not(.fang-dialog) {
    max-width: calc(100vw - 300px) !important;
    transition: none !important;
}

/* --- Background Settings & Premium Features --- */
.fang-app-container #fang-bg-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 0;
    pointer-events: none;
    transition: background-color 0.25s ease, opacity 0.25s ease;
    transform-origin: center;
    will-change: opacity, transform, filter;
    backface-visibility: hidden;
}

.fang-app-container #fang-bg-layer.no-transition {
    transition: none !important;
}

/* Texture Overlay (Grain) */
.fang-app-container .canvas-container::after {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 1;
    /* Above bg layer, below canvas */
    opacity: 0.15;
    background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Ffilter id='n' %3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.65' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
    mix-blend-mode: overlay;
}

.fang-app-container .premium-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 5px;
}

.fang-app-container .premium-badge {
    background: linear-gradient(135deg, #FFD700, #B8860B);
    color: #1a0000;
    font-size: 0.65rem;
    font-weight: 800;
    padding: 2px 6px;
    border-radius: 4px;
    text-transform: uppercase;
    box-shadow: 0 0 10px rgba(212, 175, 55, 0.4);
    border: 1px solid rgba(255, 255, 255, 0.2);
}

.fang-app-container .premium-disclaimer {
    font-size: 0.75rem;
    font-style: italic;
    color: #887b66;
    margin-top: 8px;
    line-height: 1.3;
    display: flex;
    gap: 6px;
    padding: 8px;
    background: rgba(212, 175, 55, 0.05);
    border-radius: 4px;
    border-left: 2px solid var(--fang-accent-gold);
}

.fang-app-container .bg-sub-section {
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px dashed var(--fang-border-color);
    animation: fangFadeIn 0.3s ease;
}

.fang-app-container .color-palette-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
}

.fang-app-container .color-patch {
    aspect-ratio: 1;
    border-radius: 50%; /* Make them circular for a more premium look */
    border: 2px solid rgba(255, 255, 255, 0.8);
    cursor: pointer;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
    transition: transform 0.2s, border-color 0.2s, box-shadow 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    text-shadow: 0 1px 2px rgba(0,0,0,0.5);
}

.fang-app-container .color-patch:hover {
    transform: scale(1.15);
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.3);
}

.fang-app-container .color-patch.active {
    border-color: var(--fang-accent-gold);
    box-shadow: 0 0 0 2px white, 0 0 15px var(--fang-accent-gold);
}

/* --- Background Configuration Dialog Styles (Premium Redesign) --- */
.fang-config-dialog {
    border: 1px solid var(--fang-accent-gold);
    box-shadow: 0 10px 30px rgba(0,0,0,0.8);
}

.fang-config-dialog .window-content {
    background: var(--fang-bg-color);
    color: var(--fang-text-color);
    padding: 0;
    border: none;
}

.fang-config-dialog .window-header {
    background-color: var(--fang-primary-red) !important;
    border-bottom: 2px solid var(--fang-accent-gold) !important;
}

/* More robust selectors for Foundry's V13+ app structure */
#fang-background-config {
    border: 1px solid var(--fang-accent-gold);
    box-shadow: var(--fang-shadow-md);
    border-radius: 4px;
}

#fang-background-config .window-content {
    background: var(--fang-bg-color);
    color: var(--fang-text-color);
    padding: 0;
}

#fang-background-config .window-header {
    background-color: var(--fang-primary-red) !important;
    border-bottom: 2px solid var(--fang-accent-gold) !important;
}

.background-config-container {
    padding: 15px;
}

.bg-config-section {
    margin-top: 14px;
    animation: fangSlideIn 0.3s ease-out;
    padding: 0;
    background: transparent;
    border: none;
    border-radius: 0;
}

.bg-config-section.hidden {
    display: none;
}

.bg-config-section label {
    display: block;
    margin-bottom: 10px;
    font-weight: bold;
    color: var(--fang-primary-red);
    text-transform: uppercase;
    letter-spacing: 1px;
    font-size: 0.75rem;
}

.background-config-container select,
.background-config-container input[type="text"] {
    height: 34px;
    background: #fff;
    color: var(--fang-text-color);
    border: 1px solid var(--fang-border-color);
    border-radius: 2px;
    padding: 0 10px;
}

.background-config-container .flexrow.gap-5 {
    display: flex;
    gap: 6px;
    align-items: center;
}

.background-config-container .file-picker.small-btn {
    flex: 0 0 auto;
    width: 38px;
    height: 34px;
    border: 1px solid rgba(212, 175, 55, 0.35);
    border-radius: 2px;
    background: #fff;
    color: var(--fang-text-color);
    cursor: pointer;
    transition: transform 0.12s ease, border-color 0.12s ease, box-shadow 0.12s ease;
}

.background-config-container .file-picker.small-btn:hover {
    transform: translateY(-1px);
    border-color: var(--fang-accent-gold);
    box-shadow: 0 0 10px rgba(212, 175, 55, 0.25);
}

.background-config-container .slider-group {
    margin-top: 14px;
    padding-top: 10px;
    border-top: 1px dashed rgba(0, 0, 0, 0.10);
}

.background-config-container .slider-label {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    font-size: 0.78rem;
    color: #6b5f4f;
    margin-bottom: 6px;
}

.background-config-container input[type="range"] {
    width: 100%;
}

.background-config-container .color-palette-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 8px;
    justify-items: center;
}

.background-config-container .color-patch {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: 2px solid rgba(0, 0, 0, 0.14);
    cursor: pointer;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
    transition: transform 0.2s, border-color 0.2s, box-shadow 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    text-shadow: 0 1px 2px rgba(0,0,0,0.5);
}

.background-config-container .color-patch:hover {
    transform: scale(1.15);
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.3);
}

.background-config-container .color-patch.active {
    border-color: var(--fang-accent-gold);
    box-shadow: 0 0 0 2px white, 0 0 15px var(--fang-accent-gold);
}

.background-config-container .preset-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
}

.background-config-container .preset-tile {
    position: relative;
    height: 56px;
    border-radius: 8px;
    border: 1px solid var(--fang-border-color);
    overflow: hidden;
    cursor: pointer;
    padding: 0;
    background: #fff;
    transition: transform 0.12s ease, border-color 0.12s ease, box-shadow 0.12s ease;
}

.background-config-container .preset-tile::after {
    content: "";
    position: absolute;
    inset: 0;
    background: linear-gradient(90deg, rgba(0,0,0,0.45) 0%, rgba(0,0,0,0.10) 60%, rgba(0,0,0,0) 100%);
    pointer-events: none;
}

.background-config-container .preset-tile:hover {
    transform: translateY(-1px);
    border-color: rgba(212, 175, 55, 0.55);
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.18);
}

.background-config-container .preset-tile.active {
    border-color: var(--fang-accent-gold);
    box-shadow: 0 0 0 2px rgba(212, 175, 55, 0.25), 0 8px 20px rgba(0, 0, 0, 0.18);
}

.background-config-container .preset-name {
    position: absolute;
    left: 10px;
    top: 50%;
    transform: translateY(-50%);
    z-index: 1;
    color: #fff;
    font-weight: 800;
    font-size: 0.85rem;
    text-shadow: 0 2px 6px rgba(0,0,0,0.5);
    letter-spacing: 0.2px;
    text-align: left;
}

.background-config-container .preset-tile.preset-parchment {
    background-color: #f3e6cf;
    background-image:
        radial-gradient(circle at 18% 38%, rgba(120, 75, 35, 0.10) 0%, transparent 58%),
        radial-gradient(circle at 78% 62%, rgba(120, 75, 35, 0.08) 0%, transparent 62%),
        linear-gradient(0deg, rgba(90, 60, 30, 0.04), rgba(255,255,255,0) 45%),
        repeating-linear-gradient(90deg, rgba(120, 90, 50, 0.018) 0 2px, rgba(255, 255, 255, 0) 2px 7px),
        url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='260' height='260'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.95' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='260' height='260' filter='url(%23n)' opacity='.10'/%3E%3C/svg%3E"),
        radial-gradient(circle at 50% 55%, transparent 62%, rgba(60, 40, 20, 0.18) 100%);
    background-blend-mode: multiply, multiply, normal, normal, overlay, normal;
}

.background-config-container .preset-tile.preset-dark {
    background: linear-gradient(135deg, #0f2a16 0%, #1f3b1e 55%, #2b2012 100%);
    background-image:
        radial-gradient(circle at 22% 30%, rgba(255, 238, 180, 0.13) 0%, transparent 45%),
        radial-gradient(circle at 74% 68%, rgba(255, 238, 180, 0.10) 0%, transparent 52%),
        radial-gradient(circle at 50% 55%, rgba(0, 0, 0, 0.35) 0%, transparent 65%),
        url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='320' height='320'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.8' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='320' height='320' filter='url(%23n)' opacity='.14'/%3E%3C/svg%3E"),
        radial-gradient(circle at 50% 50%, transparent 58%, rgba(0,0,0,0.45) 100%);
    background-size: cover, cover, cover, 260px 260px, cover;
    background-blend-mode: screen, screen, multiply, overlay, normal;
}

.background-config-container .preset-tile.preset-starfield {
    background-color: #020205;
    background-image:
        radial-gradient(circle at 18% 28%, rgba(170, 80, 255, 0.28) 0%, transparent 48%),
        radial-gradient(circle at 78% 68%, rgba(60, 140, 255, 0.22) 0%, transparent 52%),
        radial-gradient(circle at 88% 22%, rgba(0, 200, 180, 0.10) 0%, transparent 45%),
        url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='320' height='320'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.75' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='320' height='320' filter='url(%23n)' opacity='.22'/%3E%3C/svg%3E"),
        radial-gradient(rgba(255,255,255,0.85) 0.9px, transparent 1.1px),
        radial-gradient(rgba(255,255,255,0.55) 0.7px, transparent 0.9px);
    background-size: cover, cover, cover, 260px 260px, 170px 170px, 260px 260px;
    background-position: center, center, center, 0 0, 10px 30px, 60px 90px;
    background-blend-mode: screen, screen, screen, overlay, normal, normal;
}

.background-config-container .preset-tile.preset-ethereal {
    background: linear-gradient(135deg, #1a0d2e 0%, #0c2b3b 55%, #10341f 100%);
    background-image:
        radial-gradient(circle at 24% 32%, rgba(0, 255, 208, 0.14) 0%, transparent 46%),
        radial-gradient(circle at 70% 62%, rgba(170, 80, 255, 0.18) 0%, transparent 52%),
        radial-gradient(circle at 85% 20%, rgba(255, 255, 255, 0.08) 0%, transparent 40%),
        url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='360' height='360'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='360' height='360' filter='url(%23n)' opacity='.16'/%3E%3C/svg%3E"),
        radial-gradient(circle at 50% 55%, transparent 58%, rgba(0,0,0,0.40) 100%);
    background-size: cover, cover, cover, 260px 260px, cover;
    background-blend-mode: screen, screen, screen, overlay, normal;
}

.background-config-container .preset-tile.preset-stone {
    background-color: #2a2a2a;
    background-image:
        repeating-linear-gradient(135deg, rgba(255, 255, 255, 0.045) 0 1px, rgba(0, 0, 0, 0) 1px 9px),
        radial-gradient(circle at 35% 35%, rgba(0, 0, 0, 0.35) 0%, transparent 55%),
        linear-gradient(rgba(0,0,0,0.28), rgba(0,0,0,0.28));
    background-blend-mode: overlay;
}

.background-config-container .preset-tile.preset-stars {
    background-color: #000;
    background-image:
        radial-gradient(white, rgba(255,255,255,.2) 2px, transparent 40px),
        radial-gradient(white, rgba(255,255,255,.15) 1px, transparent 30px);
    background-size: 550px 550px, 350px 350px;
    background-position: 40px 60px, 130px 270px;
}

.background-config-container select:focus,
.background-config-container input[type="text"]:focus {
    border-color: var(--fang-accent-gold);
    box-shadow: 0 0 5px var(--fang-accent-gold);
}

.background-config-container hr {
    border: 0;
    border-top: 1px solid var(--fang-border-color);
    margin: 12px 0;
}

.background-config-container .premium-notice {
    margin-top: 30px;
    padding: 15px;
    background: rgba(212, 175, 55, 0.08);
    border-radius: 6px;
    border: 1px solid rgba(212, 175, 55, 0.35);
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    gap: 10px;
    box-shadow: none;
}

.background-config-container .premium-badge {
    background: var(--fang-accent-gold);
    color: #1a0a0a;
    padding: 4px 12px;
    border-radius: 20px;
    font-weight: bold;
    font-size: 0.7rem;
    text-transform: uppercase;
    box-shadow: 0 0 10px var(--fang-accent-gold);
}

.background-config-container .premium-notice p {
    font-size: 0.78rem;
    color: #d4af37;
    margin: 0;
    font-style: italic;
    line-height: 1.4;
}

@keyframes fangSlideIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}
/* Background Presets - Enhanced Visuals */
.fang-app-container #fang-bg-layer.fang-bg-preset-parchment {
    background-color: #f3e6cf;
    background-image: 
        radial-gradient(circle at 18% 38%, rgba(120, 75, 35, 0.10) 0%, transparent 58%),
        radial-gradient(circle at 78% 62%, rgba(120, 75, 35, 0.08) 0%, transparent 62%),
        linear-gradient(0deg, rgba(90, 60, 30, 0.04), rgba(255,255,255,0) 45%),
        repeating-linear-gradient(90deg, rgba(120, 90, 50, 0.018) 0 2px, rgba(255, 255, 255, 0) 2px 7px),
        url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='260' height='260'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.95' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='260' height='260' filter='url(%23n)' opacity='.10'/%3E%3C/svg%3E"),
        radial-gradient(circle at 50% 55%, transparent 62%, rgba(60, 40, 20, 0.18) 100%);
    background-blend-mode: multiply, multiply, normal, normal, overlay, normal;
    filter: sepia(0.25) contrast(1.05);
}

.fang-app-container #fang-bg-layer.fang-bg-preset-dark {
    background: linear-gradient(135deg, #0f2a16 0%, #1f3b1e 55%, #2b2012 100%);
    background-image:
        radial-gradient(circle at 22% 30%, rgba(255, 238, 180, 0.13) 0%, transparent 45%),
        radial-gradient(circle at 74% 68%, rgba(255, 238, 180, 0.10) 0%, transparent 52%),
        radial-gradient(circle at 50% 55%, rgba(0, 0, 0, 0.35) 0%, transparent 65%),
        url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='320' height='320'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.8' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='320' height='320' filter='url(%23n)' opacity='.14'/%3E%3C/svg%3E"),
        radial-gradient(circle at 50% 50%, transparent 58%, rgba(0,0,0,0.45) 100%);
    background-size: cover, cover, cover, 260px 260px, cover;
    background-blend-mode: screen, screen, multiply, overlay, normal;
}

.fang-app-container #fang-bg-layer.fang-bg-preset-starfield {
    background-color: #020205 !important;
    background-image: 
        radial-gradient(circle at 18% 28%, rgba(170, 80, 255, 0.28) 0%, transparent 48%),
        radial-gradient(circle at 78% 68%, rgba(60, 140, 255, 0.22) 0%, transparent 52%),
        radial-gradient(circle at 88% 22%, rgba(0, 200, 180, 0.10) 0%, transparent 45%),
        url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='320' height='320'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.75' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='320' height='320' filter='url(%23n)' opacity='.22'/%3E%3C/svg%3E"),
        radial-gradient(rgba(255,255,255,0.85) 0.9px, transparent 1.1px),
        radial-gradient(rgba(255,255,255,0.55) 0.7px, transparent 0.9px);
    background-size: cover, cover, cover, 260px 260px, 170px 170px, 260px 260px;
    background-position: center, center, center, 0 0, 10px 30px, 60px 90px;
    background-blend-mode: screen, screen, screen, overlay, normal, normal;
}

.fang-app-container #fang-bg-layer.fang-bg-preset-ethereal {
    background: linear-gradient(135deg, #1a0d2e 0%, #0c2b3b 55%, #10341f 100%) !important;
    background-image:
        radial-gradient(circle at 24% 32%, rgba(0, 255, 208, 0.14) 0%, transparent 46%),
        radial-gradient(circle at 70% 62%, rgba(170, 80, 255, 0.18) 0%, transparent 52%),
        radial-gradient(circle at 85% 20%, rgba(255, 255, 255, 0.08) 0%, transparent 40%),
        url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='360' height='360'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='360' height='360' filter='url(%23n)' opacity='.16'/%3E%3C/svg%3E"),
        radial-gradient(circle at 50% 55%, transparent 58%, rgba(0,0,0,0.40) 100%) !important;
    background-size: cover, cover, cover, 260px 260px, cover;
    background-blend-mode: screen, screen, screen, overlay, normal;
    opacity: 0.8;
}

.fang-app-container #fang-bg-layer.fang-bg-preset-stone {
    background-color: #2a2a2a !important;
    background-image: 
        repeating-linear-gradient(135deg, rgba(255, 255, 255, 0.045) 0 1px, rgba(0, 0, 0, 0) 1px 9px),
        radial-gradient(circle at 35% 35%, rgba(0, 0, 0, 0.35) 0%, transparent 55%),
        linear-gradient(rgba(0,0,0,0.28), rgba(0,0,0,0.28)) !important;
    background-blend-mode: overlay;
}

.fang-app-container #fang-bg-layer.fang-bg-preset-stars {
      background-color: #000 !important;
      background-image: 
        radial-gradient(white, rgba(255,255,255,.2) 2px, transparent 40px),
        radial-gradient(white, rgba(255,255,255,.15) 1px, transparent 30px) !important;
    background-size: 550px 550px, 350px 350px !important;
    background-position: 40px 60px, 130px 270px !important;
}

/* --- Narrative Sidebar & Quest Quests --- */
.fang-app-container .narrative-left-side {
    display: flex;
    flex-direction: column;
    width: 240px;
    flex-shrink: 0;
    gap: 15px;
}

.fang-app-container #narrative-quests-container {
    /* No "box" around the quest list; keep it integrated like the Spotlight body */
    background: transparent;
    border: none;
    border-radius: 0;
    padding: 14px 0 0 0;
}

.fang-app-container .narrative-quests-header {
    margin: 0 0 12px 0;
    font-size: 1.15rem;
    font-weight: 900;
    color: var(--fang-primary-red);
    text-transform: uppercase;
    border-bottom: 2px solid var(--fang-accent-gold);
    padding-bottom: 6px;
    display: flex;
    align-items: center;
    gap: 6px;
    justify-content: center;
    text-align: center;
    letter-spacing: 0.06em;
}

.fang-app-container #narrative-quests-list {
    list-style: none;
    margin: 0;
    padding: 0;
}

.fang-app-container .narrative-quest-item {
    padding: 7px 10px;
    margin-bottom: 4px;
    background: white;
    border-radius: 4px;
    border: 1px solid var(--fang-border-color);
    font-size: 0.9rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: all 0.2s;
}

.fang-app-container .narrative-quest-item:hover {
    background: var(--fang-nav-bg);
    border-color: var(--fang-accent-gold);
    color: var(--fang-primary-red);
    transform: translateX(3px);
}

.fang-app-container .narrative-quest-item i {
    color: var(--fang-accent-gold);
    font-size: 0.8rem;
}

/* --- Quest Spotlight Card (match Narrative Spotlight look) --- */
.fang-app-container .quest-spotlight-card {
    /* Keep same background/border/shadow as .narrative-card; only minor sizing tweak */
    max-width: 850px;
}

/* Improve title readability on some Foundry themes where primary red renders too dark */
#fang-quest-spotlight-overlay #quest-spotlight-title {
    color: var(--fang-primary-red);
    text-shadow: 0 1px 0 rgba(255, 255, 255, 0.75), 0 6px 18px rgba(0, 0, 0, 0.08);
    line-height: 1.15;
    padding-top: 2px; /* avoid glyph ascenders being clipped in some renderers */
}

#fang-quest-spotlight-overlay .narrative-content {
    /* Default .narrative-content uses overflow:hidden, which can clip shadows/large glyphs */
    overflow: visible;
}

#quest-spotlight-text {
    /* Mirror narrative text styling so it feels like the same Spotlight surface */
    font-family: var(--fang-font-main);
    font-size: 1.25rem;
    line-height: 1.7;
    color: #222;
    font-style: italic;
    white-space: pre-wrap;
    word-break: break-word;
    overflow-wrap: break-word;
    margin-top: 10px;
}

#quest-spotlight-text :is(h1, h2, h3, h4, h5, h6) {
    font-style: normal; /* base text is italic; headings should be crisp */
    color: var(--fang-primary-red);
    margin: 0.9em 0 0.35em;
    line-height: 1.15;
    padding-top: 2px;
    border-bottom: 2px solid rgba(212, 175, 55, 0.85);
    padding-bottom: 5px;
    text-transform: uppercase;
    letter-spacing: 0.02em;
}

/* === Only-Sheet: Instant Side-Shift & Pinned Sidebar (BULLETPROOF V13 FIX) === */

/* 1. FORCE PIN: Ensure the actor directory popout ALWAYS docks to the right sidebar area */
/* This prevents the "centered window" bug even if JS fails to apply classes. */
.actors-sidebar.sidebar-popout {
    position: fixed !important;
    right: 0px !important;
    top: 0px !important;
    left: auto !important; /* Force it out of the center */
    width: 300px !important;
    height: 100vh !important;
    max-height: 100vh !important;
    margin: 0 !important;
    border-radius: 0 !important;
    z-index: 9999 !important;
}

/* 2. SHIFT: Shift main windows to the left when the actor panel exists AND actually has content.
   Prevents Foundry v13 "ghost shells" (empty window-content) from triggering :has(). */
body.fang-actor-panel-open .sheet-only-sheet,
body:has(.actors-sidebar.sidebar-popout:has(.window-content > *)) .application.sheet.actor:not(.sidebar-popout) {
    max-width: calc(100vw - 300px) !important;
    width: calc(100vw - 300px) !important;
    transition: none !important; /* Eliminate the toggle delay requested by user */
}

/* 3. RECOVERY: Forced full width when the panel is GONE (destroys the "black void") */
body:not(.fang-actor-panel-open):not(:has(.actors-sidebar.sidebar-popout:has(.window-content > *))) .application.sheet.actor:not(.sidebar-popout),
body:not(.fang-actor-panel-open) .sheet-only-sheet {
    width: 100vw !important; /* Force true 100vw instead of just 100% */
    max-width: 100vw !important;
}

/* 4. Color the FANG Actor button red when the panel is open */
body.fang-actor-panel-open #fang-so-actors-btn,
body:has(.actors-sidebar.sidebar-popout:has(.window-content > *)) #fang-so-actors-btn {
    color: #ff3b3b !important;
    text-shadow: 0 0 10px rgba(255, 59, 59, 0.4);
}
