/* ═══════════════════════════════════════════════════════════════════════
   BNT — Özel arka plan medyası katmanı + arka plan düzenleyici menüsü
   Modüller: core/modules/bg-media.js · core/modules/bg-editor.js
   ═══════════════════════════════════════════════════════════════════════ */

/* `body::before` ile aynı z düzleminde (-1) durur; DOM sırası bizi onun
   üstüne çıkarır. Özel medya aktifken `--bnt-current-bg` zaten `none`.

   BODY ARKA PLANI ŞEFFAFLAŞTIRILMAK ZORUNDA: negatif z-index'li bir öğe kök
   yığınlama bağlamında blok arka planlarından ÖNCE boyanır, yani `body`nin
   donuk arka plan rengi (index.html'deki satır içi `#121212 !important` ve
   `--bg-base`) katmanı tamamen örtüyordu — arka plan siyah görünüyordu.
   `html.bnt-bg-custom body` seçicisi satır içi `html, body` kuralından daha
   belirgin olduğu için `!important`e `!important` ile karşılık verebiliyor. */
html.bnt-bg-custom body { background: transparent !important; }
html.bnt-bg-custom body::before { display: none; }

#bgMediaLayer {
    position: fixed; inset: 0; z-index: -1;
    overflow: hidden;
    pointer-events: none;
    background: var(--bg-base);
    opacity: 0;
    transition: opacity .35s ease;
}
#bgMediaLayer.is-on.is-visible { opacity: 1; }
#bgMediaLayer:not(.is-visible) { display: none; }

/* Canlı katman ve editör önizlemesi AYNI sınıfı paylaşır — görüntünün
   birebir aynı olması buna bağlı. */
.bg-media-el {
    position: absolute; inset: 0;
    width: 100%; height: 100%;
    object-fit: cover;
    object-position: center;
    transform-origin: 50% 50%;
    user-select: none; -webkit-user-drag: none;
}
/* will-change YALNIZCA editörde sürüklerken. Canlı arka plan katmanında kalıcı
   `will-change: transform, filter`, 4K bir öğe için tam çözünürlüklü filtre
   buffer'ını + ayrı GPU katmanını SÜREKLİ tutuyordu (yüzlerce MB RAM + boşuna
   yeniden-kompozit). Canlı arka plan statik olduğu için gereksiz. */
.bge-frame .bg-media-el { will-change: transform, filter; }

.bg-media-dim {
    position: absolute; inset: 0;
    background: #000;
    opacity: 0;
    pointer-events: none;
    transition: opacity .18s linear;
}

#bgEditorOverlay[hidden] { display: none !important; }
#bgEditorOverlay {
    position: fixed; inset: 0; z-index: 210;
    background: rgba(8, 9, 14, 0.82);
    backdrop-filter: blur(22px) saturate(1.1);
    -webkit-backdrop-filter: blur(22px) saturate(1.1);
    animation: bge-in .22s ease;
}
@keyframes bge-in { from { opacity: 0; } to { opacity: 1; } }

#bgEditorOverlay.is-dropping::after {
    content: '';
    position: absolute; inset: 14px;
    border: 2px dashed var(--accent);
    border-radius: 20px;
    pointer-events: none;
}

.bge {
    position: absolute; inset: 0;
    display: flex; flex-direction: column;
    color: #f3f3f5;
}

.bge-head {
    display: flex; align-items: center; gap: 14px;
    flex-shrink: 0;
    padding: 14px clamp(14px, 2.4vw, 30px);
    border-bottom: 1px solid rgba(255,255,255,0.08);
    background: rgba(0,0,0,0.18);
}
.bge-icon-btn {
    display: inline-flex; align-items: center; justify-content: center;
    width: 38px; height: 38px; flex-shrink: 0;
    background: rgba(255,255,255,0.07);
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 11px;
    color: inherit; cursor: pointer;
    transition: background .15s;
}
.bge-icon-btn:hover { background: rgba(255,255,255,0.16); }

