:root {
  --bg: #05070c;
  --accent: #4dfff0;
  --accent-dim: #1c8f86;
  --glass: rgba(18, 26, 36, 0.55);
  --glass-border: rgba(77, 255, 240, 0.25);
  --text: #dff9f6;
  --text-dim: #7ea6a2;
  --danger: #ff5d6c;
  --radius: 14px;
  --font: "Consolas", "SFMono-Regular", "Courier New", monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  overflow: hidden;
  user-select: none;
}

button, input {
  font-family: var(--font);
  color: var(--text);
}

/* ===== Boot screen ===== */

#boot {
  position: fixed;
  inset: 0;
  z-index: 500;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 24px;
  background: radial-gradient(circle at 50% 40%, #0c1620 0%, var(--bg) 70%);
  transition: opacity 0.6s ease;
}

#boot.hidden { opacity: 0; pointer-events: none; }

#bootTitle {
  letter-spacing: 0.3em;
  font-size: 1.4rem;
  color: var(--accent);
  margin: 0;
}

#bootLog {
  color: var(--text-dim);
  font-size: 0.85rem;
  min-height: 1.2em;
}

.spinner {
  --uib-size: 45px;
  --uib-color: var(--accent);
  --uib-speed: 1.75s;
  position: relative;
  height: var(--uib-size);
  width: var(--uib-size);
  animation: rotate calc(var(--uib-speed) * 4) linear infinite;
}

@keyframes rotate { to { transform: rotate(360deg); } }

.particle {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}
.particle:nth-child(1)  { --uib-delay: 0;    transform: rotate(8deg); }
.particle:nth-child(2)  { --uib-delay: -0.4; transform: rotate(36deg); }
.particle:nth-child(3)  { --uib-delay: -0.9; transform: rotate(72deg); }
.particle:nth-child(4)  { --uib-delay: -0.5; transform: rotate(90deg); }
.particle:nth-child(5)  { --uib-delay: -0.3; transform: rotate(144deg); }
.particle:nth-child(6)  { --uib-delay: -0.2; transform: rotate(180deg); }
.particle:nth-child(7)  { --uib-delay: -0.6; transform: rotate(216deg); }
.particle:nth-child(8)  { --uib-delay: -0.7; transform: rotate(252deg); }
.particle:nth-child(9)  { --uib-delay: -0.1; transform: rotate(300deg); }
.particle:nth-child(10) { --uib-delay: -0.8; transform: rotate(324deg); }
.particle:nth-child(11) { --uib-delay: -1.2; transform: rotate(335deg); }
.particle:nth-child(12) { --uib-delay: -0.5; transform: rotate(290deg); }
.particle:nth-child(13) { --uib-delay: -0.2; transform: rotate(240deg); }

.particle::before {
  content: '';
  position: absolute;
  height: 17.5%;
  width: 17.5%;
  border-radius: 50%;
  background-color: var(--uib-color);
  box-shadow: 0 0 6px var(--accent);
  --uib-d: calc(var(--uib-delay) * var(--uib-speed));
  animation: orbit var(--uib-speed) linear var(--uib-d) infinite;
}

@keyframes orbit {
  0%   { transform: translate(calc(var(--uib-size) * 0.5)) scale(0.73684); opacity: 0.65; }
  25%  { transform: translate(0%) scale(0.47368); opacity: 0.3; }
  50%  { transform: translate(calc(var(--uib-size) * -0.5)) scale(0.73684); opacity: 0.65; }
  75%  { transform: translate(0%) scale(1); opacity: 1; }
  100% { transform: translate(calc(var(--uib-size) * 0.5)) scale(0.73684); opacity: 0.65; }
}

/* ===== Background (FaultyTerminal WebGL) ===== */

#bgTerminal {
  position: fixed;
  inset: 0;
  z-index: 0;
  background: var(--bg);
}
#bgTerminal canvas { width: 100%; height: 100%; display: block; }
#bgTerminal::after {
  content: "";
  position: absolute;
  inset: 0;
  background: rgba(5, 7, 12, 0.55);
  pointer-events: none;
}

/* ===== Desktop ===== */

