/* ============================================
   SVG Pattern Generator — Styles
   Theme: Dark mode + Violet palette
   ============================================ */

:root {
    --primary: #6C63FF;
    --primary-hover: #8078FF;
    --primary-dim: rgba(108, 99, 255, 0.15);
    --secondary: #A78BFA;
    --accent: #F472B6;
    --bg: #0F0A1A;
    --bg-card: rgba(20, 14, 38, 0.6);
    --bg-hover: rgba(108, 99, 255, 0.08);
    --bg-input: rgba(15, 10, 26, 0.9);
    --surface: rgba(30, 22, 55, 0.5);
    --border: rgba(108, 99, 255, 0.12);
    --border-focus: rgba(108, 99, 255, 0.5);
    --text: #EDE9FF;
    --text-secondary: #9B8FC2;
    --text-dim: #5E4F8A;
    --radius: 12px;
    --radius-sm: 8px;
    --radius-xs: 6px;
    --font: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    --transition: 250ms ease;
    --shadow: 0 4px 24px rgba(0, 0, 0, 0.3);
    --glass: blur(16px) saturate(180%);
}

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

html {
    font-size: 16px;
    -webkit-font-smoothing: antialiased;
}

body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    line-height: 1.5;
}

body::before {
    content: '';
    position: fixed;
    top: -20%;
    left: 30%;
    width: 50%;
    height: 50%;
    background: radial-gradient(circle, rgba(108, 99, 255, 0.06) 0%, transparent 70%);
    pointer-events: none;
}

/* --- Header --- */
.app-header {
    position: sticky;
    top: 0;
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 24px;
    background: rgba(15, 10, 26, 0.85);
    backdrop-filter: var(--glass);
    border-bottom: 1px solid var(--border);
}

.header-content {
    display: flex;
    align-items: center;
    gap: 16px;
}

.logo {
    display: flex;
    align-items: center;
    gap: 10px;
}

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

.header-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

/* --- Buttons --- */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border: none;
    border-radius: var(--radius-sm);
    font-family: var(--font);
    font-size: 0.82rem;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition);
    white-space: nowrap;
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary), var(--primary-hover));
    color: #fff;
    box-shadow: 0 2px 12px rgba(108, 99, 255, 0.3);
}

.btn-primary:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 20px rgba(108, 99, 255, 0.45);
}

.btn-ghost {
    background: transparent;
    color: var(--text-secondary);
}

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

.btn-icon {
    background: rgba(15, 10, 26, 0.8);
    color: var(--text);
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    font-size: 1.1rem;
    border: 1px solid var(--border);
}

.btn-icon:hover {
    background: var(--primary-dim);
    border-color: var(--primary);
}

.btn:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

.select {
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 7px 12px;
    color: var(--text);
    font-family: var(--font);
    font-size: 0.82rem;
    cursor: pointer;
    transition: border-color var(--transition);
}

.select:focus {
    outline: none;
    border-color: var(--border-focus);
}

/* --- Layout --- */
.app-main {
    display: grid;
    grid-template-columns: 300px 1fr;
    flex: 1;
    position: relative;
    z-index: 1;
}

/* --- Controls Panel --- */
.controls-panel {
    padding: 16px;
    border-right: 1px solid var(--border);
    overflow-y: auto;
    max-height: calc(100vh - 56px);
    display: flex;
    flex-direction: column;
    gap: 16px;
    background: rgba(15, 10, 26, 0.5);
}

.control-group {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 14px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.control-label {
    font-size: 0.78rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-secondary);
}

/* Pattern type grid */
.type-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 6px;
}

.type-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 8px 4px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--text-secondary);
    font-family: var(--font);
    font-size: 0.68rem;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition);
}

.type-btn svg {
    width: 24px;
    height: 24px;
}

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

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

/* Color inputs */
.color-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

.color-field label {
    font-size: 0.72rem;
    color: var(--text-dim);
    display: block;
    margin-bottom: 4px;
}

.color-input-wrap {
    display: flex;
    align-items: center;
    gap: 6px;
}

