/* Reset & Base Variables */
:root {
    --bg-dark: #020617;
    --panel-bg: #0f172a;
    --card-bg: #1e293b;
    --border-color: #334155;
    --accent-blue: #38bdf8;
    --accent-indigo: #6366f1;
    --accent-emerald: #10b981;
    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    --font-family: 'Outfit', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
}

html, body {
    width: 100%;
    height: 100%;
    font-family: var(--font-family);
    background-color: var(--bg-dark);
    color: var(--text-main);
    overflow: hidden;
}

/* App Layout */
#app-container {
    display: flex;
    flex-direction: row;
    width: 100%;
    height: 100%;
    position: relative;
}

/* Canvas Viewport */
#canvas-container {
    flex: 1;
    height: 100%;
    position: relative;
    background-color: #060812;
    overflow: hidden;
    touch-action: none;
    -webkit-user-select: none;
    user-select: none;
}

#canvas-container.mode-stir {
    cursor: grab;
}

#canvas-container.mode-stir:active {
    cursor: grabbing;
}

#canvas-container.mode-wand {
    cursor: crosshair;
}

#canvas-container.mode-pin {
    cursor: crosshair;
}

#viewport-canvas {
    display: block;
    width: 100%;
    height: 100%;
    touch-action: none;
    -webkit-user-select: none;
    user-select: none;
}

/* Canvas Overlays */
#floating-controls {
    position: absolute;
    top: 16px;
    left: 16px;
    display: flex;
    gap: 8px;
    z-index: 10;
}

.floating-btn {
    width: 38px;
    height: 38px;
    border-radius: 10px;
    background: rgba(15, 23, 42, 0.80);
    backdrop-filter: blur(8px);
    border: 1px solid var(--border-color);
    color: var(--text-main);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
}

.floating-btn:hover {
    background: rgba(30, 41, 59, 0.95);
    border-color: var(--accent-blue);
    transform: scale(1.05);
}

.floating-btn:active {
    transform: scale(0.95);
}

#stats-badge {
    position: absolute;
    bottom: 16px;
    left: 16px;
    background: rgba(15, 23, 42, 0.75);
    backdrop-filter: blur(8px);
    border: 1px solid rgba(255, 255, 255, 0.08);
    color: #94a3b8;
    font-size: 0.75rem;
    font-weight: 500;
    padding: 6px 12px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    gap: 6px;
    z-index: 10;
    pointer-events: none;
}

.dot-separator {
    opacity: 0.4;
}

/* Toast Message */
#toast {
    position: absolute;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%);
    background: #0ea5e9;
    color: #ffffff;
    font-weight: 600;
    font-size: 0.85rem;
    padding: 10px 20px;
    border-radius: 9999px;
    box-shadow: 0 10px 25px -5px rgba(14, 165, 233, 0.5);
    z-index: 50;
    opacity: 1;
    transition: opacity 0.3s ease, transform 0.3s ease;
    pointer-events: none;
}

#toast.hidden {
    opacity: 0;
    transform: translateX(-50%) translateY(10px);
}

/* Sidebar Control Panel */
#control-panel {
    width: 390px;
    height: 100%;
    background-color: var(--panel-bg);
    border-left: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    z-index: 20;
    box-shadow: -8px 0 30px rgba(0, 0, 0, 0.4);
}

/* Fullscreen & Sidebar Visibility: Hide sidebar completely so canvas fills 100% */
#control-panel.hidden-fullscreen,
#app-container.fullscreen-active #control-panel,
#app-container.sidebar-hidden #control-panel,
body.is-fullscreen #control-panel,
:fullscreen #control-panel,
:-webkit-full-screen #control-panel {
    display: none !important;
}

#icon-exit-fullscreen {
    display: none;
}

body.is-fullscreen #icon-enter-fullscreen,
#app-container.fullscreen-active #icon-enter-fullscreen,
#app-container.sidebar-hidden #icon-enter-fullscreen {
    display: none !important;
}

