/* ===== Aqua Desktop ===== */
:root {
  --mb-h: 26px;      /* menu bar height */
  --dock-h: 78px;    /* dock reserve at bottom */
}

html, body { background: #0a3a8c; }

/* Aqua blue wallpaper */
body {
  min-height: 100vh;
  background:
    radial-gradient(120% 90% at 50% -10%, #8fc2ff 0%, #2f7be0 38%, #1858b8 70%, #0e3f93 100%) fixed;
  background-color: #1858b8;
}
/* vignette */
body::before {
  content: ""; position: fixed; inset: 0; z-index: 0; pointer-events: none;
  background: radial-gradient(circle, transparent 45%, rgba(0,0,0,0.45) 100%);
}

/* Desktop canvas: masonry via CSS columns */
#desktop {
  position: relative;
  z-index: 1;
  column-count: 3;
  column-gap: 22px;
  max-width: 1320px;
  margin: 0 auto;
  padding: calc(var(--mb-h) + 22px) 22px calc(var(--dock-h) + 22px);
  box-sizing: border-box;
  transition: opacity 0.2s ease;
}
/* During boot we hide the canvas until the web fonts are applied and the
   final layout is frozen, so the font-swap reflow is never visible. The class
   is added by JS, so without JS the desktop stays visible and readable. */
#desktop.booting { opacity: 0; }

/* Window box */
.window {
  display: block;
  break-inside: avoid;
  margin: 0 0 22px;
  background: #f7f4ea;               /* warm paper body */
  background-image: var(--paper-texture-img);
  border: 1px solid rgba(0,0,0,0.35);
  border-radius: 10px;
  box-shadow: 0 10px 28px rgba(0,0,0,0.35), 0 2px 6px rgba(0,0,0,0.25);
  overflow: hidden;
}

/* Freed (dragged) windows float above the column flow */
.window.free {
  position: absolute;
  margin: 0;
  width: var(--w, 360px);
  z-index: var(--z, 10);
}

.window-body { padding: 16px 20px 20px; }
.window-body > :first-child { margin-top: 0; }
/* The real first child is a visually-hidden <h2>; zero the top margin of the
   first *visible* block so every window's titlebar-to-content gap is 16px
   (otherwise Tech's .skills-grid margin-top makes it 26px). */
.window-body > .visually-hidden + * { margin-top: 0; }
.window-body .about-name {
  margin: 0 0 4px; text-align: center;
  display: flex; align-items: baseline; justify-content: center;
  gap: 12px; flex-wrap: wrap;
}
.about-name-en {
  font-size: 1.85em; font-weight: 700; font-variant: small-caps;
  letter-spacing: 1px; color: #2b2b2b;
  text-shadow: 0 1px 0 rgba(255,255,255,0.85);
}
.about-name-zh {
  font-size: 1.05em; color: var(--text-meta); letter-spacing: 3px;
  font-family: "Noto Serif CJK SC", "Songti SC", serif;
}
.window-body .about-subtitle {
  margin: 0 0 12px; text-align: center; font-style: italic;
  color: var(--text-meta); font-family: "Georgia", serif;
}

/* Title bar (Aqua pinstripe) */
.titlebar {
  position: relative;
  display: flex; align-items: center;
  height: 22px; padding: 0 10px;
  cursor: grab; user-select: none;
  background:
    repeating-linear-gradient(180deg, rgba(255,255,255,0.55) 0 1px, rgba(255,255,255,0) 1px 2px),
    linear-gradient(to bottom, #f6f6f6, #d7d7d7);
  border-bottom: 1px solid rgba(0,0,0,0.28);
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.9);
}
.window.dragging .titlebar { cursor: grabbing; }

.titlebar .title {
  position: absolute; left: 0; right: 0; text-align: center;
  font-family: "Lucida Grande", -apple-system, "Helvetica Neue", sans-serif;
  font-size: 12px; font-weight: 600; color: #3a3a3a;
  text-shadow: 0 1px 0 rgba(255,255,255,0.8);
  pointer-events: none;
}

/* Traffic lights — Aqua water-drop gels. Optical structure:
   a dark refractive rim around the edge, a strong specular highlight in the
   top ~20%, and a broad colored back-reflection across the bottom ~50%,
   over a saturated spherical body. */
.lights { position: relative; z-index: 1; display: inline-flex; gap: 7px; }
.light {
  position: relative;
  width: 12px; height: 12px; padding: 0; border-radius: 50%;
  border: 0.5px solid var(--rim);
  background:
    radial-gradient(ellipse 92% 62% at 50% 100%, var(--reflect) 0%, rgba(255,255,255,0) 72%),
    radial-gradient(circle at 50% 40%, var(--c-top) 0%, var(--c-mid) 50%, var(--c-bot) 100%);
  box-shadow:
    inset 0 0 2px 0.5px rgba(0,0,0,0.42),   /* dark water-drop edge */
    0 1px 1px rgba(0,0,0,0.3);              /* drop shadow */
  cursor: pointer;
}
/* strong specular highlight occupying the top ~20% */
.light::before {
  content: "";
  position: absolute; top: 1px; left: 50%; transform: translateX(-50%);
  width: 7px; height: 3px; border-radius: 50%;
  background: radial-gradient(ellipse at center, rgba(255,255,255,1) 0%, rgba(255,255,255,0.12) 78%);
  pointer-events: none;
}
.light.close { --c-top: #ff8d82; --c-mid: #ec4133; --c-bot: #c0301f; --reflect: rgba(255,176,166,0.97); --rim: rgba(108,20,13,0.6); }
.light.min   { --c-top: #ffdd76; --c-mid: #f3ad1c; --c-bot: #c47f08; --reflect: rgba(255,224,134,0.97); --rim: rgba(114,74,6,0.55); }
.light.zoom  { --c-top: #bced7a; --c-mid: #5cc233; --c-bot: #348d1e; --reflect: rgba(182,238,140,0.97); --rim: rgba(28,86,13,0.55); }
.light:focus-visible { outline: 2px solid rgba(255,255,255,0.9); outline-offset: 1px; }

/* Inactive window: desaturate title bar + dim lights */
.window:not(.active) .titlebar { background: linear-gradient(to bottom, #eee, #dcdcdc); }
.window:not(.active) .light { filter: saturate(0.32) brightness(1.04) opacity(0.72); }
.window:not(.active) .light::before { opacity: 0.65; }

/* Active window lift */
.window.active { box-shadow: 0 16px 40px rgba(0,0,0,0.45), 0 3px 10px rgba(0,0,0,0.3); }


/* Menu bar */
#menubar {
  position: fixed; top: 0; left: 0; right: 0; z-index: 1000;
  height: var(--mb-h);
  display: flex; align-items: center; gap: 14px; padding: 0 12px;
  font-family: "Lucida Grande", -apple-system, "Helvetica Neue", sans-serif;
  font-size: 13px; color: #1c1c1c;
  background: linear-gradient(to bottom, rgba(255,255,255,0.92), rgba(232,232,232,0.86));
  -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px);
  border-bottom: 1px solid rgba(0,0,0,0.25);
  box-shadow: 0 1px 0 rgba(255,255,255,0.7);
}
/* Menu-bar items keep their natural width (no flex shrink) so that when they
   stop fitting they truly overflow — which is how JS detects "constrained". */
.mb-apple { font-family: -apple-system, "Helvetica Neue", sans-serif; font-size: 15px; flex: 0 0 auto; }
.mb-name { font-weight: 700; flex: 0 0 auto; }
.mb-menus { display: flex; gap: 4px; flex: 0 0 auto; }
.mb-item { font: inherit; color: inherit; background: none; border: 0; padding: 2px 8px; border-radius: 4px; cursor: pointer; white-space: nowrap; flex: 0 0 auto; }
.mb-item:hover { background: #3b73ff; color: #fff; }
.mb-spacer { flex: 1 1 0; min-width: 0; }
.mb-clock { font-variant-numeric: tabular-nums; flex: 0 0 auto; white-space: nowrap; }

/* Inline sections fill the bar; the Window dropdown only appears when the
   bar runs out of room (#menubar.collapsed, toggled by JS overflow check). */
.mb-window-menu { display: none; }
#menubar.collapsed .mb-item[data-focus] { display: none; }
#menubar.collapsed .mb-window-menu { display: inline-block; }

/* Window menu dropdown */
.mb-window-menu { position: relative; }
#window-menu-list {
  position: fixed; top: var(--mb-h); z-index: 1001;
  min-width: 180px; padding: 4px;
  background: rgba(245,245,245,0.97);
  -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px);
  border: 1px solid rgba(0,0,0,0.25); border-top: 0;
  border-radius: 0 0 6px 6px; box-shadow: 0 8px 20px rgba(0,0,0,0.3);
  list-style: none; margin: 0; display: none;
}
#window-menu-list.open { display: block; }
/* Reset the global list-item margins (style.css sets li:last-child to -15px for
   window-body lists) so menu rows sit flush and the last one doesn't poke out
   past the dropdown's rounded bottom edge. */
#window-menu-list li { margin: 0; }
#window-menu-list button {
  display: flex; justify-content: space-between; gap: 12px; width: 100%;
  font: inherit; text-align: left; background: none; border: 0;
  padding: 5px 10px; border-radius: 4px; cursor: pointer; color: #1c1c1c;
}
#window-menu-list button:hover { background: #3b73ff; color: #fff; }
#window-menu-list .wm-state { opacity: 0.6; font-size: 11px; }

/* Dock — translucent Aqua tray; icons sit directly on it (no per-icon tile) */
#dock {
  --dock-icon: 48px;   /* one knob: icon tile size; glyphs derive from it */
  position: fixed; left: 50%; bottom: 10px; transform: translateX(-50%);
  z-index: 1000; max-width: calc(100vw - 16px);
  display: flex; flex-wrap: nowrap; align-items: flex-end; gap: 8px; padding: 6px 10px;
  background:
    repeating-linear-gradient(180deg, rgba(255,255,255,0.5) 0 1px, rgba(255,255,255,0) 1px 3px),
    linear-gradient(to bottom, rgba(246,249,253,0.72), rgba(206,221,242,0.6));
  -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px);
  border: 1px solid rgba(255,255,255,0.7);
  border-radius: 14px;
  box-shadow:
    0 8px 24px rgba(0,0,0,0.35),
    inset 0 1px 0 rgba(255,255,255,0.85),
    inset 0 0 0 1px rgba(120,150,190,0.22);
}
.dock-item {
  position: relative; width: var(--dock-icon); height: var(--dock-icon);
  flex: 0 0 auto;
  display: flex; align-items: center; justify-content: center;
  color: #21436e; text-decoration: none;
  border: 0; background: none; border-radius: 0;
  filter: drop-shadow(0 1px 1px rgba(0,0,0,0.35));
  transform-origin: bottom center;
  transition: transform 0.14s ease;
}
.dock-item i { font-size: calc(var(--dock-icon) * 0.645); }
.dock-item .kz-icon { width: calc(var(--dock-icon) * 0.645); height: calc(var(--dock-icon) * 0.645); }
.dock-item:hover { transform: translateY(-12px) scale(1.22); }
.dock-item::after {
  content: attr(data-label);
  position: absolute; bottom: calc(100% + 8px); left: 50%; transform: translateX(-50%);
  padding: 2px 8px; font-family: "Lucida Grande", -apple-system, sans-serif; font-size: 11px;
  color: #fff; background: rgba(0,0,0,0.75); border-radius: 5px; white-space: nowrap;
  opacity: 0; pointer-events: none; transition: opacity 0.12s ease;
}
.dock-item:hover::after { opacity: 1; }

