/* MeshOS branding and shared interface tokens */

@font-face {
  font-family: 'Space Grotesk';
  src: url('../../assets/fonts/space-grotesk.woff2') format('woff2');
  font-style: normal;
  font-weight: 300 700;
  font-display: swap;
}

@font-face {
  font-family: 'Orbitron';
  src: url('../../assets/fonts/orbitron.woff2') format('woff2');
  font-style: normal;
  font-weight: 400 900;
  font-display: swap;
}

:root {
  --bg:               #080d0b;
  --inset:            #0a110e;
  --surface:          #101a15;
  --surface-2:        #17251e;
  --accent:           #223628;
  --accent-hover:     #2d4934;
  --highlight:        #75f23b;
  --highlight-2:      #a3ff74;
  --highlight-soft:   rgba(117, 242, 59, 0.10);
  --highlight-border: rgba(117, 242, 59, 0.34);
  --text:             #edf6ef;
  --text-dim:         #b0c1b5;
  --text-muted:       #90a69a;
  --border:           #2a4133;
  --shadow:           rgba(0, 0, 0, 0.64);
  --danger:           #ff949b;
  --danger-soft:      rgba(255, 118, 129, 0.13);
  --danger-border:    rgba(255, 118, 129, 0.36);
  --radius:           8px;
  --radius-lg:        14px;
  --taskbar-h:        56px;
  --titlebar-h:       40px;
  --font:             'Space Grotesk', system-ui, sans-serif;
  --display-font:     'Orbitron', var(--font);
  --mono:             'Cascadia Code', 'Fira Code', 'Consolas', monospace;
  --transition:       150ms ease;
}

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

html, body {
  width: 100%; height: 100%;
  overflow: hidden;
  font-family: var(--font);
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
  user-select: none;
  -webkit-font-smoothing: antialiased;
}

input, select, textarea { font-family: inherit; }

button { cursor: pointer; border: none; background: none; color: inherit; font: inherit; }

/* ── Scrollbars (Webkit) ───────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--accent); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--highlight); }
* { scrollbar-width: thin; scrollbar-color: var(--accent) transparent; }

/* ── Desktop ───────────────────────────────────────────────── */
#desktop {
  position: fixed;
  inset: 0;
  display: grid;
  grid-template-rows: 1fr var(--taskbar-h);
  overflow: hidden;
}

/* ── Wallpaper ─────────────────────────────────────────────── */
#wallpaper {
  position: absolute;
  inset: 0 0 var(--taskbar-h);
  overflow: hidden;
  background:
    radial-gradient(ellipse at 69% 48%, #12291a, transparent 59%),
    linear-gradient(135deg, #090e0c 5%, #0b1510 57%, #080d0b 100%);
}

#wallpaper-grid {
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(rgba(142, 233, 169, 0.06) 1px, transparent 1px),
    linear-gradient(90deg, rgba(142, 233, 169, 0.06) 1px, transparent 1px);
  background-size: 44px 44px;
  mask-image: radial-gradient(ellipse at 68% 48%, #000 18%, rgba(0, 0, 0, 0.36) 88%);
}

.wallpaper-brand {
  position: absolute;
  top: 50%;
  left: 67%;
  width: clamp(220px, 42vw, 660px);
  transform: translate(-50%, -50%);
  display: grid;
  justify-items: center;
  gap: 10px;
  pointer-events: none;
}

.wallpaper-emblem {
  position: relative;
  display: grid;
  place-items: center;
  width: min(100%, 57vh);
  aspect-ratio: 1;
}

.wallpaper-emblem::before,
.wallpaper-emblem::after {
  content: '';
  position: absolute;
  border: 1px solid rgba(117, 242, 59, 0.15);
  border-radius: 50%;
  inset: 0;
}

.wallpaper-emblem::after {
  inset: -7%;
  border-color: rgba(117, 242, 59, 0.08);
}

.wallpaper-emblem img {
  position: relative;
  z-index: 1;
  width: 95%;
  height: auto;
}

.wallpaper-wordmark {
  display: block;
  width: min(58%, 300px);
  height: auto;
  z-index: 1;
}

/* ── Desktop Icons Layer ───────────────────────────────────── */
#desktop-icons {
  position: absolute;
  top: 22px;
  left: 18px;
  right: 18px;
  bottom: calc(var(--taskbar-h) + 14px);
  pointer-events: none; /* children handle events */
  z-index: 10;
}

