:root {
  color-scheme: dark;
  --bg: #050812;
  --panel: #0d1627;
  --panel-strong: #15223a;
  --line: #30415d;
  --text: #f7f4e9;
  --muted: #aab7ca;
  --gold: #e0c16d;
  --focus: #8fd9ff;
  --blue: #5dcfff;
  --blue-soft: rgba(93, 207, 255, 0.13);
  --red: #ff6f86;
  --red-soft: rgba(255, 111, 134, 0.13);
}

* { box-sizing: border-box; }
html, body { min-height: 100%; }

body {
  margin: 0;
  background:
    radial-gradient(circle at 15% -10%, rgba(63, 116, 179, 0.28), transparent 36%),
    radial-gradient(circle at 85% 10%, rgba(148, 66, 105, 0.2), transparent 34%),
    linear-gradient(180deg, #080d18 0%, var(--bg) 100%);
  color: var(--text);
  font-family: Inter, Pretendard, "Noto Sans KR", "Malgun Gothic", sans-serif;
}

button, canvas { -webkit-tap-highlight-color: transparent; }
button { font: inherit; }

.app-shell {
  width: min(100%, 1200px);
  margin: 0 auto;
  padding: 20px 14px 32px;
}

.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 16px;
}

.eyebrow, .section-kicker {
  margin: 0 0 5px;
  color: var(--gold);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.18em;
}

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

h1 {
  margin-bottom: 0;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(2rem, 8vw, 3.6rem);
  line-height: 0.98;
  letter-spacing: 0.02em;
}

h2 { margin-bottom: 0; font-size: 1.35rem; }
h3 { margin-bottom: 0; font-size: 1rem; }

.subtitle {
  max-width: 760px;
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 0.94rem;
  line-height: 1.65;
}

.status-chip {
  flex: 0 0 auto;
  margin-top: 4px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(14, 22, 39, 0.9);
  color: var(--gold);
  padding: 8px 12px;
  font-size: 0.78rem;
  font-weight: 800;
  white-space: nowrap;
}

.setup-panel {
  border: 1px solid var(--line);
  border-radius: 20px;
  background: rgba(9, 15, 27, 0.9);
  padding: 18px;
}

.setup-heading {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 16px;
  margin-bottom: 14px;
}

.selection-message {
  margin: 0;
  color: var(--muted);
  font-size: 0.82rem;
  text-align: right;
}

.roster-intro {
  margin: -2px 0 15px;
  color: var(--muted);
  font-size: 0.8rem;
  line-height: 1.55;
}

.team-preview-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.team-preview {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 15px;
  padding: 13px;
}

.team-preview-blue { background: var(--blue-soft); border-color: rgba(93, 207, 255, 0.44); }
.team-preview-red { background: var(--red-soft); border-color: rgba(255, 111, 134, 0.44); }

.team-preview-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}

.team-preview-blue .team-preview-title { color: var(--blue); }
.team-preview-red .team-preview-title { color: var(--red); }

