* {
  box-sizing: border-box;
}

:root {
  --bg: #090b14;
  --panel: #121827;
  --panel-2: #1f2937;
  --text: #f8fafc;
  --muted: #94a3b8;
  --accent: #facc15;
  --danger: #ef4444;
  --good: #22c55e;
  --blue: #38bdf8;
  --purple: #a855f7;
  --orange: #f97316;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at top, rgba(56, 189, 248, 0.12), transparent 35%),
    linear-gradient(135deg, #05060d 0%, #111827 55%, #05060d 100%);
  color: var(--text);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  overflow-x: hidden;
}

/* Loading Screen */
.loading-screen {
  display: none;
  place-items: center;
  justify-items: center;
}

.loading-screen.active {
  display: grid;
}

.loading-container {
  text-align: center;
  padding: 40px;
}

.loading-title {
  font-size: clamp(2rem, 6vw, 4rem);
  color: var(--accent);
  text-shadow: 0 0 30px rgba(250, 204, 21, 0.5);
  animation: pulse 1.5s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.8; transform: scale(1.02); }
}

.loading-bar-container {
  width: 300px;
  height: 8px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 4px;
  overflow: hidden;
  margin: 24px auto;
}

.loading-bar {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--accent), var(--orange));
  border-radius: 4px;
  transition: width 0.3s ease;
  box-shadow: 0 0 20px rgba(250, 204, 21, 0.6);
}

.loading-text {
  color: var(--muted);
  font-size: 0.9rem;
}

button {
  border: 0;
  cursor: pointer;
  font-weight: 800;
  letter-spacing: 0.02em;
  transition: all 0.2s ease;
}

button:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.3);
}

button:active:not(:disabled) {
  transform: translateY(0);
}

.screen {
  display: none;
  width: 100%;
  min-height: 100vh;
  padding: 24px;
}

.screen.active {
  display: block;
}

.menu-screen {
  display: none;
  place-items: center;
}

.menu-screen.active {
  display: grid;
}

.menu-card {
  width: min(560px, 92vw);
  padding: 36px;
  background: rgba(15, 23, 42, 0.88);
  border: 2px solid rgba(250, 204, 21, 0.5);
  border-radius: 28px;
  box-shadow: 0 30px 100px rgba(0, 0, 0, 0.45);
  text-align: center;
}

.eyebrow {
  color: var(--accent);
  font-size: 0.82rem;
  text-transform: uppercase;
  letter-spacing: 0.18em;
  margin: 0 0 10px;
}

h1, h2, h3 {
  margin: 0;
}

h1 {
  font-size: clamp(2.4rem, 8vw, 5.2rem);
  line-height: 0.9;
  text-shadow: 4px 4px 0 #000;
}

h2 {
  font-size: clamp(2rem, 5vw, 3.4rem);
}

.subtitle {
  color: var(--muted);
  margin: 16px 0 28px;
}

.menu-buttons {
  display: grid;
  gap: 12px;
}

.menu-buttons button,
.primary-btn,
.ghost-btn {
  padding: 14px 18px;
  border-radius: 16px;
  font-size: 1rem;
}

