/* ==========================================================================
   AIDOWS 2.0 OS THEME [RETRO PREMIUM]
   (c) 2025 Juzko Network.
   ========================================================================== */

:root {
    --bg-color: #050505;
    --win-bg: #111111;
    --win-header: #1a1a1a;
    --text-main: #e0e0e0;
    --accent-green: #00ff41;
    --accent-glow: rgba(0, 255, 65, 0.4);
    --border-color: #333;
    --crt-scanline: rgba(18, 16, 16, 0.1);

    --font-ui: 'Fira Code', monospace;
    --font-heading: 'VT323', monospace;
}

* {
    box-sizing: border-box;
    user-select: none;
}

body {
    margin: 0;
    padding: 0;
    width: 100vw;
    height: 100vh;
    background-color: var(--bg-color);
    color: var(--text-main);
    font-family: var(--font-ui);
    overflow: hidden;
    cursor: default;
}

/* --- BOOT SEQUENCE --- */
#boot-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: #000;
    z-index: 9999;
    padding: 40px;
    font-family: var(--font-heading);
    font-size: 1.5rem;
    color: var(--accent-green);
}

.boot-line {
    margin-bottom: 10px;
    opacity: 0;
    animation: fadeIn 0.1s forwards;
}

.status-ok {
    color: #fff;
    float: right;
}

.loading-bar {
    width: 300px;
    height: 20px;
    border: 2px solid var(--accent-green);
    margin-top: 20px;
    padding: 2px;
}

.loading-progress {
    width: 0%;
    height: 100%;
    background: var(--accent-green);
    transition: width 0.5s linear;
}

@keyframes fadeIn {
    to {
        opacity: 1;
    }
}

/* --- DESKTOP --- */
#os-desktop {
    width: 100%;
    height: 100%;
    position: relative;
    background: radial-gradient(circle at center, #111 0%, #000 100%);
}

#os-desktop::after {
    content: " ";
    display: block;
    position: absolute;
    top: 0;
    left: 0;
    bottom: 0;
    right: 0;
    background: linear-gradient(rgba(18, 16, 16, 0) 50%, rgba(0, 0, 0, 0.25) 50%), linear-gradient(90deg, rgba(255, 0, 0, 0.06), rgba(0, 255, 0, 0.02), rgba(0, 0, 255, 0.06));
    z-index: 2;
    background-size: 100% 2px, 3px 100%;
    pointer-events: none;
}

.os-hidden {
    display: none;
}

/* --- TASKBAR --- */
#os-taskbar {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 48px;
    background: rgba(20, 20, 20, 0.9);
    border-top: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    padding: 0 10px;
    z-index: 1000;
    backdrop-filter: blur(5px);
}

#start-btn {
    background: transparent;
    border: 1px solid var(--accent-green);
    color: var(--accent-green);
    padding: 5px 15px;
    font-family: var(--font-heading);
    font-size: 1.2rem;
    cursor: pointer;
    transition: 0.2s;
    box-shadow: 0 0 5px var(--accent-glow);
    touch-action: manipulation;
    /* Remove 300ms tap delay on mobile */
}

#start-btn:hover {
    background: var(--accent-green);
    color: #000;
}

#running-apps {
    flex: 1;
    display: flex;
    gap: 5px;
    padding-left: 20px;
}

.taskbar-item {
    background: #222;
    color: #ccc;
    padding: 5px 15px;
    border: 1px solid #444;
    font-size: 0.9rem;
    cursor: pointer;
    border-radius: 2px;
}

.taskbar-item.active {
    background: #333;
    border-color: #666;
    color: #fff;
    box-shadow: inset 0 -2px 0 var(--accent-green);
}

#system-tray {
    display: flex;
    gap: 15px;
    padding-right: 15px;
    font-size: 0.9rem;
    color: var(--accent-green);
}

