/* ==========================================================================
   GHOSTLINE CORE ENGINE v1.0
   Aesthetic: 1-Bit Dithered | Retro-Simulation | Void/Phosphor
   ========================================================================== */

/* -------------------------------------------
   0. RESET & BASICS
   ------------------------------------------- */
   * {
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
    cursor: crosshair; /* Immersion */
}

/* Hide scrollbars but keep functionality */
html::-webkit-scrollbar,
body::-webkit-scrollbar,
.window-content::-webkit-scrollbar {
    width: 0px;
    background: transparent;
}
html, body {
    scrollbar-width: none;
    -ms-overflow-style: none;
}

:root {
    /* 1-BIT PALETTE */
    --void: #000000;
    --phosphor: #ffffff;
    
    /* GHOSTLINE UI */
    --border-width: 2px;
    --border-style: solid;
    --font-stack: 'Courier New', Courier, 'VT323', monospace;
    --font-heading: 'Courier New', Courier, monospace; /* Keeping it mono for consistency */

    /* DITHER PATTERN (Data URI for 4x4 Bayer or Checkered) 
       Using a CSS radial gradient to simulate dispersed stippling */
    --dither-bg: 
        radial-gradient(circle, var(--phosphor) 1px, transparent 1px);
    --dither-size: 4px 4px; 
}

/* -------------------------------------------
   1. GLOBAL ENVIRONMENT
   ------------------------------------------- */
/* -------------------------------------------
   1. GLOBAL ENVIRONMENT & LAYOUT
   ------------------------------------------- */
body {
    background-color: var(--void);
    color: var(--phosphor);
    font-family: var(--font-stack);
    font-size: 16px;
    line-height: 1.5; /* Improved reading rhythm */
    margin: 0;
    min-height: 100vh;
    width: 100vw;
    overflow-x: hidden;
    display: flex;
    justify-content: center;
    align-items: flex-start; /* Top align for long scrolling */
    padding: 2vh 2vw; /* Consistent viewport padding */
    
    /* STARFIELD / STATIC BACKGROUND EFFECT */
    background-image: var(--dither-bg);
    background-size: var(--dither-size);
}

/* MAIN LAYOUT WRAPPER 
   Solves component overlap by creating explicit space */
.layout-wrapper {
    display: flex;
    flex-direction: row;
    align-items: center; /* Vertically center relative to each other */
    justify-content: center;
    width: 100%;
    max-width: 1600px; /* Cap ultra-wide screens */
    gap: 40px; /* Explicit breathing room between User & Assistant */
    height: 96vh; /* Screen height frame */
}

/* -------------------------------------------
   2. WINDOW FRAME [Replaces .hypercard-stack]
   ------------------------------------------- */
.hypercard-stack {
    flex: 1; /* Take remaining space */
    max-width: 1200px; /* Optimal reading width maximum */
    min-width: 320px;
    height: 100%; /* Fill wrapper height */
    
    background-color: var(--void);
    border: var(--border-width) solid var(--phosphor);
    display: flex;
    flex-direction: column;
    position: relative;
    box-shadow: 12px 12px 0px var(--phosphor);
    transition: transform 0.1s;
}

/* Window Title Bar */
.card-header {
    background-color: var(--phosphor);
    color: var(--void);
    padding: 12px 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: var(--border-width) solid var(--void);
    font-weight: bold;
    text-transform: uppercase;
    letter-spacing: 2px; /* Enhanced retro feel */
}

