/* ============================================================
   layout.css — Scene/stage (CRT), boot, desktop, taskbar, start menu
   ============================================================ */

/* ===================== SCENE / STAGE (CRT frame) ===================== */
:root { --scene-w: 3344px; --scene-h: 1882px; }   /* CRT_DESK.png native size */

/* dim "room" behind the desk, so the scene reads as a focal object */
body.framed { background: radial-gradient(circle at 50% 36%, #23272f 0%, #0c0d10 72%, #050506 100%); }

/* the CRT-on-a-bench photo, scaled (by stage.js) to fit the viewport */
#scene {
  position: absolute; top: 50%; left: 50%;
  width: var(--scene-w); height: var(--scene-h);
  transform-origin: center center;
  transform: translate(-50%, -50%) scale(1);
  background: url("../assets/CRT_DESK.png") center / 100% 100% no-repeat;
  will-change: transform;
}

/* the OS lives in the monitor's transparent screen cutout
   (889,304 → 2447,1356  =  1558 × 1052 in the 3344×1882 image).
   To keep the OS's UI density, it renders at a ~883×596 internal
   resolution and is scaled up to physically fill the cutout.
   keep these numbers in sync with stage.js SCREEN */
#stage {
  position: absolute;
  left: 889px; top: 304px;
  width: 882.67px; height: 596px;          /* internal resolution */
  transform: scale(1.7651);                /* fills 1558×1052 cutout */
  transform-origin: top left;
  overflow: hidden;
  background: #3a6ea5;
  box-shadow: inset 0 0 22px rgba(0,0,0,.5);   /* seat the picture into the tube */
}

/* always-on CRT glass: fakes a convex (bulged) tube with light, not geometry —
   a specular sheen toward the top + a vignette whose corners darken faster than
   the edges, which the eye reads as curvature. */
.glass {
  position: absolute; inset: 0; z-index: 8500; pointer-events: none;
  background:
    /* soft light pooling on the convex glass (upper-centre) */
    radial-gradient(115% 78% at 50% 24%, rgba(255,255,255,.11), rgba(255,255,255,0) 55%),
    /* diagonal glare streak */
    linear-gradient(128deg, rgba(255,255,255,.12) 0%, rgba(255,255,255,.03) 15%, rgba(255,255,255,0) 30%),
    /* curvature vignette — corners darker than centre */
    radial-gradient(135% 135% at 50% 50%, rgba(0,0,0,0) 47%, rgba(0,0,0,.12) 73%, rgba(0,0,0,.46) 100%);
  box-shadow: inset 0 0 38px rgba(0,0,0,.22);
}

/* ===================== BOOT ===================== */
.boot {
  position: absolute; inset: 0; z-index: 9000;
  background: #000;
  display: flex; align-items: center; justify-content: center;
}
.boot-gif {
  width: 100%;
  height: 100%;
  object-fit: contain;     /* fill the screen area, keep aspect (black bars are black-on-black) */
  image-rendering: auto;
}

/* ===================== DESKTOP ===================== */
.desktop {
  position: absolute; inset: 0; bottom: var(--taskbar-h);
  background-color: #5b8fd9;
  background-image: url("../assets/bliss.jpg");
  background-size: cover; background-position: center;
  overflow: hidden;
}
.window-layer { position: absolute; inset: 0; pointer-events: none; }
.window-layer > .window { pointer-events: auto; }

