/* =============================================================================
   style.css — AutoBrawl: Fields of War
   ============================================================================= */

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: #0d1117;
  color: #c9d1d9;
  overflow: hidden;
  height: 100vh;
  width: 100vw;
}

/* ── Screens ─────────────────────────────────────────────────────────────── */

.screen {
  width: 100%;
  height: 100vh;
  display: flex;
}

.hidden {
  display: none !important;
}

/* ── Welcome ─────────────────────────────────────────────────────────────── */

#welcome-screen {
  justify-content: center;
  align-items: center;
  position: relative;
  overflow: hidden;
}

#welcome-canvas {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 0;
  pointer-events: none;
}

.welcome-content {
  position: absolute;
  z-index: 1;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  text-align: center;
  width: 340px;
  max-width: 75vw;
  padding: 30px 24px;
  background: rgba(13, 17, 23, 0.8);
  border-radius: 16px;
  border: 1px solid rgba(48, 54, 61, 0.6);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.welcome-content h1 {
  font-size: 0.85em;
  color: #484f58;
  letter-spacing: 4px;
  text-transform: uppercase;
  font-weight: 400;
  margin-bottom: 14px;
  text-shadow: none;
}

.welcome-subtitle {
  font-size: 1.4em;
  color: #c9d1d9;
  margin-bottom: 28px;
  font-style: italic;
  line-height: 1.4;
}

.welcome-buttons {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.submenu {
  display: flex;
  gap: 8px;
  overflow: hidden;
  max-height: 0;
  opacity: 0;
  transition: max-height 0.25s ease, opacity 0.2s ease;
}

.submenu.open {
  max-height: 60px;
  opacity: 1;
}

.btn-sub {
  flex: 1;
  padding: 10px 16px;
  font-size: 0.9em;
  background: #161b22;
  color: #c9d1d9;
  border: 1px solid #30363d;
  border-radius: 6px;
  cursor: pointer;
  font-family: inherit;
  transition: all 0.15s;
}

.btn-sub:hover {
  background: #21262d;
}

.btn-sub:active {
  transform: scale(0.95);
  filter: brightness(0.85);
}

.menu-toggle {
  position: relative;
}

.menu-toggle::after {
  content: ' ▾';
  font-size: 0.7em;
}

.btn-disabled {
  background: #161b22;
  color: #484f58;
  border-color: #21262d;
  cursor: not-allowed;
  position: relative;
}

.btn-disabled:hover {
  background: #161b22;
}

.coming-soon-badge {
  display: inline-block;
  margin-left: 8px;
  padding: 2px 8px;
  font-size: 0.7em;
  background: linear-gradient(135deg, #d94a4a, #d97a4a);
  color: #fff;
  border-radius: 10px;
  text-transform: uppercase;
  letter-spacing: 1px;
  font-weight: 600;
}

/* ── Faction Picker ──────────────────────────────────────────────────────── */

.faction-pick-cards {
  display: flex;
  gap: 12px;
  margin-bottom: 16px;
}

.faction-pick-card {
  flex: 1;
  padding: 20px 16px;
  background: #161b22;
  border: 2px solid #21262d;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.15s;
  text-align: center;
}

.faction-pick-card:hover {
  border-color: #30363d;
  background: #1c2128;
}

.faction-pick-card:active {
  transform: scale(0.95);
}

.faction-pick-icon {
  width: 64px;
  height: 64px;
  image-rendering: pixelated;
  margin-bottom: 8px;
}

.faction-pick-name {
  font-size: 1.3em;
  font-weight: 700;
}

/* ── Buttons ─────────────────────────────────────────────────────────────── */

.btn {
  padding: 12px 24px;
  font-size: 1em;
  border: 1px solid #30363d;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.15s ease;
  font-family: inherit;
  user-select: none;
}

.btn:active {
  transform: scale(0.95);
  filter: brightness(0.85);
  transition: all 0.05s ease;
}

.btn-primary {
  background: #238636;
  color: #fff;
  border-color: #2ea043;
}

.btn-primary:hover {
  background: #2ea043;
}

.btn-secondary {
  background: #21262d;
  color: #c9d1d9;
}

.btn-secondary:hover {
  background: #30363d;
}

.btn-small {
  padding: 6px 14px;
  font-size: 0.85em;
  background: #21262d;
  color: #c9d1d9;
  border-color: #30363d;
}

.btn-small:hover {
  background: #30363d;
}

.btn-icon {
  padding: 0;
  width: 28px;
  height: 28px;
  font-size: 1.1em;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.game-card-actions {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.btn-full {
  width: 100%;
  margin-top: 8px;
}

.btn-tactical {
  background: #21262d;
  color: #6e7681;
  border-color: #30363d;
  font-size: 0.9em;
}

.btn-tactical:hover {
  background: #30363d;
  color: #8b949e;
}

/* ── Button click spark effect ───────────────────────────────────────────── */

@keyframes btn-spark {
  0% { transform: translate(var(--sx), var(--sy)) scale(1); opacity: 1; }
  100% { transform: translate(var(--ex), var(--ey)) scale(0); opacity: 0; }
}

.btn-spark {
  position: absolute;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  pointer-events: none;
  animation: btn-spark 0.5s ease-out forwards;
}

/* ── Strategy Selection ──────────────────────────────────────────────────── */

.strategy-panel {
  background: #0d1117;
  border: 1px solid #30363d;
  border-radius: 12px;
  padding: 24px;
  max-width: 500px;
  width: 90vw;
  text-align: center;
}

.strategy-panel h2 {
  color: #f0f6fc;
  margin-bottom: 8px;
}

.strategy-subtitle {
  color: #8b949e;
  font-size: 0.9em;
  margin-bottom: 16px;
}

.strategy-cards {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 16px;
}

.strategy-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: #161b22;
  border: 2px solid #21262d;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.15s;
  text-align: left;
}

.strategy-card:hover {
  border-color: #30363d;
  background: #1c2128;
}

.strategy-card.selected {
  border-color: #7b3aab;
  background: #1a1030;
}

.strategy-diagram {
  width: 60px;
  height: 60px;
  border-radius: 4px;
  flex-shrink: 0;
}

.strategy-card-info {
  flex: 1;
}

.strategy-card-name {
  font-weight: 600;
  color: #f0f6fc;
  font-size: 1em;
}

.strategy-card-desc {
  color: #8b949e;
  font-size: 0.8em;
  margin-top: 2px;
}

/* ── Game Layout ─────────────────────────────────────────────────────────── */

.game-layout {
  display: flex;
  width: 100%;
  height: 100vh;
  gap: 0;
}

.game-board-area {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #0d1117;
  min-width: 0;
  padding: 8px;
}

#game-canvas {
  max-width: 100%;
  max-height: 100%;
  border-radius: 4px;
}

.game-sidebar {
  width: 280px;
  min-width: 280px;
  max-width: 280px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 8px;
  overflow-y: auto;
  background: #161b22;
  border-left: 1px solid #21262d;
}

/* ── Panels ──────────────────────────────────────────────────────────────── */

.panel {
  background: #0d1117;
  border: 1px solid #21262d;
  border-radius: 6px;
  padding: 10px;
}

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-weight: 600;
  font-size: 0.9em;
  margin-bottom: 8px;
  padding-bottom: 6px;
  border-bottom: 1px solid #21262d;
}

/* ── Unit Selection ──────────────────────────────────────────────────────── */

.unit-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-height: 300px;
  overflow-y: auto;
}

.unit-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  background: #161b22;
  border: 1px solid #21262d;
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.15s;
  color: #c9d1d9;
  font-family: inherit;
  font-size: 0.85em;
  text-align: left;
}

