/* ============================================================
   desktop.css — CSS Custom Properties, Wallpaper, Body Reset
   macOS Desktop Website
   ============================================================ */

/* ── Design Tokens ─────────────────────────────────────────── */
:root {
  /* Layout */
  --window-radius: 10px;
  --btn-size: 12px;
  --titlebar-height: 52px;
  --dock-height: 70px;
  --menubar-height: 28px;
  --font-system: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display", system-ui, sans-serif;

  /* Traffic lights (invariant) */
  --btn-close: #ff5f57;
  --btn-minimize: #ffbd2e;
  --btn-maximize: #28c840;

  /* Accent (can be overridden by Settings) */
  --accent: #007AFF;
  --accent-rgb: 0, 122, 255;
  --accent-hover: #0066d6;
  --accent-light: #3395ff;

  /* Blur */
  --dock-blur: blur(25px) saturate(180%);
  --menu-blur: blur(20px);

  /* ── Semantic Colour Tokens (Light Mode) ─────────────────── */

  /* Surfaces */
  --surface-primary: #ffffff;
  --surface-secondary: #f5f5f5;
  --surface-tertiary: #e8e8e8;
  --surface-inset: #fafafa;
  --surface-elevated: #ffffff;

  /* Text */
  --text-primary: #1c1c1e;
  --text-secondary: #666666;
  --text-tertiary: #999999;
  --text-quaternary: #bbbbbb;
  --text-placeholder: #c7c7cc;
  --text-heading: #111111;
  --text-on-accent: #ffffff;

  /* Borders & Dividers */
  --border-primary: #e0e0e0;
  --border-secondary: #f0f0f0;
  --border-tertiary: #e8e8e8;
  --border-window: rgba(0, 0, 0, 0.08);

  /* Window chrome */
  --window-bg: #ffffff;
  --window-shadow: 0 22px 70px rgba(0, 0, 0, 0.56);
  --titlebar-bg: #e8e8e8;
  --titlebar-text: #4d4d4d;

  /* Sidebar */
  --sidebar-bg: #f5f5f5;
  --sidebar-hover: rgba(0, 0, 0, 0.05);
  --sidebar-active: rgba(var(--accent-rgb), 0.12);
  --sidebar-header: #888888;

  /* Selection & highlights */
  --selection: #fff2b7;
  --selection-accent: #ffd60a;
  --highlight-row: rgba(var(--accent-rgb), 0.12);

  /* Status */
  --color-success: #28c840;
  --color-error: #ff3b30;
  --color-error-hover: #e0352b;
  --color-warning: #ffd60a;

  /* Scrollbar */
  --scrollbar-thumb: rgba(0, 0, 0, 0.18);
  --scrollbar-thumb-hover: rgba(0, 0, 0, 0.32);

  /* Menu bar */
  --menubar-bg: rgba(255, 255, 255, 0.72);
  --menubar-text: rgba(0, 0, 0, 0.88);
  --menubar-icon: rgba(0, 0, 0, 0.75);
  --menubar-hover: rgba(0, 0, 0, 0.08);

  /* Dock */
  --dock-bg: rgba(255, 255, 255, 0.2);
  --dock-border: rgba(255, 255, 255, 0.3);
  --dock-dot: rgba(0, 0, 0, 0.5);
  --dock-separator: rgba(255, 255, 255, 0.25);
  --dock-glow: rgba(255, 255, 255, 0.18);
  --dock-tooltip-bg: rgba(255, 255, 255, 0.82);
  --dock-tooltip-text: rgba(0, 0, 0, 0.85);
  --dock-tooltip-border: rgba(0, 0, 0, 0.08);

  /* Spotlight */
  --spotlight-bg: rgba(255, 255, 255, 0.88);
  --spotlight-shadow: 0 24px 80px rgba(0,0,0,0.5), 0 0 0 1px rgba(255,255,255,0.4);
  --spotlight-hover: var(--accent-hover);

  /* Notification */
  --notification-bg: rgba(48, 48, 48, 0.94);
  --notification-bg-hover: rgba(60, 60, 60, 0.96);
  --notification-shadow: 0 8px 32px rgba(0, 0, 0, 0.44), 0 0 0 0.5px rgba(255, 255, 255, 0.12);
  --notification-text: #ffffff;
  --notification-text-muted: rgba(255, 255, 255, 0.55);
  --notification-text-secondary: rgba(255, 255, 255, 0.7);
  --notification-close-bg: rgba(255, 255, 255, 0.15);
  --notification-close-color: rgba(255, 255, 255, 0.7);
  --notification-close-hover: rgba(255, 255, 255, 0.28);
  --notification-action-secondary-bg: rgba(255, 255, 255, 0.14);
  --notification-action-secondary-hover: rgba(255, 255, 255, 0.22);
  --accent-light: #3395ff;

  /* App-specific (invariant brand colours) */
  --linkedin-blue: #0077b5;
  --linkedin-hover: #005f94;
  --linkedin-bg: #f3f2ef;
  --meikai-navy: #1a3050;
  --meikai-dark: #0f1d2e;
  --meikai-accent: #8fabc8;
  --meikai-tag-bg: #e8eef4;
  --meikai-bg: #f0f2f5;
  --books-bg: #faf8f5;
  --books-cover-bg: #e0dcd6;
  --terminal-green: #32d74b;
  --music-red: #fc3c44;
  --music-bg: #1a1a1a;
}

