/* battle-mode.css — Phase UI-4: Battle Mode Redesign */
/* Phase UI-8: Responsive Sizing & Device-Adaptive Layout */
/* Torn-like interaction architecture — mobile-first battle UI */

/* ════════════════════════════════════════════════════════
   BATTLE MODE STRUCTURE
   Mobile: stacked single column
   Desktop: 2-column preserved
   ════════════════════════════════════════════════════════ */

/* ── Battle Mode Wrapper (shell activates via body class) ── */
body.battle-active #shell,
body.battle-active #shell-topbar,
body.battle-active #shell-nav {
  display: none;
}

/* ── Battle Mode Wrapper ── */
#battle-mode {
  display: none;
  flex-direction: column;
  position: fixed;
  inset: 0;
  z-index: 200;
  background: var(--bg);
}

/* ── Battle Mode Reveal ── */
body.battle-active #battle-mode {
  display: flex;
  flex-direction: column;
  position: fixed;
  inset: 0;
  z-index: 200;
  background: var(--bg);
}
/* ── Battle Header ────────────────────────────────────────── */
#battle-header {
  display: none;
  flex-direction: column;
  gap: 6px;
  padding: 12px 14px 10px;  /* Phase UI-8: larger padding */
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
  /* Phase UI-8: font sizing */
  font-size: var(--font-sm, 12px);
}

body.battle-active #battle-header {
  display: flex;
}

body.battle-active #battle-arena {
  display: flex;
}

#battle-header-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

#battle-instance-info {
  display: flex;
  gap: 12px;
  font-size: 11px;
  color: var(--muted);
}

#battle-instance-info .bii-item {
  display: flex;
  align-items: center;
  gap: 4px;
}

#battle-instance-info .bii-label {
  color: var(--muted);
}

#battle-instance-info .bii-value {
  color: var(--text);
  font-weight: bold;
}

#battle-round-info {
  display: flex;
  gap: 10px;
  font-size: 11px;
}

#battle-round-info .alive-pill {
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 10px;
  font-weight: bold;
}

.alive-pill.player-alive {
  background: #1c3a1c;
  color: #3fb950;
}

.alive-pill.enemy-alive {
  background: #3a1c1c;
  color: #f85149;
}

#battle-result-badge {
  display: none;
  padding: 4px 12px;
  border-radius: 4px;
  font-size: 12px;
  font-weight: bold;
  text-align: center;
}

#battle-result-badge.show { display: block; }
#battle-result-badge.win  { background: #1c3a1c; color: #3fb950; border: 1px solid #3fb950; }
#battle-result-badge.lose { background: #3a1c1c; color: #f85149; border: 1px solid #f85149; }
#battle-result-badge.draw  { background: #1c2e3a; color: #58a6ff; border: 1px solid #58a6ff; }

/* ── Battle Arena ────────────────────────────────────────── */
#battle-arena {
  display: none;
  flex-direction: column;
  flex: 1;
  overflow: hidden;
}

body.battle-active #battle-arena {
  display: flex;
}

#battle-teams {
  display: flex;
  flex-direction: column;
  flex: 1;
  overflow-y: auto;
  padding: 8px;
  gap: 8px;
}

/* ── Team Sections ───────────────────────────────────────── */
.battle-team-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 4px;
  overflow: hidden;
}

.battle-team-section.enemy {
  border-color: #f8514960;
}

.battle-team-header {
  padding: 6px 10px;
  font-size: 11px;
  font-weight: bold;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.battle-team-section.player .battle-team-header {
  color: #3fb950;
  background: #0f1a0f;
}

.battle-team-section.enemy .battle-team-header {
  color: #f85149;
  background: #1a0f0f;
}

.battle-team-count {
  font-size: 10px;
  opacity: 0.7;
}

.battle-char-list {
  display: flex;
  flex-direction: column;
  gap: 1px;
  padding: 4px;
}

/* ── Battle Character Card (compact mobile card) ────────── */
.battle-char-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;       /* Phase UI-8: larger (was 6px 8px) */
  background: #0d0d0d;
  border-radius: 4px;
  font-size: var(--font-sm, 12px);
  min-height: 52px;           /* Phase UI-8: taller card (was 44px) */
  transition: opacity 0.2s;
}

