/* --- THEME --- */
:root { 
    --primary: #000000; 
    --secondary: #1a1a1a;
    --accent: #ffffff; 
    --red-accent: #ff3333; 
    --bg: #000000; 
    --text: #e0e0e0;
    --panel-bg: rgba(20, 20, 20, 0.95);
    --border: #444444;
    --shadow: 0 8px 32px rgba(0,0,0,0.8);
    --select-color: #0a84ff;
}

* { 
    box-sizing: border-box; 
    -webkit-tap-highlight-color: transparent; 
    user-select: none; 
}

body { 
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; 
    margin: 0; 
    height: 100vh; 
    background: var(--bg); 
    color: var(--text); 
    overflow: hidden; 
    overscroll-behavior: none;
}

/* --- BANNER AD STYLES --- */
.banner-ad {
    position: fixed;
    left: 50%;
    transform: translateX(-50%);
    width: 90%;
    max-width: 728px;
    background: rgba(20, 20, 20, 0.98);
    border: 1px solid #444;
    border-radius: 12px;
    padding: 10px 15px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(10px);
    z-index: 95;
    display: none;
    animation: slideIn 0.3s ease-out;
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateX(-50%) translateY(-20px);
    }
    to {
        opacity: 1;
        transform: translateX(-50%) translateY(0);
    }
}

.banner-ad.show {
    display: block;
}

.top-banner {
    top: 80px;
}

.bottom-banner {
    bottom: 90px;
}

.banner-ad-label {
    font-size: 8px;
    color: #666;
    text-transform: uppercase;
    letter-spacing: 1px;
    text-align: center;
    margin-bottom: 8px;
}

.banner-close-btn {
    position: absolute;
    top: 5px;
    right: 5px;
    background: rgba(255, 255, 255, 0.1);
    border: none;
    border-radius: 50%;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: #888;
    transition: all 0.2s;
    z-index: 10;
}

.banner-close-btn:hover {
    background: rgba(255, 255, 255, 0.2);
    color: #fff;
}

.banner-close-btn:active {
    transform: scale(0.9);
}

.banner-close-btn .material-symbols-outlined {
    font-size: 18px;
}

@media (max-width: 600px) {
    .banner-ad {
        width: 95%;
        max-width: none;
        padding: 8px 12px;
        border-radius: 10px;
    }
    
    .top-banner {
        top: 65px;
    }
    
    .bottom-banner {
        bottom: 75px;
    }
    
    .banner-close-btn {
        width: 22px;
        height: 22px;
    }
    
    .banner-close-btn .material-symbols-outlined {
        font-size: 16px;
    }
}

/* --- ICONS --- */
.material-symbols-outlined {
    font-size: 24px; 
    font-variation-settings: 'FILL' 0, 'wght' 400, 'GRAD' 0, 'opsz' 24;
    pointer-events: none; 
}

.pill-btn .material-symbols-outlined { font-size: 20px; margin-right: 6px; }
.icon-btn .material-symbols-outlined { font-size: 22px; }
.zoom-btn .material-symbols-outlined { font-size: 20px; }

/* --- FLOATING PILLS --- */
.float-pill {
    position: fixed;
    z-index: 100;
    display: flex;
    align-items: center;
    background: var(--panel-bg);
    border: 1px solid var(--border);
    border-radius: 50px; 
    padding: 5px;
    box-shadow: var(--shadow);
    backdrop-filter: blur(8px);
    gap: 5px;
    transition: all 0.2s ease;
}

/* --- BUTTONS --- */
.icon-btn {
    background: transparent; border: none; color: var(--text);
    width: 40px; height: 40px; border-radius: 50%; 
    cursor: pointer; display: flex; align-items: center; justify-content: center;
    transition: 0.2s ease;
    flex-shrink: 0;
    padding: 0;
}
.icon-btn:hover { background: rgba(255,255,255,0.1); }
.icon-btn:active { transform: scale(0.95); }
.icon-btn.active { background: var(--accent); color: black; }
.icon-btn.lock-btn.active { background: var(--red-accent); color: white; }
.icon-btn:disabled { opacity: 0.3; cursor: default; }

.zoom-btn { width: 36px; height: 36px; }

