 :root {
    --macos-blue: #007aff;
    --macos-gray: #8e8e93;
    --macos-light-gray: #c7c7cc;
    --macos-dark-gray: #1c1c1e;
    --macos-white: #ffffff;
    --macos-black: #000000;
    --macos-red: #ff3b30;
    --macos-green: #34c759;
    --macos-yellow: #ffcc00;
    --macos-orange: #ff9500;
    --macos-purple: #af52de;
    --macos-pink: #ff2d55;
    --macos-teal: #5ac8fa;
    --macos-indigo: #5856d6;
    --macos-accent: var(--macos-blue);
    --macos-bg-primary: #000000;
    --macos-bg-secondary: #1c1c1e;
    --macos-text-primary: #ffffff;
    --macos-text-secondary: #8e8e93;
    --macos-border: rgba(255,255,255,0.2);
    --macos-shadow: rgba(0, 0, 0, 0.6);
    --macos-blur: blur(20px);
}

body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen,
        Ubuntu, Cantarell, "Open Sans", "Helvetica Neue", sans-serif;
    color: var(--macos-text-primary);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    user-select: none;
    overflow: hidden;
    height: 100vh;
    display: flex;
    flex-direction: column;
    background: linear-gradient(180deg, var(--macos-bg-primary), var(--macos-bg-secondary));
    font-size: clamp(14px, 2vw, 16px);
}

/* Added styles for window titlebar and controls for mobile and touchpad friendliness */
.window-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: clamp(6px, 2vw, 12px);
    border-bottom: 1px solid var(--macos-border);
    border-radius: 12px 12px 0 0;
    cursor: grab;
    user-select: none;
    -webkit-user-select: none;
    -webkit-app-region: drag;
    background-color: var(--macos-bg-secondary);
    color: var(--macos-text-primary);
}

.window-controls {
    display: flex;
    gap: 8px;
    align-items: center;
    margin-right: auto;
    margin-left: 6px;
}

.window-control-button.minimize {
    background-color: #ffbd2e; /* yellow */
}

.window-control-button.maximize {
    background-color: #28c840; /* green */
}

.window-control-button.close {
    background-color: #ff5f57; /* red */
}

.window-control-button:hover::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 20px;
    height: 20px;
    background: rgba(255,255,255,0.2);
    border-radius: 50%;
    transform: translate(-50%, -50%);
    pointer-events: none;
}

/* Responsive adjustments for mobile */
@media (max-width: 600px) {
    .window-header {
        flex-direction: column;
        align-items: flex-start;
        padding: clamp(8px, 3vw, 12px);
    }
    .window-controls {
        width: 100%;
        justify-content: space-around;
        margin-bottom: 6px;
    }
    .window-control-button {
        width: 40px;
        height: 40px;
        border-radius: 8px;
        margin: 0 4px;
    }
    .window-title {
        font-size: 1.1em;
        padding-left: 4px;
    }
}

#desktop {
    flex: 1;
    padding: clamp(10px, 5vw, 30px);
    box-sizing: border-box;
    position: relative;
    overflow: hidden;
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    width: auto;
    background-attachment: fixed;
    margin: 0;
    animation: shuffleBackground 20s ease infinite;
    background-attachment: fixed;
}

@keyframes shuffleBackground {
    0% {
        background-position: 0% 50%;
    }50% {
        background-position: 100% 50%;
    }
    100% {
        background-position: 0% 50%;
    }
}

