/* ===== CSS Variables - Tokyo Night ===== */
:root {
  --bg-base: #13141c;
  --bg-surface: #16161e;
  --bg-overlay: #1e1f2e;
  --bg-hover: #292e42;
  --text-primary: #c0caf5;
  --text-secondary: #a9b1d6;
  --text-muted: #565f89;
  --accent-blue: #7aa2f7;
  --accent-lavender: #bb9af7;
  --accent-pink: #f7768e;
  --accent-mauve: #bb9af7;
  --accent-green: #9ece6a;
  --accent-yellow: #e0af68;
  --accent-red: #f7768e;
  --accent-teal: #73daca;
  --border-color: #292e42;
  --window-shadow: 0 8px 32px rgba(0, 0, 0, 0.6);
  --titlebar-height: 30px;
  --taskbar-height: 34px;
  --font-mono: "JetBrains Mono", "Fira Code", "Cascadia Code", "Consolas", monospace;
  --font-ui: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

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

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

/* ===== Scanline Overlay ===== */
.scanlines {
  position: fixed;
  inset: 0;
  z-index: 9999;
  pointer-events: none;
  background: repeating-linear-gradient(
    0deg,
    transparent,
    transparent 2px,
    rgba(0, 0, 0, 0.02) 2px,
    rgba(0, 0, 0, 0.02) 4px
  );
}

/* ===== Desktop ===== */
#desktop {
  position: fixed;
  inset: 0;
  bottom: var(--taskbar-height);
  background:
    radial-gradient(ellipse at 20% 50%, rgba(122, 162, 247, 0.04) 0%, transparent 50%),
    radial-gradient(ellipse at 80% 20%, rgba(187, 154, 247, 0.03) 0%, transparent 50%),
    radial-gradient(ellipse at 50% 80%, rgba(247, 118, 142, 0.02) 0%, transparent 50%),
    linear-gradient(135deg, #0d0e14 0%, #13141c 50%, #16161e 100%);
  background-size: cover, cover, cover, cover, 40px 40px;
  overflow: hidden;
}

#desktop::before {
  content: "";
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(rgba(122, 162, 247, 0.02) 1px, transparent 1px),
    linear-gradient(90deg, rgba(122, 162, 247, 0.02) 1px, transparent 1px);
  background-size: 40px 40px;
  pointer-events: none;
}

/* ===== Desktop Icons ===== */
#desktop-icons {
  display: flex;
  flex-direction: column;
  flex-wrap: wrap;
  align-content: flex-start;
  gap: 4px;
  padding: 12px;
  height: 100%;
}

.desktop-icon {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 72px;
  padding: 6px 4px;
  border-radius: 4px;
  cursor: pointer;
  transition: background 0.15s;
}

.desktop-icon:hover {
  background: rgba(122, 162, 247, 0.1);
}

.desktop-icon:active {
  background: rgba(122, 162, 247, 0.2);
}

.desktop-icon .icon-img {
  font-size: 28px;
  line-height: 1;
  margin-bottom: 6px;
  font-family: var(--font-ui);
  font-weight: 300;
  color: var(--text-secondary);
}

.desktop-icon .icon-label {
  font-size: 11px;
  color: var(--text-primary);
  text-align: center;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.8);
  line-height: 1.2;
  word-break: break-word;
}

/* ===== Windows ===== */
#windows {
  position: fixed;
  inset: 0;
  bottom: var(--taskbar-height);
  pointer-events: none;
}

.window {
  position: absolute;
  min-width: 280px;
  min-height: 180px;
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: 4px;
  box-shadow: var(--window-shadow);
  display: flex;
  flex-direction: column;
  pointer-events: auto;
  overflow: hidden;
}

