:root {
  /* Dewdimpple palette */
  --bg: #0c0c0e;
  --panel: #141417;
  --panel-alt: #1b1b1f;
  --border: #26262b;
  --text: #f2f1ec;
  --text-dim: #9b9aa3;
  --accent: #7bd35a;
  --accent-dim: #4f9a34;
  --accent-ink: #0c1a07;
  --accent-soft: rgba(123, 211, 90, 0.14);
  --danger: #e5555f;
  --faint: #66656e;
  --dirt: #8a5a34;

  --font: 'Space Grotesk', system-ui, -apple-system, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  --mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, 'Courier New', monospace;
  --pixel: 'Pixelify Sans', var(--mono);

  --radius-btn: 10px;
  --radius-input: 10px;
  --radius-panel: 12px;

  font-family: var(--font);
  accent-color: var(--accent);
}

* { box-sizing: border-box; }

::selection { background: var(--accent); color: var(--accent-ink); }

button:focus-visible, input:focus-visible, select:focus-visible, a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}

input[type="checkbox"] { accent-color: var(--accent); }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
}

body {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

button, input, select {
  font: inherit;
  color: inherit;
}

.hidden { display: none !important; }

/* ---------- topbar ---------- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 16px;
  background: color-mix(in srgb, var(--bg) 78%, transparent);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border);
  flex: 0 0 auto;
}

.brand { display: flex; align-items: baseline; gap: 10px; min-width: 0; }
.brand-title {
  font-family: var(--pixel);
  font-weight: 600;
  font-size: 15px;
  letter-spacing: .02em;
  white-space: nowrap;
}
.brand-title::before {
  content: '';
  display: inline-block;
  width: 16px;
  height: 16px;
  margin-right: 7px;
  vertical-align: -2px;
  border-radius: 4px;
  background: linear-gradient(var(--accent) 0 38%, var(--dirt) 38% 100%);
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.25);
}
.pack-name {
  font-family: var(--mono);
  font-size: 12px;
  letter-spacing: .02em;
  color: var(--text-dim);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.topbar-actions { display: flex; align-items: center; gap: 10px; flex: 0 0 auto; }

.export-group { display: flex; gap: 6px; }
.export-name {
  width: 140px;
  background: var(--panel-alt);
  border: 1px solid var(--border);
  border-radius: var(--radius-input);
  padding: 6px 8px;
}

.btn {
  background: var(--panel-alt);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius-btn);
  padding: 7px 12px;
  cursor: pointer;
  white-space: nowrap;
  font-weight: 500;
  transition: background-color .2s, border-color .2s, color .2s, box-shadow .2s;
}
.btn:hover { border-color: var(--faint); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn:disabled:hover { border-color: var(--border); }

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
  box-shadow: 0 8px 24px -12px var(--accent);
}
.btn-primary:hover {
  background: var(--accent-dim);
  border-color: var(--accent-dim);
  color: var(--accent-ink);
  box-shadow: 0 10px 28px -10px var(--accent-dim);
}
.btn-primary:disabled:hover { background: var(--accent); border-color: var(--accent); }
.btn-ghost { background: transparent; }
.btn-ghost:hover { background: var(--panel-alt); }
.btn-small { padding: 4px 8px; font-size: 12px; }
.home-link { text-decoration: none; align-self: center; white-space: nowrap; }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }

/* ---------- layout ---------- */

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

.sidebar {
  width: 300px;
  flex: 0 0 auto;
  background: var(--panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.tabs { display: flex; border-bottom: 1px solid var(--border); flex: 0 0 auto; }
.tab {
  flex: 1;
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--text-dim);
  padding: 10px 8px;
  cursor: pointer;
  font-size: 13px;
}
.tab.active { color: var(--text); border-bottom-color: var(--accent); font-weight: 500; }
.count {
  font-family: var(--mono);
  font-size: 10.5px;
  letter-spacing: .04em;
  color: var(--text-dim);
}

.tab-panel { flex: 1 1 auto; display: flex; flex-direction: column; min-height: 0; }

.panel-toolbar { display: flex; gap: 6px; padding: 8px; flex: 0 0 auto; }
.search {
  flex: 1;
  background: var(--panel-alt);
  border: 1px solid var(--border);
  border-radius: var(--radius-input);
  padding: 6px 8px;
}

.file-list { flex: 1 1 auto; overflow-y: auto; padding: 4px 8px 8px; }

.group-header {
  font-family: var(--mono);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-dim);
  padding: 10px 4px 4px;
}

.file-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 6px;
  border-radius: 8px;
  cursor: pointer;
}
.file-row:hover { background: var(--panel-alt); }
.file-row.selected { background: var(--accent-soft); outline: 1px solid var(--accent-dim); }
.file-row.error .file-name { color: var(--danger); }

.file-thumb {
  width: 28px; height: 28px;
  object-fit: contain;
  background:
    linear-gradient(45deg, rgba(255,255,255,0.08) 25%, transparent 25%, transparent 75%, rgba(255,255,255,0.08) 75%),
    linear-gradient(45deg, rgba(255,255,255,0.08) 25%, transparent 25%, transparent 75%, rgba(255,255,255,0.08) 75%);
  background-size: 8px 8px;
  background-position: 0 0, 4px 4px;
  border-radius: 6px;
  flex: 0 0 auto;
  image-rendering: pixelated;
}