.desktop-icon {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  width: 84px;
  padding: 6px 3px;
  border-radius: var(--radius);
  cursor: pointer;
  pointer-events: all;
  transition: background var(--transition);
  outline: none;
  position: absolute;
  user-select: none;
}

.desktop-icon.dragging {
  opacity: 0.75;
  z-index: 50;
  cursor: grabbing;
  background: rgba(255,255,255,0.12);
}

.desktop-icon.drop-target {
  background: var(--highlight-soft);
  outline: 2px dashed var(--highlight);
}

#desktop.file-drop-active::after {
  content: 'Drop files here to save to /home/user/';
  position: absolute;
  inset: 16px 16px calc(var(--taskbar-h) + 16px) 16px;
  border: 2px dashed var(--highlight);
  border-radius: 12px;
  background: rgba(10, 24, 16, 0.72);
  color: var(--text);
  font-size: 1.1rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  z-index: 900;
}

/* Icon size presets */
#desktop-icons.icons-small .desktop-icon { width: 60px; padding: 6px 3px; }
#desktop-icons.icons-small .desktop-icon-img { width: 36px; height: 36px; font-size: 1.45rem; }
#desktop-icons.icons-small .desktop-icon-label { font-size: 10px; }

#desktop-icons.icons-large .desktop-icon { width: 94px; padding: 10px 6px; }
#desktop-icons.icons-large .desktop-icon-img { width: 54px; height: 54px; font-size: 2.35rem; }
#desktop-icons.icons-large .desktop-icon-label { font-size: 12px; }

#desktop-icons.icons-hidden {
  opacity: 0;
  pointer-events: none !important;
}

/* Marquee selection box */
#desktop-selection-box {
  position: fixed;
  border: 1px solid var(--highlight);
  background: var(--highlight-soft);
  border-radius: 3px;
  pointer-events: none;
  z-index: 95;
  display: none;
}

/* Wallpaper theme presets */
#wallpaper.wallpaper--neon {
  background: linear-gradient(135deg, #0d0221 0%, #240046 50%, #3c096c 100%);
}
#wallpaper.wallpaper--ocean {
  background: linear-gradient(135deg, #041c32 0%, #064663 50%, #04293a 100%);
}
#wallpaper.wallpaper--emerald {
  background: linear-gradient(135deg, #071e18 0%, #0f3d30 50%, #145341 100%);
}
#wallpaper.wallpaper--slate {
  background: linear-gradient(135deg, #181a1f 0%, #23272e 50%, #14161a 100%);
}

.desktop-icon:hover {
  background: rgba(255,255,255,0.08);
}

.desktop-icon.selected {
  background: var(--highlight-soft);
  outline: 1px solid var(--highlight);
}

.desktop-icon.launching {
  animation: icon-launch 0.4s ease;
}

@keyframes icon-launch {
  0%   { transform: scale(1); }
  40%  { transform: scale(1.25); }
  100% { transform: scale(1); }
}

.desktop-icon-img {
  display: grid;
  place-items: center;
  width: 46px;
  height: 46px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: linear-gradient(150deg, var(--surface-2), var(--inset));
  box-shadow: 0 3px 9px rgba(0, 0, 0, 0.32);
  font-size: 1.6rem;
  line-height: 1;
}

.desktop-icon-label {
  font-size: 12px;
  font-weight: 550;
  color: var(--text);
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-align: center;
  line-height: 1.2;
  text-shadow: 0 1px 3px rgba(0,0,0,0.8);
}

/* ── Windows Layer ─────────────────────────────────────────── */
#windows-layer {
  position: absolute;
  inset: 0;
  bottom: var(--taskbar-h);
  pointer-events: none;
  z-index: 20;
}

/* ── Window Chrome ─────────────────────────────────────────── */
.wm-window {
  position: absolute;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: 0 8px 40px var(--shadow), 0 2px 8px rgba(0,0,0,0.4);
  pointer-events: all;
  overflow: hidden;
  min-width: 260px;
  min-height: 160px;
  /* Entry animation */
  opacity: 0;
  transform: scale(0.92) translateY(10px);
  transition: opacity 200ms ease, transform 200ms ease,
              box-shadow var(--transition);
}

