:root {
  --ink: #f6edd2;
  --muted: #c9b98e;
  --panel: rgba(28, 23, 23, 0.92);
  --panel-solid: #211b1c;
  --panel-soft: rgba(52, 42, 39, 0.9);
  --edge: #80633f;
  --edge-soft: #5e4936;
  --gold: #e7b64e;
  --red: #cf4d3d;
  --green: #70bd62;
  --blue: #5fa8d8;
  --violet: #a47be6;
  --orange: #dc8448;
  --shadow: rgba(0, 0, 0, 0.42);
  color-scheme: dark;
  font-family:
    "Trebuchet MS", "Microsoft YaHei", "PingFang SC", "Noto Sans SC", Arial,
    sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  background: #151414;
  color: var(--ink);
  overflow: hidden;
}

button {
  border: 0;
  color: inherit;
  font: inherit;
}

#game-shell {
  position: relative;
  width: 100vw;
  height: 100vh;
  min-height: 680px;
  isolation: isolate;
}

#phaser-root,
#phaser-root canvas {
  display: block;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
}

.screen {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: none;
  padding: 22px;
  background:
    linear-gradient(180deg, rgba(15, 17, 18, 0.62), rgba(14, 13, 13, 0.9)),
    radial-gradient(circle at 20% 18%, rgba(131, 91, 49, 0.22), transparent 36%),
    rgba(19, 18, 18, 0.82);
}

.screen.is-active {
  display: block;
}

.screen-lobby {
  overflow: auto;
}

.lobby-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  max-width: 1240px;
  margin: 0 auto 18px;
}

h1,
h2,
h3 {
  margin: 0;
  line-height: 1.08;
}

h1 {
  font-size: clamp(34px, 6vw, 72px);
}

h2 {
  font-size: 22px;
}

.eyebrow {
  color: var(--muted);
  font-size: 12px;
}

.lobby-grid {
  display: grid;
  grid-template-columns: minmax(260px, 0.95fr) minmax(360px, 1.25fr) minmax(330px, 1fr);
  gap: 14px;
  max-width: 1240px;
  margin: 0 auto;
}

.panel,
.result-panel {
  border: 2px solid var(--edge);
  border-radius: 6px;
  background: var(--panel);
  box-shadow: 0 18px 40px var(--shadow);
}

.panel {
  padding: 14px;
}

.panel-head,
.hero-row,
.resource-strip,
.item-name,
.talent-head,
.result-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.class-tabs {
  display: grid;
  grid-template-columns: 1fr;
  gap: 6px;
  margin-bottom: 14px;
}

.class-tab {
  min-height: 38px;
  border: 1px solid var(--edge-soft);
  border-radius: 4px;
  background: #251f20;
  color: var(--muted);
  cursor: pointer;
}

.class-tab.active {
  border-color: var(--gold);
  background: #3b2b22;
  color: var(--ink);
}

.portrait {
  display: grid;
  width: 56px;
  height: 56px;
  place-items: center;
  border: 2px solid #a77a43;
  background: #342728;
  color: var(--gold);
  font-size: 24px;
  font-weight: 900;
}

.hero-row {
  justify-content: flex-start;
  margin-bottom: 14px;
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}

.stat-box,
.resource-strip,
.run-chip,
.talent-card,
.item-card,
.equipment-slot {
  border: 1px solid var(--edge-soft);
  border-radius: 4px;
  background: var(--panel-soft);
}

.stat-box {
  padding: 10px;
}

.stat-box span,
.run-chip span,
.talent-desc,
.slot-name,
.item-stats {
  color: var(--muted);
  font-size: 12px;
}

.stat-box strong {
  display: block;
  margin-top: 4px;
  font-size: 20px;
}

.resource-strip {
  margin-top: 12px;
  padding: 10px 12px;
}

.resource-strip strong {
  color: var(--gold);
  font-size: 22px;
}

.start-button,
.secondary-button,
.buy-button,
.icon-button {
  border: 2px solid #966d3d;
  border-radius: 5px;
  background: #8d3e32;
  color: var(--ink);
  cursor: pointer;
  font-weight: 900;
  box-shadow: inset 0 -4px rgba(0, 0, 0, 0.22);
}

