@import url('https://fonts.googleapis.com/css2?family=Michroma&family=Outfit:wght@300;400;700&display=swap');

:root {
    --bg-main: #020204;
    --bg-panel: rgba(10, 10, 15, 0.95);
    --bg-card: rgba(22, 22, 32, 0.8);
    --accent: #00ffaa;
    --accent-glow: rgba(0, 255, 170, 0.5);
    --accent-dim: rgba(0, 255, 170, 0.15);
    --text-main: #ffffff;
    --text-dim: #888899;
    --border: rgba(255, 255, 255, 0.08);
    --header-h: 65px;
    --panel-w-left: 340px;
    --panel-w-right: 400px;
}

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

body.app-layout {
    font-family: 'Outfit', sans-serif;
    background-color: var(--bg-main);
    color: var(--text-main);
    height: 100vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background-image: 
        radial-gradient(circle at 50% 50%, rgba(0, 255, 170, 0.03) 0%, transparent 50%),
        linear-gradient(rgba(255,255,255,0.01) 1px, transparent 1px),
        linear-gradient(90deg, rgba(255,255,255,0.01) 1px, transparent 1px);
    background-size: 100% 100%, 40px 40px, 40px 40px;
}

/* Header */
.app-header {
    height: var(--header-h);
    background: var(--bg-panel);
    backdrop-filter: blur(20px);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 30px;
    z-index: 1000;
}

.logo .glitch {
    font-family: 'Michroma', sans-serif;
    font-size: 1.1rem;
    letter-spacing: 3px;
    color: var(--accent);
    text-shadow: 0 0 15px var(--accent-glow);
}

.logo .version {
    font-size: 0.6rem;
    color: var(--text-dim);
    margin-left: 10px;
    font-family: monospace;
}

.system-status {
    display: flex;
    align-items: center;
    gap: 30px;
}

.engine-ready {
    font-family: 'Michroma', sans-serif;
    font-size: 0.6rem;
    color: var(--accent);
    background: var(--accent-dim);
    padding: 6px 18px;
    border-radius: 30px;
    border: 1px solid var(--accent-dim);
    display: flex;
    align-items: center;
    gap: 8px;
}

.hud-status-integrated {
    display: flex;
    gap: 15px;
    font-family: 'Michroma', sans-serif;
    font-size: 0.55rem;
    color: var(--text-dim);
    letter-spacing: 1px;
}

.hud-coords {
    color: var(--accent);
    font-family: 'JetBrains Mono', monospace;
    min-width: 100px;
}

.indicator {
    width: 6px;
    height: 6px;
    background: var(--accent);
    border-radius: 50%;
    box-shadow: 0 0 10px var(--accent);
}

/* Main Viewport */
.app-viewport {
    flex: 1;
    display: grid;
    grid-template-columns: var(--panel-w-left) 1fr var(--panel-w-right);
    overflow: hidden;
    min-height: 0; /* Important for flex-shrink */
}

/* Sidebars */
.sidebar-left, .sidebar-right {
    background: var(--bg-panel);
    backdrop-filter: blur(20px);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    min-height: 0;
    z-index: 50;
}

.sidebar-right {
    border-right: none;
    border-left: 1px solid var(--border);
}

.sidebar-content {
    padding: 30px 20px;
    overflow-y: auto;
    flex: 1;
}

.sidebar-header {
    padding: 20px;
    border-bottom: 1px solid var(--border);
    background: rgba(255,255,255,0.02);
}

h3 {
    font-family: 'Michroma', sans-serif;
    font-size: 0.65rem;
    text-transform: uppercase;
    color: var(--text-dim);
    margin-bottom: 20px;
    letter-spacing: 2px;
}

/* Cards */
.card, .config-section, .tool-section, .upload-section {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 20px;
    margin-bottom: 25px;
    transition: 0.3s;
}

.card:hover { border-color: var(--accent-glow); }

/* Toggle Group */
.toggle-group {
    margin-bottom: 25px;
    display: flex;
    align-items: center;
}

.switch-label {
    display: flex;
    align-items: center;
    gap: 12px;
    cursor: pointer;
    font-size: 0.8rem;
    color: var(--text-main);
}

.switch-label input { display: none; }

.custom-checkbox {
    width: 40px;
    height: 20px;
    background: rgba(255,255,255,0.1);
    border-radius: 20px;
    position: relative;
    transition: 0.3s;
    border: 1px solid var(--border);
}

.custom-checkbox::after {
    content: '';
    position: absolute;
    width: 14px;
    height: 14px;
    background: #fff;
    border-radius: 50%;
    top: 2px;
    left: 3px;
    transition: 0.3s;
}

.switch-label input:checked + .custom-checkbox {
    background: var(--accent-dim);
    border-color: var(--accent);
}

.switch-label input:checked + .custom-checkbox::after {
    left: 21px;
    background: var(--accent);
    box-shadow: 0 0 10px var(--accent);
}

