:root {
  --bg:           #f3f4f6;
  --text:         #111827;
  --text-dim:     #4b5563;
  --text-faint:   #9ca3af;
  --line:         rgba(0,0,0,0.10);
  --bg-elev:      rgba(255,255,255,0.85);
  --bg-elev-2:    #f9fafb;
  --accent:       #7c3aed;
  --accent-2:     #a855f7;
  --accent-soft:  rgba(124,58,237,0.16);
  --good:         #10b981;
  --danger:       #ef4444;
  --warning:      #f59e0b;
  --shadow:       0 6px 22px rgba(15,23,42,0.10), 0 1px 3px rgba(15,23,42,0.06);
  --tray-bg:      rgba(255,255,255,0.65);
  --tray-blur:    saturate(1.4) blur(18px);
  --shelf-bg:     rgba(255,255,255,0.72);
  --easing:       cubic-bezier(.2,.8,.2,1);
  --sans:         ui-sans-serif, system-ui, -apple-system, "Segoe UI", Inter, Roboto, sans-serif;
  --mono:         ui-monospace, SFMono-Regular, "JetBrains Mono", Menlo, monospace;
}
[data-theme="dark"] {
  --bg:           #0f172a;
  --text:         #f1f5f9;
  --text-dim:     #cbd5e1;
  --text-faint:   #64748b;
  --line:         rgba(255,255,255,0.10);
  --bg-elev:      rgba(15,23,42,0.85);
  --bg-elev-2:    #1e293b;
  --tray-bg:      rgba(15,23,42,0.65);
  --shelf-bg:     rgba(15,23,42,0.72);
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; padding: 0; overflow: hidden; }
body {
  font-family: var(--sans);
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  user-select: none;
}

