:root {
  --bg: #0d0f15;
  --panel: rgba(18, 21, 30, 0.82);
  --panel-border: rgba(255, 255, 255, 0.08);
  --text: #e8ecf4;
  --text-dim: #8b94a7;
  --accent: #6ed3ff;
  --accent-2: #ffb454;
  --danger: #ff5c5c;
  --radius: 10px;
}

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

html,
body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Microsoft YaHei', sans-serif;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}

#pb-canvas {
  position: fixed;
  inset: 0;
  display: block;
}

/* ---------- Loading ---------- */
#pb-loading {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity 0.45s ease;
}
#pb-loading.fade {
  opacity: 0;
  pointer-events: none;
}
.loading-box {
  text-align: center;
}
.loading-logo {
  font-size: 46px;
  font-weight: 800;
  letter-spacing: 2px;
  background: linear-gradient(120deg, #6ed3ff, #ffb454);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}
.loading-sub {
  margin-top: 8px;
  color: var(--text-dim);
  font-size: 13px;
}
.loading-bar {
  margin: 26px auto 12px;
  width: 260px;
  height: 6px;
  border-radius: 3px;
  background: rgba(255, 255, 255, 0.08);
  overflow: hidden;
}
#pb-loadbar-fill {
  height: 100%;
  width: 0%;
  border-radius: 3px;
  background: linear-gradient(90deg, #6ed3ff, #ffb454);
  transition: width 0.25s ease;
}
#pb-loadbar-text {
  font-size: 12px;
  color: var(--text-dim);
}

/* ---------- Panels ---------- */
.panel {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

#pb-sidebar {
  position: fixed;
  left: 12px;
  top: 12px;
  bottom: 46px;
  width: 164px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 10;
  pointer-events: none;
}
#pb-sidebar > .panel {
  pointer-events: auto;
}

/* Toolbar */
#pb-toolbar {
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.tool-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 7px 8px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: var(--text-dim);
  cursor: pointer;
  transition: background 0.12s, color 0.12s, border-color 0.12s;
  text-align: left;
}
.tool-btn:hover {
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
}
.tool-btn.active {
  background: rgba(110, 211, 255, 0.14);
  color: var(--accent);
  border-color: rgba(110, 211, 255, 0.35);
}
.tool-btn .icon {
  display: inline-flex;
  width: 18px;
  height: 18px;
  flex: 0 0 18px;
}
.tool-btn .icon svg {
  width: 18px;
  height: 18px;
}
.tool-label {
  font-size: 13px;
}
.tool-spacer {
  height: 6px;
}
.tool-controls {
  border-top: 1px solid var(--panel-border);
  padding-top: 8px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.tool-control.polygon {
  display: none;
}
.ctl-label {
  font-size: 12px;
  color: var(--text-dim);
  display: block;
  margin-bottom: 4px;
}
.ctl-range {
  width: 100%;
  accent-color: var(--accent);
  background: transparent;
}
.ctl-value {
  font-size: 12px;
  color: var(--text-dim);
  float: right;
  margin-top: -16px;
}
.tool-buttons {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.ctl-btn {
  padding: 6px 8px;
  font-size: 12.5px;
  border: 1px solid var(--panel-border);
  border-radius: 7px;
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
  cursor: pointer;
  transition: background 0.12s;
}
.ctl-btn:hover {
  background: rgba(255, 255, 255, 0.1);
}
.ctl-btn.active {
  border-color: rgba(255, 180, 84, 0.5);
  color: var(--accent-2);
}
.ctl-btn.danger {
  color: var(--danger);
}
.ctl-btn kbd {
  font-size: 10.5px;
  color: var(--text-dim);
  margin-left: 4px;
}

/* Material bar */
#pb-material-bar {
  padding: 8px;
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}
.mat-btn {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 5px 7px;
  border: 1px solid transparent;
  border-radius: 7px;
  background: transparent;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 12px;
  transition: background 0.12s, color 0.12s, border-color 0.12s;
}
.mat-btn:hover {
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
}
.mat-btn.active {
  background: rgba(110, 211, 255, 0.14);
  color: var(--accent);
  border-color: rgba(110, 211, 255, 0.35);
}
.swatch {
  width: 11px;
  height: 11px;
  border-radius: 3px;
  flex: 0 0 11px;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.25);
}

