/* ============================================================
   WinBox — retro / nostalgic UI (Windows 98 inspired, no emojis)
   ============================================================ */

:root {
  --bg-desktop: #008080;
  --bg-window: #c0c0c0;
  --bg-window-light: #dcdcdc;
  --bg-menu: #c0c0c0;
  --title-start: #000080;
  --title-end: #1084d0;
  --title-inactive: #808080;
  --btn-face: #c0c0c0;
  --btn-hover: #d4d4d4;
  --text: #000000;
  --text-dim: #404040;
  --text-invert: #ffffff;
  --highlight: #000080;
  --border-light: #ffffff;
  --border-mid: #808080;
  --border-dark: #000000;
  --font: Tahoma, "MS Sans Serif", "Segoe UI", Geneva, Verdana, sans-serif;
  --font-mono: "Courier New", monospace;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
}

body {
  font-family: var(--font);
  font-size: 13px;
  background: var(--bg-desktop);
  color: var(--text);
  overflow-x: hidden;
}

a { color: var(--highlight); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------- window chrome helpers ---------- */
.win {
  background: var(--bg-window);
  border: 1px solid var(--border-light);
  outline: 1px solid var(--border-dark);
  box-shadow: 3px 3px 0 rgba(0,0,0,.3);
  border-radius: 0;
}

.titlebar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 3px 4px;
  background: linear-gradient(90deg, var(--title-start), var(--title-end));
  color: var(--text-invert);
  font-weight: bold;
  font-size: 12px;
  user-select: none;
}
.titlebar.gray { background: linear-gradient(90deg, var(--title-inactive), #b0b0b0); }

.titlebar .title-text { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.titlebar .icon { width: 16px; height: 16px; border: 1px solid #000; background: var(--bg-window); color:#000; text-align:center; font-size:10px; line-height:14px; }

.tb-btn {
  width: 18px; height: 16px;
  background: var(--btn-face);
  border: 1px solid var(--border-light);
  border-right-color: var(--border-dark);
  border-bottom-color: var(--border-dark);
  color: #000;
  font-family: var(--font);
  font-size: 11px;
  line-height: 1;
  cursor: pointer;
  text-align: center;
  padding: 0;
}
.tb-btn:active { border: 1px solid var(--border-dark); border-right-color: var(--border-light); border-bottom-color: var(--border-light); }

/* ---------- header / nav ---------- */
header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 8px;
  background: var(--bg-desktop);
  border-bottom: 1px solid var(--border-dark);
}
header .logo {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-window);
  border: 1px solid var(--border-light);
  border-right-color: var(--border-dark);
  border-bottom-color: var(--border-dark);
  padding: 3px 10px;
  color: var(--text);
  font-weight: bold;
  font-size: 13px;
  text-decoration: none;
}
header .logo:hover { text-decoration: none; }
header .logo .icon { width: 14px; height: 14px; background: var(--highlight); }
header nav { display: flex; gap: 4px; }
header nav a {
  background: var(--btn-face);
  border: 1px solid var(--border-light);
  border-right-color: var(--border-dark);
  border-bottom-color: var(--border-dark);
  padding: 3px 10px;
  color: var(--text);
  font-size: 12px;
}
header nav a:hover { text-decoration: none; background: var(--btn-hover); }

/* ---------- classic button ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  background: var(--btn-face);
  border: 1px solid var(--border-light);
  border-right-color: var(--border-dark);
  border-bottom-color: var(--border-dark);
  color: var(--text);
  font-family: var(--font);
  font-size: 13px;
  padding: 5px 14px;
  cursor: pointer;
  user-select: none;
  text-decoration: none;
}
.btn:hover { background: var(--btn-hover); }
.btn:active {
  border: 1px solid var(--border-dark);
  border-right-color: var(--border-light);
  border-bottom-color: var(--border-light);
  background: var(--bg-window);
}
.btn:disabled { color: var(--text-dim); background: var(--bg-window); cursor: default; }
.btn.primary { color: var(--text-invert); font-weight: bold; }
.btn.primary:hover { filter: brightness(1.05); }
.btn.small { font-size: 11px; padding: 2px 8px; }
.btn.square { width: 30px; height: 26px; padding: 0; }

/* ---------- welcome view ---------- */
#welcome-view {
  max-width: 860px;
  margin: 0 auto;
  padding: 20px 16px 60px;
}
.hero.win { padding: 0; margin-bottom: 18px; }
.hero .titlebar { padding: 6px 8px; font-size: 14px; }
.hero .body { padding: 18px 22px; }
.hero h1 { font-size: 22px; margin-bottom: 10px; color: var(--highlight); }
.hero p { font-size: 13px; line-height: 1.55; color: var(--text); }
.hero .hint { margin-top: 10px; font-size: 12px; color: var(--text-dim); }

.features { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; margin: 18px 0; }
.feature-card.win { padding: 12px 14px; }
.feature-card h3 { font-size: 13px; margin-bottom: 6px; color: var(--highlight); }
.feature-card p { font-size: 12px; color: var(--text); line-height: 1.4; }
.feature-card .glyph { font-size: 18px; margin-bottom: 6px; color: var(--text-dim); }

/* ---------- upload ---------- */
.upload-section.win { padding: 0; margin: 18px 0; }
.upload-section .titlebar { padding: 4px 8px; }
.dropzone {
  width: 100%;
  min-height: 120px;
  background: var(--bg-window-light);
  border: 2px dashed var(--border-mid);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 24px;
  cursor: pointer;
  text-align: center;
}
.dropzone:hover, .dropzone.dragover { border-color: var(--highlight); background: #d0e0ff; }
.dropzone .big { font-size: 14px; font-weight: bold; }
.dropzone .sub { font-size: 12px; color: var(--text-dim); }

.file-list { padding: 8px 10px; }
.file-list .empty { padding: 12px; text-align: center; color: var(--text-dim); font-size: 12px; }
.file-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 6px;
  margin-bottom: 2px;
  background: var(--bg-window-light);
}
.file-item:nth-child(odd) { background: #d4d4d4; }
.file-item .name { flex: 1; font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-item .size { color: var(--text-dim); font-size: 11px; white-space: nowrap; }
.file-item .remove { cursor: pointer; color: var(--text-dim); font-weight: bold; padding: 0 4px; }
.file-item .remove:hover { color: #000; }

.actions { display: flex; gap: 10px; margin-top: 16px; flex-wrap: wrap; }

/* ---------- emulator view ---------- */
#emulator-view { display: none; height: 100vh; flex-direction: column; background: #000; }
#emulator-view.active { display: flex; }

.emulator-toolbar { display: flex; align-items: center; gap: 8px; padding: 4px 8px; background: var(--bg-desktop); }
.emulator-toolbar .titlebar { flex: 1; }
.emulator-toolbar .status { font-size: 11px; font-weight: normal; display: inline-flex; align-items: center; gap: 6px; }
.emulator-toolbar .status .dot { width: 9px; height: 9px; border: 1px solid #000; display: inline-block; }
.emulator-toolbar .status .dot.running { background: #00ff00; }
.emulator-toolbar .status .dot.loading { background: #ffff00; }
.emulator-toolbar .status .dot.stopped { background: #ff0000; }

.canvas-wrapper {
  flex: 1;
  position: relative;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #000;
  min-height: 0;
  touch-action: none;
}
.canvas-wrapper canvas {
  display: block;
  max-width: 100%;
  max-height: 100%;
  image-rendering: pixelated;
  cursor: crosshair;
}

#loading-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: #000080;
  z-index: 10;
  gap: 12px;
}
#loading-overlay.hidden { display: none; }
#loading-overlay .box.win { padding: 18px 26px; text-align: center; }
#loading-overlay .box.win h2 { font-size: 15px; margin-bottom: 10px; color: var(--highlight); }
#loading-overlay .box.win p { font-size: 12px; color: var(--text); margin-bottom: 8px; }
#loading-overlay progress { width: 260px; height: 18px; }

/* classic progress bar */
progress[value] { -webkit-appearance: none; appearance: none; }
progress[value]::-webkit-progress-bar { background: var(--bg-window-light); border: 1px solid var(--border-mid); }
progress[value]::-webkit-progress-value { background: var(--highlight); }

.emulator-bottom {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px;
  background: var(--bg-desktop);
  border-top: 1px solid var(--border-dark);
  flex-wrap: wrap;
}
.emulator-bottom .spacer { flex: 1; }

#console {
  width: 100%;
  height: 110px;
  background: #000;
  color: #a5d6a7;
  font-family: var(--font-mono);
  font-size: 11px;
  padding: 6px 8px;
  border: none;
  resize: vertical;
  display: none;
}
#console.visible { display: block; }

/* ---------- touch controls (Winlator style) ---------- */
#touch-controls {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 5;
  display: none;
}
#touch-controls.active { display: block; }

.tc-btn {
  pointer-events: auto;
  position: absolute;
  width: 52px;
  height: 52px;
  background: rgba(0,0,0,.35);
  border: 2px solid rgba(255,255,255,.6);
  border-radius: 10px;
  color: #fff;
  font-family: var(--font);
  font-size: 16px;
  font-weight: bold;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}
.tc-btn:active { background: rgba(255,255,255,.35); }
.tc-btn .key { font-size: 10px; opacity: .8; display: block; }

/* left zone: d-pad */
#tc-left { position: absolute; left: 14px; bottom: 14px; width: 170px; height: 150px; }
#tc-up { left: 56px; top: 0; }
#tc-down { left: 56px; top: 98px; }
#tc-leftb { left: 0; top: 49px; }
#tc-rightb { left: 112px; top: 49px; }

/* right zone: action buttons */
#tc-right { position: absolute; right: 14px; bottom: 14px; width: 200px; height: 150px; }
#tc-a { right: 0; top: 0; width: 62px; height: 62px; border-radius: 50%; }
#tc-b { right: 74px; top: 52px; }
#tc-y { right: 0; top: 74px; }
#tc-click { right: 0; bottom: 0; }
#tc-rclick { right: 60px; bottom: 0; }
#tc-esc { left: 10px; bottom: 4px; width: 46px; height: 40px; }
#tc-enter { left: 64px; bottom: 4px; width: 46px; height: 40px; }
#tc-space { left: 118px; bottom: 4px; width: 70px; height: 34px; }

/* ---------- modal ---------- */
.modal {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 200;
  background: rgba(0,0,0,.55);
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.modal.active { display: flex; }
.modal-content.win { width: 100%; max-width: 460px; max-height: 80vh; display: flex; flex-direction: column; }
.modal-content .titlebar { padding: 4px 6px; }
.modal-content .body { padding: 14px 16px; overflow-y: auto; }
.modal-content .body h3 { font-size: 13px; margin-bottom: 10px; }
.form-group { margin-bottom: 12px; }
.form-group label { display: block; font-size: 12px; margin-bottom: 3px; }
select, input[type="range"] {
  width: 100%;
  background: var(--bg-window-light);
  border: 1px solid var(--border-mid);
  font-family: var(--font);
  font-size: 12px;
  padding: 4px 6px;
  color: var(--text);
}
.toggle-row { display: flex; justify-content: space-between; align-items: center; padding: 4px 0; }
.toggle-row label { font-size: 12px; }
.check {
  width: 14px; height: 14px;
  border: 1px solid var(--border-dark);
  background: var(--bg-window-light);
  cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 11px; color: var(--highlight);
}
.check.on::before { content: "\2713"; }

.file-browser .file-entry {
  padding: 4px 6px; cursor: pointer; display: flex; align-items: center; gap: 6px; font-size: 12px;
}
.file-browser .file-entry:hover { background: var(--highlight); color: #fff; }
.file-browser .file-entry .glyph { width: 16px; }
.file-browser .file-entry .glyph.folder { color: inherit; }

/* ---------- virtual D: file browser tree ---------- */
#fs-browser-body { font-family: var(--font-mono); font-size: 12px; max-height: 46vh; overflow-y: auto; }
#fs-browser-body table { border-collapse: collapse; width: 100%; }
#fs-browser-body td { padding: 1px 2px; white-space: nowrap; }
#fs-browser-body .fs-dir { cursor: pointer; color: var(--highlight); font-weight: bold; }
#fs-browser-body .fs-dirname { cursor: default; }
#fs-browser-body .fs-children { margin-left: 14px; }
#fs-browser-body .fs-file { cursor: pointer; }
#fs-browser-body .fs-file:hover { background: var(--highlight); color: #fff; }
#fs-browser-body .empty { padding: 8px; color: var(--text-dim); }

/* ---------- mobile ---------- */
@media (max-width: 640px) {
  body { font-size: 14px; }
  header { flex-wrap: wrap; gap: 4px; }
  header nav a { font-size: 11px; padding: 2px 6px; }
  .hero h1 { font-size: 18px; }
  .features { grid-template-columns: 1fr 1fr; }
  .emulator-toolbar .titlebar .title-text { max-width: 90px; }
  .canvas-wrapper canvas { width: 100% !important; }
  #tc-btn-run { }
}
@media (max-width: 380px) {
  .features { grid-template-columns: 1fr; }
}