:root {
    --bg-dark: #0f1115;
    --bg-panel: #161920;
    --bg-hover: #1f232d;
    --bg-input: #0a0c10;
    --border: #2a2e38;
    --primary: #5eff8b;
    --primary-dim: #5eff8b33;
    --accent: #5eacff;
    --text-main: #e6e6e6;
    --text-muted: #8b92a1;
    --danger: #ff5e5e;

    --font-heading: 'Outfit', sans-serif;
    --font-mono: 'JetBrains Mono', monospace;

    --shadow-sm: 0 2px 4px rgba(0, 0, 0, 0.2);
    --shadow-lg: 0 8px 16px rgba(0, 0, 0, 0.4);
}

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

body {
    background-color: var(--bg-dark);
    color: var(--text-main);
    font-family: var(--font-heading);
    height: 100vh;
    overflow: hidden;
    user-select: none;
}

.app-container {
    display: flex;
    flex-direction: column;
    height: 100%;
}

/* Header */
.top-bar {
    height: 60px;
    background: var(--bg-panel);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    z-index: 10;
}

.logo {
    display: flex;
    align-items: center;
    gap: 12px;
    color: var(--primary);
}

.logo h1 {
    font-size: 1.2rem;
    font-weight: 600;
    letter-spacing: -0.02em;
    color: var(--text-main);
}

