/* Window frame: Luna-style blue border, gradient title bar, CSS-drawn controls. */

.window {
  position: absolute;
  display: flex;
  flex-direction: column;
  min-width: 200px;
  min-height: 120px;
  overflow: hidden;
  border: 3px solid var(--frame);
  border-top-width: 0;
  border-radius: var(--radius-top) var(--radius-top) 0 0;
  background: var(--frame);
  box-shadow: 2px 4px 14px rgb(0 0 0 / 0.38);
  animation: window-open 140ms ease-out;
}

/* The frame takes focus programmatically; the title bar colour already shows it. */
.window:focus { outline: none; }

.window:not(.is-active) { border-color: var(--frame-inactive); background: var(--frame-inactive); box-shadow: 1px 3px 10px rgb(0 0 0 / 0.25); }

.window__titlebar {
  display: flex;
  flex: none;
  align-items: center;
  gap: 5px;
  height: 30px;
  padding: 0 5px 0 7px;
  border-radius: var(--radius-top) var(--radius-top) 0 0;
  background:
    linear-gradient(90deg, rgb(255 255 255 / 0.18), transparent 6px, transparent calc(100% - 6px), rgb(0 0 0 / 0.12)),
    linear-gradient(180deg, var(--title-2) 0%, var(--title-1) 9%, #0054e9 45%, #0060f6 82%, #0a5ce6 92%, #0036c8 100%);
  box-shadow: inset 0 1px 0 var(--title-hi);
  color: var(--title-text);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

.window:not(.is-active) .window__titlebar { background: linear-gradient(180deg, #b7cdf3 0%, var(--title-inactive-1) 12%, var(--title-inactive-1) 60%, var(--title-inactive-2) 100%); box-shadow: inset 0 1px 0 #c9d8f6; }

.window__icon { flex: none; width: 16px; height: 16px; }

.window__title {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  font-family: var(--font-title);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.01em;
  line-height: 1;
  white-space: nowrap;
  text-overflow: ellipsis;
  text-shadow: 1px 1px 0 #0a1883;
}

.window:not(.is-active) .window__title { color: #13307a; text-shadow: none; }

.window__controls { display: flex; flex: none; gap: 2px; }

.window__btn {
  position: relative;
  width: 21px;
  height: 21px;
  padding: 0;
  border: 1px solid #fff;
  border-radius: 3px;
  background: radial-gradient(circle at 85% 85%, #0043cf 0%, #2663e0 45%, #4c85ee 70%, #a8c4f6 92%, #fff 100%);
  box-shadow: 0 0 0 1px rgb(0 0 0 / 0.08);
}

.window__btn--close { background: radial-gradient(circle at 85% 85%, #b83200 0%, #d8541f 45%, #e47a4a 70%, #f8c7ae 92%, #fff 100%); }

.window__btn:hover { filter: brightness(1.18); }

.window__btn:active { filter: brightness(0.82); }

.window__btn:focus-visible { outline: 1px dotted #fff; outline-offset: 1px; }

.window:not(.is-active) .window__btn { opacity: 0.72; }

.window__btn::before,
.window__btn::after { content: ""; position: absolute; box-sizing: border-box; }

/* Minimize: a short bar at the bottom left */
.window__btn--min::before {
  left: 4px;
  bottom: 3px;
  width: 7px;
  height: 3px;
  background: #fff;
}

/* Maximize: one square with a thick top edge */
.window__btn--max::before {
  left: 4px;
  top: 3px;
  width: 11px;
  height: 11px;
  border: 1px solid #fff;
  border-top-width: 3px;
}

/* Restore: two overlapping squares */
.window.is-maximized .window__btn--max::before {
  left: 3px;
  top: 7px;
  width: 9px;
  height: 9px;
  border-top-width: 2px;
}

.window.is-maximized .window__btn--max::after {
  left: 6px;
  top: 3px;
  width: 9px;
  height: 9px;
  border: 1px solid #fff;
  border-top-width: 2px;
  clip-path: polygon(0 0, 100% 0, 100% 100%, 6px 100%, 6px 4px, 0 4px);
}

/* Close: a bold cross */
.window__btn--close::before,
.window__btn--close::after {
  left: 50%;
  top: 50%;
  width: 13px;
  height: 2px;
  border-radius: 1px;
  background: #fff;
}

.window__btn--close::before { transform: translate(-50%, -50%) rotate(45deg); }

.window__btn--close::after { transform: translate(-50%, -50%) rotate(-45deg); }

.window__body {
  position: relative;
  flex: 1;
  min-height: 0;
  overflow: auto;
  background: var(--face);
  color: var(--ink);
  container-type: inline-size;
  container-name: winbody;
  overscroll-behavior: contain;
  user-select: text;
  -webkit-user-select: text;
}

.window.is-maximized { border-width: 0; border-radius: 0; }

.window.is-maximized .window__titlebar { border-radius: 0; }

.window.is-dragging,
.window.is-dragging .window__body { user-select: none; -webkit-user-select: none; }

.window.is-dragging .window__titlebar { cursor: move; }

@keyframes window-open {
  from { opacity: 0; transform: scale(0.97); }
  to { opacity: 1; transform: none; }
}

@media (prefers-reduced-motion: reduce) {
  .window { animation: none; }
}

/* Compact: every window fills the desktop area */
@media (max-width: 699px) {
  .window {
    inset: 0 !important;
    width: auto !important;
    height: auto !important;
    min-width: 0;
    border-width: 0;
    border-radius: 0;
  }

  .window__titlebar { border-radius: 0; }
}