/* ── Dark Mode Tokens ──────────────────────────────────────── */
/* Applied via JS class OR OS preference when set to "auto"    */
.theme-dark {
  --surface-primary: #1c1c1e;
  --surface-secondary: #2c2c2e;
  --surface-tertiary: #3a3a3c;
  --surface-inset: #252528;
  --surface-elevated: #2c2c2e;

  --text-primary: #f5f5f7;
  --text-secondary: #a1a1a6;
  --text-tertiary: #7c7c80;
  --text-quaternary: #636366;
  --text-placeholder: #636366;
  --text-heading: #f5f5f7;
  --text-on-accent: #ffffff;

  --border-primary: #3a3a3c;
  --border-secondary: #2c2c2e;
  --border-tertiary: #333336;
  --border-window: rgba(255, 255, 255, 0.08);

  --window-bg: #1c1c1e;
  --window-shadow: 0 22px 70px rgba(0, 0, 0, 0.75);
  --titlebar-bg: #2c2c2e;
  --titlebar-text: #a1a1a6;

  --sidebar-bg: #252528;
  --sidebar-hover: rgba(255, 255, 255, 0.06);
  --sidebar-active: rgba(var(--accent-rgb), 0.2);
  --sidebar-header: #7c7c80;

  --selection: rgba(255, 214, 10, 0.2);
  --selection-accent: #ffd60a;
  --highlight-row: rgba(var(--accent-rgb), 0.2);

  --scrollbar-thumb: rgba(255, 255, 255, 0.18);
  --scrollbar-thumb-hover: rgba(255, 255, 255, 0.32);

  --menubar-bg: rgba(0, 0, 0, 0.72);
  --menubar-text: rgba(255, 255, 255, 0.88);
  --menubar-icon: rgba(255, 255, 255, 0.8);
  --menubar-hover: rgba(255, 255, 255, 0.12);

  --dock-bg: rgba(0, 0, 0, 0.4);
  --dock-border: rgba(255, 255, 255, 0.12);
  --dock-dot: rgba(255, 255, 255, 0.5);
  --dock-separator: rgba(255, 255, 255, 0.12);
  --dock-glow: rgba(255, 255, 255, 0.06);
  --dock-tooltip-bg: rgba(40, 40, 40, 0.94);
  --dock-tooltip-text: #fff;
  --dock-tooltip-border: rgba(255, 255, 255, 0.1);

  --spotlight-bg: rgba(40, 40, 42, 0.92);
  --spotlight-shadow: 0 24px 80px rgba(0,0,0,0.7), 0 0 0 1px rgba(255,255,255,0.1);
  --spotlight-hover: var(--accent-hover);

  --notification-bg: rgba(60, 60, 65, 0.96);
  --notification-bg-hover: rgba(75, 75, 80, 0.96);
  --notification-shadow: 0 8px 32px rgba(0, 0, 0, 0.6), 0 0 0 0.5px rgba(255, 255, 255, 0.08);
  --notification-text: #ffffff;
  --notification-text-muted: rgba(255, 255, 255, 0.5);
  --notification-text-secondary: rgba(255, 255, 255, 0.65);
  --notification-close-bg: rgba(255, 255, 255, 0.12);
  --notification-close-color: rgba(255, 255, 255, 0.65);
  --notification-close-hover: rgba(255, 255, 255, 0.24);
  --notification-action-secondary-bg: rgba(255, 255, 255, 0.1);
  --notification-action-secondary-hover: rgba(255, 255, 255, 0.18);
  --accent-light: #3395ff;

  --books-bg: #252528;
  --books-cover-bg: #3a3a3c;
  --linkedin-bg: #252528;
  --meikai-bg: #252528;
}