/* Dock: minimized-window area (right of a divider) */
.dock-sep {
  width: 1px; align-self: stretch; margin: 2px 4px;
  background: rgba(0,0,0,0.18);
  box-shadow: 1px 0 0 rgba(255,255,255,0.6);
}
.dock-min { display: flex; align-items: flex-end; gap: 8px; }
/* Minimized windows are square thumbnails (a window, not an app icon), so they
   keep a thin paper frame and show the window's initial. */
.dock-min-item {
  position: relative; width: var(--dock-icon); height: var(--dock-icon);
  flex: 0 0 auto;
  display: flex; align-items: center; justify-content: center;
  font-family: "Lucida Grande", -apple-system, "Helvetica Neue", sans-serif;
  font-size: calc(var(--dock-icon) * 0.44); font-weight: 600; color: #4a463f; text-decoration: none;
  text-shadow: 0 1px 0 rgba(255,255,255,0.8);
  border: 1px solid rgba(0,0,0,0.3); border-radius: 6px;
  background-image: var(--paper-texture-img);
  background-color: #f7f4ea;
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.9), 0 1px 3px rgba(0,0,0,0.3);
  cursor: pointer;
  transform-origin: bottom center;
  transition: transform 0.14s ease, box-shadow 0.14s ease;
}
.dock-min-item .dml-text { line-height: 1; }
.dock-min-item:hover {
  transform: translateY(-12px) scale(1.12);
  box-shadow: inset 0 1px 0 rgba(255,255,255,1), 0 8px 16px rgba(0,0,0,0.3);
}
.dock-min-item::after {
  content: attr(data-label);
  position: absolute; bottom: calc(100% + 8px); left: 50%; transform: translateX(-50%);
  padding: 2px 8px; font-family: "Lucida Grande", -apple-system, sans-serif; font-size: 11px;
  color: #fff; background: rgba(0,0,0,0.75); border-radius: 5px; white-space: nowrap;
  opacity: 0; pointer-events: none; transition: opacity 0.12s ease;
}
.dock-min-item:hover::after { opacity: 1; }

.window.is-closed { display: none; }
.window.is-min { display: none; }   /* minimized: hidden from canvas, reachable via Window menu */

@media (max-width: 1100px) { #desktop { column-count: 2; } }

@media (max-width: 820px) {
  #desktop {
    column-count: 1; max-width: 560px;
    padding: calc(var(--mb-h) + 16px) 14px calc(var(--dock-h) + 16px);
  }
  /* force any freed window back into flow */
  .window.free {
    position: static !important; width: auto !important;
    left: auto !important; top: auto !important; z-index: auto !important;
  }
  .window.zoomed.free { width: auto !important; }
  .titlebar { cursor: default; }
  /* macOS-style: keep one row, shrink the whole dock to fit the viewport.
     Icon size = min(42px, available width / slot budget) so it never wraps. */
  #dock {
    --dock-icon: min(42px, calc((100vw - 56px) / 8));
    gap: 6px; padding: 6px 8px; bottom: 8px;
  }
}

/* Disable the magnify on touch devices only — gate on actual pointer capability,
   not viewport width, so a narrow *desktop* window (mouse) keeps the hover lift. */
@media (hover: none), (pointer: coarse) {
  .dock-item:hover { transform: none; }
  .dock-min-item:hover { transform: none; }
}