#desktop {
  position: relative;
  z-index: 1;
  height: 100vh;
  width: 100vw;
  background: transparent;
}

#topbar {
  position: absolute;
  top: 0; left: 0;
  width: 100%;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  background: rgba(6, 10, 16, 0.45);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--glass-border);
  z-index: 100;
  font-size: 0.85rem;
  letter-spacing: 0.08em;
}

#osName { color: var(--accent); margin: 0; }
#topbarRight { display: flex; align-items: center; gap: 14px; }
#timeElement { color: var(--text-dim); margin: 0; }
#welcomeReopen {
  background: none;
  border: 1px solid var(--glass-border);
  color: var(--text-dim);
  border-radius: 8px;
  padding: 4px 10px;
  font-size: 0.7rem;
  cursor: pointer;
}
#welcomeReopen:hover { color: var(--accent); border-color: var(--accent); }

/* ===== Floating node-graph desktop (ambient layer) ===== */
#graphCanvas {
  position: absolute;
  inset: 0;
  z-index: 2;
  width: 100%;
  height: 100%;
}

/* ===== CircleMenu launcher — no persistent trigger button; left-click on empty desktop
   (wired in desktop.js's initGraph) opens the ring at the cursor, clamped on-screen. ===== */
#circleMenu {
  position: fixed;
  left: 0; top: 0; /* overridden inline by openMenuAt() in desktop.js */
  z-index: 110;
  width: 0;
  height: 0;
}
#circleMenuRing { position: absolute; left: 0; top: 0; width: 0; height: 0; }
.circle-menu-item {
  position: absolute;
  top: 0; left: 0;
  width: 44px; height: 44px;
  margin: -22px 0 0 -22px;
  border-radius: 50%;
  background: var(--glass);
  border: 1px solid var(--glass-border);
  color: var(--text);
  font-size: 1.1rem;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1), opacity 0.2s ease;
  opacity: 0;
  transform: translate(0, 0) scale(0.4);
  /* closed, every item sits exactly on the ring's anchor point (stacked) —
     without this they'd eat clicks meant for whatever's beneath them */
  pointer-events: none;
}
.circle-menu-item:hover { background: rgba(77,255,240,0.15); border-color: var(--accent); }
#circleMenu.open .circle-menu-item { pointer-events: auto; }

/* ===== Global search (lives in the topbar — a floating overlay collided with
   centered window headers, since windows sit nearly flush under the topbar) ===== */
#searchBar {
  position: relative;
  width: 240px;
}
#searchInput {
  width: 100%;
  background: rgba(0,0,0,0.3);
  border: 1px solid var(--glass-border);
  border-radius: 8px;
  padding: 5px 10px 5px 26px;
  font-size: 0.75rem;
}
#searchResults {
  display: none;
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  width: 100%;
  z-index: 110;
  background: #0a121a;
  border: 1px solid var(--glass-border);
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 10px 30px rgba(0,0,0,0.5);
}
#searchResults.visible { display: block; }
.search-result {
  padding: 8px 12px;
  font-size: 0.8rem;
  cursor: pointer;
}
.search-result:hover { background: rgba(77,255,240,0.1); }

/* both search bars share one magnifier icon + focus glow */
#searchInput, #explorerSearch {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%237ea6a2' stroke-width='2' stroke-linecap='round'%3E%3Ccircle cx='11' cy='11' r='7'/%3E%3Cline x1='21' y1='21' x2='16.65' y2='16.65'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: 8px center;
  background-size: 14px 14px;
}
select:focus, textarea:focus, input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(77,255,240,0.15);
}

/* themed scrollbars */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--accent-dim); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--accent); }

/* ===== Windows ===== */