body.is-fullscreen #icon-exit-fullscreen,
#app-container.fullscreen-active #icon-exit-fullscreen,
#app-container.sidebar-hidden #icon-exit-fullscreen {
    display: inline-block !important;
}

#panel-header {
    padding: 16px 18px;
    border-bottom: 1px solid var(--border-color);
    background: rgba(30, 41, 59, 0.5);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.collapse-sidebar-btn {
    background: transparent;
    border: 1px solid rgba(255, 255, 255, 0.12);
    color: #94a3b8;
    width: 32px;
    height: 32px;
    min-width: 32px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
}

.collapse-sidebar-btn:hover {
    background: rgba(255, 255, 255, 0.08);
    color: #f8fafc;
    border-color: rgba(255, 255, 255, 0.25);
    transform: translateX(1px);
}

.brand {
    display: flex;
    align-items: center;
    gap: 12px;
}

.brand-icon {
    font-size: 1.7rem;
}

.brand-text h1 {
    font-size: 1.1rem;
    font-weight: 700;
    letter-spacing: -0.01em;
    color: #ffffff;
}

.brand-text .subtitle {
    font-size: 0.72rem;
    color: var(--text-muted);
    font-weight: 400;
}

#panel-content {
    flex: 1;
    overflow-y: auto;
    padding: 16px 20px 32px 20px;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

/* Custom Scrollbar */
#panel-content::-webkit-scrollbar {
    width: 6px;
}

#panel-content::-webkit-scrollbar-track {
    background: transparent;
}

#panel-content::-webkit-scrollbar-thumb {
    background: #334155;
    border-radius: 4px;
}

#panel-content::-webkit-scrollbar-thumb:hover {
    background: #475569;
}

/* Section Groups */
.section-group {
    display: flex;
    flex-direction: column;
    gap: 14px;
    background: rgba(30, 41, 59, 0.35);
    border: 1px solid rgba(255, 255, 255, 0.05);
    padding: 14px;
    border-radius: 12px;
}

.section-header {
    font-size: 0.70rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    color: var(--accent-blue);
    text-transform: uppercase;
}

/* Controls & Sliders */
.control-row {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.label-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.label-row label {
    font-size: 0.82rem;
    font-weight: 500;
    color: #cbd5e1;
}

.val-badge {
    font-size: 0.75rem;
    font-family: monospace;
    font-weight: 600;
    color: var(--accent-blue);
    background: rgba(56, 189, 248, 0.12);
    padding: 2px 7px;
    border-radius: 4px;
    border: 1px solid rgba(56, 189, 248, 0.25);
}

/* Tool Selector Grid */
.tool-selector-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 6px;
    margin-top: 4px;
}

.tool-select-btn {
    background: rgba(30, 41, 59, 0.6);
    border: 1px solid var(--border-color);
    color: var(--text-muted);
    padding: 10px 4px;
    border-radius: 8px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    cursor: pointer;
    transition: all 0.2s ease;
    font-family: inherit;
}

.tool-select-btn:hover {
    background: rgba(51, 65, 85, 0.8);
    color: var(--text-main);
    border-color: rgba(56, 189, 248, 0.4);
}

.tool-select-btn.active {
    background: linear-gradient(135deg, rgba(56, 189, 248, 0.22), rgba(99, 102, 241, 0.28));
    border-color: var(--accent-blue);
    color: #ffffff;
    box-shadow: 0 0 10px rgba(56, 189, 248, 0.25);
}

.tool-btn-icon {
    font-size: 1.25rem;
}

.tool-btn-text {
    font-size: 0.72rem;
    font-weight: 500;
    text-align: center;
}

/* Toggle Switch */
.toggle-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    cursor: pointer;
}

.switch {
    position: relative;
    display: inline-block;
    width: 44px;
    height: 24px;
    flex-shrink: 0;
}

