:root {
  --bg: #0E0F13;
  --surface: #171922;
  --surface-hi: #1F212C;
  --border: #2A2D3A;
  --text: #F1F1F4;
  --text-dim: #8B8D9A;
  --accent: #7C5CFF;
  --accent-dim: #5B3FD9;

  --rarity-common: #8B93A6;
  --rarity-uncommon: #4A9EFF;
  --rarity-rare: #8B5CF6;
  --rarity-epic: #D946A8;
  --rarity-legendary: #F2B705;

  --radius: 14px;
  --font-display: 'Space Grotesk', sans-serif;
  --font-body: 'Inter', sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }
button { font-family: inherit; cursor: pointer; }

img { max-width: 100%; display: block; }

/* ---------- Topbar ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  background: rgba(14, 15, 19, 0.85);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}

.topbar__inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 16px 24px;
  display: flex;
  align-items: center;
  gap: 40px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 20px;
  letter-spacing: 0.02em;
}

.brand__mark { flex-shrink: 0; }

.topnav {
  display: flex;
  gap: 28px;
  flex: 1;
}

.topnav__link {
  font-size: 15px;
  font-weight: 500;
  color: var(--text-dim);
  padding: 6px 0;
  border-bottom: 2px solid transparent;
  transition: color 0.15s;
}

.topnav__link:hover { color: var(--text); }

.topnav__link--active {
  color: var(--text);
  border-bottom-color: var(--accent);
}

.balance {
  display: flex;
  align-items: baseline;
  gap: 6px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 8px 18px;
}

.balance__label {
  font-size: 12px;
  color: var(--text-dim);
  margin-right: 4px;
}

.balance__value {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 16px;
}

.balance__currency {
  font-size: 13px;
  color: var(--text-dim);
}

/* ---------- Hero ---------- */

.layout {
  max-width: 1400px;
  margin: 0 auto;
  display: flex;
  align-items: flex-start;
  gap: 0;
}

/* ---------- Sidebar (категории) ---------- */

.sidebar {
  width: 220px;
  flex-shrink: 0;
  padding: 32px 0 40px 24px;
  position: sticky;
  top: 73px;
  align-self: flex-start;
}

.sidebar__title {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-dim);
  margin: 0 0 14px;
  padding: 0 14px;
}

.sidebar__list {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.category-tab {
  display: flex;
  align-items: center;
  background: transparent;
  border: none;
  border-left: 3px solid transparent;
  color: var(--text-dim);
  font-size: 14px;
  font-weight: 500;
  padding: 12px 16px;
  border-radius: 0 8px 8px 0;
  text-align: left;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.category-tab:hover {
  background: var(--surface);
  color: var(--text);
  border-left-color: var(--accent-dim);
}

.category-tab--active {
  background: var(--surface-hi);
  color: var(--text);
  border-left-color: var(--accent);
  font-weight: 600;
}

/* ---------- Main content ---------- */

.page {
  flex: 1;
  min-width: 0;
  padding: 0 24px 80px;
}

.hero {
  padding: 32px 0 32px;
}

.hero__title {
  font-family: var(--font-display);
  font-size: 42px;
  line-height: 1.08;
  font-weight: 700;
  margin: 0 0 16px;
  letter-spacing: -0.01em;
}

.hero__subtitle {
  font-size: 16px;
  color: var(--text-dim);
  max-width: 480px;
  margin: 0;
  line-height: 1.5;
}

/* ---------- Case grid ---------- */

.case-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 24px;
}

.case-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  cursor: pointer;
  transition: transform 0.15s, border-color 0.15s, box-shadow 0.15s;
  display: flex;
  flex-direction: column;
}

.case-card:hover {
  transform: translateY(-4px);
  border-color: var(--accent-dim);
  box-shadow: 0 12px 32px rgba(124, 92, 255, 0.18);
}

.case-card__header {
  padding: 16px 16px 4px;
}

.case-card__name {
  font-family: var(--font-display);
  font-size: 16px;
  font-weight: 700;
  margin: 0 0 4px;
  letter-spacing: 0.01em;
}

