:root {
    --primary-purple: #5c2c70;
    --primary-orange: #eb532b;
    --batik-cream: #fef3c7;
    --panel-bg: #ffffff;
    --text-main: #333;
    --border-color: #ddd;
    --border-color: #ddd;

    /* Font config for consistency */
    --font-heading: 'Playfair Display', serif;
    --font-body: 'Segoe UI', sans-serif;
    --text-muted: #666;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
    --white: #ffffff;
}

/* --- Global Header (Copied for consistency) --- */
.site-header {
    background: linear-gradient(90deg, #5c2c70, #eb532b);
    border-bottom: 2px solid rgba(255, 255, 255, 0.1);
    padding: 0.75rem 1.5rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: sticky;
    top: 0;
    z-index: 1000;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
    flex-wrap: wrap;
    gap: 1rem;
    width: 100%;
}

.site-brand {
    text-decoration: none;
    display: flex;
    flex-direction: column;
}

.brand-title {
    font-family: var(--font-heading);
    font-size: 1.5rem;
    font-weight: 700;
    color: white;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
    line-height: 1.2;
}

.brand-subtitle {
    font-family: var(--font-body);
    font-size: 0.85rem;
    color: rgba(255, 255, 255, 0.9);
    letter-spacing: 0.5px;
}

.site-nav ul {
    list-style: none;
    display: flex;
    gap: 1.5rem;
    padding: 0;
    margin: 0;
}

.site-nav a {
    text-decoration: none;
    color: rgba(255, 255, 255, 0.8);
    font-weight: 600;
    font-size: 0.95rem;
    padding: 0.5rem 0;
    position: relative;
    transition: color 0.2s;
}

.site-nav a:hover {
    color: white;
    text-shadow: 0 0 5px rgba(255, 255, 255, 0.5);
}

.site-nav a.active {
    color: white;
}

.site-nav a.active::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 3px;
    background: #fef3c7;
    /* Batik Cream */
    border-radius: 2px;
    box-shadow: 0 0 5px rgba(0, 0, 0, 0.2);
}

@media (max-width: 600px) {
    .site-header {
        flex-direction: column;
        align-items: flex-start;
    }

    .site-nav {
        width: 100%;
        overflow-x: auto;
    }

    .site-nav ul {
        gap: 1rem;
        padding-bottom: 4px;
    }
}

/* --- End Global Header --- */

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background-color: var(--batik-cream);
    color: var(--text-main);
    height: 100vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    /* App-like feel */
}

.app-container {
    display: flex;
    flex-direction: row;
    flex: 1;
    min-height: 0;
    /* Important for nested scrolling */
    width: 100%;
}

/* Footer */
/* Footer */
.app-footer {
    background: linear-gradient(90deg, #5c2c70, #eb532b);
    color: white;
    text-align: center;
    padding: 1rem;
    font-size: 0.85rem;
    z-index: 20;
    box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.15);
    width: 100%;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
}

/* Mobile Header */
.mobile-header {
    display: none;
    background: var(--primary-purple);
    color: white;
    padding: 1rem;
    text-align: center;
}

/* Control Panel */
.control-panel {
    width: 320px;
    background: linear-gradient(135deg, #5c2c70 0%, #eb532b 100%);
    padding: 1rem;
    overflow-y: auto;
    border-right: 1px solid var(--border-color);
    box-shadow: 2px 0 5px rgba(0, 0, 0, 0.05);
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    flex-shrink: 0;
    z-index: 10;
    color: white;
    /* Default text white */
}

.panel-header h1 {
    font-size: 1.5rem;
    color: #ffffff;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}

.panel-header p {
    font-size: 0.9rem;
    color: rgba(255, 255, 255, 0.8);
    margin-bottom: 1rem;
}

.control-group {
    background: rgba(255, 255, 255, 0.95);
    /* High contrast card */
    padding: 1rem;
    border-radius: 8px;
    border: none;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    color: #333;
    /* Reset text color inside cards */
}

.group-label {
    display: block;
    font-weight: bold;
    margin-bottom: 0.5rem;
    color: var(--primary-purple);
    /* Keep purple inside white cards */
    font-size: 0.95rem;
}

.control-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0.5rem;
    gap: 10px;
}

.control-row label {
    font-size: 0.9rem;
}

input[type="range"] {
    flex: 1;
}

.status-box {
    margin-top: 0.5rem;
    padding: 0.5rem;
    background: #eee;
    font-size: 0.85rem;
    text-align: center;
    border-radius: 4px;
    color: #555;
    font-weight: bold;
}

/* Buttons */
button {
    width: 100%;
    padding: 0.6rem;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-weight: bold;
    margin-bottom: 0.5rem;
    transition: background 0.2s;
}

.btn-primary {
    background: var(--primary-purple);
    color: white;
    margin-top: 0.5rem;
}

.btn-primary:hover {
    background: #4a1f5a;
}

.btn-secondary {
    background: #ddd;
    color: #333;
}

.btn-secondary.active {
    background: var(--primary-orange);
    color: white;
    border: 1px solid #c2411e;
}

.btn-danger {
    background: #ffecec;
    color: #cc0000;
    border: 1px solid #ffcccc;
}

.btn-success {
    background: #e6fffa;
    color: #008060;
    border: 1px solid #b2f5ea;
}

/* Palette */
.palette {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
    margin-bottom: 1rem;
}

.swatch {
    width: 100%;
    aspect-ratio: 1;
    border-radius: 4px;
    cursor: pointer;
    border: 2px solid transparent;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

.swatch.active {
    border-color: #333;
    transform: scale(1.1);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

/* Workspace */
.workspace {
    flex: 1;
    background: #888;
    /* Neutral gray for workspace background */
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    padding: 2rem;
    position: relative;
    overflow: hidden;
}

.canvas-container {
    position: relative;
    width: 100%;
    max-width: 800px;
    /* aspect-ratio ensure square to match 800x800 bitmap, preventing distortion */
    aspect-ratio: 1 / 1;
    max-height: 85vh;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.3);
    background: white;
    margin: 0 auto;
}

canvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    /* Ensure bitmap fills element exactly */
    object-fit: fill;
}

#canvasOutline {
    pointer-events: none;
    z-index: 2;
}

#canvasBrushPreview {
    pointer-events: none;
    z-index: 10;
}

#canvasColor {
    z-index: 1;
    cursor: none;
    /* Hide default cursor to use custom brush */
}

.instructions {
    margin-top: 1rem;
    color: white;
    background: rgba(0, 0, 0, 0.5);
    padding: 0.5rem 1rem;
    border-radius: 20px;
    font-size: 0.9rem;
}

.advanced-toggles {
    margin-bottom: 1rem;
    padding-top: 0.5rem;
    border-top: 1px solid #eee;
    font-size: 0.9rem;
}

.advanced-toggles label {
    display: block;
    margin-bottom: 0.3rem;
    cursor: pointer;
}

.sub-controls {
    margin-left: 1.2rem;
    padding-left: 0.5rem;
    border-left: 2px solid #eee;
    margin-top: 0.5rem;
}

/* Responsive */
@media (max-width: 768px) {
    body {
        overflow: auto;
    }

    .app-container {
        flex-direction: column;
        height: auto;
    }

    .mobile-header {
        display: block;
    }

    .panel-header {
        display: none;
    }

    .control-panel {
        width: 100%;
        max-height: 40vh;
        border-right: none;
        border-bottom: 1px solid var(--border-color);
    }

    .workspace {
        min-height: 60vh;
        padding: 1rem;
    }
}
