:root {
  color-scheme: dark;
  --bg: #121015;
  --bg-deep: #09080b;
  --panel: #1d1a21;
  --panel-strong: #27222d;
  --line: #4b3d4f;
  --text: #f3eadf;
  --muted: #a89ba6;
  --gold: #e0b85b;
  --blood: #d45757;
  --violet: #9f78ff;
  --green: #65c68a;
  --blue: #68b6e8;
}

* {
  box-sizing: border-box;
}

body {
  min-height: 100vh;
  margin: 0;
  color: var(--text);
  font-family: "Trebuchet MS", "Microsoft YaHei", sans-serif;
  background:
    linear-gradient(0deg, rgba(9, 8, 11, 0.84), rgba(9, 8, 11, 0.84)),
    repeating-linear-gradient(90deg, #19151e 0 2px, #121015 2px 8px);
}

button {
  min-height: 44px;
  border: 0;
  color: inherit;
  font: inherit;
  cursor: pointer;
  touch-action: manipulation;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.shell {
  width: min(1440px, calc(100% - 28px));
  margin: 0 auto;
  padding: 22px 0;
}

.topbar,
.panel {
  border: 2px solid var(--line);
  background: rgba(29, 26, 33, 0.94);
  box-shadow: 0 0 0 4px rgba(0, 0, 0, 0.22), inset 0 0 24px rgba(0, 0, 0, 0.3);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  min-height: 96px;
  padding: 18px 22px;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--gold);
  font-size: 0.78rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: clamp(2rem, 6vw, 4.2rem);
  line-height: 0.95;
  text-shadow: 4px 4px 0 #000;
}

h2 {
  margin-bottom: 0;
}

h3 {
  margin-bottom: 8px;
}

.run-stats {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.run-stats span,
.battle-state,
.panel-title span {
  min-width: 82px;
  border: 1px solid #6b586b;
  padding: 8px 10px;
  background: var(--bg-deep);
  color: var(--gold);
  text-align: center;
}

.layout {
  display: grid;
  grid-template-columns: minmax(240px, 300px) 1fr minmax(220px, 280px);
  gap: 14px;
  margin-top: 14px;
}

.panel {
  min-height: 620px;
  padding: 16px;
}

.panel-title,
.battle-header,
.actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.icon-button {
  width: 40px;
  height: 40px;
  border: 1px solid var(--line);
  background: #33293a;
  font-size: 1.25rem;
}

.party-list,
.relic-list,
.combat-log {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.party-list {
  margin: 16px 0;
}

.card,
.relic-card,
.enemy-card {
  position: relative;
  overflow: hidden;
  border: 2px solid #5d4b61;
  background: #211d26;
  padding: 12px;
}

.card::before,
.enemy-card::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: repeating-linear-gradient(0deg, transparent 0 8px, rgba(255, 255, 255, 0.03) 8px 10px);
}

.card.common {
  border-color: #85808a;
}

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

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

.card-head,
.unit-name {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-weight: 700;
}

.portrait {
  display: grid;
  place-items: center;
  width: 54px;
  height: 54px;
  margin-bottom: 10px;
  border: 2px solid rgba(255, 255, 255, 0.14);
  background: #101014;
  font-size: 1.85rem;
  image-rendering: pixelated;
}

.stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 5px;
  margin-top: 10px;
  color: var(--muted);
  font-size: 0.88rem;
}

.hpbar {
  height: 9px;
  margin-top: 8px;
  border: 1px solid #5e4d55;
  background: #100f12;
}

.hpbar span {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, var(--blood), #f09a72);
}

.summon-box,
.codex {
  margin-top: auto;
  border: 1px solid var(--line);
  padding: 14px;
  background: #151219;
}

.summon-box p,
.codex {
  color: var(--muted);
  font-size: 0.92rem;
}

.primary-button,
.secondary-button {
  min-height: 48px;
  border: 2px solid #7d6049;
  padding: 10px 16px;
  background: #6f3b34;
  box-shadow: inset 0 -4px 0 rgba(0, 0, 0, 0.24);
  font-weight: 700;
}

.secondary-button {
  border-color: #5a5168;
  background: #342c42;
}

.battle-panel {
  display: flex;
  flex-direction: column;
}

.arena {
  display: grid;
  grid-template-columns: 1fr 70px 1fr;
  align-items: stretch;
  gap: 12px;
  margin: 16px 0;
}

.side {
  min-height: 300px;
  border: 1px solid var(--line);
  padding: 12px;
  background: rgba(11, 10, 14, 0.56);
}

.unit-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(132px, 1fr));
  gap: 10px;
}