.case-card__count {
  font-size: 12px;
  color: var(--text-dim);
  margin: 0;
}

.case-card__image-wrap {
  aspect-ratio: 4 / 3;
  background: linear-gradient(160deg, var(--surface-hi), var(--surface));
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
  margin: 10px 0;
  position: relative;
  overflow: hidden;
}

.case-card__image-wrap::before {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at 50% 30%, rgba(124,92,255,0.15), transparent 70%);
}

.case-card__image {
  width: 100%;
  height: 100%;
  object-fit: contain;
  position: relative;
  z-index: 1;
}

.case-card__body {
  padding: 0 16px 16px;
  display: flex;
  justify-content: center;
}

.case-card__price {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 15px;
  color: var(--accent);
  border: 1px solid var(--accent-dim);
  border-radius: 8px;
  padding: 6px 20px;
  width: 100%;
  text-align: center;
}

.case-card__price::after {
  content: ' ₽';
  font-weight: 600;
  font-size: 13px;
}

/* ---------- Modal overlay ---------- */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(8, 9, 12, 0.8);
  backdrop-filter: blur(4px);
  display: none;
  align-items: flex-start;
  justify-content: center;
  padding: 40px 20px;
  overflow-y: auto;
  z-index: 100;
}

.modal-overlay--open { display: flex; }

.case-modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  max-width: 760px;
  width: 100%;
  padding: 32px;
  position: relative;
}

.case-modal__close {
  position: absolute;
  top: 20px;
  right: 20px;
  background: var(--surface-hi);
  border: 1px solid var(--border);
  color: var(--text-dim);
  width: 36px;
  height: 36px;
  border-radius: 50%;
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.case-modal__close:hover { color: var(--text); }

.case-modal__header {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 28px;
}

.case-modal__thumb {
  width: 64px;
  height: 64px;
  object-fit: contain;
  background: var(--surface-hi);
  border-radius: 10px;
  padding: 8px;
}

.case-modal__title {
  font-family: var(--font-display);
  font-size: 22px;
  margin: 0 0 4px;
}

.case-modal__price {
  margin: 0;
  color: var(--accent);
  font-weight: 600;
}

/* ---------- Reel (рулетка открытия) ---------- */

.reel-viewport {
  position: relative;
  height: 160px;
  overflow: hidden;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  margin-bottom: 24px;
}

.reel-pointer {
  position: absolute;
  left: 50%;
  top: 0;
  bottom: 0;
  width: 2px;
  background: var(--accent);
  transform: translateX(-50%);
  z-index: 5;
  box-shadow: 0 0 12px var(--accent);
}

.reel-pointer::before,
.reel-pointer::after {
  content: '';
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  width: 0;
  height: 0;
  border-left: 7px solid transparent;
  border-right: 7px solid transparent;
}

.reel-pointer::before {
  top: 0;
  border-top: 9px solid var(--accent);
}

.reel-pointer::after {
  bottom: 0;
  border-bottom: 9px solid var(--accent);
}

.reel-track {
  display: flex;
  align-items: center;
  height: 100%;
  will-change: transform;
}

.reel-item {
  flex: 0 0 140px;
  height: 130px;
  margin: 0 6px;
  border-radius: 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 10px;
  border: 1px solid var(--border);
  background: var(--surface-hi);
}

.reel-item__image {
  width: 60px;
  height: 60px;
  object-fit: contain;
  margin-bottom: 8px;
}

.reel-item__name {
  font-size: 11px;
  text-align: center;
  color: var(--text-dim);
  line-height: 1.3;
  max-width: 120px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Цветовая маркировка редкости — общая иконография жанра, не чей-то товарный знак */
.rarity-common   { border-color: var(--rarity-common); }
.rarity-uncommon { border-color: var(--rarity-uncommon); }
.rarity-rare     { border-color: var(--rarity-rare); }
.rarity-epic     { border-color: var(--rarity-epic); }
.rarity-legendary{ border-color: var(--rarity-legendary); box-shadow: 0 0 16px rgba(242,183,5,0.35); }

.btn-open {
  width: 100%;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 10px;
  padding: 16px;
  font-size: 16px;
  font-weight: 600;
  font-family: var(--font-display);
  transition: background 0.15s;
}

.btn-open:hover { background: var(--accent-dim); }

.btn-open:disabled {
  background: var(--surface-hi);
  color: var(--text-dim);
  cursor: not-allowed;
}

/* ---------- Contents list ---------- */

.case-modal__contents { margin-top: 32px; }

.case-modal__contents-title {
  font-size: 14px;
  color: var(--text-dim);
  font-weight: 600;
  margin: 0 0 14px;
}

.contents-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
  gap: 10px;
}

.content-item {
  background: var(--surface-hi);
  border: 1px solid var(--border);
  border-left: 3px solid var(--rarity-common);
  border-radius: 8px;
  padding: 10px;
  text-align: center;
}

.content-item__image {
  width: 44px;
  height: 44px;
  object-fit: contain;
  margin: 0 auto 6px;
}

.content-item__name {
  font-size: 11px;
  color: var(--text-dim);
  margin: 0 0 4px;
  line-height: 1.3;
  height: 28px;
  overflow: hidden;
}

.content-item__price {
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
}

/* ---------- Win overlay ---------- */

.win-overlay {
  position: fixed;
  inset: 0;
  background: rgba(8, 9, 12, 0.85);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 200;
}

.win-overlay--open { display: flex; }

.win-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 40px;
  text-align: center;
  width: 320px;
  animation: winPop 0.35s ease-out;
}

