/* ===== CSS Variables & Reset - Gruvbox Theme ===== */
:root {
    /* Gruvbox Dark Colors */
    --bg-primary: #1d2021;
    --bg-secondary: #282828;
    --bg-tertiary: #3c3836;
    --bg-card: rgba(60, 56, 54, 0.95);
    --bg-glass: rgba(40, 40, 40, 0.85);

    --text-primary: #ebdbb2;
    --text-secondary: #d5c4a1;
    --text-muted: #928374;

    /* Gruvbox Orange as primary accent */
    --accent-primary: #fe8019;
    --accent-secondary: #d65d0e;
    --accent-glow: rgba(254, 128, 25, 0.3);

    /* Gruvbox additional colors */
    --gruvbox-red: #fb4934;
    --gruvbox-green: #b8bb26;
    --gruvbox-yellow: #fabd2f;
    --gruvbox-blue: #83a598;
    --gruvbox-purple: #d3869b;
    --gruvbox-aqua: #8ec07c;

    --border-color: rgba(168, 153, 132, 0.2);
    --border-light: rgba(168, 153, 132, 0.3);

    --gradient-primary: linear-gradient(135deg, #fe8019 0%, #d65d0e 100%);
    --gradient-glass: linear-gradient(135deg, rgba(235, 219, 178, 0.03) 0%, rgba(235, 219, 178, 0.01) 100%);

    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.4);
    --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.5);
    --shadow-lg: 0 16px 48px rgba(0, 0, 0, 0.6);
    --shadow-glow: 0 0 40px var(--accent-glow);

    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 20px;
    --radius-xl: 28px;

    --font-main: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    --font-mono: 'JetBrains Mono', 'Fira Code', monospace;

    --transition-fast: 0.15s ease;
    --transition-normal: 0.25s ease;
    --transition-slow: 0.4s ease;
}

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

html {
    font-size: 16px;
    scroll-behavior: smooth;
}

body {
    font-family: var(--font-main);
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
    overflow-x: hidden;
}

/* ===== Background Animation ===== */
.background-animation {
    position: fixed;
    inset: 0;
    z-index: -1;
    overflow: hidden;
}

.pixel-grid {
    position: absolute;
    inset: 0;
    background-image:
        radial-gradient(circle at 20% 30%, var(--accent-glow) 0%, transparent 40%),
        radial-gradient(circle at 80% 70%, rgba(214, 93, 14, 0.15) 0%, transparent 40%);
    animation: pulseBackground 8s ease-in-out infinite;
}

.pixel-grid::before {
    content: '';
    position: absolute;
    inset: 0;
    background-image:
        linear-gradient(rgba(255, 255, 255, 0.02) 1px, transparent 1px),
        linear-gradient(90deg, rgba(255, 255, 255, 0.02) 1px, transparent 1px);
    background-size: 40px 40px;
}

@keyframes pulseBackground {

    0%,
    100% {
        opacity: 1;
    }

    50% {
        opacity: 0.6;
    }
}

/* ===== Layout ===== */
.app-container {
    max-width: 1600px;
    margin: 0 auto;
    padding: 1rem 1.5rem;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* ===== Header ===== */
.header {
    text-align: center;
    padding: 1rem 0 1.5rem;
}

.logo {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    margin-bottom: 0.5rem;
}

.watch-icon {
    position: relative;
    width: 36px;
    height: 48px;
}

.watch-face {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 28px;
    height: 28px;
    background: var(--bg-tertiary);
    border: 2px solid var(--accent-primary);
    border-radius: 6px;
    box-shadow: var(--shadow-glow);
}

.watch-face::before {
    content: '';
    position: absolute;
    inset: 4px;
    background: var(--gradient-primary);
    border-radius: 2px;
    opacity: 0.3;
}

.watch-band {
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    width: 18px;
    height: 10px;
    background: var(--accent-secondary);
    border-radius: 3px;
}

.watch-band.top {
    top: 0;
}

.watch-band.bottom {
    bottom: 0;
}

.logo h1 {
    font-size: 1.75rem;
    font-weight: 700;
    background: var(--gradient-primary);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    letter-spacing: -0.02em;
}

.tagline {
    color: var(--text-secondary);
    font-size: 1rem;
    font-weight: 400;
}

/* ===== Main Content ===== */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 2rem;
}