.pill-btn {
    background: transparent; border: none; color: #888; 
    padding: 0 16px; border-radius: 25px; cursor: pointer; 
    font-weight: 600; font-size: 0.85rem;
    display: flex; align-items: center; justify-content: center;
    transition: all 0.2s ease;
    height: 40px;
    min-width: 70px;
}
.pill-btn:hover { background: rgba(255,255,255,0.1); color: var(--text); }
.pill-btn:active { transform: scale(0.96); }
.pill-btn.active { background: var(--accent); color: black; }
.pill-btn.active .material-symbols-outlined { color: black; }

.sep { width: 1px; height: 20px; background: #444; margin: 0 2px; }

/* --- LOCATIONS & SPACING --- */
#ui-menu { top: 20px; left: 20px; }

#ui-mode { 
    top: 20px; left: 50%; transform: translateX(-50%); 
    padding: 4px; gap: 0;
}

#ui-history { 
    top: 20px; right: 20px; 
    display: none; 
    gap: 2px;
}

#ui-tools { 
    top: 90px; right: 20px; 
    display: none; 
    flex-direction: row;
    transition: width 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    overflow: hidden;
    padding: 5px; 
}

#ui-text-props {
    position: fixed; 
    top: 160px; right: 20px; 
    width: 220px;
    background: var(--panel-bg);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 15px;
    box-shadow: var(--shadow);
    display: none; 
    flex-direction: column;
    gap: 12px;
    z-index: 90;
}

#ui-zoom { bottom: 30px; left: 50%; transform: translateX(-50%); padding: 4px 8px; gap: 4px; }
#zoom-disp { font-family: monospace; font-size: 0.9rem; color: #aaa; width: 45px; text-align: center; }

#tools-toggle { 
    display: none; 
    width: 28px; height: 28px; 
    border-radius: 50%;
    background: #333;
    color: white; 
    align-items: center; justify-content: center;
    cursor: pointer; 
    margin-right: 5px;
    transition: transform 0.3s;
}
#tools-toggle .material-symbols-outlined { font-size: 18px; }

.label-text { display: inline; margin-left: 5px; }

@media (max-width: 600px) {
    .float-pill { padding: 4px; gap: 2px; }
    .icon-btn { width: 36px; height: 36px; }
    .zoom-btn { width: 34px; height: 34px; }
    .pill-btn { height: 36px; padding: 0; min-width: 44px; border-radius: 18px; } 
    .pill-btn .material-symbols-outlined { margin-right: 0; font-size: 22px; }
    .label-text { display: none; }
    
    .sep { height: 16px; margin: 0 2px; }

    #ui-menu { top: 15px; left: 15px; }
    #ui-mode { top: 15px; width: auto; gap: 4px; padding: 3px; }
    #ui-history { top: 15px; right: 15px; }
    
    #ui-tools { top: 75px; right: 15px; }
    #tools-toggle { display: flex; width: 26px; height: 26px; }
    
    #ui-tools.minimized { width: 36px; padding: 4px; background: rgba(20,20,20,0.6); }
    #ui-tools.minimized .icon-btn, #ui-tools.minimized .sep { display: none; }
    #ui-tools.minimized #tools-toggle { margin-right: 0; transform: rotate(180deg); background: var(--accent); color: black; }

    #ui-text-props { top: 130px; right: 15px; width: 180px; padding: 10px; }
    .prop-label { font-size: 0.65rem; }
    input[type=range] { height: 3px; }
    
    #ui-zoom { bottom: 25px; padding: 4px 6px; width: auto; justify-content: space-between; max-width: 300px; }
}

/* --- TEXT PROPERTIES WIDGETS --- */
.prop-section { display: flex; flex-direction: column; gap: 8px; }
.prop-label { font-size: 0.7rem; color: #888; font-weight: 700; text-transform: uppercase; letter-spacing: 0.5px; }
.prop-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }

select { 
    background: #333; color: white; border: 1px solid #555; 
    padding: 6px; border-radius: 6px; width: 100%; font-size: 0.85rem; outline: none;
}

.style-grp { display: flex; background: #333; border-radius: 8px; overflow: hidden; width: 100%; border: 1px solid #555; }
.style-grp button { 
    flex: 1; background: transparent; border: none; color: #ccc; 
    padding: 8px 0; cursor: pointer; border-right: 1px solid #555;
    transition: 0.2s;
    display:flex; align-items:center; justify-content:center;
}
.style-grp button:last-child { border-right: none; }
.style-grp button:hover { background: rgba(255,255,255,0.1); }
.style-grp button.active { background: var(--accent); color: black; }
.style-grp .material-symbols-outlined { font-size: 18px; }

.color-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; }
.swatch { 
    width: 28px; height: 28px; border-radius: 50%; border: 2px solid #333; cursor: pointer; 
    transition: transform 0.2s;
}
.swatch:hover { transform: scale(1.1); }
.swatch.active { border-color: white; transform: scale(1.15); box-shadow: 0 0 8px rgba(255,255,255,0.3); }