@keyframes winPop {
  from { transform: scale(0.85); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

.win-card__eyebrow {
  color: var(--text-dim);
  font-size: 13px;
  margin: 0 0 20px;
}

.win-card__image {
  width: 120px;
  height: 120px;
  object-fit: contain;
  margin: 0 auto 20px;
}

.win-card__name {
  font-family: var(--font-display);
  font-size: 18px;
  margin: 0 0 8px;
}

.win-card__price {
  color: var(--accent);
  font-weight: 600;
  margin: 0 0 24px;
}

.btn-secondary {
  background: var(--surface-hi);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 12px 24px;
  border-radius: 10px;
  font-weight: 600;
  width: 100%;
}

.btn-secondary:hover { border-color: var(--accent-dim); }

/* ---------- Responsive ---------- */

@media (max-width: 640px) {
  .topbar__inner { gap: 16px; }
  .topnav { display: none; }
  .hero__title { font-size: 34px; }
  .case-modal { padding: 20px; }

  .layout {
    flex-direction: column;
  }

  .sidebar {
    width: 100%;
    position: static;
    padding: 16px 24px 0;
  }

  .sidebar__list {
    flex-direction: row;
    overflow-x: auto;
    gap: 8px;
    padding-bottom: 4px;
  }

  .category-tab {
    border-left: none;
    border-bottom: 3px solid transparent;
    border-radius: 8px 8px 0 0;
    white-space: nowrap;
  }

  .category-tab:hover,
  .category-tab--active {
    border-left-color: transparent;
    border-bottom-color: var(--accent);
  }
}

/* ---------- Auth area (профиль / вход) ---------- */

.header-right {
  display: flex;
  align-items: center;
  gap: 14px;
}

.auth-area {
  display: flex;
  align-items: center;
}

.btn-steam-login {
  display: flex;
  align-items: center;
  gap: 8px;
  background: #171a21;
  border: 1px solid #2a3f5f;
  color: #fff;
  padding: 8px 16px 8px 10px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 600;
  transition: background 0.15s;
}

.btn-steam-login:hover { background: #1b2838; }

.btn-steam-login__icon {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
}

.user-profile {
  display: flex;
  align-items: center;
  gap: 10px;
  position: relative;
}

.user-profile__avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 2px solid var(--border);
  cursor: pointer;
  object-fit: cover;
}

.user-profile__name {
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  max-width: 120px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.user-profile__menu {
  position: absolute;
  top: calc(100% + 10px);
  right: 0;
  background: var(--surface-hi);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 6px;
  min-width: 160px;
  display: none;
  z-index: 60;
  box-shadow: 0 12px 24px rgba(0,0,0,0.35);
}

.user-profile__menu--open { display: block; }

.user-profile__menu-item {
  display: block;
  width: 100%;
  text-align: left;
  padding: 10px 12px;
  border-radius: 6px;
  font-size: 14px;
  color: var(--text);
  background: none;
  border: none;
}

.user-profile__menu-item:hover { background: var(--surface); }

@media (max-width: 640px) {
  .user-profile__name { display: none; }
}

/* ---------- Инвентарь ---------- */

.inventory-view__header { padding: 32px 0 24px; }

.inventory-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 18px;
}

.inventory-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--rarity-common);
  border-radius: var(--radius);
  padding: 16px;
  text-align: center;
}