/* ===== Designer Layout ===== */
.designer-layout {
    display: grid;
    grid-template-columns: 280px 1fr 300px;
    gap: 1.5rem;
    min-height: 600px;
}

/* ===== Panel Styles ===== */
.widget-panel,
.properties-panel {
    background: var(--bg-card);
    backdrop-filter: blur(20px);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 1.25rem;
    overflow-y: auto;
    max-height: calc(100vh - 200px);
}

.widget-panel h3,
.properties-panel h3,
.export-section h3 {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--accent-primary);
    margin-bottom: 1rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.widget-panel h3 svg,
.properties-panel h3 svg,
.export-section h3 svg {
    width: 18px;
    height: 18px;
}

/* ===== Widget Categories ===== */
.widget-category {
    margin-bottom: 1.25rem;
}

.widget-category h4 {
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 0.75rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid var(--border-color);
}

.widget-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 0.5rem;
}

.widget-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.35rem;
    padding: 0.75rem 0.5rem;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    cursor: grab;
    transition: all var(--transition-fast);
}

.widget-item:hover {
    border-color: var(--accent-primary);
    background: var(--bg-tertiary);
    transform: translateY(-2px);
    box-shadow: var(--shadow-sm);
}

.widget-item:active {
    cursor: grabbing;
    transform: scale(0.95);
}

.widget-preview {
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-primary);
}

.widget-preview svg {
    width: 32px;
    height: 32px;
}

.widget-item span:last-child {
    font-size: 0.7rem;
    color: var(--text-muted);
    text-align: center;
}

.time-preview {
    font-family: var(--font-mono);
    font-size: 1rem;
    font-weight: 600;
}

.date-preview,
.day-preview,
.temp-preview,
.condition-preview,
.hilo-preview,
.steps-preview {
    font-family: var(--font-mono);
    font-size: 0.7rem;
    font-weight: 500;
}

.text-preview {
    font-size: 1.25rem;
    font-weight: 600;
}

/* Shape previews */
.shape-rect {
    width: 28px;
    height: 20px;
    border: 2px solid var(--text-primary);
    border-radius: 2px;
}

.shape-circle {
    width: 24px;
    height: 24px;
    border: 2px solid var(--text-primary);
    border-radius: 50%;
}

.shape-line {
    width: 28px;
    height: 2px;
    background: var(--text-primary);
    transform: rotate(-30deg);
}

/* Upload Widget Zone */
.upload-widget-zone {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
    padding: 1rem;
    background: var(--bg-secondary);
    border: 2px dashed var(--border-light);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.upload-widget-zone:hover {
    border-color: var(--accent-primary);
    background: var(--bg-tertiary);
}

.upload-widget-zone svg {
    width: 28px;
    height: 28px;
    color: var(--accent-primary);
}

.upload-widget-zone span {
    font-size: 0.75rem;
    color: var(--text-secondary);
}

/* ===== Canvas Area ===== */
.canvas-area {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.canvas-toolbar {
    display: flex;
    justify-content: center;
    gap: 1rem;
    padding: 0.75rem 1rem;
    background: var(--bg-card);
    backdrop-filter: blur(20px);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
}

.toolbar-group {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0 0.5rem;
    border-right: 1px solid var(--border-color);
}

.toolbar-group:last-child {
    border-right: none;
}

.toolbar-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.toolbar-btn:hover {
    border-color: var(--accent-primary);
    color: var(--accent-primary);
    background: var(--bg-tertiary);
}

.toolbar-btn.active {
    background: var(--accent-primary);
    border-color: var(--accent-primary);
    color: var(--bg-primary);
    box-shadow: var(--shadow-glow);
}

.toolbar-btn.danger:hover {
    border-color: var(--gruvbox-red);
    color: var(--gruvbox-red);
}

.toolbar-btn svg {
    width: 18px;
    height: 18px;
}

.zoom-level {
    font-family: var(--font-mono);
    font-size: 0.8rem;
    color: var(--text-muted);
    min-width: 50px;
    text-align: center;
}

/* Canvas Wrapper */
.canvas-wrapper {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-card);
    backdrop-filter: blur(20px);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 2rem;
    min-height: 400px;
}

.watchy-display {
    position: relative;
    background: #32302f;
    border: 3px solid var(--border-light);
    border-radius: var(--radius-md);
    padding: 16px;
    box-shadow:
        inset 0 2px 4px rgba(235, 219, 178, 0.05),
        0 8px 32px rgba(0, 0, 0, 0.5),
        var(--shadow-glow);
    transition: transform 0.2s ease;
}

.watchy-display::before {
    content: '';
    position: absolute;
    top: -12px;
    left: 50%;
    transform: translateX(-50%);
    width: 30px;
    height: 8px;
    background: var(--accent-secondary);
    border-radius: 4px;
}

.watchy-display::after {
    content: '';
    position: absolute;
    bottom: -12px;
    left: 50%;
    transform: translateX(-50%);
    width: 30px;
    height: 8px;
    background: var(--accent-secondary);
    border-radius: 4px;
}

.canvas-container {
    position: relative;
    width: 200px;
    height: 200px;
    isolation: isolate;
    /* Create stacking context for proper z-index */
}

#designCanvas {
    display: block;
    width: 200px;
    height: 200px;
    background: #ebdbb2;
    image-rendering: pixelated;
    position: relative;
    z-index: 1;
}

#overlayCanvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 200px;
    height: 200px;
    background: transparent;
    pointer-events: none;
    image-rendering: pixelated;
    z-index: 20;
    /* Above everything including images */
}

.canvas-elements {
    position: absolute;
    top: 0;
    left: 0;
    width: 200px;
    height: 200px;
    /* Remove z-index to allow children (widgets) to use their own z-index relative to overlayCanvas */
    /* pointer-events: none; is kept so we can click through to the canvas when needed */
    pointer-events: none;
}

#brushCircle {
    position: absolute;
    width: 20px;
    height: 20px;
    border: 1px solid var(--accent-primary);
    border-radius: 50%;
    pointer-events: none;
    display: none;
    z-index: 100;
    transform: translate(-50%, -50%);
    box-shadow: 0 0 5px rgba(254, 128, 25, 0.5);
}

.drawing-mode #brushCircle {
    display: block;
}

.canvas-element {
    position: absolute;
    pointer-events: all;
    cursor: move;
    user-select: none;
    z-index: 30;
    /* Widgets appear above overlay (z-20) */
}

/* Images stay below overlay so eraser can cover them */
.canvas-element.element-image {
    z-index: 5;
    /* Below overlay (z-20) so eraser covers images */
}

.canvas-elements.drawing-mode .canvas-element {
    pointer-events: none;
    /* Disable element interaction when drawing/erasing */
}

.canvas-element.selected {
    outline: 2px dashed var(--accent-primary);
    outline-offset: 2px;
}

.canvas-element .resize-handle {
    position: absolute;
    width: 10px;
    height: 10px;
    background: var(--accent-primary);
    border: 2px solid #fff;
    border-radius: 50%;
    display: none;
}

.canvas-element.selected .resize-handle {
    display: block;
}

.resize-handle.nw {
    top: -5px;
    left: -5px;
    cursor: nw-resize;
}

.resize-handle.ne {
    top: -5px;
    right: -5px;
    cursor: ne-resize;
}

.resize-handle.sw {
    bottom: -5px;
    left: -5px;
    cursor: sw-resize;
}

.resize-handle.se {
    bottom: -5px;
    right: -5px;
    cursor: se-resize;
}

.grid-overlay {
    position: absolute;
    top: 16px;
    left: 16px;
    width: 200px;
    height: 200px;
    pointer-events: none;
    opacity: 0;
    transition: opacity var(--transition-fast);
    background-image:
        linear-gradient(rgba(0, 0, 0, 0.1) 1px, transparent 1px),
        linear-gradient(90deg, rgba(0, 0, 0, 0.1) 1px, transparent 1px);
    background-size: 20px 20px;
}

.grid-overlay.visible {
    opacity: 1;
}

.canvas-info {
    display: flex;
    justify-content: center;
    gap: 1.5rem;
}

.dimension-info,
.color-info {
    font-size: 0.8rem;
    font-family: var(--font-mono);
    color: var(--text-muted);
    padding: 0.35rem 0.75rem;
    background: var(--bg-tertiary);
    border-radius: var(--radius-sm);
}

/* ===== Properties Panel ===== */
.panel-section {
    margin-bottom: 1.5rem;
}

