/* css/builder.css */

body {
    margin: 0;
    padding: 0;
    display: flex;
    height: 100vh;
    width: 100vw;
    background: #0f0f13;
    color: #e0e0e0;
    font-family: 'Segoe UI', Roboto, sans-serif;
    overflow: hidden;
}

/* --- Left: Preview --- */
.preview-section {
    flex: 1;
    position: relative;
    background: #000;
    overflow: hidden;
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 0;
}

.preview-wrapper {
    width: 100%;
    height: 100%;
    position: relative;
}

.preview-container {
    width: 2560px;
    height: 1440px;
    position: absolute;
    top: 50%;
    left: 50%;
    overflow: hidden;
    transform-origin: center center;
    container-type: inline-size;
}

#aquarium {
    background: linear-gradient(to bottom, #001f3f, #001220);
    width: 100% !important;
    height: 100% !important;
    position: absolute;
    top: 0;
    left: 0;
}

#ui-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

.preview-badge {
    position: absolute;
    top: 15px;
    left: 15px;
    background: #ff0055;
    color: white;
    padding: 4px 10px;
    border-radius: 4px;
    font-size: 10px;
    font-weight: bold;
    z-index: 2000;
}

/* --- Right: Dashboard --- */
.designer-section {
    width: 450px;
    background: #18181b;
    border-left: 1px solid #333;
    display: flex;
    flex-direction: column;
    z-index: 10000;
    /* Sidebar stays ON TOP */
    box-shadow: -5px 0 20px rgba(0, 0, 0, 0.5);
}

.dashboard-header {
    padding: 20px;
    background: #202024;
    border-bottom: 1px solid #333;
}

.dashboard-header h2 {
    margin: 0;
    font-size: 18px;
    color: #00f2ff;
}

.dashboard-content {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
}

.dash-card {
    background: #27272a;
    border-radius: 8px;
    padding: 15px;
    margin-bottom: 15px;
    border: 1px solid #333;
}

.dash-card h3 {
    margin: 0 0 10px 0;
    font-size: 13px;
    color: #aaa;
    display: flex;
    align-items: center;
    gap: 8px;
    text-transform: uppercase;
}

/* Inputs */
input[type="text"],
select,
textarea {
    background: #18181b;
    border: 1px solid #444;
    color: #fff;
    padding: 8px;
    border-radius: 4px;
    width: 100%;
    box-sizing: border-box;
    font-family: inherit;
    font-size: 13px;
    margin-bottom: 5px;
}

input:focus,
select:focus,
textarea:focus {
    border-color: #00f2ff;
    outline: none;
}

.row-inputs {
    display: flex;
    gap: 10px;
}

/* Position Mini Grid */
.row-flex {
    display: flex;
    gap: 10px;
}

.style-selector {
    flex: 1;
}

.pos-mini-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 2px;
    width: 60px;
    height: 60px;
}

.pos-mini-cell {
    background: #444;
    cursor: pointer;
    border-radius: 2px;
}

.pos-mini-cell.active {
    background: #00f2ff;
}

/* Active Item Cards */
.card-header-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
}

.btn-icon-add {
    background: #28a745;
    border: none;
    color: white;
    border-radius: 4px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
}

.btn-icon-add:hover {
    background: #34ce57;
}

.btn-icon-confirm {
    background: #e53935;
    border: none;
    color: white;
    border-radius: 4px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    animation: confirm-pulse 0.8s ease-in-out infinite alternate;
}

.btn-icon-confirm:hover {
    background: #c62828;
}

@keyframes confirm-pulse {
    0% {
        box-shadow: 0 0 0 0 rgba(229, 57, 53, 0.5);
    }

    100% {
        box-shadow: 0 0 8px 3px rgba(229, 57, 53, 0.3);
    }
}

/* Fixed Items List Container */
.items-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    min-height: 20px;
    width: 100%;
    padding-bottom: 5px;
    /* Prevent cutout */
}

.item-card {
    background: #333;
    border: 1px solid #444;
    border-radius: 6px;
    padding: 10px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: 0.2s;
}

