:root {
    --primary-color: #2563eb;
    --primary-hover: #1d4ed8;
    --bg-color: #e2e8f0;
    --panel-bg: #f1f5f9;
    --border-color: #cbd5e1;
    --text-main: #1e293b;
    --text-muted: #64748b;
    --active-bg: #e0e7ff;
    --active-border: #93c5fd;
    --canvas-bg: #d4d8e2;
    --grid-color: rgba(0, 0, 0, 0.1);
}

:root.theme-dark {
    --primary-color: #3b82f6;
    --primary-hover: #60a5fa;
    --bg-color: #0f172a;
    --panel-bg: #1e293b;
    --border-color: #334155;
    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    --active-bg: #334155;
    --active-border: #475569;
    --canvas-bg: #020617;
    --grid-color: rgba(255, 255, 255, 0.05);
}

:root.theme-tokyo {
    --primary-color: #ff007f;
    --primary-hover: #ff4da6;
    --bg-color: #1a1b26;
    --panel-bg: #24283b;
    --border-color: #414868;
    --text-main: #c0caf5;
    --text-muted: #bb9af7;
    --active-bg: #292e42;
    --active-border: #ff007f;
    --canvas-bg: #15161e;
    --grid-color: rgba(187, 154, 247, 0.1);
}

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

body {
    font-family: 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-main);
    height: 100vh;
    overflow: hidden;
}

.ide-container {
    display: flex;
    height: 100vh;
    width: 100vw;
}

/* Scrollbars */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: var(--bg-color); }
::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: #94a3b8; }

/* --- Left Sidebar (Tools) --- */
.sidebar-tools {
    width: 70px;
    background-color: var(--panel-bg);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 15px 0;
    z-index: 10;
    transition: width 0.3s;
    overflow-y: auto;
    overflow-x: hidden;
}

@media (min-width: 1024px) {
    .sidebar-tools {
        width: 200px;
        align-items: flex-start;
        padding: 15px;
    }
}

.logo {
    font-size: 1.2rem;
    font-weight: bold;
    color: var(--primary-color);
    margin-bottom: 30px;
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    justify-content: center;
}

@media (min-width: 1024px) {
    .logo {
        justify-content: flex-start;
        font-size: 1.5rem;
    }
}

.logo span { display: none; }
@media (min-width: 1024px) {
    .logo span { display: inline; }
}

.tools-section {
    width: 100%;
    margin-bottom: 25px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
}

@media (min-width: 1024px) {
    .tools-section { align-items: flex-start; }
}

.tools-section h3 {
    font-size: 0.75rem;
    text-transform: uppercase;
    color: var(--text-muted);
    margin-bottom: 10px;
    display: none;
    padding-left: 10px;
}

@media (min-width: 1024px) {
    .tools-section h3 { display: block; }
}

button {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-main);
    font-family: inherit;
}

.tool-btn, .action-btn {
    width: 40px;
    height: 40px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
    color: var(--text-muted);
    transition: all 0.2s;
}

@media (min-width: 1024px) {
    .tool-btn, .action-btn {
        width: 100%;
        justify-content: flex-start;
        padding: 0 10px;
        gap: 12px;
    }
    .tool-btn::after {
        content: attr(title);
        font-size: 0.9rem;
    }
    .action-btn::after {
        content: attr(title);
        font-size: 0.9rem;
    }
}

.tool-btn:hover, .action-btn:hover {
    background-color: var(--bg-color);
    color: var(--primary-color);
}

.tool-btn.active {
    background-color: var(--active-bg);
    color: var(--primary-color);
    border: 1px solid var(--active-border);
}

.tool-btn:disabled, .action-btn:disabled, .primary-btn:disabled {
    opacity: 0.35;
    cursor: not-allowed;
    pointer-events: none;
}

.bottom-section { margin-top: auto; }