/* --- START MENU --- */
.os-start-menu {
    position: absolute;
    bottom: 50px;
    left: 10px;
    width: 280px;
    /* Slightly wider */
    background: rgba(20, 20, 20, 0.98);
    /* Less transparent */
    border: 1px solid var(--accent-green);
    box-shadow: 0 0 20px rgba(0, 0, 0, 0.8);
    z-index: 2000;
    backdrop-filter: blur(10px);
    display: flex;
    flex-direction: column;
    animation: slideUp 0.1s ease-out;
}

/* FIX: Ensure hidden class overrides flex display */
.os-start-menu.os-hidden {
    display: none !important;
}

@keyframes slideUp {
    from {
        transform: translateY(10px);
        opacity: 0;
    }

    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.start-header {
    background: var(--accent-green);
    color: #000;
    padding: 12px 15px;
    font-weight: 700;
    font-family: 'Fira Code', monospace;
    /* Headers stay retro */
    font-size: 1.1rem;
    letter-spacing: 1px;
    text-transform: uppercase;
}

.start-list {
    padding: 8px 0;
    max-height: 400px;
    /* Prevent overflow on small screens */
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    /* Smooth iOS scrolling */
}

.start-item {
    padding: 12px 15px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 12px;
    color: #ddd;
    transition: 0.1s;
    touch-action: manipulation;
    /* Remove tap delay on mobile */

    /* Typography Polish */
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    /* Clean sans-serif */
    font-size: 15px;
    letter-spacing: 0.5px;
}

.start-item:hover {
    background: rgba(255, 255, 255, 0.1);
    color: #fff;
    padding-left: 20px;
    /* Slide effect */
}

.start-icon {
    width: 20px;
    text-align: center;
    font-size: 18px;
}

/* --- WINDOWS --- */
.os-window {
    position: absolute;
    background: var(--win-bg);
    border: 1px solid var(--border-color);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-width: 200px;
    min-height: 100px;
    animation: openWindow 0.2s cubic-bezier(0.18, 0.89, 0.32, 1.28);
}

.resize-handle {
    position: absolute;
    bottom: 0;
    right: 0;
    width: 15px;
    height: 15px;
    cursor: se-resize;
    z-index: 100;
    /* Visual indicator */
    background: linear-gradient(135deg, transparent 50%, var(--accent-green) 50%);
    opacity: 0.5;
}

.resize-handle:hover {
    opacity: 1;
}

.os-window.focused {
    border-color: var(--accent-green);
    box-shadow: 0 0 15px var(--accent-glow);
    z-index: 500;
}

/* --- DESKTOP ICONS --- */
.desktop-icon {
    position: absolute;
    width: 80px;
    padding: 10px;
    text-align: center;
    cursor: pointer;
    border: 1px solid transparent;
    border-radius: 4px;
    color: #fff;
    text-shadow: 1px 1px 2px #000;
    transition: 0.2s;
}

.desktop-icon:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: rgba(255, 255, 255, 0.2);
}

.desktop-icon.dragging {
    opacity: 0.8;
    cursor: grabbing;
    transition: none !important;
    /* FIX: Remove lag during drag */
}