.card-title {
    font-size: 1.2rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.card-number {
    font-size: 1rem;
    border: 1px solid var(--void);
    background: var(--void);
    color: var(--phosphor);
    padding: 4px 10px;
}

/* -------------------------------------------
   3. CONTENT AREA
   ------------------------------------------- */
.card-content {
    padding: 40px; /* Generous whitespace */
    flex: 1;
    overflow-y: auto;
    background-color: var(--void);
    color: var(--phosphor);
    font-size: 18px;
}

/* Typography Overrides */
h2, h3, h4 {
    font-weight: normal;
    text-transform: uppercase;
    border-bottom: 1px dashed var(--phosphor);
    padding-bottom: 10px;
    margin-top: 1.8em;
    color: var(--phosphor);
    letter-spacing: 1px;
}

h2 { font-size: 2.4rem; border-bottom: 3px solid var(--phosphor); letter-spacing: -1px; }
h3 { font-size: 1.8rem; }
p { margin-bottom: 1.6em; max-width: 65ch; line-height: 1.7; }

/* Lists: ASCII Bullets */
ul { list-style: none; padding-left: 25px; margin-bottom: 2em; }
li { margin-bottom: 10px; }
li::before {
    content: ">> ";
    font-weight: bold;
    margin-left: -25px;
    width: 25px;
    display: inline-block;
}

/* Inverted Input Areas */
.viz-input, input, textarea {
    background-color: var(--void);
    color: var(--phosphor);
    border: 1px solid var(--phosphor);
    padding: 12px;
    font-family: var(--font-stack);
    font-size: 16px;
    width: 100%;
    margin-top: 5px;
}
.viz-input:focus, input:focus, textarea:focus {
    background-color: #111;
    outline: 2px solid var(--phosphor);
    outline-offset: -2px;
}

/* -------------------------------------------
   4. UI COMPONENTS - Refined
   ------------------------------------------- */
/* Emphasized Keywords */
strong { 
    background-color: var(--phosphor); 
    color: var(--void); 
    padding: 1px 6px; 
    border-radius: 2px; /* Slight micro-detail */
}

/* Retro Buttons */
.hc-button, .arrow-button {
    background: var(--void);
    color: var(--phosphor);
    border: 2px solid var(--phosphor); /* Thicker border */
    padding: 14px 28px;
    font-family: var(--font-stack);
    text-transform: uppercase;
    font-weight: bold;
    letter-spacing: 1px;
    transition: none;
    cursor: pointer;
    box-shadow: 6px 6px 0px rgba(255,255,255,0.25);
    font-size: 1.1rem;
    position: relative;
    top: 0;
    left: 0;
}

.hc-button:hover, .arrow-button:hover {
    background: var(--phosphor);
    color: var(--void);
    box-shadow: 2px 2px 0px var(--phosphor);
    top: 4px; /* Physical press feel */
    left: 4px;
}

.hc-button:active, .arrow-button:active {
    top: 6px;
    left: 6px;
    box-shadow: none;
}

.arrow-button {
    font-size: 1.6rem;
    padding: 15px 35px;
}

/* -------------------------------------------
   4a. ASCII ASSISTANT "CLIPPY" - Layout Integration
   ------------------------------------------- */
.ascii-assistant {
    position: relative; /* Flows with flexbox now */
    width: 280px; /* Fixed width sidebar */
    flex-shrink: 0; /* Don't shrink */
    display: flex;
    flex-direction: column;
    align-items: center;
    z-index: 10;
}

.assistant-bubble {
    background: var(--phosphor);
    color: var(--void);
    padding: 20px;
    border: 2px solid var(--phosphor);
    margin-bottom: 20px;
    width: 100%;
    position: relative;
    font-size: 0.95rem;
    font-weight: bold;
    box-shadow: 8px 8px 0px rgba(255,255,255,0.2); /* Matching shadow style */
    line-height: 1.4;
    animation: popIn 0.5s steps(3, end);
}

/* Tail points DOWN to avatar */
.assistant-bubble::after {
    content: '';
    position: absolute;
    bottom: -15px;
    left: 50%;
    transform: translateX(-50%);
    width: 0;
    height: 0;
    border-left: 15px solid transparent;
    border-right: 15px solid transparent;
    border-top: 15px solid var(--phosphor);
}

.assistant-avatar {
    font-family: monospace;
    white-space: pre;
    color: var(--phosphor);
    font-size: 14px; /* Larger avatar */
    line-height: 1.1;
    text-align: center;
    padding: 10px;
}

/* Image-based avatar styles */
.assistant-avatar img {
    display: block;
    max-width: 260px;
    width: 100%;
    height: auto;
    margin: 0 auto;
    
    /* Clean, pixelated look */
    image-rendering: pixelated;
    
    /* 1-bit Monochrome Effect: Grayscale + High Contrast to make it purely B&W */
    filter: grayscale(100%) contrast(200%);
    
    border: none;
}

@media (max-width: 1024px) {
   .ascii-assistant {
        /* Stack interaction on mobile: Bubble on TOP, Avatar on BOTTOM */
        display: flex;
        flex-direction: column; 
        width: 100%;
        max-width: 100%;
        margin-top: 30px;
        align-items: center; /* Center everything horizontally */
    }

    .assistant-bubble {
        margin-bottom: 0; /* Zero gap for tightest fit */
        width: 90%; 
        max-width: 400px;
        text-align: left;
        align-self: center; /* Ensure bubble is centered */
    }
    
    /* Ensure tail points down to avatar */
    .assistant-bubble::after {
        left: 50%;
        transform: translateX(-50%);
        bottom: -15px; /* Ensure it sticks out the bottom */
        border-top-color: var(--phosphor); /* Ensure color is correct */
    }
    
    .assistant-avatar {
        padding-top: 0;
    }
}

/* -------------------------------------------
   RESPONSIVE DESIGN (Mobile)
   ------------------------------------------- */
@media (max-width: 1024px) {
    .layout-wrapper {
        flex-direction: column; /* Stack vertically */
        height: auto;
        gap: 30px;
        padding-top: 10px;
    }
    
    .hypercard-stack {
        width: 100%;
        height: auto;
        min-height: 70vh;
        margin-bottom: 20px;
    }
}

@media (max-width: 600px) {
    /* Mobile Phone: Stack strictly vertical */
    .ascii-assistant {
        flex-direction: column;
        align-items: center;
    }
    .assistant-bubble { order: 1; margin-bottom: 15px; }
    .assistant-avatar { order: 2; }
    .assistant-bubble::after {
        /* Point DOWN again */
        top: auto; bottom: -15px; left: 50%; transform: translateX(-50%);
        border-left: 15px solid transparent;
        border-right: 15px solid transparent;
        border-top: 15px solid var(--phosphor);
        border-bottom: none;
    }
}
 
/* ... Visualizations & Utilities ... */

/* Visualizations - ASCII/Terminal Style */
.visualization {
    border: 1px solid var(--phosphor);
    padding: 20px;
    margin: 20px 0;
    position: relative;
    background: repeating-linear-gradient(
        45deg,
        var(--void),
        var(--void) 2px,
        #111 2px,
        #111 4px
    ); /* Subtle hatch texture */
}

.viz-display-area, .viz-code-block, .viz-terminal {
    background: var(--void);
    border: 1px solid var(--phosphor);
    color: var(--phosphor);
    padding: 12px;
    font-family: var(--font-stack);
    margin-top: 10px;
}

.viz-state-error {
    border: 1px dashed var(--phosphor);
    background: repeating-linear-gradient(
        135deg,
        #000,
        #000 10px,
        #333 10px,
        #333 12px
    );
}

.viz-state-success {
    border: 2px solid var(--phosphor);
    background: var(--void);
}

.narrative, .key-concept {
    border: 1px solid var(--phosphor);
    padding: 16px;
    margin: 24px 0;
    background: var(--void);
}

.narrative {
    border-left: 8px solid var(--phosphor);
}

.key-concept {
    border: 1px dotted var(--phosphor);
    text-align: center;
}

/* -------------------------------------------
   5. NAVIGATION
   ------------------------------------------- */
.bottom-nav {
    border-top: var(--border-width) solid var(--phosphor);
    padding: 20px;
    display: flex;
    flex-direction: row;
    justify-content: space-between; /* Space out items */
    align-items: center;
    background: var(--void);
}

/* Move Arrows to the Right */
.nav-arrows {
    order: 2; /* Move to the right */
    display: flex;
    gap: 15px;
}

.nav-links {
    order: 1; /* Keep other links on left/center */
    display: flex;
    gap: 15px;
}

.sticky-top-nav {
    display: none; /* Hide sticky nav in retro mode, rely on main window nav */
}

/* Progress - 1-bit Fill */
.progress-bar {
    height: 10px;
    border-top: 1px solid var(--phosphor);
    background: var(--void);
    position: relative;
}
.progress-fill {
    height: 100%;
    background: repeating-linear-gradient(
        90deg,
        var(--phosphor),
        var(--phosphor) 2px,
        var(--void) 2px,
        var(--void) 4px
    );
}

/* -------------------------------------------
   6. BROWSE GRID
   ------------------------------------------- */
.card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 20px;
    padding: 20px;
}

