:root {
    --bg-color: #0f1115;
    --panel-bg: rgba(20, 22, 27, 0.9);
    --text-primary: #f8f9fa;
    --text-secondary: #94a3b8;
    --accent-color: #ec4899;
    --accent-hover: #f472b6;
    --border-color: rgba(255, 255, 255, 0.1);
    --glass-bg: rgba(30, 41, 59, 0.5);
    --glass-border: rgba(255, 255, 255, 0.15);
}

* { 
    margin: 0; 
    padding: 0; 
    box-sizing: border-box; 
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
}

body {
    font-family: 'Outfit', sans-serif;
    background-color: var(--bg-color);
    color: var(--text-primary);
    overflow: hidden;
    display: flex;
    height: 100vh;
}

#canvas-container {
    flex-grow: 1;
    position: relative;
    z-index: 1;
    touch-action: none;
    transition: height 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

#ui-container {
    width: 320px;
    height: 100vh;
    background: var(--panel-bg);
    backdrop-filter: blur(25px);
    -webkit-backdrop-filter: blur(25px);
    border-right: 1px solid var(--border-color);
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 24px;
    z-index: 2000;
    box-shadow: 4px 0 24px rgba(0,0,0,0.5);
    transition: transform 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    touch-action: pan-y;
}

h1 {
    font-size: 1.5rem;
    font-weight: 600;
    margin-bottom: 8px;
    background: linear-gradient(135deg, #f8f9fa, #94a3b8);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

.control-group {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.control-label {
    font-size: 0.85rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 1px;
    font-weight: 600;
}

.button-group {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}

button {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    padding: 10px 16px;
    border-radius: 8px;
    font-family: inherit;
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.2s ease;
}

button:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: rgba(255, 255, 255, 0.2);
}

button.active {
    background: var(--accent-color);
    border-color: var(--accent-color);
    color: white;
    box-shadow: 0 4px 12px rgba(236, 72, 153, 0.4);
}

#btn-toggle-cutting.active {
    background: #6366f1; /* Indigo */
    border-color: #6366f1;
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.4);
}

/* -- Overlay UI (Top/Bottom Float) -- */

#overlay-ui {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 1000;
    transition: opacity 0.3s ease, visibility 0.3s ease;
}

#overlay-ui * {
    pointer-events: auto;
}

#zoom-slider-container {
    position: absolute;
    top: 24px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--glass-bg);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    padding: 8px 16px;
    border-radius: 30px;
    border: 1px solid var(--glass-border);
    display: flex;
    align-items: center;
    gap: 12px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.3);
    touch-action: none;
    z-index: 2000;
}

#cutting-overlay-controls {
    position: absolute;
    top: 76px; /* Below zoom-slider-container */
    left: 50%;
    transform: translateX(-50%);
    width: 100%;
    max-width: 240px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    z-index: 1500;
}

.portal-link-btn {
    position: absolute;
    top: 24px;
    right: 24px;
    background: var(--glass-bg);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    padding: 10px;
    border-radius: 50%;
    border: 1px solid var(--glass-border);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-primary);
    text-decoration: none;
    box-shadow: 0 4px 20px rgba(0,0,0,0.3);
    transition: all 0.2s ease;
    z-index: 2000;
    touch-action: none;
}

.portal-link-btn:hover {
    background: var(--accent-color);
    border-color: var(--accent-color);
    box-shadow: 0 4px 20px rgba(236, 72, 153, 0.4);
}

.zoom-label {
    font-size: 0.7rem;
    font-weight: 700;
    color: var(--text-secondary);
    text-transform: uppercase;
}

.folding-hint {
    font-size: 0.75rem;
    color: var(--text-secondary);
    text-align: center;
    line-height: 1.4;
    margin-bottom: -4px;
    opacity: 0.8;
}

#bottom-controls-stack {
    position: absolute;
    bottom: 80px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    width: 100%;
    max-width: 420px;
    padding: 0 20px;
    transition: bottom 0.4s ease;
    touch-action: none;
}

.main-controls-row {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
}

.pill-group {
    background: var(--glass-bg);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    padding: 10px 18px;
    border-radius: 40px;
    border: 1px solid var(--glass-border);
    display: flex;
    align-items: center;
    gap: 12px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
    width: 100%;
}

#fold-ctrl-container {
    justify-content: space-between;
}