.start-button {
  min-width: 150px;
  min-height: 58px;
  padding: 0 24px;
  font-size: 22px;
}

.secondary-button {
  min-height: 48px;
  padding: 0 18px;
  background: #2c2524;
  color: var(--gold);
}

.buy-button {
  min-width: 86px;
  min-height: 38px;
  padding: 0 10px;
  background: #493022;
  color: var(--gold);
}

.buy-button:disabled {
  border-color: #51443b;
  background: #282424;
  color: #81735f;
  cursor: not-allowed;
}

.icon-button {
  display: grid;
  width: 36px;
  height: 36px;
  place-items: center;
  background: #2a2323;
  color: var(--gold);
}

.divider {
  height: 1px;
  margin: 12px 0;
  background: linear-gradient(90deg, transparent, var(--edge), transparent);
}

.equipment-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(72px, 1fr));
  gap: 7px;
  margin-top: 12px;
}

.equipment-slot,
.item-card,
.talent-card {
  padding: 10px;
}

.equipment-slot {
  min-height: 76px;
  aspect-ratio: 1 / 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 2px;
  min-width: 0;
  overflow: hidden;
  text-align: center;
}

.equipment-slot.is-equipped {
  position: relative;
  align-items: center;
  padding: 6px;
  border-width: 2px;
  box-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, 0.08),
    inset 0 -10px rgba(0, 0, 0, 0.18);
}

.equipment-slot.is-equipped::before {
  content: "";
  position: absolute;
  inset: 4px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  pointer-events: none;
}

.equipment-slot.is-equipped.worn {
  border-color: #8e877c;
  background:
    linear-gradient(180deg, rgba(142, 135, 124, 0.18), rgba(46, 43, 39, 0.34)),
    #2b2926;
}

.equipment-slot.is-equipped.common {
  border-color: #b9b1a2;
  background:
    linear-gradient(180deg, rgba(241, 241, 230, 0.22), rgba(77, 73, 67, 0.32)),
    #302c28;
}

.equipment-slot.is-equipped.fine {
  border-color: #67c56f;
  background:
    radial-gradient(circle at 50% 28%, rgba(117, 216, 126, 0.3), transparent 56%),
    linear-gradient(180deg, rgba(54, 132, 63, 0.5), rgba(22, 70, 38, 0.86)),
    #173824;
  box-shadow:
    inset 0 0 0 1px rgba(218, 255, 221, 0.14),
    inset 0 -10px rgba(0, 0, 0, 0.22),
    0 0 0 1px rgba(103, 197, 111, 0.22);
}

.equipment-slot.is-equipped.rare {
  border-color: #55a8e8;
  background:
    radial-gradient(circle at 50% 28%, rgba(120, 198, 255, 0.34), transparent 56%),
    linear-gradient(180deg, rgba(49, 123, 185, 0.52), rgba(19, 48, 79, 0.86)),
    #152d47;
  box-shadow:
    inset 0 0 0 1px rgba(210, 239, 255, 0.16),
    inset 0 -10px rgba(0, 0, 0, 0.22),
    0 0 0 1px rgba(85, 168, 232, 0.22);
}

.equipment-slot.is-equipped.epic {
  border-color: #a855ff;
  background:
    radial-gradient(circle at 50% 26%, rgba(201, 116, 255, 0.36), transparent 58%),
    linear-gradient(180deg, rgba(98, 45, 151, 0.68), rgba(37, 22, 72, 0.9)),
    #2a1948;
  box-shadow:
    inset 0 0 0 1px rgba(234, 205, 255, 0.18),
    inset 0 -10px rgba(0, 0, 0, 0.22),
    0 0 0 1px rgba(168, 85, 255, 0.3);
}

.equipment-slot.is-equipped.legendary {
  border-color: #f28c28;
  background:
    radial-gradient(circle at 50% 24%, rgba(255, 181, 84, 0.42), transparent 58%),
    linear-gradient(180deg, rgba(170, 79, 22, 0.72), rgba(71, 35, 18, 0.9)),
    #3d2013;
  box-shadow:
    inset 0 0 0 1px rgba(255, 222, 166, 0.2),
    inset 0 -10px rgba(0, 0, 0, 0.22),
    0 0 0 1px rgba(242, 140, 40, 0.34);
}