.card-item {
    border: 1px solid var(--phosphor);
    background: var(--void);
    padding: 16px;
    height: 200px;
    display: flex;
    flex-direction: column;
    text-decoration: none;
    color: var(--phosphor);
    position: relative;
    box-shadow: 5px 5px 0px #333;
}

.card-item:hover {
    background: var(--phosphor);
    color: var(--void);
    box-shadow: 5px 5px 0px var(--phosphor);
}

.card-item-number {
    position: absolute;
    top: 10px;
    right: 10px;
    font-size: 2rem;
    font-weight: bold;
    opacity: 0.3;
}

.card-item:hover .card-item-number {
    opacity: 1;
    color: var(--void);
}

/* -------------------------------------------
   7. UTILITIES
   ------------------------------------------- */
.ascii-art {
    white-space: pre;
    font-family: monospace;
    line-height: 1;
    overflow-x: hidden;
    margin-bottom: 20px;
    font-size: 10px; /* Small ascii */
    text-align: center;
    color: var(--phosphor);
}

@media (max-width: 600px) {
    .hypercard-stack { 
        height: auto; 
        min-height: 100vh; 
        border: none; 
        box-shadow: none; 
        width: 100%; 
        border-left: var(--border-width) solid var(--phosphor);
        border-right: var(--border-width) solid var(--phosphor);
    }
    .card-content { padding: 20px 16px; }
    h2 { font-size: 1.5rem; }
    
    /* Stack navigation on mobile */
    .bottom-nav {
        flex-direction: column;
        gap: 20px;
    }
    
    .nav-arrows, .nav-links {
        width: 100%;
        justify-content: center;
        order: unset; /* Reset order to stack naturally or enforce specific order */
    }
    
    .nav-arrows { order: 2; }
    .nav-links { order: 1; flex-direction: column; }
    
    .hc-button, .arrow-button {
        width: 100%;
        text-align: center;
        padding: 16px; /* Larger touch target */
    }
    
    /* Ensure code blocks scroll */
    .viz-terminal, .ascii-art, pre {
        overflow-x: auto;
        max-width: 100%;
        scrollbar-width: thin;
        scrollbar-color: var(--phosphor) var(--void);
    }
    
    /* Adjust visual input text area */
    .viz-input, input, textarea {
        font-size: 16px !important; /* Prevent zoom on iOS */
        max-width: 100%;
        width: 100%;
    }
    
    /* Layout Wrapper padding */
    .layout-wrapper {
        padding: 0;
        gap: 0;
    }
}

@media (max-width: 400px) {
    /* Very small screens */
    .card-title { font-size: 1rem; }
    .card-header { padding: 10px; }
    
    .card-grid {
        grid-template-columns: 1fr; /* Single column for cards */
    }
}