#fold-val {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--accent-color);
    min-width: 35px;
    text-align: right;
}

.pill-label {
    font-size: 0.75rem;
    font-weight: 700;
    color: var(--text-secondary);
    text-transform: uppercase;
}

.action-btn-pill {
    background: var(--accent-color);
    color: white;
    padding: 10px 24px;
    border-radius: 40px;
    border: none;
    font-weight: 600;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    box-shadow: 0 4px 20px rgba(236, 72, 153, 0.4);
    cursor: pointer;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.action-btn-pill.icon-only {
    width: 48px;
    height: 48px;
    padding: 0;
    border-radius: 50%;
}

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

/* Toggle Pill Buttons (v1.50) */
.toggle-row {
    display: flex;
    gap: 10px;
    width: 100%;
}

.toggle-pill {
    flex: 1;
    justify-content: center;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-primary);
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.toggle-pill.active {
    background: var(--accent-color);
    border-color: var(--accent-color);
    color: white;
    box-shadow: 0 0 15px rgba(236, 72, 153, 0.6);
}

/* Gear Button */
.mobile-toggle-btn {
    position: fixed;
    top: 50%;
    right: 20px;
    transform: translateY(-50%);
    background: var(--glass-bg);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    color: white;
    border: 1px solid var(--glass-border);
    border-radius: 50%;
    width: 52px;
    height: 52px;
    font-size: 1.5rem;
    box-shadow: 0 4px 15px rgba(0,0,0,0.4);
    z-index: 2500;
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: all 0.3s ease;
    touch-action: none;
}

.mobile-toggle-btn:hover {
    background: var(--accent-color);
}

/* Range Inputs */
input[type="range"] {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    height: 4px;
    background: rgba(255, 255, 255, 0.15);
    border-radius: 2px;
    outline: none;
    touch-action: pan-y !important; /* Allow touch sliding (v2.8.1 fix) */
}

input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--accent-color);
    cursor: pointer;
    border: 2px solid white;
    box-shadow: 0 0 10px rgba(236, 72, 153, 0.5);
}

/* Net Layout Grid */
.thumbnail-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    padding: 4px 0 12px 0;
}

.net-thumb {
    width: 60px;
    height: 60px;
    flex-shrink: 0;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.net-thumb.active {
    border-color: var(--accent-color);
    background: rgba(236, 72, 153, 0.15);
}

.net-thumb canvas {
    max-width: 90%;
    max-height: 90%;
    height: auto;
    object-fit: contain;
}

#version-tag {
    position: fixed;
    bottom: 15px;
    right: 20px;
    font-size: 0.75rem;
    color: var(--text-secondary);
    opacity: 0.3;
    z-index: 1000;
}

/* -- Responsive: Bottom Sheet Logic (v1.50) -- */

@media (max-width: 768px) {
    #ui-container {
        position: fixed;
        top: auto;
        bottom: 0;
        left: 0;
        right: 0;
        width: 100%;
        height: auto;
        max-height: 60svh;
        border-right: none;
        border-top: 1px solid var(--border-color);
        border-radius: 24px 24px 0 0;
        padding: 24px 20px 40px 20px;
        transform: translateY(105%);
        box-shadow: 0 -10px 40px rgba(0,0,0,0.6);
        overflow-y: auto;
    }

    body.panel-active #ui-container {
        transform: translateY(0);
    }

    /* Hide other UI when setting panel is active on mobile */
    body.panel-active #overlay-ui,
    body.panel-active #version-tag {
        opacity: 0;
        visibility: hidden;
    }

    .mobile-toggle-btn {
        top: 50% !important;
        right: 20px !important;
        bottom: auto !important;
        transform: translateY(-50%) !important;
        width: 56px;
        height: 56px;
    }

    body.panel-active .mobile-toggle-btn {
        right: 20px !important;
        background: var(--accent-color);
        transform: translateY(-50%) scale(0.9) rotate(90deg) !important;
    }

    /* Shift portal button down on mobile to avoid zoom/cutting overlap (v2.7) */
    .portal-link-btn {
        top: 24px;
        bottom: auto;
        right: 24px;
    }

    #bottom-controls-stack {
        bottom: 40px; /* Lowered from 100px */
    }

    #canvas-container {
        height: 100svh;
    }

    body.panel-active #canvas-container {
        height: 40svh;
        border-bottom: 1px solid var(--border-color);
    }
}