.versus {
  display: grid;
  place-items: center;
  color: var(--gold);
  font-size: 1.35rem;
  font-weight: 800;
  text-shadow: 2px 2px 0 #000;
}

.actions {
  justify-content: flex-start;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

.reward-choices {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 12px;
}

.reward-choices.hidden {
  display: none;
}

.relic-card {
  text-align: left;
}

.relic-card strong {
  display: block;
  margin-bottom: 6px;
  color: var(--gold);
}

.relic-card p {
  margin-bottom: 0;
  color: var(--muted);
}

.combat-log {
  flex: 1;
  min-height: 150px;
  max-height: 240px;
  overflow: auto;
  border: 1px solid var(--line);
  padding: 12px;
  background: #0c0b0f;
  color: #d7ced6;
  font-family: Consolas, "Microsoft YaHei", monospace;
  font-size: 0.9rem;
}

.log-line {
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  padding-bottom: 5px;
}

.relic-list {
  margin: 16px 0;
}

.dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  margin-right: 8px;
  border: 1px solid #000;
}

.dot.common {
  background: #85808a;
}

.dot.rare {
  background: var(--blue);
}

.dot.epic {
  background: var(--violet);
}

.empty {
  color: var(--muted);
  border: 1px dashed #5a4d5d;
  padding: 16px;
  text-align: center;
}

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

  .battle-panel {
    order: 1;
  }

  .roster-panel {
    order: 2;
  }

  .relic-panel {
    order: 3;
  }

  .panel {
    min-height: auto;
  }

  .arena,
  .reward-choices {
    grid-template-columns: 1fr;
  }

  .versus {
    min-height: 44px;
  }
}

@media (max-width: 640px) {
  body {
    background:
      linear-gradient(0deg, rgba(9, 8, 11, 0.9), rgba(9, 8, 11, 0.9)),
      repeating-linear-gradient(90deg, #19151e 0 2px, #121015 2px 7px);
  }

  .shell {
    width: 100%;
    padding: 0 0 10px;
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
    gap: 12px;
    min-height: auto;
    border-width: 0 0 2px;
    padding: 14px 12px;
  }

  .run-stats {
    display: grid;
    width: 100%;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    justify-content: flex-start;
  }

  .run-stats span,
  .battle-state,
  .panel-title span {
    min-width: 0;
    padding: 8px 6px;
    font-size: 0.88rem;
  }

  h1 {
    font-size: clamp(2rem, 13vw, 3rem);
  }

  h2 {
    font-size: 1.16rem;
  }

  h3 {
    font-size: 0.98rem;
  }

  .layout {
    gap: 10px;
    margin-top: 10px;
  }

  .panel {
    border-width: 2px 0;
    padding: 12px;
  }

  .battle-header {
    align-items: flex-start;
  }

  .arena {
    gap: 8px;
    margin: 12px 0;
  }

  .side {
    min-height: 0;
    padding: 10px;
  }

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

  .card,
  .relic-card,
  .enemy-card {
    padding: 10px;
  }

  .portrait {
    width: 42px;
    height: 42px;
    margin-bottom: 8px;
    font-size: 1.45rem;
  }

  .stats {
    grid-template-columns: 1fr;
    gap: 3px;
    font-size: 0.82rem;
  }

  .card p,
  .relic-card p,
  .summon-box p {
    font-size: 0.84rem;
    line-height: 1.45;
  }

  .actions {
    position: sticky;
    bottom: 8px;
    z-index: 8;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
    border: 1px solid var(--line);
    padding: 8px;
    background: rgba(12, 11, 15, 0.96);
    box-shadow: 0 -8px 24px rgba(0, 0, 0, 0.35);
  }

  .primary-button,
  .secondary-button {
    width: 100%;
    min-height: 52px;
    padding: 9px 8px;
  }

  .reward-choices {
    gap: 8px;
  }

  .combat-log {
    min-height: 130px;
    max-height: 210px;
    font-size: 0.82rem;
  }

  .summon-box {
    display: grid;
    grid-template-columns: 1fr;
    gap: 10px;
  }
}

@media (max-width: 380px) {
  .unit-row {
    grid-template-columns: 1fr;
  }

  .battle-header {
    flex-direction: column;
  }
}
