:root {
  --bg: #070504;
  --panel: rgba(18, 12, 10, 0.72);
  --gold: #e8c36a;
  --gold-deep: #9a7428;
  --gold-soft: rgba(232, 195, 106, 0.16);
  --crimson: #c4281c;
  --crimson-glow: rgba(196, 40, 28, 0.45);
  --cream: #f4e7c8;
  --muted: #9b8b74;
  --line: rgba(232, 195, 106, 0.22);
  --str: #e05a3a;
  --agi: #5ec46a;
  --int: #5aa8e8;
  --all: #c07be8;
  --shadow: 0 30px 80px rgba(0, 0, 0, 0.55);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--cream);
  font-family: Manrope, "Segoe UI", sans-serif;
}

body {
  overflow-x: hidden;
}

.bg-glow,
#embers,
.vignette,
.noise {
  position: fixed;
  inset: 0;
  pointer-events: none;
}

.bg-glow {
  background:
    radial-gradient(900px 520px at 50% -10%, rgba(196, 40, 28, 0.28), transparent 55%),
    radial-gradient(700px 420px at 10% 90%, rgba(154, 116, 40, 0.16), transparent 50%),
    radial-gradient(640px 380px at 90% 80%, rgba(196, 40, 28, 0.12), transparent 50%),
    linear-gradient(180deg, #120a08 0%, #070504 42%, #0b0605 100%);
  z-index: 0;
}

#embers {
  z-index: 1;
}

.vignette {
  z-index: 2;
  background: radial-gradient(ellipse at center, transparent 40%, rgba(0, 0, 0, 0.62) 100%);
}