.panel-section:last-child {
    margin-bottom: 0;
}

.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
    padding: 2rem 1rem;
    text-align: center;
    color: var(--text-muted);
}

.empty-state svg {
    width: 48px;
    height: 48px;
    opacity: 0.5;
}

.empty-state p {
    font-size: 0.85rem;
}

.hidden {
    display: none !important;
}

.property-group {
    margin-bottom: 1rem;
}

.property-group label {
    display: block;
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.03em;
    margin-bottom: 0.5rem;
}

.property-row {
    display: flex;
    gap: 0.75rem;
}

.property-input {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    padding: 0.5rem 0.75rem;
}

.property-input span {
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--text-muted);
}

.property-input input {
    flex: 1;
    background: transparent;
    border: none;
    color: var(--text-primary);
    font-family: var(--font-mono);
    font-size: 0.85rem;
    width: 100%;
    min-width: 0;
}

.property-input input:focus {
    outline: none;
}

.property-group input[type="text"] {
    width: 100%;
    padding: 0.6rem 0.75rem;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-family: var(--font-mono);
    font-size: 0.85rem;
}

.property-group input[type="text"]:focus {
    outline: none;
    border-color: var(--accent-primary);
}

.property-select {
    width: 100%;
    padding: 0.6rem 0.75rem;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-family: var(--font-main);
    font-size: 0.85rem;
    margin-bottom: 0.75rem;
    cursor: pointer;
    transition: all var(--transition-fast);
}

.property-select:focus {
    outline: none;
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 2px var(--accent-glow);
}

.property-select option {
    background: var(--bg-secondary);
    color: var(--text-primary);
}

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.8rem !important;
    color: var(--text-secondary) !important;
    text-transform: none !important;
    letter-spacing: normal !important;
    margin-top: 0.5rem;
    cursor: pointer;
}

.checkbox-label input[type="checkbox"] {
    width: 16px;
    height: 16px;
    accent-color: var(--accent-primary);
}

/* Color Options */
.color-options {
    display: flex;
    gap: 0.5rem;
}

.color-btn {
    width: 36px;
    height: 36px;
    padding: 4px;
    background: var(--bg-secondary);
    border: 2px solid var(--border-color);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.color-btn:hover {
    border-color: var(--text-muted);
}

.color-btn.active {
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 2px var(--accent-glow);
}

.color-btn span {
    display: block;
    width: 100%;
    height: 100%;
    border-radius: 2px;
}

/* Range Container */
.range-container {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.range-container input[type="range"] {
    flex: 1;
    -webkit-appearance: none;
    appearance: none;
    height: 6px;
    background: var(--bg-secondary);
    border-radius: 3px;
    cursor: pointer;
}

.range-container input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 16px;
    height: 16px;
    background: var(--accent-primary);
    border-radius: 50%;
    cursor: pointer;
    transition: transform var(--transition-fast);
}

.range-container input[type="range"]::-webkit-slider-thumb:hover {
    transform: scale(1.15);
}

.range-container span {
    font-family: var(--font-mono);
    font-size: 0.75rem;
    color: var(--accent-primary);
    min-width: 40px;
    text-align: right;
}

/* Typeable number input for ranges */
.range-number-input {
    width: 50px;
    padding: 0.3rem 0.4rem;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-family: var(--font-mono);
    font-size: 0.8rem;
    text-align: center;
    -moz-appearance: textfield;
    appearance: textfield;
}

.range-number-input::-webkit-outer-spin-button,
.range-number-input::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

.range-number-input:focus {
    outline: none;
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 2px var(--accent-glow);
}

.range-unit {
    font-family: var(--font-mono);
    font-size: 0.75rem;
    color: var(--text-muted);
    min-width: auto;
}

/* Property Actions */
.property-actions {
    display: flex;
    gap: 0.5rem;
    margin-top: 1rem;
    padding-top: 1rem;
    border-top: 1px solid var(--border-color);
}

.btn-sm {
    flex: 1;
    padding: 0.5rem 0.75rem;
    font-size: 0.8rem;
}

.btn-sm svg {
    width: 14px;
    height: 14px;
}

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

.btn-danger:hover {
    background: var(--gruvbox-red);
    color: var(--bg-primary);
}

/* Layers */
.layers-list {
    max-height: 200px;
    overflow-y: auto;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
}

.empty-layers {
    padding: 1rem;
    text-align: center;
    font-size: 0.8rem;
    color: var(--text-muted);
}

.layer-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0.75rem;
    border-bottom: 1px solid var(--border-color);
    cursor: pointer;
    transition: background var(--transition-fast);
}

