/* =========================================
   1. IMPORTS & PLD BRAND VARIABLES
   ========================================= */
@import url('https://fonts.googleapis.com/css2?family=Archivo:ital,wght@0,100..900;1,100..900&display=swap');
@import url('https://fonts.googleapis.com/css2?family=Inter:ital,opsz,wght@0,14..32,100..900;1,14..32,100..900&display=swap');

:root {
    /* PLd Brand Colors */
    --pld-dark: #141414;
    --pld-light: #f0f0f0;
    --pld-accent: #C8102E;
    --pld-white: #ffffff;
    --pld-black: #000000;

    /* Typography */
    --font-heading: "Archivo", sans-serif;
    --font-body: "Inter", sans-serif;

    /* Theme: Default Dark */
    --bg-main: var(--pld-dark);
    --bg-sidebar: var(--pld-black);
    --text-main: var(--pld-light);
    --border-color: rgba(240, 240, 240, 0.2);
}

body.light-mode {
    /* Theme: PLd Light */
    --bg-main: var(--pld-light);
    --bg-sidebar: var(--pld-white);
    --text-main: var(--pld-dark);
    --border-color: rgba(20, 20, 20, 0.2);
}

/* =========================================
   2. GLOBAL & DESKTOP STYLES
   ========================================= */
body {
    margin: 0;
    font-family: var(--font-body);
    background-color: var(--bg-main);
    color: var(--text-main);
    overflow: hidden; 
    cursor: crosshair; 
    transition: background-color 0.3s ease, color 0.3s ease;
}

.layout {
    display: flex;
    flex-direction: row; 
    height: 100vh;
    width: 100%;
}

/* Sidebar */
.sidebar {
    width: 380px;
    flex-shrink: 0;
    background: var(--bg-sidebar);
    color: var(--text-main);
    padding: 20px;
    box-sizing: border-box;
    overflow-y: auto;
    border-right: 2px solid var(--border-color);
    z-index: 10;
    height: 100%;
    transition: background-color 0.3s ease;
}

.sidebar h3 {
    margin: 15px 0 10px 0;
    font-family: var(--font-heading);
    font-weight: 500;
    text-transform: uppercase;
    font-size: 1.125rem;
    letter-spacing: 1px;
}

.control-group {
    margin-bottom: 20px;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 15px;
}

.control-group:last-of-type {
    border-bottom: none;
}

.control {
    display: flex;
    align-items: center;
    margin: 8px 0;
    flex-wrap: wrap; 
}

.control label {
    flex: 0 0 150px;
    margin-right: 10px;
    font-size: 0.875rem;
    white-space: nowrap;
}

/* Inputs & Selects */
.control select,
.control input[type="text"] {
    flex: 1;
    font-family: var(--font-heading);
    font-size: 0.875rem;
    background: transparent;
    color: var(--text-main);
    border: 1px solid var(--text-main);
    border-radius: 10px;
    padding: 8px 12px;
    transition: all 0.3s ease-in-out;
    outline: none;
    cursor: crosshair;
}

.control select:hover,
.control input[type="text"]:hover,
.control select:focus,
.control input[type="text"]:focus {
    color: var(--pld-accent);
    border-color: var(--pld-accent);
}

.control input[type="select"] option {
    background: var(--bg-sidebar);
    color: var(--text-main);
}

/* Custom Range Sliders */
.control input[type="range"] {
    flex: 1;
    accent-color: var(--pld-accent);
    cursor: crosshair;
}

.value-label {
    display: inline-block;
    width: 40px;
    text-align: center;
    margin-left: 8px;
    font-family: var(--font-heading);
    font-size: 0.85rem;
    font-weight: 500;
}

/* Main Content */
.main-content {
    flex: 1;
    padding: 20px;
    overflow: auto; 
    background: var(--bg-main);
    color: var(--text-main);
    box-sizing: border-box;
    display: block; 
}

#ascii-art {
    background: transparent;
    padding: 10px;
    white-space: pre;
    font-family: "Roboto Mono", Consolas, Monaco, monospace; 
    font-size: 7px;
    line-height: 7px;
    display: inline-block; 
}

/* =========================================
   3. BUTTONS (PLd Style)
   ========================================= */