.window {
  display: none;
  flex-direction: column;
  position: absolute;
  /* center within the area BELOW the topbar (40px), not the full viewport —
     centering on 100vh let short viewports push the header up behind the
     always-on-top topbar, hiding the title bar and controls entirely */
  top: calc(40px + (100vh - 40px) / 2);
  left: 50%;
  transform: translate(-50%, -50%);
  width: 420px;
  height: 460px;
  max-height: calc(100vh - 60px);
  background: var(--glass);
  backdrop-filter: blur(18px);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius);
  box-shadow: 0 20px 60px rgba(0,0,0,0.5);
  overflow: hidden;
  z-index: 20;
}
.window.open { display: flex; }
.window.wide { width: 640px; height: 560px; }
.window.maximized {
  top: 40px; left: 0; transform: none;
  width: 100vw; height: calc(100vh - 40px);
  max-height: none; /* base .window's max-height capped this below full height — bug fix */
  border-radius: 0;
}
.window.minimized { display: none !important; }

.windowheader {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  background: rgba(77,255,240,0.06);
  border-bottom: 1px solid var(--glass-border);
  cursor: grab;
}
.windowheader:active { cursor: grabbing; }
.windowtitle { margin: 0; font-size: 0.85rem; color: var(--accent); letter-spacing: 0.05em; }

.window-controls { display: flex; gap: 6px; }
.minbutton, .maxbutton, .closebutton {
  width: 20px; height: 20px;
  border-radius: 50%;
  background: transparent;
  line-height: 1;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  font-size: 0.7rem;
}
.minbutton, .maxbutton {
  border: 1px solid var(--glass-border);
  color: var(--text-dim);
}
.minbutton:hover, .maxbutton:hover { background: rgba(77,255,240,0.15); color: var(--accent); }
.closebutton {
  border: 1px solid var(--danger);
  color: var(--danger);
}
.closebutton:hover { background: var(--danger); color: #05070c; }

.windowbody {
  flex: 1;
  display: flex;
  overflow: hidden;
}
.windowbody.single { flex-direction: column; padding: 14px; gap: 10px; overflow-y: auto; }

/* Reusable sidebar + list-entry pattern (tabs, history lists, etc.) */
.sidebar {
  width: 140px;
  border-right: 1px solid var(--glass-border);
  overflow-y: auto;
  padding: 8px;
}
.list-entry {
  padding: 8px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.75rem;
  margin-bottom: 4px;
}
.list-entry:hover, .list-entry.active { background: rgba(77,255,240,0.1); }
.list-entry .list-meta { color: var(--text-dim); font-size: 0.65rem; }
.content { flex: 1; padding: 14px; overflow-y: auto; font-size: 0.85rem; line-height: 1.5; white-space: pre-wrap; }

/* Crypto / Decrypt / Calc form bits */
select, textarea, input[type="text"], input[type="password"], input[type="number"], input[type="search"] {
  background: rgba(0,0,0,0.3);
  border: 1px solid var(--glass-border);
  border-radius: 8px;
  color: var(--text);
  padding: 8px;
  font-size: 0.8rem;
  width: 100%;
}
input[type="number"] { appearance: textfield; }
textarea { min-height: 80px; resize: vertical; }
.row { display: flex; gap: 8px; align-items: center; }
.run-btn {
  background: var(--accent-dim);
  border: 1px solid var(--accent);
  color: #05070c;
  font-weight: bold;
  border-radius: 8px;
  padding: 8px 12px;
  cursor: pointer;
}
.run-btn:hover { background: var(--accent); }
.output-box {
  background: rgba(0,0,0,0.35);
  border: 1px solid var(--glass-border);
  border-radius: 8px;
  padding: 10px;
  font-size: 0.8rem;
  min-height: 40px;
  white-space: pre-wrap;
  word-break: break-all;
}
.error-text { color: var(--danger); font-size: 0.75rem; }
.brute-list { display: flex; flex-direction: column; gap: 2px; max-height: 160px; overflow-y: auto; font-size: 0.72rem; }

/* Calculator */
#calcDisplay {
  text-align: right;
  font-size: 1.4rem;
  padding: 10px;
  background: rgba(0,0,0,0.35);
  border-radius: 8px;
  min-height: 1.6em;
  overflow-x: auto;
}
.calc-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.calc-key {
  background: rgba(77,255,240,0.06);
  border: 1px solid var(--glass-border);
  border-radius: 8px;
  padding: 12px 0;
  cursor: pointer;
  font-size: 0.95rem;
}
.calc-key:hover { background: rgba(77,255,240,0.15); }
.calc-key.op { color: var(--accent); }

