/* --- Modern Flat OS Design System --- */

:root {
    --bg-gradient: linear-gradient(135deg, #e0c3fc 0%, #8ec5fc 100%);
    --font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
    
    /* Colors */
    --primary: #4f46e5;       /* Modern indigo */
    --primary-hover: #4338ca;
    --text-dark: #1e293b;     /* Slate 800 */
    --text-muted: #64748b;    /* Slate 500 */
    --border-color: rgba(0, 0, 0, 0.06);
    --window-bg: #ffffff;
    --taskbar-bg: rgba(255, 255, 255, 0.85);
    
    /* Layout & Shadow */
    --radius-window: 12px;
    --radius-control: 6px;
    --shadow-luxury: 0 10px 30px rgba(0, 0, 0, 0.06), 0 1px 3px rgba(0, 0, 0, 0.02);
}

/* Reset and Basics */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    background: var(--bg-gradient);
    background-color: #8ec5fc;
    font-family: var(--font-family);
    font-size: 13px;
    color: var(--text-dark);
    height: 100vh;
    width: 100vw;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    user-select: none;
}

/* Desktop Surface */
#desktop {
    flex: 1;
    min-height: 0; /* Allows container to shrink and establishes definite flexbox height boundary */
    overflow: hidden; /* Prevents children from expanding container height beyond viewport */
    position: relative;
    padding: 20px;
    display: flex;
    flex-direction: column;
    flex-wrap: wrap;
    align-content: flex-start;
    gap: 20px; /* Spacing between desktop icons vertically and horizontally */
}

.desktop-icon {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 80px;
    cursor: pointer;
    text-align: center;
    padding: 8px;
    border-radius: 8px;
    transition: background-color 0.2s, transform 0.1s;
}

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

.desktop-icon:focus,
.desktop-icon:active {
    background-color: rgba(255, 255, 255, 0.3);
    outline: none;
}

.desktop-icon img {
    width: 44px;
    height: 44px;
    margin-bottom: 8px;
    object-fit: contain;
    transition: transform 0.2s;
}

.desktop-icon:hover img {
    transform: scale(1.05);
}

.icon-label {
    color: #333333;
    font-weight: 500;
    font-size: 11px;
    word-break: break-word;
    text-shadow: 0 1px 2px rgba(255, 255, 255, 0.8);
}

/* Taskbar / Bottom Menu Bar */
#taskbar {
    background-color: var(--taskbar-bg);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    height: 48px;
    display: flex;
    align-items: center;
    padding: 0 12px;
    border-top: 1px solid var(--border-color);
    box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.02);
    z-index: 10000;
}

/* Start Button */
#start-button {
    height: 36px;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 0 14px;
    font-weight: 600;
    color: var(--text-dark);
    background: rgba(0, 0, 0, 0.04);
    border: 1px solid rgba(0, 0, 0, 0.03);
    border-radius: var(--radius-control);
    cursor: pointer;
    font-family: inherit;
    font-size: 13px;
    transition: background-color 0.2s, border-color 0.2s;
}

#start-button:hover {
    background-color: rgba(0, 0, 0, 0.08);
}

#start-button:active {
    background-color: rgba(0, 0, 0, 0.12);
}

#start-button img {
    width: 16px;
    height: 16px;
}

/* Taskbar App Containers */
#taskbar-apps {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 0 16px;
    overflow: hidden;
}

.taskbar-app-btn {
    height: 36px;
    min-width: 100px;
    max-width: 160px;
    display: flex;
    align-items: center;
    padding: 0 12px;
    gap: 8px;
    font-family: inherit;
    font-size: 12px;
    color: var(--text-dark);
    background: transparent;
    border: 1px solid transparent;
    border-radius: var(--radius-control);
    cursor: pointer;
    transition: background-color 0.2s, border-color 0.2s;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.taskbar-app-btn:hover {
    background-color: rgba(0, 0, 0, 0.04);
}

.taskbar-app-btn.active {
    background-color: rgba(0, 0, 0, 0.06);
    border-bottom: 2px solid var(--primary);
    border-radius: var(--radius-control) var(--radius-control) 0 0;
}

.taskbar-app-btn img {
    width: 16px;
    height: 16px;
    object-fit: contain;
}

/* System Tray */
#system-tray {
    height: 36px;
    display: flex;
    align-items: center;
    padding: 0 12px;
    background-color: rgba(0, 0, 0, 0.03);
    border-radius: var(--radius-control);
    margin-left: auto;
}

#clock {
    font-weight: 600;
    color: var(--text-dark);
    font-size: 12px;
}

