:root {
  --panel: rgba(22, 24, 28, 0.78);
  --panel-border: rgba(255, 255, 255, 0.08);
  --text: #e8eaed;
  --text-dim: #9aa0a8;
  --hover: rgba(255, 255, 255, 0.08);
  --accent: #4f8cff;
  --accent-soft: rgba(79, 140, 255, 0.18);
  --radius: 10px;
  --font: Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Ubuntu, sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  font: 13px/1.4 var(--font);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  user-select: none;
}

/* The canvas is transparent; the background is a cheap CSS gradient. */
body[data-bg="dark"]  { background: radial-gradient(ellipse at 50% 40%, #2b2f36 0%, #15171b 75%); }
body[data-bg="gray"]  { background: radial-gradient(ellipse at 50% 40%, #767c86 0%, #474b52 80%); }
body[data-bg="light"] { background: radial-gradient(ellipse at 50% 40%, #fbfbfc 0%, #d9dce1 85%); }

#viewport {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  outline: none;
  touch-action: none;
}

[hidden] { display: none !important; }

.panel {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  backdrop-filter: blur(14px) saturate(1.2);
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.25);
}

/* ---------- Info header ---------- */
#info {
  position: fixed;
  top: 12px;
  left: 12px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 14px 8px 10px;
  max-width: calc(100vw - 24px);
}
#info .mark { width: 26px; height: 26px; flex: none; }
.info-text { min-width: 0; }
#title {
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
#meta {
  color: var(--text-dim);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ---------- Models panel ---------- */
#models {
  position: fixed;
  top: 76px;
  left: 12px;
  width: min(320px, calc(100vw - 24px));
  max-height: calc(100vh - 160px);
  display: flex;
  flex-direction: column;
  padding: 6px;
}
#models header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 2px 4px 6px 8px;
  color: var(--text-dim);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.02em;
}
#models-swap {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 26px;
  padding: 0 9px 0 7px;
  border: 1px solid var(--panel-border);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
  font: inherit;
  font-weight: 500;
  cursor: pointer;
}
#models-swap:hover { background: var(--hover); }
#models svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
#model-list { list-style: none; margin: 0; padding: 0; overflow-y: auto; }
#model-list li {
  display: flex;
  align-items: center;
  gap: 2px;
  border-radius: 7px;
}
#model-list li:hover { background: rgba(255, 255, 255, 0.04); }
#model-list li.visible { background: var(--accent-soft); }
#model-list button {
  border: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  cursor: pointer;
}
#model-list .eye, #model-list .remove {
  flex: none;
  width: 30px;
  height: 32px;
  display: grid;
  place-items: center;
  border-radius: 6px;
  color: var(--text-dim);
}
#model-list li.visible .eye { color: #b9d0ff; }
#model-list .eye:hover, #model-list .remove:hover { background: var(--hover); color: var(--text); }
#model-list .remove { font-size: 17px; opacity: 0; }
#model-list li:hover .remove, #model-list .remove:focus-visible { opacity: 1; }
#model-list .name {
  flex: 1;
  min-width: 0;
  height: 32px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 4px;
  text-align: left;
  color: var(--text-dim);
}
#model-list li.visible .name { color: var(--text); }
#model-list .label { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#model-list .stat { flex: none; font-size: 11px; color: var(--text-dim); font-variant-numeric: tabular-nums; }
#model-list kbd { flex: none; }
#models footer {
  padding: 8px 8px 2px;
  color: var(--text-dim);
  font-size: 11px;
  line-height: 1.9;
}
#models footer kbd { min-width: 16px; padding: 0 4px; font-size: 10px; }

/* Briefly names the model that is now shown when switching. */
#flash {
  position: fixed;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  max-width: min(520px, calc(100vw - 32px));
  padding: 7px 14px;
  border-radius: 8px;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  backdrop-filter: blur(14px);
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  pointer-events: none;
}
#flash.show { animation: flash 1.4s ease forwards; }
@keyframes flash { 0%, 65% { opacity: 1; } 100% { opacity: 0; } }

/* ---------- Toolbar ---------- */
#toolbar {
  position: fixed;
  left: 50%;
  bottom: 16px;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 4px;
}
#toolbar button, .point-size {
  height: 34px;
  min-width: 34px;
  padding: 0 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--text);
  font: inherit;
  cursor: pointer;
}
#toolbar button:hover { background: var(--hover); }
#toolbar button:disabled { opacity: 0.35; cursor: default; background: transparent; }
#toolbar button[aria-pressed="true"] { background: var(--accent-soft); color: #b9d0ff; }
#toolbar button:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
#toolbar svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}
#toolbar svg .fill { fill: currentColor; }
#toolbar svg .back { stroke-dasharray: 2 2.2; opacity: 0.7; }
#toolbar button[aria-pressed="true"] svg .back { opacity: 0; }
#toolbar .label { font-size: 12px; }
.sep { width: 1px; height: 20px; margin: 0 4px; background: var(--panel-border); }