.battle-char-card.dead {
  opacity: 0.35;
}

.battle-char-card.dead .battle-char-name {
  text-decoration: line-through;
}

.battle-char-portrait {
  width: 36px;               /* Phase UI-8: 36px (was 32px) */
  height: 36px;              /* Phase UI-8: 36px (was 32px) */
  border-radius: 50%;
  background: var(--surface);
  border: 2px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;            /* Phase UI-8: 16px (was 14px) */
  flex-shrink: 0;
  overflow: hidden;
}

.battle-char-portrait.boss {
  border-color: #e6c07b;
  box-shadow: 0 0 8px #e6c07b50;
}

.battle-char-info {
  flex: 1;
  min-width: 0;
}

.battle-char-name {
  font-size: var(--font-base, 14px); /* Phase UI-8: 14px (was 12px) */
  font-weight: bold;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: flex;
  align-items: center;
  gap: 6px;
}

.battle-char-name .boss-crown {
  color: #e6c07b;
  font-size: 12px;           /* Phase UI-8: 12px (was 10px) */
}

.battle-char-prof {
  font-size: var(--font-xs, 11px); /* Phase UI-8: 11px (was 10px) */
  color: var(--muted);
}

.battle-char-bars {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 64px;           /* Phase UI-8: wider bars (was 60px) */
}

.battle-bar-row {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 10px;
}

.battle-bar-bg {
  flex: 1;
  height: 7px;
  background: rgba(255,255,255,0.06);
  border-radius: 3px;
  overflow: hidden;
  border: 1px solid rgba(255,255,255,0.08);
}

.battle-bar-fill {
  height: 100%;
  border-radius: 2px;
  transition: width 0.3s;
  position: relative;
}

.battle-bar-fill::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 50%;
  background: linear-gradient(180deg, rgba(255,255,255,0.20), transparent);
  border-radius: 2px 2px 0 0;
}

.battle-bar-fill.hp-bar {
  background: linear-gradient(90deg, #f85149, #ff7b72);
  box-shadow: 0 0 8px rgba(248,81,73,0.50);
}
.battle-bar-fill.hp-bar.low { background: linear-gradient(90deg, #e6c07b, #f0d080); box-shadow: 0 0 8px rgba(230,192,123,0.40); }
.battle-bar-fill.hp-bar.medium { background: linear-gradient(90deg, #d29940, #e6c07b); box-shadow: 0 0 8px rgba(230,192,123,0.40); }
.battle-bar-fill.hp-bar.critical { background: linear-gradient(90deg, #f85149, #ff4444); box-shadow: 0 0 10px rgba(248,81,73,0.60); animation: critical-pulse 1s ease-in-out infinite; }
.battle-bar-fill.mp-bar { background: linear-gradient(90deg, #58a6ff, #79c0ff); box-shadow: 0 0 8px rgba(88,166,255,0.50); }

@keyframes critical-pulse {
  0%, 100% { box-shadow: 0 0 10px rgba(248,81,73,0.60); }
  50% { box-shadow: 0 0 18px rgba(248,81,73,0.90); }
}

.battle-bar-text {
  color: var(--muted);
  width: 36px;
  text-align: right;
  flex-shrink: 0;
}

.battle-char-status {
  display: flex;
  gap: 2px;
  flex-wrap: wrap;
  max-width: 48px;
  justify-content: flex-end;
}

.battle-status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  font-size: 8px;
  display: inline-block;
}

/* ── Battle Action Bar (bottom fixed) ────────────────────── */
#battle-action-bar {
  display: none;
  flex-direction: column;
  gap: 8px;
  padding: 12px 14px;
  background: var(--surface);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
  /* Phase UI-8: minimum tap target */
  min-height: 120px;
}

body.battle-active #battle-action-bar {
  display: flex;
}

#battle-primary-actions {
  display: flex;
  gap: 10px;
  justify-content: center;
}

#battle-primary-actions button {
  flex: 1;
  padding: 14px 10px;
  font-size: var(--font-base, 14px);
  font-weight: bold;
  border-radius: 6px;
  cursor: pointer;
  border: 1px solid rgba(230,192,123,0.20);
  background: rgba(255,255,255,0.05);
  color: var(--text);
  transition: all 0.18s ease;
  min-height: var(--tap-min, 44px);
  letter-spacing: 0.03em;
}

#battle-primary-actions button:hover {
  background: rgba(255,255,255,0.10);
  border-color: rgba(230,192,123,0.35);
  color: var(--gold);
}

#battle-primary-actions button:active {
  transform: scale(0.97);
}

#battle-primary-actions button.primary-cta {
  background: linear-gradient(135deg, rgba(230,192,123,0.25), rgba(188,140,255,0.15));
  border-color: rgba(230,192,123,0.50);
  color: var(--gold);
  font-weight: 700;
  box-shadow: 0 0 15px rgba(230,192,123,0.25);
  text-shadow: 0 0 8px rgba(230,192,123,0.5);
}

#battle-primary-actions button.primary-cta:hover {
  background: linear-gradient(135deg, rgba(230,192,123,0.35), rgba(188,140,255,0.22));
  box-shadow: 0 0 20px rgba(230,192,123,0.40);
}

