/* ── Apple Clean — Avatar Studio ── */

:root {
    --bg: #f5f5f7;
    --surface: #ffffff;
    --card: #ffffff;

    --text: #1d1d1f;
    --muted: #86868b;
    --label: #6e6e73;

    --accent: #0071e3;
    --accent-hover: #0077ed;
    --accent-text: #ffffff;

    --border: rgba(0, 0, 0, 0.08);
    --border-strong: rgba(0, 0, 0, 0.12);

    --radius-sm: 12px;
    --radius-md: 16px;
    --radius-lg: 24px;

    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.04), 0 1px 2px rgba(0, 0, 0, 0.06);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.06), 0 1px 3px rgba(0, 0, 0, 0.04);
    --shadow-lg: 0 8px 30px rgba(0, 0, 0, 0.08), 0 2px 8px rgba(0, 0, 0, 0.04);

    --space-xs: 8px;
    --space-sm: 12px;
    --space-md: 16px;
    --space-lg: 24px;
    --space-xl: 32px;

    --focus-ring: 0 0 0 4px rgba(0, 113, 227, 0.25);
    --font: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Helvetica Neue", Arial, sans-serif;
    --transition: 200ms ease;
}

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

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

/* ── Container ── */

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: var(--space-lg);
}

/* ── Header ── */

.header {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: var(--space-xl) var(--space-xl) var(--space-lg);
    margin-bottom: var(--space-lg);
    box-shadow: var(--shadow-sm);
}

.header h1 {
    font-family: var(--font);
    font-size: 30px;
    font-weight: 600;
    color: var(--text);
    line-height: 1.15;
    letter-spacing: -0.02em;
}

.header p {
    margin-top: var(--space-xs);
    color: var(--muted);
    font-size: 15px;
    line-height: 1.5;
}

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

.asset-mode-indicator {
    display: inline-flex;
    align-items: center;
    padding: 3px 10px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.asset-mode-indicator.on {
    border: 1px solid rgba(52, 199, 89, 0.3);
    background: rgba(52, 199, 89, 0.08);
    color: #248a3d;
}

.asset-mode-indicator.off {
    border: 1px solid rgba(255, 69, 58, 0.25);
    background: rgba(255, 69, 58, 0.06);
    color: #d70015;
}

/* ── Main Layout ── */

.main-content {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: var(--space-lg);
    align-items: start;
}

/* ── Sidebar (controls + presets) ── */

.sidebar {
    display: flex;
    flex-direction: column;
    gap: var(--space-lg);
}

/* ── Panels (shared) ── */

:is(.avatar-preview, .controls-panel, .presets-panel) {
    background: var(--card);
    border-radius: var(--radius-md);
    padding: var(--space-lg);
    border: 1px solid var(--border);
    box-shadow: var(--shadow-sm);
}

:is(.avatar-preview h3, .controls-panel h3, .presets-panel h3) {
    margin-bottom: var(--space-md);
    color: var(--muted);
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

/* ── Avatar Preview ── */

.avatar-preview {
    position: sticky;
    top: var(--space-lg);
}

#avatarCanvas {
    width: min(100%, 340px);
    aspect-ratio: 1 / 1;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-md);
    background: var(--surface);
    margin: 0 auto var(--space-md);
    display: block;
    box-shadow: var(--shadow-sm);
}

/* ── Buttons ── */

.preview-actions {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: var(--space-xs);
}

.btn {
    height: 44px;
    padding: 0 var(--space-md);
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-family: var(--font);
    font-weight: 500;
    font-size: 14px;
    letter-spacing: -0.01em;
    transition: background var(--transition), color var(--transition), transform 120ms ease;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    user-select: none;
    white-space: nowrap;
}

.btn:focus-visible {
    outline: none;
    box-shadow: var(--focus-ring);
}

.btn:active {
    transform: scale(0.98);
}

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

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

.btn-secondary {
    background: rgba(0, 0, 0, 0.05);
    color: var(--text);
}

.btn-secondary:hover {
    background: rgba(0, 0, 0, 0.08);
}

.btn-success {
    background: transparent;
    color: var(--accent);
}

.btn-success:hover {
    background: rgba(0, 113, 227, 0.06);
}

/* ── Controls Panel ── */

.controls-panel {
    max-height: 760px;
    overflow-y: auto;
}

.controls-panel::-webkit-scrollbar,
.component-list::-webkit-scrollbar {
    width: 6px;
}

.controls-panel::-webkit-scrollbar-thumb,
.component-list::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.15);
    border-radius: 999px;
}

.controls-panel::-webkit-scrollbar-track,
.component-list::-webkit-scrollbar-track {
    background: transparent;
}

/* ── Accordion Control Groups ── */

.control-group {
    border-bottom: 1px solid var(--border);
    padding-bottom: var(--space-sm);
    margin-bottom: var(--space-sm);
}

.control-group:last-child {
    border-bottom: none;
    padding-bottom: 0;
    margin-bottom: 0;
}

.control-group-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    padding: var(--space-sm) 0;
    border: none;
    background: none;
    cursor: pointer;
    font-family: var(--font);
    font-size: 15px;
    font-weight: 600;
    color: var(--text);
    letter-spacing: -0.01em;
    -webkit-user-select: none;
    user-select: none;
}

.control-group-header:focus-visible {
    outline: none;
    box-shadow: var(--focus-ring);
    border-radius: var(--space-xs);
}

.control-group-header .chevron {
    width: 16px;
    height: 16px;
    color: var(--muted);
    transition: transform var(--transition);
    flex-shrink: 0;
}