.layer-item:last-child {
    border-bottom: none;
}

.layer-item:hover {
    background: var(--bg-tertiary);
}

.layer-item.active {
    background: rgba(254, 128, 25, 0.15);
}

.layer-icon {
    width: 20px;
    height: 20px;
    color: var(--text-muted);
}

.layer-name {
    flex: 1;
    font-size: 0.8rem;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.layer-visibility {
    width: 20px;
    height: 20px;
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

.layer-visibility:hover {
    color: var(--accent-primary);
}

.layer-visibility svg {
    width: 16px;
    height: 16px;
}

.layer-actions {
    display: flex;
    justify-content: center;
    gap: 0.5rem;
    margin-top: 0.75rem;
}

.layer-btn {
    width: 32px;
    height: 32px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition-fast);
}

.layer-btn:hover {
    border-color: var(--accent-primary);
    color: var(--accent-primary);
}

.layer-btn svg {
    width: 16px;
    height: 16px;
}

/* ===== Export Section ===== */
.export-section {
    background: var(--bg-card);
    backdrop-filter: blur(20px);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
}

.export-options {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 2rem;
    margin-bottom: 1.5rem;
}

.export-preview {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.75rem;
}

.watchy-export-frame {
    background: #32302f;
    border: 2px solid var(--border-light);
    border-radius: var(--radius-sm);
    padding: 12px;
    box-shadow: var(--shadow-md);
}

.watchy-export-frame canvas {
    display: block;
    background: #ebdbb2;
    image-rendering: pixelated;
}

.export-info {
    font-size: 0.75rem;
    color: var(--text-muted);
    font-family: var(--font-mono);
}

.export-settings {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1rem;
    align-content: start;
}

.setting-item {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.setting-item label,
.setting-item .setting-label {
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--text-secondary);
}

.setting-item input[type="text"],
.setting-item select {
    padding: 0.65rem 0.85rem;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-family: var(--font-mono);
    font-size: 0.85rem;
}

.setting-item input[type="text"]:focus,
.setting-item select:focus {
    outline: none;
    border-color: var(--accent-primary);
}

.toggle-row {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
}

/* Toggle Switch */
.toggle-switch {
    position: relative;
    width: 48px;
    height: 26px;
}

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

.toggle-switch .slider {
    position: absolute;
    inset: 0;
    background: var(--bg-secondary);
    border-radius: 13px;
    cursor: pointer;
    transition: background var(--transition-fast);
}

.toggle-switch .slider::before {
    content: '';
    position: absolute;
    left: 4px;
    top: 4px;
    width: 18px;
    height: 18px;
    background: var(--text-secondary);
    border-radius: 50%;
    transition: all var(--transition-fast);
}

.toggle-switch input:checked+.slider {
    background: var(--accent-primary);
}

.toggle-switch input:checked+.slider::before {
    left: 26px;
    background: white;
}

/* Export Actions */
.export-actions {
    display: flex;
    gap: 1rem;
    justify-content: center;
    flex-wrap: wrap;
}

/* Buttons */
.btn {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem 1.25rem;
    border-radius: var(--radius-md);
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition-fast);
    border: none;
}

.btn svg {
    width: 18px;
    height: 18px;
}

.btn-primary {
    background: var(--gradient-primary);
    color: var(--bg-primary);
    box-shadow: var(--shadow-sm);
}

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

.btn-secondary {
    background: var(--bg-tertiary);
    color: var(--text-primary);
    border: 1px solid var(--border-light);
}

.btn-secondary:hover {
    background: var(--bg-secondary);
    border-color: var(--accent-primary);
}

.btn-aqua {
    background: var(--gruvbox-aqua);
    color: var(--bg-primary);
}

.btn-aqua:hover {
    transform: translateY(-2px);
    box-shadow: 0 0 20px rgba(142, 192, 124, 0.4);
}

/* ===== Modal ===== */
.modal {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.8);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 1rem;
}

.modal.visible {
    display: flex;
}