.item-card:hover {
    border-color: #666;
    background: #3a3a3a;
}

.item-card.meme-card {
    border-left: 4px solid #ffa500;
}

.item-card.fish-card {
    border-left: 4px solid #00f2ff;
}

.item-info {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.item-title {
    font-weight: bold;
    font-size: 14px;
    color: #eee;
}

.item-meta {
    font-size: 11px;
    color: #aaa;
}

.item-actions {
    display: flex;
    gap: 5px;
}

.btn-mini {
    background: #444;
    border: none;
    color: #ccc;
    width: 28px;
    height: 28px;
    border-radius: 4px;
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
}

.btn-mini:hover {
    background: #555;
    color: white;
}

.btn-mini.del:hover {
    background: #ff4444;
}

/* Footer */
.dashboard-footer {
    padding: 20px;
    background: #202024;
    border-top: 1px solid #333;
}

.code-area {
    display: flex;
    gap: 5px;
    margin-bottom: 10px;
}

#final-code {
    height: 40px;
    resize: none;
    color: #00f2ff;
    border-color: #00f2ff;
}

#btn-copy {
    background: #333;
    color: white;
    border: none;
    cursor: pointer;
    font-weight: bold;
    padding: 0 10px;
}

.btn-primary {
    width: 100%;
    background: #00f2ff;
    color: #000;
    border: none;
    padding: 12px;
    border-radius: 6px;
    font-weight: 800;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

/* ================= MODALS ================= */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100%;
    background: rgba(0, 0, 0, 0.9);
    backdrop-filter: blur(8px);
    z-index: 20000;
    /* Higher than dashboard */
    display: flex;
    justify-content: center;
    align-items: center;
    opacity: 1;
    transition: opacity 0.2s;
}

.modal-overlay.hidden {
    opacity: 0;
    pointer-events: none;
}

.modal-window {
    background: #18181b;
    width: 95vw;
    height: 90vh;
    max-width: 1600px;
    border-radius: 12px;
    border: 1px solid #444;
    display: flex;
    flex-direction: column;
    box-shadow: 0 0 50px rgba(0, 0, 0, 0.8);
}

.modal-header {
    padding: 20px 30px;
    border-bottom: 1px solid #333;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: #202024;
    border-radius: 12px 12px 0 0;
    flex-shrink: 0;
}

.modal-header h2 {
    margin: 0;
    color: #fff;
    font-size: 24px;
    letter-spacing: 1px;
}

.modal-close {
    background: transparent;
    border: none;
    color: #888;
    font-size: 32px;
    cursor: pointer;
    line-height: 1;
}

.modal-close:hover {
    color: #fff;
}

.modal-body-split {
    flex: 1;
    display: flex;
    overflow: hidden;
}

/* Modal Grid */
.modal-grid-scroll {
    flex: 1;
    overflow-y: auto;
    padding: 30px;
    background: #111;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    grid-auto-rows: 180px;
    gap: 20px;
    align-content: start;
}

.modal-asset {
    width: 100%;
    height: 100%;
    background: #1a1a1a;
    border: 3px solid #333;
    border-radius: 12px;
    cursor: pointer;
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
    transition: all 0.1s ease-out;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.3);
}

.modal-asset img,
.modal-asset video {
    max-width: 85%;
    max-height: 85%;
    object-fit: contain;
    pointer-events: none;
    z-index: 1;
}

.modal-asset:hover {
    border-color: #666;
    transform: translateY(-3px);
    background: #252525;
}

.modal-asset.selected {
    border-color: #00f2ff;
    background: rgba(0, 242, 255, 0.05);
    box-shadow: 0 0 20px rgba(0, 242, 255, 0.3);
}

.modal-asset .id-badge {
    position: absolute;
    top: 8px;
    right: 8px;
    font-size: 12px;
    font-weight: bold;
    color: #fff;
    background: rgba(0, 0, 0, 0.8);
    padding: 2px 6px;
    border-radius: 4px;
    z-index: 2;
    border: 1px solid #555;
}

/* ── "Уже был" — memes this donator already put into a code before ──────────
   Dimmed, not disabled: reusing a meme is allowed, this only says which ones
   are new. Hovering lifts the dimming so the preview is never muddy. */
