:root {
  --bg: #0f1218;
  --panel: #171b23;
  --panel-2: #1f2430;
  --border: #2a3040;
  --text: #e6e9ef;
  --muted: #8a93a6;
  --accent: #f5a623;
  --milspec: #4b69ff;
  --restricted: #8847ff;
  --classified: #d32ce6;
  --covert: #eb4b4b;
  --gold: #e4ae39;
  --card-w: 150px;
  --card-gap: 6px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: radial-gradient(ellipse at top, #1b2130 0%, var(--bg) 60%);
  color: var(--text);
  font-family: "Segoe UI", system-ui, sans-serif;
  min-height: 100vh;
}

button { font: inherit; color: inherit; cursor: pointer; }

.hidden { display: none !important; }
.empty { color: var(--muted); font-size: 13px; }

.topbar {
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 12px 24px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}
.logo { font-weight: 900; font-size: 22px; letter-spacing: 2px; }
.logo span { color: var(--accent); }
.topbar-stats { display: flex; gap: 28px; flex: 1; justify-content: center; }
.stat { display: flex; flex-direction: column; align-items: center; }
.stat-label { font-size: 11px; text-transform: uppercase; color: var(--muted); letter-spacing: 1px; }
.stat-value { font-size: 20px; font-weight: 700; font-variant-numeric: tabular-nums; }
.topbar-right { display: flex; gap: 8px; align-items: center; }
.icon-btn { background: var(--panel-2); border: 1px solid var(--border); border-radius: 6px; padding: 6px 10px; }
.name-input {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  padding: 7px 10px;
  font-weight: 600;
  width: 170px;
}
.name-input:focus { outline: 1px solid var(--accent); }

.layout {
  display: grid;
  grid-template-columns: 240px minmax(0, 1fr) 300px;
  gap: 16px;
  padding: 16px;
}
.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px;
  align-self: start;
  position: sticky;
  top: 16px;
  max-height: calc(100vh - 100px);
  overflow-y: auto;
}
.panel h2 {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  color: var(--muted);
  margin: 0 0 10px;
}
.panel h2:not(:first-child) { margin-top: 20px; }

.roll-list, .online-list, .feed { list-style: none; margin: 0; padding: 0; }
.roll-item {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 10px;
  margin-bottom: 6px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
}
.roll-item:hover, .roll-item.watching { border-color: var(--accent); }
.roll-item .who { font-weight: 600; font-size: 14px; }
.roll-item .what { font-size: 12px; color: var(--muted); }
.roll-item .progress {
  position: absolute;
  left: 0;
  bottom: 0;
  height: 2px;
  background: var(--accent);
}
.live-dot {
  display: inline-block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--covert);
  margin-right: 6px;
  animation: pulse 1s infinite;
}
@keyframes pulse { 50% { opacity: .3; } }