#battle-primary-actions button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none;
}

#battle-secondary-actions {
  display: flex;
  gap: 8px;
  justify-content: center;
}

#battle-secondary-actions button {
  flex: 1;
  padding: 12px 8px;        /* Phase UI-8: larger */
  font-size: var(--font-sm, 12px);
  border-radius: 6px;
  cursor: pointer;
  border: 1px solid var(--border);
  background: #21262d;
  color: var(--text);
  min-height: var(--tap-min, 44px);
}

#battle-secondary-actions button:active {
  transform: scale(0.97);
}

#battle-secondary-actions button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none;
}

#battle-speed-row {
  display: flex;
  gap: 4px;
  justify-content: center;
  align-items: center;
}

#battle-speed-row span {
  font-size: 10px;
  color: var(--muted);
  margin-right: 4px;
}

/* ── Battle Log Drawer ───────────────────────────────────── */
#battle-log-drawer {
  display: none;
  flex-direction: column;
  max-height: 45vh;
  background: var(--surface);
  border-top: 1px solid var(--border);
}

#battle-log-drawer.open {
  display: flex;
}

#battle-log-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 6px;
  font-size: 11px;
  color: var(--muted);
  cursor: pointer;
  border: none;
  background: none;
  border-top: 1px solid var(--border);
  width: 100%;
  transition: color 0.15s;
}

#battle-log-toggle:hover {
  color: var(--text);
  background: #1a1f25;
}

#battle-log-toggle .toggle-arrow {
  transition: transform 0.2s;
}

#battle-log-drawer.open #battle-log-toggle .toggle-arrow {
  transform: rotate(180deg);
}

#battle-log-content {
  overflow-y: auto;
  flex: 1;
  padding: 6px 10px;
  font-size: 11px;
  line-height: 1.6;
  max-height: 200px;
}

#battle-log-content .log-line {
  padding: 1px 0;
  border-bottom: 1px solid #161b22;
  white-space: pre-wrap;
  word-break: break-all;
}