.dock-container, #dock {
    /* macOS Sci-Fi Neon Dock: glossy, beveled, neon glow */
    position: fixed;
    left: 50%;
    bottom: 20px;
    transform: translateX(-50%);
    display: flex;
    flex-direction: row;
    justify-content: center;
    align-items: center;
    gap: 12px;
    height: auto;
    min-height: 64px;
    padding: 10px 16px;
    width: auto;
    overflow: visible;
    user-select: none;
    z-index: 1000;
    transition: all 0.3s cubic-bezier(.2,.8,.2,1);

    /* neon background with glassy reflection */
    background: linear-gradient(180deg, rgba(0,255,255,0.1), rgba(255,0,255,0.05), rgba(0,255,255,0.02));
    border-radius: 36px;
    box-shadow:
        inset 0 2px 6px rgba(0,255,255,0.2), /* top inner cyan highlight */
        inset 0 -8px 18px rgba(255,0,255,0.3),     /* bottom inner magenta shadow */
        0 0 20px rgba(0,255,255,0.5),           /* cyan outer glow */
        0 0 40px rgba(255,0,255,0.3),           /* magenta outer glow */
        0 12px 30px rgba(0,0,0,0.55);           /* outer drop shadow */
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    animation: fadeIn 0.45s ease;
    border: 1px solid rgba(0,255,255,0.3);
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: scale(0.9);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

.window {
    position: absolute;
    display: flex;
    flex-direction: column;
    background: var(--macos-bg-secondary);
    border: 1px solid var(--macos-border);
    border-radius: 12px;
    box-shadow: 0 4px 16px var(--macos-shadow);
    min-width: clamp(280px, 50vw, 320px);
    min-height: clamp(140px, 30vh, 200px);
    width: clamp(320px, 70vw, 800px);
    max-width: calc(100vw - 40px);
    overflow: hidden; /* keep children inside */
    color: var(--macos-text-primary);
    transition: all 0.3s ease;
}

.window.maximized {
    width: 100vw !important;
    height: 100vh !important;
    top: 0 !important;
    left: 0 !important;
    border-radius: 0 !important;
    box-shadow: none !important;
}

.window.maximized .window-content {
    padding-top: 40px;
}

.window.maximized .window-header {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    z-index: 10001;
    border-radius: 0;
    cursor: grab;
    background-color: #222;
    color: white;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 6px 12px;
}

.window-content {
    padding: 60px 12px 12px;
    flex: 1 1 auto;
    overflow: auto; /* scroll inside window */
    box-sizing: border-box;
}

.window .window-header {
    border-radius: 12px 12px 0 0;
}



.window-title {
    font-weight: 600;
    font-size: clamp(12px, 2.5vw, 16px);
    color: white;
}

.window-controls {
    display: flex;
    gap: 8px;
    align-items: center;
    margin-right: auto; /* push title to center */
    margin-left: 6px; /* left-side controls like macOS */
}

.window-control-button {
    width: clamp(16px, 2vw, 24px);
    height: clamp(16px, 2vw, 24px);
    border-radius: clamp(6px, 1vw, 8px);
    box-shadow: 0 0 2px rgba(0,0,0,0.3);
    cursor: pointer;
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    margin: 0 6px;
    flex: 0 0 auto;
    -webkit-app-region: no-drag;
    border: none;
    background: none;
    padding: 0;
}

.window-control-button.minimize {
    background-color: #ffbd2e; /* yellow */
}

.window-control-button.maximize {
    background-color: #28c840; /* green */
}

.window-control-button.close { background-color: #ff5f57; }

/* larger hit targets for touch */
.window-controls [role="button"] {
    padding: 8px;
    margin: 0 2px;
    border-radius: 50%;
}

/* center title and reserve space on the right */
.window-header .window-title {
    margin: 0 auto;
    text-align: center;
}

.window-control-button:hover::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 20px;
    height: 20px;
    background: rgba(255,255,255,0.2);
    border-radius: 50%;
    transform: translate(-50%, -50%);
    pointer-events: none;
}

