:root {
  --bg: #1c211d;
  --panel: #262c27;
  --panel-2: #2f3630;
  --line: #3a423b;
  --text: #e6e8da;
  --muted: #9aa294;
  --orange: #ff6b1a;
  --paper: #ebe6d6;
  --ink: #1a1d18;
  --up: #7fc96b;
  --down: #f0614d;
  --r-common: #a7b0a3;
  --r-uncommon: #5aa0ff;
  --r-rare: #a77bff;
  --r-epic: #ff5fd2;
  --r-legendary: #ffc21a;
  --stencil: 'Big Shoulders Stencil Display', Impact, sans-serif;
  --body: 'Barlow', system-ui, sans-serif;
  --hazard: repeating-linear-gradient(-45deg, var(--orange) 0 14px, var(--ink) 14px 28px);
}
* { box-sizing: border-box; }
html { color-scheme: dark; }
body {
  margin: 0; min-height: 100vh; color: var(--text); font: 16px/1.5 var(--body);
  background: var(--bg) radial-gradient(circle at 1px 1px, #ffffff08 1px, transparent 0) 0 0 / 22px 22px;
}
.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.up { color: var(--up); } .down { color: var(--down); }
:focus-visible { outline: 2px solid var(--orange); outline-offset: 2px; }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 5; display: flex; flex-wrap: wrap; align-items: center; gap: 8px 24px;
  padding: 10px 24px; background: var(--bg); border-bottom: 1px solid var(--line);
}
.logo { margin: 0; font: 900 30px/1 var(--stencil); letter-spacing: .02em; color: var(--orange); }
nav { display: flex; gap: 2px; flex-wrap: wrap; }
nav button {
  background: none; color: var(--muted); font-weight: 600; padding: 8px 12px; border-radius: 0;
  border-bottom: 3px solid transparent;
}
nav button:hover { color: var(--text); }
nav button.active { color: var(--text); border-bottom-color: var(--orange); }
#userbox { margin-left: auto; display: flex; align-items: center; gap: 14px; }
.wallet {
  background: var(--paper); color: var(--ink); font-weight: 700; padding: 5px 12px 5px 18px;
  clip-path: polygon(10px 0, 100% 0, 100% 100%, 10px 100%, 0 50%);
}

/* ---------- base controls ---------- */
main { max-width: 1180px; margin: 0 auto; padding: 28px 24px 64px; }
button {
  background: var(--orange); color: var(--ink); border: 0; border-radius: 3px; padding: 9px 16px;
  font: 700 15px/1.2 var(--body); cursor: pointer;
}
button:hover:not(:disabled) { filter: brightness(1.1); }
button:disabled { opacity: .45; cursor: not-allowed; }
button.ghost { background: var(--panel-2); color: var(--text); box-shadow: inset 0 0 0 1px var(--line); }
button.danger { background: var(--down); color: #fff; }
button.small { padding: 6px 10px; font-size: 14px; }
input, select {
  background: var(--bg); color: var(--text); border: 1px solid var(--line); border-radius: 3px;
  padding: 8px 10px; font: inherit; max-width: 100%;
}
input:focus, select:focus { border-color: var(--orange); outline: none; }
label { display: block; margin-bottom: 14px; font-weight: 600; }
label input { display: block; width: 100%; margin-top: 6px; font-weight: 400; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 4px; padding: 18px; margin-bottom: 20px; }
.panel h2 { font: 800 24px/1.1 var(--stencil); margin: 0 0 14px; }
.panel h3 { font-size: 16px; margin: 22px 0 8px; }
.page-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 18px; margin-bottom: 18px; }
.page-head p { margin: 0; }
.page-title { font: 900 44px/1 var(--stencil); margin: 0 0 18px; }
.page-head .page-title { margin: 0; }
.empty { color: var(--muted); padding: 24px 0; }

/* rarity colour hook */
.r-Common { --rc: var(--r-common); } .r-Uncommon { --rc: var(--r-uncommon); } .r-Rare { --rc: var(--r-rare); }
.r-Epic { --rc: var(--r-epic); } .r-Legendary { --rc: var(--r-legendary); }
.rtext { color: var(--rc); }
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; background: var(--rc); margin-right: 8px; }