@keyframes window-open {
  from {
    opacity: 0;
    transform: scale(0.95) translateY(8px);
  }
  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

.window-opening {
  animation: window-open 0.2s ease-out;
}

.window.focused {
  z-index: 100;
  border-color: var(--accent-blue);
  box-shadow: var(--window-shadow), 0 0 0 1px rgba(122, 162, 247, 0.3);
}

.window.maximized {
  border-radius: 0;
  border: none;
}

.window.minimized {
  display: none;
}

@keyframes minimize-out {
  to {
    transform: scale(0.6) translateY(40px);
    opacity: 0;
  }
}

@keyframes minimize-in {
  from {
    transform: scale(0.6) translateY(40px);
    opacity: 0;
  }
  to {
    transform: scale(1) translateY(0);
    opacity: 1;
  }
}

.window.minimizing {
  animation: minimize-out 0.2s ease-in forwards;
  pointer-events: none;
}

.window.restoring {
  animation: minimize-in 0.2s ease-out forwards;
}

.window.animating-maximize {
  transition: top 0.2s ease, left 0.2s ease, width 0.2s ease, height 0.2s ease, border-radius 0.2s ease;
}

/* ===== Title Bar ===== */
.titlebar {
  height: var(--titlebar-height);
  background: var(--bg-overlay);
  display: flex;
  align-items: center;
  padding: 0 10px;
  cursor: default;
  flex-shrink: 0;
  border-bottom: 1px solid var(--border-color);
}

.window.focused .titlebar {
  background: linear-gradient(90deg, var(--bg-overlay), rgba(122, 162, 247, 0.04));
}

.titlebar-title {
  flex: 1;
  font-size: 11px;
  font-weight: 500;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-left: 4px;
}

.window.focused .titlebar-title {
  color: var(--text-primary);
}

.titlebar-controls {
  display: flex;
  gap: 6px;
  margin-left: 10px;
}

.titlebar-btn {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  border: none;
  cursor: pointer;
  transition: filter 0.15s;
}

.titlebar-btn:hover {
  filter: brightness(1.3);
}

.btn-close {
  background: var(--accent-red);
}

.btn-minimize {
  background: var(--accent-yellow);
}

.btn-maximize {
  background: var(--accent-green);
}

/* ===== Resize Handles ===== */
.resize-handle {
  position: absolute;
  z-index: 10;
}

.resize-n { top: -3px; left: 8px; right: 8px; height: 6px; cursor: n-resize; }
.resize-s { bottom: -3px; left: 8px; right: 8px; height: 6px; cursor: s-resize; }
.resize-w { left: -3px; top: 8px; bottom: 8px; width: 6px; cursor: w-resize; }
.resize-e { right: -3px; top: 8px; bottom: 8px; width: 6px; cursor: e-resize; }
.resize-nw { top: -3px; left: -3px; width: 10px; height: 10px; cursor: nw-resize; }
.resize-ne { top: -3px; right: -3px; width: 10px; height: 10px; cursor: ne-resize; }
.resize-sw { bottom: -3px; left: -3px; width: 10px; height: 10px; cursor: sw-resize; }
.resize-se { bottom: -3px; right: -3px; width: 10px; height: 10px; cursor: se-resize; }

/* ===== Window Content ===== */
.window-body {
  flex: 1;
  overflow: hidden;
  position: relative;
  display: flex;
  flex-direction: column;
}

/* ===== Taskbar ===== */
#taskbar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: var(--taskbar-height);
  background: var(--bg-surface);
  border-top: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  padding: 0 6px;
  z-index: 10000;
}

#start-btn {
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  cursor: pointer;
  transition: background 0.15s;
  flex-shrink: 0;
}

#start-btn:hover {
  background: var(--bg-hover);
}

#start-btn.active {
  background: var(--accent-blue);
}

.start-btn-icon {
  font-weight: 700;
  font-size: 14px;
  color: var(--accent-lavender);
}

#start-btn.active .start-btn-icon {
  color: var(--bg-base);
}

#taskbar-windows {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 3px;
  padding: 0 6px;
  overflow-x: auto;
}

.taskbar-item {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 3px 10px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 11px;
  color: var(--text-secondary);
  transition: background 0.15s;
  white-space: nowrap;
  flex-shrink: 0;
  border: 1px solid transparent;
}

.taskbar-item:hover {
  background: var(--bg-hover);
}

.taskbar-item.active {
  background: rgba(122, 162, 247, 0.1);
  color: var(--text-primary);
  border-color: rgba(122, 162, 247, 0.2);
}

.taskbar-item-icon {
  font-size: 13px;
}

#taskbar-tray {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 0 6px;
  flex-shrink: 0;
}