input[type="color"] {
    width: 32px;
    height: 32px;
    border: 1px solid var(--border);
    border-radius: var(--radius-xs);
    cursor: pointer;
    padding: 2px;
    background: var(--bg-input);
}

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

input[type="color"]::-webkit-color-swatch {
    border: none;
    border-radius: 3px;
}

.color-hex {
    width: 80px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-xs);
    padding: 5px 8px;
    color: var(--text);
    font-family: var(--font);
    font-size: 0.78rem;
}

.color-hex:focus {
    outline: none;
    border-color: var(--border-focus);
}

/* Palette presets */
.palette-presets {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    margin-top: 4px;
}

.palette-swatch {
    display: flex;
    gap: 2px;
    padding: 3px;
    border: 1px solid var(--border);
    border-radius: var(--radius-xs);
    cursor: pointer;
    transition: all var(--transition);
}

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

.palette-dot {
    width: 14px;
    height: 14px;
    border-radius: 3px;
}

/* Sliders */
.slider-field {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.slider-field label {
    font-size: 0.75rem;
    color: var(--text-secondary);
    display: flex;
    justify-content: space-between;
}

.slider-field label span {
    color: var(--primary);
    font-weight: 600;
}

input[type="range"] {
    -webkit-appearance: none;
    width: 100%;
    height: 4px;
    background: var(--surface);
    border-radius: 4px;
    outline: none;
    transition: all var(--transition);
}

input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--primary);
    cursor: pointer;
    box-shadow: 0 1px 6px rgba(108, 99, 255, 0.4);
    transition: transform var(--transition);
}

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

/* --- Preview Area --- */
.preview-area {
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: relative;
}

.tile-preview-wrap {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 16px;
}

.tile-label {
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--text-dim);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    white-space: nowrap;
}

.tile-preview {
    width: 80px;
    height: 80px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    overflow: hidden;
    flex-shrink: 0;
}

.tile-preview svg {
    width: 100%;
    height: 100%;
}

.full-preview {
    flex: 1;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 400px;
}

.full-preview svg {
    width: 100%;
    height: 100%;
}

/* --- Fullscreen --- */
.fullscreen-overlay {
    position: fixed;
    inset: 0;
    background: var(--bg);
    z-index: 300;
    animation: fadeIn 250ms ease;
}

.fullscreen-overlay[hidden] {
    display: none;
}

.fullscreen-close {
    position: fixed;
    top: 16px;
    right: 16px;
    z-index: 310;
}

.fullscreen-content {
    width: 100%;
    height: 100%;
}

.fullscreen-content svg {
    width: 100%;
    height: 100%;
}

/* --- Toast --- */
.toast {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    padding: 10px 20px;
    background: var(--primary);
    color: #fff;
    font-weight: 600;
    font-size: 0.85rem;
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow);
    opacity: 0;
    transition: opacity 300ms ease, transform 300ms ease;
    z-index: 400;
    pointer-events: none;
}

.toast[hidden] {
    display: block;
    opacity: 0;
    transform: translateX(-50%) translateY(20px);
}

.toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

/* --- Animations --- */
@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

/* --- Scrollbar --- */
::-webkit-scrollbar {
    width: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: rgba(108, 99, 255, 0.2);
    border-radius: 10px;
}

/* --- Responsive --- */
@media (max-width: 800px) {
    .app-main {
        grid-template-columns: 1fr;
    }

    .controls-panel {
        border-right: none;
        border-bottom: 1px solid var(--border);
        max-height: none;
        flex-direction: row;
        flex-wrap: wrap;
        overflow-x: auto;
        padding: 12px;
    }

    .control-group {
        min-width: 250px;
        flex: 1;
    }

    .full-preview {
        min-height: 300px;
    }
}

@media (max-width: 540px) {
    .app-header {
        flex-direction: column;
        gap: 10px;
        padding: 12px 16px;
    }

    .header-actions {
        width: 100%;
        overflow-x: auto;
    }

    .controls-panel {
        flex-direction: column;
    }

    .control-group {
        min-width: auto;
    }
}