.modal-content {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    width: 100%;
    max-width: 800px;
    max-height: 90vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

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

.modal-header h3 {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text-primary);
}

.modal-close {
    width: 36px;
    height: 36px;
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-sm);
    transition: all var(--transition-fast);
}

.modal-close:hover {
    background: var(--bg-tertiary);
    color: var(--gruvbox-red);
}

.modal-close svg {
    width: 20px;
    height: 20px;
}

.modal-body {
    flex: 1;
    overflow-y: auto;
}

.code-tabs {
    display: flex;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
}

.code-tab {
    flex: 1;
    padding: 0.85rem 1.25rem;
    background: transparent;
    border: none;
    color: var(--text-secondary);
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    position: relative;
    transition: all var(--transition-fast);
}

.code-tab:hover {
    color: var(--text-primary);
    background: rgba(255, 255, 255, 0.03);
}

.code-tab.active {
    color: var(--accent-primary);
}

.code-tab.active::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 2px;
    background: var(--accent-primary);
}

.code-panel {
    display: none;
}

.code-panel.active {
    display: block;
}

.code-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.65rem 1rem;
    background: var(--bg-tertiary);
    border-bottom: 1px solid var(--border-color);
}

.code-language {
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--text-muted);
    font-family: var(--font-mono);
}

.copy-btn {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.4rem 0.75rem;
    background: transparent;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    font-size: 0.8rem;
    cursor: pointer;
    transition: all var(--transition-fast);
}

.copy-btn:hover {
    background: var(--bg-secondary);
    border-color: var(--accent-primary);
    color: var(--accent-primary);
}

.copy-btn.copied {
    background: var(--accent-primary);
    border-color: var(--accent-primary);
    color: var(--bg-primary);
}

.copy-btn svg {
    width: 14px;
    height: 14px;
}

.code-block {
    margin: 0;
    padding: 1.25rem;
    background: var(--bg-secondary);
    font-family: var(--font-mono);
    font-size: 0.75rem;
    line-height: 1.5;
    overflow-x: auto;
    max-height: 350px;
    color: var(--text-secondary);
}

.code-block code {
    white-space: pre;
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    padding: 1rem 1.5rem;
    border-top: 1px solid var(--border-color);
}

/* ===== Footer ===== */
.footer {
    text-align: center;
    padding: 1.5rem 0 1rem;
    margin-top: auto;
}

.footer p {
    font-size: 0.85rem;
    color: var(--text-muted);
}

.footer a {
    color: var(--accent-primary);
    text-decoration: none;
    transition: color var(--transition-fast);
}

.footer a:hover {
    color: var(--accent-secondary);
}

/* ===== Animations ===== */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ===== Scrollbar ===== */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: var(--bg-secondary);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb {
    background: var(--bg-tertiary);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--border-light);
}

/* ===== Responsive ===== */
@media (max-width: 1200px) {
    .designer-layout {
        grid-template-columns: 240px 1fr 260px;
    }
}

@media (max-width: 1024px) {
    .designer-layout {
        grid-template-columns: 1fr;
        gap: 1rem;
    }

    .widget-panel,
    .properties-panel {
        max-height: none;
    }

    .widget-panel {
        order: 2;
    }

    .canvas-area {
        order: 1;
    }

    .properties-panel {
        order: 3;
    }

    .widget-grid {
        grid-template-columns: repeat(4, 1fr);
    }

    .export-options {
        grid-template-columns: 1fr;
        justify-items: center;
    }

    .export-settings {
        max-width: 400px;
    }
}

@media (max-width: 640px) {
    .app-container {
        padding: 1rem;
    }

    .logo h1 {
        font-size: 1.35rem;
    }

    .widget-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .canvas-toolbar {
        flex-wrap: wrap;
    }

    .export-settings {
        grid-template-columns: 1fr;
    }

    .export-actions {
        flex-direction: column;
    }

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

    .code-preview-layout {
        grid-template-columns: 1fr !important;
    }

    .code-preview-result {
        height: 250px !important;
    }
}

/* ===== Code Preview Section ===== */
.code-preview-section {
    background: var(--bg-card);
    backdrop-filter: blur(20px);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    margin-top: 1rem;
}

.code-preview-section h3 {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--gruvbox-blue);
    margin-bottom: 1rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.code-preview-section h3 svg {
    width: 18px;
    height: 18px;
}