/* ---------- crates (the loud part) ---------- */
.crate-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: 24px; }
.crate { background: var(--panel); border: 2px solid var(--line); border-radius: 4px; overflow: hidden; display: flex; flex-direction: column; }
.crate-lid {
  position: relative; display: flex; align-items: flex-end; justify-content: space-between; gap: 8px;
  min-height: 112px; padding: 26px 18px 14px; background: var(--panel-2);
  border-bottom: 2px solid var(--line);
}
.crate-lid::before { content: ''; position: absolute; inset: 0 0 auto; height: 12px; background: var(--hazard); }
.crate-name { margin: 0; font: 900 40px/.95 var(--stencil); color: var(--paper); }
.free { background: var(--orange); color: var(--ink); font-weight: 700; font-size: 13px; padding: 2px 8px; border-radius: 3px; white-space: nowrap; }
.crate-body { padding: 16px 18px 18px; display: flex; flex-direction: column; gap: 12px; flex: 1; }
.odds-bar { display: flex; height: 10px; border-radius: 2px; overflow: hidden; gap: 2px; background: var(--bg); }
.odds-bar span { background: var(--rc); min-width: 4px; }
.odds-legend { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: 1fr 1fr; gap: 2px 16px; font-size: 14px; }
.odds-legend li { display: flex; align-items: center; gap: 6px; }
.odds-legend i { width: 8px; height: 8px; border-radius: 50%; background: var(--rc); }
.odds-legend .num { margin-left: auto; color: var(--muted); }
details summary { cursor: pointer; color: var(--muted); font-size: 14px; }
details summary:hover { color: var(--text); }
.crate-items { list-style: none; margin: 8px 0 0; padding: 0; font-size: 14px; }
.crate-items li { display: flex; justify-content: space-between; gap: 8px; padding: 4px 0; border-bottom: 1px dashed var(--line); }
.open-btn { margin-top: auto; width: 100%; padding: 13px; font-size: 17px; }
.login-crate { max-width: 400px; margin: 48px auto; }

/* ---------- item tags ---------- */
.tag-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 16px; }
.tag {
  position: relative; background: var(--panel); border: 1px solid var(--line); border-left: 6px solid var(--rc);
  border-radius: 4px; padding: 14px 14px 14px 30px; display: flex; flex-direction: column; gap: 8px;
}
.tag::before { /* punched hole, like a luggage tag */
  content: ''; position: absolute; left: 9px; top: 18px; width: 10px; height: 10px; border-radius: 50%;
  background: var(--bg); box-shadow: inset 0 0 0 1px var(--line);
}
.tag-rarity { font-size: 13px; font-weight: 700; }
.tag-name { margin: -6px 0 0; font-size: 18px; line-height: 1.2; }
.tag-value b { font-size: 18px; }
.tag-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: auto; padding-top: 4px; }
.tag-note { margin-top: auto; color: var(--orange); font-size: 14px; font-weight: 600; }

