:root {
  color-scheme: dark;
  --bg: #0b0e14;
  --panel: #141922;
  --panel-soft: #1b2230;
  --border: #263042;
  --text: #cbd3e1;
  --text-bright: #f2f5fa;
  --text-muted: #7c8aa3;
  --text-dim: #4d5a70;
  --accent: #4895ef;
  --accent-bright: #74b3ff;
  --accent-dim: rgba(72, 149, 239, 0.16);
  --warm: #f5b942;
  --font-ui: 'Plus Jakarta Sans', 'Segoe UI', system-ui, sans-serif;
  --font-mono: 'JetBrains Mono', 'Roboto Mono', monospace;
  --radius-lg: 18px;
  --radius-md: 12px;
  --radius-sm: 8px;
  --shadow: 0 24px 60px -28px rgba(0, 0, 0, 0.75), 0 0 0 1px var(--border);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  overflow: hidden;
}

button { font-family: inherit; }

/* ---------- Topbar ---------- */

.topbar {
  position: relative;
  z-index: 20;
  background: rgba(11, 14, 20, 0.85);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}

.topbar-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 14px 20px;
  display: flex;
  align-items: baseline;
  gap: 12px;
  flex-wrap: wrap;
}

.brand {
  display: flex;
  align-items: center;
  gap: 9px;
  font-weight: 800;
  font-size: 1.1rem;
  color: var(--text-bright);
  text-decoration: none;
}

.brand-emoji { font-size: 1.3rem; }
.brand-text { font-family: var(--font-mono); }

.brand-sub {
  font-size: 0.82rem;
  color: var(--text-muted);
  font-weight: 600;
}

.back-link {
  margin-left: auto;
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--text-muted);
  text-decoration: none;
}
.back-link:hover { color: var(--accent-bright); }

/* ---------- Stage ---------- */

.stage {
  position: relative;
  height: calc(100vh - 57px);
  height: calc(100dvh - 57px);
  overflow: hidden;
}

#canvas-wrap { position: absolute; inset: 0; }
#canvas-wrap canvas { display: block; width: 100%; height: 100%; touch-action: none; }

.loading {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  background: var(--bg);
  color: var(--text-muted);
  font-weight: 600;
  font-size: 0.9rem;
  z-index: 15;
  transition: opacity 0.4s ease;
}
.loading.hidden { opacity: 0; pointer-events: none; }

.loading-spinner {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Rotate hint ---------- */

/* ---------- Переключатель моделей ---------- */

.model-switcher {
  position: absolute;
  top: 20px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 6px;
  background: rgba(20, 25, 34, 0.85);
  backdrop-filter: blur(8px);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 5px;
  z-index: 13;
}

.model-tab {
  display: flex;
  align-items: center;
  gap: 7px;
  border: none;
  background: none;
  color: var(--text-muted);
  font-weight: 700;
  font-size: 0.85rem;
  padding: 8px 16px;
  border-radius: 999px;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s ease, color 0.15s ease;
}
.model-tab:hover { color: var(--text); }
.model-tab.active { background: var(--accent-dim); color: var(--accent-bright); }
.model-tab .emoji { font-size: 1rem; }

@media (max-width: 640px) {
  .model-tab span:not(.emoji) { display: none; }
  .model-tab { padding: 8px 12px; }
}

.hint {
  position: absolute;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(20, 25, 34, 0.85);
  backdrop-filter: blur(8px);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 9px 18px;
  font-size: 0.82rem;
  color: var(--text-muted);
  font-weight: 600;
  z-index: 12;
  transition: opacity 0.5s ease;
  pointer-events: none;
  white-space: nowrap;
}
.hint.faded { opacity: 0; }
.hint-mobile { display: none; }

@media (pointer: coarse) {
  .hint-desktop { display: none; }
  .hint-mobile { display: inline; }
}

/* ---------- Info panel ---------- */

.info-panel {
  position: absolute;
  top: 78px;
  right: 20px;
  width: 320px;
  max-width: calc(100vw - 40px);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: 20px 22px;
  z-index: 14;
  animation: panel-in 0.25s ease;
}
@keyframes panel-in {
  from { opacity: 0; transform: translateY(-8px); }
  to { opacity: 1; transform: translateY(0); }
}

.info-close {
  position: absolute;
  top: 12px;
  right: 12px;
  border: none;
  background: var(--panel-soft);
  color: var(--text-muted);
  width: 26px;
  height: 26px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 0.8rem;
}
.info-close:hover { color: var(--text); }

.info-eyebrow {
  font-size: 0.7rem;
  font-weight: 800;
  color: var(--accent-bright);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 4px;
}

.info-title {
  margin: 0 0 10px;
  font-size: 1.25rem;
  color: var(--text-bright);
  padding-right: 24px;
}

.info-desc {
  margin: 0;
  font-size: 0.92rem;
  line-height: 1.55;
  color: var(--text);
}

/* ---------- Part legend ---------- */

.part-legend {
  position: absolute;
  bottom: 20px;
  left: 20px;
  display: flex;
  flex-direction: column;
  gap: 5px;
  max-width: 210px;
  z-index: 11;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(20, 25, 34, 0.8);
  backdrop-filter: blur(8px);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 6px 13px 6px 10px;
  font-size: 0.76rem;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  transition: background 0.12s ease, color 0.12s ease, border-color 0.12s ease;
  text-align: left;
}
.legend-item:hover { background: var(--panel-soft); color: var(--text); }
.legend-item.active {
  background: var(--accent-dim);
  color: var(--accent-bright);
  border-color: var(--accent);
}
.legend-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  flex-shrink: 0;
}

@media (max-width: 720px) {
  .part-legend { display: none; }
  .info-panel {
    top: auto;
    bottom: 14px;
    left: 14px;
    right: 14px;
    width: auto;
    max-width: none;
  }
  .topbar-inner { padding: 11px 16px; }
  .brand-sub { display: none; }
}

/* ---------- Credit ---------- */

.credit-badge {
  position: absolute;
  bottom: 20px;
  right: 20px;
  max-width: 210px;
  background: rgba(20, 25, 34, 0.8);
  backdrop-filter: blur(8px);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 8px 12px;
  font-size: 0.68rem;
  font-weight: 600;
  line-height: 1.35;
  color: var(--text-dim);
  z-index: 10;
  pointer-events: none;
}

@media (max-width: 720px) {
  .credit-badge {
    right: 10px;
    bottom: 10px;
    max-width: 150px;
    font-size: 0.62rem;
    padding: 6px 9px;
  }
}
