/* Ophanim Woodcut Theme - Monochromatic */
:root {
    --bg-primary: #050505;
    --bg-secondary: #0a0a0a;
    --bg-card: rgba(0, 0, 0, 0.7); /* Darker semi-transparent black */
    --text-primary: #e0e0e0; /* Off-white */
    --text-secondary: #a0a0a0; /* Grey */
    --accent-primary: #ffffff; /* White */
    --accent-secondary: #cccccc; /* Light Grey */
    --border-color: #ffffff;
    --success-color: #ffffff; /* Monochromatic success */
    --font-main: 'EB Garamond', serif;
    --font-header: 'IM Fell English', serif;
}

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

body {
    font-family: var(--font-main);
    background-color: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    height: 100vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background-image: url('ophanim.jpg');
    background-size: cover;
    background-position: center;
    background-blend-mode: luminosity; /* Force grayscale blend */
}

/* Texture overlay for wood grain paper effect */
body::before {
    content: "";
    position: absolute;
    top: 0; 
    left: 0;
    width: 100%; 
    height: 100%;
    background: rgba(0, 0, 0, 0.4); /* Darken slightly */
    z-index: -1;
    pointer-events: none;
}

.app-container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 1rem;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    position: relative;
    z-index: 1;
}

/* Header */
header {
    text-align: center;
    margin-bottom: 2rem;
    position: relative;
    flex-shrink: 0;
    border-bottom: 2px solid var(--border-color); /* Thicker separation line */
    padding-bottom: 1rem;
}

h1 {
    font-family: var(--font-header);
    font-size: 3rem;
    font-weight: 400;
    letter-spacing: 0.1em;
    color: var(--accent-primary);
    margin-bottom: 0.5rem;
    text-transform: uppercase;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 20px;
    /* Text shadow to lift off background slightly */
    text-shadow: 0 2px 4px rgba(0,0,0,0.8);
}

.live-indicator {
    font-family: var(--font-main);
    font-size: 0.9rem;
    background: transparent;
    color: var(--text-primary);
    padding: 2px 12px;
    border: 1px solid var(--border-color);
    border-radius: 0;
    box-shadow: inset 0 0 5px rgba(0,0,0,0.8); /* Inset shadow */
    text-transform: uppercase;
    letter-spacing: 0.1em;
}

.subtitle {
    color: var(--text-secondary);
    font-family: var(--font-main);
    font-size: 1.1rem;
    font-style: italic;
    letter-spacing: 0.05em;
}

/* Dashboard Grid */
.dashboard-grid {
    display: grid;
    grid-template-columns: 280px 1fr;
    gap: 2rem;
    flex: 1;
    min-height: 0;
}

/* Woodcut Cards - Carved Look */
.glass-card {
    background: var(--bg-card);
    backdrop-filter: none;
    border: 2px solid var(--border-color);
    border-radius: 0;
    padding: 1.5rem;
    /* Inset shadow to look carved into the page */
    box-shadow: inset 2px 2px 5px rgba(0, 0, 0, 0.8), 
                inset -1px -1px 0 rgba(255, 255, 255, 0.1); 
    transition: all 0.2s ease;
    position: relative;
}

/* Metrics Panel */
.metrics-panel {
    display: flex;
    flex-direction: column;
    gap: 1.2rem;
    overflow-y: auto;
}

.metric-item {
    background: rgba(0, 0, 0, 0.6); /* Fill for legibility */
    border-radius: 0;
    padding: 0.8rem 1rem;
    border: 1px solid var(--text-secondary);
    border-left: 4px solid var(--text-primary);
    position: relative;
}

.metric-item.cost {
    border-left-color: var(--text-primary); /* Keep uniform */
}

.metric-label {
    font-family: var(--font-header);
    font-size: 1rem;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--text-secondary);
    margin-bottom: 0.4rem;
    display: block;
    border-bottom: 1px solid var(--text-secondary);
    padding-bottom: 0.2rem;
}

.metric-row {
    display: flex;
    align-items: baseline;
    gap: 8px;
    margin-top: 0.5rem;
}

.metric-value {
    font-size: 1.8rem;
    font-weight: 400;
    font-family: var(--font-header);
    color: var(--text-primary);
    line-height: 1;
    text-shadow: 2px 2px 0 #000;
}

