* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --bg-dark: #1a1a24;
    --bg-panel: #12121a;
    --bg-card: #1e1e2a;
    --accent: #a78bfa;
    --accent-hover: #8b5cf6;
    --text: #e2e8f0;
    --text-dim: #94a3b8;
    --border: #2d2d3d;
    --radius: 12px;
}

body {
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    background-color: #0f0f17;
    color: var(--text);
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    padding: 20px;
}

.container {
    display: flex;
    gap: 20px;
    background-color: var(--bg-dark);
    padding: 24px;
    border-radius: 20px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.5);
    max-width: 1300px;
    width: 100%;
    height: 90vh;
    max-height: 900px;
}

/* ===== Левая часть ===== */
.preview-section {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    min-width: 0;
}

.preview-section h2 {
    margin-bottom: 12px;
    font-weight: 500;
    font-size: 20px;
    letter-spacing: 1px;
    color: var(--text-dim);
}

.preview-area {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    background-color: #2a2a35;
    border-radius: var(--radius);
    overflow: hidden;
    position: relative;
    margin-bottom: 16px;
}

/* Нейтральный фон с шахматной сеткой */
.canvas-wrapper {
    background-image: 
        linear-gradient(45deg, #3a3a45 25%, transparent 25%),
        linear-gradient(-45deg, #3a3a45 25%, transparent 25%),
        linear-gradient(45deg, transparent 75%, #3a3a45 75%),
        linear-gradient(-45deg, transparent 75%, #3a3a45 75%);
    background-size: 30px 30px;
    background-position: 0 0, 0 15px, 15px -15px, -15px 0px;
    background-color: #2a2a35;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
}

canvas {
    display: block;
    max-width: 90%;
    max-height: 90%;
    width: auto;
    height: auto;
    image-rendering: auto;
}

.controls-row {
    display: flex;
    gap: 12px;
    margin-bottom: 8px;
}

button {
    border: none;
    color: white;
    padding: 14px 28px;
    font-size: 16px;
    border-radius: 50px;
    cursor: pointer;
    transition: all 0.3s;
    font-weight: 600;
    letter-spacing: 0.5px;
    white-space: nowrap;
}

#downloadBtn {
    background-color: var(--accent);
}

#downloadBtn:hover {
    background-color: var(--accent-hover);
    transform: translateY(-2px);
    box-shadow: 0 8px 25px rgba(167, 139, 250, 0.4);
}

#resetBtn {
    background-color: #3d3d4d;
}

#resetBtn:hover {
    background-color: #4d4d5d;
}

.hint {
    color: #666;
    font-size: 11px;
    text-align: center;
    line-height: 1.6;
}

/* ===== Правая панель ===== */
.layers-panel {
    width: 320px;
    background-color: var(--bg-panel);
    border-radius: var(--radius);
    padding: 20px 16px;
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
}

.layers-panel h2 {
    margin-bottom: 16px;
    font-weight: 500;
    font-size: 18px;
    letter-spacing: 1px;
    color: var(--text-dim);
    text-align: center;
}

.viewer-notice {
    min-height: 42px;
    margin-bottom: 12px;
    padding: 10px 12px;
    border: 1px solid rgba(167, 139, 250, 0.22);
    border-radius: 8px;
    background: #1e1e2a;
    color: var(--text-dim);
    font-size: 12px;
    line-height: 1.35;
}

.viewer-notice.notice-pulse {
    border-color: var(--accent);
    color: var(--text);
}

.filter-tabs {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 6px;
    margin-bottom: 14px;
}

.filter-tab {
    padding: 7px 8px;
    border-radius: 7px;
    background: #252535;
    border: 1px solid var(--border);
    color: var(--text-dim);
    font-size: 11px;
    letter-spacing: 0;
}

.filter-tab:hover,
.filter-tab.active {
    background: var(--accent);
    border-color: var(--accent);
    color: white;
}

.layers-scroll {
    overflow-y: auto;
    flex: 1;
    padding-right: 8px;
    scrollbar-width: thin;
    scrollbar-color: var(--accent) var(--bg-card);
}

.layers-scroll::-webkit-scrollbar {
    width: 5px;
}

.layers-scroll::-webkit-scrollbar-track {
    background: var(--bg-card);
    border-radius: 3px;
}

.layers-scroll::-webkit-scrollbar-thumb {
    background: var(--accent);
    border-radius: 3px;
}

/* Группа слоя */
.layer-group {
    margin-bottom: 14px;
    background-color: var(--bg-card);
    border-radius: var(--radius);
    border: 1px solid var(--border);
    overflow: hidden;
}

.layer-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 14px;
    cursor: pointer;
    user-select: none;
    transition: background 0.2s;
}

.layer-header:hover {
    background-color: #252535;
}

.layer-header h3 {
    font-size: 13px;
    font-weight: 600;
    letter-spacing: 1px;
    text-transform: uppercase;
    color: var(--accent);
}

.layer-header .arrow {
    transition: transform 0.3s;
    font-size: 12px;
}

.layer-group.collapsed .layer-header .arrow {
    transform: rotate(-90deg);
}

.layer-content {
    padding: 0 14px 14px;
    transition: max-height 0.3s ease, padding 0.3s;
    max-height: 500px;
    overflow: hidden;
}

.layer-group.collapsed .layer-content {
    max-height: 0;
    padding-top: 0;
    padding-bottom: 0;
}

/* Сетка опций */
.options {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
}