#clock {
  font-size: 11px;
  color: var(--text-secondary);
  font-family: var(--font-mono);
}

/* ===== Start Menu ===== */
#start-menu {
  position: fixed;
  bottom: var(--taskbar-height);
  left: 6px;
  width: 220px;
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: 4px;
  box-shadow: var(--window-shadow);
  z-index: 10001;
  overflow: hidden;
  animation: menu-open 0.15s ease-out;
}

@keyframes menu-open {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

#start-menu.hidden {
  display: none;
}

.start-menu-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border-color);
  font-weight: 600;
  font-size: 13px;
}

.start-logo {
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--accent-lavender);
  color: var(--bg-base);
  border-radius: 4px;
  font-weight: 800;
  font-size: 12px;
}

.start-menu-items {
  padding: 4px;
}

.start-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 10px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 12px;
  color: var(--text-secondary);
  transition: all 0.15s;
}

.start-item:hover {
  background: var(--accent-blue);
  color: var(--bg-base);
}

.start-item-icon {
  font-size: 15px;
  width: 18px;
  text-align: center;
  color: var(--text-secondary);
}

/* ===== Context Menu ===== */
#context-menu {
  position: fixed;
  min-width: 160px;
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: 4px;
  box-shadow: var(--window-shadow);
  z-index: 20000;
  padding: 3px 0;
  overflow: hidden;
}

#context-menu.hidden {
  display: none;
}

.ctx-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 12px;
  cursor: pointer;
  font-size: 12px;
  color: var(--text-secondary);
  transition: all 0.1s;
}

.ctx-item:hover {
  background: var(--accent-blue);
  color: var(--bg-base);
}

.ctx-item-icon {
  width: 16px;
  text-align: center;
  font-size: 13px;
  flex-shrink: 0;
}

.ctx-separator {
  height: 1px;
  background: var(--border-color);
  margin: 3px 6px;
}

/* ===== Tab Bar ===== */
.tab-bar {
  display: flex;
  align-items: center;
  background: var(--bg-overlay);
  border-bottom: 1px solid var(--border-color);
  flex-shrink: 0;
  overflow-x: auto;
  min-height: 28px;
}

.tab-bar::-webkit-scrollbar {
  height: 0;
}

