:root {
  --bg: #0e1116;
  --bg-2: #161b22;
  --surface: #1c2230;
  --surface-2: #232b3a;
  --border: #2b3242;
  --text: #e6e9ef;
  --text-muted: #8b93a7;
  --accent: #ff9d3a;
  --accent-2: #ffb865;
  /* rarity */
  --milspec: #4b69ff;
  --restricted: #8847ff;
  --classified: #d32ce6;
  --covert: #eb4b4b;
  --gold: #ffd700;
}
* { margin: 0; padding: 0; box-sizing: border-box; }
body {
  background: radial-gradient(1200px 500px at 50% -100px, #1a2130, var(--bg)) fixed;
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  min-height: 100vh;
}
.wrap { width: 100%; max-width: 1100px; margin: 0 auto; padding: 0 1.25rem; }
.muted { color: var(--text-muted); font-weight: 400; }

header {
  border-bottom: 1px solid var(--border);
  background: rgba(14,17,22,0.85);
  backdrop-filter: blur(6px);
  position: sticky; top: 0; z-index: 20;
}
.header-inner { display: flex; align-items: center; justify-content: space-between; padding: 0.9rem 1.25rem; }
h1 { font-size: 1.3rem; font-weight: 750; letter-spacing: -0.01em; }
h1::before { content: "📦 "; }
.stats { display: flex; align-items: center; gap: 1rem; font-size: 0.9rem; color: var(--text-muted); }
.stats b { color: var(--text); }

.btn {
  font: inherit; cursor: pointer; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); padding: 0.5rem 0.9rem; transition: all .15s;
}
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); color: #10131a; border-color: var(--accent); font-weight: 700; }
.btn.primary:hover { background: var(--accent-2); }
.btn.primary:disabled { opacity: .5; cursor: default; }
.btn.ghost { background: transparent; }
.btn.big { padding: 0.7rem 2.2rem; font-size: 1.05rem; }

main { padding: 1.5rem 0 3rem; }

.controls { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: 1.25rem; flex-wrap: wrap; }
.tabs { display: flex; gap: 0.5rem; }
.tab { font: inherit; cursor: pointer; background: var(--surface); border: 1px solid var(--border); color: var(--text-muted); padding: 0.5rem 1rem; border-radius: 8px; }
.tab.active { background: var(--surface-2); color: var(--text); border-color: var(--accent); }
#search { background: var(--surface); border: 1px solid var(--border); color: var(--text); border-radius: 8px; padding: 0.5rem 0.9rem; min-width: 220px; }
#search:focus { outline: none; border-color: var(--accent); }