.team-slots {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.team-slot {
  min-height: 76px;
  border: 1px dashed rgba(188, 202, 224, 0.3);
  border-radius: 11px;
  display: grid;
  place-items: center;
  padding: 7px;
  color: var(--muted);
  font-size: 0.72rem;
  text-align: center;
}

.team-slot.filled {
  border-style: solid;
  color: var(--text);
  background: rgba(5, 10, 19, 0.52);
}

.team-slot-icon {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  margin: 0 auto 4px;
  background: var(--slot-color, #64748b);
  color: #07101b;
  font-weight: 900;
}

.team-slot small {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.64rem;
  line-height: 1.25;
}

.roster-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 11px;
  align-items: start;
}

.fighter-card {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 15px;
  background: var(--panel);
  padding: 13px;
  content-visibility: auto;
  contain-intrinsic-size: 390px;
}

.fighter-card[data-team="blue"] {
  border-color: var(--blue);
  box-shadow: inset 0 0 0 1px rgba(93, 207, 255, 0.18);
}

.fighter-card[data-team="red"] {
  border-color: var(--red);
  box-shadow: inset 0 0 0 1px rgba(255, 111, 134, 0.18);
}

.fighter-card-header {
  display: flex;
  gap: 9px;
  align-items: center;
  margin-bottom: 9px;
}

.fighter-heading-copy { min-width: 0; }

.fighter-badge {
  width: 42px;
  height: 42px;
  flex: 0 0 auto;
  border-radius: 12px;
  display: grid;
  place-items: center;
  background: linear-gradient(145deg, var(--fighter-color), #0a101c 130%);
  color: #07101b;
  font-weight: 900;
  font-size: 1rem;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.24);
}

.fighter-card h3 {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.fighter-role {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 0.72rem;
}

.fighter-summary {
  min-height: 42px;
  margin: 0 0 9px;
  color: var(--muted);
  font-size: 0.76rem;
  line-height: 1.45;
}

.skill-preview {
  display: grid;
  grid-template-columns: 28px minmax(0, 1fr);
  gap: 8px;
  margin-bottom: 9px;
  border: 1px solid var(--line);
  border-color: color-mix(in srgb, var(--ability-color) 45%, var(--line));
  border-radius: 12px;
  background: rgba(112, 140, 180, 0.08);
  background: color-mix(in srgb, var(--ability-color) 9%, transparent);
  padding: 9px;
}

.ability-mark {
  width: 28px;
  height: 28px;
  border-radius: 9px;
  display: grid;
  place-items: center;
  background: #101b2a;
  background: color-mix(in srgb, var(--ability-color) 24%, #08101b);
  color: var(--ability-color);
  font-weight: 900;
}

.skill-line {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 7px;
  margin: 0 0 4px;
  color: var(--text);
  font-size: 0.75rem;
}

.skill-line span {
  flex: 0 0 auto;
  color: var(--ability-color);
  font-size: 0.66rem;
  font-weight: 800;
}

.skill-description {
  margin: 0;
  color: var(--muted);
  font-size: 0.7rem;
  line-height: 1.42;
}

.ability-details {
  margin: 0 0 10px;
  border-top: 1px solid rgba(167, 184, 209, 0.18);
  border-bottom: 1px solid rgba(167, 184, 209, 0.18);
  padding: 7px 0;
}

.ability-details summary {
  color: var(--gold);
  font-size: 0.72rem;
  font-weight: 800;
  cursor: pointer;
}

.ability-details[open] summary { margin-bottom: 8px; }

.trait-block {
  border-left: 2px solid var(--gold);
  padding-left: 8px;
}

.trait-block p {
  margin-bottom: 0;
  color: var(--muted);
  font-size: 0.7rem;
  line-height: 1.42;
}

.trait-block .trait-title {
  margin-bottom: 3px;
  color: var(--text);
  font-weight: 800;
}

.fighter-stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 5px;
  margin-top: 8px;
}

.fighter-stat {
  border: 1px solid rgba(164, 183, 211, 0.18);
  border-radius: 8px;
  background: rgba(4, 8, 16, 0.38);
  padding: 5px 3px;
  text-align: center;
}

.fighter-stat small {
  display: block;
  color: var(--muted);
  font-size: 0.58rem;
}

.fighter-stat strong {
  display: block;
  margin-top: 2px;
  font-size: 0.72rem;
}

.team-buttons {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 7px;
}

button {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: var(--panel);
  color: var(--text);
  padding: 9px 13px;
  font-size: 0.88rem;
  font-weight: 750;
  cursor: pointer;
}

button:hover { background: var(--panel-strong); }
button:disabled { opacity: 0.43; cursor: not-allowed; }

button:focus-visible,
summary:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.team-button-blue.selected { border-color: var(--blue); background: var(--blue-soft); color: var(--blue); }
.team-button-red.selected { border-color: var(--red); background: var(--red-soft); color: var(--red); }
.primary-button { background: #caa94f; border-color: #efd27b; color: #10131b; }
.primary-button:hover { background: #e0c16d; }

.setup-actions, .viewer-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 9px;
  margin-top: 14px;
}

.setup-actions .primary-button { margin-left: auto; min-width: 150px; }

.battle-panel[hidden], .setup-panel[hidden] { display: none; }

.game-card {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: #060a12;
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.38);
}

canvas {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 720 / 1120;
  background: #080d17;
}

.notice {
  margin: 11px 2px 0;
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.55;
}

@media (max-width: 1040px) {
  .roster-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

@media (max-width: 800px) {
  .roster-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 560px) {
  .app-shell { padding-inline: 8px; }
  .page-header, .setup-heading { display: block; }
  .status-chip { display: inline-flex; margin-top: 12px; }
  .selection-message { margin-top: 9px; text-align: left; }
  .team-preview-grid { grid-template-columns: 1fr; }
  .roster-grid { grid-template-columns: 1fr; }
  .setup-actions button, .viewer-controls button { flex: 1 1 44%; }
  .setup-actions .primary-button { margin-left: 0; }
}