.wm-window--open {
  opacity: 1;
  transform: scale(1) translateY(0);
}

.wm-window--active {
  box-shadow: 0 12px 56px var(--shadow), 0 0 0 1px var(--highlight-border);
}

.wm-window--minimized {
  opacity: 0;
  transform: scale(0.7) translateY(60px);
  transition: opacity 200ms ease, transform 200ms ease;
  pointer-events: none;
}

.wm-window--closing {
  opacity: 0;
  transform: scale(0.88);
  transition: opacity 200ms ease, transform 200ms ease;
  pointer-events: none;
}

/* Maximized */
.wm-window--maximized {
  position: absolute !important;
  left: 0 !important;
  top: 0 !important;
  width: 100% !important;
  height: 100% !important;
  border-radius: 0 !important;
}

/* Title bar */
.wm-titlebar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: var(--titlebar-h);
  padding: 0 9px 0 12px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  cursor: default;
  user-select: none;
}

.wm-window--active .wm-titlebar {
  background: linear-gradient(100deg, var(--accent) 0%, var(--surface-2) 75%);
  border-bottom-color: var(--highlight-border);
}

.wm-titlebar-left {
  display: flex;
  align-items: center;
  gap: 6px;
  overflow: hidden;
}

.wm-win-icon {
  font-size: 14px;
  flex-shrink: 0;
}

.wm-win-title {
  font-size: 14px;
  font-weight: 650;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  letter-spacing: 0.02em;
}

/* Title-bar button group */
.wm-btn-group {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}

.wm-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 25px;
  height: 25px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 11px;
  color: var(--text);
  opacity: 0.7;
  transition: opacity var(--transition), background var(--transition), transform var(--transition);
  line-height: 1;
}

.wm-btn:hover {
  opacity: 1;
  transform: scale(1.1);
}

.wm-btn:hover { background: var(--accent-hover); }
.wm-btn-close:hover { background: var(--danger-soft); color: var(--danger); border-color: var(--danger-border); }

/* Window body */
.wm-body {
  flex: 1;
  overflow: auto;
  background: var(--surface);
  color: var(--text);
  position: relative;
}

/* Resize handle */
.wm-resize-handle {
  position: absolute;
  right: 0;
  bottom: 0;
  width: 16px;
  height: 16px;
  cursor: se-resize;
  background: linear-gradient(135deg, transparent 50%, rgba(255,255,255,0.1) 50%);
  border-bottom-right-radius: var(--radius-lg);
  z-index: 1;
}

/* ── Taskbar ───────────────────────────────────────────────── */
#taskbar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: var(--taskbar-h);
  background: linear-gradient(180deg, var(--surface), var(--inset));
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 12px;
  gap: 10px;
  z-index: 1000;
}

#taskbar-left {
  display: flex;
  align-items: center;
  flex-shrink: 0;
}

#taskbar-apps {
  display: flex;
  align-items: center;
  gap: 5px;
  flex: 1;
  min-width: 0;
  overflow-x: auto;
  overflow-y: hidden;
  padding: 0 4px;
  scrollbar-width: none;
}
#taskbar-apps::-webkit-scrollbar { display: none; }

#taskbar-right {
  display: flex;
  align-items: center;
  gap: 9px;
  flex-shrink: 0;
  padding-left: 10px;
  border-left: 1px solid var(--border);
}

/* Start button */
#start-btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 40px;
  padding: 2px 14px 2px 7px;
  background: linear-gradient(135deg, var(--accent), var(--surface-2));
  border-radius: var(--radius);
  color: var(--text);
  border: 1px solid var(--highlight-border);
  transition: background var(--transition), border-color var(--transition);
}

#start-btn:hover, #start-btn.active {
  background: var(--accent-hover);
  border-color: var(--highlight);
}

.start-logo { display: block; width: 32px; height: 32px; }
.start-label { font: 650 12px var(--display-font); letter-spacing: 0.04em; }

/* Taskbar app entries */
.tb-entry {
  display: flex;
  align-items: center;
  gap: 5px;
  height: 36px;
  padding: 0 9px;
  border-radius: var(--radius);
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text-dim);
  font-size: 12px;
  white-space: nowrap;
  transition: background var(--transition), color var(--transition), border-color var(--transition);
  max-width: 160px;
  overflow: hidden;
}

