/* ============================================================
   TEMPEST OS — style.css
   Layout + window-manager mechanics. Visual design → theme.css
   ============================================================ */

*, *::before, *::after { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  overflow: hidden;
}

body {
  position: relative;
}

/* ---------- z-scale ----------
   desktop 0 · windows 100+ (JS) · menubar 900 · dock 950
   boot 8000 · crt 9999                                     */

/* ---------- menu bar ---------- */
#menubar {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: 32px;
  z-index: 900;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 10px;
  -webkit-user-select: none;
  user-select: none;
}
.menu-left, .menu-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

/* ---------- desktop ---------- */
#desktop {
  position: fixed;
  inset: 0;
}
.desktop-mark {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  text-align: center;
  pointer-events: none;
  -webkit-user-select: none;
  user-select: none;
}

/* ---------- windows: mechanics ---------- */
.window {
  position: fixed;
  display: flex;
  flex-direction: column;
  z-index: 100;
  transform-origin: 50% 50%;
}
.window[hidden] { display: none !important; }

.titlebar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  cursor: move;
}
.window-body {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  position: relative;
}

/* open / close: CRT power-on & power-off */
@keyframes win-open {
  0%   { transform: scale(0.65, 0.005); filter: brightness(2.6); }
  55%  { transform: scale(1.02, 0.82);  filter: brightness(1.4); }
  100% { transform: scale(1, 1);        filter: brightness(1); }
}
@keyframes win-close {
  0%   { transform: scale(1, 1);        filter: brightness(1); opacity: 1; }
  60%  { transform: scale(1.08, 0.1);   filter: brightness(2); opacity: 1; }
  100% { transform: scale(1.1, 0.004);  filter: brightness(2.4); opacity: 0; }
}
.window.opening { animation: win-open 240ms cubic-bezier(0.2, 0.9, 0.25, 1); }
.window.closing { animation: win-close 150ms ease-in forwards; pointer-events: none; }

/* dragging */
body.is-dragging { cursor: move; }
body.is-dragging iframe { pointer-events: none; }
body.is-dragging .window { transition: none !important; }

/* ---------- dock ---------- */
#dock {
  position: fixed;
  bottom: 12px;
  left: 50%;
  translate: -50% 0;
  z-index: 950;
  display: flex;
  gap: 4px;
  max-width: calc(100vw - 16px);
  overflow-x: auto;
  overscroll-behavior-x: contain;
  -webkit-user-select: none;
  user-select: none;
}
.dock-btn {
  position: relative;
  flex: 0 0 auto;
  display: grid;
  justify-items: center;
  gap: 5px;
  cursor: pointer;
}

/* ---------- boot screen ---------- */
#boot {
  position: fixed;
  inset: 0;
  z-index: 8000;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: space-between;
  padding: 48px 56px 32px;
  transition: opacity 220ms ease-out;
}
#boot.boot-done { opacity: 0; pointer-events: none; }
#boot[hidden] { display: none !important; }
#boot-log { margin: 0; white-space: pre-wrap; }

/* ---------- CRT overlay ---------- */
.crt,
.crt > * {
  position: fixed;
  inset: 0;
  pointer-events: none;
}
.crt { z-index: 9999; contain: strict; }
.crt-noise { inset: -50%; }
html.no-crt .crt { display: none; }

/* ---------- reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
  @keyframes win-fade-in  { from { opacity: 0; } }
  @keyframes win-fade-out { to   { opacity: 0; } }
  .window.opening { animation: win-fade-in 120ms ease-out; }
  .window.closing { animation: win-fade-out 120ms ease-out forwards; }
  .crt-noise, .crt-flicker { animation: none !important; }
}

/* ---------- compact layouts (narrow OR short, e.g. landscape phones) ----------
   must mirror the `mobile` matchMedia query in js/app.js */
@media (max-width: 600px), (max-height: 520px) {
  .window[data-app] {
    left: 6px !important;
    top: 42px !important;
    width: calc(100vw - 12px) !important;
    max-height: calc(100dvh - 42px - 108px);
  }
  #menubar { padding: 0 6px; }
  .menu-ver { display: none; }
  #dock { bottom: 8px; }
}