.primary-btn {
    background-color: var(--primary-color);
    color: white;
    padding: 10px;
    border-radius: 8px;
    font-weight: 500;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 40px;
    height: 40px;
    transition: background 0.2s;
}

.sidebar-tools .primary-btn span { display: none; }

@media (min-width: 1024px) {
    .primary-btn {
        width: 100%;
        height: auto;
        padding: 10px 15px;
    }
    .sidebar-tools .primary-btn span { display: inline; }
}

.primary-btn:hover { background-color: var(--primary-hover); color: white; }

/* --- Main Workspace --- */
.workspace {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.workspace-header {
    height: 50px;
    background-color: var(--panel-bg);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 15px;
}

.tabs {
    display: flex;
    gap: 5px;
    height: 100%;
    align-items: flex-end;
}

.tab {
    padding: 8px 16px;
    background-color: var(--bg-color);
    border: 1px solid var(--border-color);
    border-bottom: none;
    border-radius: 6px 6px 0 0;
    font-size: 0.9rem;
    cursor: pointer;
    color: var(--text-muted);
    max-width: 150px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    display: flex;
    align-items: center;
    gap: 8px;
    user-select: none;
}

.tab.dragging {
    opacity: 0.5;
    background-color: var(--active-bg);
}

.tab-name {
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
    min-width: 0;
}

.tab-rename-input {
    border: 1px solid var(--primary-color);
    border-radius: 4px;
    padding: 2px 6px;
    font-size: 0.85rem;
    font-family: inherit;
    width: 100%;
    outline: none;
    background: var(--panel-bg);
    color: var(--text-main);
}

.delete-tab {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 0.8rem;
    padding: 0;
    display: none;
}

.tab:not(.add-tab):hover .delete-tab, .tab.active:not(.add-tab) .delete-tab {
    display: block;
}

.delete-tab:hover {
    color: #ef4444;
}

.tab.active {
    background-color: var(--panel-bg);
    color: var(--primary-color);
    font-weight: 500;
    position: relative;
}

.tab.active::after {
    content: '';
    position: absolute;
    bottom: -1px;
    left: 0;
    width: 100%;
    height: 2px;
    background-color: var(--primary-color);
}

.add-tab { padding: 8px; border: none; background: transparent; }

.view-controls { display: flex; gap: 10px; }
.view-controls button { color: var(--text-muted); font-size: 1.1rem; padding: 5px; border-radius: 4px; }
.view-controls button:hover, .view-controls button.active { color: var(--primary-color); background-color: var(--active-bg); }

.canvas-container {
    flex: 1;
    background-color: var(--canvas-bg);
    overflow: auto;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 40px;
    background-image: radial-gradient(var(--grid-color) 1.5px, transparent 1.5px);
    background-size: 20px 20px;
    position: relative;
}

.workspace-watermark-layer {
    position: absolute;
    inset: 0;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-evenly;
    gap: 50px;
    padding: 20px;
    pointer-events: none;
    user-select: none;
    z-index: 0;
    overflow: hidden;
}
.watermark-item {
    text-align: center;
    color: var(--text-muted);
    opacity: 0.12;
    transform: rotate(-15deg);
}
.watermark-item .watermark-brand {
    font-size: 1.8rem;
    font-weight: 800;
    display: block;
    margin: 0;
    letter-spacing: 1px;
}
.watermark-item p {
    font-size: 0.8rem;
    margin-top: 5px;
    font-weight: 500;
}

.canvas {
    background-color: white;
    width: 375px;
    height: 812px;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    position: relative;
    overflow: hidden;
    transition: width 0.3s, height 0.3s;
    z-index: 1;
}

/* Drawn Elements */
.drawn-element {
    position: absolute;
    border: 1px solid transparent;
    cursor: grab;
    user-select: none;
    display: flex;
    align-items: center;
    justify-content: center;
    box-sizing: border-box;
}

.drawn-element:hover { outline: 1px dashed var(--primary-color); }
.drawn-element.selected { outline: 2px solid var(--primary-color); z-index: 100; }
.drawn-element.selected::after {
    content: '';
    position: absolute;
    bottom: -5px;
    right: -5px;
    width: 10px;
    height: 10px;
    background-color: var(--primary-color);
    border: 2px solid white;
    border-radius: 50%;
    cursor: nwse-resize;
}

/* Default shapes */
.shape-rectangle { background-color: #e2e8f0; border-radius: 4px; }
.shape-circle { background-color: #e2e8f0; border-radius: 50%; }
.shape-text { font-size: 16px; padding: 4px; color: #000; align-items: flex-start; justify-content: flex-start; white-space: nowrap;}
.shape-image { background-color: #cbd5e1; color: #94a3b8; }
.shape-input { border: 1px solid #cbd5e1; background-color: #ffffff; color: #94a3b8; border-radius: 4px; justify-content: flex-start; padding: 0 10px; font-size: 14px;}
.shape-button_element { background-color: var(--primary-color); color: white; border-radius: 8px; justify-content: center; font-weight: 500; font-size: 14px; }
.shape-checkbox { justify-content: flex-start; align-items: center; padding: 4px; font-size: 14px; }
.shape-radio { justify-content: flex-start; align-items: center; padding: 4px; font-size: 14px; }
.shape-switch { align-items: center; justify-content: flex-start; padding: 4px; }
.switch-ui { width: 40px; height: 20px; background-color: #cbd5e1; border-radius: 10px; position: relative; }
.switch-knob { width: 16px; height: 16px; background-color: white; border-radius: 50%; position: absolute; top: 2px; left: 2px; box-shadow: 0 1px 3px rgba(0,0,0,0.3); }
.shape-slider { align-items: center; justify-content: center; padding: 4px; }
.shape-select_dropdown { justify-content: flex-start; font-size: 14px; }

/* --- Right Sidebar (Properties) --- */
.sidebar-properties {
    width: 300px;
    background-color: var(--panel-bg);
    border-left: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    z-index: 10;
}

@media (max-width: 767px) { .sidebar-properties { display: none; } }
@media (min-width: 768px) and (max-width: 1023px) { .sidebar-properties { display: none; } }

/* Mobile props toggle button — shown via JS */
.btn-props-toggle {
    display: none;
    background: var(--primary-color);
    color: white;
    border-radius: 50%;
    width: 42px;
    height: 42px;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
    box-shadow: 0 4px 12px rgba(0,0,0,0.25);
    border: none;
    cursor: pointer;
    transition: background 0.2s;
}
.btn-props-toggle:hover { background: var(--primary-hover); }
@media (max-width: 1023px) {
    .btn-props-toggle { display: flex; }
}


.sidebar-properties > h3, .layers-section h3 {
    padding: 15px;
    font-size: 0.9rem;
    border-bottom: 1px solid var(--border-color);
    background-color: var(--bg-color);
    color: var(--text-main);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.properties-panel { flex: 1; overflow-y: auto; padding: 15px; }

.empty-text { color: var(--text-muted); font-size: 0.9rem; text-align: center; margin-top: 20px; }

.property-group { margin-bottom: 20px; }
.property-group h4 { font-size: 0.85rem; color: var(--text-muted); margin-bottom: 10px; border-bottom: 1px solid var(--border-color); padding-bottom: 5px; }

.prop-row { display: flex; gap: 10px; }
.prop-item { margin-bottom: 12px; display: flex; flex-direction: column; }
.prop-item.half { width: 50%; }
.prop-item label { font-size: 0.8rem; color: var(--text-muted); margin-bottom: 4px; }

.prop-item input, .prop-item select {
    padding: 6px 8px;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    font-size: 0.85rem;
    color: var(--text-main);
    background-color: var(--bg-color);
}

.prop-item input:focus { outline: none; border-color: var(--primary-color); box-shadow: 0 0 0 2px var(--active-border); }
.prop-item input[type="color"] { padding: 2px; height: 30px; width: 100%; cursor: pointer; }

.layers-section {
    height: 35%;
    border-top: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
}

.layer-list { list-style: none; overflow-y: auto; flex: 1; margin:0; padding:0; }

.layer-item {
    padding: 10px 15px;
    font-size: 0.85rem;
    display: flex;
    align-items: center;
    gap: 10px;
    border-bottom: 1px solid var(--border-color);
    cursor: pointer;
}

.layer-item i { color: var(--text-muted); width: 16px; text-align: center; }
.layer-item:hover { background-color: var(--bg-color); }
.layer-item.active { background-color: var(--active-bg); color: var(--primary-color); border-left: 3px solid var(--primary-color); }
.layer-item.active i { color: var(--primary-color); }

.hidden { display: none !important; }

/* Web Console Overlay */
#apk-loading-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background-color: rgba(0, 0, 0, 0.85);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    backdrop-filter: blur(5px);
}
.console-modal {
    width: 650px;
    max-width: 95%;
    background: #0f172a;
    border-radius: 8px;
    box-shadow: 0 20px 40px rgba(0,0,0,0.5);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    font-family: 'Consolas', 'Courier New', monospace;
    border: 1px solid #334155;
    pointer-events: auto;
}
.console-header {
    background: #1e293b;
    padding: 10px 15px;
    display: flex;
    align-items: center;
    border-bottom: 1px solid #334155;
}
.console-dots {
    display: flex;
    gap: 6px;
}
.console-dots span {
    width: 12px; height: 12px; border-radius: 50%;
}
.console-dots span:nth-child(1) { background: #ef4444; }
.console-dots span:nth-child(2) { background: #eab308; }
.console-dots span:nth-child(3) { background: #22c55e; }
.console-title {
    color: #94a3b8;
    font-size: 0.85rem;
    margin-left: auto;
    margin-right: auto;
    font-family: 'Inter', sans-serif;
}
.console-animation {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 30px;
    padding: 20px;
    background: #020617;
    border-bottom: 1px solid #334155;
}
.console-animation .code-box {
    font-size: 2.5rem;
    color: #3b82f6;
    animation: glowPulse 2s infinite ease-in-out;
    text-shadow: 0 0 15px rgba(59, 130, 246, 0.5);
}
.console-animation .apk-box { 
    color: #22c55e; 
    display: flex; 
    align-items: center; 
    justify-content: center; 
    animation: hoverBot 3s ease-in-out infinite;
    filter: drop-shadow(0 4px 6px rgba(34, 197, 94, 0.2));
}
@keyframes glowPulse {
    0%, 100% { transform: scale(1); text-shadow: 0 0 10px rgba(59, 130, 246, 0.4); }
    50% { transform: scale(1.1); text-shadow: 0 0 25px rgba(59, 130, 246, 0.8); }
}
@keyframes hoverBot {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-6px); }
}

/* Animated Android Bot */
.android-bot {
    width: 2.8rem;
    height: 2.8rem;
    color: currentColor;
    overflow: visible;
}
.android-head {
    transform-origin: 50px 45px;
    animation: headTilt 5s ease-in-out infinite;
}
.eyes {
    animation: lookAround 7s ease-in-out infinite;
}
.eye {
    transform-origin: center;
    animation: blink 4s infinite;
}
.arm-left {
    transform-origin: 9px 55px;
    animation: waveLeft 6s ease-in-out infinite;
}
.arm-right {
    transform-origin: 91px 55px;
    animation: waveRight 7s ease-in-out infinite;
}
.think-bubble {
    transform-origin: 90px 10px;
    animation: thinkPop 8s ease-in-out infinite;
}

@keyframes headTilt {
    0%, 15%, 85%, 100% { transform: rotate(0deg); }
    25%, 45% { transform: rotate(8deg); }
    55%, 75% { transform: rotate(-8deg); }
}
@keyframes lookAround {
    0%, 25%, 75%, 100% { transform: translateX(0); }
    35%, 45% { transform: translateX(-4px); }
    55%, 65% { transform: translateX(4px); }
}
@keyframes blink {
    0%, 46%, 48%, 100% { transform: scaleY(1); }
    47% { transform: scaleY(0.1); }
}
@keyframes waveLeft {
    0%, 20%, 100% { transform: rotate(0deg); }
    10% { transform: rotate(30deg); }
}
@keyframes waveRight {
    0%, 80%, 100% { transform: rotate(0deg); }
    85%, 95% { transform: rotate(-40deg); }
    90% { transform: rotate(-20deg); }
}
@keyframes thinkPop {
    0%, 50%, 100% { opacity: 0; transform: translateY(5px) scale(0.8); }
    60%, 90% { opacity: 1; transform: translateY(0) scale(1); }
}
.console-animation .arrow-anim {
    width: 80px;
    height: 4px;
    background: #334155;
    border-radius: 2px;
    position: relative;
    overflow: hidden;
}
.console-animation .data-stream {
    position: absolute;
    top: 0; left: 0;
    height: 100%;
    width: 40%;
    background: linear-gradient(90deg, transparent, #3b82f6, #60a5fa, transparent);
    animation: streamFlow 1.2s infinite linear;
}
@keyframes streamFlow {
    0% { transform: translateX(-100%); opacity: 0; }
    20% { opacity: 1; }
    80% { opacity: 1; }
    100% { transform: translateX(250%); opacity: 0; }
}
.console-body {
    padding: 20px;
    height: 350px;
    overflow-y: auto;
    color: #e2e8f0;
    font-size: 0.85rem;
    line-height: 1.5;
    background: #0f172a;
}
.console-log { 
    margin-bottom: 6px; 
    word-wrap: break-word; 
    animation: logFadeIn 0.35s ease-out forwards;
    opacity: 0;
    transform: translateY(10px);
}
@keyframes logFadeIn {
    to { opacity: 1; transform: translateY(0); }
}
.log-time { color: #64748b; margin-right: 8px; user-select: none; }
.log-info { color: #3b82f6; }
.log-success { color: #22c55e; }
.log-warn { color: #eab308; }
.log-error { color: #ef4444; }
.log-step { color: #c0caf5; font-weight: bold; margin-top: 10px; margin-bottom: 8px; }
.console-footer {
    padding: 15px;
    background: #1e293b;
    display: flex;
    justify-content: flex-end;
    border-top: 1px solid #334155;
}

.secondary-btn {
    background: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-main);
    padding: 8px 12px;
    border-radius: 6px;
    font-size: 0.85rem;
    cursor: pointer;
    transition: all 0.2s;
    font-weight: 500;
}
.secondary-btn:hover {
    background: var(--active-bg);
    border-color: var(--primary-color);
    color: var(--primary-color);
}

.template-card {
    background: var(--bg-color);
    border: 2px solid var(--border-color);
    border-radius: 8px;
    padding: 15px;
    text-align: left;
    cursor: pointer;
    transition: all 0.2s;
}
.template-card:hover {
    border-color: var(--primary-color);
}
.template-card.active {
    border-color: var(--primary-color);
    background: var(--active-bg);
}
.template-card i {
    font-size: 1.5rem;
    color: var(--primary-color);
    margin-bottom: 10px;
    display: block;
}
.template-card h4 {
    color: var(--text-main);
    margin: 0 0 5px 0;
    font-size: 0.95rem;
}
.template-card p {
    color: var(--text-muted);
    font-size: 0.8rem;
    margin: 0;
    line-height: 1.4;
}

/* Welcome Modal */
.modal-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background-color: rgba(15, 23, 42, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10000;
    opacity: 1;
    visibility: visible;
    transition: opacity 0.3s, visibility 0.3s;
    backdrop-filter: blur(4px);
}
.modal-overlay.hidden {
    opacity: 0;
    visibility: hidden;
}
.modal-content {
    background: var(--panel-bg);
    border-radius: 16px;
    padding: 30px;
    width: 90%;
    max-width: 450px;
    text-align: center;
    box-shadow: 0 20px 40px rgba(0,0,0,0.3);
    position: relative;
    transform: translateY(0) scale(1);
    transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}
.modal-overlay.hidden .modal-content {
    transform: translateY(30px) scale(0.95);
}
.modal-logo {
    width: 140px;
    height: 140px;
    object-fit: cover;
    border-radius: 50%;
    margin: 0 auto 20px;
    display: block;
    box-shadow: 0 8px 20px rgba(37, 99, 235, 0.25);
    border: 4px solid white;
    user-select: none;
    pointer-events: none;
}
.modal-content h2 {
    color: var(--text-main);
    margin-bottom: 12px;
    font-size: 1.6rem;
    font-weight: 700;
}
.modal-content > p {
    color: var(--text-muted);
    line-height: 1.6;
    margin-bottom: 25px;
    font-size: 0.95rem;
}
.contact-box {
    background: #ecfdf5;
    border: 1px solid #34d399;
    border-radius: 12px;
    padding: 15px;
    display: flex;
    align-items: center;
    gap: 15px;
    text-align: left;
}
.contact-box i {
    font-size: 2.2rem;
    color: #10b981;
}
.contact-box p {
    margin: 0;
    color: #064e3b;
    font-size: 0.9rem;
    line-height: 1.4;
}

/* PRO Buttons */
.pro-btn {
    background-color: #1e293b;
    color: white;
    padding: 10px 15px;
    border-radius: 8px;
    font-weight: 500;
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 8px;
    width: 100%;
    margin-bottom: 8px;
    border: 1px solid #334155;
    transition: all 0.2s;
    position: relative;
    cursor: pointer;
    font-family: inherit;
    font-size: 0.85rem;
}
.pro-btn:hover {
    background-color: #0f172a;
    border-color: #fbbf24;
}
.badge-pro {
    background: linear-gradient(135deg, #f59e0b, #fbbf24);
    color: #fff;
    font-size: 0.65rem;
    font-weight: 800;
    padding: 2px 6px;
    border-radius: 4px;
    margin-left: auto;
    letter-spacing: 0.5px;
    text-shadow: 0 1px 1px rgba(0,0,0,0.2);
}
@media (max-width: 1023px) {
    .pro-btn span:not(.badge-pro) { display: none; }
    .pro-btn { width: 40px; height: 40px; padding: 0; justify-content: center; }
    .badge-pro { position: absolute; top: -4px; right: -4px; font-size: 0.45rem; padding: 2px 3px; border-radius: 4px; }
}

/* Theme Switcher */
.theme-switch-wrapper {
    position: relative;
    display: flex;
    align-items: center;
    margin-right: 15px;
    background: var(--bg-color);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 0 8px;
    transition: all 0.2s ease;
    height: 32px;
}
.theme-switch-wrapper:hover {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 2px var(--active-border);
}
.theme-icon {
    color: var(--primary-color);
    font-size: 0.9rem;
    pointer-events: none;
}
.theme-select {
    appearance: none;
    -webkit-appearance: none;
    background: transparent;
    border: none;
    padding: 0 20px 0 8px;
    color: var(--text-main);
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    outline: none;
    font-family: inherit;
    width: 125px;
    height: 100%;
    background-image: url('data:image/svg+xml;utf8,<svg fill="%2364748b" height="24" viewBox="0 0 24 24" width="24" xmlns="http://www.w3.org/2000/svg"><path d="M7 10l5 5 5-5z"/></svg>');
    background-repeat: no-repeat;
    background-position: right center;
    background-size: 18px;
}
:root.theme-dark .theme-select, :root.theme-tokyo .theme-select {
    background-image: url('data:image/svg+xml;utf8,<svg fill="%2394a3b8" height="24" viewBox="0 0 24 24" width="24" xmlns="http://www.w3.org/2000/svg"><path d="M7 10l5 5 5-5z"/></svg>');
}
.theme-select option {
    background: var(--panel-bg);
    color: var(--text-main);
}

/* ══════════════════════════════════════════════════════════
   RESPONSIVE DESIGN
   ══════════════════════════════════════════════════════════ */

/* ── Tablet  (768 – 1023 px) ──────────────────────────── */
@media (min-width: 768px) and (max-width: 1023px) {
    .sidebar-tools {
        width: 64px;
        padding: 10px 0;
        align-items: center;
    }
    .logo {
        flex-direction: column;
        gap: 0;
        padding: 10px 0 8px;
        margin-bottom: 10px;
    }
    /* hide text labels in tool/action buttons */
    .tool-btn::after,
    .action-btn::after { content: none; }
    .tool-btn, .action-btn {
        width: 44px;
        height: 44px;
        justify-content: center;
        padding: 0;
    }
    .pro-btn { width: 44px; height: 44px; padding: 0; justify-content: center; }
    .pro-btn span:not(.badge-pro) { display: none; }
    .primary-btn { width: 44px; height: 44px; padding: 0; }
    .sidebar-tools .primary-btn span { display: none; }
    .tools-section h3 { display: none; }
    /* theme select shrinks */
    .theme-select { width: 90px; font-size: 0.78rem; }
    /* tabs truncate */
    .tab { max-width: 110px; padding: 6px 10px; font-size: 0.82rem; }
}

/* ── Mobile  (≤ 767 px) ───────────────────────────────── */
@media (max-width: 767px) {

    /* 1. Layout: stack IDE vertically, left sidebar → bottom bar */
    .ide-container {
        flex-direction: column;
        height: 100dvh;  /* dynamic viewport height for mobile browsers */
        overflow: hidden;
    }

    /* 2. Left sidebar becomes a horizontal bottom toolbar */
    .sidebar-tools {
        width: 100%;
        height: 56px;
        order: 3;                    /* push to the bottom */
        flex-direction: row;
        align-items: center;
        justify-content: space-around;
        padding: 0 8px;
        border-right: none;
        border-top: 1px solid var(--border-color);
        overflow-x: auto;
        overflow-y: hidden;
        gap: 4px;
    }

    /* 3. Logo hides in mobile (shown inline in header instead) */
    .logo { display: none; }

    /* 4. Tools / Actions: compact square buttons */
    .tools-section {
        flex-direction: row;
        margin-bottom: 0;
        gap: 2px;
        align-items: center;
    }
    .tools-section h3 { display: none; }
    .bottom-section {
        margin-top: 0;
        flex-direction: row;
        gap: 2px;
    }
    .tool-btn, .action-btn {
        width: 40px;
        height: 40px;
        min-width: 40px;
        justify-content: center;
        padding: 0;
        font-size: 1rem;
    }
    .tool-btn::after, .action-btn::after { content: none; }

    /* PRO buttons in bottom bar */
    .pro-btn {
        width: 40px;
        height: 40px;
        min-width: 40px;
        padding: 0;
        justify-content: center;
        margin-bottom: 0;
        font-size: 0.95rem;
    }
    .pro-btn span:not(.badge-pro) { display: none; }
    .badge-pro {
        position: absolute;
        top: -4px; right: -4px;
        font-size: 0.42rem;
        padding: 1px 3px;
    }

    /* Generar APK button in bottom bar */
    .primary-btn {
        width: 40px;
        height: 40px;
        min-width: 40px;
        padding: 0;
        margin-top: 0 !important;
    }
    .sidebar-tools .primary-btn span { display: none; }

    /* 5. Workspace: fills remaining space */
    .workspace {
        flex: 1;
        order: 2;
        min-height: 0;
        overflow: hidden;
    }

    /* 6. Header: compact, show mini logo */
    .workspace-header {
        height: 44px;
        padding: 0 8px;
        gap: 6px;
    }
    .workspace-header::before {
        content: "Drawpp";
        font-weight: 800;
        font-size: 1rem;
        color: var(--primary-color);
        letter-spacing: 1px;
        flex-shrink: 0;
    }
    .tabs {
        flex: 1;
        overflow-x: auto;
        overflow-y: hidden;
        scrollbar-width: none;
    }
    .tabs::-webkit-scrollbar { display: none; }
    .tab {
        padding: 5px 10px;
        font-size: 0.78rem;
        max-width: 120px;
        flex-shrink: 0;
    }
    .view-controls { gap: 4px; flex-shrink: 0; }
    .view-controls button { font-size: 0.95rem; padding: 4px; }
    /* hide theme selector on mobile to save space */
    .theme-switch-wrapper { display: none; }

    /* 7. Canvas container fills workspace */
    .canvas-container {
        padding: 16px 8px;
        align-items: flex-start;
        justify-content: center;
        overflow: auto;
    }

    /* 8. Canvas scales down to fit screen */
    .canvas {
        width: 100%;
        max-width: 375px;
        height: auto;
        min-height: 480px;
        aspect-ratio: 375 / 812;
    }

    /* 9. Modals: full-width on mobile */
    .modal-content {
        width: 95%;
        padding: 20px 18px;
        border-radius: 12px;
    }
    .modal-content h2 { font-size: 1.3rem; }
    .modal-logo { width: 100px; height: 100px; }

    /* 10. Project setup modal: single-col template grid */
    .template-grid { grid-template-columns: 1fr !important; }

    /* 11. Console modal */
    .console-modal { width: 95%; }
    .console-body { height: 220px; font-size: 0.78rem; }
    .console-animation { padding: 12px; gap: 18px; }
    .console-animation .code-box,
    .console-animation .apk-box { font-size: 1.8rem; }
}

/* ── Tablet & Mobile Drawer (≤ 1023 px) ───────────────── */
@media (max-width: 1023px) {
    /* Slide-in properties drawer (opened via JS toggle) */
    .sidebar-properties {
        display: flex !important;  /* override the hide rule */
        position: fixed;
        top: 0;
        right: -100%;
        width: 85%;
        max-width: 320px;
        height: 100%;
        z-index: 500;
        transition: right 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        box-shadow: -4px 0 20px rgba(0,0,0,0.25);
        overflow-y: auto;
    }
    .sidebar-properties.open {
        right: 0;
    }
    /* backdrop when drawer is open */
    .props-backdrop {
        display: none;
        position: fixed;
        inset: 0;
        background: rgba(0,0,0,0.4);
        z-index: 499;
        backdrop-filter: blur(2px);
    }
    .props-backdrop.active { display: block; }

    /* Floating properties toggle button */
    .btn-props-toggle {
        position: fixed;
        bottom: 30px;
        right: 20px;
        z-index: 1000;
        box-shadow: 0 4px 15px rgba(0,0,0,0.4);
    }
}

/* Move toggle button above bottom toolbar specifically on mobile */
@media (max-width: 767px) {
    .btn-props-toggle {
        bottom: 90px;
        right: 15px;
    }
}


/* ── Very small screens  (≤ 380 px) ─────────────────────── */
@media (max-width: 380px) {
    .sidebar-tools { height: 52px; }
    .tool-btn, .action-btn, .pro-btn, .primary-btn {
        width: 36px;
        height: 36px;
        min-width: 36px;
        font-size: 0.9rem;
    }
    .tab { max-width: 90px; font-size: 0.74rem; padding: 4px 8px; }
    .canvas { min-height: 380px; }
}