/* Explorer */
#explorerbody { position: relative; padding: 10px; gap: 8px; }
#explorerSearch { flex: none; padding-left: 30px; }
#explorerCanvas {
  flex: 1;
  width: 100%;
  height: 100%;
  cursor: grab;
  border-radius: 8px;
}
#explorerCanvas:active { cursor: grabbing; }

.face-title, .face-description, .action-button {
  position: absolute;
  pointer-events: none;
  transition: opacity 0.3s ease;
}
.face-title { left: 24px; bottom: 76px; font-size: 1.1rem; color: var(--accent); margin: 0; }
.face-description { left: 24px; bottom: 54px; font-size: 0.7rem; color: var(--text-dim); margin: 0; max-width: 60%; }
.action-button {
  right: 24px; bottom: 54px;
  width: 34px; height: 34px;
  border-radius: 50%;
  background: var(--accent);
  color: #05070c;
  display: flex; align-items: center; justify-content: center;
  text-decoration: none;
  font-weight: bold;
}
.face-title.active, .face-description.active, .action-button.active { opacity: 1; pointer-events: auto; }
.face-title.inactive, .face-description.inactive, .action-button.inactive { opacity: 0; }

/* Taskbar (restores minimized windows) */
#taskbar {
  position: absolute;
  bottom: 0; left: 0;
  width: 100%;
  min-height: 40px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 16px;
  background: rgba(6, 10, 16, 0.45);
  backdrop-filter: blur(14px);
  border-top: 1px solid var(--glass-border);
  z-index: 100;
}
.task-chip {
  background: var(--glass);
  border: 1px solid var(--glass-border);
  color: var(--text);
  border-radius: 8px;
  padding: 6px 12px;
  font-size: 0.75rem;
  cursor: pointer;
}
.task-chip:hover { background: rgba(77,255,240,0.12); border-color: var(--accent); }

/* Explorer hint */
.explorer-hint { color: var(--text-dim); font-size: 0.72rem; line-height: 1.4; margin: 0; }

/* scramble-reveal text effect */
.decrypt-char { transition: color 0.1s ease; }
.decrypt-char.encrypted { color: var(--accent-dim); }
.decrypt-char.revealed { color: var(--accent); }

