:root {
    /* Color System - MacOS Inspired */
    --bg-app: #F5F5F7;
    --bg-panel: #FFFFFF;
    --bg-input: #F2F2F7;

    --primary: #007AFF;
    --primary-hover: #0060C9;

    --text-primary: #1C1C1E;
    --text-secondary: #8E8E93;
    --text-tertiary: #C7C7CC;

    --border: #E5E5EA;
    --border-hover: #C7C7CC;

    --success: #34C759;
    --danger: #FF3B30;

    /* Spacing */
    --space-xs: 4px;
    --space-sm: 8px;
    --space-md: 12px;
    --space-lg: 16px;
    --space-xl: 24px;

    /* Layout */
    --sidebar-width: 320px;
    --layer-panel-width: 240px;
    --header-height: 50px;

    /* UI Elements */
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 14px;
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.08);
}

/* Base Reset */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-font-smoothing: antialiased;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background-color: var(--bg-app);
    color: var(--text-primary);
    font-size: 13px;
    line-height: 1.5;
    height: 100vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* Layout Structure */
.app-container {
    display: flex;
    flex: 1;
    overflow: hidden;
    height: calc(100vh - var(--header-height));
}

.main-header {
    height: var(--header-height);
    background: var(--bg-panel);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    padding: 0 var(--space-xl);
    justify-content: space-between;
    z-index: 10;
}

.logo {
    font-weight: 600;
    font-size: 15px;
    color: var(--text-primary);
    letter-spacing: -0.01em;
}

/* Sidebars based styles */
aside {
    background: var(--bg-panel);
    overflow-y: auto;
    display: flex;
    flex-direction: column;
}

/* Left Control Panel */
.control-panel {
    width: var(--sidebar-width);
    border-right: 1px solid var(--border);
    padding: 0;
}

/* Right Layer Panel */
.layer-panel {
    width: var(--layer-panel-width);
    border-left: 1px solid var(--border);
    padding: var(--space-md);
}

/* Center Preview */
.preview-area {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    background-image:
        radial-gradient(#E5E5EA 1px, transparent 1px);
    background-size: 20px 20px;
    padding: 40px;
    overflow: hidden;
    position: relative;
}

.canvas-container {
    box-shadow: var(--shadow-md);
    border-radius: 4px;
    /* Canvas corners usually sharp or slight radius */
    overflow: hidden;
    max-width: 100%;
    max-height: 100%;
    display: flex;
}

#previewCanvas {
    max-width: 100%;
    max-height: 80vh;
    display: block;
    object-fit: contain;
}

/* Components: Details/Summary Sections */
details {
    border-bottom: 1px solid var(--border);
}

details:last-child {
    border-bottom: none;
}

summary {
    padding: var(--space-md) var(--space-lg);
    font-weight: 600;
    font-size: 12px;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    cursor: pointer;
    list-style: none;
    /* Hide default triangle */
    display: flex;
    align-items: center;
    justify-content: space-between;
    transition: background 0.1s;
}

summary:hover {
    background: var(--bg-input);
}

summary::-webkit-details-marker {
    display: none;
}

summary::after {
    content: "›";
    font-size: 14px;
    transition: transform 0.2s;
}

details[open] summary::after {
    transform: rotate(90deg);
}

.control-content {
    padding: var(--space-sm) var(--space-lg) var(--space-xl);
    display: flex;
    flex-direction: column;
    gap: var(--space-lg);
}

/* Components: Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 8px 16px;
    font-size: 13px;
    font-weight: 500;
    border-radius: var(--radius-sm);
    border: 1px solid transparent;
    cursor: pointer;
    transition: all 0.2s;
    line-height: 1.2;
}

.btn-primary {
    background: var(--primary);
    color: white;
}

.btn-primary:hover {
    background: var(--primary-hover);
}

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

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

/* Components: Toggles (Segmented Control) */
.toggle-group {
    display: flex;
    background: var(--bg-input);
    padding: 2px;
    border-radius: var(--radius-sm);
}