.inventory-card__image {
  width: 72px;
  height: 72px;
  object-fit: contain;
  margin: 0 auto 10px;
}

.inventory-card__name {
  font-size: 13px;
  font-weight: 600;
  margin: 0 0 4px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.inventory-card__price {
  font-size: 13px;
  color: var(--accent);
  font-weight: 600;
  margin: 0 0 12px;
}

.inventory-card__actions {
  display: flex;
  justify-content: center;
  gap: 6px;
}

.inv-action {
  background: var(--surface-hi);
  border: 1px solid var(--border);
  color: var(--text-dim);
  border-radius: 8px;
  width: 34px;
  height: 34px;
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: border-color 0.15s, color 0.15s;
}

.inv-action:hover {
  border-color: var(--accent-dim);
  color: var(--text);
}

/* ---------- Toast (уведомление о демо-режиме) ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translateX(-50%) translateY(20px);
  background: var(--surface-hi);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 12px 20px;
  border-radius: 10px;
  font-size: 14px;
  max-width: 90vw;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 300;
  box-shadow: 0 12px 24px rgba(0,0,0,0.35);
}

.user-profile__menu-toggle {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 12px;
  cursor: pointer;
  padding: 4px;
}

.toast--visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ---------- Апгрейдер ---------- */

.upgrade-layout {
  display: grid;
  grid-template-columns: 1fr 260px 1fr;
  gap: 24px;
  align-items: start;
}

.upgrade-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
}

.upgrade-panel__title {
  font-size: 13px;
  color: var(--text-dim);
  margin: 0 0 14px;
}

.upgrade-panel__grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(90px, 1fr));
  gap: 10px;
  max-height: 420px;
  overflow-y: auto;
}

.upgrade-item {
  background: var(--surface-hi);
  border: 2px solid var(--border);
  border-radius: 8px;
  padding: 8px;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.15s, transform 0.15s;
}

.upgrade-item:hover { transform: translateY(-2px); }

.upgrade-item--selected {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent);
}

.upgrade-item__image {
  width: 100%;
  height: 48px;
  object-fit: contain;
  margin-bottom: 6px;
}

.upgrade-item__price {
  font-size: 11px;
  font-weight: 600;
  margin: 0;
}

.upgrade-center {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  padding-top: 20px;
}

.upgrade-wheel {
  --chance: 0deg;
  width: 160px;
  height: 160px;
  border-radius: 50%;
  background: conic-gradient(var(--accent) var(--chance), var(--surface-hi) var(--chance));
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}

.upgrade-wheel::before {
  content: '';
  position: absolute;
  inset: 10px;
  border-radius: 50%;
  background: var(--bg);
}

.upgrade-wheel__chance {
  position: relative;
  z-index: 1;
  font-family: var(--font-display);
  font-size: 24px;
  font-weight: 700;
}

.upgrade-center__values {
  color: var(--text-dim);
  font-size: 14px;
  margin: 0;
}

.upgrade-center .btn-open { width: 200px; }

@media (max-width: 900px) {
  .upgrade-layout { grid-template-columns: 1fr; }
}

/* ---------- Win / Lose overlay ---------- */

.win-overlay--lose .win-card__name,
.win-overlay--lose .win-card__eyebrow {
  color: var(--text-dim);
}

.win-overlay--lose .win-card__price { display: none; }

.win-overlay--lose .win-card__image {
  filter: grayscale(1) brightness(0.6);
}


/* ---------- Upgrade dial / animation ---------- */

