#windows {
  position: absolute;
  inset: 0;
  z-index: 10;
  pointer-events: none;
  isolation: isolate;
}

.window {
  position: absolute;
  min-width: 320px;
  min-height: 200px;
  display: flex;
  flex-direction: column;
  background: var(--win-bg);
  color: var(--fg);
  border-radius: var(--win-radius);
  box-shadow: var(--shadow-win);
  border: 1px solid var(--border);
  overflow: hidden;
  pointer-events: auto;
  transform-origin: center;
  animation: win-open var(--win-duration) ease;
}
.window.unfocused {
  background: var(--win-unfocused);
  box-shadow: 0 6px 22px rgba(0, 0, 0, 0.28);
}
.window.maximized {
  border-radius: 0;
  border-color: transparent;
}
.window.minimizing {
  animation: win-min var(--win-duration) ease forwards;
}
.window.closing {
  animation: win-close var(--win-duration) ease forwards;
}
.window.snapping { transition: left var(--snap-duration) ease, top var(--snap-duration) ease, width var(--snap-duration) ease, height var(--snap-duration) ease; }

@keyframes win-open {
  from { opacity: 0; transform: scale(0.94); }
  to { opacity: 1; transform: none; }
}
@keyframes win-close {
  to { opacity: 0; transform: scale(0.92); }
}
@keyframes win-min {
  to { opacity: 0; transform: scale(0.4) translateY(40px); }
}

.titlebar {
  height: var(--titlebar-h);
  flex: 0 0 var(--titlebar-h);
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 8px;
  padding: 0 10px;
  background: var(--win-header);
  cursor: default;
}
.window.unfocused .titlebar { filter: saturate(0.7) brightness(0.96); }

.win-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  padding-left: 4px;
}
.win-btn {
  width: var(--ctrl-size);
  height: var(--ctrl-size);
  border-radius: 50%;
  background: #5a5a5a;
  position: relative;
  display: grid;
  place-items: center;
}
.window.unfocused .win-btn { background: #4a4a4a; }
.win-btn.close { background: #e95420; }
.window.unfocused .win-btn.close { background: #a84a2c; }
.win-btn::before {
  content: "";
  width: 8px;
  height: 8px;
  opacity: 0;
  background: center / contain no-repeat;
}
.titlebar:hover .win-btn::before, .win-btn:focus-visible::before { opacity: 1; }
.win-btn.close::before {
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 8 8'><path stroke='%23620e0e' stroke-width='1.4' d='M1.4 1.4l5.2 5.2M6.6 1.4L1.4 6.6'/></svg>");
}
.win-btn.min::before {
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 8 8'><path stroke='%23111111' stroke-width='1.4' d='M1.5 4h5'/></svg>");
}
.win-btn.max::before {
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 8 8'><rect x='1.6' y='1.6' width='4.8' height='4.8' rx='0.6' fill='none' stroke='%23111111' stroke-width='1.2'/></svg>");
}
.win-btn:hover { filter: brightness(1.08); }

.win-title {
  text-align: center;
  font-size: 13.5px;
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  pointer-events: none;
}
.win-extra { display: flex; align-items: center; gap: 4px; min-width: 62px; justify-content: flex-end; }

.window-body {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: var(--win-bg);
  overflow: hidden;
}
.window-body > * { min-height: 0; flex: 1; }

.resize-h {
  position: absolute;
  z-index: 3;
}
.resize-h.n, .resize-h.s { left: 8px; right: 8px; height: 6px; cursor: ns-resize; }
.resize-h.e, .resize-h.w { top: 8px; bottom: 8px; width: 6px; cursor: ew-resize; }
.resize-h.n { top: 0; }
.resize-h.s { bottom: 0; }
.resize-h.e { right: 0; }
.resize-h.w { left: 0; }
.resize-h.nw, .resize-h.ne, .resize-h.sw, .resize-h.se {
  width: 10px; height: 10px;
}
.resize-h.nw { top: 0; left: 0; cursor: nwse-resize; }
.resize-h.se { bottom: 0; right: 0; cursor: nwse-resize; }
.resize-h.ne { top: 0; right: 0; cursor: nesw-resize; }
.resize-h.sw { bottom: 0; left: 0; cursor: nesw-resize; }
.window.maximized .resize-h { display: none; }