.toggle-btn {
    flex: 1;
    padding: 6px 12px;
    font-size: 12px;
    font-weight: 500;
    color: var(--text-secondary);
    background: transparent;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s;
}

.toggle-btn.active {
    background: white;
    color: var(--text-primary);
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

/* Components: Inputs & Labels */
.control-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-md);
    margin-bottom: var(--space-sm);
}

.control-label {
    font-size: 12px;
    color: var(--text-secondary);
    min-width: 60px;
}

input[type="text"],
select {
    width: 100%;
    padding: 6px 10px;
    font-size: 13px;
    color: var(--text-primary);
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    transition: border-color 0.2s;
}

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

/* Custom Color Input */
.color-input-wrapper {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
}

input[type="color"] {
    -webkit-appearance: none;
    appearance: none;
    border: none;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    overflow: hidden;
    cursor: pointer;
    padding: 0;
    background: none;
}

input[type="color"]::-webkit-color-swatch-wrapper {
    padding: 0;
}

input[type="color"]::-webkit-color-swatch {
    border: 1px solid rgba(0, 0, 0, 0.1);
    border-radius: 50%;
}

/* Sliders */
input[type="range"] {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    background: transparent;
}

input[type="range"]::-webkit-slider-runnable-track {
    width: 100%;
    height: 4px;
    background: var(--bg-input);
    border-radius: 2px;
}

input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    height: 16px;
    width: 16px;
    border-radius: 50%;
    background: white;
    border: 1px solid rgba(0, 0, 0, 0.1);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.15);
    margin-top: -6px;
    cursor: pointer;
}

/* Color Presets */
.color-presets-grid {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: var(--space-sm);
    padding: 4px 0;
}

.color-swatch {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    cursor: pointer;
    border: 2px solid transparent;
    transition: transform 0.1s;
}

.color-swatch.active {
    border-color: var(--text-primary);
    transform: scale(1.1);
}

.gradient-swatch {
    border-radius: 6px;
}

/* Layer Panel Specifics */
.layer-panel h3 {
    /* Using details/summary now, but keeping h3 for static title if needed */
    font-size: 11px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    margin-bottom: var(--space-md);
    letter-spacing: 0.05em;
}

.layer-list {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: var(--space-xs);
}

.layer-item {
    display: flex;
    align-items: center;
    gap: var(--space-md);
    padding: 8px 12px;
    background: var(--bg-panel);
    border: 1px solid var(--bg-app);
    /* Subtle separation */
    border-radius: var(--radius-sm);
    cursor: default;
    transition: all 0.2s;
}

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

.layer-item.selected {
    background: #E3F0FF;
    border-color: rgba(0, 122, 255, 0.3);
}

.layer-item .layer-icon {
    width: 28px;
    height: 28px;
    background: white;
    border: 1px solid rgba(0, 0, 0, 0.05);
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.layer-item .layer-name {
    font-size: 12px;
    font-weight: 500;
    color: var(--text-primary);
}

/* Upload Area */
.upload-area {
    border: 1px dashed var(--border);
    border-radius: var(--radius-sm);
    padding: var(--space-lg);
    text-align: center;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 12px;
    transition: all 0.2s;
    background: var(--bg-input);
}

.upload-area:hover {
    border-color: var(--primary);
    color: var(--primary);
    background: #Edf6ff;
}

/* Utility Classes */
.full-width {
    width: 100%;
}

.mt-sm {
    margin-top: var(--space-sm);
}

.mb-sm {
    margin-bottom: var(--space-sm);
}

.text-right {
    text-align: right;
}

.flex-row {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
}

.flex-between {
    justify-content: space-between;
}

.icp-license {
    position: fixed;
    bottom: 15px;
    right: 20px;
    font-size: 11px;
    color: var(--text-tertiary);
    z-index: 1000;
    pointer-events: none;
    font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", sans-serif;
}