/* Scene bar */
#pb-scene-bar {
  padding: 8px;
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}
.scene-btn {
  padding: 5px 8px;
  font-size: 12px;
  border: 1px solid transparent;
  border-radius: 7px;
  background: transparent;
  color: var(--text-dim);
  cursor: pointer;
  transition: background 0.12s, color 0.12s, border-color 0.12s;
}
.scene-btn:hover {
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
}
.scene-btn.active {
  background: rgba(255, 180, 84, 0.14);
  color: var(--accent-2);
  border-color: rgba(255, 180, 84, 0.35);
}

/* Settings button + panel */
.icon-btn {
  position: fixed;
  top: 12px;
  right: 12px;
  z-index: 30;
  width: 40px;
  height: 40px;
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  background: var(--panel);
  color: var(--text);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  transition: background 0.12s;
}
.icon-btn:hover {
  background: rgba(255, 255, 255, 0.1);
}
.icon-btn svg {
  width: 20px;
  height: 20px;
}
#pb-settings-btn svg {
  width: 22px;
  height: 22px;
}

#pb-settings {
  position: fixed;
  top: 12px;
  right: 12px;
  z-index: 20;
  width: 300px;
  max-height: calc(100vh - 90px);
  overflow-y: auto;
  padding: 14px;
  display: none;
}
#pb-settings.open {
  display: block;
}
.settings-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 15px;
  font-weight: 700;
  margin-bottom: 10px;
}
.settings-head .settings-close {
  position: static;
  width: 30px;
  height: 30px;
  font-size: 14px;
}
.setting-row {
  margin-bottom: 12px;
}
.setting-head {
  font-size: 12px;
  color: var(--text-dim);
  margin-bottom: 6px;
}
.range-wrap {
  display: flex;
  align-items: center;
  gap: 10px;
}
.range-wrap .ctl-range {
  flex: 1;
}
.range-wrap .ctl-value {
  float: none;
  margin-top: 0;
  min-width: 52px;
  text-align: right;
}
.toggle-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px 10px;
}
.toggle-row {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12.5px;
  color: var(--text);
  cursor: pointer;
}
.toggle-row input {
  accent-color: var(--accent);
}

/* Status bar */
#pb-status {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  height: 34px;
  z-index: 15;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 14px;
  background: rgba(10, 12, 18, 0.78);
  border-top: 1px solid var(--panel-border);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  font-size: 12px;
  color: var(--text-dim);
}
.status-left {
  display: flex;
  align-items: center;
  gap: 14px;
}
.status-scene {
  color: var(--text);
  font-weight: 600;
}
.status-stats {
  font-variant-numeric: tabular-nums;
}
.status-hints {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 60vw;
}

/* Toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: 56px;
  transform: translateX(-50%) translateY(12px);
  z-index: 100;
  padding: 9px 18px;
  border-radius: 8px;
  background: rgba(18, 21, 30, 0.92);
  border: 1px solid var(--panel-border);
  color: var(--text);
  font-size: 13px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s, transform 0.25s;
  max-width: 80vw;
  text-align: center;
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

kbd {
  font-family: inherit;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 4px;
  padding: 1px 5px;
  font-size: 11px;
  color: var(--text-dim);
}

@media (max-width: 640px) {
  #pb-sidebar {
    width: 54px;
  }
  #pb-sidebar .tool-label,
  #pb-sidebar .mat-label,
  #pb-sidebar .scene-label {
    display: none;
  }
  .tool-btn {
    justify-content: center;
    padding: 8px 0;
  }
  .mat-btn {
    justify-content: center;
    padding: 6px 0;
    width: 100%;
  }
  .scene-btn {
    padding: 6px 0;
    width: 100%;
  }
  .status-hints {
    display: none;
  }
  #pb-material-bar,
  #pb-scene-bar {
    flex-direction: column;
  }
}
