:root {
  --bg: #141312;
  --panel: #221f1d;
  --panel-2: #2c2824;
  --ink: #f7f1e7;
  --muted: #b8aca0;
  --line: rgba(255, 244, 220, 0.16);
  --gold: #d6a849;
  --danger: #d9584a;
  --ok: #53b58d;
  --water: #59a8d8;
  --metal: #c2c8cb;
  --earth: #b8874d;
  --fire: #e15f3d;
  --wood: #68aa72;
  color-scheme: dark;
  font-family:
    "Segoe UI",
    "Noto Sans KR",
    system-ui,
    sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
}

body {
  min-height: 100vh;
  margin: 0;
  background:
    linear-gradient(130deg, rgba(27, 34, 31, 0.94), rgba(31, 24, 21, 0.98) 48%, rgba(22, 20, 19, 1)),
    var(--bg);
  color: var(--ink);
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  min-height: 42px;
  border: 1px solid rgba(255, 244, 220, 0.28);
  border-radius: 8px;
  background: #f1dfba;
  color: #191512;
  cursor: pointer;
  font-weight: 800;
  letter-spacing: 0;
  transition:
    transform 160ms ease,
    border-color 160ms ease,
    background 160ms ease,
    color 160ms ease;
}

button:hover:not(:disabled) {
  transform: translateY(-1px);
  background: #fff0ca;
  border-color: rgba(255, 244, 220, 0.65);
}

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

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

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  min-height: 82px;
  padding: 14px 0 20px;
  border-bottom: 1px solid var(--line);
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
}

.brand-mark,
.empty-mark {
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  flex: 0 0 auto;
  border: 1px solid rgba(214, 168, 73, 0.5);
  border-radius: 50%;
  background: #2a2319;
  color: var(--gold);
  font-weight: 900;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: clamp(1.55rem, 2.8vw, 2.45rem);
  line-height: 1.05;
  letter-spacing: 0;
}

.brand p,
.section-head p,
.muted {
  color: var(--muted);
}

.brand p {
  margin-top: 6px;
  font-size: 0.95rem;
}

.meta-strip {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
  max-width: 440px;
}

.meta-strip span,
.tag,
.element-chip {
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 244, 220, 0.06);
  color: var(--ink);
  white-space: nowrap;
}

.meta-strip span {
  padding: 8px 11px;
  font-size: 0.82rem;
  font-weight: 750;
}

main {
  display: grid;
  gap: 24px;
  padding-top: 22px;
}

.battlefield {
  display: grid;
  grid-template-columns: minmax(260px, 1fr) minmax(270px, 360px) minmax(260px, 1fr);
  gap: 18px;
  align-items: stretch;
}

.fighter-pane,
.command-panel,
.collection {
  border: 1px solid var(--line);
  background: rgba(34, 31, 29, 0.84);
  box-shadow: 0 22px 80px rgba(0, 0, 0, 0.22);
}

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