.tab {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  font-size: 11px;
  color: var(--text-muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  white-space: nowrap;
  transition: all 0.15s;
  flex-shrink: 0;
  max-width: 140px;
}

.tab:hover {
  color: var(--text-secondary);
  background: var(--bg-hover);
}

.tab.active {
  color: var(--text-primary);
  border-bottom-color: var(--accent-blue);
}

.tab-title {
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
}

.tab-close {
  width: 14px;
  height: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 2px;
  font-size: 12px;
  opacity: 0;
  transition: all 0.15s;
  flex-shrink: 0;
}

.tab:hover .tab-close,
.tab.active .tab-close {
  opacity: 1;
}

.tab-close:hover {
  background: var(--accent-red);
  color: var(--bg-base);
}

.tab-add {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  margin: 0 4px;
  border-radius: 3px;
  font-size: 14px;
  color: var(--text-muted);
  cursor: pointer;
  flex-shrink: 0;
  transition: all 0.15s;
}

.tab-add:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.tab-content {
  flex: 1;
  overflow: hidden;
  position: relative;
  display: flex;
  flex-direction: column;
}

/* ===== Terminal App ===== */
.terminal-app {
  background: #0d0e14;
  color: var(--text-primary);
  font-family: var(--font-mono);
  font-size: 12px;
  flex: 1;
  overflow-y: auto;
}

.terminal-app.hidden {
  display: none;
}

.terminal-output {
  padding: 8px 10px;
  white-space: pre-wrap;
  word-break: break-all;
  line-height: 1.5;
}

.terminal-app::-webkit-scrollbar {
  width: 5px;
}

.terminal-app::-webkit-scrollbar-track {
  background: transparent;
}

.terminal-app::-webkit-scrollbar-thumb {
  background: var(--bg-hover);
  border-radius: 3px;
}

.terminal-prompt {
  color: var(--accent-green);
}

.terminal-prompt .path {
  color: var(--accent-blue);
}

.terminal-prompt .symbol {
  color: var(--text-muted);
}

.terminal-error {
  color: var(--accent-red);
}

.terminal-info {
  color: var(--accent-teal);
}

.terminal-motd {
  color: var(--accent-mauve);
}

.terminal-input-line {
  display: flex;
  align-items: center;
  padding: 0 10px 8px;
}

.terminal-prompt-label {
  color: var(--accent-green);
  margin-right: 6px;
  white-space: nowrap;
}

.terminal-prompt-label .path {
  color: var(--accent-blue);
}

.terminal-input {
  flex: 1;
  background: none;
  border: none;
  outline: none;
  color: var(--text-primary);
  font-family: var(--font-mono);
  font-size: 12px;
  caret-color: var(--accent-green);
}

/* ===== File Explorer ===== */
.explorer-app {
  background: var(--bg-surface);
  flex: 1;
  display: flex;
  flex-direction: column;
}

.explorer-toolbar {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 5px 8px;
  background: var(--bg-overlay);
  border-bottom: 1px solid var(--border-color);
  flex-shrink: 0;
}

.explorer-breadcrumb {
  display: flex;
  align-items: center;
  gap: 2px;
  flex: 1;
  font-size: 11px;
  color: var(--text-muted);
  overflow-x: auto;
  min-height: 22px;
}

.explorer-breadcrumb::-webkit-scrollbar {
  height: 0;
}

.breadcrumb-segment {
  cursor: pointer;
  padding: 2px 5px;
  border-radius: 3px;
  transition: all 0.15s;
  white-space: nowrap;
}

.breadcrumb-segment:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.breadcrumb-separator {
  color: var(--text-muted);
}

.explorer-path-input {
  flex: 1;
  background: var(--bg-base);
  border: 1px solid var(--accent-blue);
  border-radius: 3px;
  padding: 3px 8px;
  color: var(--text-primary);
  font-family: var(--font-mono);
  font-size: 11px;
  outline: none;
  display: none;
}

.explorer-path-input.visible {
  display: block;
}

.explorer-breadcrumb.hidden {
  display: none;
}

.explorer-toolbar-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border-radius: 3px;
  border: none;
  background: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 13px;
  transition: all 0.15s;
  flex-shrink: 0;
}

.explorer-toolbar-btn:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.explorer-toolbar-btn.active {
  color: var(--accent-blue);
}

.explorer-content {
  flex: 1;
  overflow-y: auto;
  padding: 6px;
}

.explorer-content::-webkit-scrollbar {
  width: 5px;
}

.explorer-content::-webkit-scrollbar-track {
  background: transparent;
}

.explorer-content::-webkit-scrollbar-thumb {
  background: var(--bg-hover);
  border-radius: 3px;
}

/* Explorer list view */
.explorer-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 8px;
  border-radius: 3px;
  cursor: pointer;
  transition: background 0.15s;
}

.explorer-item:hover {
  background: var(--bg-hover);
}

.explorer-item.selected {
  background: rgba(122, 162, 247, 0.15);
}

.explorer-item-icon {
  font-size: 16px;
  width: 20px;
  text-align: center;
  flex-shrink: 0;
}

.explorer-item-name {
  flex: 1;
  font-size: 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.explorer-item-size {
  font-size: 10px;
  color: var(--text-muted);
  font-family: var(--font-mono);
  flex-shrink: 0;
}

/* Explorer grid view */
.explorer-content.view-grid {
  display: flex;
  flex-wrap: wrap;
  align-content: flex-start;
  gap: 4px;
  padding: 8px;
}

.explorer-content.view-grid .explorer-item {
  flex-direction: column;
  width: 80px;
  padding: 8px 4px;
  text-align: center;
  gap: 4px;
}

.explorer-content.view-grid .explorer-item-icon {
  font-size: 32px;
  width: auto;
}

.explorer-content.view-grid .explorer-item-name {
  font-size: 11px;
  white-space: normal;
  word-break: break-word;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.explorer-content.view-grid .explorer-item-size {
  display: none;
}

.explorer-empty {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--text-muted);
  font-size: 12px;
}

/* ===== Notepad ===== */
.notepad-app {
  background: var(--bg-surface);
  flex: 1;
  display: flex;
  flex-direction: column;
}

.notepad-toolbar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  background: var(--bg-overlay);
  border-bottom: 1px solid var(--border-color);
  flex-shrink: 0;
}

