:root {
  --bg: #0f172a;
  --bg2: #111827;
  --desktop-grad-1: #0f172a;
  --desktop-grad-2: #1e293b;
  --panel: rgba(15, 23, 42, 0.78);
  --panel-2: rgba(30, 41, 59, 0.88);
  --border: rgba(148, 163, 184, 0.22);
  --text: #e5eefc;
  --muted: #aab6c9;
  --accent: #60a5fa;
  --accent-2: #38bdf8;
  --shadow: 0 16px 50px rgba(0, 0, 0, 0.35);
  --taskbar-h: 52px;
  --titlebar-h: 40px;
  --radius: 16px;
  --icon-size: 84px;
}

body.theme-light {
  --bg: #dbeafe;
  --bg2: #f8fbff;
  --desktop-grad-1: #cfe3ff;
  --desktop-grad-2: #eef5ff;
  --panel: rgba(255, 255, 255, 0.72);
  --panel-2: rgba(255, 255, 255, 0.92);
  --border: rgba(15, 23, 42, 0.12);
  --text: #0f172a;
  --muted: #475569;
  --accent: #2563eb;
  --accent-2: #0ea5e9;
  --shadow: 0 16px 50px rgba(15, 23, 42, 0.18);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  font-family:
    system-ui,
    -apple-system,
    Segoe UI,
    Roboto,
    Ubuntu,
    Cantarell,
    "Helvetica Neue",
    Arial,
    sans-serif;
  color: var(--text);
  background: var(--bg);
}

button,
input,
textarea {
  font: inherit;
}

button {
  border: 0;
  background: none;
  color: inherit;
}

#desktop {
  position: fixed;
  inset: 0 0 var(--taskbar-h) 0;
  background:
    radial-gradient(
      circle at top left,
      rgba(96, 165, 250, 0.22),
      transparent 35%
    ),
    radial-gradient(
      circle at bottom right,
      rgba(56, 189, 248, 0.16),
      transparent 40%
    ),
    linear-gradient(135deg, var(--desktop-grad-1), var(--desktop-grad-2));
  user-select: none;
  overflow: hidden;
}

#desktop-icons {
  position: absolute;
  inset: 16px;
  display: grid;
  grid-auto-flow: column; /* fill vertically first, then next column */
  grid-template-rows: repeat(auto-fill, 92px);
  grid-auto-columns: 92px;
  gap: 12px;
  align-content: start;
  justify-content: start;
  pointer-events: none;
}

.desktop-icon {
  width: 84px;
  height: 84px;
  padding: 10px 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border-radius: 14px;
  cursor: default;
  text-align: center;
  color: var(--text);
  background: transparent;
  transition:
    background 160ms ease,
    transform 160ms ease,
    box-shadow 160ms ease;
  pointer-events: auto;
}

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

.desktop-icon:active {
  transform: scale(0.97);
}

.desktop-icon .icon-emoji {
  font-size: 2rem;
  line-height: 1;
}

.desktop-icon .icon-label {
  font-size: 0.76rem;
  line-height: 1.1;
  text-shadow: 0 1px 1px rgba(0, 0, 0, 0.25);
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#windows-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.window {
  position: absolute;
  min-width: 260px;
  min-height: 180px;
  border-radius: var(--radius);
  background: var(--panel);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  overflow: hidden;
  backdrop-filter: blur(16px);
  transform: translateZ(0);
  pointer-events: auto;
}

.window.focused {
  outline: 1px solid rgba(96, 165, 250, 0.6);
}

.window.maximized {
  border-radius: 0;
}

.window.minimized {
  display: none;
}

