* { box-sizing: border-box; }

:root {
  --bg: #14161c;
  --panel: #1e2029;
  --panel-2: #262936;
  --text: #f0f1f5;
  --muted: #9aa0ae;
  --accent: #4f8cff;
  color-scheme: dark;
}

body {
  margin: 0;
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  touch-action: pan-y;
}

.topbar {
  padding: 14px 16px 0;
  text-align: center;
}
.topbar h1 {
  margin: 0 0 10px;
  font-size: 1.4rem;
}

.categories, .subnav {
  display: flex;
  justify-content: center;
  gap: 8px;
  flex-wrap: wrap;
  padding: 0 8px;
}

.subnav { margin: 10px 0 0; }

.categories button, .subnav-btn {
  background: var(--panel);
  color: var(--text);
  border: 1px solid #333748;
  border-radius: 8px;
  padding: 8px 14px;
  font-size: 0.95rem;
  cursor: pointer;
}
.categories button.active, .subnav-btn.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

main {
  max-width: 1100px;
  margin: 0 auto;
  padding: 16px;
}

.build-toolbar {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
  margin-bottom: 14px;
}
.build-toolbar input {
  flex: 1;
  min-width: 200px;
  padding: 8px 10px;
  border-radius: 6px;
  border: 1px solid #333748;
  background: var(--panel);
  color: var(--text);
}
.build-toolbar button {
  padding: 8px 14px;
  border-radius: 6px;
  border: none;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  font-size: 0.95rem;
}
#resetBtn { background: #43485c; }
.save-status { font-size: 0.85rem; color: var(--muted); }

.board {
  display: flex;
  flex-direction: column;
  gap: 4px;
  border-radius: 10px;
  overflow: hidden;
}

.tier-row {
  display: flex;
  align-items: flex-start;
  flex-wrap: wrap;
  gap: 6px;
  min-height: 74px;
  padding: 8px;
}

.tier-row.board-row {
  padding-left: 0;
}

.tier-label {
  flex: 0 0 88px;
  width: 88px;
  min-height: 58px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  text-align: center;
  border-radius: 6px;
  color: #fff;
  text-shadow: 0 1px 2px rgba(0,0,0,.5);
  padding: 4px;
}

.tier-items {
  flex: 1;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  min-height: 58px;
  background: var(--panel);
  border-radius: 6px;
  padding: 6px;
}

.tier-items.drag-over {
  outline: 2px dashed #fff;
  outline-offset: -2px;
}

.pool-title { margin: 18px 0 8px; color: var(--muted); font-size: 0.95rem; }
.pool {
  background: var(--panel);
  border-radius: 8px;
  min-height: 90px;
}
.pool.drag-over { outline: 2px dashed #fff; outline-offset: -2px; }

.item-card {
  width: 64px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  cursor: grab;
  touch-action: none;
}
.item-card .item-icon {
  width: 64px;
  height: 64px;
  border-radius: 6px;
  background: var(--panel-2);
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid #333748;
}
.item-card img {
  max-width: 100%;
  max-height: 100%;
  pointer-events: none;
  user-select: none;
  -webkit-user-drag: none;
}
.item-card.dragging { opacity: 0.25; }

.item-card .item-name {
  font-size: 0.6rem;
  line-height: 1.1;
  color: var(--muted);
  text-align: center;
  white-space: nowrap;
  max-width: 64px;
  overflow: hidden;
  text-overflow: ellipsis;
  pointer-events: none;
}

.ghost-card {
  position: fixed;
  width: 64px;
  height: 64px;
  pointer-events: none;
  z-index: 999;
  border-radius: 6px;
  background: var(--panel-2);
  border: 2px solid var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 6px 18px rgba(0,0,0,.5);
}
.ghost-card img { max-width: 100%; max-height: 100%; }

.history-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.history-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--panel);
  border-radius: 8px;
  padding: 10px 14px;
  gap: 10px;
  flex-wrap: wrap;
}
.history-item .meta { color: var(--muted); font-size: 0.85rem; }
.history-item button {
  padding: 6px 12px;
  border-radius: 6px;
  border: none;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
}
.empty-msg { color: var(--muted); padding: 20px; text-align: center; }

@media (max-width: 640px) {
  .tier-label { flex-basis: 64px; width: 64px; font-size: 0.75rem; }
  .item-card { width: 52px; height: 52px; }
}
