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

:root {
  --bg: #0f172a;
  --bg-2: #0b1224;
  --surface: #1e293b;
  --surface-2: #334155;
  --border: #475569;
  --text: #f8fafc;
  --text-muted: #94a3b8;
  --primary: #6366f1;
  --primary-light: #818cf8;
  --gold: #f59e0b;
  --gold-light: #fbbf24;
  --green: #10b981;
  --red: #ef4444;
}

html, body {
  height: 100%;
  overflow: hidden;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
}

/* ── Top bar ── */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.6rem 1.25rem;
  background: linear-gradient(135deg, #1e293b 0%, #0f172a 100%);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  gap: 1rem;
}

.topbar__back {
  font-size: 0.8rem;
  color: var(--text-muted);
  text-decoration: none;
  transition: color 0.2s;
  flex: 1;
}

.topbar__back:hover { color: var(--text); }

.topbar__brand {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex: 1;
  justify-content: center;
}

.topbar__logo {
  font-size: 1.5rem;
}

.topbar__title {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.01em;
}

.topbar__reset {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text-muted);
  padding: 0.45rem 1rem;
  border-radius: 0.5rem;
  cursor: pointer;
  font-size: 0.82rem;
  transition: all 0.2s;
  flex: 1;
  max-width: 120px;
}

.topbar__reset:hover {
  background: var(--surface);
  color: var(--text);
  border-color: var(--primary-light);
}

/* ── Layout ── */
.layout {
  flex: 1;
  display: grid;
  grid-template-columns: 1fr 320px;
  min-height: 0;
}

/* ── Canvas ── */
.canvas {
  position: relative;
  background:
    radial-gradient(ellipse at 25% 30%, rgba(99,102,241,0.08) 0%, transparent 55%),
    radial-gradient(ellipse at 75% 70%, rgba(245,158,11,0.06) 0%, transparent 55%),
    var(--bg-2);
  overflow: hidden;
  touch-action: none;
}

.canvas__hint {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
  color: var(--text-muted);
  font-size: 0.9rem;
  text-align: center;
  pointer-events: none;
  max-width: 320px;
  line-height: 1.5;
}

.canvas__hint-emoji {
  font-size: 3rem;
  opacity: 0.7;
}

.canvas__hint.hidden {
  display: none;
}

/* ── Element chip ── */
.element {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.35rem 0.7rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text);
  cursor: grab;
  user-select: none;
  transition: border-color 0.15s, box-shadow 0.15s, transform 0.05s;
  white-space: nowrap;
  touch-action: none;
}

.element:hover {
  border-color: var(--primary-light);
  box-shadow: 0 4px 12px rgba(99,102,241,0.18);
}

.element:active,
.element.dragging {
  cursor: grabbing;
  opacity: 0.6;
  pointer-events: none;
}

.element--drag-over {
  border-color: var(--gold-light);
  box-shadow: 0 0 0 3px rgba(245,158,11,0.35);
  transform: scale(1.04);
}

.element--canvas {
  position: absolute;
  z-index: 1;
}

.element__emoji {
  font-size: 1.05rem;
  line-height: 1;
}

.element__name {
  font-size: 0.85rem;
}

.element__close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: rgba(239, 68, 68, 0.15);
  color: var(--red);
  font-size: 0.7rem;
  border: none;
  cursor: pointer;
  margin-left: 0.1rem;
  line-height: 1;
}

.element__close:hover {
  background: var(--red);
  color: white;
}

.element--new {
  animation: popIn 0.45s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes popIn {
  0% { transform: scale(0.3); opacity: 0; }
  60% { transform: scale(1.15); opacity: 1; }
  100% { transform: scale(1); }
}

/* ── Sidebar ── */
.sidebar {
  background: var(--surface);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.sidebar__head {
  padding: 0.85rem 1rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}

.sidebar__count {
  display: flex;
  align-items: baseline;
  gap: 0.4rem;
}

.sidebar__count-num {
  font-size: 1.4rem;
  font-weight: 800;
  color: var(--gold-light);
  font-variant-numeric: tabular-nums;
}

.sidebar__count-label {
  font-size: 0.78rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.sidebar__search {
  position: relative;
  display: flex;
  align-items: center;
}

.sidebar__search-icon {
  position: absolute;
  left: 0.6rem;
  font-size: 0.85rem;
  color: var(--text-muted);
  pointer-events: none;
}

.sidebar__search-input {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 0.85rem;
  padding: 0.45rem 0.7rem 0.45rem 1.85rem;
  border-radius: 0.5rem;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.sidebar__search-input:focus {
  border-color: var(--primary-light);
  box-shadow: 0 0 0 3px rgba(99,102,241,0.18);
}

.sidebar__list {
  flex: 1;
  overflow-y: auto;
  padding: 0.7rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  align-content: flex-start;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

.sidebar__list::-webkit-scrollbar { width: 8px; }
.sidebar__list::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 999px;
}

.sidebar__list .element {
  cursor: grab;
}

.sidebar__empty {
  padding: 1rem;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.82rem;
}

/* ── Toast ── */
.toast {
  position: fixed;
  bottom: 1.5rem;
  left: 50%;
  transform: translateX(-50%) translateY(150%);
  background: linear-gradient(135deg, var(--gold-dark, #d97706), var(--gold-light));
  color: white;
  padding: 0.7rem 1.25rem;
  border-radius: 999px;
  font-weight: 700;
  font-size: 0.88rem;
  box-shadow: 0 10px 30px rgba(245,158,11,0.4);
  z-index: 100;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  transition: transform 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
  pointer-events: none;
}

.toast.show {
  transform: translateX(-50%) translateY(0);
}

.toast__icon {
  font-size: 1.1rem;
}

/* ── Combine flash effect ── */
.canvas__flash {
  position: absolute;
  width: 80px;
  height: 80px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(245,158,11,0.5), rgba(99,102,241,0.2) 60%, transparent 75%);
  pointer-events: none;
  animation: flash 0.7s ease-out forwards;
  z-index: 5;
}

@keyframes flash {
  0% { transform: scale(0.3); opacity: 1; }
  100% { transform: scale(2.2); opacity: 0; }
}

/* ── Responsive ── */
@media (max-width: 768px) {
  .layout {
    grid-template-columns: 1fr;
    grid-template-rows: 1fr 240px;
  }
  .sidebar {
    border-left: none;
    border-top: 1px solid var(--border);
  }
  .topbar__title { display: none; }
  .canvas__hint { font-size: 0.82rem; }
}
