:root {
  --bg: #111;
  --surface: #000;
  --border: #333;
  --border-strong: #555;
  --text: #fff;
  --muted: #999;
  --ok: #44cc66;
  --warn: #e5a00d;
  --err: #ff5f56;
  --accent: wheat;
  --accent-dim: rgba(245, 222, 179, 0.12);
  --serial-focus: rgb(229, 151, 0);
  --font-mono: "JetBrains Mono", "DejaVu Sans Mono", "Liberation Mono", monospace;
  --radius: 0;
  --gap: 12px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--font-mono);
  font-size: 13px;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

a {
  color: wheat;
  text-decoration: none;
  cursor: pointer;
}

a:hover { text-decoration: underline; }

/* ── Header ───────────────────────────────────── */

.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.header-brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.header-brand h1 {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--accent);
}

.header-brand span {
  font-size: 0.75rem;
  color: var(--muted);
  font-weight: 400;
}

.header-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.field {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.8rem;
  color: var(--muted);
  white-space: nowrap;
}

select {
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 0;
  padding: 5px 8px;
  font-family: inherit;
  font-size: 0.8rem;
}

.header-toolbar button {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 0;
  color: var(--text);
  padding: 5px 10px;
  cursor: pointer;
  font-family: inherit;
  font-size: 0.8rem;
  font-weight: 400;
  transition: border-color 0.15s, background 0.15s;
}

.header-toolbar button:hover {
  background: var(--bg);
  border-color: var(--border-strong);
}

/* ── Main Layout ──────────────────────────────── */

.main {
  display: flex;
  flex: 1;
  min-height: 0;
}

.vm-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  padding: var(--gap);
}

#screen_container {
  flex: 1;
  min-height: 280px;
  outline: 1px solid var(--border-strong);
  background: #000;
  overflow: hidden;
  contain: layout paint;
  transition: opacity 0.3s ease;
}

#screen_container > div {
  white-space: pre;
  font: 15px var(--font-mono);
  font-weight: bold;
  color: #e6e9ed;
  padding: 8px;
}

#screen_container > canvas {
  display: block;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

#screen_container:fullscreen,
#screen_container:-webkit-full-screen {
  display: flex !important;
  align-items: center;
  justify-content: center;
  background: #000;
}

#screen_container:fullscreen #vga,
#screen_container:-webkit-full-screen #vga {
  width: auto !important;
  height: 100% !important;
  max-width: 100%;
  max-height: 100%;
}

/* ── Boot Progress ────────────────────────────── */

.boot-progress {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.75rem;
  color: var(--muted);
  margin-top: 8px;
}

.boot-step { opacity: 0.4; }
.boot-step.active { opacity: 1; color: var(--accent); }
.boot-step.done { opacity: 1; color: var(--ok); }

/* ── Loading Skeleton ─────────────────────────── */

.boot-skeleton {
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 1;
  min-height: 280px;
  border: 1px solid var(--border);
  background: var(--surface);
  flex-direction: column;
  gap: 16px;
}

.boot-skeleton.hidden { display: none; }

.skeleton-spinner {
  width: 40px;
  height: 40px;
  border: 3px solid #222;
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

.skeleton-text {
  font-size: 0.85rem;
  color: var(--muted);
}

.skeleton-steps {
  display: flex;
  gap: 8px;
  font-size: 0.75rem;
  color: var(--muted);
}

.skeleton-steps .step { opacity: 0.4; }
.skeleton-steps .step.active { opacity: 1; color: var(--accent); }
.skeleton-steps .step.done { opacity: 1; color: var(--ok); }

/* ── Menu ─────────────────────────────────────── */

.menu-panel {
  display: none;
  position: sticky;
  top: 0;
  z-index: 50;
  max-height: 62vh;
  overflow-y: auto;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.menu-panel.open { display: block; }

.menu-inner {
  max-width: 1100px;
  margin: 0 auto;
  padding: 14px 20px;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 18px;
}

.menu-group { min-width: 0; }

.menu-btn {
  font-size: 1.05rem;
  line-height: 1;
}

.menu-btn.active {
  border-color: var(--accent);
  color: var(--accent);
}

.panel-title {
  margin: 0 0 10px;
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--accent);
}

.row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 10px;
}

.row:last-of-type { margin-bottom: 0; }

.progress {
  height: 2px;
  margin-top: 8px;
  background: #1c1c1c;
}

.progress[hidden] { display: none; }

.progress .progress-fill {
  height: 100%;
  width: 0;
  background: var(--accent);
  transition: width 0.2s ease;
}

/* ── Buttons ──────────────────────────────────── */

button, .labelBtn {
  background: #222;
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 0;
  padding: 7px 11px;
  cursor: pointer;
  font-family: inherit;
  font-size: 0.8rem;
  font-weight: 400;
  transition: border-color 0.15s, background 0.15s;
}

button:hover, .labelBtn:hover {
  background: #2b2b2b;
  border-color: var(--border-strong);
}

.labelBtn input { display: none; }

/* ── Serial Console ───────────────────────────── */

#serialDetails { margin-top: 12px; }

#serialDetails summary {
  cursor: pointer;
  color: var(--muted);
  font-size: 0.85rem;
}

#serial_console {
  margin-top: 8px;
  height: 120px;
  overflow: auto;
  user-select: text;
  -webkit-user-select: text;
  background: #000;
  border: 1px solid var(--border);
  padding: 8px;
  color: #c8c8c8;
  font: 13px var(--font-mono);
  white-space: pre-wrap;
  word-break: break-word;
}