.modal-asset .used-badge {
    display: none;
    position: absolute;
    top: 8px;
    left: 8px;
    font-size: 9px;
    font-weight: 800;
    letter-spacing: 0.04em;
    color: #ffce6b;
    background: rgba(40, 26, 0, 0.88);
    padding: 2px 6px;
    border-radius: 4px;
    z-index: 3;
    border: 1px solid rgba(255, 206, 107, 0.55);
    pointer-events: none;
}

.modal-asset.used .used-badge {
    display: block;
}

.modal-asset.used {
    border-color: #4a4326;
}

.modal-asset.used .thumb-img,
.modal-asset.used .thumb-placeholder {
    opacity: 0.38;
    filter: grayscale(0.7);
    transition: opacity 0.12s ease-out, filter 0.12s ease-out;
}

.modal-asset.used:hover .thumb-img,
.modal-asset.used:hover .thumb-placeholder,
.modal-asset.used.selected .thumb-img,
.modal-asset.used.selected .thumb-placeholder {
    opacity: 1;
    filter: none;
}

/* Modal Sidebar */
.modal-sidebar {
    width: 420px;
    background: #202024;
    padding: 30px;
    border-left: 1px solid #333;
    display: flex;
    flex-direction: column;
    gap: 20px;
    flex-shrink: 0;
    overflow-y: auto;
}

.preview-box {
    width: 100%;
    aspect-ratio: 1;
    background: #050505;
    border: 2px solid #444;
    border-radius: 12px;
    display: flex;
    justify-content: center;
    align-items: center;
    box-shadow: inset 0 0 20px rgba(0, 0, 0, 0.5);
    overflow: hidden;
    position: relative;
}

#fish-preview-container {
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: transform 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

#fish-preview-img {
    max-width: 200px;
    filter: drop-shadow(4px 4px 0px rgba(0, 0, 0, 0.5));
}

.preview-name-label {
    position: absolute;
    bottom: 120%;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.7);
    color: white;
    padding: 4px 10px;
    border-radius: 4px;
    font-size: 14px;
    white-space: nowrap;
    border: 1px solid #555;
}

.stats-row {
    display: flex;
    justify-content: space-between;
    background: #333;
    padding: 10px 15px;
    border-radius: 6px;
    font-size: 13px;
    color: #ccc;
    font-weight: bold;
    margin-top: -10px;
    border: 1px solid #444;
}

.video-preview-wrapper {
    width: 100%;
    aspect-ratio: 16/9;
    background: #000;
    border: 2px solid #444;
    border-radius: 12px;
    position: relative;
    overflow: hidden;
    display: flex;
    justify-content: center;
    align-items: center;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.5);
}

#meme-preview-player {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

#green-preview-player {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.video-overlay-text {
    position: absolute;
    color: #666;
    pointer-events: none;
    font-size: 16px;
}

/* Form Controls */
.control-group label {
    display: block;
    color: #ccc;
    margin-bottom: 8px;
    font-size: 14px;
    font-weight: bold;
}

/* Timing Selector */
.timing-selector {
    display: flex;
    flex-direction: column;
    gap: 8px;
    width: 100%;
}

.timing-option {
    position: relative;
}

.timing-option input[type="radio"] {
    position: absolute;
    opacity: 0;
    width: 0;
    height: 0;
}

.timing-card {
    display: flex;
    align-items: center;
    padding: 12px 15px;
    background: #111;
    border: 2px solid #333;
    border-radius: 8px;
    cursor: pointer;
    transition: 0.2s;
    font-size: 14px;
    color: #aaa;
}

.timing-card:hover {
    border-color: #555;
    background: #1a1a1a;
}

/* Checked State */
.timing-option input[type="radio"]:checked+.timing-card {
    border-color: #00f2ff;
    background: rgba(0, 242, 255, 0.1);
    color: #fff;
    font-weight: bold;
}

/* Note Boxes */
.note-box {
    margin-top: 15px;
    padding: 10px;
    border-radius: 4px;
    font-size: 13px;
    color: #ddd;
    text-align: left;
}

