/* --- SCANLINES OVERLAY --- */
body::before {
    content: " ";
    display: block;
    position: absolute;
    top: 0;
    left: 0;
    bottom: 0;
    right: 0;
    background: linear-gradient(rgba(18, 16, 16, 0) 50%, rgba(0, 0, 0, 0.15) 50%), linear-gradient(90deg, rgba(255, 0, 0, 0.03), rgba(0, 255, 0, 0.01), rgba(0, 0, 255, 0.03));
    z-index: 2000;
    background-size: 100% 3px, 3px 100%;
    pointer-events: none;
    opacity: 0.5;
}

/* --- RADAR SWEEP --- */
.radar-container {
    position: relative;
    box-shadow: inset 0 0 20px rgba(0, 255, 65, 0.2);
}
.radar-sweep {
    position: absolute;
    inset: 0;
    background: conic-gradient(from 0deg, transparent 270deg, rgba(0, 255, 65, 0.3) 360deg);
    border-radius: 50%;
    pointer-events: none;
    animation: radar-rotate 4s linear infinite;
    z-index: 5;
}
@keyframes radar-rotate {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

/* --- DOSSIER PORTRAIT --- */
#avatar-container {
    max-height: 250px;
    aspect-ratio: 1/1;
    overflow: hidden;
    border: 1px solid #1a3a1a;
}
#avatar-container img {
    filter: contrast(1.1) brightness(1.1); /* Vibrant full color */
    width: 100%;
    height: 100%;
    object-fit: contain;
}

/* --- COMBAT ANIMATIONS --- */
@keyframes timer-shrink {
    from { transform: scaleX(1); }
    to { transform: scaleX(0); }
}
.timer-active {
    animation: timer-shrink 45s linear forwards;
}

/* --- COMBAT OVERLAY STYLES --- */
.combat-card {
    transition: all 0.3s ease;
    position: relative;
    overflow: hidden;
}

.opponent-card {
    border-left: 4px solid var(--term-amber) !important;
    box-shadow: inset 5px 0 15px rgba(255, 176, 0, 0.05);
}

.player-card {
    border-left: 4px solid var(--crayola-blue) !important;
    box-shadow: inset 5px 0 15px rgba(59, 130, 246, 0.05);
}

.active-intent-box {
    background: rgba(255, 176, 0, 0.02);
    animation: intent-pulse 2s infinite ease-in-out;
}

@keyframes intent-pulse {
    0% { border-color: rgba(255, 176, 0, 0.2); background: rgba(255, 176, 0, 0.02); }
    50% { border-color: rgba(255, 176, 0, 0.6); background: rgba(255, 176, 0, 0.08); }
    100% { border-color: rgba(255, 176, 0, 0.2); background: rgba(255, 176, 0, 0.02); }
}

.ability-chip {
    border: 1px solid var(--crayola-blue);
    color: var(--crayola-blue);
    background: rgba(59, 130, 246, 0.05);
    font-size: 9px;
    padding: 3px 8px;
    text-transform: uppercase;
    letter-spacing: 1px;
    cursor: pointer;
    transition: 0.1s;
}

.ability-chip:hover {
    background: var(--crayola-blue);
    color: black;
    box-shadow: 0 0 10px var(--crayola-blue);
}

.combat-stat-row {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 9px;
}

.combat-stat-label {
    width: 45px;
    flex-shrink: 0;
    color: rgba(255, 255, 255, 0.4);
    text-transform: uppercase;
    letter-spacing: 1px;
}

.combat-stat-bar-bg {
    flex-grow: 1;
    height: 4px;
    background: rgba(255, 255, 255, 0.05);
    position: relative;
    border: 1px solid rgba(255, 255, 255, 0.05);
}

.combat-stat-bar-fill {
    height: 100%;
    transition: width 0.5s ease-out;
    box-shadow: 0 0 5px currentColor;
}

@keyframes combat-shake {
    0% { transform: translate(1px, 1px) rotate(0deg); }
    10% { transform: translate(-1px, -2px) rotate(-1deg); }
    20% { transform: translate(-3px, 0px) rotate(1deg); }
    30% { transform: translate(3px, 2px) rotate(0deg); }
    40% { transform: translate(1px, -1px) rotate(1deg); }
    50% { transform: translate(-1px, 2px) rotate(-1deg); }
    60% { transform: translate(-3px, 1px) rotate(0deg); }
    70% { transform: translate(3px, 1px) rotate(-1deg); }
    80% { transform: translate(-1px, -1px) rotate(1deg); }
    90% { transform: translate(1px, 2px) rotate(0deg); }
    100% { transform: translate(1px, -2px) rotate(-1deg); }
}

.animate-combat-shake {
    animation: combat-shake 0.3s cubic-bezier(0.36, 0.07, 0.19, 0.97) both;
}

/* Phase 5.4 Astral Stat Overrides */
.stat-will-astral > .combat-stat-bar-bg {
    height: 8px !important;
}
.stat-will-astral > .combat-stat-bar-bg > .combat-stat-bar-fill {
    box-shadow: 0 0 15px var(--gm-purple);
}

