/* General Styling & Fonts */
:root {
    --primary-color: #00f0ff;
    --secondary-color: #ff00c1;
    --background-color: #0a0a10;
    --panel-bg: rgba(20, 20, 35, 0.6);
    --border-color: rgba(0, 240, 255, 0.2);
    --glow-shadow: 0 0 8px var(--primary-color);
    font-family: 'Roboto Mono', monospace;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
body {
    background-color: var(--background-color);
    background-image: radial-gradient(var(--primary-color) 0.5px, transparent 0.5px), radial-gradient(var(--secondary-color) 0.5px, transparent 0.5px);
    background-size: 30px 30px;
    background-position: 0 0, 15px 15px;
    color: #e0e0e0;
    min-height: 100vh;
    /* CHANGE: Allow vertical scroll for mobile, but hide horizontal scroll */
    overflow-y: auto;
    overflow-x: hidden;
}

/* Main App Layout */
#app-grid {
    display: grid;
    /* Desktop: two columns, Right panel is 420px */
    grid-template-columns: 1fr 420px;
    width: 100vw;
    height: 100vh;
    gap: 20px;
    padding: 20px;
}
#visual-panel {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    overflow: hidden;
    gap: 15px;
}
#control-panel {
    background: var(--panel-bg);
    border: 1px solid var(--border-color);
    border-radius: 15px;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    padding: 25px;
    display: flex;
    flex-direction: column;
    gap: 15px;
    overflow-y: auto;
}

/* Visuals Panel */
#canvas-container {
    /* Container will be a square */
    aspect-ratio: 1 / 1;
    width: 100%;
    /* Desktop: Don't let canvas be taller than the viewport */
    max-height: calc(100vh - 40px);
    position: relative;
}
#kaleidoscope-canvas {
    width: 100%;
    height: 100%;
    background-color: #000;
    border-radius: 50%;
    box-shadow: 0 0 15px rgba(0, 240, 255, 0.1), 0 0 30px rgba(0, 240, 255, 0.2);
}