.equipment-slot.is-equipped.mythic {
  border-color: #e34b4b;
  background:
    radial-gradient(circle at 50% 24%, rgba(255, 100, 100, 0.34), transparent 58%),
    linear-gradient(180deg, rgba(123, 35, 52, 0.74), rgba(50, 18, 31, 0.92)),
    #2c1420;
  box-shadow:
    inset 0 0 0 1px rgba(255, 206, 206, 0.18),
    inset 0 -10px rgba(0, 0, 0, 0.24),
    0 0 0 1px rgba(227, 75, 75, 0.34);
}

.equipment-slot.is-empty {
  justify-content: center;
  gap: 5px;
  background:
    linear-gradient(180deg, rgba(255, 215, 106, 0.03), rgba(0, 0, 0, 0)),
    var(--panel-soft);
}

.equipment-slot.is-empty .slot-name {
  color: #d9c18d;
}

.equipment-slot.is-empty .slot-item {
  color: #7d6d59 !important;
}

.equipment-slot.is-empty .slot-power {
  color: #a89062;
}

.slot-name {
  width: 100%;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.slot-item {
  width: 100%;
  min-width: 0;
  margin-top: 2px;
  font-size: 12px;
  font-weight: 900;
  line-height: 1.12;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.slot-icon {
  display: grid;
  flex: 0 0 auto;
  width: 24px;
  height: 24px;
  place-items: center;
  margin: 0 auto 1px;
  border: 1px solid #8a6840;
  background: #171313;
  color: var(--gold);
  font-size: 13px;
  font-weight: 900;
}

.equipment-slot.is-equipped .slot-icon {
  width: 48px;
  height: 48px;
  margin: 0;
  border: 0;
  background:
    radial-gradient(circle at 50% 42%, rgba(255, 255, 255, 0.14), transparent 64%),
    rgba(0, 0, 0, 0.18);
  box-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, 0.16),
    0 2px 0 rgba(0, 0, 0, 0.24);
}

.slot-icon img {
  width: 20px;
  height: 20px;
  object-fit: contain;
  image-rendering: pixelated;
}

.equipment-slot.is-equipped .slot-icon img {
  width: 40px;
  height: 40px;
}

.slot-power {
  width: 100%;
  min-width: 0;
  margin-top: 1px;
  color: var(--gold);
  font-size: 10px;
  line-height: 1.12;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.set-bonus-list {
  display: grid;
  gap: 6px;
  margin-top: 10px;
}

.set-bonus {
  border: 1px solid #5f4938;
  border-radius: 4px;
  background: rgba(21, 17, 17, 0.72);
  padding: 8px;
  color: var(--muted);
  font-size: 12px;
}

.set-bonus strong {
  display: block;
  color: var(--ink);
  margin-bottom: 4px;
}

.set-bonus span {
  display: block;
  margin-top: 2px;
}

.set-bonus span.active {
  color: var(--gold);
}

.set-bonus.empty {
  text-align: center;
}

.inventory-list,
.talent-list,
.loot-list {
  display: grid;
  gap: 8px;
}

.inventory-list {
  grid-template-columns: repeat(auto-fill, minmax(56px, 1fr));
  max-height: 440px;
  overflow: auto;
  padding-right: 4px;
}

.loot-list {
  grid-template-columns: repeat(auto-fill, minmax(54px, 1fr));
  align-content: start;
  flex: 1 1 auto;
  min-height: 112px;
  margin-top: 12px;
  overflow-y: auto;
  padding: 2px 4px 4px 0;
}

.item-card {
  width: 100%;
  text-align: left;
  cursor: pointer;
}

.empty-card {
  grid-column: 1 / -1;
}

.item-icon {
  position: relative;
  display: grid;
  width: 56px;
  height: 56px;
  justify-self: start;
  place-items: center;
  border: 1px solid var(--edge-soft);
  border-radius: 4px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.06), transparent 45%),
    rgba(37, 31, 32, 0.94);
  box-shadow: inset 0 -4px rgba(0, 0, 0, 0.24);
  cursor: help;
}