.meme-note {
    background: rgba(177, 79, 245, 0.1);
    border-left: 3px solid #b14ff5;
}

.green-note {
    background: rgba(76, 175, 80, 0.1);
    border-left: 3px solid #4CAF50;
}

.btn-confirm {
    margin-top: auto;
    padding: 20px;
    background: linear-gradient(to right, #28a745, #218838);
    color: white;
    border: none;
    border-radius: 8px;
    font-weight: 800;
    cursor: pointer;
    font-size: 18px;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.btn-confirm:disabled {
    background: #333;
    color: #555;
    cursor: not-allowed;
}

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

input[type=range]::-webkit-slider-thumb {
    -webkit-appearance: none;
    height: 20px;
    width: 20px;
    border-radius: 50%;
    background: #00f2ff;
    cursor: pointer;
    margin-top: -8px;
}

input[type=range]::-webkit-slider-runnable-track {
    width: 100%;
    height: 4px;
    cursor: pointer;
    background: #555;
    border-radius: 2px;
}

/* --- New Footer Buttons --- */
.dashboard-footer {
    margin-top: 25px;
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.footer-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    width: 100%;
}

.footer-actions .btn-copy-code,
.footer-actions .btn-send-donate {
    flex: 1 1 45%;
    min-width: 0;
}

.footer-actions .btn-secondary {
    flex: 1 1 100%;
}

.btn-send-donate {
    background: #555;
    color: #aaa;
    border: none;
    padding: 12px;
    border-radius: 8px;
    font-size: 13px;
    font-weight: bold;
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 8px;
    transition: all 0.3s ease;
    text-decoration: none;
}

.btn-send-donate:hover {
    transform: translateY(-2px);
}

.btn-secondary {
    flex: 1;
    background: #333;
    color: #fff;
    border: 1px solid #555;
    padding: 15px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: bold;
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 8px;
    transition: 0.2s;
}

.btn-secondary:hover {
    background: #444;
}

.btn-copy-code {
    background: #555;
    color: #aaa;
    border: none;
    padding: 12px;
    border-radius: 8px;
    font-size: 13px;
    font-weight: bold;
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 8px;
    transition: all 0.3s ease;
}

.btn-copy-code:hover {
    transform: translateY(-2px);
}

/* --- State Classes for Button Toggling --- */
.active-green {
    background: #00ff88 !important;
    color: #000 !important;
    box-shadow: 0 0 15px rgba(0, 255, 136, 0.3);
}

.active-green:hover {
    background: #00e077 !important;
}

.dormant-grey {
    background: #444 !important;
    color: #888 !important;
    box-shadow: none;
}

.modal-text-content {
    padding: 20px;
    font-size: 16px;
    line-height: 1.5;
    color: #ddd;
}

.btn-icon-edit {
    background: #f39c12;
    border: none;
    color: white;
    border-radius: 4px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
}

.btn-icon-edit:hover {
    background: #e67e22;
}

/* --- Override Indicator --- */
.override-indicator {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 10px 14px;
    background: rgba(229, 57, 53, 0.12);
    border: 1px solid rgba(229, 57, 53, 0.35);
    border-radius: 8px;
    margin-top: 5px;
}

.override-thumb-wrap {
    position: relative;
    width: 60px;
    height: 36px;
    border-radius: 4px;
    overflow: hidden;
    flex-shrink: 0;
    border: 2px solid rgba(229, 57, 53, 0.6);
}

.override-thumb-wrap video {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.override-thumb-wrap::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(229, 57, 53, 0.35);
    pointer-events: none;
}

.override-x-mark {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 24px;
    color: #ff4444;
    font-weight: bold;
    text-shadow: 0 0 6px rgba(0, 0, 0, 0.8);
    z-index: 2;
    pointer-events: none;
}

.override-arrow {
    color: #888;
    font-size: 22px;
    flex-shrink: 0;
}

.override-new-label {
    font-size: 12px;
    font-weight: bold;
    color: #4CAF50;
    text-transform: uppercase;
    letter-spacing: 1px;
    flex-shrink: 0;
}

/* --- VTuber Builder Override --- */
.preview-container #vtuber-layer {
    position: absolute;
    right: 20px;
    z-index: 5000;
}

/* --- Modal Search Bar --- */
.modal-search-wrap {
    display: flex;
    align-items: center;
    gap: 8px;
    background: #111;
    border: 1px solid #444;
    border-radius: 8px;
    padding: 6px 12px;
    flex: 1;
    max-width: 280px;
    margin: 0 20px;
    transition: border-color 0.2s;
}

.modal-search-wrap:focus-within {
    border-color: #00f2ff;
}

.modal-search-wrap .material-icons {
    color: #666;
    font-size: 20px;
}

.modal-search-wrap input {
    background: transparent;
    border: none;
    color: #fff;
    font-size: 14px;
    outline: none;
    width: 100%;
    margin: 0;
    padding: 0;
}

.modal-search-wrap input::placeholder {
    color: #555;
}

/* --- Thumbnail / Lazy Grid --- */
.modal-asset .thumb-img {
    max-width: 85%;
    max-height: 85%;
    object-fit: contain;
    pointer-events: none;
    z-index: 1;
    border-radius: 4px;
}

.modal-asset .thumb-placeholder {
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
    border-radius: 8px;
    pointer-events: none;
    z-index: 1;
    position: relative;
}

.modal-asset .thumb-placeholder .placeholder-icon {
    font-size: 40px;
    color: #334;
    opacity: 0.6;
}

.modal-asset.hidden-by-search {
    display: none !important;
}

.modal-asset .hover-video {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    z-index: 3;
    border-radius: 8px;
    background: #1a1a1a;
    pointer-events: none;
}

/* Hide thumbnail when hover video is active */
.modal-asset .hover-video ~ .thumb-img,
.modal-asset .hover-video ~ .thumb-placeholder {
    visibility: hidden;
}
.modal-asset:has(.hover-video) .thumb-img,
.modal-asset:has(.hover-video) .thumb-placeholder {
    visibility: hidden;
}

/* Loading spinner for hover video */
.modal-asset.loading-video::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 24px;
    height: 24px;
    margin: -12px 0 0 -12px;
    border: 3px solid rgba(0, 242, 255, 0.2);
    border-top-color: #00f2ff;
    border-radius: 50%;
    animation: spin-thumb 0.6s linear infinite;
    z-index: 4;
}

