:root {
  --bg: #0a0e1a;
  --accent: #00d9ff;
  --accent-dim: #0a7a94;
  --panel-bg: rgba(16, 24, 42, 0.72);
  --border: rgba(0, 217, 255, 0.25);
  --text: #dbeafe;
  --muted: #7d93b8;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html, body {
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  font-family: 'Vazirmatn', sans-serif;
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
}

#scene-container {
  position: fixed;
  inset: 0;
  z-index: 1;
}
#scene-container canvas { display: block; touch-action: none; }

/* ---------------- Header ---------------- */
#topbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 10;
  padding: 14px 22px;
  pointer-events: none;
  background: linear-gradient(180deg, rgba(10,14,26,0.85), transparent);
}
.title-wrap h1 {
  font-weight: 900;
  font-size: clamp(1.05rem, 3.5vw, 1.7rem);
  letter-spacing: -0.5px;
  background: linear-gradient(90deg, #fff, var(--accent));
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  text-shadow: 0 0 30px rgba(0,217,255,0.25);
}
.title-wrap .subtitle {
  font-weight: 300;
  font-size: 0.78rem;
  color: var(--muted);
  margin-top: 2px;
}

/* ---------------- Control panel ---------------- */
#panel {
  position: fixed;
  top: 78px;
  right: 16px;
  z-index: 20;
  width: 230px;
  padding: 16px;
  border-radius: 18px;
  background: var(--panel-bg);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--border);
  box-shadow: 0 10px 40px rgba(0,0,0,0.5), inset 0 0 30px rgba(0,217,255,0.05);
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.panel-heading {
  font-weight: 700;
  font-size: 0.8rem;
  color: var(--accent);
  margin-bottom: 10px;
  letter-spacing: 0.5px;
}
.layer-btns {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.layer-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 10px 6px;
  border-radius: 12px;
  border: 1px solid rgba(255,255,255,0.08);
  background: rgba(255,255,255,0.03);
  color: var(--muted);
  font-family: inherit;
  font-size: 0.72rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.22s ease;
}
.layer-btn .ic { font-size: 1.3rem; filter: grayscale(0.6) opacity(0.6); transition: filter 0.22s; }
.layer-btn.active {
  color: var(--text);
  border-color: var(--accent);
  background: rgba(0,217,255,0.12);
  box-shadow: 0 0 18px rgba(0,217,255,0.28);
}
.layer-btn.active .ic { filter: none; }
.layer-btn:active { transform: scale(0.94); }

.slider-label {
  display: flex;
  justify-content: space-between;
  font-size: 0.75rem;
  color: var(--muted);
  margin-bottom: 8px;
}
.slider-label span { color: var(--accent); font-weight: 700; }
input[type="range"] {
  width: 100%;
  -webkit-appearance: none;
  appearance: none;
  height: 5px;
  border-radius: 5px;
  background: linear-gradient(90deg, var(--accent-dim), var(--accent));
  outline: none;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 18px; height: 18px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 0 12px var(--accent);
  cursor: pointer;
}
input[type="range"]::-moz-range-thumb {
  width: 18px; height: 18px; border: none;
  border-radius: 50%; background: #fff;
  box-shadow: 0 0 12px var(--accent); cursor: pointer;
}

.toggles { display: flex; flex-direction: column; gap: 10px; }
.switch-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.8rem;
  color: var(--text);
  cursor: pointer;
}
.switch-row input {
  appearance: none;
  -webkit-appearance: none;
  width: 40px; height: 22px;
  border-radius: 22px;
  background: rgba(255,255,255,0.12);
  position: relative;
  cursor: pointer;
  transition: background 0.22s;
}
.switch-row input::after {
  content: '';
  position: absolute;
  top: 2px; right: 2px;
  width: 18px; height: 18px;
  border-radius: 50%;
  background: #fff;
  transition: transform 0.22s;
}
.switch-row input:checked { background: var(--accent); box-shadow: 0 0 12px rgba(0,217,255,0.4); }
.switch-row input:checked::after { transform: translateX(-18px); }

