:root {
    --bg-dark: #0a0a0c;
    --surface-color: rgba(20, 20, 24, 0.15); 
    --border-color: rgba(255, 255, 255, 0.05);
    --text-primary: #ededed;
    --text-secondary: #a0a0a5;
    --ui-accent: #6366f1;
    --ui-accent-glow: rgba(99, 102, 241, 0.4);
}

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

body, html {
    width: 100%; 
    height: 100%;
    background-color: var(--bg-dark);
    font-family: 'Inter', sans-serif;
    color: var(--text-primary);
    overflow: hidden; 
    user-select: none;
    /* Запрет системных жестов обновления страницы (pull-to-refresh) на телефонах */
    overscroll-behavior: none; 
}

/* ==========================================
   Netlify внедряет свой бейдж в iframe с гигантским z-index —
   он перекрывает кнопку админа. Прячем полностью.
   (Отключить навсегда можно в Netlify: Project configuration →
   General → Powered by Netlify badge.)
   ========================================== */
#nl-badge-frame,
iframe[src*="netlify"] {
    display: none !important;
    visibility: hidden !important;
    pointer-events: none !important;
}

#viewport {
    width: 100vw; 
    height: 100vh;
    position: relative; 
    overflow: hidden;
    cursor: default;
    touch-action: none; /* Критично для кастомного тач-скролла на телефонах */
}

#viewport.panning { 
    cursor: grab; 
}

#viewport.panning:active { 
    cursor: grabbing; 
}

#wall {
    width: 100vw; 
    height: 100vh;
    position: absolute; 
    top: 0; 
    left: 0;
    transform-origin: 0 0;
    background-image: radial-gradient(rgba(255, 255, 255, 0.08) 1px, transparent 1px);
    background-size: 40px 40px; 
    /* Появляется только после автоподгонки масштаба под все карточки */
    opacity: 0;
    transition: opacity 0.3s ease;
}

body.view-ready #wall {
    opacity: 1;
}

.click-marker {
    position: absolute; 
    width: 12px; 
    height: 12px;
    background: var(--ui-accent); 
    border-radius: 50%;
    box-shadow: 0 0 15px var(--ui-accent-glow);
    transform: translate(-50%, -50%); 
    pointer-events: none; 
    z-index: 99999;
}

.wall-item {
    position: absolute;
    --post-scale: 1; 
    /* max-content: ширина зависит только от содержимого, а не от того,
       насколько далеко карточка стоит от левого края холста.
       Без этого абсолютно позиционированный блок у правого края сжимался,
       а при движении влево распирал — карточка «меняла размер» при драге. */
    width: max-content;
    background: var(--surface-color);
    backdrop-filter: blur(8px);
    padding: calc(16px * var(--post-scale));
    border-radius: calc(10px * var(--post-scale));
    border: 1px solid var(--border-color);
    border-top: calc(2px * var(--post-scale)) solid var(--accent); 
    max-width: calc(280px * var(--post-scale));
    word-wrap: break-word; 
    cursor: pointer;
    display: flex; 
    flex-direction: column; 
    gap: calc(12px * var(--post-scale));
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
    transition: box-shadow 0.3s ease, border 0.3s ease;
    touch-action: none;
}

.wall-item:hover { 
    box-shadow: 0 8px 32px var(--accent-glow); 
}

.wall-item.dragging { 
    cursor: grabbing; 
    box-shadow: 0 12px 40px var(--accent-glow); 
    z-index: 1000 !important; 
}

/* Чужая карточка: двигать/редактировать нельзя */
.wall-item.not-owned {
    cursor: default;
}

.wall-item.not-owned:hover {
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
}

.wall-item.style-transparent {
    background: transparent; 
    backdrop-filter: none;
    border: 1px solid transparent; 
    border-top: 1px solid transparent;
    box-shadow: none !important; 
    padding: calc(8px * var(--post-scale));
}

.wall-item.style-transparent:hover { 
    border: 1px dashed var(--accent); 
    background: rgba(255, 255, 255, 0.02); 
}

.wall-item.style-transparent.dragging { 
    border: 1px dashed var(--accent); 
    box-shadow: 0 12px 40px var(--accent-glow) !important; 
}

.wall-item img { 
    max-width: 100%; 
    border-radius: calc(6px * var(--post-scale)); 
    pointer-events: none; 
}

.wall-item p { 
    font-size: calc(15px * var(--post-scale)); 
    line-height: 1.4; 
    margin: 0; 
    pointer-events: none; 
}

/* Подпись автора: микро-лейбл в правом нижнем углу карточки */
.post-author {
    align-self: flex-end;
    max-width: 100%;
    margin-top: calc(-6px * var(--post-scale));
    font-size: calc(10px * var(--post-scale));
    letter-spacing: 0.04em;
    color: var(--text-secondary);
    opacity: 0.8;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    pointer-events: none;
    user-select: none;
}

.wall-item.style-transparent .post-author {
    opacity: 0.6;
}

.delete-btn {
    position: absolute; 
    top: -10px; 
    right: -10px; 
    background: #ef4444; 
    color: white;
    border: none; 
    width: 24px; 
    height: 24px; 
    border-radius: 50%; 
    cursor: pointer;
    font-size: 14px; 
    font-weight: bold; 
    display: none; 
    align-items: center; 
    justify-content: center;
    box-shadow: 0 4px 10px rgba(239, 68, 68, 0.4); 
    z-index: 10;
}

.delete-btn:hover { 
    background: #dc2626; 
    transform: scale(1.1); 
}

body.admin-mode .delete-btn { 
    display: flex; 
}