input[type=range] { flex: 1; accent-color: var(--red-accent); cursor: pointer; height: 4px; border-radius: 2px; }
.slider-val { font-size: 0.8rem; color: #ccc; width: 30px; text-align: right; font-family: monospace; }

/* --- SETTINGS MODAL --- */
#modal-overlay {
    display: none; position: fixed; top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.8); z-index: 300; backdrop-filter: blur(5px);
    align-items: center; justify-content: center;
}
#modal-overlay.active { display: flex; }
.modal-box {
    background: var(--secondary); border: 1px solid var(--border);
    border-radius: 20px; padding: 25px; width: 90%; max-width: 320px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.8);
}
.modal-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; border-bottom: 1px solid #333; padding-bottom: 10px; }
.modal-header h3 { margin: 0; color: var(--accent); }
.close-modal-btn { background: none; border: none; color: #888; font-size: 1.5rem; cursor: pointer; display:flex; align-items:center;}

/* --- CUSTOM DIALOGS --- */
#dialog-overlay {
    display: none; position: fixed; top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.85); z-index: 400; backdrop-filter: blur(8px);
    align-items: center; justify-content: center;
}
#dialog-overlay.active { display: flex; }
.dialog-box {
    background: var(--secondary); border: 1px solid var(--border);
    border-radius: 20px; padding: 25px; width: 90%; max-width: 360px;
    box-shadow: 0 10px 40px rgba(0,0,0,0.9);
    animation: dialogSlideIn 0.2s ease-out;
}
@keyframes dialogSlideIn {
    from { transform: translateY(-20px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}
.dialog-title {
    font-size: 1.1rem; font-weight: 600; color: var(--accent); 
    margin-bottom: 15px; display: flex; align-items: center; gap: 10px;
}
.dialog-message {
    color: #ccc; font-size: 0.95rem; line-height: 1.5; margin-bottom: 20px;
}
.dialog-input {
    width: 100%; padding: 12px; background: #111; border: 1px solid #444;
    border-radius: 10px; color: var(--text); font-size: 0.95rem;
    margin-bottom: 20px; outline: none; font-family: inherit;
}
.dialog-input:focus { border-color: var(--accent); }
.dialog-buttons {
    display: flex; gap: 10px; justify-content: flex-end;
}
.dialog-btn {
    padding: 10px 20px; border-radius: 12px; border: none;
    font-weight: 600; font-size: 0.9rem; cursor: pointer;
    transition: all 0.2s; min-width: 80px;
}
.dialog-btn-primary {
    background: var(--accent); color: #000;
}
.dialog-btn-primary:hover { transform: scale(1.05); }
.dialog-btn-primary:active { transform: scale(0.98); }
.dialog-btn-secondary {
    background: #333; color: #ccc; border: 1px solid #555;
}
.dialog-btn-secondary:hover { background: #444; }
.dialog-btn-danger {
    background: var(--red-accent); color: white;
}
.dialog-btn-danger:hover { transform: scale(1.05); }
.dialog-btn-danger:active { transform: scale(0.98); }

/* --- LIVE TEXTAREA --- */
.live-textarea {
    position: absolute;
    background: rgba(0,0,0,0.8); 
    border: 1px solid rgba(255,255,255,0.2);
    border-radius: 12px; 
    padding: 4px; margin: 0;
    outline: none; overflow: hidden; resize: none;
    line-height: 1.2;
    z-index: 50; white-space: pre; 
    user-select: text;
    box-shadow: 0 4px 15px rgba(0,0,0,0.5);
    min-width: 30px;
    min-height: 30px;
}

/* --- SIDEBAR --- */
#sidebar { 
    position: fixed; top: 0; left: 0; height: 100%; width: 280px;
    background: var(--primary); border-right: 1px solid var(--border);
    display: flex; flex-direction: column; padding: 20px;
    transform: translateX(-100%); transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 200; box-shadow: 5px 0 20px rgba(0,0,0,0.5);
}
#sidebar.open { transform: translateX(0); }
#sidebar-overlay {
    display: none; position: fixed; top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.6); backdrop-filter: blur(3px); z-index: 150;
}
#sidebar-overlay.active { display: block; }