/* Inputs & Buttons */
.secondary-btn,
.primary-btn,
.danger-btn {
    padding: 8px 16px;
    border-radius: 6px;
    font-size: 0.9rem;
    cursor: pointer;
    border: none;
    font-family: var(--font-heading);
    font-weight: 500;
    transition: all 0.2s;
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.secondary-btn {
    background: var(--bg-hover);
    color: var(--text-main);
    border: 1px solid var(--border);
}

.secondary-btn:hover {
    background: #2a2e38;
}

.primary-btn {
    background: var(--primary);
    color: #000;
    font-weight: 600;
}

.primary-btn:hover {
    filter: brightness(1.1);
    box-shadow: 0 0 12px var(--primary-dim);
}

.danger-btn {
    background: transparent;
    color: var(--danger);
    border: 1px solid #ff5e5e44;
}

.danger-btn:hover {
    background: #ff5e5e11;
}

.input-group {
    display: flex;
    align-items: center;
    gap: 8px;
}

.input-group label {
    font-size: 0.8rem;
    color: var(--text-muted);
}

input[type="number"],
input[type="text"] {
    background: var(--bg-input);
    border: 1px solid var(--border);
    color: var(--text-main);
    padding: 6px 10px;
    border-radius: 4px;
    font-family: var(--font-mono);
    width: 70px;
}

input[type="number"]:focus,
input[type="text"]:focus {
    outline: none;
    border-color: var(--accent);
}

.screen-settings {
    display: flex;
    gap: 16px;
    align-items: center;
}

.toggle-group {
    display: flex;
    gap: 12px;
    margin-left: 10px;
    padding-left: 15px;
    border-left: 1px solid var(--border);
}

.toggle {
    display: flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
    font-size: 0.8rem;
    color: var(--text-muted);
}

.toggle input {
    cursor: pointer;
}

.toggle-label {
    user-select: none;
}

.actions {
    display: flex;
    gap: 12px;
}

/* Workspace */
.main-workspace {
    flex: 1;
    display: flex;
    overflow: hidden;
}

/* Tools Panel */
.tools-panel {
    width: 60px;
    background: var(--bg-panel);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 20px 0;
    gap: 24px;
}

.tool-group {
    display: flex;
    flex-direction: column;
    gap: 10px;
    align-items: center;
    width: 100%;
}

.tool-group h3 {
    font-size: 0.65rem;
    text-transform: uppercase;
    color: var(--text-muted);
    font-weight: 600;
    margin-bottom: 4px;
}

.tool-btn {
    width: 40px;
    height: 40px;
    border-radius: 8px;
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 1.1rem;
    transition: all 0.2s;
}

.tool-btn:hover {
    background: var(--bg-hover);
    color: var(--text-main);
}

.tool-btn.active {
    background: var(--primary-dim);
    color: var(--primary);
}

.color-pickers-panel {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.color-picker-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
}

.color-picker-item input[type="color"] {
    width: 32px;
    height: 32px;
    border-radius: 6px;
    padding: 0;
    border: 2px solid var(--border);
    cursor: pointer;
    background: none;
}

.color-picker-item span {
    font-size: 0.6rem;
    color: var(--text-muted);
    text-transform: uppercase;
    font-weight: 600;
}

/* Canvas Area */
.canvas-area {
    flex: 1;
    background: #000;
    position: relative;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background-image:
        linear-gradient(var(--bg-dark) 2px, transparent 2px),
        linear-gradient(90deg, var(--bg-dark) 2px, transparent 2px);
    background-size: 40px 40px;
    background-color: #050507;
}

.canvas-wrapper {
    flex: 1;
    display: flex;
    justify-content: flex-start;
    align-items: flex-start;
    overflow: hidden;
    padding: 20px;
    background: #050505;
}

canvas.pipette-cursor {
    cursor: crosshair !important;
}

canvas {
    background: #000;
    image-rendering: pixelated;
    image-rendering: crisp-edges;
    cursor: crosshair;
    /* We'll use a pseudo-element or background-image for the grid at a higher res */
    box-shadow: 0 0 0 1px #333;
    outline: none;
}

/* Sharp CSS Grid Overlay Layer */
.grid-overlay {
    position: absolute;
    top: 0;
    left: 0;
    pointer-events: none;
    z-index: 5;
}

.handle-layer {
    position: absolute;
    top: 0;
    left: 0;
    pointer-events: none;
    z-index: 10;
}

.handle-icon {
    position: absolute;
    width: 24px;
    height: 24px;
    background: var(--bg-panel);
    border: 1px solid var(--primary);
    border-radius: 50%;
    color: var(--primary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.8rem;
    transform: translate(-50%, -50%);
    pointer-events: auto;
    cursor: pointer;
    box-shadow: var(--shadow-sm);
    transition: transform 0.1s;
}

.handle-icon:hover {
    transform: translate(-50%, -50%) scale(1.2);
    background: var(--bg-hover);
}

.handle-icon.handle-add {
    width: 18px;
    height: 18px;
    font-size: 0.6rem;
    background: rgba(0, 100, 0, 0.8);
    border-color: var(--success);
    color: #fff;
    opacity: 0.7;
}

.handle-icon.handle-add:hover {
    opacity: 1;
    background: var(--success);
    transform: translate(-50%, -50%) scale(1.3);
}

.handle-icon i {
    pointer-events: none;
}

.status-bar {
    height: 24px;
    background: var(--bg-panel);
    border-top: 1px solid var(--border);
    display: flex;
    align-items: center;
    padding: 0 16px;
    gap: 20px;
    font-family: var(--font-mono);
    font-size: 0.75rem;
    color: var(--text-muted);
}

.status-bar .status-active {
    color: #4ade80;
    /* Brighter green */
    font-weight: 700;
}

/* Properties Panel */
.properties-panel {
    width: 300px;
    background: var(--bg-panel);
    border-left: 1px solid var(--border);
    display: flex;
    flex-direction: column;
}

.panel-section {
    padding: 20px;
    border-bottom: 1px solid var(--border);
}

.panel-section h2 {
    font-size: 0.9rem;
    font-weight: 600;
    margin-bottom: 16px;
    color: var(--text-main);
    display: flex;
    justify-content: space-between;
}

.empty-state {
    color: var(--text-muted);
    font-style: italic;
    font-size: 0.9rem;
    text-align: center;
    padding: 40px 0;
}

.hidden {
    display: none !important;
}

.prop-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
}

.prop-group {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.prop-row label {
    font-size: 0.85rem;
    color: var(--text-muted);
}

.badge {
    background: var(--bg-hover);
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--accent);
    font-family: var(--font-mono);
}

/* Custom Color Palette UI */
.custom-color-picker {
    position: relative;
    width: 32px;
    height: 32px;
    background: var(--bg-hover);
    border: 1px solid var(--border);
    border-radius: 6px;
    cursor: pointer;
    overflow: visible;
}

.color-preview-swatch {
    width: 100%;
    height: 100%;
    border-radius: 5px;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.palette-dropdown {
    position: absolute;
    top: calc(100% + 8px);
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 12px;
    z-index: 1000;
    box-shadow: var(--shadow-lg);
    display: none;
    width: 150px;
    backdrop-filter: blur(10px);
}

.palette-dropdown.active {
    display: block;
}

.palette-dropdown.pos-left {
    right: 8px;
    /* Buffer from edge */
}

.palette-dropdown.pos-right {
    left: 0;
}

.palette-dropdown h4 {
    font-size: 0.65rem;
    text-transform: uppercase;
    color: var(--text-muted);
    margin-bottom: 8px;
    letter-spacing: 0.05em;
}

.swatch-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
    margin-bottom: 12px;
}

.swatch {
    width: 100%;
    aspect-ratio: 1;
    border-radius: 4px;
    cursor: pointer;
    border: 1px solid rgba(255, 255, 255, 0.1);
    transition: transform 0.1s;
}

.alpha-slider-row {
    margin-top: 12px;
    border-top: 1px solid var(--border);
    padding-top: 12px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.alpha-slider-row label {
    font-size: 0.65rem;
    text-transform: uppercase;
    color: var(--text-muted);
}

.alpha-slider {
    width: 100%;
    height: 4px;
    -webkit-appearance: none;
    background: var(--bg-hover);
    border-radius: 2px;
    outline: none;
}

.alpha-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: var(--primary);
    cursor: pointer;
    border: 2px solid var(--bg-panel);
}

.alpha-val {
    font-size: 0.65rem;
    color: var(--primary);
    text-align: right;
    font-family: var(--font-mono);
}



.swatch:hover {
    transform: scale(1.15);
    border-color: var(--primary);
}

.swatch-transparent {
    background: linear-gradient(135deg,
            #333 0%, #333 45%,
            #ff3333 45%, #ff3333 55%,
            #333 55%, #333 100%) !important;
    position: relative;
}

.custom-rgb-btn:hover,
.eyedropper-btn:hover {
    background: var(--primary-dim);
    color: var(--primary);
    border-color: var(--primary);
    transform: translateY(-1px);
}

.eyedropper-btn,
.custom-rgb-btn {
    width: 100%;
    padding: 8px 12px;
    font-size: 0.75rem;
    font-weight: 600;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text-muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    margin-top: 8px;
    box-sizing: border-box;
}

.custom-rgb-btn {
    margin-top: 12px;
    /* Extra space for the primary action */
}

.hidden-picker {
    position: absolute;
    width: 1px;
    height: 1px;
    opacity: 0;
    pointer-events: none;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
}

.palette-dropdown.pos-left .hidden-picker {
    left: -150px;
    /* Big shift left to keep dialog onscreen */
    transform: translateY(-50%);
}

.color-input-wrapper {
    display: flex;
    gap: 8px;
    align-items: center;
}

.color-input-wrapper input[type="text"] {
    width: 100px;
}

.color-input-wrapper input[type="color"] {
    width: 28px;
    height: 28px;
    border: 1px solid var(--border);
    padding: 0;
    background: none;
    border-radius: 4px;
    cursor: pointer;
}

.checkbox-row {
    justify-content: flex-start;
    gap: 10px;
    cursor: pointer;
}

.prop-actions {
    display: flex;
    gap: 8px;
    margin-top: 20px;
    justify-content: flex-end;
}

.code-section {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    padding-bottom: 0;
}

.code-preview-container {
    background: #000;
    border-radius: 6px;
    border: 1px solid var(--border);
    flex: 1;
    overflow: auto;
    padding: 0;
    position: relative;
    margin-bottom: 20px;
}

pre {
    font-family: var(--font-mono);
    font-size: 0.85rem;
    line-height: 1.5;
    color: #a8b1c2;
    white-space: pre-wrap;
    word-break: break-all;
}

::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: var(--bg-dark);
}

::-webkit-scrollbar-thumb {
    background: #333;
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: #444;
}

/* Shortcuts in Status Bar */
.shortcuts-info {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 0.7rem;
    color: var(--text-muted);
}

.shortcuts-info span {
    display: flex;
    align-items: center;
    gap: 4px;
}

.shortcuts-info kbd {
    background: var(--bg-hover);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 1px 5px;
    font-family: var(--font-heading);
    font-size: 0.65rem;
    color: var(--text-main);
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
    font-weight: 600;
}

.shortcuts-info .divider {
    color: var(--border);
    font-size: 0.8rem;
    margin: 0 2px;
}

/* Poly tool dynamic hint */
.shortcuts-info .poly-hint {
    color: #d88f9f;
    /* Soft red (red with blue) */
}

.shortcuts-info .poly-hint kbd {
    background: #4a2833;
    border-color: #6a3844;
}

.shortcuts-info .poly-hint.hidden {
    display: none;
}

/* Code Output Zebra Striping */
#code-output {
    padding: 0;
    margin: 0;
}