.noise {
  z-index: 3;
  opacity: 0.07;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

.frame {
  position: relative;
  z-index: 4;
  width: min(1240px, calc(100% - 32px));
  margin: 0 auto;
  padding: 36px 0 48px;
}

.hero-head {
  text-align: center;
  margin-bottom: 28px;
}

.hero-head h1 {
  margin: 0;
  font-family: Cinzel, serif;
  font-weight: 900;
  font-size: clamp(42px, 7vw, 84px);
  line-height: 0.95;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  background: linear-gradient(180deg, #fff4d2 0%, #e8c36a 46%, #8d5c1d 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 10px 24px rgba(196, 40, 28, 0.28));
}

.stats {
  margin-bottom: 32px;
}

.stats-board {
  display: grid;
  grid-template-columns: minmax(220px, 1.1fr) 2fr;
  gap: 18px;
  padding: 18px 20px;
  border: 1px solid var(--line);
  background: var(--panel);
  box-shadow: var(--shadow);
}

.stats-identity {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
}

.stats-avatar {
  width: 56px;
  height: 56px;
  flex: 0 0 56px;
  border: 1px solid var(--line);
  background: #140e0b center/cover no-repeat;
}

.stats-name {
  margin: 0;
  font-family: Cinzel, serif;
  font-size: 22px;
  line-height: 1.15;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.stats-rank {
  margin: 4px 0 0;
  color: var(--gold);
  font-size: 14px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.stats-metrics {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
}

.stat {
  display: grid;
  gap: 4px;
  align-content: center;
  padding: 8px 10px;
  border: 1px solid rgba(232, 195, 106, 0.12);
  background: rgba(0, 0, 0, 0.22);
}

.stat-value {
  font-family: Unbounded, sans-serif;
  font-size: clamp(22px, 2.4vw, 32px);
  font-weight: 700;
  line-height: 1;
}

.stat-value.win {
  color: #7dce86;
}

.stat-value.lose {
  color: #e07a70;
}

.stat-label {
  color: var(--muted);
  font-size: 11px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.recent-matches {
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 10px 0 0;
  padding: 0;
  min-height: 28px;
}

.recent-matches:empty {
  display: none;
}

.match-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px;
  border: 1px solid var(--line);
  background: rgba(0, 0, 0, 0.28);
  font-size: 12px;
}

.match-pill.win {
  border-color: rgba(125, 206, 134, 0.35);
}

.match-pill.lose {
  border-color: rgba(224, 122, 112, 0.35);
}

.match-pill b {
  font-size: 11px;
  letter-spacing: 0.08em;
}

.match-pill.win b {
  color: #7dce86;
}

.match-pill.lose b {
  color: #e07a70;
}

.controls {
  display: grid;
  justify-items: center;
  gap: 22px;
  margin-bottom: 34px;
}

.toggles {
  width: 100%;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
}

.toggle input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.toggle-card {
  position: relative;
  display: grid;
  gap: 4px;
  padding: 18px 18px 16px 52px;
  border: 1px solid var(--line);
  background: var(--panel);
  box-shadow: var(--shadow);
  cursor: pointer;
  overflow: hidden;
  transition: transform 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
}

.toggle-card::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 3px;
  background: var(--gold-deep);
}

.toggle-card:hover {
  transform: translateY(-2px);
  border-color: rgba(232, 195, 106, 0.5);
}

.toggle-mark {
  position: absolute;
  left: 16px;
  top: 22px;
  width: 22px;
  height: 22px;
  border: 1px solid var(--gold);
  background: rgba(0, 0, 0, 0.35);
}

.toggle-mark::after {
  content: "";
  position: absolute;
  inset: 4px;
  background: var(--gold);
  transform: scale(0);
  transition: transform 0.18s ease;
}

.toggle input:checked + .toggle-card .toggle-mark::after {
  transform: scale(1);
}

.toggle input:checked + .toggle-card {
  border-color: rgba(232, 195, 106, 0.55);
  box-shadow: 0 0 0 1px rgba(232, 195, 106, 0.12), 0 18px 40px rgba(196, 40, 28, 0.12);
}

.toggle input:checked + .toggle-card::before {
  background: linear-gradient(180deg, var(--gold), var(--crimson));
}

.toggle-kicker {
  font-size: 11px;
  letter-spacing: 0.22em;
  color: var(--gold-deep);
}

.toggle-title {
  font-family: Unbounded, sans-serif;
  font-size: 20px;
  font-weight: 700;
}

.toggle-sub {
  color: var(--muted);
  font-size: 13px;
}

.random-btn {
  position: relative;
  isolation: isolate;
  min-width: 280px;
  padding: 18px 46px 16px;
  border: 1px solid #f0d48a;
  background: linear-gradient(180deg, #f3d78a 0%, #c8962d 48%, #8a5a14 100%);
  color: #2a1606;
  font-family: Unbounded, sans-serif;
  font-size: 28px;
  font-weight: 800;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  cursor: pointer;
  box-shadow:
    0 0 0 1px #5a3a10,
    0 10px 0 #5a320c,
    0 18px 40px rgba(196, 40, 28, 0.28);
  transition: transform 0.12s ease, filter 0.12s ease;
}

.random-btn-glow {
  position: absolute;
  inset: -20px;
  z-index: -1;
  background: radial-gradient(circle, rgba(232, 195, 106, 0.35), transparent 65%);
  animation: pulse 2.4s ease-in-out infinite;
}

.random-btn-label {
  display: block;
}

.random-btn-hint {
  display: block;
  margin-top: 2px;
  font-family: Manrope, sans-serif;
  font-size: 11px;
  letter-spacing: 0.28em;
  opacity: 0.7;
}

.random-btn:hover {
  filter: brightness(1.06);
  transform: translateY(-1px);
}

.random-btn:active {
  transform: translateY(6px);
  box-shadow: 0 0 0 1px #5a3a10, 0 4px 0 #5a320c;
}

.random-btn:disabled {
  cursor: wait;
  filter: saturate(0.7);
}

.random-btn.shake {
  animation: shake 0.38s ease;
}

.hint {
  margin: 0;
  color: #f0b4a8;
  font-size: 14px;
}

.results {
  display: grid;
  grid-template-columns: 1.05fr 1.15fr 0.95fr;
  gap: 16px;
  min-height: 360px;
}

.result-card {
  position: relative;
  min-height: 360px;
  padding: 16px;
  background:
    linear-gradient(180deg, rgba(42, 24, 16, 0.35), rgba(10, 7, 5, 0.72)),
    var(--panel);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.result-card.off {
  opacity: 0.42;
  filter: grayscale(0.4);
}

.card-ornament {
  position: absolute;
  inset: 8px;
  border: 1px solid rgba(232, 195, 106, 0.12);
  pointer-events: none;
}

.card-ornament::before,
.card-ornament::after {
  content: "";
  position: absolute;
  width: 18px;
  height: 18px;
  border: 1px solid var(--gold);
}

.card-ornament::before {
  top: -1px;
  left: -1px;
  border-right: 0;
  border-bottom: 0;
}

.card-ornament::after {
  right: -1px;
  bottom: -1px;
  border-left: 0;
  border-top: 0;
}

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 12px;
  padding: 0 6px;
  font-family: Cinzel, serif;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  font-size: 12px;
  color: var(--gold);
}

.card-head-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.mode-switch {
  display: flex;
  border: 1px solid var(--line);
  background: rgba(0, 0, 0, 0.25);
}

.mode-btn {
  padding: 6px 8px;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-family: Manrope, sans-serif;
  font-size: 10px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  cursor: pointer;
  white-space: nowrap;
}

.mode-btn.is-on {
  color: #2a1606;
  background: linear-gradient(180deg, #f3d78a 0%, #c8962d 100%);
}

.mode-btn:hover:not(.is-on) {
  color: var(--gold);
}

.reroll {
  width: 32px;
  height: 32px;
  border: 1px solid var(--line);
  background: rgba(0, 0, 0, 0.25);
  color: var(--gold);
  cursor: pointer;
  font-size: 16px;
}

.reroll:hover {
  border-color: var(--gold);
}

.card-body {
  height: calc(100% - 36px);
}

.placeholder {
  height: 100%;
  display: grid;
  place-content: center;
  text-align: center;
  color: var(--muted);
}

.placeholder span {
  font-family: Cinzel, serif;
  font-size: 64px;
  color: rgba(232, 195, 106, 0.22);
  line-height: 1;
}

.hero-view {
  display: grid;
  align-content: start;
  gap: 12px;
}

.hero-art {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 256 / 144;
  object-fit: contain;
  object-position: center;
  background: #140e0b;
}

.hero-meta {
  padding: 0 6px 2px;
}

.hero-view.spinning {
  filter: blur(2px) saturate(1.2);
}

.attr {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.attr i {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--dot);
  box-shadow: 0 0 10px var(--dot);
}

.hero-view h2,
.build-view h2,
.challenge-view h2 {
  margin: 0 0 6px;
  font-family: Cinzel, serif;
  font-size: clamp(24px, 2.4vw, 34px);
  line-height: 1.05;
}

.challenge-view p {
  margin: 0;
  line-height: 1.5;
  font-size: 18px;
  color: #d8cbb0;
}

.build-view,
.challenge-view {
  height: 100%;
  display: grid;
  align-content: start;
  gap: 14px;
  padding: 8px 6px;
}

.tag,
.tier {
  display: inline-block;
  padding: 3px 8px;
  border: 1px solid var(--line);
  color: var(--gold);
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.tier[data-tier="тяжёлое"],
.tier[data-tier="хаос"] {
  color: #ffb4a8;
  border-color: rgba(196, 40, 28, 0.45);
}

.items-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.item {
  aspect-ratio: 1;
  border: 1px solid rgba(232, 195, 106, 0.2);
  background: #140e0b center/cover no-repeat;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.4);
  position: relative;
}

.item span {
  position: absolute;
  right: 0;
  bottom: 0;
  left: 0;
  padding: 4px 5px 3px;
  background: linear-gradient(180deg, transparent, rgba(0, 0, 0, 0.82));
  font-size: 10px;
  line-height: 1.2;
  color: var(--cream);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history-wrap {
  margin-top: 28px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}

.history-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  color: var(--muted);
  font-size: 12px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.history {
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 12px 0 0;
  padding: 0;
}

.history:empty::after {
  content: "Пока пусто — сделай первый бросок";
  color: var(--muted);
  letter-spacing: 0;
  text-transform: none;
}

.history li {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px 6px 6px;
  border: 1px solid var(--line);
  background: rgba(0, 0, 0, 0.25);
  font-size: 13px;
}

.history img {
  width: 36px;
  height: 20px;
  object-fit: cover;
}

.text-btn {
  border: 0;
  background: none;
  color: var(--gold);
  cursor: pointer;
  font: inherit;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.flash {
  animation: flash 0.55s ease;
}

@keyframes pulse {
  0%,
  100% {
    opacity: 0.45;
    transform: scale(0.96);
  }
  50% {
    opacity: 1;
    transform: scale(1.05);
  }
}

@keyframes shake {
  0%,
  100% {
    transform: translateX(0);
  }
  25% {
    transform: translateX(-8px);
  }
  75% {
    transform: translateX(8px);
  }
}

@keyframes flash {
  0% {
    box-shadow: 0 0 0 1px var(--gold), 0 0 40px var(--crimson-glow);
  }
  100% {
    box-shadow: var(--shadow);
  }
}

@media (max-width: 980px) {
  .toggles,
  .results,
  .stats-board {
    grid-template-columns: 1fr;
  }

  .stats-metrics {
    grid-template-columns: repeat(2, 1fr);
  }

  .result-card,
  .hero-view {
    min-height: 280px;
  }
}

@media (max-width: 640px) {
  .hero-head h1 {
    font-size: 36px;
  }

  .random-btn {
    width: 100%;
    min-width: 0;
    font-size: 22px;
  }

  .mode-btn {
    padding: 6px 6px;
    font-size: 9px;
  }
}