#battle-log-content .log-line.empty { height: 4px; border: none; }
#battle-log-content .log-line.turn { color: #e6c07b; font-weight: bold; margin-top: 8px; text-align: center; background: rgba(230,192,123,0.08); padding: 4px 0; border-radius: 3px; }
#battle-log-content .log-line.dmg { color: #f85149; }
#battle-log-content .log-line.heal { color: #3fb950; }
#battle-log-content .log-line.miss { color: #6e7681; }
#battle-log-content .log-line.crit   { color: #ff7b72; font-weight: bold; }
#battle-log-content .log-line.block  { color: #79c0ff; font-weight: bold; }
#battle-log-content .log-line.dodge { color: #6e7681; font-style: italic; }
#battle-log-content .log-line.bleed  { color: #f85149; }
#battle-log-content .log-line.poison { color: #a371f7; }
#battle-log-content .log-line.boss   { color: #e6c07b; font-weight: bold; }
#battle-log-content .log-line.actor { color: #e6c07b; font-weight: bold; }
#battle-log-content .log-line.elite { color: #ff7b72; font-weight: bold; }
#battle-log-content .log-line.skill { color: #79c0ff; }
#battle-log-content .log-line.status { color: #a371f7; }
#battle-log-content .log-line.info { color: #8b949e; }
#battle-log-content .log-line.system { color: #e6c07b; }
#battle-log-content .log-line.mp { color: #58a6ff; }
#battle-log-content .log-line.buff { color: #3fb950; }
#battle-log-content .log-line.debuff { color: #f85149; }
#battle-log-content .log-line.item { color: #d2a8ff; }
#battle-log-content .log-line.error { color: #ff7b72; font-weight: bold; }
#battle-log-content .log-line.turn-summary {
  color: #e6c07b;
  font-style: italic;
  padding: 4px 8px;
  background: #1c2128;
  border-left: 3px solid #e6c07b;
  margin: 2px 0;
}
#battle-log-content .log-line.satori { color: #79c0ff; }

/* ── Wave Complete / Battle End Banner ────────────────────── */
#battle-wave-banner {
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
  text-align: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  margin: 10px;
  gap: 10px;
}

#battle-wave-banner.show { display: flex; }

#battle-wave-banner .banner-title {
  font-size: 18px;
  font-weight: bold;
  color: var(--gold);
}

#battle-wave-banner .banner-sub {
  font-size: var(--font-sm, 12px);
  color: var(--muted);
}

/* ── Battle Team Sections ──────────────────────────────────── */
.battle-team-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
  /* Phase UI-8: minimum width for readability on mobile */
  min-width: 0;
}

.battle-team-section.enemy {
  border-color: #f8514960;
}

.battle-team-header {
  padding: 10px 12px;
  font-size: var(--font-sm, 12px);
  font-weight: bold;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.battle-team-section.player .battle-team-header {
  color: #3fb950;
  background: #0f1a0f;
}

.battle-team-section.enemy .battle-team-header {
  color: #f85149;
  background: #1a0f0f;
}

.battle-team-count {
  font-size: var(--font-xs, 11px);
  opacity: 0.7;
}

.battle-char-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 6px;
}

#battle-teams {
  display: flex;
  flex-direction: column;
  flex: 1;
  overflow-y: auto;
  padding: 10px;
  gap: 10px;
}

/* ── Battle Log Drawer ───────────────────────────────────── */
#battle-log-drawer {
  display: none;
  flex-direction: column;
  max-height: 45vh;
  background: var(--surface);
  border-top: 1px solid var(--border);
}

#battle-log-drawer.open {
  display: flex;
}

#battle-log-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px;
  font-size: var(--font-sm, 12px);
  color: var(--muted);
  cursor: pointer;
  border: none;
  background: none;
  border-top: 1px solid var(--border);
  width: 100%;
  transition: color 0.15s;
}

#battle-log-toggle:hover {
  color: var(--text);
  background: #1a1f25;
}

#battle-log-toggle .toggle-arrow {
  transition: transform 0.2s;
}

#battle-log-drawer.open #battle-log-toggle .toggle-arrow {
  transform: rotate(180deg);
}

#battle-log-content {
  overflow-y: auto;
  flex: 1;
  padding: 8px 12px;
  font-size: var(--font-sm, 12px);
  line-height: 1.6;
  max-height: 200px;
}

#battle-log-content .log-line {
  padding: 2px 0;
  border-bottom: 1px solid #161b22;
  white-space: pre-wrap;
  word-break: break-all;
}