button.item-icon {
  cursor: pointer;
}

.item-icon:hover,
.item-icon:focus-visible {
  border-color: var(--gold);
  outline: none;
  transform: translateY(-1px);
}

.item-icon.worn {
  border-color: #756f65;
}

.item-icon.common {
  border-color: #8b8271;
}

.item-icon.fine {
  border-color: #67c56f;
  box-shadow: inset 0 -4px rgba(0, 0, 0, 0.24), 0 0 0 1px rgba(103, 197, 111, 0.22);
}

.item-icon.rare {
  border-color: var(--blue);
  box-shadow: inset 0 -4px rgba(0, 0, 0, 0.24), 0 0 0 1px rgba(95, 168, 216, 0.24);
}

.item-icon.epic {
  border-color: var(--violet);
  box-shadow: inset 0 -4px rgba(0, 0, 0, 0.24), 0 0 0 1px rgba(164, 123, 230, 0.3);
}

.item-icon.legendary {
  border-color: #f28c28;
  box-shadow: inset 0 -4px rgba(0, 0, 0, 0.24), 0 0 0 1px rgba(242, 140, 40, 0.34);
}

.item-icon.mythic {
  border-color: #e34b4b;
  box-shadow: inset 0 -4px rgba(0, 0, 0, 0.24), 0 0 0 1px rgba(227, 75, 75, 0.34);
}

.item-icon img {
  width: 42px;
  height: 42px;
  object-fit: contain;
  image-rendering: pixelated;
}

.item-icon-power {
  position: absolute;
  right: 3px;
  bottom: 2px;
  color: var(--gold);
  font-size: 11px;
  font-weight: 900;
  text-shadow: 0 1px 0 #151111;
}

.item-icon-slot {
  position: absolute;
  top: 2px;
  left: 4px;
  color: rgba(246, 237, 210, 0.72);
  font-size: 11px;
  font-weight: 900;
}

.item-icon[data-diff]::after {
  content: attr(data-diff);
  position: absolute;
  top: -6px;
  right: -5px;
  min-width: 22px;
  border: 1px solid #2d1d14;
  border-radius: 999px;
  background: var(--gold);
  color: #251812;
  font-size: 10px;
  font-weight: 900;
  line-height: 16px;
  text-align: center;
}

.item-tooltip-layer {
  position: fixed;
  z-index: 30;
  width: min(260px, calc(100vw - 24px));
  border: 1px solid var(--gold);
  border-radius: 4px;
  background: rgba(21, 17, 17, 0.96);
  box-shadow: 0 16px 32px rgba(0, 0, 0, 0.44);
  padding: 10px;
  color: var(--ink);
  pointer-events: none;
}

.item-tooltip-layer[hidden] {
  display: none;
}

.tooltip-name {
  margin-bottom: 5px;
  font-size: 15px;
  font-weight: 900;
}

.tooltip-line,
.tooltip-stats,
.tooltip-effect {
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.42;
}

.tooltip-stats {
  color: var(--ink);
}

.item-card:hover,
.equipment-slot:hover {
  border-color: var(--gold);
}

.item-card.worn {
  border-color: #756f65;
}

.item-card.common {
  border-color: #8b8271;
}

.item-card.fine {
  border-color: #67c56f;
}

.item-card.rare {
  border-color: var(--blue);
}

.item-card.epic {
  border-color: var(--violet);
}

.item-card.legendary {
  border-color: #f28c28;
}

.item-card.mythic {
  border-color: #e34b4b;
}

.item-name strong {
  color: var(--gold);
}

.item-stats {
  margin-top: 5px;
  line-height: 1.45;
}

.talent-card {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px 12px;
}

.talent-desc {
  margin-top: 4px;
}

.run-hud {
  position: absolute;
  top: 16px;
  left: 50%;
  z-index: 4;
  display: none;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  width: min(1180px, calc(100vw - 32px));
  transform: translateX(-50%);
  pointer-events: none;
}

