:root {
  --bg: #14161b;
  --panel: #1e2229;
  --panel2: #262b34;
  --panel3: #2e343f;
  --border: #3a414d;
  --text: #e8e8e8;
  --muted: #9aa1ab;
  --accent: #f0b429;
  --green: #57c26b;
  --red: #e05252;
  --blue: #54a6e8;
  --purple: #b06ae0;
  --amber: #e8a33d;
  --gray: #8a9099;
}

* { box-sizing: border-box; }

html { scrollbar-color: var(--border) transparent; }

body {
  margin: 0;
  font-family: "Segoe UI", "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  background: radial-gradient(1200px 600px at 50% -10%, #29303c 0%, var(--bg) 60%);
  color: var(--text);
  min-height: 100vh;
}

a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------- Top bar ---------- */
.topbar {
  background: linear-gradient(180deg, #343b47, #23272f);
  border-bottom: 2px solid var(--accent);
  padding: 12px 20px 10px;
  position: sticky;
  top: 0;
  z-index: 20;
  box-shadow: 0 4px 16px rgba(0,0,0,.45);
}
.topbar-inner { max-width: 1280px; margin: 0 auto; display: flex; align-items: center; gap: 18px; flex-wrap: wrap; }
.logo { margin: 0; font-size: 21px; letter-spacing: .5px; white-space: nowrap; }
.logo span { color: var(--accent); font-weight: 700; }
.search-wrap { margin-left: auto; flex: 1; max-width: 320px; position: relative; }
#search {
  width: 100%;
  padding: 9px 34px 9px 14px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #16191f;
  color: var(--text);
  font-size: 14px;
  outline: none;
  transition: border-color .15s;
}
#search:focus { border-color: var(--accent); }
.search-wrap::after { content: "🔍"; position: absolute; right: 12px; top: 50%; transform: translateY(-50%); opacity: .5; font-size: 12px; }

.topbar-sub {
  max-width: 1280px; margin: 8px auto 0;
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
  font-size: 12px; color: var(--muted);
}
.stats { display: flex; gap: 14px; }
.stats span { background: var(--panel); border: 1px solid var(--border); padding: 3px 10px; border-radius: 999px; }
.stats b { color: var(--accent); }
.tip { margin-left: auto; }