#battle-log-content .log-line.empty { height: 4px; border: none; }
#battle-log-content .log-line.turn { color: #e6c07b; font-weight: bold; margin-top: 8px; text-align: center; background: rgba(230,192,123,0.08); padding: 4px 0; border-radius: 3px; }
#battle-log-content .log-line.dmg { color: #f85149; }
#battle-log-content .log-line.heal { color: #3fb950; }
#battle-log-content .log-line.miss { color: #6e7681; }
#battle-log-content .log-line.crit   { color: #ff7b72; font-weight: bold; }
#battle-log-content .log-line.block  { color: #79c0ff; font-weight: bold; }
#battle-log-content .log-line.dodge { color: #6e7681; font-style: italic; }
#battle-log-content .log-line.bleed  { color: #f85149; }
#battle-log-content .log-line.poison { color: #a371f7; }
#battle-log-content .log-line.boss   { color: #e6c07b; font-weight: bold; }
#battle-log-content .log-line.actor { color: #e6c07b; font-weight: bold; }
#battle-log-content .log-line.elite { color: #ff7b72; font-weight: bold; }
#battle-log-content .log-line.skill { color: #79c0ff; }
#battle-log-content .log-line.status { color: #a371f7; }
#battle-log-content .log-line.info { color: #8b949e; }
#battle-log-content .log-line.system { color: #e6c07b; }
#battle-log-content .log-line.mp { color: #58a6ff; }
#battle-log-content .log-line.buff { color: #3fb950; }
#battle-log-content .log-line.debuff { color: #f85149; }
#battle-log-content .log-line.item { color: #d2a8ff; }
#battle-log-content .log-line.error { color: #ff7b72; font-weight: bold; }
#battle-log-content .log-line.turn-summary {
  color: #e6c07b;
  font-style: italic;
  padding: 6px 10px;
  background: #1c2128;
  border-left: 3px solid #e6c07b;
  margin: 4px 0;
}
#battle-log-content .log-line.satori { color: #79c0ff; }

/* ── Satori Display in Battle Header ────────────────────── */
#battle-satori-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: var(--font-sm, 12px);
  color: var(--cyan);
  padding: 6px 0;
  border-top: 1px solid var(--border);
  margin-top: 4px;
}

/* ── Battle Status Bar ────────────────────────────────────── */
#battle-char-status-strip {
  display: flex;
  gap: 4px;
  overflow-x: auto;
  padding: 6px 0;
  font-size: var(--font-xs, 11px);
}

.battle-status-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 8px;
  border-radius: 4px;
  white-space: nowrap;
  flex-shrink: 0;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.battle-status-badge.buff  { background: rgba(63,185,80,0.15); color: var(--green); border: 1px solid rgba(63,185,80,0.35); box-shadow: 0 0 6px rgba(63,185,80,0.20); }
.battle-status-badge.debuff { background: rgba(248,81,73,0.15); color: var(--red); border: 1px solid rgba(248,81,73,0.35); box-shadow: 0 0 6px rgba(248,81,73,0.20); }
.battle-status-badge.cc    { background: rgba(230,192,123,0.15); color: var(--gold); border: 1px solid rgba(230,192,123,0.35); box-shadow: 0 0 6px rgba(230,192,123,0.20); }

/* ═══════════════════════════════════════════════════════════
   Phase UI-8: Device-Adaptive Battle Layout
   Desktop: 2-column side-by-side
   Mobile: stacked single column
   ═══════════════════════════════════════════════════════════ */

/* ── Mobile (≤767px): Stacked single column ─────────────── */
@media (max-width: 767px) {
  #battle-teams {
    flex-direction: column;
    gap: 10px;
  }

  .battle-team-section {
    /* Full width on mobile */
  }

  #battle-char-list {
    max-height: none;
    overflow-y: visible;
  }

  /* Mobile: battle header info compact */
  #battle-instance-info {
    gap: 8px;
    font-size: 11px;
  }

  #battle-round-info {
    gap: 8px;
    font-size: 11px;
  }
}

/* ── Desktop (≥768px): Side-by-side two column ─────────── */
@media (min-width: 768px) {
  #battle-teams {
    flex-direction: row;
    align-items: flex-start;
    gap: 12px;
  }

  .battle-team-section {
    flex: 1;
    min-width: 0;
  }

  #battle-char-list {
    max-height: 50vh;
    overflow-y: auto;
  }

  /* Battle action bar taller on desktop */
  #battle-action-bar {
    min-height: 140px;
  }
}

/* ── Extra wide desktop (>1024px) ─────────────────────────── */
@media (min-width: 1024px) {
  body.battle-active #battle-mode {
    max-width: 700px;
    left: 50%;
    transform: translateX(-50%);
  }
}