/* --- Window Components --- */

.win98-window {
    position: absolute;
    background-color: var(--window-bg);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-window);
    box-shadow: var(--shadow-luxury);
    display: flex;
    flex-direction: column;
    min-width: 320px;
    min-height: 240px;
    top: 60px;
    left: 60px;
    overflow: hidden;
    transition: box-shadow 0.2s;
}

.win98-window.inactive {
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.03);
    opacity: 0.98;
}

.title-bar {
    background: #f8fafc;
    border-bottom: 1px solid var(--border-color);
    padding: 10px 14px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    color: var(--text-dark);
    font-weight: 600;
    cursor: default;
    user-select: none;
}

.win98-window.inactive .title-bar {
    background: #f1f5f9;
    color: var(--text-muted);
}

.title-bar-text {
    flex-grow: 1;
    font-size: 13px;
}

.title-bar-controls {
    display: flex;
    gap: 8px;
    align-items: center;
}

.title-bar-controls button {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: #e2e8f0;
    color: transparent;
    position: relative;
    transition: background-color 0.2s;
}

.title-bar-controls button:hover {
    background-color: #cbd5e1;
}

/* Close button gets bright red on hover */
.title-bar-controls .close-btn {
    background-color: #fee2e2;
}

.title-bar-controls .close-btn:hover {
    background-color: #ef4444;
}

/* Draw clean icons inside round buttons on hover */
.title-bar-controls button[aria-label="Minimize"]::before {
    content: "";
    width: 6px;
    height: 1.5px;
    background: #64748b;
    display: block;
}

.title-bar-controls button[aria-label="Maximize"]::before {
    content: "";
    width: 6px;
    height: 6px;
    border: 1.5px solid #64748b;
    display: block;
}

.title-bar-controls button[aria-label="Maximize"].restore::before {
    content: "";
    width: 4px;
    height: 4px;
    border: 1.5px solid #64748b;
    box-shadow: 1.5px -1.5px 0 -0.5px #f8fafc, 1.5px -1.5px 0 0.5px #64748b;
    display: block;
}

.title-bar-controls .close-btn::before {
    content: "×";
    color: #991b1b;
    font-size: 12px;
    font-weight: 700;
    display: block;
    line-height: 1;
}

.title-bar-controls .close-btn:hover::before {
    color: #ffffff;
}

/* Window Body Content */
.window-body {
    padding: 16px;
    flex-grow: 1;
    overflow: auto;
    background-color: var(--window-bg);
}

.window-body ul {
    list-style: none;
}

.window-body li {
    padding: 8px 0;
}

.window-body hr {
    border: 0;
    border-top: 1px solid var(--border-color);
    margin: 8px 0;
}

/* Maximized Window Layout Styles */
.win98-window.maximized {
    border-radius: 0 !important;
    box-shadow: none !important;
    border: none !important;
}

/* Theme Toggle Button */
.theme-btn {
    position: absolute;
    top: 20px; /* Positioned cleanly at the top-right of the desktop */
    right: 20px;
    z-index: 9999;
    padding: 8px 14px;
    font-family: inherit;
    font-weight: 600;
    font-size: 12px;
    cursor: pointer;
    background-color: var(--window-bg);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-control);
    box-shadow: 0 2px 8px rgba(0,0,0,0.04);
    color: var(--text-dark);
    transition: background-color 0.2s, box-shadow 0.2s, transform 0.1s;
}

.theme-btn:hover {
    background-color: #f8fafc;
    box-shadow: 0 4px 12px rgba(0,0,0,0.06);
}

.theme-btn:active {
    transform: translateY(1px);
    box-shadow: 0 1px 4px rgba(0,0,0,0.04);
}

/* --- Dark Mode Overrides --- */
body.dark-mode {
    --bg-gradient: linear-gradient(135deg, #1e293b 0%, #0f172a 100%);
    --text-dark: #f8fafc;     /* Slate 50 */
    --text-muted: #94a3b8;    /* Slate 400 */
    --border-color: rgba(255, 255, 255, 0.08);
    --window-bg: #1e293b;     /* Slate 800 */
    --taskbar-bg: rgba(15, 23, 42, 0.85); /* Slate 900 translucent */
}

/* Dark Mode specific updates */
body.dark-mode .icon-label {
    color: #ffffff;
    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.9);
}

body.dark-mode .desktop-icon:hover {
    background-color: rgba(255, 255, 255, 0.05);
}

body.dark-mode .desktop-icon:focus,
body.dark-mode .desktop-icon:active {
    background-color: rgba(255, 255, 255, 0.1);
}

