:root {
  color-scheme: dark;
  --ink: #f5efe1;
  --muted: #b9b0a3;
  --panel: #17130f;
  --panel-2: #221b14;
  --wood: #5e3520;
  --gold: #d9a441;
  --red: #c54035;
  --cyan: #4fc3bf;
  --line: rgba(255, 255, 255, 0.14);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(180deg, rgba(0, 0, 0, 0.2), rgba(0, 0, 0, 0.72)),
    radial-gradient(circle at 50% 10%, #624126 0, #17100b 45%, #070605 100%);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
select {
  font: inherit;
}

.shell {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 330px;
  gap: 16px;
  min-height: 100vh;
  padding: 16px;
}

.arena-wrap {
  position: relative;
  min-width: 0;
  border: 1px solid var(--line);
  background: #0b0806;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.38);
}

canvas {
  display: block;
  width: 100%;
  height: calc(100vh - 34px);
  min-height: 520px;
  background: #1c120d;
}

.hud {
  position: absolute;
  inset: 12px 12px auto 12px;
  z-index: 2;
  display: grid;
  grid-template-columns: minmax(250px, 1fr) 118px minmax(250px, 1fr);
  gap: 12px;
  pointer-events: none;
}

.fighter-card,
.round-panel,
.panel {
  border: 1px solid var(--line);
  background: rgba(18, 13, 10, 0.84);
  backdrop-filter: blur(10px);
}

.fighter-card {
  position: relative;
  overflow: hidden;
  padding: 8px 10px 10px;
  box-shadow: inset 0 0 0 1px rgba(217, 164, 65, 0.12), 0 10px 24px rgba(0, 0, 0, 0.34);
}

.fighter-card::before {
  content: "";
  position: absolute;
  inset: 0;
  background:
    linear-gradient(90deg, rgba(217, 164, 65, 0.18), transparent 38%),
    repeating-linear-gradient(135deg, rgba(255, 255, 255, 0.055) 0 1px, transparent 1px 8px);
  pointer-events: none;
}

.fighter-card.right {
  text-align: right;
}

.fighter-card.right::before {
  background:
    linear-gradient(270deg, rgba(79, 195, 191, 0.18), transparent 38%),
    repeating-linear-gradient(45deg, rgba(255, 255, 255, 0.055) 0 1px, transparent 1px 8px);
}

.hud-top {
  position: relative;
  display: grid;
  grid-template-columns: 58px minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  margin-bottom: 7px;
}

.right .hud-top {
  grid-template-columns: minmax(0, 1fr) 58px;
}

.portrait {
  display: grid;
  place-items: center;
  width: 58px;
  height: 58px;
  border: 2px solid rgba(217, 164, 65, 0.78);
  background:
    radial-gradient(circle at 50% 58%, rgba(217, 164, 65, 0.28), transparent 58%),
    #120c09;
  box-shadow: inset 0 0 18px rgba(0, 0, 0, 0.66);
}

.right .portrait {
  border-color: rgba(79, 195, 191, 0.78);
}

.portrait img {
  display: block;
  width: 48px;
  height: 48px;
  object-fit: contain;
  image-rendering: pixelated;
}

.nameplate {
  min-width: 0;
}

.player-tag {
  display: inline-grid;
  place-items: center;
  min-width: 34px;
  height: 18px;
  margin-bottom: 4px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  color: #110b08;
  background: var(--gold);
  font-size: 11px;
  font-weight: 950;
}

.right .player-tag {
  color: #061614;
  background: var(--cyan);
}

.fighter-name {
  height: 24px;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  color: #fff9ea;
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.7);
  font-size: 17px;
  font-weight: 950;
  letter-spacing: 0;
}

.meter-row {
  position: relative;
  display: grid;
  grid-template-columns: 48px minmax(0, 1fr) 34px;
  align-items: center;
  gap: 8px;
  margin-top: 5px;
}

.right .meter-row {
  grid-template-columns: 34px minmax(0, 1fr) 48px;
}

.meter-row span,
.meter-row b {
  color: #e8d8b9;
  font-size: 11px;
  font-weight: 900;
}

.meter-row b {
  color: #fff4d2;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.bar {
  position: relative;
  height: 15px;
  margin-top: 0;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.24);
  background:
    repeating-linear-gradient(90deg, rgba(255, 255, 255, 0.08) 0 10px, transparent 10px 13px),
    rgba(0, 0, 0, 0.48);
  box-shadow: inset 0 1px 5px rgba(0, 0, 0, 0.72);
}

.bar span {
  display: block;
  width: 100%;
  height: 100%;
  transform-origin: left center;
}

.right .bar span {
  transform-origin: right center;
  margin-left: auto;
}