.menu-buttons button {
  background: #263244;
  color: white;
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.primary-btn {
  background: linear-gradient(135deg, #facc15, #f97316);
  color: #111827;
  box-shadow: 0 10px 30px rgba(250, 204, 21, 0.25);
}

.primary-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.ghost-btn {
  background: rgba(255, 255, 255, 0.08);
  color: white;
  border: 1px solid rgba(255, 255, 255, 0.14);
}

.small-message {
  color: var(--muted);
  min-height: 22px;
}

.select-header,
.fight-topbar {
  width: min(1180px, 96vw);
  margin: 0 auto 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
}

.select-layout {
  width: min(1180px, 96vw);
  margin: 0 auto;
  display: grid;
  grid-template-columns: 1fr 340px;
  gap: 20px;
}

.character-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 14px;
}

.character-card {
  min-height: 170px;
  padding: 14px;
  background: rgba(15, 23, 42, 0.88);
  border: 2px solid rgba(148, 163, 184, 0.22);
  border-radius: 22px;
  color: white;
  text-align: left;
  transition: transform 0.12s ease, border 0.12s ease, background 0.12s ease;
}

.character-card:hover,
.character-card.selected {
  transform: translateY(-4px);
  border-color: var(--accent);
  background: rgba(30, 41, 59, 0.96);
}

.pixel-portrait,
.portrait-large {
  display: grid;
  place-items: center;
  image-rendering: pixelated;
  font-weight: 1000;
  text-shadow: 2px 2px 0 #000;
  border: 3px solid rgba(255, 255, 255, 0.18);
  box-shadow: inset 0 -10px 0 rgba(0,0,0,0.22);
}

.pixel-portrait {
  width: 70px;
  height: 70px;
  margin-bottom: 12px;
  border-radius: 14px;
  font-size: 1.3rem;
}

.card-name {
  font-weight: 900;
  margin-bottom: 6px;
}

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

.info-panel {
  position: sticky;
  top: 20px;
  align-self: start;
  background: rgba(15, 23, 42, 0.92);
  border: 2px solid rgba(250, 204, 21, 0.28);
  border-radius: 26px;
  padding: 20px;
  min-height: 570px;
}

.portrait-large {
  width: 128px;
  height: 128px;
  border-radius: 24px;
  font-size: 2rem;
  margin-bottom: 18px;
}

.tag {
  color: var(--accent);
  font-weight: 800;
}

#infoDescription {
  color: #cbd5e1;
  line-height: 1.5;
}

.info-row {
  display: grid;
  grid-template-columns: 92px 1fr;
  gap: 10px;
  padding: 10px 0;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  color: #cbd5e1;
}

.info-panel .primary-btn {
  width: 100%;
  margin-top: 18px;
}

/* Secondary button style */
.secondary-btn {
  background: linear-gradient(135deg, #38bdf8, #2563eb);
  color: #111827;
  box-shadow: 0 10px 30px rgba(56, 189, 248, 0.25);
}

/* Stats display in character select */
.stats-display {
  margin: 16px 0;
  padding: 12px;
  background: rgba(0, 0, 0, 0.3);
  border-radius: 12px;
}

.stat-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
  font-size: 0.85rem;
}

.stat-row:last-child {
  margin-bottom: 0;
}

.stat-bar {
  flex: 1;
  height: 8px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 4px;
  overflow: hidden;
}

.stat-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--orange));
  border-radius: 4px;
  transition: width 0.4s ease;
}

/* Fight screen enhancements */
.fight-screen {
  padding-top: 16px;
}

.fight-title {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 10px 24px;
  background: rgba(15, 23, 42, 0.9);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 999px;
  font-weight: 900;
}

.vs-badge {
  color: var(--danger);
  font-size: 0.9em;
}

.round-timer {
  padding: 8px 16px;
  background: rgba(250, 204, 21, 0.15);
  border: 1px solid var(--accent);
  border-radius: 8px;
  font-weight: 900;
  color: var(--accent);
  font-size: 1.1rem;
}

#gameCanvas {
  display: block;
  width: min(960px, 96vw);
  height: auto;
  margin: 0 auto;
  background: #000000;
  border: 3px solid rgba(250, 204, 21, 0.5);
  border-radius: 22px;
  box-shadow: 0 25px 70px rgba(0,0,0,0.45);
  image-rendering: pixelated;
}

/* Fight overlay for combo display */
.fight-overlay {
  position: relative;
  width: min(960px, 96vw);
  margin: 0 auto;
  height: 0;
  pointer-events: none;
}

.combo-display {
  position: absolute;
  top: -280px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 2.5rem;
  font-weight: 900;
  color: var(--accent);
  text-shadow: 0 0 20px rgba(250, 204, 21, 0.8);
  opacity: 0;
  transition: opacity 0.2s ease;
}

.combo-display.active {
  opacity: 1;
  animation: comboPulse 0.3s ease;
}

