:root {
  --font-system: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Helvetica Neue", sans-serif;
  --window-radius: 10px;
  --transition-fast: 120ms ease-out;
  --transition-med: 200ms ease-out;
}

:root[data-theme="light"] {
  --wallpaper-base: linear-gradient(160deg, #c5b8e8 0%, #9bb6e8 50%, #8fc7e0 100%);
  --wallpaper-highlight: radial-gradient(circle at 30% 20%, rgba(255, 200, 180, 0.45), transparent 50%);
  --menubar-bg: rgba(245, 245, 247, 0.55);
  --menubar-fg: #1d1d1f;
  --dock-bg: rgba(245, 245, 247, 0.45);
  --window-bg: #ffffff;
  --window-fg: #1d1d1f;
  --window-border: rgba(0, 0, 0, 0.15);
  --window-shadow: 0 22px 50px rgba(0, 0, 0, 0.25);
  --titlebar-bg: rgba(245, 245, 247, 0.7);
  --accent: #0a84ff;
  --secondary: #8e8e93;
}

:root[data-theme="dark"] {
  --wallpaper-base: linear-gradient(160deg, #2a2356 0%, #1c2a4f 50%, #143b50 100%);
  --wallpaper-highlight: radial-gradient(circle at 30% 20%, rgba(40, 200, 220, 0.25), transparent 50%);
  --menubar-bg: rgba(30, 30, 32, 0.55);
  --menubar-fg: #f5f5f7;
  --dock-bg: rgba(30, 30, 32, 0.45);
  --window-bg: #2a2a2c;
  --window-fg: #f5f5f7;
  --window-border: rgba(255, 255, 255, 0.1);
  --window-shadow: 0 22px 50px rgba(0, 0, 0, 0.6);
  --titlebar-bg: rgba(40, 40, 42, 0.7);
  --accent: #0a84ff;
  --secondary: #98989d;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: var(--font-system);
  font-size: 13px;
  color: var(--window-fg);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

#desktop {
  position: relative;
  width: 100vw;
  height: 100vh;
  overflow: hidden;
}

#wallpaper {
  position: absolute; inset: 0;
  background: var(--wallpaper-highlight), var(--wallpaper-base);
  z-index: 0;
}

.mac-window {
  position: absolute;
  background: var(--window-bg);
  color: var(--window-fg);
  border-radius: var(--window-radius);
  box-shadow: var(--window-shadow);
  border: 1px solid var(--window-border);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  min-width: 320px;
  min-height: 200px;
  transition: opacity var(--transition-fast), transform var(--transition-med);
}
.mac-window.entering { opacity: 0; transform: scale(0.92); }
.mac-window.closing { opacity: 0; transform: scale(0.95); }
.mac-window.unfocused { filter: saturate(0.85); box-shadow: 0 12px 30px rgba(0,0,0,0.18); }
.mac-window.fullscreen {
  left: 0 !important; top: 28px !important;
  width: 100vw !important; height: calc(100vh - 28px) !important;
  border-radius: 0; border: none;
}

.titlebar {
  height: 28px;
  background: var(--titlebar-bg);
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  flex-shrink: 0;
  user-select: none;
  cursor: grab;
}
.titlebar:active { cursor: grabbing; }
.titlebar .title { font-size: 13px; font-weight: 500; opacity: 0.7; }
.mac-window.unfocused .titlebar .title { opacity: 0.5; }
.mac-window.fullscreen .titlebar .title { display: none; }

.traffic-lights {
  position: absolute; left: 12px; top: 50%; transform: translateY(-50%);
  display: flex; gap: 8px; align-items: center;
}
.mac-window.fullscreen .traffic-lights { left: 50%; transform: translate(-50%, -50%); }
.light {
  width: 12px; height: 12px; border-radius: 50%; border: none; padding: 0; cursor: pointer;
  background: #d4d4d6; display: flex; align-items: center; justify-content: center;
  font-size: 9px; line-height: 1; color: rgba(0,0,0,0);
}
.mac-window:not(.unfocused) .light { color: rgba(0,0,0,0.5); }
.mac-window:not(.unfocused) .light.close:hover { background: #ff5f57; color: rgba(0,0,0,0.6); }
.mac-window:not(.unfocused) .light.min:hover   { background: #febc2e; color: rgba(0,0,0,0.6); }
.mac-window:not(.unfocused) .light.max:hover   { background: #28c840; color: rgba(0,0,0,0.6); }
.mac-window.unfocused .light.close { background: #5a5a5c; }
.mac-window.unfocused .light.min   { background: #5a5a5c; }
.mac-window.unfocused .light.max   { background: #5a5a5c; }
.light:hover::after { content: attr(aria-label); }
.light.close::before { content: "\00d7"; font-weight: 700; font-size: 10px; }
.light.max::before   { content: "\25F1"; }
.light.min::before   { content: "\2013"; }

.content { flex: 1; overflow: hidden; display: flex; flex-direction: column; min-height: 0; }

.resize { position: absolute; z-index: 10; }
.resize-n  { top: 0; left: 0; right: 0; height: 4px; cursor: ns-resize; }
.resize-s  { bottom: 0; left: 0; right: 0; height: 4px; cursor: ns-resize; }
.resize-e  { top: 0; bottom: 0; right: 0; width: 4px; cursor: ew-resize; }
.resize-w  { top: 0; bottom: 0; left: 0; width: 4px; cursor: ew-resize; }
.resize-ne { top: 0; right: 0; width: 8px; height: 8px; cursor: nesw-resize; }
.resize-nw { top: 0; left: 0; width: 8px; height: 8px; cursor: nwse-resize; }
.resize-se { bottom: 0; right: 0; width: 14px; height: 14px; cursor: nwse-resize; }
.resize-sw { bottom: 0; left: 0; width: 8px; height: 8px; cursor: nesw-resize; }

#menubar {
  position: fixed; top: 0; left: 0; right: 0; height: 28px;
  background: var(--menubar-bg);
  color: var(--menubar-fg);
  backdrop-filter: blur(20px) saturate(180%);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 12px; z-index: 5000; font-size: 13px;
  border-bottom: 1px solid rgba(0,0,0,0.1);
}
.menubar-left, .menubar-right { display: flex; align-items: center; gap: 0; }
.mb-item {
  background: transparent; border: none; color: inherit; font: inherit;
  padding: 2px 10px; border-radius: 4px; cursor: pointer;
}
.mb-item:hover { background: rgba(0,0,0,0.08); }
:root[data-theme="dark"] .mb-item:hover { background: rgba(255,255,255,0.1); }
.mb-item.app-name { font-weight: 600; }
.mb-item.apple { width: 18px; height: 18px; padding: 0; }
.mb-item.apple::after {
  content: "";
  display: block; width: 14px; height: 14px;
  background: currentColor;
  -webkit-mask: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M17 12c0-3 2.5-4 2.5-4s-1-2.5-4-2.5c-2 0-3 1.2-4 1.2s-2-1.2-4-1.2c-3 0-5 2.5-5 6 0 5 4 11 7 11 1 0 2-.7 3-.7s2 .7 3 .7c2 0 3.5-2.5 4.5-5-1.5-.7-3-2-3-4.5zM14 6c1-1.5 2.5-2.5 2.5-2.5s-1 1.5-2 3z"/></svg>') center/contain no-repeat;
          mask: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M17 12c0-3 2.5-4 2.5-4s-1-2.5-4-2.5c-2 0-3 1.2-4 1.2s-2-1.2-4-1.2c-3 0-5 2.5-5 6 0 5 4 11 7 11 1 0 2-.7 3-.7s2 .7 3 .7c2 0 3.5-2.5 4.5-5-1.5-.7-3-2-3-4.5zM14 6c1-1.5 2.5-2.5 2.5-2.5s-1 1.5-2 3z"/></svg>') center/contain no-repeat;
}
.mb-item.icon { width: 24px; height: 24px; padding: 0; }

.mb-menu {
  position: fixed; min-width: 200px;
  background: var(--menubar-bg);
  backdrop-filter: blur(20px) saturate(180%);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  border: 1px solid var(--window-border);
  border-radius: 8px; padding: 4px; z-index: 6000;
  box-shadow: 0 8px 24px rgba(0,0,0,0.25);
  display: flex; flex-direction: column;
}
.mb-row {
  text-align: left; background: transparent; border: none; color: inherit;
  font: inherit; padding: 4px 12px; border-radius: 4px; cursor: pointer;
}
.mb-row:hover { background: var(--accent); color: #fff; }
.mb-sep { height: 1px; background: var(--window-border); margin: 4px 0; }

.mb-menu.control-center { min-width: 240px; }
.cc-row { padding: 8px; display: flex; flex-direction: column; gap: 6px; }
.cc-row + .cc-row { border-top: 1px solid var(--window-border); }
.cc-toggle-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.cc-tile {
  background: var(--accent); color: #fff; border: none; padding: 8px;
  border-radius: 8px; font: inherit; cursor: pointer;
}
.cc-display { font-size: 12px; opacity: 0.8; }
.cc-slider { width: 100%; }
.cc-theme { flex-direction: row; align-items: center; gap: 8px; }
.cc-theme button {
  flex: 1; background: var(--accent); color: #fff; border: none; padding: 6px;
  border-radius: 6px; cursor: pointer; font: inherit;
}

#dock-container {
  position: fixed; bottom: 8px; left: 0; right: 0;
  display: flex; justify-content: center; z-index: 4000;
  pointer-events: none;
}
#dock {
  pointer-events: auto;
  background: var(--dock-bg);
  backdrop-filter: blur(20px) saturate(180%);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  border-radius: 18px;
  padding: 6px 8px;
  display: flex; gap: 4px; align-items: flex-end;
  box-shadow: 0 8px 20px rgba(0,0,0,0.2);
  border: 1px solid var(--window-border);
}
.dock-item {
  --scale: 1;
  position: relative;
  background: transparent; border: none; padding: 0; cursor: pointer;
  width: 52px; height: 52px;
  display: flex; flex-direction: column; align-items: center; justify-content: flex-end;
  transform: scale(var(--scale));
  transform-origin: bottom center;
  transition: transform 80ms ease-out;
}
.dock-item svg { width: 100%; height: 100%; border-radius: 12px; box-shadow: 0 2px 4px rgba(0,0,0,0.3); }
.dock-label {
  position: absolute; top: -28px;
  background: rgba(20,20,20,0.85); color: #fff; font-size: 12px;
  padding: 2px 8px; border-radius: 4px;
  opacity: 0; pointer-events: none; transition: opacity 100ms;
  white-space: nowrap;
}
.dock-item:hover .dock-label { opacity: 1; }
.dock-item.running::after {
  content: ""; position: absolute; bottom: -6px;
  width: 4px; height: 4px; border-radius: 50%;
  background: rgba(120,120,120,0.9);
}
:root[data-theme="dark"] .dock-item.running::after { background: rgba(200,200,200,0.9); }
@keyframes dock-bounce {
  0%,100% { transform: scale(var(--scale)) translateY(0); }
  50%     { transform: scale(var(--scale)) translateY(-12px); }
}
.dock-item.bouncing svg { animation: dock-bounce 500ms ease-in-out 3; }

#lock-screen {
  position: fixed; inset: 0; z-index: 99999;
  background: var(--wallpaper-highlight), var(--wallpaper-base);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 10px; transition: opacity 600ms ease-out;
}
#lock-screen.dismissing { opacity: 0; pointer-events: none; }
.lock-avatar {
  width: 110px; height: 110px; border-radius: 50%;
  background: linear-gradient(135deg, #5b9bf0, #8e7af0);
  display: flex; align-items: center; justify-content: center;
  font-size: 48px; color: #fff; font-weight: 300;
  box-shadow: 0 6px 20px rgba(0,0,0,0.3);
  margin-bottom: 8px;
}
.lock-name { font-size: 18px; opacity: 0.85; }
.lock-time { font-size: 72px; font-weight: 200; }
.lock-date { font-size: 18px; opacity: 0.85; margin-bottom: 24px; }
.lock-input {
  background: rgba(255,255,255,0.18); border: 1px solid rgba(255,255,255,0.3);
  color: #fff; padding: 6px 10px; border-radius: 6px; width: 220px;
  font: inherit; outline: none;
}
.lock-input::placeholder { color: rgba(255,255,255,0.6); }
.lock-input:focus { border-color: rgba(255,255,255,0.6); }

.mc-tile { transition: transform 200ms ease-out; }
.mc-tile:hover { transform: scale(1.04); }
.mc-label {
  position: absolute; top: -22px; left: 0; right: 0; text-align: center;
  font-size: 12px; color: #fff; text-shadow: 0 1px 2px rgba(0,0,0,0.6);
}

.terminal {
  background: rgba(20, 20, 22, 0.95);
  color: #f5f5f7;
  font-family: "SF Mono", Menlo, Monaco, Consolas, monospace;
  font-size: 13px;
  padding: 10px 12px;
  height: 100%; overflow-y: auto;
  line-height: 1.45;
}
.terminal .t-line { white-space: pre-wrap; word-break: break-word; }
.terminal .t-prompt { color: #5ac8fa; margin-right: 6px; }
.terminal .t-prompt-line { display: flex; align-items: center; }
.terminal .t-input {
  flex: 1; background: transparent; border: none; outline: none;
  color: #f5f5f7; font: inherit; padding: 0; caret-color: #f5f5f7;
}
.terminal .t-dir { color: #5ac8fa; }

.safari { display: flex; flex-direction: column; height: 100%; background: #fff; color: #1d1d1f; }
:root[data-theme="dark"] .safari { background: #1c1c1e; color: #f5f5f7; }
.safari-tabbar {
  display: flex; gap: 2px; padding: 4px 4px 0 4px;
  background: rgba(230, 230, 232, 0.8); align-items: center;
}
:root[data-theme="dark"] .safari-tabbar { background: rgba(40, 40, 42, 0.8); }
.tab {
  display: flex; align-items: center; gap: 6px; padding: 4px 10px;
  background: rgba(0,0,0,0.06); border-radius: 6px 6px 0 0;
  max-width: 180px; min-width: 80px; font-size: 12px; cursor: pointer;
}
:root[data-theme="dark"] .tab { background: rgba(255,255,255,0.06); }
.tab.active { background: var(--window-bg); }
.tab-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }
.tab-close { background: transparent; border: none; cursor: pointer; color: inherit; opacity: 0.6; }
.tab-add { background: transparent; border: none; cursor: pointer; padding: 2px 8px; color: inherit; font-size: 16px; }
.safari-toolbar {
  display: flex; align-items: center; gap: 6px; padding: 6px 10px;
  background: var(--window-bg); border-bottom: 1px solid var(--window-border);
}
.tb-btn { background: transparent; border: none; font-size: 16px; cursor: pointer; color: inherit; padding: 2px 6px; border-radius: 4px; }
.tb-btn:hover { background: rgba(0,0,0,0.08); }
:root[data-theme="dark"] .tb-btn:hover { background: rgba(255,255,255,0.1); }
.addr { flex: 1; padding: 4px 10px; border-radius: 6px; border: 1px solid var(--window-border); background: rgba(0,0,0,0.04); color: inherit; font: inherit; outline: none; }
:root[data-theme="dark"] .addr { background: rgba(255,255,255,0.06); }
.safari-bookmarks { display: flex; gap: 4px; padding: 4px 10px; background: var(--window-bg); border-bottom: 1px solid var(--window-border); }
.bm { background: transparent; border: none; padding: 2px 8px; border-radius: 4px; cursor: pointer; color: inherit; font: inherit; font-size: 12px; }
.bm:hover { background: rgba(0,0,0,0.08); }
:root[data-theme="dark"] .bm:hover { background: rgba(255,255,255,0.1); }
.safari-viewport { flex: 1; overflow: auto; }
.safari-viewport iframe { width: 100%; height: 100%; border: 0; }
.safari-viewport h1 { font-size: 28px; font-weight: 600; margin: 24px 24px 12px; }
.safari-viewport p { margin: 8px 24px; line-height: 1.5; }
.safari-viewport .tile-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 12px; padding: 16px 24px; }
.safari-viewport .tile { background: rgba(0,0,0,0.05); padding: 24px 12px; border-radius: 10px; text-align: center; text-decoration: none; color: inherit; }
:root[data-theme="dark"] .safari-viewport .tile { background: rgba(255,255,255,0.06); }
.safari-viewport .card { margin: 12px 24px; padding: 16px; border-radius: 10px; background: rgba(0,0,0,0.04); }
:root[data-theme="dark"] .safari-viewport .card { background: rgba(255,255,255,0.06); }
.safari-viewport pre { background: rgba(0,0,0,0.08); padding: 12px; border-radius: 8px; margin: 12px 24px; overflow-x: auto; }
.safari-viewport .search-result { padding: 12px 24px; border-bottom: 1px solid var(--window-border); }
.safari-viewport .result-title { color: var(--accent); text-decoration: none; font-size: 18px; }
.safari-viewport .result-url { color: var(--secondary); font-size: 12px; }
.safari-viewport .result-snippet { font-size: 13px; line-height: 1.4; margin-top: 4px; }
.safari-status { padding: 4px 10px; font-size: 11px; background: var(--window-bg); border-top: 1px solid var(--window-border); color: var(--secondary); }

.finder, .notes, .calc, .photos, .settings { display: flex; height: 100%; background: var(--window-bg); color: var(--window-fg); }
.finder-sidebar { width: 180px; border-right: 1px solid var(--window-border); padding: 10px; overflow-y: auto; font-size: 12px; }
.sb-section + .sb-section { margin-top: 14px; }
.sb-head { font-size: 11px; color: var(--secondary); text-transform: uppercase; padding: 4px 6px; }
.finder-sidebar button { display: block; width: 100%; text-align: left; background: transparent; border: none; padding: 4px 8px; border-radius: 4px; color: inherit; font: inherit; cursor: pointer; }
.finder-sidebar button:hover { background: rgba(0,0,0,0.06); }
.tags { display: flex; flex-wrap: wrap; gap: 4px; padding: 4px 6px; }
.tags span { width: 14px; height: 14px; border-radius: 3px; display: inline-block; }
.finder-main { flex: 1; display: flex; flex-direction: column; }
.finder-toolbar { display: flex; align-items: center; gap: 8px; padding: 8px; border-bottom: 1px solid var(--window-border); }
.finder-toolbar .spacer { flex: 1; }
.finder-path { font-weight: 500; }
.finder-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)); gap: 16px; padding: 16px; overflow: auto; }
.finder-item { text-align: center; cursor: pointer; }
.finder-icon { width: 64px; height: 80px; margin: 0 auto 6px; border-radius: 6px; display: flex; align-items: flex-end; justify-content: center; color: #fff; font-size: 9px; padding: 4px; box-shadow: 0 2px 4px rgba(0,0,0,0.15); }
.finder-name { font-size: 12px; }
.finder-kind { font-size: 11px; color: var(--secondary); }

.notes-side { width: 200px; border-right: 1px solid var(--window-border); padding: 8px; overflow-y: auto; }
.notes-head { font-size: 14px; font-weight: 600; padding: 6px 8px; color: var(--secondary); }
.notes-item { padding: 6px 8px; border-radius: 6px; cursor: pointer; }
.notes-item:hover { background: rgba(0,0,0,0.06); }
.notes-item.active { background: var(--accent); color: #fff; }
.notes-item .t { font-size: 13px; font-weight: 500; }
.notes-item .d { font-size: 11px; opacity: 0.7; }
.notes-main { flex: 1; padding: 24px; overflow-y: auto; background: #fef9d8; color: #5a4a00; }
:root[data-theme="dark"] .notes-main { background: #2a2410; color: #f0e0a0; }
.notes-date { font-size: 12px; color: var(--secondary); }
.notes-title { font-size: 22px; font-weight: 600; margin: 4px 0 12px; }
.notes-body { line-height: 1.5; outline: none; min-height: 200px; }

.calc { flex-direction: column; background: #1d1d1f; color: #fff; padding: 12px; }
.calc-display { text-align: right; font-size: 56px; font-weight: 200; padding: 20px 12px; min-height: 80px; }
.calc-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; flex: 1; }
.calc button { background: #3a3a3c; color: #fff; border: none; border-radius: 50%; font-size: 22px; cursor: pointer; }
.calc button:hover { filter: brightness(1.2); }
.calc button.accent { background: #ff9500; }
.calc button.op { background: #5a5a5c; }
.calc button.zero { grid-column: span 2; border-radius: 36px; }

.photos { padding: 12px; overflow: auto; }
.photos-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.photo-tile { aspect-ratio: 1; border-radius: 6px; cursor: pointer; transition: transform 100ms; }
.photo-tile:hover { transform: scale(1.02); }
.lightbox { position: fixed; inset: 0; background: rgba(0,0,0,0.85); z-index: 9999; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px; }
.lightbox-img { width: 70vw; height: 60vh; max-width: 900px; border-radius: 6px; }
.lightbox-title { color: #fff; font-size: 16px; }
.lightbox-close { position: absolute; top: 20px; right: 20px; background: rgba(255,255,255,0.2); color: #fff; border: none; width: 32px; height: 32px; border-radius: 50%; font-size: 20px; cursor: pointer; }

.settings-side { width: 200px; border-right: 1px solid var(--window-border); padding: 8px; }
.set-side { width: 200px; border-right: 1px solid var(--window-border); padding: 8px; overflow-y: auto; }
.set-cat { display: block; width: 100%; text-align: left; background: transparent; border: none; padding: 6px 10px; border-radius: 6px; color: inherit; font: inherit; cursor: pointer; font-size: 13px; }
.set-cat:hover { background: rgba(0,0,0,0.06); }
.set-cat.active { background: var(--accent); color: #fff; }
.set-main { flex: 1; padding: 24px; overflow-y: auto; }
.set-main h2 { margin-top: 0; }
.theme-pick { display: flex; flex-direction: column; gap: 8px; margin: 16px 0; }
.theme-pick label { display: flex; align-items: center; gap: 8px; }
.muted { color: var(--secondary); }