.online-list li { font-size: 13px; padding: 3px 0; }
.player-link { cursor: pointer; }
.player-link:hover { color: var(--accent); text-decoration: underline; }
.online-list li::before { content: "●"; color: #3fbf5f; margin-right: 6px; font-size: 10px; }

.center { min-width: 0; }
.stage {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px;
  position: relative;
}
.stage-title { text-align: center; font-weight: 600; margin-bottom: 12px; color: var(--muted); }
.stage-title strong { color: var(--text); }

.reel-viewport {
  position: relative;
  height: 150px;
  overflow: hidden;
  border-radius: 6px;
  background: #0b0e13;
  mask-image: linear-gradient(90deg, transparent, #000 12%, #000 88%, transparent);
}
.reel-track {
  display: flex;
  gap: var(--card-gap);
  position: absolute;
  top: 10px;
  left: 0;
  will-change: transform;
}
.reel-marker {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 50%;
  width: 2px;
  margin-left: -1px;
  background: var(--accent);
  box-shadow: 0 0 10px var(--accent);
}
.reel-marker::before, .reel-marker::after {
  content: "";
  position: absolute;
  left: -7px;
  border: 8px solid transparent;
}
.reel-marker::before { top: 0; border-top-color: var(--accent); }
.reel-marker::after { bottom: 0; border-bottom-color: var(--accent); }

.card {
  width: var(--card-w);
  flex: 0 0 var(--card-w);
  height: 130px;
  border-radius: 4px;
  background: linear-gradient(180deg, #232938 0%, color-mix(in srgb, var(--rarity) 25%, #232938) 100%);
  border-bottom: 4px solid var(--rarity);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 8px;
  position: relative;
  overflow: hidden;
}
.card .weapon { font-size: 11px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card .skin { font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card .badges { position: absolute; top: 6px; right: 6px; display: flex; gap: 3px; }
.badge { font-size: 10px; font-weight: 700; padding: 1px 4px; border-radius: 3px; background: rgba(0,0,0,.5); }
.badge.st { color: #cf6a32; }

.rarity-milspec { --rarity: var(--milspec); }
.rarity-restricted { --rarity: var(--restricted); }
.rarity-classified { --rarity: var(--classified); }
.rarity-covert { --rarity: var(--covert); }
.rarity-gold { --rarity: var(--gold); }

.result {
  margin-top: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 18px;
  animation: pop .4s ease-out;
}
.result .card { width: 220px; flex-basis: 220px; height: 170px; box-shadow: 0 0 30px color-mix(in srgb, var(--rarity) 60%, transparent); }
.result-info .result-name { font-size: 22px; font-weight: 800; }
.result-info .result-meta { color: var(--muted); margin-top: 4px; }
.result-info .result-rarity { font-weight: 700; color: var(--rarity); text-transform: uppercase; letter-spacing: 1px; font-size: 13px; }
@keyframes pop { from { transform: scale(.85); opacity: 0; } to { transform: scale(1); opacity: 1; } }

.tabs { display: flex; gap: 4px; margin: 16px 0 10px; }
.tab {
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  padding: 8px 14px;
  color: var(--muted);
  font-weight: 600;
}
.tab.active { color: var(--text); border-bottom-color: var(--accent); }

.crate-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 10px; }
.crate {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 8px;
  text-align: center;
  transition: transform .15s, border-color .15s;
}
.crate:hover { transform: translateY(-3px); border-color: var(--case-color); }
.crate-name { font-size: 12px; font-weight: 600; }
.crate:disabled { opacity: .5; cursor: not-allowed; transform: none; }

.item-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; }
.item-grid .card { width: auto; }
.item-grid.small { grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); }
.item-grid.small .card { height: 110px; }
.card .odds { font-size: 10px; color: var(--muted); }

.inventory-summary { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 10px; font-size: 13px; }
.inventory-summary span { padding: 4px 8px; border-radius: 4px; background: var(--panel-2); border-left: 3px solid var(--rarity); }

.feed li {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 10px;
  margin-bottom: 5px;
  border-radius: 4px;
  background: linear-gradient(90deg, color-mix(in srgb, var(--rarity) 22%, transparent), rgba(0,0,0,.25));
  border-left: 3px solid var(--rarity);
  font-size: 13px;
  animation: slide-in .35s ease-out;
}
.feed .feed-body { display: flex; flex-direction: column; gap: 2px; min-width: 0; flex: 1; }
.feed .card { width: 96px; flex: 0 0 96px; height: 52px; padding: 2px; border-bottom-width: 2px; }
.feed .card :is(.weapon, .skin, .badges) { display: none; }
.feed .feed-item { overflow: hidden; text-overflow: ellipsis; }
.feed .feed-head { display: flex; justify-content: space-between; color: var(--muted); font-size: 11px; }
.feed .feed-who { color: var(--text); font-weight: 700; }
.feed .feed-item { color: var(--rarity); font-weight: 600; }
.feed li.rarity-gold, .feed li.rarity-covert { box-shadow: 0 0 12px color-mix(in srgb, var(--rarity) 45%, transparent); }
@keyframes slide-in { from { transform: translateX(30px); opacity: 0; } to { transform: none; opacity: 1; } }

.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
  padding: 16px;
}
.modal-box {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 20px;
  width: min(820px, 100%);
  max-height: 90vh;
  overflow-y: auto;
  position: relative;
}
.modal-box h3 { margin: 0 0 14px; text-align: center; }
.modal-crate-art { width: 220px; margin: 0 auto; }
.modal-crate-art svg { width: 100%; display: block; }
.modal-close { position: absolute; top: 12px; right: 12px; background: none; border: none; font-size: 18px; }
.open-btn {
  display: block;
  margin: 18px auto 0;
  padding: 12px 40px;
  border: none;
  border-radius: 6px;
  background: linear-gradient(180deg, #f7b733, #e08e0b);
  color: #1a1a1a;
  font-weight: 800;
  font-size: 16px;
  text-transform: uppercase;
  letter-spacing: 1px;
}
.open-btn:disabled { opacity: .5; cursor: not-allowed; }

.player-name { font-weight: 600; }
.login-box { width: min(380px, 100%); display: flex; flex-direction: column; gap: 10px; text-align: center; }
.login-box .name-input { width: 100%; font-size: 18px; padding: 10px; text-align: center; }
.login-box .open-btn { margin-top: 6px; }
.link-btn { background: none; border: none; color: var(--muted); text-decoration: underline; }

.celebration {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  background: radial-gradient(circle, color-mix(in srgb, var(--rarity) 35%, rgba(0,0,0,.85)) 0%, rgba(0,0,0,.92) 70%);
  backdrop-filter: blur(4px);
  cursor: pointer;
  animation: pop .45s ease-out;
}
.celebration-title { font-size: 34px; font-weight: 900; text-transform: uppercase; letter-spacing: 3px; color: var(--rarity); text-shadow: 0 0 24px var(--rarity); }
.celebration-who { font-size: 22px; }
.celebration-who strong { color: var(--accent); }
.celebration .card { width: 320px; flex-basis: 320px; height: 230px; box-shadow: 0 0 60px var(--rarity); }
.celebration-name { font-size: 26px; font-weight: 800; }
.celebration-meta { color: var(--muted); }
.celebration.rarity-gold .celebration-title { font-size: 46px; animation: celebrate-pulse 1s ease-in-out infinite; }
.celebration.rarity-gold .card { width: 380px; flex-basis: 380px; height: 270px; }
@keyframes celebrate-pulse { 50% { transform: scale(1.08); } }

.toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--covert);
  padding: 10px 18px;
  border-radius: 6px;
  font-weight: 600;
  z-index: 20;
}

@media (max-width: 1100px) {
  .layout { grid-template-columns: 1fr; }
  .panel { position: static; max-height: none; }
  .panel.right { order: -1; max-height: 220px; overflow-y: auto; }
  .topbar { flex-wrap: wrap; }
}
