:root {
    --bg-color: #111111;
    --panel-bg: rgba(30, 30, 30, 0.7);
    --panel-border: rgba(255, 255, 255, 0.1);
    --text-main: #f0f0f0;
    --text-dim: #a0a0a0;
    --accent: #5a8dee;
    --accent-hover: #7aa2f7;
    --danger: #ff4b4b;
    --danger-hover: #ff7676;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-tap-highlight-color: transparent; /* Remove tap highlight on mobile v1.3 */
}

body {
    font-family: 'Inter', sans-serif;
    background-color: var(--bg-color);
    color: var(--text-main);
    overflow: hidden;
    width: 100vw;
    height: 100vh;
    -webkit-user-select: none;  /* Mobile Safari */
    -ms-user-select: none;      /* IE/Edge */
    user-select: none;          /* Standard */
    -webkit-touch-callout: none; /* Disable iOS long-press menu */
}

#canvas-container {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1;
    touch-action: none; /* v1.1: Enable smooth mobile interaction */
}

#ui-container {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 10;
    pointer-events: none;
    display: flex;
    flex-direction: column;
    justify-content: flex-end; /* Push controls to bottom */
    align-items: center;       /* Center controls horizontally */
    padding: 24px;
    padding-bottom: calc(32px + env(safe-area-inset-bottom, 0px)); /* Avoid mobile address bar */
}

.panel {
    background: var(--panel-bg);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--panel-border);
    border-radius: 12px;
    padding: 16px;
    pointer-events: auto;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
    user-select: none;
    font-size: 13px;
    width: 95%;
    max-width: 390px;
}

.main-title {
    position: absolute;
    top: 24px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 100;
    font-size: 28px;
    font-weight: 600;
    margin: 0;
    background: linear-gradient(135deg, var(--accent), var(--accent-hover));
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    pointer-events: none;
    text-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    white-space: nowrap;
}

.cut-instructions {
    position: absolute;
    top: 72px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 100;
    background: rgba(50, 50, 50, 0.8);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    border: 1px solid var(--panel-border);
    padding: 8px 16px;
    border-radius: 20px;
    color: #fff;
    font-size: 14px;
    pointer-events: none;
    box-shadow: 0 4px 20px rgba(0,0,0,0.4);
    transition: all 0.3s ease;
}

.cut-instructions.warning {
    color: #ff4b4b;
    border: 1px solid rgba(255, 75, 75, 0.3);
    background: rgba(255, 75, 75, 0.1);
}

.startup-guide {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 2000;
    background: rgba(0, 0, 0, 0.85);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid rgba(79, 172, 254, 0.5);
    padding: 24px 48px 24px 32px;
    border-radius: 16px;
    color: #fff;
    font-size: 15px;
    font-weight: 500;
    box-shadow: 0 12px 48px rgba(0,0,0,0.5);
    transition: all 0.5s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    align-items: center;
    white-space: nowrap;
}

.startup-guide.hidden {
    opacity: 0;
    transform: translate(-50%, calc(-50% - 20px));
    pointer-events: none;
}

.close-guide-btn {
    position: absolute;
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    color: rgba(255, 255, 255, 0.6);
    font-size: 20px;
    line-height: 1;
    cursor: pointer;
    padding: 4px;
    transition: color 0.2s;
    min-height: auto;
    width: auto;
}

.close-guide-btn:hover {
    color: #fff;
    background: none;
}

.hud-stats {
    position: absolute;
    top: 12px;
    left: 12px;
    z-index: 1000;
    background: rgba(50, 50, 50, 0.8);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    padding: 8px 12px;
    border-radius: 12px;
    color: #fff;
    min-width: 110px;
    pointer-events: none;
    transition: opacity 0.3s ease, transform 0.3s ease;
    box-shadow: 0 8px 32px rgba(0,0,0,0.4);
}

.hud-stats.hidden {
    opacity: 0;
    transform: translateY(-10px);
}

.hud-row {
    display: flex;
    justify-content: flex-start;
    align-items: baseline;
    gap: 4px;
    margin-bottom: 2px;
}

.hud-row:last-child {
    margin-bottom: 0;
}

.hud-label {
    font-size: 11px;
    font-weight: 500;
    color: rgba(255, 255, 255, 0.5);
    white-space: nowrap;
}

.hud-value {
    font-size: 14px;
    font-weight: 800;
    font-family: 'Outfit', sans-serif;
}

.hud-value.removed {
    color: #ff3366;
    text-shadow: 0 0 10px rgba(255, 51, 102, 0.3);
}


.preset-section {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.preset-title {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-main);
    opacity: 0.9;
}

.preset-controls {
    display: flex;
    gap: 8px;
    width: 100%;
}