.health span {
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.38), transparent 42%),
    linear-gradient(90deg, #b81624, #f24c3d 48%, #ffd166);
  box-shadow: 0 0 12px rgba(242, 76, 61, 0.68);
}

.energy span {
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.44), transparent 46%),
    linear-gradient(90deg, #1667ff, #35d6ff 52%, #adfff1);
  box-shadow: 0 0 12px rgba(53, 214, 255, 0.62);
}

.round-panel {
  display: grid;
  grid-template-columns: 1fr 34px;
  align-items: center;
  min-width: 0;
  padding: 8px;
  gap: 6px;
  text-align: center;
  font-weight: 900;
  box-shadow: inset 0 0 0 1px rgba(217, 164, 65, 0.14), 0 10px 24px rgba(0, 0, 0, 0.3);
}

#restartBtn {
  width: 34px;
  height: 34px;
  border: 1px solid var(--line);
  color: var(--ink);
  background: rgba(255, 255, 255, 0.08);
  cursor: pointer;
  pointer-events: auto;
}

.panel {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 14px;
  min-width: 0;
}

.mode-row {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}

.mode,
.music-toggle,
.wallet-button,
.selectors select {
  width: 100%;
  border: 1px solid var(--line);
  color: var(--ink);
  background: var(--panel-2);
}

.mode {
  height: 38px;
  cursor: pointer;
}

.music-toggle {
  min-height: 38px;
  cursor: pointer;
}

.wallet-panel {
  display: grid;
  gap: 8px;
}

.wallet-button {
  min-height: 40px;
  cursor: pointer;
  border-color: rgba(217, 164, 65, 0.55);
}

.wallet-button.connected {
  border-color: rgba(79, 195, 191, 0.82);
  background: #12312e;
}

.wallet-status {
  min-height: 34px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.mode.active {
  border-color: rgba(217, 164, 65, 0.78);
  background: #3a2817;
}

.music-toggle.active {
  border-color: rgba(79, 195, 191, 0.82);
  background: #14312e;
}

.selectors {
  display: grid;
  gap: 10px;
}

label {
  display: block;
  margin-bottom: 5px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

select {
  min-height: 38px;
  padding: 0 10px;
}

.stats-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
  overflow: auto;
}

.stat-card {
  min-height: 142px;
  padding: 10px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.04);
}

.stat-title {
  margin-bottom: 8px;
  font-weight: 900;
}

.stat-line {
  display: grid;
  grid-template-columns: 82px 1fr 24px;
  align-items: center;
  gap: 8px;
  margin: 6px 0;
  font-size: 12px;
}

.stat-meter {
  height: 7px;
  background: rgba(0, 0, 0, 0.38);
}

.stat-meter span {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, var(--gold), var(--cyan));
}

.trait-list {
  margin-top: 8px;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.45;
}

.controls {
  margin-top: auto;
  display: grid;
  gap: 8px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.leaderboard-panel {
  display: grid;
  gap: 8px;
  padding: 10px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.035);
}

.panel-title {
  color: #fff4d2;
  font-size: 12px;
  font-weight: 950;
}

.leaderboard-list {
  display: grid;
  gap: 6px;
  max-height: 138px;
  overflow: auto;
}

.leader-row {
  display: grid;
  grid-template-columns: 22px minmax(0, 1fr) 44px;
  gap: 8px;
  align-items: center;
  color: var(--muted);
  font-size: 11px;
}

.leader-row b {
  color: var(--ink);
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

@media (max-width: 980px) {
  .shell {
    grid-template-columns: 1fr;
    padding: 10px;
  }

  canvas {
    height: 62vh;
    min-height: 420px;
  }

  .hud {
    grid-template-columns: minmax(0, 1fr) 88px minmax(0, 1fr);
    gap: 8px;
  }

  .fighter-card {
    padding: 7px;
  }

  .hud-top {
    grid-template-columns: 42px minmax(0, 1fr);
    gap: 6px;
  }

  .right .hud-top {
    grid-template-columns: minmax(0, 1fr) 42px;
  }

  .portrait {
    width: 42px;
    height: 42px;
  }

  .portrait img {
    width: 34px;
    height: 34px;
  }

  .fighter-name {
    height: 20px;
    font-size: 13px;
  }

  .player-tag {
    min-width: 28px;
    height: 16px;
    font-size: 10px;
  }

  .meter-row {
    grid-template-columns: 34px minmax(0, 1fr) 28px;
    gap: 5px;
  }

  .right .meter-row {
    grid-template-columns: 28px minmax(0, 1fr) 34px;
  }

  .meter-row span,
  .meter-row b {
    font-size: 9px;
  }

  .panel {
    min-height: auto;
  }
}
