:root {
  --bg: #f4f5f7;
  --panel: #ffffff;
  --text: #1c1f24;
  --muted: #667085;
  --border: #d9dde3;
  --accent: #2563eb;
  --accent-soft: #e6eefe;
  --check-a: #e9ebee;
  --check-b: #ffffff;
  --bad: #c2410c;
  --mono: ui-monospace, SFMono-Regular, Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111317;
    --panel: #1a1d23;
    --text: #e6e8eb;
    --muted: #8b93a1;
    --border: #2c313a;
    --accent: #6b9bff;
    --accent-soft: #1f2a44;
    --check-a: #23272e;
    --check-b: #2c3139;
    --bad: #fb923c;
  }
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.4 system-ui, -apple-system, "Segoe UI", sans-serif;
}
button, input { font: inherit; color: inherit; }
button {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 4px 10px;
  cursor: pointer;
}
button:hover { border-color: var(--accent); }
input[type="search"] {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 5px 10px;
  min-width: 0;
  width: 220px;
}

.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: baseline; gap: 16px; flex-wrap: wrap;
  padding: 12px 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}
.topbar h1 { margin: 0; font-size: 16px; }
.stats { font-family: var(--mono); font-size: 12px; color: var(--muted); }

main { max-width: 1400px; margin: 0 auto; padding: 16px; display: grid; gap: 16px; }
.panel { background: var(--panel); border: 1px solid var(--border); border-radius: 10px; padding: 14px; min-width: 0; }
.panel-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.panel-head h2 { margin: 0; font-size: 14px; }
.count, .hint { font-weight: 400; color: var(--muted); font-size: 12px; }
.hint { flex: 1; }
.controls { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-left: auto; }
.check { display: flex; gap: 6px; align-items: center; color: var(--muted); font-size: 12px; }

.tabs { display: flex; gap: 4px; flex-wrap: wrap; }
.tabs button { font-size: 12px; }
.tabs button[aria-selected="true"] { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }

/* Mode toggle */
.mode-toggle { display: flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.mode-toggle button { border: 0; border-radius: 0; font-size: 13px; padding: 5px 12px; }
.mode-toggle button + button { border-left: 1px solid var(--border); }
.mode-toggle button[aria-selected="true"] { background: var(--accent-soft); color: var(--accent); }

body:not([data-mode="viewer"]) .viewer-only,
body:not([data-mode="app"]) .app-only { display: none; }
body[data-mode="app"] { overflow-x: hidden; }

/* Game canvas placeholder */
.canvas-wrap { background: #000; border-radius: 6px; overflow: hidden; }
#game-canvas { display: block; width: 100%; height: auto; aspect-ratio: 16 / 9; }

/* Checkerboard to reveal transparency */
.checker {
  background-color: var(--check-b);
  background-image:
    linear-gradient(45deg, var(--check-a) 25%, transparent 25%, transparent 75%, var(--check-a) 75%),
    linear-gradient(45deg, var(--check-a) 25%, transparent 25%, transparent 75%, var(--check-a) 75%);
  background-size: 16px 16px;
  background-position: 0 0, 8px 8px;
}

/* Image grid */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 8px; }
.tile { margin: 0; cursor: pointer; border: 1px solid var(--border); border-radius: 6px; overflow: hidden; min-width: 0; }
.tile:hover { border-color: var(--accent); }
.thumb { aspect-ratio: 1; display: grid; place-items: center; }
.thumb img { max-width: 100%; max-height: 100%; object-fit: contain; image-rendering: auto; }
.tile figcaption {
  font-family: var(--mono); font-size: 11px; padding: 4px 6px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  border-top: 1px solid var(--border);
}
.tile figcaption[data-dim]::after { content: " " attr(data-dim); color: var(--muted); }
.tile.broken { border-color: var(--bad); }
.tile.broken .thumb::after { content: "decode error"; color: var(--bad); font-size: 11px; }
.sentinel { height: 1px; }

/* Audio list */
.audio-list { list-style: none; margin: 0; padding: 0; max-height: 480px; overflow: auto;
  display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 4px 12px; }
.audio-list li { display: flex; align-items: center; gap: 8px; padding: 4px 6px; border-radius: 6px; min-width: 0; }
.audio-list li:hover { background: var(--bg); }
.audio-list li.playing { background: var(--accent-soft); }
.audio-list li.broken .a-meta { color: var(--bad); }
.play { width: 32px; padding: 3px 0; font-size: 11px; flex: none; }
.a-name { font-family: var(--mono); font-size: 12px; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.a-meta { font-family: var(--mono); font-size: 11px; color: var(--muted); flex: none; }

/* Lightbox */
dialog#lightbox {
  border: 1px solid var(--border); border-radius: 10px; padding: 0;
  background: var(--panel); color: var(--text);
  width: min(960px, calc(100vw - 32px)); max-height: calc(100vh - 32px);
}
dialog#lightbox::backdrop { background: rgb(0 0 0 / 0.6); }
.lb-body { display: grid; grid-template-columns: 1fr 280px; }
.lb-img { display: grid; place-items: center; min-height: 300px; max-height: calc(100vh - 34px); padding: 12px; }
.lb-img img { max-width: 100%; max-height: calc(100vh - 60px); object-fit: contain; }
.lb-meta { padding: 16px; display: flex; flex-direction: column; gap: 10px; border-left: 1px solid var(--border); min-width: 0; }
.lb-name { font-weight: 600; word-break: break-all; }
.lb-info { color: var(--muted); font-size: 12px; }
.lb-path { font-family: var(--mono); font-size: 11px; word-break: break-all; color: var(--muted); }
.lb-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: auto; align-items: center; }
.lb-actions a { color: var(--accent); font-size: 13px; }

@media (max-width: 700px) {
  main { padding: 16px; }
  input[type="search"] { width: 100%; }
  .controls { margin-left: 0; width: 100%; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(90px, 1fr)); }
  .lb-body { grid-template-columns: 1fr; }
  .lb-meta { border-left: 0; border-top: 1px solid var(--border); }
  .audio-list { grid-template-columns: 1fr; }
}

/* the dev bar (App | Asset Viewer) only shows inside the Asset Viewer; the viewer opens from Settings -> Developer */
body:not([data-mode="viewer"]) > header { display: none; }