.metric-unit {
    font-size: 1.1rem;
    color: var(--text-secondary);
    font-weight: 400;
    font-style: italic;
}

/* Entity List */
.entities-card {
    flex: 1;
    min-height: 200px;
    display: flex;
    flex-direction: column;
}

.entity-list {
    list-style: none;
    margin-top: 1rem;
    overflow-y: auto;
    flex: 1;
    padding-right: 5px;
}

/* Scrollbar - Minimal, carved */
.entity-list::-webkit-scrollbar {
    width: 6px;
}
.entity-list::-webkit-scrollbar-thumb {
    background: var(--text-secondary);
    border: 1px solid #000;
    border-radius: 0;
}
.entity-list::-webkit-scrollbar-track {
    background: rgba(0,0,0,0.3);
    box-shadow: inset 0 0 5px rgba(0,0,0,0.5);
}

.entity-list li {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 0;
    border-bottom: 1px solid var(--text-secondary);
    font-family: var(--font-main);
    font-size: 1.1rem;
}

.entity-name {
    color: var(--text-primary);
    text-transform: capitalize;
}

.entity-score {
    color: var(--text-primary); /* Monochromatic */
    font-weight: 700;
}

.empty-state {
    color: var(--text-secondary);
    font-style: italic;
    justify-content: center !important;
    border-bottom: none !important;
}

/* Main Display Area */
.display-area {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    position: relative;
    overflow: hidden;
    /* Transparent to show woodcut behind, but darkened for contrast */
    background: rgba(0,0,0,0.2); 
}

#canvas {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    border: 2px solid var(--border-color);
    /* Shadow behind image to separate it */
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.9);
}

.upload-overlay {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.7);
    transition: opacity 0.2s ease;
    cursor: pointer;
    z-index: 10;
}

.upload-overlay.hidden {
    opacity: 0;
    pointer-events: none;
}

.upload-icon {
    font-size: 4rem;
    color: var(--text-primary);
    margin-bottom: 1rem;
    /* Engraved look for icon */
    text-shadow: -1px -1px 0 #000, 1px 1px 0 rgba(255,255,255,0.1);
}

.upload-text {
    font-family: var(--font-header);
    font-size: 1.5rem;
    color: var(--text-primary);
}

#imageUpload { display: none; }

/* Desktop Controls */
.controls-bar {
    margin-top: 1.5rem;
    display: flex;
    justify-content: center;
    gap: 1.5rem;
    flex-shrink: 0;
}

/* BUTTONS - The Carved Look */
.btn {
    background: rgba(0, 0, 0, 0.7); /* Dark fill for legibility */
    border: 2px solid var(--border-color);
    color: var(--text-primary);
    padding: 1rem 2.5rem;
    font-size: 1.1rem;
    font-weight: 700;
    border-radius: 0;
    cursor: pointer;
    transition: all 0.1s ease;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    font-family: var(--font-header);
    
    /* Deep Inset Shadow = Carved into wood */
    box-shadow: inset 3px 3px 6px rgba(0,0,0,0.9), 
                inset -1px -1px 2px rgba(255,255,255,0.2);
    /* Remove text shadow for cleaner look or inset it? 
       Let's keep it clean since shadow is on the box */
}

.btn:hover {
    /* "Pressing deeper" or slightly lighting up the edges */
    background: rgba(255, 255, 255, 0.05);
    box-shadow: inset 4px 4px 8px rgba(0,0,0,0.95), 
                inset -1px -1px 2px rgba(255,255,255,0.3);
    color: #fff;
}

.btn:active {
    /* Very deep press */
    background: rgba(0, 0, 0, 0.3);
    box-shadow: inset 6px 6px 12px rgba(0,0,0,1);
    transform: translateY(1px);
}

.btn-primary {
    /* Make the primary button stand out by being "inverted" or just thicker border?
       Monochromatic typically uses fill. Let's try a filled style that looks like a Stamp. */
    background: var(--text-primary);
    color: var(--bg-primary); /* Black text on white */
    border-color: var(--text-primary);
    /* Raised look instead of carved? OR just bold contrast */
    box-shadow: 4px 4px 0px rgba(0,0,0,0.8); /* Solid drop shadow for Stamp effect */
}
.btn-primary:active {
    transform: translate(2px, 2px);
    box-shadow: 2px 2px 0px rgba(0,0,0,0.8);
}