.stat-phys-astral > .combat-stat-bar-bg {
    height: 2px !important;
    opacity: 0.5;
}


/* --- FLEX DENSITY --- */
#header-row, #visuals, #input-container, #footer-hud {
    flex-shrink: 0;
    width: 100%;
}
#visuals canvas, #visuals img {
    width: 100% !important;
    height: 100% !important;
    object-fit: cover !important;
}
#output {
    flex-grow: 1;
    min-height: 0;
}

/* --- PROMPT INSPECTOR --- */
#prompt-text-display {
    transition: all 0.2s ease-in-out;
    opacity: 0.4;
}
#prompt-text-display:hover {
    opacity: 1;
    background: rgba(0, 0, 0, 0.95);
    border-color: var(--term-green);
    color: var(--term-green);
    max-width: 400px;
    font-size: 10px;
}

:root {
    --term-green: #00ff41;
    --term-amber: #ffb000;
    --term-red: #ff3e3e;
    --term-bg: #050505;
    --crayola-blue: #3b82f6;
    --gm-purple: #a855f7;
    --astral-cyan: #00f5ff;
    --astral-pink: #ff00ff;
}

/* --- MOBILE NAV RAIL --- */
.nav-rail-btn {
    width: 24px;
    height: 24px;
    border: 1px solid var(--term-green);
    color: var(--term-green);
    background: transparent;
    font-size: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: 0.1s;
    opacity: 0.6;
}
.nav-rail-btn:hover, .nav-rail-btn.active {
    background: var(--term-green);
    color: black;
    opacity: 1;
    box-shadow: 0 0 8px var(--term-green);
}

/* --- RESPONSIVE SIDEBAR (MOBILE DRAWER) --- */
@media (max-width: 768px) {
    /* Main terminal takes full width */
    #main-terminal-area {
        width: 100vw !important;
        flex: 1 1 100% !important;
    }

    /* Transform Sidebar into a sliding drawer overlay */
    #right-sidebar {
        position: fixed !important;
        top: 0;
        right: -100%; /* Hidden off-screen to the right */
        width: 85vw !important; /* Covers 85% of the screen */
        height: 100dvh !important;
        z-index: 9999;
        background: rgba(5, 10, 5, 0.98) !important;
        backdrop-filter: blur(10px);
        border-left: 2px solid var(--term-green) !important;
        transition: right 0.3s ease-in-out;
        
        /* Enforce vertical stacking */
        display: flex !important;
        flex-direction: column !important;
        flex-wrap: nowrap !important;
    }

    /* When the .open class is added via JS, it slides in */
    #right-sidebar.open {
        right: 0 !important;
    }

    /* Ensure Map is visible in the mobile drawer */
    #map-canvas-container {
        display: block !important; 
    }
}

@media (max-width: 768px) {
    /* Phase 5.1: The Combat Modal Takeover */
    #combat-overlay {
        position: fixed !important;
        top: 0;
        left: 0;
        width: 100vw;
        height: 100dvh;
        z-index: 500;
        padding-bottom: 200px; /* Leave space for input container */
    }

    #input-container {
        position: fixed;
        bottom: 0;
        left: 0;
        width: 100vw;
        z-index: 501; /* Must sit above combat modal */
    }

    /* Phase 5.2: Responsive Card Stacking */
    #combat-clash {
        flex-direction: column-reverse !important;
    }
}

#header-row { z-index: 100; }
/* Ensure the root containers occupy full screen */
html, body { height: 100%; margin: 0; overflow: hidden; background: #000; }

/* Force main area to handle vertical segments without overflow leakage */
#main-terminal-area {
    height: 100dvh;
    display: flex;
    flex-direction: column;
}

/* Ensure output area handles the scrolling exclusively */
#output {
    flex: 1 1 auto;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    display: flex;
    flex-direction: column;
}

#log {
    max-width: 100%;
    break-words: break-all;
    padding-bottom: 220px; /* SPACE FOR FLOATING MOBILE CONTROLS */
}

@media (min-width: 640px) {
    #log {
        padding-bottom: 20px; /* Reset for desktop */
    }
}

/* --- MAP CANVAS --- */
/* --- NPC THUMBNAILS --- */
.npc-thumbnail-token {
    box-shadow: 0 0 10px rgba(0, 0, 0, 0.5);
    position: relative;
    overflow: hidden;
    animation: npc-pulse 4s ease-in-out infinite;
}

.npc-thumbnail-token[data-stratum="mundane"] {
    border-color: var(--term-amber);
}

.npc-thumbnail-token[data-stratum="astral"] {
    border-color: var(--gm-purple);
}

.npc-thumbnail-token[data-stratum="technate"] {
    border-color: var(--crayola-blue);
}

.npc-thumbnail-token[data-stratum="faen"] {
    border-color: var(--term-green);
}