/* crate grid */
.crate-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 1rem; }
.crate-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 1rem;
  display: flex; flex-direction: column; align-items: center; gap: 0.5rem; cursor: pointer; transition: all .15s;
}
.crate-card:hover { border-color: var(--accent); transform: translateY(-3px); box-shadow: 0 8px 24px rgba(0,0,0,.4); }
.crate-card img { width: 100%; height: 110px; object-fit: contain; }
.crate-card .name { font-size: 0.85rem; text-align: center; line-height: 1.3; color: #fff; }

/* opener */
.back { margin-bottom: 1rem; }
.opener-head { display: flex; gap: 1.25rem; align-items: center; margin-bottom: 1.5rem; flex-wrap: wrap; }
.opener-head img { width: 130px; height: 100px; object-fit: contain; }
#opener-name { font-size: 1.5rem; font-weight: 700; }
.odds-toggle { background: none; border: none; color: var(--accent); cursor: pointer; font: inherit; padding: 0.4rem 0; }
.odds-table { border-collapse: collapse; margin-top: 0.5rem; font-size: 0.85rem; }
.odds-table td { padding: 0.15rem 0.75rem 0.15rem 0; }
.odds-table .swatch { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 6px; vertical-align: middle; }
.odds-table .pct { color: var(--text-muted); font-variant-numeric: tabular-nums; }

/* reel */
.reel-viewport {
  position: relative; overflow: hidden; border: 1px solid var(--border); border-radius: 12px;
  background: linear-gradient(var(--bg-2), var(--surface));
  height: calc(var(--rows, 1) * var(--rowh, 132px)); margin-bottom: 1.5rem;
  -webkit-mask-image: linear-gradient(90deg, transparent, #000 12%, #000 88%, transparent);
  mask-image: linear-gradient(90deg, transparent, #000 12%, #000 88%, transparent);
}
.marker { position: absolute; left: 50%; top: 0; bottom: 0; width: 3px; background: var(--accent); transform: translateX(-50%); z-index: 3; box-shadow: 0 0 12px var(--accent); }
.reel { display: flex; height: var(--rowh, 132px); align-items: center; will-change: transform; }
.reel + .reel { border-top: 1px solid var(--border); }
.reel-item {
  flex: 0 0 120px; height: calc(var(--rowh, 132px) - 16px); margin: 0 4px; border-radius: 8px;
  background: var(--surface); border-bottom: 4px solid var(--tier, var(--border));
  display: flex; align-items: center; justify-content: center; position: relative;
}
.reel-item img { max-width: 92%; max-height: 82%; object-fit: contain; }
.reel-item::before { content: ""; position: absolute; inset: 0; border-radius: 8px; background: var(--tier, transparent); opacity: .10; }

/* reveal */
.reveal { text-align: center; padding: 1rem 0 0.5rem; }
.reveal.show { animation: pop .4s ease; }
@keyframes pop { from { transform: scale(.85); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.reveal .card {
  display: inline-block; padding: 1.25rem 2rem; border-radius: 14px; background: var(--surface);
  border: 1px solid var(--tier, var(--border)); border-bottom: 5px solid var(--tier, var(--border));
  box-shadow: 0 0 40px -8px var(--tier, transparent);
}
.reveal img { width: 260px; max-width: 70vw; height: 170px; object-fit: contain; }
.reveal .r-rarity { font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.1em; font-weight: 700; color: var(--tier, var(--text)); }
.reveal .r-name { font-size: 1.25rem; font-weight: 700; margin: 0.25rem 0; }
.reveal .r-sub { color: var(--text-muted); font-size: 0.9rem; }
.reveal .st { color: var(--accent); font-weight: 700; }
.reveal .r-price { font-size: 1.15rem; font-weight: 700; color: var(--good); margin-top: 0.4rem; }
.reveal .r-price .est { font-size: 0.7rem; color: var(--text-muted); font-weight: 400; }
.reveal .r-price.muted { color: var(--text-muted); font-weight: 400; font-size: 0.9rem; }

.opener-actions { text-align: center; margin-top: 1rem; display: flex; flex-direction: column; align-items: center; gap: 0.9rem; }
.qty-select { display: inline-flex; gap: 0.3rem; background: var(--surface); border: 1px solid var(--border); border-radius: 9px; padding: 0.25rem; }
.qty { font: inherit; cursor: pointer; background: transparent; border: none; color: var(--text-muted); padding: 0.35rem 0.8rem; border-radius: 6px; }
.qty.active { background: var(--surface-2); color: var(--text); font-weight: 700; }

/* bulk results */
.bulk-results { margin-bottom: 1rem; }
.bulk-summary { text-align: center; margin-bottom: 1rem; }
.bulk-summary > b { font-size: 1.1rem; }
.bt-row { display: flex; flex-wrap: wrap; gap: 0.4rem; justify-content: center; margin: 0.6rem 0 0.4rem; }
.bt { font-size: 0.78rem; padding: 0.15rem 0.6rem; border-radius: 999px; border: 1px solid var(--tier, var(--border)); color: var(--tier, var(--text)); font-weight: 600; }
.h-item .h-name .muted { font-size: 0.62rem; }

/* history */
#history-section { margin-top: 2.5rem; border-top: 1px solid var(--border); padding-top: 1.25rem; }
#history-section h3 { font-size: 1.05rem; margin-bottom: 1rem; }
.history-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 0.6rem; }
.h-item { background: var(--surface); border-radius: 8px; border-bottom: 3px solid var(--tier, var(--border)); padding: 0.5rem; text-align: center; }
.h-item img { width: 100%; height: 60px; object-fit: contain; }
.h-item .h-name { font-size: 0.68rem; color: var(--text-muted); line-height: 1.2; margin-top: 0.25rem;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.h-item .h-meta { font-size: 0.66rem; margin-top: 0.2rem; }
.h-item .h-price { color: var(--good); font-weight: 700; }
.bulk-total { margin-top: 0.5rem; font-size: 1.05rem; font-weight: 700; color: var(--text); }
.bulk-total .muted { font-weight: 400; font-size: 0.8rem; }
.net.pos { color: var(--good); }
.net.neg { color: var(--covert); }
.stats .net.pos { color: var(--good); }
.stats .net.neg { color: var(--covert); }

footer { color: var(--text-muted); font-size: 0.82rem; padding: 1.5rem 1.25rem 2.5rem; text-align: center; }
footer a { color: var(--accent); text-decoration: none; }
footer a:hover { text-decoration: underline; }

@media (max-width: 560px) {
  .header-inner { flex-direction: column; gap: 0.5rem; align-items: flex-start; }
  .reel-item, .reveal img { flex-basis: 100px; }
}