.control-group[data-accordion="closed"] .chevron {
    transform: rotate(-90deg);
}

.control-group-body {
    overflow: hidden;
    transition: max-height var(--transition), opacity var(--transition);
    max-height: 300px;
    opacity: 1;
}

.control-group[data-accordion="closed"] .control-group-body {
    max-height: 0;
    opacity: 0;
}

/* ── Control Rows ── */

.control-row {
    display: grid;
    grid-template-columns: 80px 1fr;
    align-items: center;
    gap: var(--space-sm);
    margin-bottom: var(--space-sm);
}

.control-row:last-child {
    margin-bottom: 0;
}

.control-row label {
    font-weight: 500;
    color: var(--label);
    font-size: 13px;
}

/* ── Inputs ── */

select,
input[type="text"] {
    width: 100%;
    height: 44px;
    padding: 0 var(--space-sm);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--text);
    font-family: var(--font);
    font-size: 14px;
    transition: border-color var(--transition), box-shadow var(--transition);
    appearance: none;
    -webkit-appearance: none;
}

select {
    padding-right: 36px;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='none' stroke='%2386868b' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M3 4.5 6 7.5 9 4.5'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    background-size: 12px;
    cursor: pointer;
}

select:hover,
input[type="text"]:hover {
    border-color: rgba(0, 0, 0, 0.2);
}

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

input[type="color"] {
    width: 44px;
    height: 44px;
    padding: 2px;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    cursor: pointer;
    background: var(--surface);
}

input[type="color"]:focus-visible {
    outline: none;
    box-shadow: var(--focus-ring);
}

/* ── Layer Toggle ── */

.layer-toggle {
    display: flex;
    align-items: center;
    gap: var(--space-xs);
    margin-top: var(--space-xs);
    padding-top: var(--space-xs);
    border-top: 1px solid var(--border);
    color: var(--muted);
    font-size: 13px;
}

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

/* ── Presets ── */

.presets-panel {
    display: flex;
    flex-direction: column;
    gap: var(--space-md);
}

.save-preset {
    display: grid;
    gap: var(--space-xs);
}

.save-preset input {
    width: 100%;
    height: 44px;
    padding: 0 var(--space-sm);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    background: var(--surface);
    font-family: var(--font);
    font-size: 14px;
}

.save-preset input:focus {
    outline: none;
    box-shadow: var(--focus-ring);
    border-color: var(--accent);
}

#presetsList {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: var(--space-xs);
}

.preset-item {
    background: var(--surface);
    border-radius: var(--radius-sm);
    padding: var(--space-md);
    border: 1px solid var(--border);
    cursor: pointer;
    transition: background var(--transition), border-color var(--transition);
}

.preset-item:hover {
    background: var(--bg);
    border-color: var(--border-strong);
}

.preset-thumb {
    width: 100%;
    aspect-ratio: 1;
    background: var(--bg);
    border-radius: var(--space-xs);
    margin-bottom: var(--space-sm);
}

.preset-item h5 {
    font-family: var(--font);
    font-size: 14px;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 2px;
}

.preset-item p {
    font-size: 12px;
    color: var(--muted);
    margin: 0;
}

/* ── Export Info ── */

.export-info {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: var(--space-md);
    margin-top: var(--space-md);
    font-size: 13px;
    color: var(--label);
}

.export-info h5 {
    font-family: var(--font);
    font-size: 14px;
    font-weight: 600;
    color: var(--text);
    margin-bottom: var(--space-xs);
}

.export-info code {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 2px 6px;
    font-size: 12px;
}

.component-list {
    max-height: 150px;
    overflow-y: auto;
    background: var(--surface);
    border-radius: var(--space-xs);
    padding: var(--space-sm);
    margin-top: var(--space-xs);
    border: 1px solid var(--border);
}

.component-item {
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
    font-size: 12px;
    padding: 2px 0;
    color: var(--label);
}

/* ── Toast ── */

.toast-container {
    position: fixed;
    top: var(--space-lg);
    right: var(--space-lg);
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: var(--space-xs);
    pointer-events: none;
}

.toast {
    background: var(--text);
    color: var(--surface);
    padding: var(--space-sm) var(--space-md);
    border-radius: var(--radius-sm);
    font-family: var(--font);
    font-size: 14px;
    font-weight: 500;
    box-shadow: var(--shadow-lg);
    opacity: 0;
    transform: translateY(-8px) scale(0.96);
    animation: toast-in 300ms ease forwards;
    pointer-events: auto;
}

.toast.toast-out {
    animation: toast-out 200ms ease forwards;
}

@keyframes toast-in {
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

@keyframes toast-out {
    to {
        opacity: 0;
        transform: translateY(-8px) scale(0.96);
    }
}

/* ── Responsive ── */

@media (max-width: 1024px) {
    .main-content {
        grid-template-columns: 1fr;
    }

    .avatar-preview {
        position: static;
    }

    .controls-panel {
        max-height: none;
        overflow: visible;
    }
}

@media (max-width: 600px) {
    .container {
        padding: var(--space-sm);
    }

    .header {
        padding: var(--space-lg) var(--space-md);
    }

    .header h1 {
        font-size: 24px;
    }

    .preview-actions {
        grid-template-columns: 1fr;
    }

    #avatarCanvas {
        width: min(100%, 280px);
    }

    #presetsList {
        grid-template-columns: 1fr 1fr;
    }
}

@media (prefers-reduced-motion: reduce) {
    * {
        transition: none !important;
        animation: none !important;
    }
}