.tb-entry:hover {
  background: rgba(255,255,255,0.1);
  color: var(--text);
}

.tb-entry--active {
  background: var(--highlight-soft);
  border-color: var(--highlight-border);
  color: var(--text);
}

.tb-entry-icon { font-size: 14px; flex-shrink: 0; }
.tb-entry-title {
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
}

/* Clock */
#taskbar-clock {
  font-family: var(--display-font);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  color: var(--text);
  letter-spacing: 0.04em;
  min-width: 68px;
  text-align: center;
}

/* Net indicator */
#net-indicator {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  color: var(--text-dim);
  padding: 4px 8px;
  border-radius: var(--radius);
  background: var(--surface-2);
  border: 1px solid var(--border);
  transition: color var(--transition), border-color var(--transition);
}

.net-icon { width: 7px; height: 7px; border-radius: 50%; background: var(--text-muted); }

#net-indicator.net-indicator--connected { color: var(--highlight-2); border-color: var(--highlight-border); }
.net-indicator--connected .net-icon {
  background: var(--highlight);
  box-shadow: 0 0 8px var(--highlight-border);
}

/* ── Context Menu ──────────────────────────────────────────── */
.context-menu {
  position: fixed;
  display: none;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 8px 32px var(--shadow);
  z-index: 9999;
  overflow: visible;
  min-width: 195px;
  padding: 4px 0;
  animation: menu-pop 120ms ease;
}

@keyframes menu-pop {
  from { opacity: 0; transform: scale(0.95) translateY(-4px); }
  to   { opacity: 1; transform: scale(1) translateY(0); }
}

.context-menu-item {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 7px 14px;
  font-size: 13px;
  color: var(--text);
  cursor: pointer;
  transition: background var(--transition), color var(--transition);
  white-space: nowrap;
}

.context-menu-item:hover {
  background: var(--accent);
  color: var(--highlight-2);
}

.context-menu-arrow {
  font-size: 10px;
  opacity: 0.75;
}

.context-menu-submenu {
  display: none;
  position: absolute;
  top: -4px;
  left: 100%;
  min-width: 175px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 8px 32px var(--shadow);
  padding: 4px 0;
  z-index: 10000;
}

.context-menu-item:hover > .context-menu-submenu {
  display: block;
}

.context-menu-submenu.flip-left {
  left: auto;
  right: 100%;
}

.context-menu-separator {
  height: 1px;
  background: var(--border);
  margin: 2px 0;
}

/* ── Start Menu ────────────────────────────────────────────── */
#start-menu {
  position: fixed;
  bottom: calc(var(--taskbar-h) + 10px);
  left: 12px;
  width: min(344px, calc(100vw - 24px));
  max-height: calc(100dvh - var(--taskbar-h) - 20px);
  background: var(--surface);
  border: 1px solid var(--highlight-border);
  border-radius: var(--radius-lg);
  box-shadow: 0 16px 48px var(--shadow);
  z-index: 9000;
  overflow: hidden;
  display: none;
  flex-direction: column;
  animation: menu-pop 160ms ease;
}

#start-menu.start-menu--visible { display: flex; }

.start-menu-header {
  padding: 12px 18px;
  background: radial-gradient(ellipse at left, var(--accent), var(--inset) 85%);
  border-bottom: 1px solid var(--border);
}

.start-menu-header img {
  display: block;
  width: 194px;
  max-width: 100%;
  height: auto;
}

.start-menu-apps {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
  padding: 12px;
  overflow-y: auto;
}

.start-app-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  padding: 6px 9px;
  font-size: 14px;
  text-align: left;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  transition: background var(--transition), border-color var(--transition);
}

.start-app-btn:hover {
  background: var(--accent);
  border-color: var(--highlight-border);
}

.start-app-icon { font-size: 18px; width: 24px; text-align: center; flex-shrink: 0; }
.start-app-label { overflow-wrap: anywhere; }

.start-menu-divider {
  height: 1px;
  flex-shrink: 0;
  background: var(--border);
}

.start-menu-sysinfo {
  padding: 10px 14px;
  color: var(--text-dim);
  font: 12px var(--mono);
  overflow-wrap: anywhere;
}