.pane-head,
.section-head,
.card-title-row,
.stats-row,
.card-tags,
.mini-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.side-label,
.round-kicker,
.log-title {
  color: var(--gold);
  font-size: 0.72rem;
  font-weight: 900;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.pane-head strong {
  color: var(--muted);
  font-size: 0.9rem;
}

.card-slot {
  display: grid;
  min-height: 720px;
}

.empty-card {
  display: grid;
  place-items: center;
  align-content: center;
  gap: 14px;
  min-height: 100%;
  border: 1px dashed rgba(255, 244, 220, 0.22);
  border-radius: 8px;
  color: var(--muted);
}

.battle-card {
  position: relative;
  display: grid;
  grid-template-rows: auto auto 1fr auto;
  gap: 12px;
  width: 100%;
  min-height: 100%;
  overflow: hidden;
  border: 1px solid rgba(255, 244, 220, 0.2);
  border-radius: 8px;
  background: linear-gradient(180deg, #342e27, #171514);
  padding: 12px;
}

.battle-card::before {
  position: absolute;
  inset: 0;
  pointer-events: none;
  content: "";
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.card-art {
  position: relative;
  min-height: 320px;
  overflow: hidden;
  border: 1px solid rgba(255, 244, 220, 0.18);
  border-radius: 6px;
  background-color: #171514;
  background-image: var(--card-art-url), var(--sprite-art-url);
  background-repeat: no-repeat, no-repeat;
  background-size: cover, 500% 400%;
  background-position: center, var(--sprite-x) var(--sprite-y);
  filter: hue-rotate(var(--art-hue, 0deg)) saturate(var(--art-sat, 1)) brightness(var(--art-bright, 1));
  isolation: isolate;
}

.battle-card[data-art-ready="false"] .card-art {
  background-image: var(--sprite-art-url);
  background-size: 500% 400%;
  background-position: var(--sprite-x) var(--sprite-y);
}

.card-art::before,
.card-art::after {
  position: absolute;
  inset: 0;
  z-index: 2;
  pointer-events: none;
  content: "";
  opacity: 0;
  transition: opacity 200ms ease;
}

.card-art::before {
  background:
    linear-gradient(113deg, transparent 0 32%, rgba(245, 231, 198, 0.7) 33%, transparent 35% 100%),
    linear-gradient(71deg, transparent 0 55%, rgba(31, 22, 16, 0.72) 56%, transparent 59% 100%),
    linear-gradient(151deg, transparent 0 42%, rgba(245, 231, 198, 0.52) 43%, transparent 45% 100%);
  mix-blend-mode: screen;
}

.card-art::after {
  background:
    linear-gradient(118deg, transparent 0 52%, rgba(36, 21, 16, 0.8) 53%, transparent 55% 100%),
    linear-gradient(16deg, transparent 0 37%, rgba(214, 168, 73, 0.42) 38%, transparent 40% 100%),
    linear-gradient(170deg, transparent 0 64%, rgba(36, 21, 16, 0.72) 65%, transparent 67% 100%);
}

.battle-card[data-damage="1"] .card-art::before {
  opacity: 0.28;
}

.battle-card[data-damage="2"] .card-art::before {
  opacity: 0.42;
}

.battle-card[data-damage="2"] .card-art::after {
  opacity: 0.22;
}

.battle-card[data-damage="3"] .card-art::before {
  opacity: 0.58;
}

.battle-card[data-damage="3"] .card-art::after,
.battle-card[data-damage="4"] .card-art::after {
  opacity: 0.42;
}

.battle-card[data-damage="4"] .card-art {
  filter: hue-rotate(var(--art-hue, 0deg)) saturate(var(--art-sat, 1)) brightness(0.72) grayscale(0.35);
}

.battle-card[data-damage="4"] .card-art::before {
  opacity: 0.64;
}

.damage-tag {
  position: absolute;
  right: 10px;
  bottom: 10px;
  z-index: 3;
  max-width: calc(100% - 20px);
  padding: 7px 9px;
  border: 1px solid rgba(255, 244, 220, 0.22);
  border-radius: 999px;
  background: rgba(20, 17, 15, 0.75);
  color: #fff0ca;
  font-size: 0.74rem;
  font-weight: 850;
  line-height: 1.1;
}

.asset-tag {
  position: absolute;
  left: 10px;
  bottom: 10px;
  z-index: 3;
  max-width: calc(100% - 20px);
  padding: 7px 9px;
  border: 1px solid rgba(255, 244, 220, 0.22);
  border-radius: 999px;
  background: rgba(20, 17, 15, 0.75);
  color: #f4d99f;
  font-size: 0.68rem;
  font-weight: 850;
  line-height: 1.1;
}

.battle-card[data-art-ready="true"] .asset-tag {
  color: #9ff0d0;
}

.element-badge {
  position: absolute;
  top: 10px;
  left: 10px;
  z-index: 3;
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border: 1px solid rgba(255, 255, 255, 0.3);
  border-radius: 50%;
  background: rgba(16, 14, 12, 0.76);
  color: var(--element-color);
  font-size: 1.35rem;
  font-weight: 950;
}

.card-name {
  display: grid;
  gap: 4px;
  min-width: 0;
}

.card-name strong {
  overflow: hidden;
  font-size: 1.24rem;
  line-height: 1.1;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.card-name span {
  color: var(--muted);
  font-size: 0.82rem;
}

.stars {
  color: var(--gold);
  font-size: 1rem;
  white-space: nowrap;
}

.card-tags {
  flex-wrap: wrap;
  justify-content: flex-start;
}

.character-notes {
  display: grid;
  gap: 7px;
  border: 1px solid rgba(255, 244, 220, 0.12);
  border-radius: 6px;
  background: rgba(255, 244, 220, 0.045);
  padding: 9px;
}

.character-notes div {
  display: grid;
  grid-template-columns: 74px 1fr;
  gap: 8px;
  min-width: 0;
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.35;
}

.character-notes strong {
  color: var(--gold);
}

.tag,
.element-chip {
  padding: 5px 8px;
  font-size: 0.74rem;
  font-weight: 800;
}

.element-chip {
  color: var(--element-color);
}

.hp-block {
  display: grid;
  gap: 8px;
  align-self: end;
}

.hp-line {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 750;
}

.hp-bar {
  height: 13px;
  overflow: hidden;
  border: 1px solid rgba(255, 244, 220, 0.18);
  border-radius: 999px;
  background: #151312;
}

.hp-fill {
  width: var(--hp-pct);
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--ok), #e0bd5a 62%, var(--danger));
  transition: width 240ms ease;
}

.stats-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
}

.stat {
  display: grid;
  gap: 2px;
  min-width: 0;
  border: 1px solid rgba(255, 244, 220, 0.13);
  border-radius: 6px;
  padding: 8px;
  background: rgba(255, 244, 220, 0.045);
  text-align: center;
}

.stat span {
  color: var(--muted);
  font-size: 0.72rem;
}

.stat strong {
  font-size: 1.08rem;
}

.command-panel {
  display: grid;
  grid-template-rows: auto auto auto auto minmax(220px, 1fr);
  gap: 14px;
  min-height: 100%;
  padding: 16px;
}

.round-display {
  display: grid;
  place-items: center;
  gap: 4px;
  border: 1px solid rgba(214, 168, 73, 0.32);
  border-radius: 8px;
  background: #281f16;
  padding: 14px;
}

.round-display strong {
  font-size: 2.6rem;
  line-height: 0.95;
}

.matchup-panel {
  display: grid;
  gap: 8px;
  min-height: 104px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 244, 220, 0.045);
  padding: 12px;
}

.matchup-title {
  font-weight: 900;
}

.matchup-detail {
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.45;
}

.advantage {
  color: #ffe19f;
}

.disadvantage {
  color: #ff9a8f;
}

.actions {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
}

.cycle-board {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  padding: 12px 0;
}

.element-token {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 50%;
  color: #12100f;
  font-weight: 950;
}

.water {
  --element-color: var(--water);
  background-color: color-mix(in srgb, var(--water) 82%, #141312);
}

.metal {
  --element-color: var(--metal);
  background-color: color-mix(in srgb, var(--metal) 82%, #141312);
}

.earth {
  --element-color: var(--earth);
  background-color: color-mix(in srgb, var(--earth) 82%, #141312);
}

.fire {
  --element-color: var(--fire);
  background-color: color-mix(in srgb, var(--fire) 82%, #141312);
}

.wood {
  --element-color: var(--wood);
  background-color: color-mix(in srgb, var(--wood) 82%, #141312);
}

.beats {
  color: var(--muted);
  font-weight: 900;
}

.battle-log {
  display: grid;
  grid-template-rows: auto 1fr;
  gap: 10px;
  min-height: 220px;
  overflow: hidden;
}

#battleLog {
  display: flex;
  flex-direction: column-reverse;
  gap: 8px;
  min-height: 0;
  margin: 0;
  overflow: auto;
  padding: 0;
  list-style: none;
}

#battleLog li {
  border-left: 3px solid rgba(214, 168, 73, 0.52);
  background: rgba(255, 244, 220, 0.05);
  padding: 9px 10px;
  color: var(--ink);
  font-size: 0.88rem;
  line-height: 1.42;
}

.collection {
  display: grid;
  gap: 16px;
  padding: 18px;
}

.section-head {
  align-items: flex-end;
  flex-wrap: wrap;
}

.section-head h2 {
  font-size: 1.25rem;
}

.roster-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(168px, 1fr));
  gap: 12px;
}

.mini-card {
  display: grid;
  gap: 9px;
  min-width: 0;
  border: 1px solid rgba(255, 244, 220, 0.16);
  border-radius: 8px;
  background: rgba(20, 18, 16, 0.72);
  padding: 10px;
}

.mini-art {
  aspect-ratio: 1 / 1.08;
  border: 1px solid rgba(255, 244, 220, 0.14);
  border-radius: 6px;
  background-color: #171514;
  background-image: var(--card-art-url), var(--sprite-art-url);
  background-repeat: no-repeat, no-repeat;
  background-size: cover, 500% 400%;
  background-position: center, var(--sprite-x) var(--sprite-y);
  filter: hue-rotate(var(--art-hue, 0deg)) saturate(var(--art-sat, 1)) brightness(var(--art-bright, 1));
}

.mini-card[data-art-ready="false"] .mini-art {
  background-image: var(--sprite-art-url);
  background-size: 500% 400%;
  background-position: var(--sprite-x) var(--sprite-y);
}

.mini-card strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.mini-meta {
  align-items: flex-start;
  color: var(--muted);
  font-size: 0.76rem;
}

.mini-meta span {
  min-width: 0;
}

.mini-card p,
.mini-card small {
  margin: 0;
  color: var(--muted);
  font-size: 0.74rem;
  line-height: 1.35;
}

.mini-card small {
  color: #e7d2ad;
}

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

  .command-panel {
    grid-column: 1 / -1;
    grid-row: 1;
    grid-template-columns: minmax(110px, 0.42fr) minmax(220px, 1fr) minmax(180px, 0.9fr);
    grid-template-rows: auto auto;
    align-items: stretch;
  }

  .cycle-board,
  .battle-log {
    grid-column: span 3;
  }

  .card-slot {
    min-height: 680px;
  }

  .roster-grid {
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  }
}

@media (max-width: 760px) {
  .app-shell {
    padding: 16px;
  }

  .topbar,
  .battlefield,
  .command-panel {
    grid-template-columns: 1fr;
  }

  .topbar {
    display: grid;
  }

  .meta-strip {
    justify-content: flex-start;
  }

  .command-panel {
    grid-column: auto;
    grid-row: auto;
  }

  .cycle-board,
  .battle-log {
    grid-column: auto;
  }

  .card-slot {
    min-height: 650px;
  }

  .card-art {
    min-height: 280px;
  }

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

@media (max-width: 430px) {
  .brand {
    align-items: flex-start;
  }

  .brand-mark {
    width: 42px;
    height: 42px;
  }

  .stats-row {
    grid-template-columns: 1fr;
  }

  .card-title-row {
    align-items: flex-start;
    flex-direction: column;
  }
}