/* ---------- Tabs ---------- */
.tabs {
  max-width: 1280px; margin: 16px auto 0; padding: 0 20px;
  display: flex; gap: 8px; flex-wrap: wrap;
}
.tab {
  padding: 8px 16px; border-radius: 8px; background: var(--panel);
  border: 1px solid var(--border); color: var(--muted); cursor: pointer;
  font-size: 14px; display: inline-flex; align-items: center; gap: 7px;
  transition: all .15s;
}
.tab:hover { color: var(--text); border-color: var(--accent); transform: translateY(-1px); }
.tab.active { background: linear-gradient(180deg,#f6c23b,#e0a51e); color: #241a05; font-weight: 700; border-color: #f6c23b; }
.tab-count {
  font-size: 11px; background: rgba(0,0,0,.18); padding: 0 7px; border-radius: 999px; font-weight: 700;
}
.tab.active .tab-count { background: rgba(0,0,0,.22); }

/* ---------- Layout ---------- */
.layout {
  max-width: 1280px; margin: 16px auto 40px; padding: 0 20px;
  display: grid; grid-template-columns: 300px 1fr; gap: 18px; align-items: start;
}

/* ---------- Sidebar ---------- */
.sidebar {
  background: var(--panel); border: 1px solid var(--border); border-radius: 12px;
  overflow: hidden; position: sticky; top: 108px;
  max-height: calc(100vh - 122px); display: flex; flex-direction: column;
}
.item-list { overflow-y: auto; padding: 6px; }
.group-header {
  padding: 10px 10px 5px; font-size: 12px; font-weight: 700;
  color: var(--accent); letter-spacing: .5px;
  position: sticky; top: 0; background: var(--panel); z-index: 2;
}
.item-row {
  display: flex; align-items: center; gap: 10px; padding: 6px 8px;
  border-radius: 8px; cursor: pointer; border-left: 3px solid transparent;
  transition: background .12s;
}
.item-row:hover { background: var(--panel2); }
.item-row.active { background: var(--panel2); border-left-color: var(--accent); }
.row-body { min-width: 0; }
.i-name { font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.i-sub { font-size: 11px; color: var(--muted); }
.empty { padding: 24px; color: var(--muted); text-align: center; }

/* ---------- Item tile（Minecraft 风格凹槽） ---------- */
.tile {
  width: 40px; height: 40px; border-radius: 8px;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 20px; position: relative; user-select: none; flex: none;
  border: 2px solid var(--border);
  background: var(--panel3);
  box-shadow: inset 0 2px 0 rgba(255,255,255,.12), inset 0 -3px 0 rgba(0,0,0,.35), 0 1px 2px rgba(0,0,0,.4);
}
.tile.sm { width: 30px; height: 30px; font-size: 15px; border-radius: 6px; }
.tile.big { width: 60px; height: 60px; font-size: 30px; border-radius: 10px; }
.tile.type-gun { background: #3c2424; border-color: var(--red); }
.tile.type-ammo { background: #3a3323; border-color: var(--amber); }
.tile.type-component { background: #232d3a; border-color: var(--blue); }
.tile.type-station { background: #2c233a; border-color: var(--purple); }
.tile.type-vanilla { background: #2d2f34; border-color: var(--gray); }
.tile.clickable { cursor: pointer; transition: transform .12s, filter .12s; }
.tile.clickable:hover { transform: translateY(-2px) scale(1.05); filter: brightness(1.18); }
.tile .count {
  position: absolute; right: -6px; bottom: -6px; background: #000; color: #fff;
  font-size: 11px; font-weight: 700; padding: 1px 5px; border-radius: 6px;
  border: 1px solid var(--border); box-shadow: 0 1px 2px rgba(0,0,0,.5);
}
.tile .output-badge {
  position: absolute; left: -6px; top: -6px; background: var(--green); color: #07210b;
  font-size: 10px; font-weight: 800; padding: 1px 5px; border-radius: 6px; box-shadow: 0 1px 2px rgba(0,0,0,.5);
}

/* ---------- Detail ---------- */
.detail {
  background: var(--panel); border: 1px solid var(--border); border-radius: 12px;
  padding: 18px; min-height: 440px;
  animation: fade .25s ease;
}
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

/* 面包屑 */
.breadcrumb {
  display: flex; align-items: center; flex-wrap: wrap; gap: 6px;
  font-size: 13px; color: var(--muted); margin-bottom: 14px;
  padding-bottom: 12px; border-bottom: 1px solid var(--border);
}
.crumb {
  cursor: pointer; color: var(--blue); padding: 4px 9px; border-radius: 6px;
  background: var(--panel2); border: 1px solid transparent; font-size: 13px;
}
.crumb:hover { border-color: var(--blue); }
.crumb.current { color: var(--text); cursor: default; border-color: var(--border); }
.crumb.back { color: var(--accent); font-weight: 600; }
.crumb.back:hover { border-color: var(--accent); }
.sep { opacity: .45; }

/* 头部 */
.detail-head { display: flex; align-items: center; gap: 14px; margin-bottom: 18px; }
.head-info h2 { margin: 0; font-size: 22px; }
.meta { color: var(--muted); font-size: 13px; margin-top: 6px; display: flex; flex-wrap: wrap; gap: 6px; }
.badge {
  display: inline-block; padding: 2px 10px; border-radius: 999px;
  font-size: 11px; font-weight: 700; color: #0f0f0f;
}
.badge.type-gun { background: var(--red); }
.badge.type-ammo { background: var(--amber); }
.badge.type-component { background: var(--blue); }
.badge.type-station { background: var(--purple); }
.badge.rar-common { background: #9aa0a9; }
.badge.rar-rare { background: #54a6e8; }
.badge.rar-epic { background: #b06ae0; }
.badge.rar-legendary { background: #f0b429; }

.placeholder { padding: 30px 10px; text-align: center; color: var(--muted); }
.placeholder h2 { color: var(--text); }

/* 区块标题 */
.section-title {
  font-size: 13px; color: var(--muted); text-transform: uppercase;
  letter-spacing: 1px; margin-bottom: 10px; font-weight: 700;
}
.section-title .hint { text-transform: none; letter-spacing: 0; font-weight: 400; color: var(--gray); margin-left: 8px; }

/* 配方 */
.station-line {
  display: flex; align-items: center; gap: 8px; font-size: 13px;
  color: var(--muted); margin-bottom: 14px; flex-wrap: wrap;
}
.station-line b { color: var(--text); }
.station-line .dot { opacity: .4; }
.recipe-flow {
  display: flex; align-items: center; gap: 18px; flex-wrap: wrap;
  background: #191c22; border: 1px solid var(--border); border-radius: 10px; padding: 16px;
}
.ingredients { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 12px; flex: 1; }
.ing-item {
  background: var(--panel2); border: 1px solid var(--border); border-radius: 10px;
  padding: 10px 8px; text-align: center; cursor: default; transition: all .15s;
}
.ing-item .tile { margin: 0 auto; }
.ing-item.craftable { cursor: pointer; }
.ing-item.craftable:hover {
  border-color: var(--accent); transform: translateY(-2px);
  box-shadow: 0 6px 14px rgba(0,0,0,.4);
}
.i-label { margin-top: 8px; font-size: 12px; line-height: 1.3; }
.i-hint { font-size: 10px; margin-top: 4px; }
.i-hint.craftable { color: var(--green); }
.i-hint.leaf { color: var(--gray); }

.arrow { font-size: 32px; color: var(--green); font-weight: 700; align-self: center; }
.result { text-align: center; }
.result .tile { margin: 0 auto; }
.res-label { font-size: 12px; margin-top: 8px; max-width: 88px; }

/* 分解树 */
.tree {
  border: 1px solid var(--border); border-radius: 10px;
  background: #191c22; padding: 14px; overflow-x: auto;
}
.tree-node { font-size: 13px; }
.tree-node.leaf { display: flex; align-items: center; gap: 8px; padding: 3px 0; color: var(--gray); }
.tree details { margin-left: 12px; }
.tree details > summary {
  list-style: none; cursor: pointer; display: flex; align-items: center; gap: 8px;
  padding: 4px 6px; border-radius: 6px; user-select: none;
}
.tree details > summary:hover { background: var(--panel2); }
.tree details > summary::-webkit-details-marker { display: none; }
.tree details > summary::before {
  content: "▸"; color: var(--muted); font-size: 11px; transition: transform .15s; width: 12px;
}
.tree details[open] > summary::before { content: "▾"; }
.t-name { font-weight: 600; }
.t-count { color: var(--muted); font-size: 12px; }
.t-tag { font-size: 10px; padding: 1px 7px; border-radius: 999px; }
.t-tag.leaf { background: var(--panel3); color: var(--gray); }
.tree-children { margin-left: 18px; border-left: 2px dashed var(--border); padding-left: 6px; }

/* 页脚 */
.foot {
  text-align: center; color: var(--muted); font-size: 12px;
  padding: 20px; border-top: 1px solid var(--border);
}

/* 滚动条 */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 6px; }
::-webkit-scrollbar-track { background: transparent; }

/* 响应式 */
@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { position: static; max-height: 340px; }
  .tip { display: none; }
}