.run-hud.is-active {
  display: flex;
}

.run-chip {
  min-width: 96px;
  padding: 8px 10px;
  background: rgba(25, 21, 22, 0.86);
  box-shadow: 0 10px 24px var(--shadow);
}

.run-chip strong {
  display: block;
  margin-top: 2px;
  font-size: 22px;
}

.run-chip.wide {
  width: 180px;
}

.run-chip.objective-chip {
  width: 220px;
}

.objective-chip em {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-style: normal;
  font-size: 12px;
  font-weight: 800;
  line-height: 1.15;
}

.mini-bar {
  height: 8px;
  margin-top: 5px;
  border: 1px solid #4f3931;
  background: #161213;
}

.mini-bar i {
  display: block;
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, #a93d35, #e0604b);
}

.timer-bar i {
  background: linear-gradient(90deg, #e7b64e, #70bd62);
}

.boss-bar i {
  background: linear-gradient(90deg, #a855ff, #e7b64e);
}

.boss-chip strong {
  font-size: 18px;
  line-height: 1.08;
}

.run-help {
  margin-left: auto;
  border: 1px solid var(--edge-soft);
  border-radius: 4px;
  background: rgba(25, 21, 22, 0.78);
  padding: 9px 12px;
  color: var(--muted);
  font-size: 13px;
}

.result-screen {
  place-items: center;
  background: rgba(14, 13, 13, 0.68);
}

.result-screen.is-active {
  display: grid;
}

.result-panel {
  width: min(680px, calc(100vw - 32px));
  max-height: calc(100vh - 32px);
  max-height: calc(100dvh - 32px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding: 18px;
}

.result-stats {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  flex-shrink: 0;
  gap: 8px;
  margin-top: 14px;
}

.result-stat {
  min-width: 0;
  border: 1px solid var(--edge-soft);
  border-radius: 4px;
  background: #211b1c;
  padding: 10px;
}

.result-stat span {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.result-stat strong {
  display: block;
  margin-top: 4px;
  color: var(--gold);
  font-size: 20px;
  overflow-wrap: anywhere;
}

.result-actions {
  position: sticky;
  bottom: 0;
  flex-shrink: 0;
  margin-top: 14px;
  padding-top: 10px;
  background: linear-gradient(180deg, rgba(28, 23, 23, 0), rgba(28, 23, 23, 0.98) 28%);
  justify-content: flex-end;
}

.toast-log {
  position: absolute;
  z-index: 8;
  left: 50%;
  bottom: 24px;
  display: grid;
  gap: 6px;
  width: min(420px, 84vw);
  transform: translateX(-50%);
  pointer-events: none;
}

.toast {
  border: 1px solid #8e693f;
  border-radius: 4px;
  background: rgba(17, 15, 16, 0.88);
  padding: 8px 10px;
  text-align: center;
  animation: toast-rise 1.9s ease forwards;
}

@keyframes toast-rise {
  0% {
    opacity: 0;
    transform: translateY(12px);
  }
  14%,
  74% {
    opacity: 1;
    transform: translateY(0);
  }
  100% {
    opacity: 0;
    transform: translateY(-18px);
  }
}

@media (max-width: 1040px) {
  body {
    overflow: hidden;
  }

  #game-shell {
    height: 100vh;
    height: 100dvh;
    min-height: 0;
  }

  .lobby-grid {
    grid-template-columns: 1fr;
  }

  .run-hud {
    left: 12px;
    flex-wrap: wrap;
    width: calc(100vw - 24px);
    transform: none;
  }

  .run-help {
    width: 100%;
    margin-left: 0;
  }
}

@media (max-width: 620px) {
  .screen {
    padding: 12px;
  }

  .lobby-top {
    align-items: stretch;
    flex-direction: column;
  }

  .start-button {
    width: 100%;
  }

  .equipment-grid {
    grid-template-columns: 1fr;
  }

  .result-stats {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 6px;
  }

  .result-stat {
    padding: 8px;
  }

  .result-stat strong {
    font-size: 16px;
  }

  .result-actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .stat-grid {
    grid-template-columns: 1fr;
  }
}