.point-size { cursor: default; padding: 0 10px; }
.point-size svg { stroke: none !important; fill: currentColor !important; }
.point-size input { width: 96px; accent-color: var(--accent); }
.point-size output { min-width: 26px; font-size: 12px; color: var(--text-dim); font-variant-numeric: tabular-nums; }

/* ---------- Empty state ---------- */
#empty {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 16px;
  pointer-events: none;
}
.empty-card {
  max-width: 420px;
  text-align: center;
  padding: 32px 32px 24px;
  border: 1.5px dashed rgba(255, 255, 255, 0.14);
  border-radius: 16px;
  pointer-events: auto;
}
.empty-icon { width: 56px; height: 56px; color: var(--text-dim); }
.empty-card h1 { margin: 12px 0 6px; font-size: 18px; font-weight: 600; }
.empty-card p { margin: 0 0 18px; color: var(--text-dim); }
.empty-card b { color: var(--text); font-weight: 500; }
.empty-card .hint { margin: 12px 0 0; font-size: 12px; }
body[data-bg="light"] .empty-card { border-color: rgba(0, 0, 0, 0.18); color: #202328; }
body[data-bg="light"] .empty-card p, body[data-bg="light"] .empty-icon { color: #5d636c; }
body[data-bg="light"] .empty-card b { color: #202328; }

button.primary {
  height: 36px;
  padding: 0 18px;
  border: 0;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font: inherit;
  font-weight: 500;
  cursor: pointer;
}
button.primary:hover { filter: brightness(1.08); }

kbd {
  display: inline-block;
  min-width: 20px;
  padding: 1px 5px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-bottom-width: 2px;
  border-radius: 4px;
  font: 11px/1.4 var(--font);
  text-align: center;
  color: var(--text);
  background: rgba(255, 255, 255, 0.04);
}
body[data-bg="light"] .empty-card kbd { color: #202328; border-color: rgba(0, 0, 0, 0.2); }

/* ---------- Loading ---------- */
#progress {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 2px;
  overflow: hidden;
}
#progress div {
  width: 30%;
  height: 100%;
  background: var(--accent);
  animation: slide 1.1s ease-in-out infinite;
}
@keyframes slide { from { transform: translateX(-100%); } to { transform: translateX(340%); } }

#loading {
  position: fixed;
  inset: 0;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 12px;
  pointer-events: none;
  color: var(--text-dim);
}
body[data-bg="light"] #loading { color: #5d636c; }
.spinner {
  width: 28px;
  height: 28px;
  border: 2.5px solid rgba(128, 128, 128, 0.25);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Help ---------- */
#help {
  position: fixed;
  right: 12px;
  bottom: 64px;
  width: 320px;
  padding: 14px 16px;
}
#help h2 { margin: 0 0 10px; font-size: 13px; font-weight: 600; }
#help dl { display: grid; grid-template-columns: auto 1fr; gap: 7px 16px; margin: 0; }
#help dt { color: var(--text-dim); }
#help dd { margin: 0; text-align: right; }

/* ---------- Drop overlay / toast ---------- */
#drop-overlay {
  position: fixed;
  inset: 10px;
  display: grid;
  place-items: center;
  border: 2px dashed var(--accent);
  border-radius: 16px;
  background: rgba(79, 140, 255, 0.08);
  pointer-events: none;
}
#drop-overlay div {
  padding: 10px 18px;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-weight: 500;
}

#toast {
  position: fixed;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  max-width: min(560px, calc(100vw - 32px));
  padding: 10px 14px;
  border-radius: 8px;
  background: #3a1d20;
  border: 1px solid #7a2e35;
  color: #ffd9dc;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.3);
  white-space: pre-line;
}

@media (max-width: 560px) {
  #models footer { display: none; }
  #toolbar { bottom: 12px; }
  #toolbar .label, .point-size output { display: none; }
  #toolbar button { min-width: 32px; padding: 0 6px; }
  .point-size { padding: 0 6px; }
  .point-size input { width: 56px; }
  .sep { margin: 0 2px; }
  #help { left: 12px; right: 12px; width: auto; }
}