/* --- STICKY NOTES --- */
.desktop-note {
    position: absolute;
    width: 200px;
    height: 160px;
    background: #fff740;
    /* Post-it Yellow */
    color: #333;
    padding: 0;
    box-shadow: 2px 2px 5px rgba(0, 0, 0, 0.3);
    border-radius: 2px;
    transform: rotate(-1deg);
    transition: transform 0.2s;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.desktop-note:hover {
    transform: scale(1.02) rotate(0deg);
    z-index: 10;
    box-shadow: 4px 4px 10px rgba(0, 0, 0, 0.4);
}

.desktop-note.dragging {
    transition: none !important;
    opacity: 0.9;
    cursor: grabbing;
    z-index: 100;
}

.note-handle {
    height: 20px;
    background: rgba(0, 0, 0, 0.05);
    cursor: grab;
    display: flex;
    justify-content: flex-end;
    align-items: center;
    padding-right: 5px;
}

.note-close {
    font-size: 14px;
    cursor: pointer;
    color: #666;
    font-weight: bold;
    padding: 0 5px;
}

.note-close:hover {
    color: #000;
}

.note-content {
    flex: 1;
    width: 100%;
    border: none;
    background: transparent;
    resize: none;
    padding: 10px;
    font-family: 'Comic Sans MS', 'Marker Felt', sans-serif;
    /* Authentic feel */
    font-size: 14px;
    outline: none;
}

.d-icon-img {
    font-size: 32px;
    margin-bottom: 5px;
    pointer-events: none;
}

.d-icon-label {
    font-size: 12px;
    font-family: 'Segoe UI', sans-serif;
    word-wrap: break-word;
    line-height: 1.2;
    text-shadow: 1px 1px 2px #000;
    pointer-events: none;
}

/* --- CONTEXT MENU --- */
.os-context-menu {
    display: none;
    position: absolute;
    background: #252526;
    border: 1px solid #454545;
    width: 200px;
    box-shadow: 2px 2px 10px rgba(0, 0, 0, 0.5);
    z-index: 9999;
}

.ctx-item {
    padding: 8px 15px;
    color: #ccc;
    cursor: pointer;
    font-size: 0.9rem;
}

.ctx-item:hover {
    background: #0e639c;
    color: #fff;
}

.ctx-hr {
    height: 1px;
    background: #454545;
    margin: 4px 0;
}

/* --- TOAST NOTIFICATIONS --- */
.os-toast {
    position: fixed;
    bottom: 60px;
    right: 20px;
    background: rgba(20, 20, 20, 0.95);
    border: 1px solid var(--accent-green);
    color: var(--accent-green);
    padding: 10px 20px;
    border-radius: 4px;
    font-family: var(--font-ui);
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.5);
    z-index: 9999;
    opacity: 0;
    transform: translateY(20px);
    transition: 0.3s cubic-bezier(0.18, 0.89, 0.32, 1.28);
    pointer-events: none;
}

.os-toast.show {
    opacity: 1;
    transform: translateY(0);
}

.window-header {
    height: 32px;
    background: var(--win-header);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 10px;
    cursor: grab;
    user-select: none;
}

.window-title {
    font-size: 0.8rem;
    font-weight: bold;
    color: #888;
}

.focused .window-title {
    color: #fff;
}

.window-controls {
    display: flex;
    gap: 5px;
}

.win-btn {
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    cursor: pointer;
    font-size: 0.8rem;
}

.btn-close {
    background: #cc3333;
    color: white;
}

.btn-min {
    background: #444;
    color: white;
}

.btn-max {
    background: #444;
    color: white;
}

.window-content {
    flex: 1;
    position: relative;
    background: #000;
}

iframe.app-frame {
    width: 100%;
    height: 100%;
    border: none;
    background: #111;
}

@keyframes openWindow {
    from {
        transform: scale(0.8);
        opacity: 0;
    }

    to {
        transform: scale(1);
        opacity: 1;
    }
}

/* --- SYSTEM DIALOGS --- */
.os-dialog-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    z-index: 10000;
    display: flex;
    justify-content: center;
    align-items: center;
    backdrop-filter: blur(2px);
}

.os-dialog {
    background: var(--win-bg);
    border: 1px solid var(--accent-green);
    width: 400px;
    box-shadow: 0 0 20px rgba(0, 255, 65, 0.2);
    display: flex;
    flex-direction: column;
}

.dialog-header {
    background: var(--win-header);
    padding: 10px;
    color: var(--accent-green);
    font-weight: bold;
    border-bottom: 1px solid #333;
    display: flex;
    justify-content: space-between;
}

.dialog-content {
    padding: 20px;
    color: #eee;
}

.dialog-content label {
    display: block;
    margin-bottom: 5px;
    color: #888;
    font-size: 12px;
}

