:root {
  --bg: #10141b;
  --bg2: #171d27;
  --panel: #1d2532;
  --border: #2b3648;
  --text: #dfe6f0;
  --muted: #8b98ab;
  --accent: #f5a623;
  --accent2: #4f9eff;
  --danger: #e5484d;
  --green: #46c46e;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

header {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 20px;
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
  flex-wrap: wrap;
}
.brand { font-weight: 800; font-size: 20px; letter-spacing: 1px; white-space: nowrap; }
.brand-cs { color: var(--accent); }
.brand-duels { color: var(--text); }
.brand-sub { color: var(--muted); font-size: 12px; font-weight: 600; margin-left: 6px; }

.search-wrap { flex: 1; max-width: 420px; min-width: 180px; }
#search {
  width: 100%;
  padding: 9px 14px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 14px;
  outline: none;
}
#search:focus { border-color: var(--accent2); }

#account { margin-left: auto; display: flex; align-items: center; gap: 10px; }
#user-chip { display: flex; align-items: center; gap: 8px; }
#user-chip img { border-radius: 50%; border: 1px solid var(--border); }
#user-name { font-size: 14px; font-weight: 600; max-width: 140px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.btn {
  display: inline-block;
  padding: 8px 16px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  transition: filter .15s;
}
.btn:hover { filter: brightness(1.15); }
.steam-btn { background: #1b2838; border-color: #2a475e; color: #66c0f4; }
.steam-btn.big { font-size: 17px; padding: 13px 28px; margin-top: 26px; }
.join-btn { background: var(--green); border-color: var(--green); color: #0c1310; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #14181f; }
.btn.danger { background: transparent; border-color: var(--danger); color: var(--danger); }
.btn.ghost { background: transparent; color: var(--muted); padding: 6px 10px; }

/* Hero (signed out) */
#hero { text-align: center; padding: 56px 20px 40px; max-width: 900px; margin: 0 auto; }
#hero h1 { font-size: 40px; font-weight: 800; }
#hero h1 span { color: var(--accent); }
#hero .tagline { color: var(--muted); font-size: 17px; margin-top: 10px; }
.steps { display: flex; gap: 16px; margin-top: 34px; text-align: left; }
.step {
  flex: 1;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 18px;
}
.step-num {
  display: inline-flex; width: 28px; height: 28px;
  align-items: center; justify-content: center;
  background: var(--accent); color: #14181f;
  font-weight: 800; border-radius: 50%; margin-bottom: 10px;
}
.step h3 { font-size: 15px; margin-bottom: 6px; }
.step p { font-size: 13px; color: var(--muted); line-height: 1.5; }
.step code, #howto code, footer code { background: var(--bg); padding: 1px 6px; border-radius: 4px; color: var(--accent); font-size: 12px; }

/* How-to strip (signed in) */
#howto {
  display: flex; align-items: center; justify-content: center; gap: 12px; flex-wrap: wrap;
  padding: 9px 16px;
  background: #14202e;
  border-bottom: 1px solid var(--border);
  font-size: 13px; color: var(--muted);
}
#howto b {
  display: inline-flex; width: 18px; height: 18px;
  align-items: center; justify-content: center;
  background: var(--accent2); color: #0c1017;
  border-radius: 50%; font-size: 11px; margin-right: 5px;
}
#howto .arrow { color: var(--border); }
#howto a { color: var(--green); font-weight: 700; text-decoration: none; }

main { flex: 1; padding: 20px; max-width: 1500px; width: 100%; margin: 0 auto; }

