:root {
  --bg: #0d1220;
  --bg-elev: #141a2e;
  --bg-elev2: #1a2140;
  --border: #26305a;
  --border-strong: #384780;
  --fg: #e6ecff;
  --fg-dim: #9aa5cf;
  --accent: #7ea6ff;
  --tier-s: #ff5b6b;
  --tier-a: #ff9a3c;
  --tier-b: #ffd23c;
  --tier-c: #5fd97a;
  --tier-x: #6aa9ff;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: radial-gradient(1200px 700px at 80% -10%, #1b2350 0%, transparent 60%),
              radial-gradient(1000px 600px at -10% 100%, #241847 0%, transparent 60%),
              var(--bg);
  color: var(--fg);
  font-family: "PingFang SC", "Microsoft YaHei", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  min-height: 100vh;
}

/* Top bar */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 24px;
  border-bottom: 1px solid var(--border);
  background: rgba(13,18,32,0.7);
  backdrop-filter: blur(8px);
  position: sticky; top: 0; z-index: 20;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand .logo {
  color: var(--accent); font-size: 22px;
  text-shadow: 0 0 10px rgba(126,166,255,0.7);
}
.brand .title { font-weight: 600; letter-spacing: 1px; font-size: 18px; }
.brand .meta { color: var(--fg-dim); font-size: 13px; margin-left: 8px; }
.brand .meta b { color: var(--fg); font-weight: 600; }

.tabs { display: flex; gap: 4px; background: var(--bg-elev); padding: 4px; border-radius: 10px; border: 1px solid var(--border); }
.tab {
  background: transparent; color: var(--fg-dim);
  border: 0; padding: 8px 18px;
  font-size: 14px; cursor: pointer; border-radius: 7px;
  transition: color .15s, background .15s;
}
.tab:hover { color: var(--fg); }
.tab.active { background: linear-gradient(180deg, #2c3968, #1e2749); color: #fff; box-shadow: inset 0 1px 0 rgba(255,255,255,0.06); }

/* Main */
main { padding: 20px 24px 48px; max-width: 1560px; margin: 0 auto; }
.panel { display: none; }
.panel.active { display: block; }

/* Toolbar */
.toolbar {
  display: flex; align-items: center; gap: 14px;
  padding: 10px 0 16px;
}
.toolbar .hint { color: var(--fg-dim); font-size: 13px; }
.toolbar .tools { margin-left: auto; display: flex; gap: 8px; }

input[type="search"] {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  color: var(--fg);
  padding: 8px 12px; border-radius: 8px; min-width: 220px;
  outline: none;
}
input[type="search"]:focus { border-color: var(--border-strong); }

.btn {
  background: linear-gradient(180deg, #2c3968, #1e2749);
  color: #fff; border: 1px solid var(--border-strong);
  padding: 8px 14px; border-radius: 8px; font-size: 13px; cursor: pointer;
}
.btn.ghost { background: transparent; }
.btn:hover { filter: brightness(1.15); }

/* Gallery grid */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 14px;
}
.card {
  background: linear-gradient(180deg, #1a2140, #131a34);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px;
  text-align: center; cursor: pointer;
  transition: transform .12s, border-color .12s, box-shadow .12s;
}
.card:hover { transform: translateY(-2px); border-color: var(--border-strong); box-shadow: 0 8px 24px -6px rgba(0,0,0,0.5), 0 0 0 1px rgba(126,166,255,0.25); }
.card img {
  width: 100%; aspect-ratio: 1; object-fit: cover;
  border-radius: 8px; background: #0a0e1c;
  display: block;
}
.card .name {
  margin-top: 8px; font-size: 13px; color: var(--fg);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

/* Tier list */
.tiers { display: flex; flex-direction: column; gap: 8px; margin-bottom: 20px; }
.tier {
  display: flex; align-items: stretch;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 10px; overflow: hidden;
}
.tier-label {
  width: 84px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 34px; font-weight: 800; letter-spacing: 1px;
  color: #16192a;
  text-shadow: 0 1px 0 rgba(255,255,255,0.15);
}
.tier[data-tier="S"] .tier-label { background: var(--tier-s); }
.tier[data-tier="A"] .tier-label { background: var(--tier-a); }
.tier[data-tier="B"] .tier-label { background: var(--tier-b); }
.tier[data-tier="C"] .tier-label { background: var(--tier-c); }
.tier[data-tier="X"] .tier-label { background: var(--tier-x); font-size: 22px; }

.tier-row {
  flex: 1;
  min-height: 88px;
  padding: 8px;
  display: flex; flex-wrap: wrap; gap: 6px;
  align-content: flex-start;
}
.tier-row.dropping { background: rgba(126,166,255,0.08); box-shadow: inset 0 0 0 2px rgba(126,166,255,0.35); }

.pool-wrap {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
}
.pool-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 12px;
  background: rgba(255,255,255,0.03);
  border-bottom: 1px solid var(--border);
  font-size: 13px; color: var(--fg-dim);
}
.pool-head input[type="search"] { min-width: 180px; padding: 6px 10px; font-size: 12px; }
.pool { min-height: 120px; }

/* Chip (small draggable card) */
.chip {
  width: 68px;
  background: linear-gradient(180deg, #1e2749, #141a34);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 4px;
  cursor: grab;
  user-select: none;
  transition: transform .1s, border-color .1s;
}
.chip:hover { border-color: var(--border-strong); transform: translateY(-1px); }
.chip.dragging { opacity: .4; }
.chip img { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 5px; display: block; background: #0a0e1c; }
.chip .chip-name {
  font-size: 11px; text-align: center; margin-top: 3px;
  color: var(--fg-dim);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

/* Modal */
.modal { position: fixed; inset: 0; z-index: 50; display: flex; align-items: center; justify-content: center; }
.modal.hidden { display: none; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(6,8,20,0.75); backdrop-filter: blur(4px); }
.modal-body {
  position: relative; z-index: 1;
  max-width: min(90vw, 560px);
  max-height: 92vh;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  overflow: hidden;
}
.modal-body img {
  max-width: 100%; max-height: 70vh;
  border-radius: 6px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.6);
}
.modal-detail {
  margin-top: 12px;
  padding: 12px 16px;
  background: rgba(30, 20, 50, 0.92);
  border-radius: 8px;
  color: #e8e0f0;
  font-size: 14px;
  line-height: 1.7;
  max-width: 100%;
  word-break: break-word;
  overflow: hidden;
}
.modal-close {
  position: absolute; top: -12px; right: -12px;
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--bg-elev); color: var(--fg);
  border: 1px solid var(--border-strong);
  font-size: 20px; line-height: 1; cursor: pointer;
}

/* Responsive */
@media (max-width: 720px) {
  .topbar { flex-direction: column; gap: 10px; align-items: stretch; }
  .tabs { justify-content: center; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 10px; }
  .tier-label { width: 60px; font-size: 26px; }
  .chip { width: 58px; }
  .show-tier-label { width: 68px; font-size: 30px; }
  .show-card { width: 140px; }
}

/* ---------- Showcase Tier (tftacademy-style) ---------- */
.showcase { display: flex; flex-direction: column; gap: 14px; }

.show-tier {
  display: flex; align-items: stretch;
  background: linear-gradient(180deg, rgba(255,255,255,0.02), transparent), var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 14px; overflow: hidden;
  box-shadow: 0 4px 20px -8px rgba(0,0,0,0.4);
}
.show-tier-label {
  width: 110px; flex-shrink: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  font-weight: 900; letter-spacing: 2px;
  color: #16192a;
  text-shadow: 0 1px 0 rgba(255,255,255,0.18);
  position: relative;
}
.show-tier-label .rank { font-size: 46px; line-height: 1; }
.show-tier-label .sub { font-size: 11px; opacity: 0.75; margin-top: 4px; letter-spacing: 3px; }
.show-tier-label .count {
  position: absolute; bottom: 6px; right: 8px;
  font-size: 10px; letter-spacing: 0;
  background: rgba(0,0,0,0.25); color: rgba(255,255,255,0.9);
  padding: 2px 6px; border-radius: 10px;
  text-shadow: none; font-weight: 600;
}
.show-tier[data-tier="S"] .show-tier-label { background: linear-gradient(180deg, #ff7480, var(--tier-s)); }
.show-tier[data-tier="A"] .show-tier-label { background: linear-gradient(180deg, #ffb060, var(--tier-a)); }
.show-tier[data-tier="B"] .show-tier-label { background: linear-gradient(180deg, #ffe066, var(--tier-b)); }
.show-tier[data-tier="C"] .show-tier-label { background: linear-gradient(180deg, #7fe693, var(--tier-c)); }
.show-tier[data-tier="X"] .show-tier-label { background: linear-gradient(180deg, #8ac0ff, var(--tier-x)); }
.show-tier[data-tier="X"] .show-tier-label .rank { font-size: 30px; }
.show-tier[data-tier="?"] .show-tier-label { background: linear-gradient(180deg, #4a5580, #333e6a); color: #e6ecff; text-shadow: none; }
.show-tier[data-tier="?"] .show-tier-label .rank { font-size: 22px; }

.show-row {
  flex: 1;
  padding: 14px;
  display: flex; flex-wrap: wrap; gap: 12px;
  align-content: flex-start;
  min-height: 130px;
  background:
    linear-gradient(90deg, rgba(255,255,255,0.02), transparent 40%),
    repeating-linear-gradient(45deg, transparent 0 12px, rgba(255,255,255,0.015) 12px 13px);
}

.show-card {
  width: 168px;
  border-radius: 10px;
  overflow: hidden;
  cursor: pointer;
  position: relative;
  background: #0a0e1c;
  box-shadow: 0 4px 14px -4px rgba(0,0,0,0.6);
  border: 1px solid transparent;
  transition: transform .15s, border-color .15s, box-shadow .15s;
}
.show-card:hover {
  transform: translateY(-3px) scale(1.02);
  border-color: rgba(126,166,255,0.5);
  box-shadow: 0 12px 28px -6px rgba(0,0,0,0.7), 0 0 0 1px rgba(126,166,255,0.3);
  z-index: 2;
}
.show-card img {
  width: 100%; aspect-ratio: 501/755;
  object-fit: cover; display: block;
}

.show-empty {
  color: var(--fg-dim); font-size: 12px;
  align-self: center; padding: 4px 6px;
}

.chk { color: var(--fg-dim); font-size: 13px; display: inline-flex; align-items: center; gap: 6px; cursor: pointer; }
.chk input { accent-color: var(--accent); }

.empty {
  margin-top: 40px; padding: 40px 20px;
  text-align: center; color: var(--fg-dim);
  background: var(--bg-elev); border: 1px dashed var(--border); border-radius: 12px;
}
.empty.hidden { display: none; }
.empty a { color: var(--accent); }

/* ---------- Share-code dialog ---------- */
.code-body {
  position: relative; z-index: 1;
  background: var(--bg-elev);
  border: 1px solid var(--border-strong);
  border-radius: 12px;
  padding: 20px 24px 18px;
  width: min(560px, 92vw);
  box-shadow: 0 20px 60px rgba(0,0,0,0.6);
}
.code-body h3 { margin: 0 0 8px; font-size: 16px; }
.code-hint { color: var(--fg-dim); font-size: 12px; margin: 0 0 12px; line-height: 1.6; }
.code-body textarea {
  width: 100%; min-height: 100px; max-height: 220px;
  background: #0a0e1c; color: var(--fg);
  border: 1px solid var(--border); border-radius: 8px;
  padding: 10px 12px;
  font-family: ui-monospace, "Cascadia Code", Consolas, monospace;
  font-size: 12px; line-height: 1.5;
  resize: vertical; outline: none;
  word-break: break-all;
}
.code-body textarea:focus { border-color: var(--border-strong); }
.code-actions { display: flex; gap: 8px; margin-top: 12px; }
.code-msg { min-height: 18px; margin-top: 8px; font-size: 12px; color: var(--fg-dim); }
.code-msg.ok { color: var(--tier-c); }
.code-msg.err { color: var(--tier-s); }