/* Buttons */
.btn-primary, .btn-export {
    width: 100%;
    background: var(--accent);
    color: #000;
    border: none;
    padding: 15px;
    border-radius: 8px;
    font-family: 'Michroma', sans-serif;
    font-size: 0.65rem;
    font-weight: 700;
    cursor: pointer;
    transition: 0.3s;
}

.btn-primary:hover { transform: translateY(-2px); box-shadow: 0 5px 20px var(--accent-glow); }

.btn-secondary {
    background: rgba(68, 136, 255, 0.1);
    border: 1px solid rgba(68, 136, 255, 0.3);
    color: #4488ff;
    padding: 8px 15px;
    border-radius: 6px;
    font-family: 'Michroma', sans-serif;
    font-size: 0.55rem;
    cursor: pointer;
    transition: 0.3s;
    margin-right: 5px;
}

.btn-secondary:hover {
    background: #4488ff;
    color: #fff;
    box-shadow: 0 0 15px rgba(68, 136, 255, 0.4);
}

.btn-danger {
    background: rgba(255, 50, 70, 0.1);
    border: 1px solid rgba(255, 50, 70, 0.3);
    color: #ff3344;
    padding: 8px 15px;
    border-radius: 6px;
    font-family: 'Michroma', sans-serif;
    font-size: 0.55rem;
    cursor: pointer;
    transition: 0.3s;
}

.btn-danger:hover {
    background: #ff3344;
    color: #fff;
    box-shadow: 0 0 15px rgba(255, 51, 68, 0.4);
}