.bge-head-text { flex: 1; min-width: 0; }
.bge-head-text h2 {
    margin: 0; font-size: clamp(.98rem, 1.1vw + .4rem, 1.2rem); font-weight: 700;
}
.bge-file {
    margin: 2px 0 0; font-size: .76rem; opacity: .55;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.bge-head-actions { display: flex; align-items: center; gap: 8px; flex-shrink: 0; flex-wrap: wrap; }
.bge-head-actions .action-btn[hidden] { display: none; }

.bge-body {
    flex: 1; min-height: 0;
    display: grid;
    grid-template-columns: minmax(0, 1fr) 340px;
}
.bge.is-empty .bge-body { grid-template-columns: minmax(0, 1fr); }

.bge-stage {
    min-width: 0; min-height: 0;
    display: grid; place-items: center;
    padding: clamp(14px, 2.6vw, 34px);
}

.bge-empty { width: min(560px, 100%); }
.bge-drop {
    display: flex; flex-direction: column; align-items: center; gap: 10px;
    width: 100%; padding: 46px 28px;
    background: rgba(255,255,255,0.03);
    border: 2px dashed rgba(255,255,255,0.16);
    border-radius: 20px;
    color: inherit; font: inherit; cursor: pointer; text-align: center;
    transition: border-color .18s, background .18s;
}
.bge-drop:hover { border-color: var(--accent); background: rgba(255,255,255,0.06); }
.bge-drop-icon {
    display: inline-flex; align-items: center; justify-content: center;
    width: 68px; height: 68px; margin-bottom: 4px;
    border-radius: 50%;
    background: color-mix(in srgb, var(--accent) 18%, transparent);
    color: var(--accent);
}
.bge-drop h3 { margin: 0; font-size: 1.02rem; font-weight: 700; }
.bge-drop p  { margin: 0; font-size: .84rem; opacity: .6; max-width: 40ch; line-height: 1.5; }
.bge-drop-cta {
    margin-top: 8px; padding: 10px 20px;
    background: var(--accent); color: #fff;
    border-radius: 10px; font-size: .88rem; font-weight: 600;
}
.bge-drop small { font-size: .72rem; opacity: .38; letter-spacing: .02em; }

.bge-frame-wrap {
    display: flex; flex-direction: column; align-items: center; gap: 12px;
    width: 100%; height: 100%;
    justify-content: center;
}
.bge-frame-wrap[hidden] { display: none; }

/* Ölçüsü JS'te (`syncFrameSize`) piksel olarak verilir: çerçeve pencerenin
   en-boy oranını birebir taşımak zorunda ve saf CSS'te `aspect-ratio` +
   çift yönlü sığdırma tarayıcılar arasında güvenilir çalışmıyor. */
.bge-frame {
    position: relative;
    overflow: hidden;
    border-radius: 14px;
    background: #05060a;
    border: 1px solid rgba(255,255,255,0.14);
    box-shadow: 0 24px 70px rgba(0,0,0,0.55);
    cursor: grab;
    touch-action: none;
    contain: paint;
}
.bge-frame.is-dragging { cursor: grabbing; }

/* Üçte-bir kılavuzları — yalnızca sürüklerken görünür */
.bge-guides {
    position: absolute; inset: 0; pointer-events: none;
    opacity: 0; transition: opacity .18s ease;
    background:
        linear-gradient(to right,  transparent calc(33.333% - .5px), rgba(255,255,255,.4) calc(33.333% - .5px), rgba(255,255,255,.4) calc(33.333% + .5px), transparent calc(33.333% + .5px)),
        linear-gradient(to right,  transparent calc(66.666% - .5px), rgba(255,255,255,.4) calc(66.666% - .5px), rgba(255,255,255,.4) calc(66.666% + .5px), transparent calc(66.666% + .5px)),
        linear-gradient(to bottom, transparent calc(33.333% - .5px), rgba(255,255,255,.4) calc(33.333% - .5px), rgba(255,255,255,.4) calc(33.333% + .5px), transparent calc(33.333% + .5px)),
        linear-gradient(to bottom, transparent calc(66.666% - .5px), rgba(255,255,255,.4) calc(66.666% - .5px), rgba(255,255,255,.4) calc(66.666% + .5px), transparent calc(66.666% + .5px));
}
.bge-frame.is-dragging .bge-guides { opacity: .55; }

.bge-hint {
    margin: 0; font-size: .76rem; opacity: .45; text-align: center;
}

.bge-tools {
    display: flex; flex-direction: column;
    min-height: 0;
    border-left: 1px solid rgba(255,255,255,0.08);
    background: rgba(16,17,24,0.55);
}
.bge-tools[hidden] { display: none; }

.bge-tabs {
    display: flex; flex-shrink: 0;
    padding: 10px 10px 0;
    gap: 6px;
}
.bge-tab {
    flex: 1;
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    padding: 9px 8px;
    background: transparent; border: none;
    border-radius: 10px 10px 0 0;
    color: inherit; font: inherit; font-size: .82rem; font-weight: 600;
    opacity: .55; cursor: pointer;
    transition: background .15s, opacity .15s;
}
.bge-tab[hidden] { display: none; }
.bge-tab:hover { opacity: .85; background: rgba(255,255,255,0.05); }
.bge-tab.active {
    opacity: 1;
    background: rgba(255,255,255,0.07);
    box-shadow: inset 0 -2px 0 var(--accent);
}

.bge-panels { flex: 1; min-height: 0; overflow-y: auto; padding: 16px; }
.bge-panel { display: none; flex-direction: column; gap: 16px; }
.bge-panel.active { display: flex; animation: bge-panel-in .2s ease; }
@keyframes bge-panel-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.bge-row { display: flex; flex-direction: column; gap: 7px; font-size: .82rem; }
.bge-row.is-disabled { opacity: .4; pointer-events: none; }
.bge-row-inline {
    flex-direction: row; align-items: center; justify-content: space-between;
    font-weight: 600;
}
.bge-row-head {
    display: flex; align-items: baseline; justify-content: space-between; gap: 10px;
    font-size: .82rem; font-weight: 600;
}
.bge-out { font-size: .75rem; font-weight: 600; opacity: .55; font-variant-numeric: tabular-nums; }

.bge-range {
    -webkit-appearance: none; appearance: none;
    width: 100%; height: 4px;
    background: rgba(255,255,255,0.14);
    border-radius: 999px; outline: none; cursor: pointer;
}
.bge-range::-webkit-slider-thumb {
    -webkit-appearance: none; appearance: none;
    width: 16px; height: 16px; border-radius: 50%;
    background: var(--accent);
    border: 2px solid rgba(255,255,255,0.85);
    box-shadow: 0 2px 8px rgba(0,0,0,0.4);
    cursor: pointer;
}
.bge-range::-moz-range-thumb {
    width: 14px; height: 14px; border-radius: 50%;
    background: var(--accent); border: 2px solid rgba(255,255,255,0.85);
    cursor: pointer;
}

.bge-seg {
    display: flex; gap: 4px;
    padding: 4px;
    background: rgba(0,0,0,0.3);
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 11px;
}
.bge-seg button {
    flex: 1; padding: 8px 6px;
    background: transparent; border: none; border-radius: 8px;
    color: inherit; font: inherit; font-size: .8rem; font-weight: 600;
    opacity: .6; cursor: pointer;
    transition: background .15s, opacity .15s;
}
.bge-seg button:hover { opacity: .9; background: rgba(255,255,255,0.06); }
.bge-seg button.active { opacity: 1; background: var(--accent); color: #fff; }

.bge-btn-row { display: flex; flex-wrap: wrap; gap: 6px; }
.bge-chip {
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    padding: 8px 12px;
    background: rgba(255,255,255,0.06);
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 10px;
    color: inherit; font: inherit; font-size: .78rem; font-weight: 600;
    cursor: pointer;
    transition: background .15s, border-color .15s;
}
.bge-chip:hover { background: rgba(255,255,255,0.13); }
.bge-chip.active { background: color-mix(in srgb, var(--accent) 26%, transparent); border-color: var(--accent); }
.bge-chip.wide { flex: 1; }

.bge-note {
    margin: 0; padding: 10px 12px;
    background: rgba(255,255,255,0.04);
    border-radius: 10px;
    font-size: .76rem; line-height: 1.5; opacity: .6;
}

@media (max-width: 900px), (max-height: 560px) {
    .bge-body { grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(0, 1fr) auto; }
    .bge-tools {
        border-left: none;
        border-top: 1px solid rgba(255,255,255,0.08);
        max-height: 46vh;
    }
    .bge-head-actions .action-btn { padding: 0 12px; font-size: .82rem; }
    .bge-stage { padding: 12px; }
}
@media (max-width: 560px) {
    .bge-head { flex-wrap: wrap; gap: 10px; }
    .bge-head-actions { width: 100%; }
    .bge-head-actions .action-btn { flex: 1; }
}