.file-info { min-width: 0; flex: 1 1 auto; }
.file-name { font-size: 12.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-path {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: .01em;
  color: var(--text-dim);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.file-actions { display: flex; gap: 3px; opacity: 0; flex: 0 0 auto; }
.file-row:hover .file-actions { opacity: 1; }
.row-btn {
  background: var(--panel-alt);
  border: 1px solid var(--border);
  color: var(--text-dim);
  border-radius: 6px;
  font-size: 10.5px;
  padding: 3px 6px;
  cursor: pointer;
}
.row-btn:hover { color: var(--text); border-color: var(--accent); }
.row-remove:hover { color: var(--danger); border-color: var(--danger); }

.texture-grid .file-row { flex-wrap: wrap; }

/* ---------- entities tab ---------- */

#panel-entities { min-height: 0; }
#entityListView, #entityDetailView { display: flex; flex-direction: column; min-height: 0; flex: 1 1 auto; }

.issue-badge {
  display: inline-block;
  margin-left: 6px;
  padding: 1px 6px;
  border-radius: 999px;
  font-family: var(--mono);
  font-size: 10px;
  font-weight: 600;
  vertical-align: middle;
}
.issue-badge.has-errors { background: rgba(229, 85, 95, 0.18); color: #ff9aa2; }
.issue-badge.has-warnings-only { background: rgba(230, 180, 60, 0.18); color: #f0c766; }

.entity-row-badges { display: flex; gap: 4px; flex: 0 0 auto; align-items: center; }
.entity-dot { width: 7px; height: 7px; border-radius: 50%; flex: 0 0 auto; }
.entity-dot.err { background: var(--danger); }
.entity-dot.warn { background: #e6b43c; }
.entity-dot.ok { background: var(--accent); }

.entity-detail-header { padding: 8px; flex: 0 0 auto; }

.entity-detail-title { padding: 0 12px 8px; flex: 0 0 auto; }
.entity-detail-identifier { font-size: 14px; font-weight: 600; word-break: break-word; }
.entity-detail-path { font-size: 11px; color: var(--text-dim); word-break: break-all; margin-top: 2px; }

.entity-issues {
  flex: 0 0 auto;
  max-height: 220px;
  overflow-y: auto;
  padding: 0 12px 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.entity-issue {
  font-size: 11.5px;
  line-height: 1.4;
  padding: 6px 8px;
  border-radius: 8px;
  border-left: 3px solid transparent;
}
.entity-issue.err { background: rgba(229, 85, 95, 0.1); border-left-color: var(--danger); color: #ffd7da; }
.entity-issue.warn { background: rgba(230, 180, 60, 0.1); border-left-color: #e6b43c; color: #f5dfa6; }
.entity-issues-empty { font-size: 11.5px; color: var(--text-dim); padding: 0 12px 8px; }

.entity-section-header {
  font-family: var(--mono);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-dim);
  padding: 8px 12px 4px;
  flex: 0 0 auto;
  border-top: 1px solid var(--border);
}

.entity-sublist { flex: 1 1 auto; max-height: 220px; }
.entity-sublist:last-child { flex: 1 1 auto; }
.entity-sublist-empty { font-size: 11.5px; color: var(--text-dim); padding: 6px 12px; }

.sidebar-hint {
  font-family: var(--mono);
  font-size: 11px;
  line-height: 1.5;
  color: var(--text-dim);
  padding: 8px 12px;
  border-top: 1px solid var(--border);
  margin: 0;
  flex: 0 0 auto;
}

/* ---------- viewport ---------- */

.viewport {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.viewer-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
  padding: 8px 14px;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
  flex: 0 0 auto;
}

.selection-summary { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.selection-label { font-size: 12px; color: var(--text-dim); }

.select {
  background: var(--panel-alt);
  border: 1px solid var(--border);
  border-radius: var(--radius-input);
  padding: 5px 6px;
  max-width: 220px;
}
.select-small { max-width: 100px; padding: 3px 4px; }

.camera-presets { display: flex; gap: 4px; flex-wrap: wrap; }

.view-toggles { display: flex; align-items: center; gap: 12px; font-size: 12px; color: var(--text-dim); margin-left: auto; }
.view-toggles label { display: flex; align-items: center; gap: 4px; cursor: pointer; }
.bg-toggle { gap: 6px !important; }

.canvas-wrap {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
}

#canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }

.viewer-empty {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--faint);
  text-align: center;
  padding: 20px;
  pointer-events: none;
}
.viewer-empty p { max-width: 42ch; font-size: 14px; }

/* ---------- drop overlay ---------- */

.drop-overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(12, 12, 14, 0.85);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
}
.drop-overlay-inner {
  border: 2px dashed var(--accent);
  border-radius: var(--radius-panel);
  padding: 40px 60px;
  font-size: 18px;
}

/* ---------- toast ---------- */

.toast {
  position: fixed;
  bottom: 18px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--panel-alt);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 16px;
  border-radius: var(--radius-panel);
  font-size: 13px;
  z-index: 100;
  box-shadow: 0 1px 0 rgba(255,255,255,0.04) inset, 0 20px 40px -24px rgba(0,0,0,0.8);
  max-width: 80vw;
}
.toast.error { border-color: var(--danger); color: #ffd7da; }

@media (max-width: 760px) {
  .sidebar { width: 240px; }
  .view-toggles { margin-left: 0; }
  .topbar { flex-wrap: wrap; gap: 8px; padding: 8px 12px; }
  .brand { min-width: 0; flex: 1 1 100%; }
  .topbar-actions { flex: 1 1 100%; overflow-x: auto; scrollbar-width: none; padding-bottom: 2px; }
  .topbar-actions > * { flex: 0 0 auto; }
}
@media (max-width: 520px) {
  .sidebar { width: 150px; }
}