#adminToggle {
    position: fixed; 
    bottom: 20px; 
    left: 20px; 
    background: rgba(255,255,255,0.1);
    padding: 10px; 
    border-radius: 50%; 
    cursor: pointer; 
    opacity: 0.3; 
    transition: 0.3s; 
    z-index: 2147483647;
    user-select: none;
}

#adminToggle:hover { 
    opacity: 1; 
}

body.admin-mode #adminToggle { 
    opacity: 1; 
    background: var(--ui-accent); 
}

.modal-backdrop {
    position: fixed; 
    inset: 0; 
    background: rgba(0, 0, 0, 0.6); 
    backdrop-filter: blur(4px);
    display: flex; 
    align-items: center; 
    justify-content: center; 
    z-index: 2000;
    opacity: 0; 
    pointer-events: none; 
    transition: 0.2s;
}

.modal-backdrop.active { 
    opacity: 1; 
    pointer-events: all; 
}

.modal {
    background: rgba(15, 15, 18, 0.95); 
    padding: 24px; 
    border: 1px solid var(--border-color);
    border-radius: 16px; 
    width: 360px; 
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.8);
    display: flex; 
    flex-direction: column; 
    gap: 16px; 
    transform: scale(0.95); 
    transition: 0.2s;
}

.modal-backdrop.active .modal { 
    transform: scale(1); 
}

.modal h2 { 
    font-size: 16px; 
    font-weight: 500; 
    color: var(--text-primary); 
    margin: 0;
}

.text-settings { 
    display: flex; 
    gap: 8px; 
    align-items: center; 
}

select {
    flex: 1; 
    background: rgba(0, 0, 0, 0.2); 
    border: 1px solid var(--border-color);
    color: var(--text-primary); 
    padding: 8px; 
    border-radius: 8px; 
    outline: none; 
    font-size: 13px;
}

input[type="color"] {
    -webkit-appearance: none; 
    border: none; 
    width: 34px; 
    height: 34px;
    border-radius: 50%; 
    cursor: pointer; 
    background: transparent; 
    padding: 0; 
    outline: none; 
    flex-shrink: 0;
}

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

input[type="color"]::-webkit-color-swatch { 
    border: 2px solid var(--border-color); 
    border-radius: 50%; 
}

textarea {
    background: rgba(0, 0, 0, 0.2); 
    border: 1px solid var(--border-color);
    padding: 12px; 
    color: var(--text-primary); 
    font-family: inherit; 
    font-size: 14px;
    border-radius: 8px; 
    outline: none; 
    resize: none; 
    min-height: 80px; 
    transition: 0.3s;
}

textarea:focus { 
    border-color: var(--ui-accent); 
}

textarea.preview-transparent { 
    background: transparent; 
    border: 1px dashed var(--border-color); 
}

.custom-file-upload {
    display: block; 
    padding: 12px; 
    background: rgba(255, 255, 255, 0.03);
    border: 1px dashed var(--border-color); 
    border-radius: 8px; 
    text-align: center;
    font-size: 13px; 
    color: var(--text-secondary); 
    cursor: pointer; 
    transition: 0.2s;
}

.custom-file-upload:hover { 
    border-color: var(--ui-accent); 
    color: var(--text-primary); 
}

input[type="file"] { 
    display: none; 
}

.size-control label { 
    font-size: 12px; 
    color: var(--text-secondary); 
    display: flex; 
    justify-content: space-between; 
}

/* Строка «Подпись» в модалке */
.author-control {
    display: flex;
    align-items: center;
    gap: 10px;
}

.author-control label {
    font-size: 12px;
    color: var(--text-secondary);
    white-space: nowrap;
    flex-shrink: 0;
}

.author-control input {
    flex: 1;
    min-width: 0;
    background: rgba(0, 0, 0, 0.2);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 8px 10px;
    color: var(--text-primary);
    font-family: inherit;
    font-size: 13px;
    outline: none;
    transition: 0.3s;
}

.author-control input::placeholder {
    color: rgba(255, 255, 255, 0.25);
}

.author-control input:focus {
    border-color: var(--ui-accent);
}

input[type="range"] { 
    accent-color: var(--ui-accent); 
    cursor: pointer; 
    width: 100%; 
    margin-top: 5px; 
}

#imagePreview { 
    display: none; 
    width: 100%; 
    max-height: 140px; 
    object-fit: cover; 
    border-radius: 8px; 
}

.btn-group { 
    display: flex; 
    gap: 12px; 
    margin-top: 8px; 
}

button.btn {
    flex: 1; 
    padding: 10px; 
    font-family: inherit; 
    font-size: 14px; 
    font-weight: 500;
    border-radius: 8px; 
    border: none; 
    cursor: pointer;
}

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

.btn-cancel:hover { 
    background: rgba(255, 255, 255, 0.05); 
}

.btn-add { 
    background: var(--ui-accent); 
    color: #fff; 
}

.btn-add:hover { 
    background: #4f46e5; 
}

.btn-add:disabled { 
    opacity: 0.6; 
    cursor: not-allowed; 
}

/* ================================== */
/* MOBILE OPTIMIZATION (СМАРТФОНЫ)    */
/* ================================== */
@media (max-width: 768px) {
    .modal {
        width: 92%; 
        padding: 20px;
    }
    .text-settings {
        flex-direction: column; 
        align-items: stretch;
    }
    input[type="color"] {
        align-self: center; 
        width: 44px; 
        height: 44px; /* Крупнее для пальца */
    }
    .delete-btn {
        width: 32px; 
        height: 32px; 
        font-size: 18px; /* Крупный крестик на мобилках */
        top: -15px; 
        right: -15px;
    }
}