.serial-controls {
  display: flex;
  gap: 8px;
  margin-top: 8px;
}

#serial_input {
  flex: 1;
  background: #000;
  border: 1px solid var(--border);
  border-radius: 0;
  color: var(--text);
  padding: 7px 9px;
  font: 13px var(--font-mono);
}

#serial_input:focus {
  outline: 1px solid var(--serial-focus);
}

/* ── Dropzone ─────────────────────────────────── */

.dropzone {
  border: 1px dashed var(--border-strong);
  border-radius: 0;
  padding: 16px;
  text-align: center;
  color: var(--muted);
  font-size: 0.85rem;
  margin-bottom: 10px;
  transition: border-color 0.2s, background 0.2s;
}

.dropzone.active {
  border-color: var(--accent);
  background: var(--accent-dim);
  color: var(--text);
}

/* ── Status ───────────────────────────────────── */

.status {
  min-height: 20px;
  margin-bottom: 8px;
  font-size: 0.8rem;
  color: var(--muted);
  transition: color 0.2s;
}

.status.ok { color: var(--ok); }
.status.warn { color: var(--warn); }
.status.err { color: var(--err); }

.status::before {
  content: "$ ";
  color: var(--muted);
  font-weight: 700;
}

/* ── Toast Notifications ──────────────────────── */

.toast-container {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 2000;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}

.toast {
  background: #000;
  border: 1px solid var(--border);
  border-radius: 0;
  padding: 10px 16px;
  font-size: 0.8rem;
  color: var(--text);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
  pointer-events: auto;
  animation: toast-in 0.25s ease, toast-out 0.25s ease forwards;
  animation-delay: 0s, 3s;
  max-width: 320px;
}

.toast.ok { border-left: 3px solid var(--ok); }
.toast.warn { border-left: 3px solid var(--warn); }
.toast.err { border-left: 3px solid var(--err); }

@keyframes toast-in {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes toast-out {
  from { opacity: 1; }
  to { opacity: 0; }
}

/* ── Files Table ──────────────────────────────── */

.files-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8rem;
}

.files-table th,
.files-table td {
  padding: 8px;
  border-bottom: 1px solid var(--border);
  text-align: left;
}

.files-table th {
  color: var(--muted);
  font-weight: 700;
  white-space: nowrap;
}

.hint {
  font-size: 0.75rem;
  color: var(--muted);
  margin-top: 8px;
  margin-bottom: 0;
}

/* ── Snapshots ────────────────────────────────── */

.snapshots-panel summary {
  cursor: pointer;
  color: var(--muted);
  font-size: 0.85rem;
}

.snapshot-list {
  list-style: none;
  padding: 0;
  margin: 8px 0 0;
  max-height: 120px;
  overflow-y: auto;
}

.snapshot-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 6px 8px;
  margin-bottom: 4px;
  background: #0c0c0c;
  font-size: 0.8rem;
}

.snapshot-list li span {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
}

.snapshot-list .snapshot-actions {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}

/* ── Modals ───────────────────────────────────── */

.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.85);
  z-index: 1000;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal-overlay.open { display: flex; }

.modal-content {
  background: #000;
  border: 1px solid var(--border);
  padding: 20px;
  max-width: 420px;
  width: 100%;
}

.modal-content h3 {
  margin: 0 0 12px;
  font-size: 1rem;
  color: var(--accent);
}

.modal-content table {
  width: 100%;
  font-size: 0.85rem;
}

.modal-content td {
  padding: 6px 8px;
  border-bottom: 1px solid var(--border);
}

.modal-content td:last-child { color: var(--muted); }

.modal-content code {
  font-size: 0.8rem;
}

.modal-close {
  margin-top: 12px;
  width: 100%;
}

.modal-content pre {
  margin: 12px 0;
  padding: 12px;
  background: #000;
  border: 1px solid #222;
  font-size: 0.85rem;
  overflow: auto;
  max-height: 240px;
  white-space: pre-wrap;
}

/* ── Footer ───────────────────────────────────── */

.footer {
  padding: 8px 20px;
  font-size: 0.75rem;
  color: var(--muted);
  border-top: 1px solid var(--border);
  background: var(--surface);
}

.footer a {
  color: wheat;
  text-decoration: none;
}

.footer a:hover { text-decoration: underline; }

/* ── Utilities ────────────────────────────────── */

code { color: var(--accent); font-family: var(--font-mono); }

.text-input {
  flex: 1;
  min-width: 220px;
  background: #000;
  border: 1px solid var(--border);
  border-radius: 0;
  color: var(--text);
  padding: 7px 9px;
  font-size: 0.8rem;
}

.text-input:focus,
.text-input-sm:focus {
  outline: 1px solid var(--serial-focus);
}

.text-input-sm {
  flex: 1;
  background: #000;
  border: 1px solid var(--border);
  border-radius: 0;
  color: var(--text);
  padding: 6px 8px;
  font-size: 0.8rem;
}

/* ── Responsive ───────────────────────────────── */

@media (max-width: 900px) {
  .header {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
  }

  .header-brand { justify-content: center; }
  .header-toolbar { justify-content: center; }

  .main { flex-direction: column; }

  .menu-inner {
    grid-template-columns: 1fr;
    padding: 12px;
  }
}