.titlebar {
  height: var(--titlebar-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 0 8px 0 12px;
  background: var(--panel-2);
  border-bottom: 1px solid var(--border);
  cursor: grab;
}

.titlebar:active {
  cursor: grabbing;
}

.titlebar-left {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.window-title {
  font-size: 0.92rem;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.window-controls {
  display: flex;
  align-items: center;
  gap: 6px;
}

.win-btn {
  width: 30px;
  height: 26px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  cursor: pointer;
  color: var(--text);
  background: rgba(255, 255, 255, 0.06);
  transition:
    background 140ms ease,
    transform 140ms ease;
}

.win-btn:hover {
  background: rgba(255, 255, 255, 0.14);
}

.win-btn:active {
  transform: scale(0.96);
}

.win-content {
  position: relative;
  width: 100%;
  height: calc(100% - var(--titlebar-h));
  overflow: hidden;
}

.resize-handle {
  position: absolute;
  right: 2px;
  bottom: 2px;
  width: 18px;
  height: 18px;
  cursor: nwse-resize;
  border-bottom-right-radius: 12px;
  background: linear-gradient(
    135deg,
    transparent 0 45%,
    rgba(255, 255, 255, 0.35) 45% 52%,
    transparent 52% 100%
  );
  opacity: 0.8;
}

#taskbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  height: var(--taskbar-h);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 10px;
  background: rgba(15, 23, 42, 0.82);
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  backdrop-filter: blur(16px);
  z-index: 9999;
}

body.theme-light #taskbar {
  background: rgba(255, 255, 255, 0.86);
  border-top: 1px solid rgba(15, 23, 42, 0.1);
}

.taskbar-start,
.taskbar-icon {
  width: 38px;
  height: 38px;
  border-radius: 12px;
  cursor: pointer;
  display: grid;
  place-items: center;
  background: rgba(255, 255, 255, 0.08);
  transition:
    background 140ms ease,
    transform 140ms ease;
}

.taskbar-start:hover,
.taskbar-icon:hover,
.taskbar-item:hover {
  background: rgba(255, 255, 255, 0.14);
}

.taskbar-start:active,
.taskbar-icon:active,
.taskbar-item:active {
  transform: scale(0.98);
}

.taskbar-windows {
  flex: 1;
  min-width: 0;
  display: flex;
  gap: 8px;
  overflow: auto;
  padding-bottom: 2px;
}

.taskbar-item {
  height: 38px;
  max-width: 220px;
  padding: 0 12px;
  border-radius: 12px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(255, 255, 255, 0.08);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 0 0 auto;
}

.taskbar-item.active {
  background: rgba(96, 165, 250, 0.3);
  outline: 1px solid rgba(96, 165, 250, 0.35);
}

.taskbar-item .mini-icon {
  font-size: 1rem;
}

.taskbar-item .mini-title {
  overflow: hidden;
  text-overflow: ellipsis;
}

.taskbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.taskbar-clock {
  min-width: 72px;
  text-align: center;
  font-size: 0.95rem;
  color: var(--text);
}

.menu {
  position: fixed;
  z-index: 10000;
  min-width: 180px;
  padding: 8px;
  border-radius: 14px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  backdrop-filter: blur(14px);
}

.menu.hidden {
  display: none;
}

.menu-item {
  width: 100%;
  border: 0;
  background: transparent;
  color: var(--text);
  padding: 10px 12px;
  border-radius: 10px;
  text-align: left;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 10px;
}

.menu-item:hover {
  background: rgba(255, 255, 255, 0.12);
}

.menu-sep {
  height: 1px;
  margin: 6px 2px;
  background: var(--border);
}

/* Clock */
.clock-app {
  height: 100%;
  display: grid;
  place-items: center;
  text-align: center;
  padding: 16px;
}

.clock-card {
  padding: 24px 20px;
}

.clock-time {
  font-size: clamp(2.4rem, 6vw, 4.8rem);
  font-weight: 700;
  letter-spacing: 0.04em;
}

.clock-date {
  margin-top: 8px;
  font-size: 1rem;
  color: var(--muted);
}

/* Calculator */
.calc-app {
  height: 100%;
  display: grid;
  grid-template-rows: auto 1fr;
  gap: 10px;
  padding: 12px;
}

.calc-display {
  min-height: 72px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.08);
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  border: 1px solid var(--border);
  overflow: hidden;
}

.calc-expression {
  font-size: 0.95rem;
  color: var(--muted);
  min-height: 1.2em;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.calc-result {
  margin-top: 6px;
  font-size: 1.8rem;
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.calc-keys {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}

.calc-key {
  min-height: 54px;
  border-radius: 14px;
  cursor: pointer;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid transparent;
  transition:
    background 140ms ease,
    transform 140ms ease;
  font-weight: 600;
}

.calc-key:hover {
  background: rgba(255, 255, 255, 0.14);
}

.calc-key:active {
  transform: scale(0.98);
}

.calc-key.op {
  background: rgba(96, 165, 250, 0.2);
}

.calc-key.eq {
  background: rgba(34, 197, 94, 0.2);
}

/* Browser */
.browser-app {
  height: 100%;
  display: grid;
  grid-template-rows: auto 1fr;
}

.browser-toolbar {
  display: grid;
  grid-template-columns: auto auto auto 1fr auto;
  gap: 8px;
  padding: 10px;
  border-bottom: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.06);
}

.browser-btn,
.browser-go {
  width: 38px;
  height: 36px;
  border-radius: 12px;
  cursor: pointer;
  background: rgba(255, 255, 255, 0.08);
}

.browser-btn:hover,
.browser-go:hover {
  background: rgba(255, 255, 255, 0.14);
}

.browser-url {
  min-width: 0;
  width: 100%;
  height: 36px;
  padding: 0 12px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.08);
  color: var(--text);
  outline: none;
}