/* Auto mode: respect OS preference */
@media (prefers-color-scheme: dark) {
  .theme-auto {
    --surface-primary: #1c1c1e;
    --surface-secondary: #2c2c2e;
    --surface-tertiary: #3a3a3c;
    --surface-inset: #252528;
    --surface-elevated: #2c2c2e;

    --text-primary: #f5f5f7;
    --text-secondary: #a1a1a6;
    --text-tertiary: #7c7c80;
    --text-quaternary: #636366;
    --text-placeholder: #636366;
    --text-heading: #f5f5f7;

    --border-primary: #3a3a3c;
    --border-secondary: #2c2c2e;
    --border-tertiary: #333336;
    --border-window: rgba(255, 255, 255, 0.08);

    --window-bg: #1c1c1e;
    --window-shadow: 0 22px 70px rgba(0, 0, 0, 0.75);
    --titlebar-bg: #2c2c2e;
    --titlebar-text: #a1a1a6;

    --sidebar-bg: #252528;
    --sidebar-hover: rgba(255, 255, 255, 0.06);
    --sidebar-active: rgba(var(--accent-rgb), 0.2);
    --sidebar-header: #7c7c80;

    --selection: rgba(255, 214, 10, 0.2);
    --selection-accent: #ffd60a;
    --highlight-row: rgba(var(--accent-rgb), 0.2);

    --scrollbar-thumb: rgba(255, 255, 255, 0.18);
    --scrollbar-thumb-hover: rgba(255, 255, 255, 0.32);

    --menubar-bg: rgba(0, 0, 0, 0.72);
    --menubar-text: rgba(255, 255, 255, 0.88);
    --menubar-icon: rgba(255, 255, 255, 0.8);
    --menubar-hover: rgba(255, 255, 255, 0.12);

    --dock-bg: rgba(0, 0, 0, 0.4);
    --dock-border: rgba(255, 255, 255, 0.12);
    --dock-dot: rgba(255, 255, 255, 0.5);
    --dock-separator: rgba(255, 255, 255, 0.12);
    --dock-glow: rgba(255, 255, 255, 0.06);
    --dock-tooltip-bg: rgba(40, 40, 40, 0.94);
  --dock-tooltip-text: #fff;
  --dock-tooltip-border: rgba(255, 255, 255, 0.1);

    --spotlight-bg: rgba(40, 40, 42, 0.92);
    --spotlight-shadow: 0 24px 80px rgba(0,0,0,0.7), 0 0 0 1px rgba(255,255,255,0.1);

    --notification-bg: rgba(60, 60, 65, 0.96);
    --notification-bg-hover: rgba(75, 75, 80, 0.96);
    --notification-shadow: 0 8px 32px rgba(0, 0, 0, 0.6), 0 0 0 0.5px rgba(255, 255, 255, 0.08);
    --notification-text: #ffffff;
    --notification-text-muted: rgba(255, 255, 255, 0.5);
    --notification-text-secondary: rgba(255, 255, 255, 0.65);
    --notification-close-bg: rgba(255, 255, 255, 0.12);
    --notification-close-color: rgba(255, 255, 255, 0.65);
    --notification-close-hover: rgba(255, 255, 255, 0.24);
    --notification-action-secondary-bg: rgba(255, 255, 255, 0.1);
    --notification-action-secondary-hover: rgba(255, 255, 255, 0.18);
    --accent-light: #3395ff;

    --books-bg: #252528;
    --books-cover-bg: #3a3a3c;
    --linkedin-bg: #252528;
    --meikai-bg: #252528;
  }
}

/* Smooth theme transitions */
body.macos-desktop-page.theme-transitioning,
body.macos-desktop-page.theme-transitioning *,
body.macos-desktop-page.theme-transitioning *::before,
body.macos-desktop-page.theme-transitioning *::after {
  transition: background-color 0.3s ease, color 0.3s ease, border-color 0.3s ease, box-shadow 0.3s ease !important;
}

@media (prefers-reduced-motion: reduce) {
  body.macos-desktop-page.theme-transitioning,
  body.macos-desktop-page.theme-transitioning *,
  body.macos-desktop-page.theme-transitioning *::before,
  body.macos-desktop-page.theme-transitioning *::after {
    transition: none !important;
  }
}

/* Legacy aliases for backwards compat */
:root {
  --accent-blue: var(--accent);
  --selection-yellow: var(--selection);
}

/* ── Reset ──────────────────────────────────────────────────── */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html,
body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  font-family: var(--font-system);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Scope all desktop chrome under this class to avoid theme bleed */
body.macos-desktop-page {
  background: #000;
}

button {
  font-family: var(--font-system);
  border: none;
  background: none;
  cursor: pointer;
}

/* ── Desktop Container ──────────────────────────────────────── */
#macos-desktop {
  position: relative;
  width: 100vw;
  height: 100vh;
  overflow: hidden;
}