/* ===== Secure ID welcome card (ReflectiveCard port) ===== */
#welcomebody { padding: 0; }
.reflective-card-container {
  position: relative;
  width: 100%;
  height: 100%;
  border-radius: var(--radius);
  overflow: hidden;
  background: #10161c;
  isolation: isolate;
}
.reflective-svg-filters { position: absolute; width: 0; height: 0; pointer-events: none; opacity: 0; }
.reflective-video {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  object-fit: cover;
  transform: scale(1.2) scaleX(-1);
  filter: saturate(0.4) contrast(120%) brightness(110%) blur(10px) url(#metallic-displacement);
  z-index: 0;
  opacity: 0.9;
}
.reflective-noise {
  position: absolute; inset: 0; z-index: 1;
  opacity: 0.4;
  pointer-events: none;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noiseFilter'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.8' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noiseFilter)'/%3E%3C/svg%3E");
  mix-blend-mode: overlay;
}
.reflective-sheen {
  position: absolute; inset: 0; z-index: 2;
  background: linear-gradient(135deg, rgba(77,255,240,0.3) 0%, rgba(77,255,240,0.08) 40%, rgba(77,255,240,0) 50%, rgba(77,255,240,0.08) 60%, rgba(77,255,240,0.25) 100%);
  pointer-events: none;
  mix-blend-mode: overlay;
}
.reflective-border {
  position: absolute; inset: 0;
  border-radius: var(--radius);
  padding: 1px;
  background: linear-gradient(135deg, rgba(77,255,240,0.8) 0%, rgba(77,255,240,0.2) 50%, rgba(77,255,240,0.6) 100%);
  -webkit-mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
  -webkit-mask-composite: xor;
  mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
  mask-composite: exclude;
  z-index: 20;
  pointer-events: none;
}
.reflective-content {
  position: relative; z-index: 10;
  height: 100%;
  display: flex; flex-direction: column; justify-content: space-between;
  padding: 24px;
  color: var(--text);
  background: rgba(5,7,12,0.25);
}
.reflective-content .card-header {
  display: flex; justify-content: space-between; align-items: center;
  border-bottom: 1px solid var(--glass-border);
  padding-bottom: 14px;
}
.reflective-content .security-badge {
  display: flex; align-items: center; gap: 6px;
  font-size: 0.65rem; font-weight: 700; letter-spacing: 0.1em;
  padding: 4px 8px;
  background: rgba(77,255,240,0.1);
  border-radius: 4px;
  border: 1px solid var(--glass-border);
  color: var(--accent);
}
.reflective-content .status-icon { opacity: 0.8; color: var(--accent); }
.reflective-content .card-body {
  flex: 1;
  display: flex; flex-direction: column; justify-content: end; align-items: center;
  text-align: center;
}
.reflective-content .user-name { font-size: 1.3rem; font-weight: 700; letter-spacing: 0.05em; margin: 0 0 8px 0; color: var(--accent); }
.reflective-content .user-role { font-size: 0.7rem; letter-spacing: 0.2em; opacity: 0.7; margin: 0; text-transform: uppercase; }
.reflective-content .card-footer {
  display: flex; justify-content: space-between; align-items: flex-end;
  border-top: 1px solid var(--glass-border);
  padding-top: 16px;
}
.reflective-content .id-section { display: flex; flex-direction: column; gap: 4px; }
.reflective-content .label { font-size: 0.6rem; letter-spacing: 0.1em; opacity: 0.6; }
.reflective-content .value { font-family: var(--font); font-size: 0.8rem; letter-spacing: 0.05em; }
.reflective-content .fingerprint-icon { opacity: 0.5; color: var(--accent); }

/* ===== Shared building blocks: tabs, badges, meters, terminal ===== */

.tab-bar { display: flex; gap: 4px; border-bottom: 1px solid var(--glass-border); margin-bottom: 10px; flex-wrap: wrap; }
.tab-btn {
  background: none; border: none; color: var(--text-dim);
  padding: 6px 10px; font-size: 0.72rem; cursor: pointer;
  border-bottom: 2px solid transparent;
}
.tab-btn:hover { color: var(--text); }
.tab-btn.active { color: var(--accent); border-bottom-color: var(--accent); }
.tab-panel { display: none; flex: 1; overflow-y: auto; flex-direction: column; gap: 10px; }
.tab-panel.active { display: flex; }

.badge-sim, .badge-real {
  display: inline-block; font-size: 0.6rem; letter-spacing: 0.08em; font-weight: 700;
  padding: 2px 7px; border-radius: 4px; text-transform: uppercase;
}
.badge-sim { background: rgba(255,93,108,0.12); border: 1px solid var(--danger); color: var(--danger); }
.badge-real { background: rgba(77,255,240,0.12); border: 1px solid var(--accent); color: var(--accent); }

.meter { display: flex; flex-direction: column; gap: 4px; }
.meter-label { display: flex; justify-content: space-between; font-size: 0.7rem; color: var(--text-dim); }
.meter-track { height: 8px; border-radius: 4px; background: rgba(0,0,0,0.35); overflow: hidden; }
.meter-fill { height: 100%; background: var(--accent-dim); transition: width 0.3s ease; }
.meter-fill.weak { background: var(--danger); }
.meter-fill.strong { background: var(--accent); }

.terminal-output {
  flex: 1; overflow-y: auto; font-size: 0.78rem; line-height: 1.5;
  white-space: pre-wrap; word-break: break-word;
}
.terminal-line { margin: 0; }
.terminal-line.cmd { color: var(--accent); }
.terminal-line.err { color: var(--danger); }
.terminal-input-row { display: flex; align-items: center; gap: 6px; }
.terminal-prompt { color: var(--accent); font-size: 0.8rem; }
.terminal-input-row input {
  flex: 1; background: transparent; border: none; padding: 4px 0;
  font-size: 0.8rem; outline: none;
}

