:root {
  --bg: #0b0d12;
  --panel: rgba(18, 21, 29, 0.92);
  --line: #2a3040;
  --text: #e8ebf2;
  --muted: #8d95a8;
  --accent: #19d3f3;
  --danger: #ff5d5d;
  color-scheme: dark;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

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

button {
  background: #1b2030;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 12px;
  cursor: pointer;
  touch-action: manipulation;
}

button:hover { border-color: #46506a; }
button.primary { background: var(--accent); border-color: var(--accent); color: #04222a; font-weight: 600; }
button.danger { color: var(--danger); }
button.active { border-color: var(--accent); color: var(--accent); }
button:disabled { opacity: 0.45; cursor: default; }

input[type="text"], input[type="password"], select {
  background: #11141d;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  min-width: 0;
}

input[type="range"] { width: 100%; accent-color: var(--accent); }

/* ---------- Admin ---------- */

.page {
  max-width: 760px;
  margin: 0 auto;
  padding: 24px 16px 64px;
}

.page h1 { font-size: 22px; margin: 0 0 20px; }
.page h2 { font-size: 16px; margin: 28px 0 10px; color: var(--muted); font-weight: 600; }

.card {
  background: #12151d;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px;
}

.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row > .grow { flex: 1 1 180px; }
.stack { display: flex; flex-direction: column; gap: 10px; }
.muted { color: var(--muted); }
.error { color: var(--danger); }
.small { font-size: 13px; }

.project { display: flex; flex-direction: column; gap: 8px; }
.project + .project { margin-top: 10px; }
.project .title { font-weight: 600; }

progress { width: 100%; accent-color: var(--accent); }

.profiles { display: flex; flex-direction: column; gap: 10px; }
.profile { border-top: 1px solid var(--line); padding-top: 10px; }
.profile:first-child { border-top: 0; padding-top: 0; }
.profile .title { font-weight: 600; margin-bottom: 6px; }
.profile .fields { display: flex; flex-wrap: wrap; gap: 8px 14px; align-items: center; }
.profile label { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); }
.profile input[type="number"] {
  width: 84px;
  background: #11141d;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px 8px;
}
.profile select { padding: 6px 8px; }
.badge {
  font-size: 11px;
  font-weight: 600;
  color: #04222a;
  background: var(--accent);
  border-radius: 999px;
  padding: 1px 8px;
  margin-left: 6px;
}

/* ---------- Viewer ---------- */

body.viewer { overflow: hidden; overscroll-behavior: none; }

#stage {
  position: fixed;
  inset: 0;
  display: flex;
}

#view {
  position: relative;
  flex: 1 1 auto;
  min-width: 0;
  min-height: 0;
}

#canvas {
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  outline: none;
}

#loading {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 24px;
  background: var(--bg);
  text-align: center;
}

#loading progress { max-width: 280px; }

#topbar {
  position: absolute;
  top: max(10px, env(safe-area-inset-top));
  left: 10px;
  right: 10px;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 8px;
  pointer-events: none;
}

#topbar > * { pointer-events: auto; }

#title {
  background: var(--panel);
  border-radius: 8px;
  padding: 6px 10px;
  font-weight: 600;
  max-width: 55%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#tools { display: flex; gap: 6px; }
#tools button { background: var(--panel); }

#looks {
  position: absolute;
  left: 0;
  right: 0;
  bottom: max(12px, env(safe-area-inset-bottom));
  display: flex;
  gap: 8px;
  padding: 0 12px;
  overflow-x: auto;
  scrollbar-width: none;
  justify-content: safe center;
}

#looks button {
  background: var(--panel);
  white-space: nowrap;
  flex: 0 0 auto;
  padding: 10px 16px;
}

#stick {
  position: absolute;
  width: 110px;
  height: 110px;
  margin: -55px 0 0 -55px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.25);
  pointer-events: none;
  display: none;
}

/* On touch screens the stick stays visible at its resting place. */
#stick.resting {
  display: block;
  left: 84px;
  bottom: calc(96px + env(safe-area-inset-bottom));
  margin: 0 0 -55px -55px;
  opacity: 0.6;
}

#stick i {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 46px;
  height: 46px;
  margin: -23px 0 0 -23px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.35);
}

#hint {
  position: absolute;
  left: 50%;
  top: 38%;
  transform: translateX(-50%);
  background: var(--panel);
  border-radius: 10px;
  padding: 10px 14px;
  text-align: center;
  pointer-events: none;
  transition: opacity 0.6s;
  max-width: 86%;
}

#notice {
  position: absolute;
  left: 50%;
  top: 64px;
  transform: translateX(-50%);
  background: var(--accent);
  color: #04222a;
  font-weight: 600;
  border-radius: 8px;
  padding: 6px 12px;
  display: none;
}

/* ---------- Editor ---------- */

#editor {
  flex: 0 0 340px;
  background: #0f1219;
  border-left: 1px solid var(--line);
  overflow-y: auto;
  padding: 12px;
  display: none;
}

body.editing #editor { display: block; }

#editor h3 {
  margin: 16px 0 8px;
  font-size: 12px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}

#editor h3:first-child { margin-top: 0; }
#editor label { display: grid; grid-template-columns: 84px 1fr 44px; align-items: center; gap: 8px; margin: 6px 0; }
#editor label output { text-align: right; color: var(--muted); font-variant-numeric: tabular-nums; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chips button { padding: 5px 9px; font-size: 13px; border-radius: 999px; }

.swatches { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.swatches button { width: 32px; height: 32px; padding: 0; border-radius: 50%; }
.swatches input[type="color"] { width: 40px; height: 32px; padding: 0; border: 1px solid var(--line); border-radius: 8px; background: none; }

@media (max-width: 760px), (orientation: portrait) {
  #stage { flex-direction: column; }
  #editor { flex: 0 0 46%; border-left: 0; border-top: 1px solid var(--line); }
}
