:root {
  font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Noto Sans", "Noto Sans SC", sans-serif;
  color-scheme: dark;
  --text: #ededef;
  --muted: #b0b0b3;
  --surface: #242426;
  --surface-low: #1c1c1e;
  --surface-high: #2e2e30;
  --field: #343437;
  --hover: rgb(255 255 255 / 16%);
  --selected: rgb(255 255 255 / 16%);
  --primary: #fff;
  --on-primary: #000;
  --focus: rgb(255 255 255 / 28%);
  --shadow: 0 8px 28px rgb(0 0 0 / 38%);

  --panel-radius: 18px;
  --pill-radius: 999px;
  --glass: color-mix(in srgb, var(--surface-high) 82%, transparent);
  --panel: color-mix(in srgb, var(--surface) 86%, transparent);
  --frost: blur(20px) saturate(1.6);
  --ease-out: cubic-bezier(.16, 1, .3, 1);

  --graphite: linear-gradient(150deg, #222224, #1a1a1c);
  --ridge: url("./assets/twilight-ridge.webp");
  --tide: linear-gradient(145deg, #23353a, #141d23);
  --wallpaper: var(--graphite);
}

:root[data-theme="light"] {
  color-scheme: light;
  --text: #1d1d1d;
  --muted: #5e5e5f;
  --surface: #f4f4f5;
  --surface-low: #f8f8f9;
  --surface-high: #ededef;
  --field: #e8e8eb;
  --hover: rgb(24 24 27 / 8%);
  --selected: rgb(24 24 27 / 12%);
  --primary: #18181b;
  --on-primary: #fff;
  --focus: rgb(24 24 27 / 22%);
  --shadow: 0 8px 24px rgb(28 27 31 / 14%);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  background: #1c1c1e;
  color: var(--text);
}

button {
  padding: 0;
  border: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

button:focus-visible,
[role="tabpanel"]:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px var(--focus);
}

button:disabled { cursor: wait; opacity: .5; }

.icons {
  position: absolute;
  width: 0;
  height: 0;
  overflow: hidden;
}

.icon {
  width: 16px;
  height: 16px;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.65;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.mark { width: 20px; height: 20px; flex: none; }

#desktop {
  --desk-gap: 16px;
  --dock-bottom: max(12px, env(safe-area-inset-bottom));
  --dock-height: 40px;
  position: relative;
  isolation: isolate;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
}

.desktop-wallpaper,
.wallpaper-preview,
.wallpaper-swatch {
  background: var(--wallpaper) center / cover no-repeat;
  background-color: var(--surface-low);
}

.desktop-wallpaper { position: absolute; z-index: -1; inset: 0; }

.desktop-watermark {
  position: absolute;
  inset-block-end: max(18px, env(safe-area-inset-bottom));
  inset-inline-end: max(var(--desk-gap), env(safe-area-inset-right));
  display: grid;
  grid-template-columns: auto auto;
  align-items: center;
  column-gap: 5px;
  color: rgb(237 237 239 / 57%);
  font-size: 14px;
  text-shadow: 0 1px 3px rgb(0 0 0 / 65%);
  pointer-events: none;
}

.desktop-watermark .mark { width: 18px; height: 18px; }
.watermark-name { font-weight: 550; }
.watermark-version { grid-column: 2; font-size: 12px; }

.shortcuts {
  position: absolute;
  inset-block-start: max(var(--desk-gap), env(safe-area-inset-top));
  inset-inline-start: max(calc(var(--desk-gap) - 4px), env(safe-area-inset-left));
}

.shortcut {
  display: grid;
  justify-items: center;
  gap: 6px;
  width: 56px;
  padding: 6px 4px;
  border-radius: 12px;
  color: #ededef;
  font-size: 12px;
  text-shadow: 0 1px 2px rgb(0 0 0 / 65%);
}

.shortcut:hover { background: rgb(255 255 255 / 8%); }
.shortcut:focus-visible { box-shadow: 0 0 0 3px rgb(255 255 255 / 28%); }

.glass {
  background-color: var(--glass);
  -webkit-backdrop-filter: var(--frost);
  backdrop-filter: var(--frost);
}

.shortcut-icon {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: 12px;
  color: var(--text);
}
.shortcut-icon .icon { width: 20px; height: 20px; }

.taskbar-area {
  position: absolute;
  z-index: 3;
  bottom: 0;
  left: 50%;
  padding-bottom: var(--dock-bottom);
  pointer-events: none;
  translate: -50% 0;
}

.taskbar-reveal {
  position: absolute;
  inset: auto -10px 0;
  display: none;
  height: calc(var(--dock-bottom) + 4px);
  pointer-events: auto;
}

.taskbar {
  position: relative;
  display: flex;
  align-items: center;
  gap: 4px;
  pointer-events: auto;
  transition: transform 260ms var(--ease-out), opacity 210ms ease, visibility 0s;
}

.has-maximized-window .taskbar-reveal { display: block; }

.has-maximized-window .taskbar-area:not(:hover, :focus-within) .taskbar {
  transform: translateY(calc(var(--dock-bottom) + var(--dock-height)));
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: transform 260ms var(--ease-out), opacity 210ms ease, visibility 0s 260ms;
}

.taskbar > * {
  height: var(--dock-height);
  border-radius: var(--pill-radius);
}

.start-button {
  display: grid;
  place-items: center;
  width: var(--dock-height);
  transition: background-color 150ms ease;
}

.start-button .mark { width: 26px; height: 26px; }
.start-button:is(:hover, [aria-expanded="true"]) { background-color: var(--field); }

.task-pill { display: flex; align-items: stretch; }

.task-button {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 0 12px;
  border-radius: var(--pill-radius);
  color: var(--muted);
  font-size: 12.5px;
  white-space: nowrap;
}
.task-button:is(:hover, [aria-expanded="true"]) { color: var(--text); background: var(--hover); }

.clock-pill {
  display: grid;
  min-width: 60px;
  padding: 0 12px;
  place-items: center;
  font-size: 13px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.start-menu,
.desktop-menu {
  position: absolute;
  z-index: 3;
  background-color: var(--panel);
  box-shadow: var(--shadow);
  border-radius: var(--panel-radius);
}

.start-menu {
  left: 50%;
  bottom: calc(var(--dock-bottom) + var(--dock-height) + 6px);
  width: min(210px, calc(100dvw - 24px));
  padding: 12px;
  translate: -50% 0;
  pointer-events: auto;
  animation: reveal 160ms var(--ease-out);
}

.start-menu h2 {
  margin: 0 0 6px 8px;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
}

.launch-row,
.menu-row {
  display: flex;
  align-items: center;
  width: 100%;
  min-height: 34px;
  gap: 8px;
  padding: 0 10px;
  border-radius: var(--pill-radius);
  font-size: 12.5px;
  text-align: start;
}

.launch-row { background: var(--surface-high); }
.launch-row:hover, .menu-row:hover { background: var(--hover); }
.desktop-menu { width: 148px; padding: 6px; }

#window-area {
  --window-top-inset: max(12px, env(safe-area-inset-top));
  --window-right-inset: max(12px, env(safe-area-inset-right));
  --window-bottom-inset: calc(var(--dock-bottom) + var(--dock-height) + 12px);
  --window-left-inset: max(12px, env(safe-area-inset-left));
  position: absolute;
  z-index: 2;
  inset: var(--window-top-inset) var(--window-right-inset)
    var(--window-bottom-inset) var(--window-left-inset);
  pointer-events: none;
}

.settings-window {
  --window-width: 516px;
  --window-height: 414px;
  --window-x-limit: max(0px, calc(100% - var(--window-width)));
  --window-y-limit: max(0px, calc(100% - var(--window-height)));
  --window-duration: 380;
  --window-easing: cubic-bezier(.28, .08, .22, 1);
  --window-motion: calc(var(--window-duration) * 1ms) var(--window-easing);
  position: absolute;
  top: clamp(0px, var(--window-y, calc(var(--window-y-limit) / 2)), var(--window-y-limit));
  left: clamp(0px, var(--window-x, calc(var(--window-x-limit) / 2)), var(--window-x-limit));
  display: flex;
  flex-direction: column;
  width: min(100%, var(--window-width));
  height: min(100%, var(--window-height));
  overflow: hidden;
  border-radius: var(--panel-radius);
  background-color: var(--panel);
  box-shadow: var(--shadow);
  pointer-events: auto;
  transition:
    top var(--window-motion),
    left var(--window-motion),
    width var(--window-motion),
    height var(--window-motion),
    border-radius var(--window-motion),
    box-shadow var(--window-motion);
}

.settings-window.is-maximized {
  top: calc(-1 * var(--window-top-inset));
  left: calc(-1 * var(--window-left-inset));
  width: calc(100% + var(--window-left-inset) + var(--window-right-inset));
  height: calc(100% + var(--window-top-inset) + var(--window-bottom-inset));
  border-radius: 0;
  box-shadow: none;
}

.settings-window:has(.window-titlebar.is-dragging) { transition: none; }

.settings-window.is-animating {
  transition: none;
  transform-origin: top left;
}

.window-titlebar {
  display: flex;
  flex: none;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 10px 10px 18px;
  touch-action: none;
  cursor: grab;
}

.window-titlebar.is-dragging { cursor: grabbing; }
.is-maximized .window-titlebar {
  padding-block-start: max(10px, env(safe-area-inset-top));
  padding-inline-start: max(18px, env(safe-area-inset-left));
  padding-inline-end: max(10px, env(safe-area-inset-right));
  cursor: default;
}
.window-titlebar h1 { margin: 0; font-size: 15px; font-weight: 700; }
.window-titlebar h1:focus { outline: none; }

.window-controls {
  --dot-scale: 1;
  --dot-spread: 0;
  --group-offset: 0px;
  --dot-fill: var(--field);
  --dot-duration: 380ms;
  --dot-easing: cubic-bezier(.36, .02, .24, 1);
  --icon-opacity: 1;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex: none;
  gap: 3px;
  width: 104px;
  height: 32px;
  padding-inline: 4px;
}

.window-button {
  position: relative;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  color: var(--text);
}

.window-button:first-child { --dot-offset: 20px; }
.window-button:last-child { --dot-offset: -20px; }

.window-button-face {
  position: absolute;
  inset: 2px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background-color: var(--dot-fill);
  pointer-events: none;
  transform: translateX(calc(var(--group-offset) + var(--dot-offset, 0px) * var(--dot-spread))) scale(var(--dot-scale));
  transition:
    transform var(--dot-duration) var(--dot-easing),
    background-color var(--dot-duration) var(--dot-easing);
}

.window-button:hover .window-button-face {
  background-color: color-mix(in srgb, var(--field), var(--text) 12%);
}

.window-button-face .icon {
  width: 13px;
  height: 13px;
  opacity: var(--icon-opacity);
  transition: opacity var(--dot-duration) var(--dot-easing);
}

@media (hover: hover) and (pointer: fine) {
  .window-controls:not(:hover, :has(.window-button:focus-visible)) {
    --dot-scale: .29;
    --dot-spread: 1;
    --group-offset: 18px;
    --dot-fill: color-mix(in srgb, var(--muted) 67%, transparent);
    --dot-duration: 320ms;
    --icon-opacity: 0;
  }
}

.window-body {
  display: flex;
  flex: 1;
  flex-direction: column;
  width: 100%;
  max-width: 650px;
  min-height: 0;
  margin: 0 auto;
}

.settings-nav { flex: none; padding: 2px 18px 12px; }

.settings-tabs {
  display: flex;
  gap: 4px;
  padding: 3px;
  border-radius: 12px;
  background: var(--field);
}

.settings-tab {
  flex: 1;
  padding: 6px 12px;
  border-radius: 9px;
  color: var(--muted);
  font-size: 12.5px;
  font-weight: 500;
}

.settings-tab:hover { color: var(--text); }
.settings-tab[aria-selected="true"] { background: var(--selected); color: var(--text); font-weight: 600; }

.settings-content {
  flex: 1;
  min-width: 0;
  padding: 0 18px 20px;
  overflow: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
}

.wallpaper-preview {
  height: clamp(92px, 19dvh, 151px);
  border-radius: 14px;
}

.wallpaper-options {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
  margin-top: 8px;
}

.wallpaper-option {
  display: grid;
  gap: 5px;
  min-width: 0;
  padding: 5px 5px 4px;
  border-radius: 11px;
  color: var(--muted);
  font-size: 12px;
  text-align: center;
}

.wallpaper-option:is(:hover, [aria-pressed="true"]) { background: var(--selected); color: var(--text); }
.wallpaper-option[aria-pressed="true"] { font-weight: 650; }
.wallpaper-swatch { display: block; height: 49px; border-radius: 8px; }
[data-wallpaper="graphite"] .wallpaper-swatch { --wallpaper: var(--graphite); }
[data-wallpaper="ridge"] .wallpaper-swatch { --wallpaper: var(--ridge); }
[data-wallpaper="tide"] .wallpaper-swatch { --wallpaper: var(--tide); }

.upload-button {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 34px;
  margin-top: 10px;
  padding: 0 14px;
  border-radius: var(--pill-radius);
  background: var(--surface-high);
  font-size: 12.5px;
}

.upload-button:hover { background: var(--hover); }
.upload-status { margin: 6px 0 0; color: var(--muted); font-size: 12px; overflow-wrap: anywhere; }
.upload-status:empty { display: none; }

.section-label { margin: 0 0 8px; font-size: 13px; font-weight: 600; }

.theme-options {
  display: inline-flex;
  gap: 2px;
  max-width: 100%;
  padding: 3px;
  border-radius: var(--pill-radius);
  background: var(--field);
}

.theme-option {
  min-height: 28px;
  padding: 0 10px;
  border-radius: var(--pill-radius);
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.theme-option:hover { background: var(--hover); color: var(--text); }
.theme-option[aria-pressed="true"] { background: var(--primary); color: var(--on-primary); }
.theme-caption { display: flex; align-items: center; gap: 5px; }
.theme-caption .icon { width: 13px; height: 13px; }

@keyframes reveal {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: none; }
}

@media (max-width: 520px) {
  .desktop-watermark { inset-block-end: calc(var(--dock-bottom) + var(--dock-height) + 10px); }
}

@media (max-width: 360px) {
  .theme-caption .icon { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  .settings-window { --window-duration: 0; }

  .start-button, .start-menu, .window-button-face, .window-button-face .icon {
    transition: none;
    animation: none;
  }

  .taskbar, .has-maximized-window .taskbar-area:not(:hover, :focus-within) .taskbar { transition: none; }
}