.preset-section label {
    font-size: 11px;
    color: var(--text-dim);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

#preset-select, #preset-scale {
    padding: 10px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--panel-border);
    border-radius: 6px;
    color: var(--text-main);
    font-size: 14px;
    cursor: pointer;
    outline: none;
    transition: all 0.2s ease;
    min-height: 44px;
}

#preset-scale {
    flex: 1;
}

#preset-select {
    flex: 2;
}

#preset-select:hover, #preset-scale:hover {
    background: rgba(255, 255, 255, 0.1);
}

#preset-select option, #preset-scale option {
    background: #2a2a2a;
    color: #fff;
}

.mode-toggles {
    display: flex;
    gap: 8px;
}

button {
    flex: 1;
    padding: 12px 8px; /* v1.2: Larger padding for touch */
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--panel-border);
    border-radius: 8px;
    color: var(--text-main);
    font-family: inherit;
    font-weight: 600;
    font-size: 14px; /* v1.2: Larger font for readability */
    cursor: pointer;
    transition: all 0.2s ease;
    white-space: nowrap;
    min-height: 44px; /* v1.2: Minimum hit size */
}

button:hover {
    background: rgba(255, 255, 255, 0.15);
}

button.active {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
}

button.danger {
    flex: none;
    background: rgba(255, 75, 75, 0.2);
    border-color: rgba(255, 75, 75, 0.4);
    color: #fff;
}

button.danger:hover {
    background: var(--danger);
    border-color: var(--danger);
}

.hidden {
    display: none !important;
}

.actions {
    display: flex;
    flex-direction: column;
    gap: 8px; /* Slightly tighter gap */
}

.action-btn {
    font-size: 14px !important;
    padding: 10px 8px !important;
    min-height: 44px;
}

#points-count {
    font-size: 1.1em;
}

.stats-panel {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--panel-border);
    border-radius: 8px;
    padding: 10px;
    margin-bottom: 8px;
    font-size: 12px;
}

.stats-row {
    display: flex;
    justify-content: space-between;
    margin-bottom: 4px;
}

.stats-label {
    color: var(--text-dim);
}

.stats-value {
    font-weight: 600;
    color: var(--accent);
}

.stats-value.removed {
    color: #ff7676; /* Red for removed items */
}

#cut-toggles {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    width: 100%;
}

.toggle-button:hover {
    background: rgba(255, 255, 255, 0.15);
}

#cut-toggles.options-expanded > div:first-child {
    display: none !important;
}

/* Checkbox Toggle Switch */
/* Options Accordion */
.options-header {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--panel-border);
    border-radius: 8px 8px 0 0;
    padding: 8px 12px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: pointer;
    font-size: 11px;
    font-weight: 600;
    color: var(--text-dim);
    transition: background 0.2s ease, color 0.2s ease;
    margin-top: 10px;
    pointer-events: auto;
}

.options-header:hover {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-main);
}

.options-header.expanded {
    position: relative;
    height: 0;
    margin: 0;
    padding: 0;
    border-top: 1px solid var(--panel-border);
    border-left: 1px solid var(--panel-border);
    border-right: 1px solid var(--panel-border);
    border-radius: 8px 8px 0 0;
    z-index: 100;
}

.options-header.expanded #options-toggle-icon {
    position: absolute;
    right: 8px;
    top: 10px; /* Moved up slightly */
    background: rgba(255, 255, 255, 0.05);
    border-radius: 4px;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.options-header.expanded span:first-child {
    display: none;
}

.options-content {
    display: flex;
    flex-direction: column;
    gap: 4px;
    width: 100%;
    padding: 8px;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--panel-border);
    border-top: none;
    border-radius: 0 0 8px 8px;
    overflow: hidden;
    transition: max-height 0.3s ease, padding 0.3s ease, opacity 0.3s ease, border-color 0.3s ease;
    max-height: 400px;
}

.options-content.collapsed {
    max-height: 0;
    padding-top: 0;
    padding-bottom: 0;
    opacity: 0;
    border-color: rgba(255, 255, 255, 0);
}

#options-toggle-icon {
    font-size: 14px;
    font-family: monospace;
    width: 20px;
    text-align: center;
}

.checkbox-group {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 0.75rem;
    padding: 2px 0;
}

.checkbox-group label:not(.switch) {
    font-size: 12px;
    color: var(--text-color);
    cursor: pointer;
    user-select: none;
}

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

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

