.window-layer {
  position: fixed;
  inset: 0;
  z-index: 50;
  pointer-events: none;
}

.window-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(8, 6, 12, 0.5);
  opacity: 0;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  transition: opacity 0.35s var(--ease-os);
}

.window-layer.is-open {
  pointer-events: auto;
}

.window-layer.is-open .window-backdrop {
  opacity: 1;
}

.app-window {
  position: fixed;
  display: flex;
  flex-direction: column;
  background: var(--window-bg);
  color: var(--window-ink);
  box-shadow: 0 40px 90px rgba(0, 0, 0, 0.5), 0 4px 18px rgba(0, 0, 0, 0.3);
  overflow: hidden;
  opacity: 0;
  will-change: left, top, width, height, border-radius, opacity;
  transition: left 0.46s var(--ease-os), top 0.46s var(--ease-os),
    width 0.46s var(--ease-os), height 0.46s var(--ease-os),
    border-radius 0.46s var(--ease-os), opacity 0.3s ease;
}

.window-layer.is-open .app-window {
  opacity: 1;
}

.window-layer.is-closing .window-backdrop {
  opacity: 0;
}

.window-layer.is-closing .app-window {
  opacity: 0;
}

/* ===== Title bar — desktop (macOS) ===== */
.app-window__titlebar {
  flex: 0 0 auto;
  height: 38px;
  display: flex;
  align-items: center;
  padding: 0 14px;
  background: #f6f6f8;
  border-bottom: 1px solid rgba(0, 0, 0, 0.08);
  position: relative;
  user-select: none;
}

.is-desktop .app-window__titlebar {
  cursor: grab;
}

.is-desktop .app-window.is-dragging .app-window__titlebar {
  cursor: grabbing;
}

.traffic-lights {
  display: flex;
  align-items: center;
  gap: 8px;
  z-index: 1;
}

.traffic {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  padding: 0;
  border: none;
}

.traffic--red {
  background: var(--traffic-red);
}

.traffic--yellow {
  background: var(--traffic-yellow);
}

.traffic--green {
  background: var(--traffic-green);
}

button.traffic--red {
  cursor: pointer;
}

.app-window__title {
  position: absolute;
  left: 0;
  right: 0;
  text-align: center;
  font-size: 13px;
  font-weight: 600;
  color: #3a3a3e;
  margin: 0;
  pointer-events: none;
}

.app-window__close-mobile {
  display: none;
}

.app-window__body {
  flex: 1 1 auto;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  background: var(--window-bg);
}

/* ===== Fullscreen variant — mobile / tablet (iOS/iPadOS) ===== */
.is-mobile .app-window__titlebar {
  height: 46px;
  background: var(--window-bg);
  border-bottom: none;
  justify-content: center;
}

.is-mobile .traffic-lights {
  display: none;
}

.is-mobile .app-window__titlebar::before {
  content: "";
  width: 36px;
  height: 5px;
  border-radius: 3px;
  background: rgba(0, 0, 0, 0.18);
}

.is-mobile .app-window__title {
  bottom: 8px;
  top: auto;
  font-size: 12px;
  color: rgba(0, 0, 0, 0.45);
}

.is-mobile .app-window__close-mobile {
  display: flex;
  align-items: center;
  justify-content: center;
  position: absolute;
  right: 10px;
  top: 6px;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.06);
  font-size: 14px;
  color: #3a3a3e;
}

@media (prefers-reduced-motion: reduce) {
  .app-window,
  .window-backdrop,
  #wallpaper {
    transition-duration: 0.01ms !important;
    animation: none !important;
  }
}
