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

:root {
  --bg: #0b0f17;
  --surface: #131825;
  --surface-2: #1c2233;
  --surface-3: #2a3147;
  --border: #2f3a55;
  --text: #f1f5f9;
  --text-muted: #94a3b8;
  --primary: #6366f1;
  --primary-light: #818cf8;
  --accent: #ec4899;
  --gold: #f59e0b;
  --green: #10b981;
  --red: #ef4444;
  --blue: #38bdf8;
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  overflow: hidden;
}

/* ── Top bar ── */
.topbar {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.6rem 1.25rem;
  background: linear-gradient(180deg, #1a2030 0%, #131825 100%);
  border-bottom: 1px solid var(--border);
  height: 56px;
}

.topbar__back {
  color: var(--text-muted);
  text-decoration: none;
  font-size: 0.82rem;
  white-space: nowrap;
}
.topbar__back:hover { color: var(--text); }

.topbar__brand {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 700;
  font-size: 1.05rem;
}

.topbar__logo {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  background: linear-gradient(135deg, #6366f1, #ec4899);
  border-radius: 7px;
  font-size: 0.95rem;
}

.topbar__tools {
  margin-left: auto;
  display: flex;
  gap: 0.4rem;
}

.tool-btn {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.4rem 0.7rem;
  font-size: 0.78rem;
  cursor: pointer;
  transition: background 0.12s ease, border-color 0.12s ease;
}
.tool-btn:hover {
  background: var(--surface-3);
  border-color: var(--primary);
}
.tool-btn.active {
  background: var(--primary);
  border-color: var(--primary-light);
  color: #fff;
}

/* ── Layout ── */
.layout {
  display: grid;
  grid-template-columns: 1fr 280px;
  height: calc(100vh - 56px);
}

/* ── Stage ── */
.stage {
  display: flex;
  flex-direction: column;
  background: #05070b;
  overflow: hidden;
}

.stage__inner {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  position: relative;
  overflow: hidden;
}

.world {
  background: #000;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  width: 100%;
  height: 100%;
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  cursor: crosshair;
  border: 1px solid var(--border);
  box-shadow: 0 0 0 1px rgba(99,102,241,0.15), 0 8px 24px rgba(0,0,0,0.5);
}

.stage__hint {
  position: absolute;
  top: 24px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: rgba(15, 23, 42, 0.85);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.4rem 0.9rem;
  font-size: 0.8rem;
  color: var(--text-muted);
  pointer-events: none;
  backdrop-filter: blur(6px);
  transition: opacity 0.4s ease;
}
.stage__hint.hidden { opacity: 0; }
.stage__hint-emoji {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  background: linear-gradient(135deg, #6366f1, #ec4899);
  border-radius: 4px;
  font-size: 0.75rem;
}

/* ── Status bar ── */
.statusbar {
  display: flex;
  align-items: center;
  gap: 1.25rem;
  padding: 0.45rem 1rem;
  background: var(--surface);
  border-top: 1px solid var(--border);
  font-size: 0.75rem;
  color: var(--text-muted);
  flex-wrap: wrap;
}
.statusbar__item { white-space: nowrap; }
.statusbar__item strong { color: var(--text); font-weight: 600; }
.statusbar__checkbox {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  cursor: pointer;
  margin-left: auto;
}
.statusbar__checkbox input { cursor: pointer; }

/* ── Sidebar ── */
.sidebar {
  background: var(--surface);
  border-left: 1px solid var(--border);
  overflow-y: auto;
  padding: 0.85rem;
}
.sidebar::-webkit-scrollbar { width: 8px; }
.sidebar::-webkit-scrollbar-track { background: var(--surface); }
.sidebar::-webkit-scrollbar-thumb { background: var(--surface-3); border-radius: 4px; }

.sidebar__section { margin-bottom: 1.25rem; }
.sidebar__section-title {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-bottom: 0.55rem;
}

.brush-slider {
  width: 100%;
  accent-color: var(--primary);
  cursor: pointer;
}

.search-input {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.45rem 0.6rem;
  color: var(--text);
  font-size: 0.82rem;
  margin-bottom: 0.6rem;
}
.search-input:focus {
  outline: none;
  border-color: var(--primary);
}

.categories {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}

.category__title {
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-bottom: 0.35rem;
}

.element-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 4px;
}

.element-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.4rem 2px;
  cursor: pointer;
  transition: transform 0.08s ease, border-color 0.12s ease, background 0.12s ease;
  position: relative;
}
.element-btn:hover {
  background: var(--surface-3);
  border-color: var(--primary);
}
.element-btn.active {
  border-color: var(--primary-light);
  background: rgba(99,102,241,0.18);
  box-shadow: 0 0 0 1px var(--primary-light);
}
.element-btn__swatch {
  width: 22px;
  height: 22px;
  border-radius: 4px;
  border: 1px solid rgba(255,255,255,0.08);
}
.element-btn__label {
  font-size: 0.62rem;
  color: var(--text-muted);
  text-align: center;
  line-height: 1.05;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 100%;
}
.element-btn.active .element-btn__label { color: var(--text); }

/* ── Tips ── */
.tips {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  font-size: 0.74rem;
  color: var(--text-muted);
  line-height: 1.4;
}
.tips li {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.4rem 0.55rem;
}
.tips strong { color: var(--text); }
.tips kbd {
  display: inline-block;
  padding: 1px 5px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 0.7rem;
  font-family: 'Inter', monospace;
  color: var(--text);
}

/* ── Responsive ── */
@media (max-width: 860px) {
  .layout {
    grid-template-columns: 1fr;
    grid-template-rows: 1fr auto;
    height: calc(100vh - 56px);
  }
  .sidebar {
    border-left: none;
    border-top: 1px solid var(--border);
    max-height: 40vh;
  }
  .statusbar { font-size: 0.68rem; gap: 0.75rem; }
}