.dock-icon {
    width: 64px;
    height: 64px;
    border-radius: 14px; /* squircle-ish for skeuomorphic look */
    background: linear-gradient(180deg, rgba(0,255,255,0.1), rgba(255,0,255,0.05), rgba(0,255,255,0.02));
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s cubic-bezier(.2,.8,.2,1);
    cursor: pointer;
    box-shadow: 0 0 10px rgba(0,255,255,0.3), 0 0 20px rgba(255,0,255,0.2), 0 10px 20px rgba(0,0,0,0.45), inset 0 1px 0 rgba(0,255,255,0.1);
    padding: 8px;
    border: 1px solid rgba(0,255,255,0.2);
    overflow: visible;
    position: relative;
    color: #00ffff; /* cyan text for icons */
}

.dock-icon img {
    width: 30px;
    height: 30px;
    pointer-events: none;
    user-select: none;
    filter: drop-shadow(0 6px 8px rgba(0,0,0,0.45));
}

/* Strong override to ensure dock is horizontal and centered (helps if other styles conflict) */
#dock, .dock-container {
    position: fixed !important;
    left: 50% !important;
    bottom: 20px !important;
    transform: translateX(-50%) !important;
    display: flex !important;
    flex-direction: row !important;
    justify-content: center !important;
    align-items: center !important;
    gap: 12px !important;
    padding: 8px 14px !important;
    z-index: 9999 !important;
    width: auto !important;
    min-height: 56px !important;
    background: rgba(33, 132, 143, 0.04) !important;
    border-radius: 28px !important;
}

/* accessible focus styles for dock icons */
.dock-icon:focus {
    outline: 2px solid rgba(255,255,255,0.2);
    outline-offset: 3px;
}

.dock-icon .badge {
    position: absolute;
    top: -6px;
    right: -6px;
    background: #ff3b30;
    color: white;
    font-size: 11px;
    padding: 2px 6px;
    border-radius: 999px;
}

.dock-icon:hover {
    transform: translateY(-8px) scale(1.14);
    background: linear-gradient(180deg, rgba(0,255,255,0.2), rgba(255,0,255,0.1), rgba(0,255,255,0.05));
    box-shadow: 0 0 15px rgba(0,255,255,0.5), 0 0 30px rgba(255,0,255,0.3), 0 18px 36px rgba(0,0,0,0.6), inset 0 1px 0 rgba(0,255,255,0.1);
    z-index: 11;
}

/* subtle glossy reflection for the dock - uses pseudo-element */
.dock-container::before, #dock::before {
    content: '';
    position: absolute;
    left: 6px;
    right: 6px;
    top: 6px;
    height: 24px;
    border-radius: 28px;
    background: linear-gradient(180deg, rgba(255,255,255,0.08), rgba(255,255,255,0.01));
    pointer-events: none;
    mix-blend-mode: overlay;
    opacity: 0.9;
}

#noteFileName {
    background: rgba(255, 255, 255, 0.2);
    color: white;
    border: none;
    border-radius: 8px;
    padding: 8px;
    font-size: 14px;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen,
        Ubuntu, Cantarell, "Open Sans", "Helvetica Neue", sans-serif;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    user-select: text;
    outline: none;
    box-shadow: 0 0 10px rgba(255, 255, 255, 0.2);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    transition: box-shadow 0.3s ease;
}

#noteFileName:focus {
    box-shadow: 0 0 15px rgba(255, 255, 255, 0.5);
    outline: none;
}

/* Tablet styles */
@media (min-width: 769px) and (max-width: 1024px) {
    .window {
        width: clamp(400px, 60vw, 700px);
        max-width: calc(100vw - 60px);
    }
    .dock-icon {
        width: 72px;
        height: 72px;
    }
    .dock-icon img {
        width: 36px;
        height: 36px;
    }
}

/* Large screen styles */
@media (min-width: 1201px) {
    .window {
        width: clamp(500px, 50vw, 1000px);
        min-height: 250px;
    }
    .dock-icon {
        width: 80px;
        height: 80px;
    }
    .dock-icon img {
        width: 40px;
        height: 40px;
    }
}