/* Control Panel General Controls */
.control-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 15px; }
.control-group, .output-group, .stats-group { display: flex; flex-direction: column; gap: 8px; }
label { font-size: 0.8rem; font-weight: 700; color: var(--primary-color); opacity: 0.8; text-transform: uppercase; }
input, textarea, select { background: rgba(0,0,0,0.3); border: 1px solid var(--border-color); border-radius: 5px; padding: 10px; font-family: 'Roboto Mono', monospace; font-size: 1rem; color: #f0f0f0; outline: none; transition: all 0.2s ease; }
input:focus, textarea:focus, select:focus { border-color: var(--primary-color); box-shadow: var(--glow-shadow); }
textarea { resize: vertical; }
select { appearance: none; -webkit-appearance: none; background-image: url('data:image/svg+xml;charset=US-ASCII,%3Csvg%20xmlns%3D%22http%3A//www.w3.org/2000/svg%22%20width%3D%22292.4%22%20height%3D%22292.4%22%3E%3Cpath%20fill%3D%22%2300f0ff%22%20d%3D%22M287%2069.4a17.6%2017.6%200%200%200-13-5.4H18.4c-5%200-9.3%201.8-12.9%205.4A17.6%2017.6%200%200%200%200%2082.2c0%205%201.8%209.3%205.4%2012.9l128%20127.9c3.6%203.6%207.8%205.4%2012.8%205.4s9.2-1.8%2012.8-5.4L287%2095c3.5-3.5%205.4-7.8%205.4-12.8%200-5-1.9-9.2-5.5-12.8z%22/%3E%3C/svg%3E'); background-repeat: no-repeat; background-position: right 10px top 50%; background-size: .65em auto; padding-right: 2em; }

/* Toggles and Radios */
.switch-toggle { position: relative; display: inline-block; width: 40px; height: 22px; }
.switch-toggle.small { width: 34px; height: 20px; }
.switch-toggle input { opacity: 0; width: 0; height: 0; }
.slider { position: absolute; cursor: pointer; top: 0; left: 0; right: 0; bottom: 0; background-color: rgba(0,0,0,0.3); border: 1px solid var(--border-color); transition: .4s; border-radius: 22px; }
.slider:before { position: absolute; content: ""; height: 14px; width: 14px; left: 3px; bottom: 3px; background-color: white; transition: .4s; border-radius: 50%; }
.switch-toggle.small .slider:before { height: 12px; width: 12px; left: 3px; bottom: 3px; }
input:checked + .slider { background-color: var(--secondary-color); border-color: var(--secondary-color); }
input:checked + .slider:before { transform: translateX(18px); }
.switch-toggle.small input:checked + .slider:before { transform: translateX(14px); }
.visual-controls, .mode-switch-container { display: flex; align-items: center; gap: 10px; }
.radio-group { display: flex; gap: 15px; align-items: center; }
.radio-group label { text-transform: none; opacity: 0.8; cursor: pointer; }
.radio-group input { width: 1em; height: 1em; accent-color: var(--primary-color); }

/* File Drop Zone & Output Area */
#file-drop-zone { border: 2px dashed var(--border-color); border-radius: 10px; padding: 20px; text-align: center; color: rgba(255,255,255,0.5); transition: all 0.2s ease; }
#file-drop-zone.dragover { border-color: var(--secondary-color); background: rgba(255, 0, 193, 0.1); color: #fff; }
#file-info { display: flex; justify-content: center; align-items: center; gap: 10px; font-size: 0.8rem; color: var(--secondary-color); }
#clear-file-btn { cursor: pointer; font-weight: bold; color: #ff4d4d; }
.hash-container { display: flex; background: rgba(0,0,0,0.4); border-radius: 5px; border: 1px solid var(--border-color); align-items: center; }
#hash-output { padding: 10px; word-break: break-all; flex-grow: 1; font-size: 0.9rem; }
#copy-button { background: transparent; border: none; border-left: 1px solid var(--border-color); color: var(--primary-color); padding: 10px; cursor: pointer; transition: background 0.2s; height: 100%; }
#copy-button:hover { background: rgba(0, 240, 255, 0.1); }
#copy-button svg { width: 20px; height: 20px; }
#stats-container { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; text-align: center; }
.stat-item { background: rgba(0,0,0,0.2); border: 1px solid var(--border-color); padding: 10px; border-radius: 5px; }
.stat-item span { font-size: 0.7rem; opacity: 0.7; }
.stat-item p { font-size: 1.1rem; font-weight: 700; margin-top: 5px; }
#stat-color { text-shadow: 0 0 5px currentColor; }

/* Help Button & Modal Styles */
#help-button { margin-top: auto; padding: 10px; background: none; border: 1px solid var(--border-color); color: var(--primary-color); font-family: 'Roboto Mono', monospace; border-radius: 5px; cursor: pointer; transition: all 0.2s ease; }
#help-button:hover { background: var(--panel-bg); border-color: var(--primary-color); }
.hidden { display: none !important; }
#help-modal { position: fixed; top: 0; left: 0; width: 100%; height: 100%; z-index: 1000; display: flex; justify-content: center; align-items: center; }
.modal-overlay { position: absolute; top: 0; left: 0; width: 100%; height: 100%; background: rgba(10, 10, 16, 0.8); backdrop-filter: blur(5px); -webkit-backdrop-filter: blur(5px); }
.modal-content { position: relative; z-index: 1001; background: #141423; border: 1px solid var(--primary-color); border-radius: 15px; max-width: 600px; width: 90%; padding: 30px; box-shadow: 0 0 30px rgba(0, 240, 255, 0.3); }
#modal-close-btn { position: absolute; top: 10px; right: 15px; background: none; border: none; font-size: 2rem; color: #fff; cursor: pointer; opacity: 0.7; transition: opacity 0.2s; }
#modal-close-btn:hover { opacity: 1; }
.modal-content h2 { font-family: 'Orbitron', sans-serif; color: var(--primary-color); margin-bottom: 15px; }
.modal-content h3 { color: var(--secondary-color); margin-top: 20px; margin-bottom: 10px; }
.modal-content p, .modal-content li { font-size: 0.9rem; line-height: 1.6; opacity: 0.9; }
.modal-content ul { list-style-position: inside; padding-left: 10px; }
.modal-content li { margin-bottom: 5px; }
.modal-content .warning { margin-top: 20px; padding: 10px; background: rgba(255,0,0,0.1); border-left: 3px solid #ff0000; font-size: 0.85rem; }

/* Responsive */
@media (max-width: 900px) {
    #app-grid {
        /* Stack visual and control panels vertically */
        grid-template-columns: 1fr;
        grid-template-rows: auto 1fr;
        /* Allow grid to grow taller than the screen and scroll */
        height: auto;
        min-height: 100vh;
        /* Reduce padding and gap on smaller screens */
        padding: 10px;
        gap: 15px;
    }

    #visual-panel {
        /* Let the canvas container define the height */
        height: auto;
    }

    #canvas-container {
        /* On mobile, size relative to screen width, not height */
        width: 90vw;
        /* Add a max size to prevent it from being huge on tablets */
        max-width: 450px;
        /* Remove the desktop height constraint */
        max-height: none;
        /* Center the canvas container */
        margin: 0 auto;
    }

    #control-panel {
        /* Ensure panel can take the height it needs */
        height: auto;
        /* Make padding a bit tighter for mobile */
        padding: 20px;
        /* Remove blur on mobile for potentially better performance */
        backdrop-filter: none;
        -webkit-backdrop-filter: none;
        background: var(--panel-bg);
    }
    
    .modal-content {
        width: 95%;
        padding: 20px;
    }
}
/* --- mobile fit (added for portfolio embed) --- */
@media (max-width: 640px) {
  html, body { max-width: 100vw !important; height: auto !important; min-height: 100dvh; overflow-x: hidden !important; overflow-y: auto !important; }
  body * { max-width: 100vw !important; box-sizing: border-box !important; }
  #app-grid { display: block !important; width: 100% !important; height: auto !important; min-height: 100dvh; }
  #visual-panel, #control-panel { width: 100% !important; max-width: 100% !important; }
  #canvas-container { max-height: 60vh !important; }
  #kaleidoscope-canvas { width: 100% !important; height: auto !important; }
}
