/* 준환 OS 2004 — window chrome (wm.js). Pastel glossy title bars, candy buttons. */

#windows {
  position: fixed;
  inset: 0 0 var(--taskbar-h) 0;
  z-index: 30;
  pointer-events: none;
}

.win {
  position: absolute;
  display: flex;
  flex-direction: column;
  min-width: 260px;
  min-height: 180px;
  border: 1px solid var(--c-win-line);
  border-radius: 12px;
  background: var(--c-paper);
  box-shadow: var(--sh-3), inset 0 0 0 1px rgba(255, 255, 255, 0.6);
  overflow: hidden;
  pointer-events: auto;
  transform-origin: 50% 30%;
}
.win:focus-visible { outline-offset: -1px; box-shadow: var(--sh-3); }
.win:not(.is-active) { box-shadow: var(--sh-2); border-color: #a3b6c9; }

.win.is-opening { animation: win-in 200ms var(--ease-out); }
.win.is-closing { animation: win-out 150ms ease-in forwards; pointer-events: none; }
.win.is-dragging { user-select: none; }
.win.is-dragging .win-titlebar { cursor: grabbing; }
@keyframes win-in {
  from { opacity: 0; transform: translateY(10px) scale(0.965); }
  to { opacity: 1; transform: none; }
}
@keyframes win-out {
  to { opacity: 0; transform: translateY(6px) scale(0.97); }
}

.win.is-max {
  left: 0 !important;
  top: 0 !important;
  width: 100% !important;
  height: 100% !important;
  border-radius: 0;
}

/* ---------- title bar ---------- */
.win-titlebar {
  position: relative;
  display: flex;
  align-items: center;
  gap: 8px;
  flex: none;
  height: 38px;
  padding: 0 6px 0 12px;
  border-bottom: 1px solid #8fb6d8;
  background: linear-gradient(180deg, var(--c-title-1) 0%, var(--c-title-2) 48%, var(--c-title-3) 52%, var(--c-title-4) 100%);
  color: var(--c-title-ink);
  cursor: grab;
  touch-action: none;
  user-select: none;
}
.win:not(.is-active) .win-titlebar {
  border-bottom-color: #c0ccd8;
  background: linear-gradient(180deg, var(--c-title-off-1) 0%, var(--c-title-off-2) 50%, var(--c-title-off-3) 100%);
  color: var(--c-title-off-ink);
}
.win-titlebar::after {
  /* a thin mint line under the gloss, the 2004 touch */
  content: "";
  position: absolute;
  left: 0; right: 0; bottom: -1px;
  height: 2px;
  background: linear-gradient(90deg, #5fd3c4, #6db7f2 60%, #b7a6f5);
  opacity: 0.9;
}
.win:not(.is-active) .win-titlebar::after { opacity: 0; }

.win-icon {
  flex: none;
  width: 20px;
  height: 20px;
  filter: drop-shadow(0 1px 0 rgba(255, 255, 255, 0.8));
}
.win-title {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  font-size: 14px;
  font-weight: 800;
  letter-spacing: -0.01em;
  white-space: nowrap;
  text-overflow: ellipsis;
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.85);
}

.win-controls { display: flex; gap: 4px; flex: none; }
.win-btn {
  display: grid;
  place-items: center;
  width: 28px;
  height: 24px;
  border: 1px solid #7f9fbf;
  border-radius: 7px;
  background: var(--gloss), linear-gradient(180deg, #ffffff, #d5e5f3);
  color: var(--c-navy);
  box-shadow: var(--sh-inset), 0 1px 1px rgba(12, 34, 64, 0.16);
  transition: filter var(--t-fast), transform var(--t-fast);
}
.win-btn svg {
  width: 16px;
  height: 16px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.2;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.win-btn:hover { filter: brightness(1.05) saturate(1.2); }
.win-btn:active { transform: translateY(1px); }
.win-btn--close {
  border-color: #8e1a25;
  background: var(--gloss-soft), linear-gradient(180deg, #c42a38, #a11d29);
  color: #fff;
}
.win:not(.is-active) .win-btn { filter: saturate(0.4); }
.win:not(.is-active) .win-btn:hover { filter: none; }

/* back button only shows on phones */
.win-back {
  display: none;
  align-items: center;
  gap: 2px;
  flex: none;
  height: 34px;
  padding: 0 10px 0 4px;
  border: 1px solid #7f9fbf;
  border-radius: var(--r-pill);
  background: var(--gloss), linear-gradient(180deg, #ffffff, #d5e5f3);
  color: var(--c-navy);
  font-size: 14px;
  font-weight: 800;
  box-shadow: var(--sh-inset);
}
.win-back svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.4;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* ---------- body ---------- */
.win-body {
  position: relative;
  flex: 1;
  min-height: 0;
  overflow: auto;
  overscroll-behavior: contain;
  background: var(--c-paper);
  color: var(--c-ink);
}
.win-body > * { min-height: 100%; }

/* ---------- taskbar window buttons ---------- */
.tb-win {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  flex: 0 1 184px;
  min-width: 44px;
  height: 34px;
  padding: 0 12px 0 8px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 9px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.12), rgba(255, 255, 255, 0.04));
  color: var(--c-bar-ink);
  font-size: 13px;
  font-weight: 700;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.12);
  transition: background var(--t-fast);
}
.tb-win:hover { background: linear-gradient(180deg, rgba(255, 255, 255, 0.2), rgba(255, 255, 255, 0.08)); }
.tb-win.is-active {
  border-color: rgba(143, 243, 255, 0.55);
  background: linear-gradient(180deg, rgba(120, 200, 255, 0.42), rgba(40, 120, 200, 0.32));
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.3), 0 0 10px rgba(110, 200, 255, 0.25);
}
.tb-win.is-min { color: var(--c-bar-ink-2); }
.tb-win.is-min .tb-win-icon { opacity: 0.75; }
.tb-win-icon { flex: none; width: 18px; height: 18px; }
.tb-win-label {
  min-width: 0;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}
/* many windows (wm.js sets is-crowded): icon-only buttons, the title stays in the tooltip and aria-label */
.tb-windows.is-crowded .tb-win { flex: 0 0 44px; justify-content: center; padding: 0; }
.tb-windows.is-crowded .tb-win-label { display: none; }

/* ---------- phones: every window is a full-screen panel ---------- */
@media (max-width: 767.98px) {
  .win {
    left: 0 !important;
    top: 0 !important;
    width: 100% !important;
    height: 100% !important;
    min-width: 0;
    border: 0;
    border-radius: 0;
    box-shadow: none;
  }
  .win.is-opening { animation: panel-in 220ms var(--ease-out); }
  .win:not(.is-active) { visibility: hidden; }
  .win-titlebar {
    height: 50px;
    padding: 0 8px;
    cursor: default;
  }
  .win-back { display: inline-flex; }
  .win-btn--min, .win-btn--max { display: none; }
  .win-btn { width: 36px; height: 34px; }
  .win-title { font-size: 15px; }
  .tb-win { flex: 0 0 auto; padding: 0 8px; }
  .tb-win-label { display: none; }
  @keyframes panel-in {
    from { opacity: 0; transform: translateY(24px); }
    to { opacity: 1; transform: none; }
  }
}