.unit-btn:hover {
  background: #21262d;
  border-color: #30363d;
}

.unit-btn.selected {
  background: #1f3a1f;
  border-color: #238636;
}

.unit-btn-sprite {
  width: 32px;
  height: 32px;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

.unit-btn-symbol {
  font-size: 1.3em;
  font-weight: bold;
  font-family: monospace;
  width: 32px;
  text-align: center;
}

.unit-btn-info {
  display: flex;
  flex-direction: column;
  flex: 1;
}

.unit-btn-cost {
  font-size: 0.8em;
  color: #8b949e;
}

/* ── Unit Stats ──────────────────────────────────────────────────────────── */

.unit-stats {
  font-size: 0.8em;
  padding: 8px;
  background: #161b22;
  border-radius: 4px;
  margin-top: 6px;
  min-height: 80px;
}

.stat-name {
  font-weight: bold;
  font-size: 1.1em;
  margin-bottom: 4px;
}

.stat-row {
  display: flex;
  gap: 12px;
  margin-bottom: 2px;
  color: #8b949e;
}

.stat-special {
  margin-top: 4px;
  font-size: 0.95em;
  color: #d2a8ff;
}

/* ── Battle Controls ─────────────────────────────────────────────────────── */

.battle-controls {
  display: flex;
  gap: 6px;
  justify-content: flex-end;
}

/* ── Status Panel ────────────────────────────────────────────────────────── */

.status-faction {
  margin-bottom: 8px;
}

.status-header {
  font-weight: 600;
  font-size: 0.85em;
  margin-bottom: 4px;
}

.status-unit {
  display: flex;
  justify-content: space-between;
  font-size: 0.8em;
  padding: 2px 0;
  color: #8b949e;
}

.status-hp {
  font-family: monospace;
  font-size: 0.9em;
}

/* ── Game Log ────────────────────────────────────────────────────────────── */

.panel-log {
  flex: 1;
  min-height: 150px;
  display: flex;
  flex-direction: column;
}

.log-content {
  flex: 1;
  overflow-y: auto;
  font-size: 0.78em;
  font-family: 'Menlo', 'Consolas', monospace;
  line-height: 1.5;
  max-height: 250px;
}

.log-entry {
  padding: 1px 0;
  border-bottom: 1px solid rgba(33, 38, 45, 0.5);
}

.log-normal { color: #8b949e; }
.log-important { color: #f0f6fc; font-weight: bold; }
.log-death { color: #f85149; }
.log-crit { color: #f0883e; font-weight: bold; }
.log-spell { color: #bc8cff; }

.log-crown { border-left: 2px solid #4a90d9; padding-left: 4px; }
.log-horde { border-left: 2px solid #d94a4a; padding-left: 4px; }

/* ── Game Over Overlay ───────────────────────────────────────────────────── */

.overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.8);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 100;
}

.overlay-content {
  text-align: center;
  padding: 40px;
  background: #161b22;
  border: 1px solid #30363d;
  border-radius: 12px;
}

.overlay-content h2 {
  font-size: 2.5em;
  margin-bottom: 20px;
  color: #f0f6fc;
}

.battle-stats {
  margin-top: 16px;
  font-size: 0.45em;
  font-weight: normal;
}

.stats-row {
  display: flex;
  justify-content: center;
  gap: 40px;
  margin-bottom: 12px;
}

.stats-col {
  text-align: center;
}

.stats-label {
  font-weight: 600;
  font-size: 1.1em;
  margin-bottom: 4px;
}

.stats-value {
  color: #8b949e;
  margin: 2px 0;
}

.stats-mvp {
  color: #ffd700;
  margin-top: 8px;
  font-size: 1.05em;
}

.stats-turns {
  color: #484f58;
  margin-top: 6px;
  font-size: 0.9em;
}

.handoff-subtitle {
  color: #8b949e;
  font-style: italic;
  margin-bottom: 24px;
  font-size: 1.1em;
}

/* ── Scrollbar ───────────────────────────────────────────────────────────── */

::-webkit-scrollbar {
  width: 6px;
}

::-webkit-scrollbar-track {
  background: #0d1117;
}

::-webkit-scrollbar-thumb {
  background: #30363d;
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: #484f58;
}

/* ── Mobile ──────────────────────────────────────────────────────────────── */

@media (max-width: 768px) {
  .game-layout {
    flex-direction: column;
  }

  .game-board-area {
    flex: none;
    height: 50vh;
    padding: 4px;
  }

  .game-sidebar {
    width: 100%;
    min-width: 100%;
    max-width: 100%;
    flex: 1;
    border-left: none;
    border-top: 1px solid #21262d;
  }

  .welcome-content h1 {
    font-size: 0.75em;
  }

  .welcome-subtitle {
    font-size: 1.15em;
  }

  .welcome-content {
    max-width: 70vw;
    padding: 24px 18px;
  }

  .unit-list {
    flex-direction: row;
    flex-wrap: wrap;
    max-height: 120px;
  }

  .unit-btn {
    flex: 1;
    min-width: 100px;
  }

  .lobby-layout {
    padding: 12px;
  }
}

/* ── Blood Drip Transition ────────────────────────────────────────────────── */

#blood-transition {
  position: fixed !important;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  z-index: 9999;
  background: transparent;
  pointer-events: none;
  display: block !important;
}

#blood-transition.hidden {
  display: none !important;
}

#blood-canvas {
  width: 100%;
  height: 100%;
  display: block;
}

/* ── Auth Screen ─────────────────────────────────────────────────────────── */

#auth-screen {
  justify-content: center;
  align-items: center;
  background: linear-gradient(135deg, #0d1117 0%, #161b22 50%, #0d1117 100%);
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.input-field {
  padding: 10px 14px;
  font-size: 1em;
  background: #0d1117;
  border: 1px solid #30363d;
  border-radius: 6px;
  color: #c9d1d9;
  font-family: inherit;
}

.input-field:focus {
  outline: none;
  border-color: #238636;
}

.auth-error {
  color: #f85149;
  font-size: 0.85em;
  min-height: 1.2em;
}

/* ── Lobby Screen ────────────────────────────────────────────────────────── */

#lobby-screen {
  background: #0d1117;
  display: flex;
  flex-direction: column;
}

.lobby-layout {
  max-width: 600px;
  width: 100%;
  margin: 0 auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  overflow-y: auto;
  height: 100vh;
}

.lobby-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.lobby-header h2 {
  font-size: 1.4em;
  color: #f0f6fc;
}

.lobby-user {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.85em;
  color: #8b949e;
}

.lobby-panel {
  background: #161b22;
}

.new-game-form {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.new-game-form .input-field {
  flex: 1;
  min-width: 150px;
}

.game-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 300px;
  overflow-y: auto;
}

.game-card {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 12px;
  background: #0d1117;
  border: 1px solid #21262d;
  border-radius: 6px;
  cursor: pointer;
  transition: border-color 0.2s;
}

.game-card:hover {
  border-color: #30363d;
}

.game-card-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.game-card-opponent {
  font-weight: 600;
  color: #c9d1d9;
}

.game-card-status {
  font-size: 0.8em;
  color: #8b949e;
}

.badge {
  display: inline-block;
  padding: 1px 8px;
  border-radius: 10px;
  font-size: 0.75em;
  font-weight: 600;
}

.badge-ready {
  background: #238636;
  color: #fff;
  animation: pulse-badge 1.5s ease-in-out infinite;
}

.badge-deploy {
  background: #d29922;
  color: #fff;
}

.badge-waiting {
  background: #30363d;
  color: #8b949e;
}

.badge-completed {
  background: #21262d;
  color: #8b949e;
}

@keyframes pulse-badge {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.6; }
}

.invite-card {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 12px;
  background: #0d1117;
  border: 1px solid #21262d;
  border-radius: 6px;
}

.invite-actions {
  display: flex;
  gap: 6px;
}

.empty-state {
  color: #484f58;
  font-size: 0.85em;
  padding: 12px;
  text-align: center;
}