.collapse-btn {
    margin-left: auto;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all var(--transition-fast);
    color: var(--text-secondary);
}

.collapse-btn:hover {
    border-color: var(--gruvbox-blue);
    color: var(--gruvbox-blue);
}

.collapse-btn svg {
    width: 14px;
    height: 14px;
    transition: transform var(--transition-fast);
}

.collapse-btn.collapsed svg {
    transform: rotate(-90deg);
}

.code-preview-content {
    display: grid;
    gap: 1.5rem;
    transition: all var(--transition-normal);
    overflow: hidden;
    max-height: 800px;
}

.code-preview-content.collapsed {
    max-height: 0;
    padding: 0;
    margin: 0;
    opacity: 0;
}

.code-preview-layout {
    display: grid;
    grid-template-columns: 1fr 320px;
    gap: 1.5rem;
}

.code-input-area {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.code-input-area label {
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--text-secondary);
}

.code-input-area textarea {
    width: 100%;
    min-height: 180px;
    max-height: 300px;
    resize: vertical;
    padding: 1rem;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-family: var(--font-mono);
    font-size: 0.85rem;
    line-height: 1.5;
    transition: border-color var(--transition-fast);
}

.code-input-area textarea::placeholder {
    color: var(--text-muted);
    opacity: 0.7;
}

.code-input-area textarea:focus {
    outline: none;
    border-color: var(--gruvbox-blue);
    box-shadow: 0 0 0 2px rgba(131, 165, 152, 0.2);
}

.code-input-info {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.code-input-info span {
    font-size: 0.75rem;
    font-family: var(--font-mono);
    color: var(--text-muted);
    padding: 0.25rem 0.5rem;
    background: var(--bg-tertiary);
    border-radius: var(--radius-sm);
}

.code-input-info span.detected {
    color: var(--gruvbox-green);
    background: rgba(184, 187, 38, 0.1);
}

.code-input-info span.error {
    color: var(--gruvbox-red);
    background: rgba(251, 73, 52, 0.1);
}

.code-preview-settings {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.preview-dimension-inputs {
    display: flex;
    gap: 0.75rem;
}

.dimension-input-group {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
}

.dimension-input-group label {
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.dimension-input-group input {
    padding: 0.6rem 0.75rem;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-family: var(--font-mono);
    font-size: 0.9rem;
    text-align: center;
}

.dimension-input-group input:focus {
    outline: none;
    border-color: var(--gruvbox-blue);
}

.preview-options {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.preview-options .checkbox-label {
    font-size: 0.85rem !important;
    color: var(--text-secondary) !important;
    text-transform: none !important;
}

.preview-actions {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    margin-top: auto;
}

.preview-actions .btn {
    justify-content: center;
}

.code-preview-result {
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    min-height: 220px;
    padding: 1rem;
    position: relative;
    overflow: hidden;
}

.preview-placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.75rem;
    color: var(--text-muted);
    padding: 2rem;
}

.preview-placeholder svg {
    width: 48px;
    height: 48px;
    opacity: 0.4;
}

.preview-placeholder p {
    font-size: 0.85rem;
}

#codePreviewCanvas {
    background: #ebdbb2;
    image-rendering: pixelated;
    border: 2px solid var(--border-light);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-md);
    max-width: 100%;
    max-height: 200px;
}

/* Preview success animation */
@keyframes previewSuccess {
    0% {
        box-shadow: 0 0 0 0 rgba(184, 187, 38, 0.4);
    }

    70% {
        box-shadow: 0 0 0 10px rgba(184, 187, 38, 0);
    }

    100% {
        box-shadow: 0 0 0 0 rgba(184, 187, 38, 0);
    }
}

.code-preview-result.success #codePreviewCanvas {
    animation: previewSuccess 0.6s ease-out;
    border-color: var(--gruvbox-green);
}

/* Error state */
.code-preview-result.error {
    border-color: var(--gruvbox-red);
}

.code-preview-result .error-message {
    color: var(--gruvbox-red);
    font-size: 0.85rem;
    text-align: center;
    padding: 1rem;
}

.code-preview-result .error-message svg {
    width: 32px;
    height: 32px;
    margin-bottom: 0.5rem;
    opacity: 0.7;
}