/* Loadout */
.load-cat-title {
  font-size: 12px; font-weight: 800; letter-spacing: 1.5px; text-transform: uppercase;
  color: var(--muted); margin: 22px 0 10px;
}
.load-cat-title:first-child { margin-top: 0; }
.load-row { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 12px; }
.load-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px;
  cursor: pointer;
  transition: transform .12s, border-color .12s;
  position: relative;
}
.load-card:hover { transform: translateY(-3px); border-color: var(--accent2); }
.load-card img { width: 100%; aspect-ratio: 4 / 3; object-fit: contain; }
.load-card .w-name { font-size: 13px; font-weight: 700; margin-top: 4px; }
.load-card .s-name { font-size: 12px; margin-top: 2px; color: var(--muted); min-height: 16px; }
.load-card.has-skin .s-name { color: var(--accent); }
.load-card .team-tags { position: absolute; top: 8px; right: 8px; display: flex; gap: 4px; }
.team-tag { font-size: 9px; font-weight: 800; border-radius: 5px; padding: 1px 5px; background: var(--accent2); color: #0c1017; }
.team-tag.t { background: #e0b23c; }
.load-card .mini-stickers { position: absolute; top: 8px; left: 8px; display: flex; gap: 2px; }
.load-card .mini-stickers img { width: 20px; height: 20px; object-fit: contain; aspect-ratio: auto; }

/* Picker */
.picker-head { display: flex; align-items: center; gap: 14px; margin-bottom: 16px; }
.picker-head h2 { font-size: 20px; }
#grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 14px; }
.skin-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-top: 3px solid var(--rarity, var(--border));
  border-radius: 10px;
  padding: 10px;
  cursor: pointer;
  transition: transform .12s, border-color .12s;
  position: relative;
}
.skin-card:hover { transform: translateY(-3px); border-color: var(--accent2); }
.skin-card img { width: 100%; aspect-ratio: 4 / 3; object-fit: contain; }
.skin-card .skin-name { font-size: 13px; font-weight: 600; margin-top: 6px; line-height: 1.3; }
.skin-card .skin-weapon { font-size: 11px; color: var(--muted); margin-top: 2px; }
.skin-card.equipped::after {
  content: "EQUIPPED";
  position: absolute; top: 8px; right: 8px;
  background: var(--accent); color: #14181f;
  font-size: 10px; font-weight: 800;
  padding: 2px 7px; border-radius: 6px;
}

/* Modal */
#modal-backdrop, #sticker-backdrop {
  position: fixed; inset: 0;
  background: rgba(5, 8, 12, .78);
  display: flex; align-items: center; justify-content: center;
  z-index: 50;
}
#modal {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 14px;
  width: min(460px, 94vw);
  max-height: 92vh;
  overflow-y: auto;
  padding: 22px;
  position: relative;
}
#modal-close {
  position: absolute; top: 10px; right: 14px;
  background: none; border: none; color: var(--muted);
  font-size: 26px; cursor: pointer;
}
#modal-img { width: 62%; display: block; margin: 0 auto; }
#modal h2 { font-size: 17px; text-align: center; margin: 8px 0 16px; }
.control { margin-bottom: 15px; }
.control label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.control .muted { color: var(--muted); font-weight: 400; }
.control input[type="range"] { width: 100%; accent-color: var(--accent); }
.control input[type="number"] {
  width: 100%; padding: 8px 12px;
  background: var(--panel); border: 1px solid var(--border);
  border-radius: 8px; color: var(--text);
}
.wear-labels { display: flex; justify-content: space-between; font-size: 10px; color: var(--muted); }
#team-picker { display: flex; gap: 8px; }
.team-btn {
  flex: 1; padding: 8px;
  background: var(--panel); border: 1px solid var(--border);
  border-radius: 8px; color: var(--text); font-weight: 700; cursor: pointer;
}
.team-btn.active { background: var(--accent2); border-color: var(--accent2); color: #0c1017; }
.modal-actions { display: flex; gap: 10px; margin-top: 4px; }
.modal-actions .btn { flex: 1; text-align: center; }
#modal-msg { font-size: 13px; margin-top: 10px; text-align: center; color: var(--accent); min-height: 18px; }

/* Sticker slots */
#sticker-slots { display: flex; gap: 8px; }
.sticker-slot {
  flex: 1; aspect-ratio: 1;
  background: var(--panel);
  border: 1px dashed var(--border);
  border-radius: 10px;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  color: var(--muted); font-size: 20px;
  overflow: hidden;
}
.sticker-slot:hover { border-color: var(--accent2); }
.sticker-slot img { width: 88%; height: 88%; object-fit: contain; }
.sticker-slot.filled { border-style: solid; }

/* Sticker picker */
#sticker-panel {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 14px;
  width: min(680px, 95vw);
  height: min(560px, 88vh);
  display: flex; flex-direction: column;
  padding: 16px;
}
.sticker-head { display: flex; gap: 10px; margin-bottom: 12px; }
#sticker-search {
  flex: 1; padding: 9px 14px;
  background: var(--panel); border: 1px solid var(--border);
  border-radius: 8px; color: var(--text); outline: none;
}
#sticker-grid {
  flex: 1; overflow-y: auto;
  display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 8px;
  align-content: start;
}
.sticker-item {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px;
  cursor: pointer;
  text-align: center;
}
.sticker-item:hover { border-color: var(--accent2); }
.sticker-item img { width: 100%; aspect-ratio: 1; object-fit: contain; }
.sticker-item .st-name { font-size: 10px; color: var(--muted); line-height: 1.25; margin-top: 3px; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }

footer {
  padding: 12px 20px;
  border-top: 1px solid var(--border);
  background: var(--bg2);
  color: var(--muted);
  font-size: 13px;
  text-align: center;
}

.hidden { display: none !important; }

@media (max-width: 720px) {
  .steps { flex-direction: column; }
  #hero h1 { font-size: 28px; }
  #grid, .load-row { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }
  .search-wrap { order: 10; max-width: none; width: 100%; }
}

.join-btn.match { background: var(--accent2); border-color: var(--accent2); color: #0c1017; }

/* Sticker preview editor */
#sticker-preview {
  position: relative;
  margin-top: 10px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
}
#preview-weapon { width: 100%; display: block; user-select: none; pointer-events: none; }
#preview-layer { position: absolute; inset: 0; }
.pv-sticker {
  position: absolute;
  width: 20%;
  cursor: grab;
  touch-action: none;
  user-select: none;
}
.pv-sticker:active { cursor: grabbing; }
.pv-sticker.active { filter: drop-shadow(0 0 6px var(--accent2)); }
#sticker-adjust { margin-top: 10px; }
#sticker-adjust input[type="range"] { width: 100%; accent-color: var(--accent2); }

/* Loadout card action buttons */
.card-actions { display: flex; gap: 6px; margin-top: 8px; }
.card-btn {
  flex: 1;
  padding: 5px 6px;
  font-size: 11px;
  font-weight: 700;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  cursor: pointer;
}
.card-btn.edit { border-color: var(--accent); color: var(--accent); }
.card-btn:hover { filter: brightness(1.35); }

/* Profile bar */
#profile-bar {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  margin-bottom: 18px;
  padding: 10px 14px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
}
.pb-label { font-size: 12px; font-weight: 800; letter-spacing: 1px; text-transform: uppercase; color: var(--muted); }
.profile-tab {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 13px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-weight: 800;
  cursor: pointer;
}
.profile-tab.viewing { border-color: var(--accent2); color: var(--accent2); }
.profile-tab.active { border-color: var(--accent); }
.pb-count {
  font-size: 10px; font-weight: 700;
  background: var(--border); color: var(--muted);
  border-radius: 8px; padding: 1px 6px;
}
.pb-use { margin-left: auto; }
.pb-active-tag { margin-left: auto; font-size: 12px; color: var(--accent); font-weight: 700; }
@media (max-width: 720px) { .pb-use, .pb-active-tag { margin-left: 0; width: 100%; text-align: center; } }

/* 2D/3D toggle + 3D viewer */
#view-toggle { display: flex; gap: 6px; margin-top: 10px; }
.view-tab {
  padding: 5px 12px; font-size: 12px; font-weight: 700;
  background: var(--bg); border: 1px solid var(--border);
  border-radius: 7px; color: var(--muted); cursor: pointer;
}
.view-tab.active { border-color: var(--accent2); color: var(--accent2); }
.view-tab.unavailable { opacity: .45; }
.view-tab.ghosty { margin-left: auto; }
#preview-3d { margin-top: 10px; }
#canvas3d {
  width: 100%; height: 260px;
  background: radial-gradient(ellipse at 50% 40%, #202a3a 0%, #12161d 75%);
  border: 1px solid var(--border); border-radius: 10px; overflow: hidden;
  touch-action: none;
}
#canvas3d canvas { display: block; }
#hint3d { font-size: 11px; color: var(--muted); text-align: center; margin-top: 6px; }
.pb-import { font-size: 12px; padding: 6px 12px; }

/* Charms + nametag */
#charm-row { display: flex; align-items: center; gap: 10px; }
#charm-slot { width: 54px; height: 54px; flex: none; }
#charm-name { font-size: 13px; flex: 1; }
#nametag-control input {
  width: 100%; padding: 8px 12px;
  background: var(--panel); border: 1px solid var(--border);
  border-radius: 8px; color: var(--text); font-size: 14px;
}
#nametag-control input:focus { border-color: var(--accent2); outline: none; }
#charm-grid {
  flex: 1; overflow-y: auto;
  display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 8px;
  align-content: start;
}