.upgrade-center {
  min-height: 100%;
}

.upgrade-wheel {
  isolation: isolate;
  box-shadow: 0 0 0 1px rgba(255,255,255,0.04), 0 18px 45px rgba(0,0,0,0.35);
  background: conic-gradient(
    from -90deg,
    var(--accent) 0deg var(--chance),
    var(--surface-hi) var(--chance) 360deg
  );
  transition: filter 0.2s ease, transform 0.2s ease;
}

.upgrade-wheel__ring {
  position: absolute;
  inset: 5px;
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 50%;
  z-index: 2;
  pointer-events: none;
}

.upgrade-needle {
  --needle-angle: 0deg;
  position: absolute;
  left: 50%;
  top: 50%;
  width: 4px;
  height: 66px;
  border-radius: 999px;
  background: var(--text);
  transform-origin: 50% 100%;
  transform: translate(-50%, -100%) rotate(var(--needle-angle));
  z-index: 4;
  box-shadow: 0 0 12px rgba(255,255,255,0.45);
  transition: transform 0.2s ease-out;
}

.upgrade-needle::before {
  content: '';
  position: absolute;
  top: -7px;
  left: 50%;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  transform: translateX(-50%);
  background: var(--text);
  box-shadow: 0 0 0 4px var(--surface), 0 0 14px rgba(255,255,255,0.3);
}

.upgrade-needle::after {
  content: '';
  position: absolute;
  top: -13px;
  left: 50%;
  transform: translateX(-50%);
  width: 0;
  height: 0;
  border-left: 6px solid transparent;
  border-right: 6px solid transparent;
  border-bottom: 10px solid var(--text);
}

.upgrade-wheel--spinning {
  animation: upgradeWheelPulse 0.8s ease-in-out infinite alternate;
  filter: brightness(1.08);
}

.upgrade-needle--spinning {
  transition: transform 4.2s cubic-bezier(0.12, 0.78, 0.08, 1);
}

@keyframes upgradeWheelPulse {
  from { box-shadow: 0 0 0 1px rgba(255,255,255,0.04), 0 12px 30px rgba(0,0,0,0.25); }
  to { box-shadow: 0 0 0 1px rgba(124,92,255,0.22), 0 0 36px rgba(124,92,255,0.24); }
}

.upgrade-center__values {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
}

.upgrade-value {
  min-width: 82px;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: var(--surface);
  text-align: center;
}

.upgrade-arrow {
  color: var(--accent);
  font-size: 22px;
  font-weight: 700;
}

.upgrade-center__min {
  margin: -7px 0 0;
  color: var(--text-dim);
  font-size: 11px;
  text-align: center;
}

.upgrade-center__min b {
  color: var(--text);
}

.upgrade-item--blocked {
  opacity: 0.32;
  filter: grayscale(0.75);
  cursor: not-allowed;
  transform: none !important;
  position: relative;
}

.upgrade-item--blocked::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: 7px;
  background: repeating-linear-gradient(
    -45deg,
    transparent 0 8px,
    rgba(255,255,255,0.035) 8px 10px
  );
}

.upgrade-item__lock {
  display: block;
  margin-top: 3px;
  font-size: 8px;
  color: var(--text-dim);
  white-space: nowrap;
}

.upgrade-panel__grid::-webkit-scrollbar {
  width: 7px;
}

.upgrade-panel__grid::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 99px;
}

/* ---------- Slower, more pronounced case opening ---------- */

.reel-viewport {
  box-shadow: inset 0 0 35px rgba(0,0,0,0.3);
}

.reel-track {
  transform: translate3d(0,0,0);
}

.reel-item {
  box-shadow: inset 0 0 0 1px rgba(255,255,255,0.02);
}

.reel-pointer {
  width: 3px;
  box-shadow: 0 0 18px var(--accent), 0 0 4px var(--accent);
}

@media (max-width: 900px) {
  .upgrade-center {
    order: -1;
  }
}

@media (prefers-reduced-motion: reduce) {
  .upgrade-wheel--spinning,
  .upgrade-needle--spinning {
    animation: none;
    transition-duration: 0.1s;
  }
}
