:root {
  --bg: #202020;
  --panel: #fbfaf7;
  --panel-fg: #1d1d1f;
  --muted: #66655f;
  --line: #dddbd3;
  --accent: #2f5d8a;
  --accent-fg: #ffffff;
  --danger: #a3362b;
  --row: #f1efe9;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --panel: #26262a;
    --panel-fg: #ececef;
    --muted: #a3a3aa;
    --line: #3b3b41;
    --accent: #7fb0de;
    --accent-fg: #101418;
    --danger: #f08a7e;
    --row: #2f2f34;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overscroll-behavior: none;
}

#screen {
  position: fixed;
  inset: 0;
  overflow: hidden;
  background: var(--bg);
}

#canvas {
  position: absolute;
  left: 0;
  top: 0;
  display: block;
  image-rendering: pixelated;
  outline: none;
  touch-action: none;
  cursor: text;
}

/* ---- toolbar: shown while the mouse moves near the top ---- */
#toolbar {
  position: fixed;
  top: 8px;
  right: 8px;
  display: flex;
  gap: 6px;
  opacity: 0;
  transform: translateY(-6px);
  transition: opacity 0.25s, transform 0.25s;
  pointer-events: none;
  z-index: 5;
}
#toolbar.shown {
  opacity: 0.92;
  transform: none;
  pointer-events: auto;
}
#toolbar button {
  font: inherit;
  font-size: 13px;
  padding: 4px 10px;
  border-radius: 6px;
  border: 1px solid rgba(255, 255, 255, 0.25);
  background: rgba(32, 32, 32, 0.85);
  color: #f2f2f2;
  cursor: pointer;
}
#toolbar button:hover { background: rgba(60, 60, 60, 0.95); }

/* ---- panels ---- */
.panel-backdrop {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(0, 0, 0, 0.55);
  z-index: 10;
}
.panel-backdrop[hidden] { display: none; }
#message { background: var(--bg); }

.panel {
  background: var(--panel);
  color: var(--panel-fg);
  border-radius: 10px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.45);
  width: min(640px, 100%);
  max-height: 100%;
  overflow: auto;
  padding: 20px 24px;
}
.panel h1 { font-size: 20px; margin: 0 0 12px; }
.panel h2 { font-size: 16px; margin: 0; }
.panel p { margin: 0 0 10px; }
.panel a { color: var(--accent); }
.panel ul { margin: 0 0 10px; padding-left: 22px; }
.panel .version { color: var(--muted); font-size: 12px; margin: 14px 0 0; }
.panel .hint { color: var(--muted); font-size: 13px; }

.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.actions.top { margin: 4px 0 12px; }
.panel button {
  font: inherit;
  font-size: 14px;
  padding: 6px 12px;
  border-radius: 6px;
  border: 1px solid var(--line);
  background: var(--row);
  color: var(--panel-fg);
  cursor: pointer;
}
.panel button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-fg);
}
.panel button:disabled { opacity: 0.5; cursor: default; }
.panel button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

/* ---- Files panel ---- */
.files-panel { width: min(760px, 100%); }
.files-panel header { display: flex; align-items: center; justify-content: space-between; }
.files-panel .close {
  font-size: 22px;
  line-height: 1;
  padding: 2px 10px;
  border: none;
  background: transparent;
}
#files-status { min-height: 1.45em; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
#files-status.error { color: var(--danger); }

.project {
  border: 1px solid var(--line);
  border-radius: 8px;
  margin-bottom: 12px;
  overflow: hidden;
}
.project.drop { outline: 2px dashed var(--accent); outline-offset: -2px; }
.project-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background: var(--row);
}
.project-head h2 { flex: 1 1 auto; overflow-wrap: anywhere; }
.project-head button { font-size: 13px; padding: 4px 10px; background: var(--panel); }
.file {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 12px;
  border-top: 1px solid var(--line);
}
.file .name { flex: 1 1 auto; overflow-wrap: anywhere; }
.file .size { color: var(--muted); font-size: 13px; white-space: nowrap; }
.file .badge { font-size: 12px; color: var(--muted); white-space: nowrap; }
.file button { font-size: 13px; padding: 3px 10px; }
.empty { padding: 8px 12px; color: var(--muted); font-size: 13px; border-top: 1px solid var(--line); }

@media (max-width: 480px) {
  .panel { padding: 16px; }
  .file { flex-wrap: wrap; }
}