/* Responsive design */
@media (max-width: 768px) and (orientation: portrait) {
    #desktop {
        padding: clamp(5px, 3vw, 15px);
    }
    .window {
        width: 90vw;
        min-width: 200px;
        max-width: 90vw;
        top: 20px !important;
        left: 5vw !important;
    }
}
@media (max-width: 768px) and (orientation: landscape) {
    #desktop {
        padding: clamp(5px, 3vw, 15px);
    }
    .window {
        width: 85vw;
        min-width: 200px;
        max-width: 85vw;
        top: 10px !important;
        left: 7.5vw !important;
    }
    .window-content {
        padding: clamp(40px, 10vh, 60px) 12px 12px;
    }
    .window.maximized .window-header {
        height: 48px;
        padding: 8px 12px;
    }
.window.maximized .window-header {
    display: none;
}
.window.maximized .window-content {
    padding: 0;
}
    .dock-container {
        bottom: 10px;
        height: 50px;
        padding: 0 10px;
        gap: 8px;
    }
    .dock-icon {
        width: 40px;
        height: 40px;
    }
    .dock-icon img {
        width: 24px;
        height: 24px;
    }
    /* Improve touch targets on mobile */
    .window-control-button {
        width: 32px;
        height: 32px;
        border-radius: 8px;
    }
    .window-controls [role="button"] {
        padding: 12px;
    }
}

@media (max-width: 320px) {
    .window {
        width: 98vw;
        max-width: 98vw;
        min-width: 150px;
    }
    .window-header {
        padding: clamp(6px, 2vw, 10px);
    }
    .window-control-button {
        width: 28px;
        height: 28px;
    }
    .dock-container {
        height: 40px;
        gap: 4px;
    }
    .dock-icon {
        width: 30px;
        height: 30px;
    }
    .dock-icon img {
        width: 18px;
        height: 18px;
    }
}

@media (max-width: 480px) {
    .window {
        width: 95vw;
        max-width: 95vw;
        padding: clamp(2px, 2vw, 8px);
    }
    .window.maximized .window-header {
        height: 52px;
        padding: 10px 12px;
    }
    .window.maximized .window-content {
        padding-top: 60px;
    }
    .window-header {
        padding: clamp(8px, 3vw, 12px);
    }
    .window-title {
        font-size: clamp(10px, 3vw, 14px);
    }
    .dock-container {
        height: 45px;
        gap: 6px;
    }
    .dock-icon {
        width: 35px;
        height: 35px;
    }
    .dock-icon img {
        width: 20px;
        height: 20px;
    }
    /* Further improve touch targets */
    .window-control-button {
        width: 24px;
        height: 24px;
        border-radius: 8px;
    }
    .window-controls [role="button"] {
        padding: 10px;
    }
}

/* Orientation-specific adjustments for mobile */
@media (orientation: landscape) and (max-width: 768px) {
    .window {
        max-width: clamp(80vw, 90vw, 85vw);
        max-height: 75vh;
    }
    .window.maximized {
        max-height: calc(100vh - 60px); /* leave more space for dock */
    }
    .window.maximized .window-content {
        padding-top: 50px;
    }
    .dock-container {
        bottom: 5px;
        z-index: 10001; /* ensure dock is above maximized windows */
    }
}

@media (orientation: portrait) and (max-width: 768px) {
    .window {
        max-width: clamp(85vw, 95vw, 90vw);
    }
    .window.maximized {
        max-height: calc(100vh - 80px);
    }
}

/* WebDisk responsiveness */
#webdiskWindow {
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
}
#webdiskContent {
    overflow-x: auto;
}
#webdiskContent table {
    min-width: 100%;
    white-space: nowrap;
}
@media (max-width: 768px) {
    #webdiskContent table {
        font-size: 12px;
    }
    #webdiskContent table th,
    #webdiskContent table td {
        padding: 2px 4px;
    }
    #webdiskContent .btn {
        font-size: 12px;
        padding: 4px 8px;
    }
}