.start-shutdown-btn {
  padding: 10px 14px;
  text-align: left;
  font-size: 14px;
  color: var(--danger);
  border-top: 1px solid var(--border);
  transition: background var(--transition);
}

.start-shutdown-btn:hover { background: var(--danger-soft); }

/* ── Selection box (future) ────────────────────────────────── */
.select-box {
  position: fixed;
  border: 1px solid var(--highlight);
  background: var(--highlight-soft);
  pointer-events: none;
  z-index: 15;
}

/* ── Utility / helpers ─────────────────────────────────────── */
.visually-hidden {
  position: absolute;
  width: 1px; height: 1px;
  overflow: hidden; clip: rect(0,0,0,0);
  white-space: nowrap;
}

.monospace { font-family: var(--mono); }

/* ── Focus outline override ────────────────────────────────── */
:focus-visible {
  outline: 2px solid var(--highlight);
  outline-offset: 2px;
}

/* ── Browser ───────────────────────────────────────────────── */
.browser-app {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--surface);
}

.browser-toolbar {
  display: flex;
  flex-wrap: wrap;
  flex-shrink: 0;
  align-items: center;
  gap: 5px;
  padding: 7px 9px;
  border-bottom: 1px solid var(--border);
}

.browser-toolbar button {
  min-width: 30px;
  min-height: 30px;
  padding: 3px 7px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-2);
}

.browser-toolbar button:hover:not(:disabled) { background: var(--accent-hover); }
.browser-toolbar button:disabled { opacity: 0.44; cursor: default; }

.browser-toolbar input {
  flex: 1 1 120px;
  min-width: 0;
  min-height: 30px;
  padding: 4px 11px;
  color: var(--text);
  background: var(--inset);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.browser-toolbar input::placeholder,
.browser-home input::placeholder { color: var(--text-muted); }

.browser-bookmarks {
  display: flex;
  gap: 4px;
  padding: 4px 9px;
  overflow-x: auto;
  flex-shrink: 0;
  background: var(--inset);
  border-bottom: 1px solid var(--border);
}

.browser-bookmarks button {
  padding: 2px 7px;
  border-radius: var(--radius);
  color: var(--text-dim);
  white-space: nowrap;
}

.browser-bookmarks button:hover { background: var(--accent); color: var(--text); }

.browser-viewport {
  display: grid;
  flex: 1;
  min-height: 0;
  overflow: hidden;
  background: #fff;
}

.browser-home,
.browser-message {
  display: grid;
  place-content: center;
  gap: 12px;
  min-width: 0;
  padding: 18px;
  text-align: center;
  background: var(--bg);
  color: var(--text);
  overflow: auto;
}

.browser-home {
  grid-template-columns: min(100%, 444px);
  gap: 14px;
  background:
    radial-gradient(ellipse at 50% 43%, var(--accent) 0%, transparent 68%),
    linear-gradient(165deg, var(--surface), var(--bg));
}

.browser-home h1 img {
  display: block;
  margin: auto;
  width: min(100%, 340px);
  height: auto;
}

.browser-home form {
  display: flex;
  width: 100%;
  padding: 4px;
  border: 1px solid var(--highlight-border);
  border-radius: 13px;
  background: var(--inset);
}

.browser-home input {
  flex: 1;
  min-width: 0;
  border: 0;
  background: transparent;
  color: var(--text);
  padding: 8px 12px;
  font-size: 16px;
  user-select: auto;
}

.browser-home button {
  padding: 7px 14px;
  color: var(--bg);
  background: var(--highlight);
  font-weight: 700;
  border-radius: var(--radius);
}

.browser-home button:hover { background: var(--highlight-2); }
.browser-message span { color: var(--text-dim); }

.browser-status {
  padding: 4px 10px;
  background: var(--inset);
  color: var(--text-muted);
  font-size: 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex-shrink: 0;
}

@media (max-width: 620px) {
  .wallpaper-brand { left: 68%; width: clamp(160px, 42vw, 270px); }
  #taskbar { padding: 0 6px; gap: 6px; }
  #taskbar-right { gap: 5px; padding-left: 5px; }
  .net-label { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  .desktop-icon.launching, .context-menu, #start-menu { animation: none; }
  .wm-window, .desktop-icon, .wm-btn { transition-duration: 0.01ms; }
}