@keyframes comboPulse {
  0% { transform: translateX(-50%) scale(0.8); }
  50% { transform: translateX(-50%) scale(1.1); }
  100% { transform: translateX(-50%) scale(1); }
}

.hit-counter {
  position: absolute;
  top: -240px;
  right: calc(50% - 480px);
  font-size: 1.2rem;
  font-weight: 800;
  color: var(--danger);
  background: rgba(0, 0, 0, 0.7);
  padding: 6px 12px;
  border-radius: 8px;
  border: 1px solid var(--danger);
}

/* Control key styling */
.control-key {
  display: inline-block;
  background: rgba(255, 255, 255, 0.15);
  padding: 2px 8px;
  border-radius: 4px;
  font-weight: 700;
  color: var(--accent);
  border: 1px solid rgba(250, 204, 21, 0.3);
}

.controls-box,
.fight-log {
  width: min(960px, 96vw);
  margin: 12px auto 0;
  padding: 12px 14px;
  border-radius: 16px;
  background: rgba(15, 23, 42, 0.82);
  color: #cbd5e1;
  border: 1px solid rgba(255,255,255,0.08);
}

.fight-log {
  color: var(--accent);
  font-weight: 800;
  min-height: 46px;
}

/* Modal overlays */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.85);
  display: none;
  place-items: center;
  justify-items: center;
  z-index: 1000;
  backdrop-filter: blur(4px);
}

.modal-overlay.active {
  display: grid;
}

.modal-card,
.results-card {
  background: rgba(15, 23, 42, 0.98);
  border: 2px solid var(--accent);
  border-radius: 28px;
  padding: 36px;
  text-align: center;
  max-width: 500px;
  width: 92vw;
  box-shadow: 0 30px 100px rgba(0, 0, 0, 0.6);
}

.difficulty-buttons {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  margin: 24px 0;
}

.difficulty-btn {
  padding: 16px 20px;
  border-radius: 12px;
  font-size: 1rem;
  font-weight: 800;
  color: white;
  border: 2px solid transparent;
}

.difficulty-btn.easy {
  background: linear-gradient(135deg, #22c55e, #16a34a);
}

.difficulty-btn.medium {
  background: linear-gradient(135deg, #facc15, #f97316);
  color: #111827;
}

.difficulty-btn.hard {
  background: linear-gradient(135deg, #ef4444, #dc2626);
}

.difficulty-btn.expert {
  background: linear-gradient(135deg, #a855f7, #7c3aed);
}

.difficulty-btn:hover {
  transform: translateY(-3px);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
}

/* Results screen */
.winner-display {
  margin: 24px 0;
}

.winner-portrait {
  width: 100px;
  height: 100px;
  border-radius: 50%;
  margin: 0 auto 16px;
  border: 4px solid var(--accent);
  display: grid;
  place-items: center;
  font-size: 2.5rem;
  font-weight: 900;
  text-shadow: 2px 2px 0 #000;
  background: linear-gradient(135deg, var(--accent), var(--orange));
}

#winnerName {
  font-size: clamp(1.8rem, 5vw, 2.8rem);
  color: var(--accent);
  text-shadow: 0 0 30px rgba(250, 204, 21, 0.5);
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 16px;
  margin: 24px 0;
}

.stat-box {
  background: rgba(255, 255, 255, 0.05);
  padding: 16px;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.stat-label {
  display: block;
  color: var(--muted);
  font-size: 0.85rem;
  margin-bottom: 6px;
}

.stat-value {
  display: block;
  font-size: 1.8rem;
  font-weight: 900;
  color: var(--accent);
}

.results-buttons {
  display: grid;
  gap: 12px;
  margin-top: 24px;
}

@media (max-width: 900px) {
  .select-layout {
    grid-template-columns: 1fr;
  }
  .info-panel {
    position: static;
  }
  .fight-topbar {
    flex-wrap: wrap;
    justify-content: center;
  }
  .hit-counter {
    right: auto;
    left: calc(50% + 240px);
  }
}