/* Desktop icons */
.desktop-icons {
  position: absolute; top: 8px; left: 8px;
  display: flex; flex-direction: column; flex-wrap: wrap;
  align-content: flex-start;
  gap: 2px 6px; max-height: 100%;
}
.desktop-icon {
  width: 84px; padding: 6px 4px 8px; border: 1px solid transparent;
  display: flex; flex-direction: column; align-items: center; gap: 5px;
  cursor: pointer; text-align: center;
}
.desktop-icon .icon-img { width: 38px; height: 38px; filter: drop-shadow(1px 1px 1px rgba(0,0,0,.4)); }
.desktop-icon .icon-img svg { width: 100%; height: 100%; display: block; }
.desktop-icon .icon-label {
  color: #fff; font-size: 12.5px; line-height: 1.2;
  text-shadow: 1px 1px 1px rgba(0,0,0,.9), 0 0 2px rgba(0,0,0,.6);
  padding: 1px 3px; max-width: 100%;
}
.desktop-icon.selected { border-color: rgba(255,255,255,.5); background: rgba(11,53,120,.45); }
.desktop-icon.selected .icon-img { filter: drop-shadow(0 0 0 transparent) hue-rotate(0); }
.desktop-icon.selected .icon-label { background: var(--select-blue); border-radius: 1px; }
.desktop-icon:focus-visible { outline: 1px dotted #fff; }

.selection-box {
  position: absolute; z-index: 5;
  border: 1px dotted #fff; background: rgba(49,106,197,.25);
  pointer-events: none;
}

/* ===================== WINDOWS (XP Luna frame) ===================== */
.window {
  position: absolute;
  min-width: 240px; min-height: 130px;
  /* inactive frame by default */
  background: #6d8fda;
  border: 1px solid #4069b8;
  border-radius: 8px 8px 0 0;
  padding: 0 0 4px;                 /* 4px blue frame at the bottom */
  display: flex; flex-direction: column;
  box-shadow: 2px 5px 16px rgba(0,0,0,.45);
  transform-origin: center;
  animation: win-open .14s ease-out;
}
.window.active {
  background: var(--luna-frame);
  border-color: var(--luna-frame-edge);
  box-shadow: 3px 7px 22px rgba(0,0,0,.5);
}
/* 4px blue frame down the sides (title bar stays full-width) */
.window > .window-menubar,
.window > .window-body,
.window > .window-statusbar { margin-left: 4px; margin-right: 4px; }
@keyframes win-open { from { transform: scale(.92); opacity: .2; } to { transform: scale(1); opacity: 1; } }
.window.closing { animation: win-close .12s ease-in forwards; }
@keyframes win-close { to { transform: scale(.9); opacity: 0; } }
.window.minimizing { animation: win-min .16s ease-in forwards; }
@keyframes win-min { to { transform: scale(.4) translateY(60vh); opacity: 0; } }

.window.maximized {
  left: 0 !important; top: 0 !important;
  width: 100% !important; height: 100% !important;
  border-radius: 0; padding-bottom: 0;
}
.window.maximized > .window-menubar,
.window.maximized > .window-body,
.window.maximized > .window-statusbar { margin-left: 0; margin-right: 0; }

.title-bar {
  height: var(--titlebar-h);
  display: flex; align-items: center; gap: 4px;
  padding: 0 3px 1px 6px;
  background: var(--title-inactive);
  color: var(--title-inactive-text);
  cursor: default;
  flex: 0 0 auto;
  border-radius: 7px 7px 0 0;
  position: relative;
}
/* glossy top highlight on the title bar */
.title-bar::after {
  content: ""; position: absolute; left: 0; right: 0; top: 0; height: 45%;
  border-radius: 7px 7px 0 0;
  background: linear-gradient(180deg, rgba(255,255,255,.45), rgba(255,255,255,0));
  pointer-events: none;
}
.window.active .title-bar {
  background: var(--title-active);
  color: var(--title-active-text);
}
.title-bar-text {
  flex: 1 1 auto; display: flex; align-items: center; gap: 6px;
  font-family: var(--title-font);
  font-weight: 700; font-size: 13px; letter-spacing: .2px;
  text-shadow: 1px 1px 2px rgba(0,0,0,.55);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  position: relative; z-index: 1;
}
.title-bar-text .title-icon { width: 16px; height: 16px; flex: 0 0 16px; filter: drop-shadow(0 1px 1px rgba(0,0,0,.4)); }
.title-bar-text .title-icon svg { width: 100%; height: 100%; display: block; }
.title-bar-controls { display: flex; gap: 2px; flex: 0 0 auto; position: relative; z-index: 1; }
/* caption buttons show the real XP icon images (glossy button is baked in) */
.tb-btn {
  width: 22px; height: 22px; padding: 0; border: none; border-radius: 0;
  background: transparent; display: grid; place-items: center; cursor: pointer;
}
.tb-btn .cap-img { width: 100%; height: 100%; object-fit: contain; display: block; pointer-events: none; }
.tb-btn:hover { filter: brightness(1.12) saturate(1.04); }
.tb-btn:active { filter: brightness(.88); transform: translateY(.5px); }
.tb-btn.close { margin-left: 2px; }
.window:not(.active) .tb-btn { filter: saturate(.55) brightness(.97); }

/* Optional menubar inside a window */
.window-menubar {
  display: flex; gap: 2px; padding: 3px 4px;
  font-size: 13px; flex: 0 0 auto;
  background: var(--luna-face);
  border-bottom: 1px solid #d6d2c2;
}
.window-menubar span { padding: 2px 8px; cursor: default; border-radius: 3px; }
.window-menubar span u { text-decoration: underline; }
.window-menubar span:hover { background: var(--select-blue-soft); color: #fff; }

.window-body {
  flex: 1 1 auto; overflow: auto; position: relative;
  margin: 0; padding: 0;
  background: var(--luna-face);
}
.window.has-well .window-body { padding: 0; }

/* status bar */
.window-statusbar {
  flex: 0 0 auto; display: flex; gap: 3px; padding: 2px 3px;
  font-size: 12px;
}
.window-statusbar .sb-panel {
  padding: 2px 7px; flex: 0 0 auto;
  box-shadow: inset -1px -1px var(--edge-light), inset 1px 1px var(--edge-shadow);
}
.window-statusbar .sb-panel.grow { flex: 1 1 auto; }

.resize-handle {
  position: absolute; right: 0; bottom: 0; width: 16px; height: 16px;
  cursor: nwse-resize; z-index: 3;
  background:
    linear-gradient(135deg, transparent 0 38%, var(--edge-shadow) 38% 46%, transparent 46% 60%, var(--edge-shadow) 60% 68%, transparent 68% 82%, var(--edge-shadow) 82% 90%, transparent 90%);
}

/* ===================== TASKBAR ===================== */
.taskbar {
  position: absolute; left: 0; right: 0; bottom: 0; height: var(--taskbar-h);
  z-index: 6000;
  background: var(--taskbar-grad);
  border-top: 1px solid var(--taskbar-top-line);
  display: flex; align-items: stretch; gap: 6px; padding-right: 2px;
}
/* Start button — official 3-state sprite (idle / hover / pressed, stacked) */
.start-button {
  flex: 0 0 auto;
  height: var(--taskbar-h);
  aspect-ratio: 159 / 51;     /* matches one sprite frame so it never distorts */
  width: auto;
  padding: 0; margin: 0; border: none; cursor: pointer;
  font-size: 0;               /* hide the fallback text */
  background-color: transparent;
  background-image: url("../assets/start_buttons.png");
  background-repeat: no-repeat;
  background-size: 100% 300%; /* 3 frames tall → each frame fills the button */
  background-position: 0 0;   /* idle (top frame) */
  border-radius: 0;
  box-shadow: none;
}
.start-button:hover { background-position: 0 50%; }     /* hover (middle frame) */
.start-button:active,
.start-button.open { background-position: 0 100%; }     /* pressed (bottom frame) */
.start-flag, .start-text { display: none; }

.task-buttons { flex: 1 1 auto; display: flex; align-items: center; gap: 4px; padding: 4px 2px; overflow: hidden; }
.task-button {
  flex: 0 1 165px; min-width: 44px; height: 100%;
  display: flex; align-items: center; gap: 6px; padding: 0 8px;
  border: none; border-radius: 2px; cursor: pointer;
  font-size: 13px; color: #fff; text-align: left;
  background: linear-gradient(180deg, #3f8df0, #2566d8 50%, #1e57c8);
  box-shadow: inset 1px 1px rgba(255,255,255,.35), inset -1px -1px rgba(0,0,0,.25);
  white-space: nowrap; overflow: hidden;
}
.task-button .tb-ico { width: 16px; height: 16px; flex: 0 0 16px; }
.task-button .tb-ico svg { width: 100%; height: 100%; }
.task-button .tb-label { overflow: hidden; text-overflow: ellipsis; }
.task-button.active {
  background: linear-gradient(180deg, #1c4fb0, #2766cc 60%, #2f74dd);
  box-shadow: inset 1px 1px rgba(0,0,0,.4), inset -1px -1px rgba(255,255,255,.2);
  font-weight: 600;
}
.task-button:not(.active):hover { background: linear-gradient(180deg, #57a0f5, #2f74e0 50%, #2a63d4); }

.tray {
  display: flex; align-items: center; gap: 6px; padding: 0 8px 0 10px;
  background: linear-gradient(180deg, #1f8ae0, #137fd8 40%, #0d6fc8);
  box-shadow: inset 1px 0 2px rgba(0,0,0,.35), inset 0 1px 1px rgba(255,255,255,.2);
}
.tray-ic { width: 20px; height: 20px; border: none; background: transparent; cursor: pointer; display: grid; place-items: center; opacity: .9; }
.tray-ic:hover { opacity: 1; }
.tray-ic svg { width: 16px; height: 16px; }
.clock {
  color: #fff; font-size: 12.5px; padding: 2px 4px;
  text-shadow: 1px 1px 1px rgba(0,0,0,.35); min-width: 56px; text-align: center;
}

/* ===================== START MENU (XP-faithful) ===================== */
.start-menu {
  position: absolute; left: 0; bottom: var(--taskbar-h); z-index: 6500;
  width: 386px; border-radius: 7px 7px 0 0; overflow: hidden;
  border: 1px solid #00308f; border-bottom: none;
  box-shadow: 2px 0 14px rgba(0,0,0,.5);
  background: #fff;
  font-family: var(--ui-font); font-size: 11px;
  animation: start-open .14s ease-out;
}
@keyframes start-open { from { transform: translateY(16px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

/* --- header (user banner) --- */
.start-header {
  height: 58px; display: flex; align-items: center; gap: 9px; padding: 0 9px;
  color: #fff;
  background: linear-gradient(180deg, #5b9bea 0%, #3f82e4 10%, #2d72dd 48%, #2065d3 90%, #1b5ec9 100%);
  border-bottom: 2px solid #e88a00;
  box-shadow: inset 0 1px 0 rgba(255,255,255,.45), inset 0 -3px 6px rgba(0,0,0,.12);
}
.start-avatar {
  width: 42px; height: 42px; flex: 0 0 42px; border-radius: 4px;
  background: rgba(255,255,255,.22);
  border: 1px solid rgba(255,255,255,.7);
  box-shadow: inset 0 0 0 1px rgba(0,0,0,.12), 0 1px 2px rgba(0,0,0,.3);
  display: grid; place-items: center; overflow: hidden;
}
.start-avatar svg { width: 38px; height: 38px; }
.start-avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }
.start-username {
  font-weight: 700; font-size: 14px; letter-spacing: .2px;
  text-shadow: 1px 1px 2px rgba(0,0,0,.45);
}

/* --- body --- */
.start-body { display: flex; align-items: stretch; }
.start-col-left {
  flex: 0 0 200px; display: flex; flex-direction: column;
  background: #fff; border-right: 1px solid #fff; padding: 5px 2px 0;
}
.start-col-right {
  flex: 1 1 auto; padding: 5px 3px;
  background: linear-gradient(180deg, #d8e7fb 0%, #cbe0f9 60%, #c3dbf7 100%);
  border-left: 1px solid #aec7ea;
}
.start-frequent { flex: 1 1 auto; }

/* items (shared) */
.start-item, .start-place {
  display: flex; align-items: center; gap: 8px; padding: 5px 7px; cursor: pointer;
  border-radius: 2px; color: #0b0b0b; border: 1px solid transparent;
}
.start-item .si-ico { width: 28px; height: 28px; flex: 0 0 28px; }
.start-item .si-ico svg { width: 100%; height: 100%; }
.start-item .si-text { display: flex; flex-direction: column; line-height: 1.2; min-width: 0; }
.start-item .si-name { font-size: 11px; }
.start-item .si-sub { font-size: 11px; color: #6d6d6d; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.start-place .si-ico { width: 22px; height: 22px; flex: 0 0 22px; }
.start-place .si-ico svg { width: 100%; height: 100%; }
.start-place .si-name { font-size: 11px; font-weight: 700; color: #15387a; }
.start-place .si-arrow {
  margin-left: auto; flex: 0 0 auto;
  width: 0; height: 0;
  border-left: 5px solid #45689f;
  border-top: 4px solid transparent;
  border-bottom: 4px solid transparent;
}

.start-item:hover, .start-item:focus-visible,
.start-place:hover, .start-place:focus-visible {
  background: linear-gradient(180deg, #3d86ea, #1f60d4);
  border-color: #16489f; color: #fff; outline: none;
}
.start-item:hover .si-sub { color: #dceaff; }
.start-place:hover .si-name { color: #fff; }
.start-place:hover .si-arrow { border-left-color: #fff; }

/* group separators (right column) */
.start-gsep { height: 0; margin: 4px 8px; border-top: 1px solid #aac3e6; box-shadow: 0 1px 0 #fff; }

/* All Programs */
.start-allsep { margin: 3px 6px 0; border-top: 1px solid #c6d8f1; box-shadow: 0 1px 0 #fff; }
.start-all {
  display: flex; align-items: center; gap: 7px; padding: 7px 7px; cursor: pointer;
  font-weight: 700; font-size: 11px; color: #0b0b0b; border-radius: 2px; border: 1px solid transparent;
}
.start-all:hover, .start-all:focus-visible {
  background: linear-gradient(180deg, #3d86ea, #1f60d4); border-color: #16489f; color: #fff; outline: none;
}
.start-all-arrow {
  width: 19px; height: 17px; border-radius: 3px; display: grid; place-items: center; order: 2;
  background: linear-gradient(180deg, #7cd24f 0%, #54ab2c 50%, #3f9220 51%, #5bb433 100%);
  box-shadow: inset 0 1px 1px rgba(255,255,255,.6), 0 1px 1px rgba(0,0,0,.3);
}
.start-all-arrow::before { content: ""; border-left: 6px solid #fff; border-top: 4px solid transparent; border-bottom: 4px solid transparent; margin-left: 2px; }
.start-all-label { order: 1; }

/* --- footer --- */
.start-footer {
  display: flex; justify-content: flex-end; align-items: center; gap: 4px; padding: 5px 8px;
  background: linear-gradient(180deg, #3074d6 0%, #2467d0 50%, #1c5ec9 100%);
  border-top: 1px solid #16439b;
  box-shadow: inset 0 1px 0 rgba(255,255,255,.35);
}
.start-power {
  display: flex; align-items: center; gap: 7px; padding: 4px 8px;
  background: transparent; border: 1px solid transparent; color: #fff; font-size: 11px; cursor: pointer;
  text-shadow: 1px 1px 1px rgba(0,0,0,.4); border-radius: 4px;
}
.start-power:hover { background: rgba(255,255,255,.16); border-color: rgba(255,255,255,.35); }
/* real XP footer icons (extracted from WinIcons_48.png) with state variants */
.start-power-ic {
  width: 24px; height: 24px;
  background-size: contain; background-repeat: no-repeat; background-position: center;
}
.start-power-ic[data-ic="logoff"] { background-image: url("../assets/icons/logoff.png"); }
.start-power-ic[data-ic="power"]  { background-image: url("../assets/icons/turnoff.png"); }
#start-logoff:hover   .start-power-ic[data-ic="logoff"] { background-image: url("../assets/icons/logoff_hover.png"); }
#start-shutdown:active .start-power-ic[data-ic="power"]  { background-image: url("../assets/icons/turnoff_active.png"); }

/* ===================== CONTEXT MENU ===================== */
.context-menu {
  position: absolute; z-index: 7000; min-width: 180px; margin: 0; padding: 2px; list-style: none;
  background: var(--silver);
  box-shadow:
    inset -1px -1px var(--edge-dark), inset 1px 1px var(--edge-light),
    inset -2px -2px var(--edge-shadow), inset 2px 2px var(--edge-face),
    2px 2px 8px rgba(0,0,0,.4);
}
.context-menu li { padding: 4px 22px; font-size: 13px; cursor: pointer; white-space: nowrap; }
.context-menu li:hover { background: var(--select-blue-soft); color: #fff; }
.context-menu li.disabled { color: var(--gray); pointer-events: none; }
.context-menu li.sep { height: 1px; padding: 0; margin: 3px 2px; background: var(--edge-shadow); box-shadow: 0 1px var(--edge-light); }

/* ===================== SHUTDOWN ===================== */
.shutdown {
  position: absolute; inset: 0; z-index: 9500; background: #000;
  display: flex; align-items: center; justify-content: center; color: #fff;
}
.shutdown.boot-fade { background: #5b8fd9; }
.shutdown-msg { text-align: center; max-width: 80%; }
.shutdown-big { font-size: clamp(20px, 4vw, 30px); color: #f7c000; font-weight: 400; }
.shutdown-small { font-size: 14px; color: #ccc; margin-bottom: 26px; }
.shutdown-restart {
  font-size: 14px; padding: 8px 22px; cursor: pointer;
  background: var(--silver); border: none; color: #000;
  box-shadow: inset -1px -1px var(--edge-dark), inset 1px 1px var(--edge-light),
    inset -2px -2px var(--edge-shadow), inset 2px 2px var(--edge-face);
}

/* ===================== CRT EFFECT (RGB phosphor) ===================== */
/* Rendered in SCREEN space (position:fixed, sized to the on-screen monitor by
   stage.js) so the fine stripes draw at real device pixels — no moiré. The
   overlay (mix-blend-mode: overlay) blends with the desktop; its ::after
   combines with the horizontal stripes to form the RGB grid. */
.crt-overlay {
  position: fixed; z-index: 60; pointer-events: none;
  mix-blend-mode: overlay;
  opacity: 0.42;
  background: repeating-linear-gradient(
    var(--crt-red) 0px,
    var(--crt-green) 2px,
    var(--crt-blue) 4px
  );
}
.crt-overlay::after {
  content: ""; position: absolute; inset: 0;
  pointer-events: none;
  mix-blend-mode: overlay;
  background: repeating-linear-gradient(
    90deg,
    var(--crt-red) 1px,
    var(--crt-green) 2px,
    var(--crt-blue) 3px
  );
}
