:root {
  --bg: #100d0a;
  --bg2: #17130e;
  --panel: #1d1812;
  --panel2: #241e16;
  --line: #3d3121;
  --line2: #57452a;
  --gold: #e7c877;
  --gold2: #b9963f;
  --text: #eadfc8;
  --muted: #9c8d72;
  --red: #d4553f;
  --green: #5fae62;
  --blue: #5b9bd5;
  --orange: #d99a3d;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0; padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Microsoft YaHei", "PingFang SC", system-ui, -apple-system, sans-serif;
  font-size: 15px;
}

body {
  background-image:
    radial-gradient(1200px 500px at 50% -10%, rgba(231,200,119,.07), transparent 60%),
    radial-gradient(800px 400px at 100% 100%, rgba(120,70,20,.10), transparent 60%);
  min-height: 100vh;
}

a { color: var(--gold); text-decoration: none; }

/* ===== 顶部 ===== */
.topbar {
  position: sticky; top: 0; z-index: 20;
  background: linear-gradient(180deg, #1d1710f2, #16110cf2);
  border-bottom: 1px solid var(--line2);
  backdrop-filter: blur(6px);
  padding: 10px 14px;
}
.topbar .row1 {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  max-width: 1100px; margin: 0 auto;
}
.brand {
  font-size: 18px; font-weight: 700; color: var(--gold);
  letter-spacing: 1px; white-space: nowrap;
  text-shadow: 0 0 12px rgba(231,200,119,.25);
}
.brand small { font-size: 11px; color: var(--muted); font-weight: 400; margin-left: 6px; letter-spacing: 0; }
.player {
  display: flex; align-items: center; gap: 8px; margin-left: auto; flex-wrap: wrap;
}
.player .tag {
  font-size: 12px; color: var(--gold); border: 1px solid var(--line2);
  background: #221b12; padding: 3px 9px; border-radius: 20px; white-space: nowrap;
  max-width: 46vw; overflow: hidden; text-overflow: ellipsis;
}
.player .tag.z { color: var(--muted); }

.btn {
  border: 1px solid var(--line2); background: linear-gradient(180deg, #2a2318, #1e1810);
  color: var(--text); border-radius: 8px; padding: 7px 14px; font-size: 14px;
  cursor: pointer; transition: .15s; user-select: none; white-space: nowrap;
}
.btn:hover { border-color: var(--gold2); color: var(--gold); }
.btn.primary {
  background: linear-gradient(180deg, #b9963f, #8f6f28);
  border-color: #d9b95e; color: #1a1409; font-weight: 700;
}
.btn.primary:hover { filter: brightness(1.08); color: #1a1409; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.sm { padding: 4px 10px; font-size: 13px; border-radius: 6px; }

/* ===== 标签页 ===== */
.tabs {
  display: flex; gap: 6px; max-width: 1100px; margin: 10px auto 0; padding: 0 14px;
  overflow-x: auto;
}
.tab {
  padding: 8px 18px; border: 1px solid var(--line); border-bottom: none;
  border-radius: 9px 9px 0 0; background: #14100b; color: var(--muted);
  cursor: pointer; font-size: 14px; white-space: nowrap;
}
.tab.active {
  background: var(--panel); color: var(--gold); border-color: var(--line2);
  font-weight: 700;
}

.wrap { max-width: 1100px; margin: 0 auto; padding: 14px; }

/* ===== 工具行 ===== */
.toolbar {
  display: flex; gap: 10px; align-items: center; flex-wrap: wrap;
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  padding: 12px;
}
.search {
  flex: 1; min-width: 200px; position: relative;
}
.search input {
  width: 100%; padding: 10px 14px 10px 36px; font-size: 15px;
  background: var(--bg2); border: 1px solid var(--line2); color: var(--text);
  border-radius: 9px; outline: none;
}
.search input:focus { border-color: var(--gold2); box-shadow: 0 0 0 2px rgba(231,200,119,.08); }
.search::before {
  content: "🔍"; position: absolute; left: 11px; top: 50%; transform: translateY(-50%);
  font-size: 14px; opacity: .7;
}
.counts { display: flex; gap: 8px; flex-wrap: wrap; font-size: 13px; }
.counts .c {
  border: 1px solid var(--line); background: var(--bg2); border-radius: 20px;
  padding: 5px 12px; color: var(--muted);
}
.counts .c b { color: var(--gold); }
.counts .c.red b { color: var(--red); }
.counts .c.green b { color: var(--green); }
.counts .c.blue b { color: var(--blue); }

/* ===== 分类栏 ===== */
.cats {
  display: flex; gap: 6px; flex-wrap: wrap; margin: 12px 0;
}
.cat {
  padding: 6px 13px; border: 1px solid var(--line); border-radius: 20px;
  background: var(--panel); color: var(--muted); font-size: 13px; cursor: pointer;
}
.cat.active { border-color: var(--gold2); color: var(--gold); background: #2a2216; }
.cat .n { font-size: 11px; opacity: .65; margin-left: 4px; }

/* ===== 物品网格 ===== */
.items {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
  gap: 8px;
}
.item {
  display: flex; align-items: center; gap: 10px;
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 10px; padding: 9px 10px; position: relative;
  transition: .12s;
}
.item:hover { border-color: var(--line2); }
.item .nm { flex: 1; min-width: 0; }
.item .nm .name {
  font-size: 14.5px; color: var(--text); white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis;
}
.item .nm .sub { font-size: 11px; color: var(--muted); margin-top: 2px; }
.item .ops { display: flex; gap: 4px; flex-shrink: 0; }
.op {
  width: 30px; height: 30px; display: flex; align-items: center; justify-content: center;
  border-radius: 7px; border: 1px solid var(--line); background: var(--bg2);
  color: var(--muted); font-size: 13px; cursor: pointer; user-select: none;
  transition: .12s;
}
.op:hover { border-color: var(--gold2); }
.op.f.on { background: rgba(212,85,63,.18); border-color: var(--red); color: #ff8f7c; }
.op.r.on { background: rgba(95,174,98,.15); border-color: var(--green); color: #8fd992; }
.op.s.on { background: rgba(91,155,213,.15); border-color: var(--blue); color: #8fc0ee; }

.item.is-f { border-color: rgba(212,85,63,.55); }
.item.is-r { border-color: rgba(95,174,98,.5); }
.item.is-s { border-color: rgba(91,155,213,.5); }

.item .badge {
  position: absolute; top: -7px; left: 10px; font-size: 10px;
  padding: 1px 7px; border-radius: 10px; letter-spacing: 1px;
}
.badge.f { background: var(--red); color: #fff; }
.badge.r { background: var(--green); color: #10240f; }
.badge.s { background: var(--blue); color: #0b1a2a; }

.empty {
  text-align: center; color: var(--muted); padding: 60px 20px; font-size: 14px;
}

/* ===== 底部保存栏 ===== */
.savebar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  background: linear-gradient(0deg, #17120cf5, #17120ce8);
  border-top: 1px solid var(--line2);
  padding: 10px 14px calc(10px + env(safe-area-inset-bottom));
}
.savebar .inner {
  max-width: 1100px; margin: 0 auto; display: flex; gap: 10px; align-items: center;
}
.savebar .hint { font-size: 12px; color: var(--muted); flex: 1; line-height: 1.5; }
.savebar .hint b { color: var(--gold); }

.toast {
  position: fixed; left: 50%; top: 16%; transform: translateX(-50%);
  background: #2b2317; border: 1px solid var(--gold2); color: var(--gold);
  padding: 12px 22px; border-radius: 10px; font-size: 14px; z-index: 99;
  box-shadow: 0 10px 40px rgba(0,0,0,.5); opacity: 0; pointer-events: none;
  transition: .25s; max-width: 80vw; text-align: center;
}
.toast.show { opacity: 1; }
.toast.err { border-color: var(--red); color: #ff9a86; }

/* 底部留白 */
.footer-space { height: 84px; }

.tips {
  margin: 12px 0 0; border: 1px dashed var(--line); border-radius: 10px;
  padding: 10px 14px; font-size: 12.5px; color: var(--muted); line-height: 1.9;
}
.tips b { color: var(--gold); }
.tips .r { color: #ff8f7c; }
.tips .g { color: #8fd992; }
.tips .b { color: #8fc0ee; }

.loading { text-align: center; padding: 50px; color: var(--muted); }
.spinner {
  width: 26px; height: 26px; margin: 0 auto 12px;
  border: 3px solid var(--line2); border-top-color: var(--gold);
  border-radius: 50%; animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ===== 仓库 / 克隆码 ===== */
.storage-head { display: flex; gap: 10px; align-items: center; margin-bottom: 10px; flex-wrap: wrap; }
.claim-banner {
  border: 1px solid var(--gold2); background: rgba(231,200,119,.08); color: var(--gold);
  border-radius: 10px; padding: 10px 14px; font-size: 13px; margin-bottom: 10px; line-height: 1.8;
}
.storage-list { display: flex; flex-direction: column; gap: 8px; }
.storage-row {
  display: flex; align-items: center; gap: 10px; background: var(--panel);
  border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px;
}
.storage-row .nm { flex: 1; min-width: 0; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.storage-row .qty { font-size: 12px; color: var(--gold); white-space: nowrap; }
.storage-row input {
  width: 74px; padding: 6px 8px; font-size: 13px; background: var(--bg2);
  border: 1px solid var(--line2); border-radius: 7px; color: var(--text); outline: none;
}

.modal {
  position: fixed; inset: 0; z-index: 95; background: rgba(0,0,0,.6);
  display: flex; align-items: center; justify-content: center; padding: 18px;
}
.modal-box {
  width: 100%; max-width: 420px; background: var(--panel); border: 1px solid var(--line2);
  border-radius: 14px; padding: 18px; box-shadow: 0 20px 60px rgba(0,0,0,.6);
}
.modal-box h3 { margin: 0 0 8px; color: var(--gold); font-size: 17px; }
.clone-row { display: flex; gap: 8px; margin-top: 12px; align-items: center; }
.clone-row .pselect { flex: 1; }
.clone-row .pinput {
  flex: 1; padding: 9px 12px; background: var(--bg2); border: 1px solid var(--line2);
  border-radius: 8px; color: var(--text); font-size: 14px; outline: none;
}
.clone-code {
  margin-top: 12px; text-align: center; font-size: 28px; letter-spacing: 6px;
  color: var(--gold); background: var(--bg2); border: 1px dashed var(--gold2);
  border-radius: 10px; padding: 14px; cursor: pointer; font-family: Consolas, monospace;
}

/* ===== 资料库 ===== */
.lib-tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 10px; }
.lib-tab {
  padding: 7px 16px; border: 1px solid var(--line); border-radius: 8px;
  background: var(--panel); color: var(--muted); font-size: 13.5px; cursor: pointer;
}
.lib-tab.active { border-color: var(--gold2); color: var(--gold); background: #2a2216; font-weight: 700; }

.lib-toolbar { display: flex; gap: 8px; align-items: center; margin-bottom: 10px; }
.lib-body { display: grid; grid-template-columns: 38% 1fr; gap: 12px; align-items: start; }
.lib-body.rank-mode { grid-template-columns: 1fr; }
.lib-list-wrap { min-width: 0; }
.lib-meta { font-size: 12px; color: var(--muted); margin: 2px 0 8px; }
.lib-list { display: flex; flex-direction: column; gap: 6px; }
.lib-row {
  display: flex; align-items: center; gap: 8px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 9px;
  padding: 9px 11px; cursor: pointer; transition: .12s;
}
.lib-row:hover { border-color: var(--line2); }
.lib-row.active { border-color: var(--gold2); background: #2a2216; }
.lib-row .t { flex: 1; min-width: 0; }
.lib-row .t .n { font-size: 14px; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lib-row .t .s { font-size: 11px; color: var(--muted); margin-top: 2px; }
.lib-row .v { font-size: 12px; color: var(--gold); white-space: nowrap; }
.lib-row .v small { color: var(--muted); }

.lib-detail {
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  padding: 14px; min-height: 200px;
}
.lib-detail .empty { color: var(--muted); text-align: center; padding: 50px 10px; font-size: 13px; }
.lib-back { display: none; }
.dt-title { font-size: 17px; color: var(--gold); font-weight: 700; margin-bottom: 4px; }
.dt-sub { font-size: 12px; color: var(--muted); margin-bottom: 12px; }
.dt-tags { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 12px; }
.dt-tag {
  font-size: 12px; color: var(--muted); border: 1px solid var(--line);
  border-radius: 6px; padding: 3px 8px; background: var(--bg2);
}
.dt-tag b { color: var(--gold); font-weight: 600; }
.dt-section { margin-top: 14px; }
.dt-section h4 {
  margin: 0 0 8px; font-size: 13px; color: var(--gold);
  border-left: 3px solid var(--gold2); padding-left: 8px; font-weight: 700;
}
.dt-section h4 span { color: var(--muted); font-weight: 400; font-size: 12px; margin-left: 6px; }
.dt-stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 6px; }
.dt-stat { background: var(--bg2); border: 1px solid var(--line); border-radius: 7px; padding: 6px 9px; font-size: 12px; color: var(--muted); }
.dt-stat b { display: block; color: var(--text); font-size: 13px; margin-top: 2px; }

.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
.tbl th, .tbl td { padding: 7px 8px; border-bottom: 1px solid var(--line); text-align: left; }
.tbl th { color: var(--muted); font-weight: 400; font-size: 12px; }
.tbl tr:last-child td { border-bottom: none; }
.tbl td.q { color: var(--gold); white-space: nowrap; }
.tbl .lnk { color: var(--gold); cursor: pointer; }
.tbl .lnk:hover { text-decoration: underline; }
.tbl .cond { color: var(--muted); font-size: 11px; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
  font-size: 12px; color: var(--text); border: 1px solid var(--line);
  background: var(--bg2); border-radius: 20px; padding: 4px 11px; cursor: pointer;
}
.chip:hover { border-color: var(--gold2); color: var(--gold); }
.chip .x { color: var(--muted); margin-left: 4px; }

.rank-block { margin-bottom: 18px; }
.rank-block h4 { margin: 0 0 8px; font-size: 14px; color: var(--gold); }
.rank-item { display: flex; align-items: center; gap: 10px; padding: 6px 2px; font-size: 13px; border-bottom: 1px dashed var(--line); }
.rank-item .no { width: 26px; color: var(--muted); font-size: 12px; }
.rank-item .no.top { color: var(--gold); font-weight: 700; }
.rank-item .nm { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; cursor: pointer; }
.rank-item .bar { width: 120px; height: 6px; background: var(--bg2); border-radius: 4px; overflow: hidden; }
.rank-item .bar i { display: block; height: 100%; background: linear-gradient(90deg, var(--gold2), var(--gold)); }
.rank-item .num { width: 56px; text-align: right; color: var(--gold); font-size: 12px; }

@media (max-width: 820px) {
  .lib-body { grid-template-columns: 1fr; }
  .lib-body.show-detail .lib-list-wrap { display: none; }
  .lib-body.show-detail .lib-detail { display: block; }
  .lib-body:not(.show-detail) .lib-detail { display: none; }
  .lib-back { display: inline-block; margin-bottom: 10px; }
  .rank-item .bar { width: 70px; }
}
@media (min-width: 821px) {
  .lib-detail { position: sticky; top: 118px; max-height: calc(100vh - 140px); overflow: auto; }
}

@media (max-width: 640px) {
  .items { grid-template-columns: 1fr 1fr; gap: 6px; }
  .item { padding: 8px; gap: 6px; }
  .item .nm .sub { display: none; }
  .item .ops { gap: 3px; }
  .op { width: 26px; height: 26px; font-size: 12px; }
  .brand { font-size: 16px; }
  .toolbar { padding: 10px; }
}
@media (max-width: 380px) {
  .items { grid-template-columns: 1fr; }
}