body.dark-mode #start-button {
    background: rgba(255, 255, 255, 0.05);
    border-color: rgba(255, 255, 255, 0.05);
}

body.dark-mode #start-button:hover {
    background-color: rgba(255, 255, 255, 0.1);
}

body.dark-mode #start-button:active {
    background-color: rgba(255, 255, 255, 0.15);
}

body.dark-mode .taskbar-app-btn:hover {
    background-color: rgba(255, 255, 255, 0.04);
}

body.dark-mode .taskbar-app-btn.active {
    background-color: rgba(255, 255, 255, 0.06);
}

body.dark-mode .theme-btn {
    background-color: var(--window-bg);
    border-color: var(--border-color);
}

body.dark-mode .theme-btn:hover {
    background-color: #334155; /* Slate 700 */
}

body.dark-mode .title-bar {
    background: #0f172a; /* Slate 900 header */
}

body.dark-mode .win98-window.inactive .title-bar {
    background: #1e293b;
}

body.dark-mode .title-bar-controls button {
    background-color: #334155;
}

body.dark-mode .title-bar-controls button:hover {
    background-color: #475569;
}

body.dark-mode .title-bar-controls button[aria-label="Minimize"]::before,
body.dark-mode .title-bar-controls button[aria-label="Maximize"]::before {
    background-color: #94a3b8;
}

body.dark-mode .title-bar-controls button[aria-label="Maximize"]::before {
    border-color: #94a3b8;
    background-color: transparent;
}

body.dark-mode .title-bar-controls button[aria-label="Maximize"].restore::before {
    border-color: #94a3b8;
    box-shadow: 1.5px -1.5px 0 -0.5px #0f172a, 1.5px -1.5px 0 0.5px #94a3b8;
}

body.dark-mode .title-bar-controls .close-btn {
    background-color: #450a0a; /* Dark red close circle */
}

body.dark-mode .title-bar-controls .close-btn:hover {
    background-color: #ef4444;
}

body.dark-mode .title-bar-controls .close-btn::before {
    color: #f87171;
}

body.dark-mode .title-bar-controls .close-btn:hover::before {
    color: #ffffff;
}

body.dark-mode .window-body {
    background-color: #1e293b;
}

body.dark-mode .window-body ul li {
    background: transparent;
}

body.dark-mode .window-body div {
    background-color: #1e293b !important;
    color: #f8fafc !important;
}

/* Centered Taskbar Title */
.taskbar-title {
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    font-weight: 700;
    font-size: 13px;
    letter-spacing: 2px;
    text-transform: uppercase;
    color: var(--text-dark);
    pointer-events: none;
    opacity: 0.8;
}

/* Start Menu Popup Sidebar */
#start-menu {
    position: absolute;
    bottom: 56px; /* Sits 8px above the 48px taskbar */
    left: 12px;
    width: 200px;
    background-color: var(--window-bg);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-window);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.15);
    padding: 8px 0;
    z-index: 10001;
    display: flex;
    flex-direction: column;
    transition: opacity 0.15s ease, transform 0.15s ease;
    opacity: 0;
    transform: translateY(10px);
    pointer-events: none;
}

#start-menu.active {
    opacity: 1;
    transform: translateY(0);
    pointer-events: auto;
}

.menu-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 16px;
    cursor: pointer;
    transition: background-color 0.2s;
    color: var(--text-dark);
}

.menu-item:hover {
    background-color: rgba(0, 0, 0, 0.04);
}

body.dark-mode .menu-item:hover {
    background-color: rgba(255, 255, 255, 0.05);
}

.menu-item img {
    width: 20px;
    height: 20px;
    object-fit: contain;
}

.menu-item span {
    font-weight: 500;
    font-size: 13px;
}

/* Calculator Grid Buttons */
.calc-btn {
    height: 38px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 13px;
    background-color: rgba(0, 0, 0, 0.03);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-control);
    color: var(--text-dark);
    cursor: pointer;
    transition: background-color 0.2s;
}

.calc-btn:hover {
    background-color: rgba(0, 0, 0, 0.08);
}

body.dark-mode .calc-btn {
    background-color: rgba(255, 255, 255, 0.05);
}

body.dark-mode .calc-btn:hover {
    background-color: rgba(255, 255, 255, 0.1);
}

/* Text Notes Custom Window Sizing and Layout Constraints */
.win98-window[data-app-id="text-notes"] {
    width: 600px;
    height: 420px;
}

.win98-window[data-app-id="text-notes"] .window-body {
    padding: 0;
    overflow: hidden;
}