.notepad-btn {
  padding: 3px 10px;
  background: var(--bg-hover);
  border: 1px solid var(--border-color);
  border-radius: 3px;
  color: var(--text-primary);
  font-size: 11px;
  cursor: pointer;
  transition: all 0.15s;
  font-family: var(--font-ui);
}

.notepad-btn:hover {
  background: var(--accent-blue);
  color: var(--bg-base);
  border-color: var(--accent-blue);
}

.notepad-filename {
  flex: 1;
  font-size: 11px;
  color: var(--text-secondary);
  text-align: right;
  font-family: var(--font-mono);
}

.notepad-status {
  font-size: 10px;
  color: var(--text-muted);
  padding: 2px 10px;
  background: var(--bg-overlay);
  border-top: 1px solid var(--border-color);
  flex-shrink: 0;
}

.notepad-status.saved {
  color: var(--accent-green);
}

.notepad-status.modified {
  color: var(--accent-yellow);
}

.notepad-editor {
  flex: 1;
  width: 100%;
  background: var(--bg-base);
  color: var(--text-primary);
  border: none;
  outline: none;
  padding: 10px;
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 1.6;
  resize: none;
  user-select: text;
  -webkit-user-select: text;
}

.notepad-editor::-webkit-scrollbar {
  width: 5px;
}

.notepad-editor::-webkit-scrollbar-track {
  background: transparent;
}

.notepad-editor::-webkit-scrollbar-thumb {
  background: var(--bg-hover);
  border-radius: 3px;
}

/* ===== Image Viewer ===== */
.viewer-app {
  background: #0d0e14;
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.viewer-img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

/* ===== README App ===== */
.readme-app {
  background: var(--bg-base);
  flex: 1;
  overflow-y: auto;
  padding: 20px 24px;
  color: var(--text-primary);
  font-family: var(--font-ui);
  line-height: 1.6;
}

.readme-app h1 {
  font-size: 20px;
  color: var(--accent-lavender);
  margin-bottom: 6px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border-color);
}

.readme-app h2 {
  font-size: 14px;
  color: var(--accent-blue);
  margin-top: 16px;
  margin-bottom: 6px;
}

.readme-app ul {
  margin: 6px 0;
  padding-left: 20px;
}

.readme-app li {
  margin: 3px 0;
  color: var(--text-secondary);
}

.readme-app p {
  margin: 6px 0;
  color: var(--text-secondary);
}

.readme-app code {
  background: var(--bg-overlay);
  padding: 1px 5px;
  border-radius: 3px;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--accent-teal);
}

/* ===== System App ===== */
.system-app {
  background: var(--bg-base);
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  color: var(--text-primary);
}

.system-app h2 {
  font-size: 14px;
  color: var(--accent-lavender);
  margin-bottom: 12px;
}

.system-group {
  margin-bottom: 16px;
}

.system-group-title {
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-bottom: 6px;
}

.system-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 7px 10px;
  background: var(--bg-surface);
  border-radius: 3px;
  margin-bottom: 3px;
}

.system-item label {
  font-size: 12px;
  color: var(--text-primary);
}

.system-item span {
  font-size: 11px;
  color: var(--accent-teal);
  font-family: var(--font-mono);
}

.sys-bar-container {
  height: 14px;
  background: var(--bg-overlay);
  border-radius: 7px;
  overflow: hidden;
  margin-bottom: 3px;
}

.sys-bar {
  height: 100%;
  background: linear-gradient(90deg, var(--accent-blue), var(--accent-lavender));
  border-radius: 7px;
  transition: width 0.5s ease;
  min-width: 2px;
}

.sys-bar-label {
  font-size: 11px;
  color: var(--text-secondary);
  font-family: var(--font-mono);
  padding: 0 10px;
  margin-bottom: 3px;
}

/* ===== Selection ===== */
::selection {
  background: rgba(122, 162, 247, 0.3);
  color: var(--text-primary);
}