.slider {
    position: absolute;
    cursor: pointer;
    top: 0; left: 0; right: 0; bottom: 0;
    background-color: rgba(255, 255, 255, 0.1);
    transition: .3s;
    border-radius: 18px;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.slider:before {
    position: absolute;
    content: "";
    height: 12px; width: 12px;
    left: 2px; bottom: 2px;
    background-color: #94a3b8;
    transition: .3s;
    border-radius: 50%;
}

input:checked + .slider { background-color: var(--accent); border-color: var(--accent); }
input:checked + .slider:before { transform: translateX(16px); background-color: #fff; }

.side-button {
    position: fixed;
    right: 24px;
    z-index: 1000;
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 50%;
    color: white;
    text-decoration: none;
    transition: all 0.3s ease;
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    cursor: pointer;
    box-sizing: border-box;
    padding: 0;
}

.home-button {
    top: 24px;
}

.zoom-button {
    top: 128px; /* 76 + 44 + 8 */
}

.trash-button, .clear-button {
    top: 76px; /* 24 + 44 + 8 */
}

/* New slot for Presets */
#btn-toggle-presets { top: 200px; }

/* Mode Buttons shifted down */
#btn-mode-build { top: 272px; }
#btn-mode-delete { top: 324px; }
#btn-mode-cut { top: 376px; }

.side-button:hover {
    background: var(--accent);
    border-color: var(--accent);
    transform: scale(1.1);
    box-shadow: 0 0 15px rgba(79, 172, 254, 0.4);
}

.side-button.active {
    background: var(--accent);
    border-color: var(--accent);
    box-shadow: 0 0 20px rgba(79, 172, 254, 0.6);
}

.side-button svg {
    width: 20px;
    height: 20px;
    stroke: currentColor;
}

.overlay-guide {
    position: fixed;
    top: 65px; /* Slightly closer to the title */
    left: 50%;
    transform: translateX(-50%);
    color: var(--text-dim);
    font-size: 13px;
    font-weight: 500;
    z-index: 500;
    pointer-events: none;
    transition: opacity 0.3s ease, transform 0.3s ease;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.5); /* Keep text readable against 3D scene */
}

.overlay-guide.hidden {
    opacity: 0;
    transform: translate(-50%, -10px);
    pointer-events: none;
    display: block !important;
}


/* History Controls (Undo/Redo) */
#history-dashboard {
    position: fixed;
    top: 116px; /* Positioned below .cut-instructions (top: 72px) */
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 12px;
    z-index: 2000;
    pointer-events: none;
    transition: top 0.4s cubic-bezier(0.18, 0.89, 0.32, 1.28);
}

#history-dashboard.moved-up {
    top: 72px;
}

.history-btn {
    pointer-events: auto;
    background: rgba(30, 30, 40, 0.6);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: var(--text);
    width: 36px;
    height: 36px;
    min-width: 36px; /* Ensure it stays a circle */
    min-height: 36px;
    aspect-ratio: 1 / 1;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    padding: 0;
}

.history-btn svg {
    width: 16px;
    height: 16px;
    margin: 0;
}

.history-btn:hover:not(:disabled) {
    background: rgba(50, 50, 70, 0.8);
    transform: translateY(-2px) scale(1.05);
    border-color: rgba(255, 255, 255, 0.2);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.4);
}

.history-btn:active:not(:disabled) {
    transform: translateY(0) scale(0.95);
}

.history-btn:disabled {
    opacity: 0.15;
    cursor: not-allowed;
    filter: grayscale(1);
    box-shadow: none;
}

@media (max-width: 600px) {
    /* Main Panel */
    .panel {
        max-width: 330px !important;
    }

    /* Titles & HUD */
    .main-title {
        font-size: 20px;
        top: 16px;
    }
    .hud-stats {
        top: 8px;
        left: 8px;
        padding: 6px 10px;
        min-width: auto;
    }
    .hud-label {
        font-size: 9px;
    }
    .hud-value {
        font-size: 13px;
    }
    .hud-row {
        gap: 3px;
        margin-bottom: 1px;
    }

    /* Instructions & Buttons */
    .cut-instructions {
        font-size: 11px;
        padding: 6px 12px;
        top: 56px;
    }
    .action-btn {
        min-height: 32px !important;
        padding: 4px 8px !important;
        font-size: 11px !important;
    }
    .pc-only {
        display: none;
    }
    .checkbox-group label:not(.switch) {
        font-size: 10px !important;
    }

    /* Floating UI */
    .side-button {
        width: 38px;
        height: 38px;
        min-width: 38px;
        min-height: 38px;
        aspect-ratio: 1 / 1;
        flex-shrink: 0;
        right: 16px;
    }
    .side-button svg {
        width: 18px;
        height: 18px;
    }

    /* History Dashboard */
    #history-dashboard {
        top: 100px;
        gap: 10px;
    }
    .history-btn {
        width: 32px;
        height: 32px;
    }
}