.actions { display: flex; flex-direction: column; gap: 8px; }
.action-btn {
  padding: 10px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: rgba(0,217,255,0.08);
  color: var(--text);
  font-family: inherit;
  font-weight: 500;
  font-size: 0.82rem;
  cursor: pointer;
  transition: all 0.2s;
}
.action-btn:hover { background: rgba(0,217,255,0.18); }
.action-btn:active { transform: scale(0.96); }
.action-btn.peel {
  background: linear-gradient(90deg, #b43227, #d6252b);
  border-color: transparent;
  font-weight: 700;
}
.action-btn.peel:hover { filter: brightness(1.12); }
.action-btn.ghost { background: transparent; color: var(--muted); }

.panel-footer {
  border-top: 1px solid rgba(255,255,255,0.08);
  padding-top: 10px;
  text-align: center;
}
.panel-footer a {
  color: var(--muted);
  text-decoration: none;
  font-size: 0.75rem;
  transition: color 0.2s;
}
.panel-footer a:hover { color: var(--accent); }

/* ---------------- Mobile panel toggle ---------------- */
#panel-toggle {
  display: none;
  position: fixed;
  bottom: 18px; right: 18px;
  z-index: 30;
  width: 54px; height: 54px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--panel-bg);
  backdrop-filter: blur(14px);
  color: var(--accent);
  font-size: 1.5rem;
  cursor: pointer;
  box-shadow: 0 6px 24px rgba(0,0,0,0.5), 0 0 20px rgba(0,217,255,0.3);
}

/* ---------------- 3D Labels ---------------- */
#labels { position: fixed; inset: 0; z-index: 8; pointer-events: none; }
.label-3d {
  position: absolute;
  transform: translate(50%, -50%);
  display: flex;
  align-items: center;
  gap: 5px;
  white-space: nowrap;
  font-size: 0.72rem;
  font-weight: 500;
  color: #eaf6ff;
  padding: 2px 8px 2px 4px;
  border-radius: 20px;
  background: rgba(10,20,38,0.55);
  border: 1px solid rgba(0,217,255,0.3);
  backdrop-filter: blur(4px);
  text-shadow: 0 0 8px rgba(0,0,0,0.8);
}
.label-3d .dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 8px var(--accent);
}

/* ---------------- Info card ---------------- */
#info-card {
  position: fixed;
  z-index: 40;
  bottom: 24px; left: 24px;
  max-width: 300px;
  padding: 18px 20px;
  border-radius: 16px;
  background: var(--panel-bg);
  backdrop-filter: blur(16px);
  border: 1px solid var(--border);
  box-shadow: 0 10px 40px rgba(0,0,0,0.5), 0 0 24px rgba(0,217,255,0.18);
  animation: popin 0.3s cubic-bezier(0.2,1.2,0.4,1);
}
#info-card.hidden { display: none; }
#info-card h3 {
  font-weight: 900;
  font-size: 1.15rem;
  color: var(--accent);
  margin-bottom: 6px;
}
#info-card p { font-weight: 300; line-height: 1.6; font-size: 0.9rem; }
#info-close {
  position: absolute;
  top: 10px; left: 12px;
  background: none; border: none;
  color: var(--muted);
  font-size: 1rem; cursor: pointer;
}
@keyframes popin {
  from { opacity: 0; transform: translateY(16px) scale(0.94); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

/* ---------------- Loading ---------------- */
#loading {
  position: fixed; inset: 0; z-index: 100;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 18px;
  background: radial-gradient(circle at 50% 40%, #12203a, var(--bg));
  transition: opacity 0.6s ease;
}
#loading.hide { opacity: 0; pointer-events: none; }
.loader-glyph { font-size: 3.5rem; animation: spin 2.4s linear infinite, pulse 1.2s ease-in-out infinite; }
.loader-text { font-weight: 300; color: var(--muted); font-size: 1rem; }
.loader-bar {
  width: 180px; height: 5px;
  border-radius: 5px;
  background: rgba(255,255,255,0.1);
  overflow: hidden;
}
.loader-fill {
  height: 100%; width: 40%;
  border-radius: 5px;
  background: linear-gradient(90deg, var(--accent-dim), var(--accent));
  animation: loadmove 1.1s ease-in-out infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes pulse { 50% { transform: scale(1.12); } }
@keyframes loadmove {
  0% { transform: translateX(-160%); }
  100% { transform: translateX(320%); }
}

/* ---------------- Mobile ---------------- */
@media (max-width: 720px) {
  #panel-toggle { display: block; }
  #panel {
    top: auto;
    bottom: 0; right: 0; left: 0;
    width: 100%;
    border-radius: 22px 22px 0 0;
    transform: translateY(110%);
    transition: transform 0.35s cubic-bezier(0.2,0.9,0.3,1);
    max-height: 78vh;
    overflow-y: auto;
  }
  #panel.open { transform: translateY(0); }
  .layer-btns { grid-template-columns: repeat(4, 1fr); }
  #info-card { left: 12px; right: 12px; bottom: 84px; max-width: none; }
}