.dialog-content input,
.dialog-content select {
    width: 100%;
    background: #111;
    border: 1px solid #444;
    color: #fff;
    padding: 8px;
    margin-bottom: 15px;
    font-family: var(--font-ui);
}

.dialog-content input:focus,
.dialog-content select:focus {
    border-color: var(--accent-green);
    outline: none;
}

.dialog-footer {
    padding: 15px;
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    border-top: 1px solid #333;
}

.btn-dialog {
    background: #333;
    color: #fff;
    border: 1px solid #555;
    padding: 6px 15px;
    cursor: pointer;
    font-family: var(--font-ui);
}

.btn-dialog:hover {
    border-color: #888;
}

.btn-primary {
    background: var(--accent-green);
    color: #000;
    border-color: var(--accent-green);
}

.btn-primary:hover {
    background: #00cc33;
}

/* --- MOBILE COMPATIBILITY --- */
@media (max-width: 768px) {

    /* ROOT FIXES */
    html {
        height: 100%;
        overflow-x: hidden;
    }

    /* Allow body scrolling but prevent horizontal */
    body {
        height: 100%;
        min-height: 100vh;
        overflow-y: auto !important;
        overflow-x: hidden !important;
        -webkit-overflow-scrolling: touch;
        position: relative !important;
        touch-action: pan-y;

        /* iOS FIX: Prevent text selection/highlight/callout on long press */
        -webkit-touch-callout: none !important;
        -webkit-user-select: none !important;
        user-select: none !important;
    }

    /* Ensure desktop container grows with content */
    #os-desktop {
        height: auto !important;
        min-height: 100%;
        overflow-y: auto !important;
        overflow-x: hidden !important;
        position: relative !important;

        /* Flow Layout for Icons - wrap to multiple rows */
        display: flex;
        flex-direction: row;
        flex-wrap: wrap;
        align-content: flex-start;
        align-items: flex-start;
        justify-content: flex-start;
        gap: 15px;
        padding: 20px 15px 120px 15px;
        /* Space for taskbar at bottom */
    }

    /* Force background to stay fixed */
    #os-background {
        position: fixed !important;
        top: 0;
        left: 0;
        width: 100vw;
        height: 100vh;
        z-index: -1;
    }

    /* Override Absolute Positioning for Icons */
    .desktop-icon {
        position: relative !important;
        top: auto !important;
        left: auto !important;
        width: 80px !important;
        height: auto !important;
        margin: 0 !important;
        transform: none !important;
        pointer-events: auto;
        -webkit-user-select: none;
        user-select: none;
    }

    /* Notes take full width on mobile */
    .desktop-note {
        position: relative !important;
        top: auto !important;
        left: auto !important;
        width: 100% !important;
        height: auto !important;
        min-height: 150px;
        transform: none !important;
        margin-bottom: 20px;
    }

    /* Windows: ABSOLUTE positioning allows native scroll */
    .os-window {
        position: absolute !important;
        /* KEY FIX for Android */
        top: 20px !important;
        left: 50% !important;
        transform: translateX(-50%) !important;
        width: 95% !important;
        height: calc(100vh - 100px) !important;
        /* iOS FIX: explicit height */
        height: calc(100dvh - 100px) !important;
        /* iOS Safari dynamic vh */
        min-height: 400px;
        max-height: none;
        z-index: 5000;
        display: flex;
        flex-direction: column;
    }

    /* iOS FIX: iframe needs explicit height, not just flex */
    .window-content {
        flex: 1;
        min-height: 0;
        /* Allow shrinking */
        height: 100%;
        /* iOS needs this */
        position: relative;
    }

    iframe.app-frame {
        position: absolute;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
    }

    /* START MENU MOBILE FIXES */
    .os-start-menu {
        max-height: calc(100vh - 70px);
        /* Account for taskbar */
        display: flex !important;
        flex-direction: column;
    }

    .start-list {
        max-height: calc(100vh - 120px);
        /* Header + taskbar space */
        flex: 1;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }
}