/* ---------- Wallpaper ---------- */
#wallpaper {
  position: fixed; inset: 0; z-index: 0;
  background:
    radial-gradient(ellipse at 20% 0%, #c4b5fd 0%, transparent 55%),
    radial-gradient(ellipse at 80% 100%, #d8b4fe 0%, transparent 55%),
    linear-gradient(135deg, #7c3aed 0%, #4c1d95 70%, #1e1b4b 100%);
  background-size: cover;
  transition: filter .8s var(--easing);
}
[data-theme="dark"] #wallpaper {
  background:
    radial-gradient(ellipse at 20% 0%, #312e81 0%, transparent 55%),
    radial-gradient(ellipse at 80% 100%, #581c87 0%, transparent 55%),
    linear-gradient(135deg, #1e1b4b 0%, #0f172a 100%);
}

/* ---------- Status tray (top) ---------- */
.status-tray {
  position: fixed; top: 0; left: 0; right: 0; z-index: 30;
  height: 32px;
  display: flex; align-items: center; gap: 6px;
  padding: 0 14px;
  background: var(--tray-bg);
  backdrop-filter: var(--tray-blur);
  -webkit-backdrop-filter: var(--tray-blur);
  border-bottom: 1px solid var(--line);
  font: 500 12px var(--sans);
  color: var(--text);
}
.tray-spacer { flex: 1; }
.tray-clock { font: 500 12px var(--mono); color: var(--text); padding: 0 8px; }
.tray-desks { display: inline-flex; align-items: center; gap: 4px; margin-left: 8px; }
.tray-desk {
  width: 16px; height: 8px;
  background: var(--text-faint); border: none; border-radius: 3px;
  cursor: pointer; padding: 0;
  opacity: 0.5; transition: opacity .12s, background .12s, width .15s;
}
.tray-desk:hover { opacity: 1; }
.tray-desk.active { opacity: 1; background: var(--accent); width: 24px; }
.tray-desk-add {
  width: 16px; height: 16px;
  background: transparent; color: var(--text-faint);
  border: 1px dashed var(--line); border-radius: 4px;
  cursor: pointer; padding: 0;
  font: 600 12px var(--sans); line-height: 1;
  transition: color .12s, border-color .12s;
}
.tray-desk-add:hover { color: var(--accent); border-color: var(--accent); }
.tray-pill {
  display: inline-flex; align-items: center; gap: 6px;
  height: 22px; padding: 0 10px;
  background: transparent;
  border: 1px solid transparent; border-radius: 11px;
  color: var(--text-dim); font: 500 12px var(--sans);
  cursor: pointer; transition: background .12s, color .12s;
}
.tray-pill:hover { background: var(--bg-elev); color: var(--text); border-color: var(--line); }
.tray-pill svg { display: block; }
.tray-auth { padding: 0 12px; }
.tray-auth-on { color: var(--accent); border-color: var(--accent-soft); background: var(--accent-soft); }
.tray-auth-on:hover { color: var(--accent); }

/* ---------- Windows area ---------- */
.windows {
  position: fixed; inset: 32px 0 56px 0;
  z-index: 10;
  pointer-events: none; /* children re-enable */
}
.windows > .window { pointer-events: auto; }

/* ---------- Shelf (bottom) ---------- */
.shelf {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  height: 56px;
  display: flex; align-items: center; justify-content: center;
  background: var(--shelf-bg);
  backdrop-filter: var(--tray-blur);
  -webkit-backdrop-filter: var(--tray-blur);
  border-top: 1px solid var(--line);
  padding: 0 16px;
}
.shelf-running { display: flex; align-items: center; gap: 8px; }
.shelf-empty {
  font: 12px var(--mono);
  color: var(--text-faint);
  letter-spacing: 0.04em;
}
.shelf-app {
  display: flex; align-items: center; gap: 8px;
  height: 36px; padding: 0 14px;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: 18px;
  color: var(--text-dim);
  font: 500 13px var(--sans);
  cursor: pointer;
  transition: background .12s, color .12s, border-color .12s, transform .08s;
}
.shelf-app:hover { color: var(--text); border-color: var(--accent); transform: translateY(-1px); }
.shelf-app.active { color: var(--text); border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }
.shelf-app.minimized { opacity: 0.55; }
.shelf-app-icon { font-size: 16px; }
.shelf-app-name { max-width: 200px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.shelf-app.pinned { background: var(--bg-elev-2); border-style: dashed; }
.shelf-app.pinned:hover { border-style: solid; }
.shelf-app.launching { opacity: 0.6; }
.shelf-app.builtin { background: var(--accent-soft); border-color: var(--accent-soft); color: var(--accent); }
.shelf-app.builtin:hover { border-color: var(--accent); }
.shelf-sep { width: 1px; height: 28px; background: var(--line); margin: 0 4px; }

/* ---------- Windows ---------- */
.window {
  background: var(--bg-elev);
  backdrop-filter: var(--tray-blur);
  -webkit-backdrop-filter: var(--tray-blur);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--shadow);
  display: flex; flex-direction: column;
  overflow: hidden;
  transition: box-shadow .15s var(--easing);
}
.window.win-active { box-shadow: 0 18px 40px rgba(15,23,42,0.18), 0 4px 10px rgba(15,23,42,0.10); }
.window.win-maximized { border-radius: 0; }

.win-titlebar {
  height: 32px;
  display: flex; align-items: center;
  padding: 0 6px 0 12px;
  background: var(--bg-elev);
  border-bottom: 1px solid var(--line);
  cursor: grab;
  user-select: none;
  flex-shrink: 0;
}
.win-titlebar:active { cursor: grabbing; }
.win-title { flex: 1; display: flex; align-items: center; gap: 8px; min-width: 0; }
.win-icon { font-size: 14px; flex-shrink: 0; }
.win-title-text { font: 500 13px var(--sans); color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.win-actions { display: flex; align-items: center; gap: 2px; }
.win-act {
  width: 26px; height: 22px;
  display: grid; place-items: center;
  background: transparent; border: none; border-radius: 5px;
  color: var(--text-dim);
  font: 500 14px var(--sans);
  cursor: pointer;
  transition: background .1s, color .1s;
}
.win-act:hover { background: var(--bg-elev-2); color: var(--text); }
.win-close:hover { background: var(--danger); color: white; }
.win-content { flex: 1; overflow: auto; }
.win-error {
  padding: 14px 18px;
  background: rgba(239,68,68,0.08);
  border-bottom: 1px solid var(--line);
  color: var(--danger);
  font: 13px var(--mono);
}

/* Resize handles — invisible bands at the edges + corners. */
.win-resize { position: absolute; }
.win-n { top: -3px; left: 8px; right: 8px; height: 6px; cursor: ns-resize; }
.win-s { bottom: -3px; left: 8px; right: 8px; height: 6px; cursor: ns-resize; }
.win-e { top: 8px; bottom: 8px; right: -3px; width: 6px; cursor: ew-resize; }
.win-w { top: 8px; bottom: 8px; left: -3px; width: 6px; cursor: ew-resize; }
.win-ne { top: -4px; right: -4px; width: 12px; height: 12px; cursor: nesw-resize; }
.win-nw { top: -4px; left: -4px; width: 12px; height: 12px; cursor: nwse-resize; }
.win-se { bottom: -4px; right: -4px; width: 12px; height: 12px; cursor: nwse-resize; }
.win-sw { bottom: -4px; left: -4px; width: 12px; height: 12px; cursor: nesw-resize; }
.window.win-maximized .win-resize { display: none; }

/* Snap preview overlay shown during title-bar drag near an edge. */
.win-snap-preview {
  position: fixed;
  z-index: 50;
  background: var(--accent-soft);
  border: 2px dashed var(--accent);
  border-radius: 12px;
  pointer-events: none;
  opacity: 0;
  transition: opacity .12s var(--easing), left .12s var(--easing), top .12s var(--easing), width .12s var(--easing), height .12s var(--easing);
}

/* ---------- Launcher (full-screen overlay) ---------- */
.launcher-overlay {
  position: fixed; inset: 0; z-index: 60;
  display: grid; place-items: start center;
  padding-top: 84px;
  background: rgba(15,23,42,0.42);
  backdrop-filter: saturate(1.2) blur(18px);
  -webkit-backdrop-filter: saturate(1.2) blur(18px);
  animation: launcher-fade .15s var(--easing);
}
@keyframes launcher-fade { from { opacity: 0; } to { opacity: 1; } }

.launcher-card {
  width: min(92vw, 880px);
  max-height: calc(100vh - 140px);
  display: flex; flex-direction: column;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: 0 24px 60px rgba(0,0,0,0.30), 0 4px 14px rgba(0,0,0,0.10);
  overflow: hidden;
  animation: launcher-pop .2s var(--easing);
}
@keyframes launcher-pop { from { transform: translateY(8px) scale(.98); opacity: 0; } to { transform: none; opacity: 1; } }

.launcher-search {
  display: flex; align-items: center; gap: 10px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
}
.launcher-search-icon { width: 18px; height: 18px; color: var(--text-faint); flex-shrink: 0; }
.launcher-input {
  flex: 1;
  background: transparent; border: none; outline: none;
  font: 500 18px var(--sans);
  color: var(--text);
}
.launcher-input::placeholder { color: var(--text-faint); }
.launcher-hint {
  font: 11px var(--mono);
  color: var(--text-faint);
  background: var(--bg-elev-2);
  border: 1px solid var(--line);
  border-radius: 5px;
  padding: 1px 6px;
}

.launcher-grid {
  flex: 1; overflow-y: auto;
  padding: 18px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(132px, 1fr));
  gap: 8px;
  align-content: start;
}
.launcher-app {
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  padding: 18px 10px 14px;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 12px;
  cursor: pointer;
  font: inherit; color: var(--text);
  transition: background .12s, border-color .12s, transform .08s;
}
.launcher-app:hover, .launcher-app:focus {
  background: var(--bg-elev-2);
  border-color: var(--line);
  outline: none;
}
.launcher-app:active { transform: scale(0.97); }
.launcher-app-icon {
  width: 56px; height: 56px;
  display: grid; place-items: center;
  font-size: 32px;
  background: var(--bg-elev-2);
  border-radius: 14px;
}
.launcher-app:hover .launcher-app-icon { background: var(--accent-soft); }
.launcher-app-name { font: 500 13px var(--sans); text-align: center; line-height: 1.3; }
.launcher-app-author { font: 11px var(--mono); color: var(--text-faint); }
.launcher-app { position: relative; }
.launcher-app.pinned .launcher-app-icon { box-shadow: 0 0 0 2px var(--accent-soft); }
.launcher-pin {
  position: absolute; top: 6px; right: 6px;
  width: 26px; height: 26px;
  display: grid; place-items: center;
  background: transparent; border: none; border-radius: 50%;
  color: var(--text-faint);
  font-size: 16px; line-height: 1; cursor: pointer;
  opacity: 0;
  transition: opacity .12s, color .12s, background .12s;
}
.launcher-app:hover .launcher-pin, .launcher-pin.on { opacity: 1; }
.launcher-pin:hover { background: var(--bg-elev-2); color: var(--accent); }
.launcher-pin.on { color: var(--accent); }
.launcher-status {
  grid-column: 1 / -1;
  text-align: center;
  padding: 32px 16px;
  color: var(--text-faint);
  font: 13px var(--sans);
}
.launcher-status.err { color: var(--danger); font-family: var(--mono); }
.launcher-foot {
  padding: 10px 18px;
  border-top: 1px solid var(--line);
  font: 11px var(--mono);
  color: var(--text-faint);
}

/* ---------- Quick settings popover ---------- */
.quick-settings {
  position: fixed; z-index: 70;
  width: 320px;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: 0 16px 40px rgba(0,0,0,0.18), 0 4px 10px rgba(0,0,0,0.06);
  padding: 12px;
  display: flex; flex-direction: column; gap: 10px;
  animation: qs-pop .12s var(--easing);
}
@keyframes qs-pop { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; } }

.qs-row { display: flex; align-items: center; gap: 10px; }
.qs-row.qs-stack { flex-direction: column; align-items: stretch; gap: 6px; }
.qs-label { flex: 0 0 80px; font: 500 13px var(--sans); color: var(--text-dim); }
.qs-seg { display: inline-flex; gap: 0; }
.qs-seg button {
  background: var(--bg-elev-2); border: 1px solid var(--line); color: var(--text-dim);
  padding: 5px 14px; font: 13px var(--sans); cursor: pointer;
}
.qs-seg button:first-child { border-radius: 7px 0 0 7px; }
.qs-seg button:last-child  { border-radius: 0 7px 7px 0; border-left: none; }
.qs-seg button.on { background: var(--accent); color: var(--text-on-accent, white); border-color: var(--accent); }
.qs-input-row { display: flex; gap: 6px; }
.qs-input-row input {
  flex: 1; background: var(--bg-elev-2); border: 1px solid var(--line);
  border-radius: 7px; padding: 6px 10px; font: 13px var(--mono);
  color: var(--text); outline: none; min-width: 0;
}
.qs-input-row input:focus { border-color: var(--accent); }
.qs-btn {
  background: var(--accent); color: var(--text-on-accent, white);
  border: none; border-radius: 7px; padding: 6px 14px;
  font: 500 13px var(--sans); cursor: pointer;
}
.qs-btn:hover { filter: brightness(1.05); }
.qs-btn.qs-ghost { background: var(--bg-elev-2); color: var(--text-dim); border: 1px solid var(--line); }
.qs-btn.qs-wide { width: 100%; padding: 8px; }
.qs-hint { font: 11px var(--mono); color: var(--text-faint); }
.qs-foot { padding-top: 8px; border-top: 1px solid var(--line); font: 11px var(--mono); color: var(--text-faint); }
.qs-foot code { word-break: break-all; }

/* ---------- Lock screen ---------- */
.lock-overlay {
  position: fixed; inset: 0; z-index: 1000;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 4px;
  background: rgba(15,23,42,0.55);
  backdrop-filter: saturate(1.2) blur(28px);
  -webkit-backdrop-filter: saturate(1.2) blur(28px);
  color: white;
  cursor: pointer;
  user-select: none;
  animation: lock-fade-in .25s var(--easing);
}
@keyframes lock-fade-in { from { opacity: 0; } to { opacity: 1; } }
.lock-overlay.lock-fading { opacity: 0; transition: opacity .25s var(--easing); }
.lock-clock { font: 200 96px/1 var(--sans); letter-spacing: -0.04em; }
.lock-date  { font: 400 18px var(--sans); opacity: 0.85; margin-top: 8px; }
.lock-user  { font: 13px var(--mono); opacity: 0.6; margin-top: 18px; }
.lock-hint  { font: 12px var(--mono); opacity: 0.5; margin-top: 24px; }

/* When a custom wallpaper is applied, ditch the gradient. */
#wallpaper.wallpaper-custom { background-image: var(--wp-url); }