.option-item {
    aspect-ratio: 1;
    border: 2px solid transparent;
    border-radius: 8px;
    cursor: pointer;
    overflow: hidden;
    background-color: #252535;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    padding: 4px;
    position: relative;
}

.option-item:hover {
    border-color: var(--accent);
    background-color: #2d2d40;
}

.option-item.selected {
    border-color: var(--accent);
    box-shadow: 0 0 12px rgba(167, 139, 250, 0.4);
    background-color: #2d2d40;
}

.option-item.locked {
    cursor: not-allowed;
    border-color: rgba(148, 163, 184, 0.16);
}

.option-item.locked img {
    filter: grayscale(0.9);
    opacity: 0.35;
}

.option-item.locked::after {
    content: attr(data-reason);
    position: absolute;
    left: 6px;
    right: 6px;
    bottom: 6px;
    z-index: 4;
    padding: 6px;
    border-radius: 6px;
    background: rgba(18, 18, 26, 0.96);
    color: var(--text);
    font-size: 10px;
    line-height: 1.25;
    opacity: 0;
    pointer-events: none;
    transform: translateY(4px);
    transition: opacity 0.2s, transform 0.2s;
}

.option-item.locked:hover::after,
.option-item.locked:focus-visible::after {
    opacity: 1;
    transform: translateY(0);
}

.option-item img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.access-badge {
    position: absolute;
    top: 4px;
    left: 4px;
    z-index: 2;
    max-width: calc(100% - 8px);
    padding: 2px 5px;
    border-radius: 5px;
    background: rgba(18, 18, 26, 0.86);
    color: var(--text);
    font-size: 9px;
    font-weight: 700;
    line-height: 1.1;
}

.badge-public {
    color: #86efac;
}

.badge-vip {
    color: #f0abfc;
}

.badge-moderator {
    color: #93c5fd;
}

.badge-streak {
    color: #fde68a;
}

.lock-icon {
    position: absolute;
    right: 6px;
    top: 6px;
    z-index: 3;
    width: 22px;
    height: 22px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background: rgba(15, 15, 23, 0.88);
    font-size: 12px;
}

/* Кнопка перемещения слоя */
.move-layer-btn {
    display: block;
    width: 100%;
    margin-top: 8px;
    padding: 6px;
    font-size: 11px;
    background: #2d2d40;
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text-dim);
    cursor: pointer;
    transition: all 0.2s;
}

.move-layer-btn:hover {
    background: var(--accent);
    color: white;
    border-color: var(--accent);
}

/* ===== Модальное окно ===== */
.modal-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.7);
    z-index: 1000;
    justify-content: center;
    align-items: center;
}

.modal-overlay.active {
    display: flex;
}

.modal {
    background: var(--bg-dark);
    border-radius: 16px;
    padding: 24px;
    text-align: center;
    min-width: 320px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.6);
}

.modal h3 {
    color: var(--accent);
    margin-bottom: 8px;
}

#modalLayerName {
    color: var(--text-dim);
    font-size: 14px;
    margin-bottom: 20px;
}

.position-controls {
    margin-bottom: 16px;
}

.pos-row {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 12px;
    margin-bottom: 8px;
}

.pos-btn {
    width: 50px;
    height: 50px;
    border-radius: 12px;
    font-size: 20px;
    padding: 0;
    background: #2d2d40;
    border: 2px solid var(--border);
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.pos-btn:hover {
    background: var(--accent);
    border-color: var(--accent);
}

.pos-info {
    background: #252535;
    padding: 10px 16px;
    border-radius: 8px;
    display: flex;
    gap: 16px;
    font-size: 13px;
}

.pos-info b {
    color: var(--accent);
}

.modal-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
    justify-content: center;
}

#stepRange {
    width: 80px;
    accent-color: var(--accent);
}

#stepValue {
    font-size: 12px;
    color: var(--text-dim);
    min-width: 35px;
}

#resetPosBtn, #closeModalBtn {
    padding: 8px 16px;
    font-size: 13px;
    border-radius: 8px;
}

#resetPosBtn {
    background: #5a3a3a;
}

#closeModalBtn {
    background: #3d3d4d;
}

/* ===== Адаптив ===== */
@media (max-width: 900px) {
    .container {
        flex-direction: column;
        height: auto;
        max-height: none;
        padding: 16px;
        gap: 12px;
    }
    
    .preview-section {
        order: 1;
        min-height: 400px;
    }
    
    .layers-panel {
        order: 2;
        width: 100%;
        max-height: 50vh;
    }
    
    canvas {
        max-width: 95%;
        max-height: 95%;
    }
}

#exportStatus { color: #fbbf24; font-size: 13px; margin-bottom: 10px; }
#downloadBtn:disabled { opacity: .5; cursor: wait; transform: none; }

.auth-controls { display:flex; gap:10px; align-items:center; flex-wrap:wrap; margin-bottom:12px; }
.twitch-login { display:block; padding:12px 16px; background:#9146ff; color:white; text-decoration:none; border-radius:8px; font-weight:600; text-align:center; width:100%; }
.twitch-login:hover { background:#772ce8; }
.auth-controls [hidden] { display:none; }
#twitchProfile { font-size:13px; overflow-wrap:anywhere; }
#twitchLogout { background:#3d3d4d; padding:7px 12px; font-size:12px; }
#authStatus { font-size:12px; color:#fbbf24; margin-bottom:10px; }