/* ── Wallpaper ──────────────────────────────────────────────── */
/*
 * Pure-CSS mesh gradient wallpaper — no external image dependency.
 * Built from layered radial-gradients on a deep navy base.
 *
 * To swap in a real image later, add:
 *   background-image: url('/path/to/wallpaper.avif'), var(--wallpaper-mesh);
 * The mesh will show as a fallback if the image fails to load.
 */
:root {
  --wallpaper-mesh:
    radial-gradient(ellipse 80% 60% at 20%  20%, #1a4a8a 0%, transparent 60%),
    radial-gradient(ellipse 60% 80% at 80%  10%, #0d2f6e 0%, transparent 55%),
    radial-gradient(ellipse 70% 70% at 70%  75%, #1b3a6b 0%, transparent 60%),
    radial-gradient(ellipse 90% 50% at 10%  80%, #0a1e40 0%, transparent 65%),
    radial-gradient(ellipse 50% 60% at 50%  50%, #2a5298 0%, transparent 55%),
    radial-gradient(ellipse 40% 40% at 85%  50%, #0e4d92 0%, transparent 50%),
    radial-gradient(ellipse 55% 45% at 30%  60%, #163d75 0%, transparent 55%);
  --wallpaper-base: #0b1e3d;
}

#desktop-wallpaper {
  position: fixed;
  inset: 0;
  z-index: 1;
  background-color: var(--wallpaper-base);
  background-image: var(--wallpaper-mesh);
}

/* Animated shimmer layer — shifts the mesh subtly over 30s */
#desktop-wallpaper::after {
  content: '';
  position: absolute;
  inset: 0;
  background-image:
    radial-gradient(ellipse 45% 55% at 65% 35%, rgba(100, 180, 255, 0.12) 0%, transparent 60%),
    radial-gradient(ellipse 35% 40% at 25% 70%, rgba(60,  120, 220, 0.10) 0%, transparent 55%);
  animation: wallpaper-drift 30s ease-in-out infinite alternate;
  pointer-events: none;
}

@keyframes wallpaper-drift {
  0%   { transform: translate(0,     0)    scale(1); }
  33%  { transform: translate(2%,   -1.5%) scale(1.02); }
  66%  { transform: translate(-1.5%, 2%)   scale(0.99); }
  100% { transform: translate(1%,    1%)   scale(1.01); }
}

@media (prefers-reduced-motion: reduce) {
  #desktop-wallpaper::after {
    animation: none;
  }
}

/* ── Global drag state: suppress text selection everywhere ─────
   Applied by window-manager.js on mousedown, removed on mouseup  */
body.is-dragging,
body.is-dragging * {
  user-select: none !important;
  -webkit-user-select: none !important;
  cursor: grabbing !important;
}

/* ── Reduced Motion ─────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* ── Mobile alert overlay ───────────────────────────────────── */
#mobile-alert-overlay {
  display: none; /* shown by JS on mobile */
  position: fixed;
  inset: 0;
  z-index: 99999;
  background: rgba(0, 0, 0, 0.72);
  align-items: center;
  justify-content: center;
  padding: 20px;
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
}

#mobile-alert-dialog {
  width: 100%;
  max-width: 420px;
  background: var(--surface-tertiary);
  border-radius: 14px;
  box-shadow: 0 24px 64px rgba(0,0,0,0.55), 0 0 0 0.5px rgba(255,255,255,0.15);
  overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, sans-serif;
}

.ma-content {
  display: flex;
  align-items: flex-start;
  gap: 16px;
  padding: 24px 22px 20px;
}

.ma-icon {
  flex-shrink: 0;
  margin-top: 2px;
}

.ma-text {
  flex: 1;
}

.ma-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 7px;
  line-height: 1.3;
}

.ma-body {
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.5;
}

/* Button row */
.ma-buttons {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 9px;
  padding: 12px 18px 16px;
  border-top: 1px solid var(--border-window);
  background: var(--surface-tertiary);
}

.ma-btn,
a.ma-btn {
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  padding: 6px 18px;
  border-radius: 7px;
  border: 1px solid rgba(0,0,0,0.22);
  cursor: pointer;
  min-width: 80px;
  min-height: 44px; /* meets touch target minimum */
  touch-action: manipulation; /* removes 300ms tap delay */
  -webkit-tap-highlight-color: transparent;
  transition: filter 0.1s ease;
}

.ma-btn:active {
  filter: brightness(0.92);
}

.ma-btn-secondary {
  background: linear-gradient(to bottom, var(--surface-primary), var(--surface-secondary));
  color: var(--text-primary);
}

.ma-btn-primary {
  background: linear-gradient(to bottom, #4a9eff, #0070e0);
  color: #fff;
  border-color: #005bbf;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
}