.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider-toggle {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: #334155;
    transition: 0.25s ease;
    border-radius: 24px;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.slider-toggle:before {
    position: absolute;
    content: "";
    height: 16px;
    width: 16px;
    left: 3px;
    bottom: 3px;
    background-color: #ffffff;
    transition: 0.25s ease;
    border-radius: 50%;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}

input:checked + .slider-toggle {
    background-color: var(--accent-blue);
    border-color: rgba(56, 189, 248, 0.4);
}

input:checked + .slider-toggle:before {
    transform: translateX(20px);
}

input[type="range"] {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    height: 6px;
    background: #334155;
    border-radius: 3px;
    outline: none;
    cursor: pointer;
    transition: background 0.15s;
}

input[type="range"]:hover {
    background: #475569;
}

input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 16px;
    height: 16px;
    background: #ffffff;
    border: 2px solid var(--accent-blue);
    border-radius: 50%;
    box-shadow: 0 0 10px rgba(56, 189, 248, 0.5);
    cursor: pointer;
    transition: transform 0.1s ease, box-shadow 0.1s ease;
}

input[type="range"]::-webkit-slider-thumb:hover {
    transform: scale(1.15);
    box-shadow: 0 0 14px rgba(56, 189, 248, 0.8);
}

/* Select Dropdowns */
.select-dropdown {
    width: 100%;
    padding: 8px 12px;
    background: #1e293b;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    color: #f1f5f9;
    font-family: var(--font-family);
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    outline: none;
    transition: border-color 0.2s, background-color 0.2s;
}

.select-dropdown:hover {
    border-color: #475569;
}

.select-dropdown:focus {
    border-color: var(--accent-blue);
    box-shadow: 0 0 0 2px rgba(56, 189, 248, 0.2);
}

/* Buttons */
.button-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin-top: 4px;
}

.btn {
    padding: 9px 14px;
    border-radius: 8px;
    font-family: var(--font-family);
    font-size: 0.82rem;
    font-weight: 600;
    cursor: pointer;
    border: none;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
}

.btn-primary {
    background: #2563eb;
    color: #ffffff;
}

.btn-primary:hover {
    background: #1d4ed8;
    transform: translateY(-1px);
}

.btn-secondary {
    background: #334155;
    color: #f8fafc;
}

.btn-secondary:hover {
    background: #475569;
    transform: translateY(-1px);
}

/* Export Buttons */
.export-group {
    border-color: rgba(56, 189, 248, 0.3);
    background: rgba(14, 165, 233, 0.05);
}

.export-note {
    font-size: 0.72rem;
    color: var(--text-muted);
}

.button-stack {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.btn-export {
    background: linear-gradient(135deg, #0284c7 0%, #0369a1 100%);
    color: #ffffff;
    padding: 12px 14px;
    border-radius: 10px;
    text-align: left;
    display: flex;
    align-items: center;
    gap: 12px;
    box-shadow: 0 4px 15px rgba(2, 132, 199, 0.3);
}

.btn-export:hover {
    background: linear-gradient(135deg, #0369a1 0%, #075985 100%);
    transform: translateY(-1px);
    box-shadow: 0 6px 20px rgba(2, 132, 199, 0.4);
}

.btn-export-outline {
    background: rgba(30, 41, 59, 0.7);
    color: #e2e8f0;
    border: 1px solid var(--border-color);
    padding: 10px 14px;
    border-radius: 10px;
    text-align: left;
    display: flex;
    align-items: center;
    gap: 12px;
}

.btn-export-outline:hover {
    background: rgba(51, 65, 85, 0.8);
    border-color: var(--accent-blue);
    transform: translateY(-1px);
}

.btn-icon {
    font-size: 1.3rem;
}

.btn-text {
    display: flex;
    flex-direction: column;
}

.btn-text strong {
    font-size: 0.85rem;
}

.btn-text small {
    font-size: 0.68rem;
    opacity: 0.8;
}

.hidden {
    display: none !important;
}

/* Responsive Styles for Mobile */
@media (max-width: 900px) {
    #app-container {
        flex-direction: column;
    }
    
    #canvas-container {
        height: 50vh;
    }
    
    #control-panel {
        width: 100%;
        height: 50vh;
        border-left: none;
        border-top: 1px solid var(--border-color);
    }
}