button, .donate-btn {
    font-family: var(--font-heading);
    font-size: 0.875rem;
    background: transparent;
    color: var(--text-main);
    border: 2px solid var(--text-main);
    border-radius: 10px;
    padding: 10px 15px;
    cursor: crosshair;
    transition: all 0.3s ease-in-out;
    margin-right: 10px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    text-decoration: none;
    display: inline-block;
    text-align: center;
}

.donate-btn {
    width: 100%;
    box-sizing: border-box;
}

button:hover, .donate-btn:hover {
    background: var(--pld-accent);
    color: var(--pld-light); 
    border-color: var(--pld-accent);
    letter-spacing: 1.5px;
}

button:active, .donate-btn:active {
    transform: scale(0.98);
}

/* Conditional UI toggles */
#halftoneControl {
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px dashed var(--border-color);
}

#halftoneSize {
    flex: 1;
    margin-right: 10px;
}

.big-dots-mode {
    font-size: 14px !important;
    /* Force square aspect ratio: width and line-height must match */
    line-height: 10px !important; 
    width: 10px !important; 
    display: inline-block;
    text-align: center;
    letter-spacing: 0px; 
    font-weight: 900;
    /* This ensures the circular glyphs are perfectly centered */
    vertical-align: middle;
}

/* Hide handle and float bar on desktop */
@media (min-width: 851px) {
    .drawer-handle { display: none; }
    .action-buttons { margin-top: 20px; }
}

/* =========================================
   4. MOBILE STYLES (Max width 850px)
   ========================================= */
@media (max-width: 850px) {
    .layout {
        display: block;
        height: 100vh;
        width: 100vw;
        position: relative;
        overflow: hidden;
    }

    /* 1. Main Content Gets 100% of the screen */
    .main-content {
        position: absolute;
        top: 0;
        left: 0;
        width: 100vw;
        height: calc(100vh - 120px); /* Leave space for action bar */
        padding: 10px;
        overflow: auto; 
        border: none;
        display: block; 
    }

    #ascii-art {
        transform-origin: top left; 
    }

    /* 2. Floating Action Bar (Always visible) */
    .action-buttons {
        display: flex;
        gap: 10px;
        position: fixed;
        bottom: 115px; /* Sits just above the collapsed drawer */
        left: 0;
        width: 100vw;
        padding: 15px;
        box-sizing: border-box;
     
        z-index: 20;
    }

    .action-buttons button {
        flex: 1;
        margin: 0;
        font-size: 0.8rem;
        padding: 15px 5px;
        background: var(--bg-main);
    }

    /* 3. The Drawer (The Sidebar turned into a bottom sheet) */
    .sidebar {
        position: absolute;
        bottom: 100px;
        left: 0;
        width: 100vw;
        height: 60vh; /* Expanded height */
        border-top: 2px solid var(--border-color);
        border-right: none;
        border-radius: 20px 20px 0 0;
        padding: 30px 20px 20px 20px; /* Extra top padding for the handle */
        box-shadow: 0 -5px 25px rgba(0,0,0,0.5);
        z-index: 50;
        
        /* The magic: Transform it down so only the top 50px is visible */
        transform: translateY(calc(100% - 50px)); 
        transition: transform 0.4s cubic-bezier(0.19, 1, 0.22, 1);
        overflow-y: auto;
    }

    /* When a class 'open' is added via JS, it slides up */
    .sidebar.open {
        transform: translateY(0);
    }

    /* The visual handle line at the top of the drawer */
    .drawer-handle {
        position: absolute;
        top: 15px;
        left: 50%;
        transform: translateX(-50%);
        width: 40px;
        height: 4px;
        background: var(--text-main);
        border-radius: 4px;
        opacity: 0.3;
    }

    /* Adjust controls for vertical layout */
    .control {
        margin: 15px 0;
        flex-direction: column;
        align-items: flex-start;
    }
    
    .control label {
        flex: none;
        margin-bottom: 8px;
    }
    
    .control input[type="range"],
    .control select {
        width: 100%;
    }

    .value-label {
        align-self: flex-end;
        margin-top: -25px; /* Pulls the number up next to the label */
    }
}