.browser-frame {
  width: 100%;
  height: 100%;
  border: 0;
  background: white;
}

/* Explorer */
.explorer-app {
  height: 100%;
  display: grid;
  grid-template-columns: 260px 1fr;
  min-height: 0;
}

.explorer-sidebar {
  border-right: 1px solid var(--border);
  padding: 10px;
  overflow: auto;
  background: rgba(255, 255, 255, 0.04);
}

.explorer-main {
  padding: 12px;
  overflow: auto;
  min-width: 0;
}

.tree-node {
  margin-left: 12px;
}

.tree-item {
  padding: 8px 10px;
  border-radius: 10px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
}

.tree-item:hover {
  background: rgba(255, 255, 255, 0.1);
}

.tree-item.active {
  background: rgba(96, 165, 250, 0.24);
}

.file-view {
  height: 100%;
  border-radius: 14px;
  border: 1px solid var(--border);
  padding: 14px;
  background: rgba(255, 255, 255, 0.06);
  overflow: auto;
  white-space: pre-wrap;
}

.folder-title {
  font-size: 1.05rem;
  font-weight: 700;
  margin-bottom: 10px;
}

.file-meta {
  font-size: 0.9rem;
  color: var(--muted);
  margin-bottom: 12px;
}

/* Notes */
.notes-app {
  height: 100%;
  display: grid;
  grid-template-rows: auto 1fr;
}

.notes-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px;
  border-bottom: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.06);
}

.notes-title-input {
  flex: 1;
  min-width: 0;
  height: 36px;
  padding: 0 12px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.08);
  color: var(--text);
  outline: none;
}

.notes-editor {
  width: 100%;
  height: 100%;
  resize: none;
  border: 0;
  outline: none;
  padding: 14px;
  color: var(--text);
  background: transparent;
  line-height: 1.5;
  font-size: 0.98rem;
}

.small-muted {
  color: var(--muted);
  font-size: 0.9rem;
}

/* Settings App */
.settings-app {
  padding: 20px;
  height: 100%;
  overflow-y: auto;
}

.settings-section {
  margin-bottom: 24px;
}

.settings-section h3 {
  margin-top: 0;
  margin-bottom: 14px;
  font-size: 1.1rem;
}

.wallpaper-presets {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 18px;
}

.preset-btn {
  width: 60px;
  height: 44px;
  border-radius: 10px;
  border: 2px solid var(--border);
  cursor: pointer;
  transition: transform 140ms ease, border-color 140ms ease;
}

.preset-btn:hover {
  transform: scale(1.05);
  border-color: var(--accent);
}

.settings-row {
  margin-top: 12px;
  display: flex;
  gap: 12px;
  align-items: center;
}

/* Paint App */
.paint-app {
  height: 100%;
  display: grid;
  grid-template-rows: auto 1fr;
}

.paint-toolbar {
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  display: flex;
  gap: 12px;
  align-items: center;
  background: rgba(255, 255, 255, 0.05);
}

.paint-canvas-wrap {
  overflow: auto;
  background: #cbd5e1;
  padding: 32px;
  display: flex;
  justify-content: center;
  align-items: flex-start;
}

.paint-canvas-wrap canvas {
  background: white;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
  cursor: crosshair;
  flex: 0 0 auto;
}

/* Responsive */
@media (max-width: 700px) {
  :root {
    --titlebar-h: 38px;
    --taskbar-h: 50px;
    --icon-size: 76px;
  }

  #desktop-icons {
    inset: 12px;
    grid-template-rows: repeat(auto-fill, 84px);
    grid-auto-columns: 84px;
  }

  .desktop-icon {
    width: 76px;
    height: 76px;
  }

  .explorer-app {
    grid-template-columns: 1fr;
    grid-template-rows: 190px 1fr;
  }
}