.npc-thumbnail-token:hover {
    box-shadow: 0 0 15px currentColor;
    z-index: 50;
    animation-play-state: paused;
}

@keyframes npc-pulse {
    0% { transform: scale(1); opacity: 0.9; }
    50% { transform: scale(1.05); opacity: 1; }
    100% { transform: scale(1); opacity: 0.9; }
}

.npc-thumbnail-mini[data-stratum="mundane"] { border-color: var(--term-amber); }
.npc-thumbnail-mini[data-stratum="astral"] { border-color: var(--gm-purple); }
.npc-thumbnail-mini[data-stratum="technate"] { border-color: var(--crayola-blue); }
.npc-thumbnail-mini[data-stratum="faen"] { border-color: var(--term-green); }

#map-canvas {
    width: 100%;
    height: 100%;
    display: block;
}

/* --- COMPASS WIDGET --- */
.compass-grid {
    display: grid;
    grid-template-columns: repeat(3, 24px);
    grid-template-rows: repeat(3, 24px);
    gap: 3px;
}
.compass-btn {
    border: 1px solid var(--term-green);
    background: rgba(0, 40, 0, 0.4);
    color: var(--term-green);
    font-size: 10px;
    font-family: monospace;
    display: flex; align-items: center; justify-content: center;
    cursor: pointer; transition: 0.1s;
}
.compass-btn:not(:disabled):hover { background: var(--term-green); color: black; }
.compass-btn:disabled { 
    opacity: 0.6; 
    cursor: not-allowed; 
    border: 1px dotted rgba(0, 255, 65, 0.4); 
    color: rgba(0, 255, 65, 0.5);
    background: rgba(0, 40, 0, 0.1);
}
#compass-n { grid-column: 2; grid-row: 1; }
#compass-w { grid-column: 1; grid-row: 2; }
#compass-center { grid-column: 2; grid-row: 2; display: flex; align-items: center; justify-content: center; color: #1a3a1a; font-size: 10px; }
#compass-e { grid-column: 3; grid-row: 2; }
#compass-s { grid-column: 2; grid-row: 3; }

/* CONTEXT CHIPS */
.context-chip {
    border: 1px solid var(--term-green);
    color: var(--term-green);
    background: transparent;
    font-family: inherit;
    font-size: 10px;
    padding: 4px 10px;
    cursor: pointer;
    text-transform: uppercase;
    letter-spacing: 1px;
    white-space: nowrap;
    transition: all 0.1s;
    opacity: 0.8;
}

.context-chip:hover {
    background: var(--term-green);
    color: black;
    opacity: 1;
    box-shadow: 0 0 8px var(--term-green);
}

/* MODALS */
.terminal-window {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 95%;
    max-width: 800px;
    background: #000;
    border: 2px solid var(--term-green);
    z-index: 10000; /* Ensure above drawer */
    max-height: 95vh;
    display: flex;
    flex-direction: column;
}

/* MOBILE FULLSCREEN DOSSIER */
@media (max-width: 640px) {
    #dossier-modal {
        width: 100vw !important;
        height: 100dvh !important;
        max-height: none !important;
        top: 0 !important;
        left: 0 !important;
        transform: none !important;
        border: none !important;
    }
}

.hidden { display: none; }

@keyframes dots {
    0%, 20% { content: '.'; }
    40% { content: '..'; }
    60% { content: '...'; }
    80%, 100% { content: ''; }
}
.loading-dots:after {
    content: '.';
    animation: dots 1.5s steps(5, end) infinite;
}

/* --- NPC THUMBNAILS --- */
.npc-thumbnail-token {
    box-shadow: 0 0 10px rgba(0, 0, 0, 0.5);
    position: relative;
    overflow: hidden;
    animation: npc-pulse 4s ease-in-out infinite;
}

.npc-thumbnail-token[data-stratum="mundane"] {
    border-color: var(--term-amber);
}

.npc-thumbnail-token[data-stratum="astral"] {
    border-color: var(--gm-purple);
}

.npc-thumbnail-token[data-stratum="technate"] {
    border-color: var(--crayola-blue);
}

.npc-thumbnail-token[data-stratum="faen"] {
    border-color: var(--term-green);
}

.npc-thumbnail-token:hover {
    box-shadow: 0 0 15px currentColor;
    z-index: 50;
    animation-play-state: paused;
}

@keyframes npc-pulse {
    0% { transform: scale(1); opacity: 0.9; }
    50% { transform: scale(1.05); opacity: 1; }
    100% { transform: scale(1); opacity: 0.9; }
}

.npc-thumbnail-mini[data-stratum="mundane"] { border-color: var(--term-amber); }
.npc-thumbnail-mini[data-stratum="astral"] { border-color: var(--gm-purple); }
.npc-thumbnail-mini[data-stratum="technate"] { border-color: var(--crayola-blue); }
.npc-thumbnail-mini[data-stratum="faen"] { border-color: var(--term-green); }

#map-canvas {
    width: 100%;
    height: 100%;
    display: block;
}