/* wear meter: green (fresh) to red (scarred), pin = item's float */
.wear-scale {
  position: relative; height: 6px; border-radius: 3px;
  background: linear-gradient(90deg, #4fbf6a 0 7%, #9bcf4f 7% 15%, #e3c93f 15% 38%, #e8913a 38% 45%, #e0533f 45%);
}
.wear-pin { position: absolute; top: -4px; width: 3px; height: 14px; background: var(--paper); transform: translateX(-50%); border-radius: 1px; }
.wear-text { display: flex; justify-content: space-between; font-size: 13px; color: var(--muted); margin-top: 4px; }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 15px; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; white-space: nowrap; }
th { color: var(--muted); font-weight: 600; font-size: 14px; }
th.r, td.r { text-align: right; }
tbody tr:hover { background: #ffffff05; }
#mfilter { width: 100%; max-width: 320px; margin-bottom: 10px; }
svg.spark { width: 120px; height: 30px; display: block; }
svg.spark polyline { fill: none; stroke: var(--orange); stroke-width: 1.5; }

/* ---------- admin ---------- */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 1px; background: var(--line); border: 1px solid var(--line); border-radius: 4px; overflow: hidden; margin: 0 0 20px; }
.stats div { background: var(--panel); padding: 14px 16px; }
.stats dt { color: var(--muted); font-size: 14px; }
.stats dd { margin: 2px 0 0; font: 800 32px/1.1 var(--stencil); }
.admin-case { border-top: 1px solid var(--line); padding: 12px 0; }
.admin-case:last-child { border-bottom: 1px solid var(--line); }
.admin-case > summary { cursor: pointer; color: var(--text); font-size: 16px; }
.admin-case > summary .muted { margin-left: 8px; font-size: 14px; }
.admin-case[open] > summary { margin-bottom: 12px; }
.admin-case > .row { margin-bottom: 8px; }
td input, td select { padding: 5px 8px; }
#newCase { margin-bottom: 14px; }
.badge { background: var(--orange); color: var(--ink); border-radius: 3px; padding: 1px 6px; font-size: 12px; font-weight: 700; }

/* ---------- opening modal ---------- */
#modal { position: fixed; inset: 0; z-index: 10; display: flex; align-items: center; justify-content: center; padding: 16px; background: #0d100dd9; }
#modal[hidden] { display: none; }
.modal-box { width: min(920px, 100%); background: var(--panel); border: 2px solid var(--line); border-radius: 4px; overflow: hidden; }
.reel-wrap { position: relative; overflow: hidden; background: var(--bg); padding: 16px 0; border-bottom: 2px solid var(--line); }
.reel-wrap::before { content: ''; display: block; height: 10px; background: var(--hazard); margin: -16px 0 16px; }
.reel { display: flex; will-change: transform; }
/* width + margin must total 150px: openCase() uses W = 150 */
.reel-item {
  flex: 0 0 140px; margin: 0 5px; height: 92px; display: flex; align-items: flex-end; padding: 10px;
  background: var(--panel-2); border-bottom: 4px solid var(--rc); border-radius: 3px; font-size: 14px; font-weight: 600; line-height: 1.2;
}
.reel-item.hit { background: color-mix(in srgb, var(--rc) 22%, var(--panel-2)); outline: 2px solid var(--rc); }
.reel-marker { position: absolute; left: 50%; top: 10px; bottom: 0; width: 2px; background: var(--orange); z-index: 2; transform: translateX(-50%); }
.reel-marker::before, .reel-marker::after { content: ''; position: absolute; left: 50%; transform: translateX(-50%); border: 8px solid transparent; }
.reel-marker::before { top: 0; border-top-color: var(--orange); }
.reel-marker::after { bottom: 0; border-bottom-color: var(--orange); }
#result { padding: 20px; min-height: 120px; }
#result:empty { display: none; }
.won { max-width: 360px; margin: 0 auto; display: flex; flex-direction: column; gap: 8px; text-align: left; }
.won-name { margin: -6px 0 0; font: 900 40px/1 var(--stencil); color: var(--rc); }
.won-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin-top: 18px; }

/* ---------- toast ---------- */
#toast {
  position: fixed; bottom: 20px; left: 50%; transform: translate(-50%, 8px); z-index: 20; pointer-events: none;
  background: var(--paper); color: var(--ink); font-weight: 600; padding: 10px 16px; border-radius: 3px;
  opacity: 0; transition: opacity .15s, transform .15s; max-width: calc(100% - 32px);
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#toast.err { background: var(--down); color: #fff; }

@media (max-width: 640px) {
  .topbar { padding: 10px 16px; }
  #userbox { margin-left: 0; width: 100%; justify-content: space-between; }
  main { padding: 20px 16px 48px; }
  .page-title { font-size: 36px; }
  .crate-name { font-size: 34px; }
}
/* The reel spin always plays (owner's choice); only the toast honours reduced motion. */
@media (prefers-reduced-motion: reduce) {
  #toast { transition: none; }
}