.code-line {
    display: block;
    min-width: 100%;
    width: max-content;
    padding: 3px 10px;
    margin: 0;
    font-family: var(--font-code);
    font-size: 0.75rem;
    white-space: pre;
    box-sizing: border-box;
}

.code-line.even {
    background: #1a1d24;
}

.code-line.odd {
    background: #22262e;
}

.code-line.selected {
    background: #2a3545;
    color: var(--primary);
    font-weight: 600;
}

.division-overlay {
    position: absolute;
    top: 0;
    left: 0;
    pointer-events: none;
    z-index: 5;
}

.guide-line {
    position: absolute;
    background: cyan;
    opacity: 0.6;
}

.guide-line.center {
    background: #5eff8b;
    /* Xenon Green */
    opacity: 0.8;
    z-index: 6;
}

.guide-v {
    width: 1px;
    height: 100%;
    top: 0;
}

.guide-h {
    height: 1px;
    width: 100%;
    left: 0;
}

/* Alignment Drag Guides (Pink Crosshair) */
.drag-guides {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 100;
}

.drag-guides.hidden {
    display: none;
}

.drag-guide-v,
.drag-guide-h {
    position: absolute;
    background: #ff5eff;
    /* Vibrant Pink */
    box-shadow: 0 0 2px rgba(255, 94, 255, 0.5);
}

.drag-guide-v {
    width: 1px;
    height: 100%;
    top: 0;
}

.drag-guide-h {
    height: 1px;
    width: 100%;
    left: 0;
}