@keyframes spin-thumb {
    to { transform: rotate(360deg); }
}

/* --- Mobile Responsiveness --- */
@media screen and (max-width: 900px) {
    body {
        flex-direction: column;
        overflow-y: auto;
    }

    .preview-section {
        flex: none;
        width: 100vw;
        height: 56vw;
        /* 16:9 aspect ratio */
        min-height: 250px;
    }

    .designer-section {
        width: 100vw;
        border-left: none;
        border-top: 2px solid #333;
        flex: 1;
        overflow-y: visible;
    }

    .dashboard-content {
        overflow-y: visible;
    }

    .modal-window {
        width: 100vw;
        height: 100%;
        max-height: 100%;
        border-radius: 0;
    }

    .modal-body-split {
        flex-direction: column;
        overflow: hidden;
    }

    .modal-grid-scroll {
        flex: 1;
        min-height: 0;
        overflow-y: auto;
        padding: 15px;
    }

    .modal-sidebar,
    .wide-sidebar {
        width: 100%;
        flex: 0 0 auto;
        overflow-y: visible;
        border-left: none;
        border-top: 2px solid #00f2ff;
        padding: 15px;
        gap: 8px;
    }

    .note-box {
        margin-top: 0;
    }

    .btn-confirm {
        margin-top: 5px !important;
    }

    .video-preview-wrapper {
        display: none !important;
    }

    .mobile-hide {
        display: none !important;
    }

    .timing-selector {
        flex-direction: row;
    }

    .timing-option {
        flex: 1;
    }

    .timing-card {
        justify-content: center;
        text-align: center;
        padding: 10px 5px;
        font-size: 11px;
    }
}