.panel-header {
    padding: 20px;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.panel-header h3 {
    font-family: 'Michroma', sans-serif;
    font-size: 0.7rem;
    letter-spacing: 1px;
}

/* Toolbar */
.toolbar { display: flex; gap: 8px; margin-bottom: 15px; }
.tool-btn {
    flex: 1;
    background: rgba(255,255,255,0.05);
    border: 1px solid var(--border);
    color: #fff;
    padding: 12px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 1.2rem;
    transition: 0.2s;
}

.tool-btn:hover { border-color: var(--accent); }
.tool-btn.active { 
    background: var(--accent-dim);
    border-color: var(--accent);
    color: var(--accent);
    box-shadow: inset 0 0 10px var(--accent-dim);
}

.tool-tip { font-size: 0.7rem; color: var(--text-dim); font-style: italic; text-align: center; }

/* Drop Zone */
.drop-zone {
    border: 2px dashed var(--border);
    padding: 40px 20px;
    text-align: center;
    border-radius: 12px;
    cursor: pointer;
}

.drop-icon { font-size: 2.5rem; margin-bottom: 15px; opacity: 0.3; }

/* CANVAS STAGE - NO CENTERING TO PREVENT SHIFTS */
.canvas-stage {
    background: #000;
    position: relative;
    overflow: hidden;
    height: 100%;
    width: 100%;
    border-left: 1px solid var(--border);
    border-right: 1px solid var(--border);
}

.hud-marker {
    position: absolute;
    width: 20px;
    height: 20px;
    border: 2px solid var(--accent);
    z-index: 100;
    pointer-events: none;
    opacity: 0.5;
}

.hud-marker.tl { top: 20px; left: 20px; border-right: none; border-bottom: none; }
.hud-marker.tr { top: 20px; right: 20px; border-left: none; border-bottom: none; }
.hud-marker.bl { bottom: 20px; left: 20px; border-right: none; border-top: none; }
.hud-marker.br { bottom: 20px; right: 20px; border-left: none; border-top: none; }



.canvas-container {
    width: 100%;
    height: 100%;
    overflow: auto;
    background-image: 
        linear-gradient(45deg, #0a0a0a 25%, transparent 25%), 
        linear-gradient(-45deg, #0a0a0a 25%, transparent 25%), 
        linear-gradient(45deg, transparent 75%, #0a0a0a 75%), 
        linear-gradient(-45deg, transparent 75%, #0a0a0a 75%);
    background-size: 20px 20px;
    background-position: 0 0, 0 10px, 10px -10px, -10px 0px;
    position: relative;
    display: flex;
    justify-content: flex-start;
    align-items: flex-start;
}

#zoom-wrapper {
    position: relative;
    transform-origin: 0 0;
    transition: transform 0.1s ease-out;
}

#main-canvas {
    display: block;
    image-rendering: pixelated;
    box-shadow: 0 0 50px rgba(0,0,0,0.5);
}

.zoom-controls {
    position: absolute;
    bottom: 30px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(15, 15, 20, 0.85);
    backdrop-filter: blur(10px);
    border: 1px solid var(--border);
    padding: 8px 15px;
    border-radius: 30px;
    display: flex;
    align-items: center;
    gap: 15px;
    z-index: 500;
    box-shadow: 0 10px 30px rgba(0,0,0,0.5);
}

.zoom-controls button {
    background: rgba(255,255,255,0.05);
    border: 1px solid var(--border);
    color: #fff;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    transition: 0.2s;
}

.zoom-controls button:hover {
    background: var(--accent);
    color: #000;
}

#zoom-level {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.8rem;
    color: var(--accent);
    min-width: 50px;
    text-align: center;
}

.btn-reset-zoom {
    font-family: 'Michroma', sans-serif !important;
    font-size: 0.5rem !important;
    width: auto !important;
    padding: 0 12px !important;
    border-radius: 15px !important;
}

#overlay-container {
    position: absolute;
    top: 0;
    left: 0;
    pointer-events: none;
    z-index: 10;
}

/* UI Boxes */
.selection-area {
    position: absolute;
    border: 1px solid #4488ff;
    background: rgba(68, 136, 255, 0.2);
    z-index: 1000;
    pointer-events: none;
}

.ghost-box {
    position: absolute;
    border: 2px dashed var(--accent);
    background: var(--accent-dim);
    z-index: 1000;
    pointer-events: none;
}

.ui-box {
    position: absolute;
    border: 1px solid var(--accent);
    background: rgba(0, 255, 170, 0.02);
    pointer-events: auto;
    cursor: pointer;
    transition: background 0.1s, border-color 0.1s;
}

.ui-box:hover { background: rgba(0, 255, 170, 0.1); border-color: #fff; }
.ui-box.selected { 
    border-width: 2px; 
    border-color: #fff; 
    background: rgba(255,255,255,0.1); 
    box-shadow: 0 0 15px rgba(255,255,255,0.2);
    z-index: 50;
}

/* Resizing Handles */
.ui-box.selected .handle {
    position: absolute;
    width: 8px;
    height: 8px;
    background: #fff;
    border: 1px solid var(--accent);
    border-radius: 2px;
    z-index: 60;
}

.handle.tl { top: -5px; left: -5px; cursor: nwse-resize; }
.handle.tr { top: -5px; right: -5px; cursor: nesw-resize; }
.handle.bl { bottom: -5px; left: -5px; cursor: nesw-resize; }
.handle.br { bottom: -5px; right: -5px; cursor: nwse-resize; }

.ui-box:active { cursor: grabbing; }

/* Removing Animation */
.ui-box.removing {
    border-color: #ff3344 !important;
    background: rgba(255, 50, 70, 0.5) !important;
    box-shadow: 0 0 20px #ff3344 !important;
    transform: scale(0.9);
    opacity: 0;
    transition: 0.2s;
}

/* Results Sidebar */
.results-grid {
    padding: 15px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    overflow-y: auto;
}

.sprite-preview {
    background: var(--bg-card);
    border: 1px solid var(--border);
    padding: 15px;
    border-radius: 12px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    transition: 0.3s;
}

.sprite-preview:hover { 
    border-color: var(--accent); 
    transform: translateY(-2px); 
}

.export-section {
    padding: 20px;
    background: rgba(0,0,0,0.4);
    border-top: 1px solid rgba(0,255,149,0.1);
}

.filename-input-container {
    margin-bottom: 15px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.filename-input-container label {
    font-size: 0.7rem;
    color: var(--accent);
    letter-spacing: 2px;
    font-weight: bold;
}

.filename-input-container input {
    background: rgba(0,0,0,0.5);
    border: 1px solid rgba(0,255,149,0.3);
    color: #fff;
    padding: 10px;
    font-family: inherit;
    font-size: 0.9rem;
    border-radius: 4px;
    outline: none;
    transition: 0.3s;
}

.filename-input-container input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 10px rgba(0,255,149,0.2);
}

.btn-export {
    width: 100%;
    justify-content: center;
}

.sprite-preview.selected {
    border-color: #fff;
    background: rgba(255,255,255,0.05);
    box-shadow: 0 0 20px rgba(255,255,255,0.1);
}

.sprite-preview img {
    max-width: 100%;
    max-height: 200px;
    object-fit: contain;
    image-rendering: pixelated;
    border-radius: 4px;
    background: rgba(0,0,0,0.2);
}

.sprite-info {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.65rem;
    color: var(--text-dim);
}

.btn-delete {
    background: rgba(255, 50, 70, 0.1);
    border: 1px solid rgba(255, 50, 70, 0.2);
    color: #ff3344;
    padding: 6px 15px;
    border-radius: 6px;
    font-size: 0.65rem;
    cursor: pointer;
    width: 100%;
}

.btn-delete:hover { background: #ff3344; color: #fff; }

/* Status Popups */
.status-popup {
    position: fixed;
    bottom: 30px;
    right: 30px;
    background: var(--bg-panel);
    backdrop-filter: blur(10px);
    border: 1px solid var(--accent);
    padding: 20px 30px;
    color: var(--accent);
    font-family: 'Michroma', sans-serif;
    font-size: 0.7rem;
    border-radius: 12px;
    z-index: 2000;
    display: flex;
    align-items: center;
    gap: 15px;
}

/* Scrollbars */
::-webkit-scrollbar { width: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 10px; }
::-webkit-scrollbar-thumb:hover { background: var(--accent-dim); }