h2 { 
    margin: 0 0 20px 0; 
    border-bottom: 1px solid var(--border); 
    padding-bottom: 15px; 
    display: flex; 
    justify-content: space-between; 
    align-items: center; 
}

.logo-container {
    font-family: 'Futura', 'Trebuchet MS', 'Century Gothic', sans-serif;
    font-weight: bold;
    font-size: 28px;
    color: white;
    letter-spacing: -1px;
    display: flex;
    align-items: center;
}
.logo-dot { color: var(--red-accent); }

.close-sidebar-btn { background: none; border: none; color: var(--accent); font-size: 1.8rem; cursor: pointer; display:flex; align-items:center; }

.btn { 
    display: flex; align-items: center; justify-content: center; gap: 8px;
    width: 100%; padding: 12px; margin-bottom: 8px; 
    border: 1px solid var(--border); 
    border-radius: 30px; 
    cursor: pointer; font-weight: 600; text-align: center; color: var(--text); 
    font-size: 13px; background: #333; 
}
.btn .material-symbols-outlined { font-size: 18px; }
.btn:hover { background: #444; }
input[type="file"] { display: none; }

/* --- GALLERY & GROUPING --- */
#gallery-list { flex: 1; overflow-y: auto; margin-top: 15px; margin-bottom: 60px; }

details { margin-bottom: 4px; margin-left: 10px; border-left: 1px solid #333; }
#gallery-list > details { margin-left: 0; border-left: none; }

summary { 
    cursor: pointer; font-weight: bold; color: #888; font-size: 0.8rem; 
    padding: 8px 5px; list-style: none; text-transform: uppercase;
    display: flex; align-items: center; justify-content: space-between;
}
summary::-webkit-details-marker { display: none; }
summary::after { content: 'expand_more'; font-family: 'Material Symbols Outlined'; font-size: 1.2rem; transition: transform 0.2s; }
details[open] > summary::after { transform: rotate(180deg); }

.gallery-item { 
    padding: 8px 10px; margin-bottom: 4px; 
    border-radius: 12px;
    cursor: pointer; display: flex; align-items: center; justify-content: space-between; 
    background: #111; border: 1px solid #333; margin-left: 8px;
    transition: background 0.2s, border-color 0.2s;
    position: relative;
}
.gallery-item.active { background: #222; border-color: var(--accent); }
.gallery-item img { width: 30px; height: 30px; object-fit: cover; border-radius: 8px; margin-right: 10px; background: #000; }
.gallery-item span { font-size: 0.85rem; color: #ccc; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.rename-btn { background: none; border: none; color: #666; cursor: pointer; font-size: 1rem; padding: 0 5px; display:flex; align-items:center;}
.rename-btn:hover { color: var(--accent); }
.rename-btn .material-symbols-outlined { font-size: 16px; }

/* --- SELECTION UI --- */
.select-indicator {
    width: 20px; height: 20px; border-radius: 50%;
    border: 2px solid #555; background: rgba(0,0,0,0.5);
    display: flex; align-items: center; justify-content: center;
    margin-right: 10px; transition: all 0.2s;
    flex-shrink: 0;
}
.selected .select-indicator {
    background: var(--select-color); border-color: var(--select-color);
}
.selected .select-indicator::after {
    content: 'check'; font-family: 'Material Symbols Outlined'; font-size: 14px; color: white;
}
.gallery-item.selected { background: #15202b; border-color: var(--select-color); }

#selection-bar {
    position: absolute; 
    bottom: calc(20px + env(safe-area-inset-bottom)); 
    left: 50%; transform: translateX(-50%) translateY(150%);
    width: 90%; max-width: 260px;
    background: rgba(30, 30, 30, 0.98);
    border: 1px solid #555; border-radius: 20px;
    box-shadow: 0 10px 40px rgba(0,0,0,0.9);
    backdrop-filter: blur(10px);
    display: flex; flex-direction: column;
    padding: 8px; gap: 8px;
    transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    z-index: 250;
}
#selection-bar.active { transform: translateX(-50%) translateY(0); }

.sel-header { 
    display: flex; justify-content: space-between; align-items: center; 
    padding: 5px 10px; border-bottom: 1px solid #444; font-size: 0.75rem; color: #888; font-weight: bold; text-transform: uppercase;
}
.sel-btn-row { display: flex; justify-content: space-between; gap: 4px; }
.sel-icon-btn {
    background: #252525; border: 1px solid #333; color: #ccc;
    width: 42px; height: 42px; border-radius: 12px;
    display: flex; align-items: center; justify-content: center;
    cursor: pointer; flex: 1;
    touch-action: manipulation;
}
.sel-icon-btn:active { transform: scale(0.95); background: #333; }
.sel-icon-btn.delete { color: #ff5555; border-color: #552222; }
.sel-icon-btn.delete:active { background: rgba(255,50,50,0.2); }
.sel-icon-btn span { font-size: 20px; }

#select-count { color: var(--select-color); }

/* --- MAIN CANVAS AREA --- */
#main { position: relative; width: 100vw; height: 100vh; overflow: hidden; background: #000; display: flex; align-items: center; justify-content: center; }
#content-wrapper { transform-origin: center center; box-shadow: 0 0 50px rgba(0,0,0,0.5); transition: transform 0.05s linear; position: relative; } 
canvas { display: block; background: #111; touch-action: none; }

#status-msg { position: fixed; bottom: 90px; left: 50%; transform: translateX(-50%); background: var(--accent); color: #000; padding: 8px 16px; border-radius: 20px; font-size: 12px; font-weight: bold; opacity: 0; transition: opacity 0.5s; pointer-events: none; z-index: 100; }
#empty-state { text-align: center; color: #444; pointer-events: none; }
#version-tag { margin-top: 0; padding-top: 10px; border-top: 1px solid var(--border); text-align: center; color: #555; font-size: 0.75rem; font-family: monospace; }
#btn-settings { margin-top: auto; margin-bottom: 15px; }

.default-mark { 
    position: absolute; 
    top: 50px; 
    color: #666; 
    font-size: 10px; 
    pointer-events: none;
    line-height: 1;
}
.default-mark .material-symbols-outlined {
    display: block;
    margin: 0;
    padding: 0;
}
.default-mark-zoom { 
    left: 48.28%;
    transform: translateX(-50%);
}
.default-mark-opacity { 
    left: 100%;
    transform: translateX(-50%);
}

/* --- UPDATE NOTIFICATION --- */
#update-banner {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    background: var(--red-accent);
    color: white;
    padding: 12px 20px;
    text-align: center;
    font-weight: 600;
    z-index: 500;
    display: none;
    align-items: center;
    justify-content: center;
    gap: 15px;
}
#update-banner.show { display: flex; }
#update-banner button {
    background: white;
    color: var(--red-accent);
    border: none;
    padding: 8px 20px;
    border-radius: 20px;
    font-weight: 700;
    cursor: pointer;
}
#update-banner button:hover { transform: scale(1.05); }

/* --- BANNER ADS --- */
.banner-ad {
    position: fixed;
    left: 0;
    right: 0;
    background: rgba(0, 0, 0, 0.95);
    border: 1px solid var(--border);
    padding: 8px;
    z-index: 95;
    display: none;
    flex-direction: column;
    align-items: center;
    box-shadow: 0 4px 20px rgba(0,0,0,0.8);
    transition: transform 0.3s ease;
}

.banner-ad.top-banner {
    top: 80px;
    border-top: none;
    border-bottom: 1px solid var(--border);
}

.banner-ad.bottom-banner {
    bottom: 90px;
    border-bottom: none;
    border-top: 1px solid var(--border);
}

.banner-ad.visible {
    display: flex;
}

.banner-close-btn {
    position: absolute;
    top: 4px;
    right: 4px;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: #ccc;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    z-index: 10;
}

.banner-close-btn:hover {
    background: rgba(255, 255, 255, 0.2);
    color: white;
}

.banner-close-btn .material-symbols-outlined {
    font-size: 16px;
}

.banner-ad-label {
    font-size: 8px;
    color: #666;
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 4px;
}

.banner-ad .adsbygoogle {
    width: 100%;
    max-width: 728px;
    min-height: 90px;
}

/* Mobile: Only show one banner at a time */
@media (max-width: 600px) {
    .banner-ad.top-banner {
        top: 70px;
    }
    
    .banner-ad.bottom-banner {
        bottom: 80px;
    }
    
    .banner-ad .adsbygoogle {
        max-width: 100%;
        min-height: 50px;
    }
}