/* Loading */
.loading-indicator {
    display: none;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    text-align: center;
    z-index: 20;
    background: #000;
    padding: 20px;
    border: 2px solid var(--border-color);
}

.loading-indicator.active { display: block; }

.spinner {
    width: 60px;
    height: 60px;
    border: 4px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    border-top-color: var(--text-primary);
    animation: spin 1s linear infinite;
    margin-bottom: 1rem;
    margin-left: auto;
    margin-right: auto;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* MOBILE ERGONOMICS */
/* MOBILE ERGONOMICS */
/* MOBILE ERGONOMICS */
@media (max-width: 900px) {
    .app-container {
        padding: clamp(0.3rem, 1.5vw, 0.5rem); 
        height: 100vh;
        max-height: 100vh;
        overflow-y: auto; 
    }

    .dashboard-grid {
        display: flex !important;
        flex-direction: column-reverse !important; /* Forces Image Top (Item 2 -> 1) */
        gap: clamp(0.5rem, 2vw, 1rem);
        margin-bottom: 70px;
        overflow-y: visible; 
    }

    .metrics-panel {
        width: 100%;
        display: grid;
        grid-template-columns: 1fr 1fr; 
        gap: clamp(0.3rem, 1.5vw, 0.8rem);
        padding-bottom: 2rem;
    }
    
    .display-area {
        width: 100%;
        min-height: 35vh; 
        max-height: 50vh;
        margin-bottom: 0.2rem;
        flex-shrink: 0;
    }

    header {
        margin-bottom: 0.2rem;
        padding-bottom: 0.2rem;
    }

    /* User Request: visible even on smallest screen */
    h1 { font-size: clamp(1.2rem, 5vw, 2rem); }
    .subtitle { font-size: clamp(0.7rem, 2.5vw, 0.9rem); }
    
    .glass-card { 
        padding: clamp(0.4rem, 2vw, 1rem); /* Reduced min padding */
    }
    
    .metric-value { font-size: clamp(1rem, 4vw, 1.5rem); }
    .metric-unit { font-size: clamp(0.7rem, 2vw, 0.9rem); }
    .metric-label { font-size: clamp(0.7rem, 2.5vw, 0.9rem); }

    .entities-card {
        grid-column: span 2; 
        min-height: 100px; /* Reduced min height */
    }

    /* Floating Thumb Controls */
    .controls-bar {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        background: rgba(0,0,0,0.9);
        padding: clamp(5px, 1.5vw, 10px);
        margin-top: 0;
        z-index: 100;
        border-top: 1px solid var(--border-color);
    }
    .btn {
        width: auto;
        flex: 1;
        padding: clamp(0.5rem, 2vw, 1rem); /* Reduced padding */
        font-size: clamp(0.75rem, 3vw, 1.1rem); /* Smaller font min */
    }
}

/* MOBILE LANDSCAPE OPTIMIZATION */
/* Added min-width to avoid triggering on narrow portrait devices falsely */
@media (max-height: 500px) and (orientation: landscape) and (min-width: 480px) {
    .app-container {
        padding: 0.2rem;
        overflow: hidden; 
    }

    header {
        display: flex;
        justify-content: space-between;
        align-items: center;
        margin-bottom: 0.2rem;
        padding-bottom: 0.2rem;
        border-bottom: 1px solid var(--border-color);
        background: rgba(0,0,0,0.8);
    }
    h1 { font-size: 1rem; margin: 0; }
    .subtitle { display: none; }

    .dashboard-grid {
        display: flex !important;
        flex-direction: row-reverse !important; /* Display (2nd) -> Left, Metrics (1st) -> Right */
        align-items: stretch;
        gap: 0.5rem;
        margin-bottom: 0;
        height: calc(100vh - 40px); 
    }

    .display-area {
        flex: 1;
        height: 100%;
        max-height: none;
        min-height: 0;
        margin-bottom: 0;
    }
    
    .metrics-panel {
        width: 240px;
        flex-shrink: 0;
        padding-bottom: 0;
        display: flex;
        flex-direction: column;
        overflow-y: auto;
        gap: 0.4rem;
    }

    .metrics-panel .glass-card {
        padding: 0.5rem;
    }
    
    .metric-item { padding: 0.3rem 0.5rem; }
    .metric-value { font-size: 1.2rem; }
    
    .controls-bar {
       display: none; 
    }
}