@import url('https://fonts.googleapis.com/css2?family=Cinzel:wght@700;900&family=Rajdhani:wght@600;700;800&family=Orbitron:wght@700;900&display=swap');

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background-color: #050406;
  font-family: 'Rajdhani', sans-serif;
  color: #ffffff;
  touch-action: none;
}

#game-container {
  position: relative;
  width: 100%;
  height: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  background: #000000;
  overflow: hidden;
}

#gameCanvas {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #0b090e;
  image-rendering: -webkit-optimize-contrast;
  image-rendering: crisp-edges;
}

/* ==================== HUD OVERLAY ==================== */
#hud-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 18px 24px;
  z-index: 10;
}

/* Top Bar: Health, Names, Timer */
.top-hud {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  max-width: 1180px;
  margin: 0 auto;
}

/* Fighter Profile Card */
.fighter-hud {
  display: flex;
  align-items: center;
  gap: 14px;
  width: 42%;
}

.fighter-hud.enemy {
  flex-direction: row-reverse;
}

.avatar-frame {
  width: 54px;
  height: 54px;
  border-radius: 8px;
  background: linear-gradient(135deg, #1c1822, #0d0b10);
  border: 2px solid rgba(255, 75, 75, 0.4);
  box-shadow: 0 0 14px rgba(255, 60, 60, 0.3), inset 0 0 10px rgba(0, 0, 0, 0.8);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  flex-shrink: 0;
}

.fighter-hud.enemy .avatar-frame {
  border-color: rgba(255, 170, 40, 0.4);
  box-shadow: 0 0 14px rgba(255, 170, 40, 0.3), inset 0 0 10px rgba(0, 0, 0, 0.8);
}

.avatar-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  filter: drop-shadow(0 0 4px rgba(255, 255, 255, 0.15));
}

.bars-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.fighter-info {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
}

.fighter-hud.enemy .fighter-info {
  flex-direction: row-reverse;
}

.fighter-name {
  font-family: 'Cinzel', serif;
  font-weight: 900;
  font-size: 1.15rem;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: #fff;
  text-shadow: 0 0 10px rgba(255, 255, 255, 0.4);
}

.round-dots {
  display: flex;
  gap: 6px;
}

.round-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  border: 1.5px solid rgba(255, 255, 255, 0.4);
  background: rgba(0, 0, 0, 0.6);
  transition: all 0.3s ease;
}

.round-dot.won {
  background: #ff3344;
  border-color: #ff8899;
  box-shadow: 0 0 8px #ff3344;
}

.fighter-hud.enemy .round-dot.won {
  background: #ffaa22;
  border-color: #ffdd77;
  box-shadow: 0 0 8px #ffaa22;
}

/* Health Bar Base */
.health-bar-track {
  position: relative;
  width: 100%;
  height: 20px;
  background: rgba(12, 10, 16, 0.85);
  border: 2px solid rgba(255, 255, 255, 0.4);
  border-radius: 4px;
  overflow: hidden;
  box-shadow: inset 0 2px 6px rgba(0, 0, 0, 0.9), 0 0 15px rgba(255, 255, 255, 0.2);
  transform: skewX(-12deg);
}

.fighter-hud.enemy .health-bar-track {
  transform: skewX(12deg);
}

/* Lag Damage Bar (Red trail behind green/gold health) */
.health-bar-lag {
  position: absolute;
  top: 0;
  height: 100%;
  background: #aa1122;
  width: 100%;
  transition: width 0.4s cubic-bezier(0.25, 1, 0.5, 1);
}

.fighter-hud.player .health-bar-lag {
  left: 0;
}

.fighter-hud.enemy .health-bar-lag {
  right: 0;
}

/* Active Fill Bar */
.health-bar-fill {
  position: absolute;
  top: 0;
  height: 100%;
  width: 100%;
  transition: width 0.1s linear;
}

.fighter-hud.player .health-bar-fill {
  left: 0;
  background: linear-gradient(90deg, #ff2233 0%, #ff5566 40%, #ff7788 100%);
  box-shadow: 0 0 10px rgba(255, 40, 60, 0.7);
}

.fighter-hud.enemy .health-bar-fill {
  right: 0;
  background: linear-gradient(270deg, #ff8800 0%, #ffaa22 40%, #ffcc44 100%);
  box-shadow: 0 0 10px rgba(255, 160, 30, 0.7);
}

/* Center Timer & Round Info */
.timer-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: radial-gradient(circle, rgba(28, 22, 34, 0.9) 0%, rgba(10, 8, 14, 0.95) 100%);
  border: 2px solid rgba(255, 200, 100, 0.4);
  box-shadow: 0 0 20px rgba(255, 80, 50, 0.3), inset 0 0 10px rgba(0, 0, 0, 0.9);
  width: 74px;
  height: 74px;
  border-radius: 50%;
  margin: 0 12px;
  flex-shrink: 0;
}

#round-timer {
  font-family: 'Orbitron', monospace;
  font-size: 1.9rem;
  font-weight: 900;
  color: #fff;
  line-height: 1;
  text-shadow: 0 0 12px rgba(255, 255, 255, 0.8);
}

#round-timer.urgent {
  color: #ff3344;
  animation: pulseTimer 0.6s infinite alternate;
}

@keyframes pulseTimer {
  0% { transform: scale(1); text-shadow: 0 0 8px #ff3344; }
  100% { transform: scale(1.18); text-shadow: 0 0 22px #ff0022; }
}

.round-banner {
  font-family: 'Cinzel', serif;
  font-size: 0.75rem;
  font-weight: 700;
  color: #ffbb66;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  margin-top: 2px;
}

/* Floating Combo / Status Text */
#combo-container {
  position: absolute;
  top: 110px;
  left: 40px;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  pointer-events: none;
  transition: opacity 0.3s ease;
  opacity: 0;
}

#combo-container.active {
  opacity: 1;
}

.combo-hits {
  font-family: 'Orbitron', monospace;
  font-size: 3rem;
  font-weight: 900;
  font-style: italic;
  color: #fff;
  background: linear-gradient(180deg, #ffffff 0%, #ffaa00 50%, #ff2200 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  filter: drop-shadow(0 0 14px rgba(255, 80, 0, 0.8));
  line-height: 1;
  animation: comboPop 0.2s cubic-bezier(0.18, 0.89, 0.32, 1.28);
}

.combo-label {
  font-family: 'Cinzel', serif;
  font-size: 1.2rem;
  font-weight: 900;
  letter-spacing: 3px;
  color: #ffcc55;
  text-shadow: 0 0 8px rgba(0, 0, 0, 0.9);
}

@keyframes comboPop {
  0% { transform: scale(1.4) rotate(-4deg); }
  100% { transform: scale(1) rotate(0deg); }
}

/* Middle Announcer Banner (e.g. ROUND 1, FIGHT!, K.O.!) */
#announcer-text {
  position: absolute;
  top: 40%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0.5);
  font-family: 'Cinzel', serif;
  font-size: 4.5rem;
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: 6px;
  color: #fff;
  background: linear-gradient(180deg, #ffffff 0%, #ffcc44 40%, #ff2233 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  filter: drop-shadow(0 0 24px rgba(255, 50, 0, 0.95)) drop-shadow(0 4px 10px rgba(0, 0, 0, 0.9));
  pointer-events: none;
  opacity: 0;
  transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  z-index: 50;
  text-align: center;
  white-space: nowrap;
}

#announcer-text.show {
  opacity: 1;
  transform: translate(-50%, -50%) scale(1);
}

/* Controls Hint Bar at Bottom (Desktop) */
#controls-hint {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 16px;
  background: rgba(10, 8, 14, 0.75);
  backdrop-filter: blur(8px);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 20px;
  padding: 6px 20px;
  margin: 0 auto;
  font-size: 0.88rem;
  letter-spacing: 1px;
  color: rgba(255, 255, 255, 0.75);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.6);
}

.key-tag {
  display: inline-block;
  background: rgba(255, 255, 255, 0.15);
  border: 1px solid rgba(255, 255, 255, 0.3);
  border-radius: 4px;
  padding: 1px 6px;
  font-weight: 700;
  color: #ffcc55;
  margin-right: 4px;
}

/* Top Toolbar: Pause & Audio */
.hud-toolbar {
  position: absolute;
  top: 16px;
  right: 24px;
  display: flex;
  gap: 10px;
  pointer-events: auto;
  z-index: 25;
}

.icon-btn {
  background: rgba(18, 15, 24, 0.8);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 8px;
  color: #fff;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 1.2rem;
  transition: all 0.2s ease;
  backdrop-filter: blur(6px);
}

.icon-btn:hover {
  background: rgba(255, 50, 70, 0.3);
  border-color: #ff4455;
  transform: scale(1.06);
}

/* ==================== MOBILE TOUCH CONTROLS (LANDSCAPE & COMPACT) ==================== */
#touch-controls {
  position: absolute;
  bottom: 12px;
  left: 0;
  width: 100%;
  height: auto;
  pointer-events: none;
  display: none;
  justify-content: space-between;
  align-items: flex-end;
  padding: 0 max(20px, env(safe-area-inset-right)) 8px max(20px, env(safe-area-inset-left));
  z-index: 30;
}

/* Show touch controls on touch-capable devices */
@media (pointer: coarse), (max-width: 900px) {
  #touch-controls {
    display: flex;
  }
  #controls-hint {
    display: none;
  }
}

.touch-cluster {
  display: flex;
  pointer-events: auto;
}

/* D-Pad Cross (Left Hand) */
.dpad-cross {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.dpad-mid {
  display: flex;
  align-items: center;
  gap: 8px;
}

.dpad-center {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.05);
  border: 1px dashed rgba(255, 255, 255, 0.15);
}

/* Action Buttons Cluster (Right Hand Arc) */
.actions-cluster {
  display: flex;
  align-items: flex-end;
  gap: 14px;
}

/* Base Touch Button Styling */
.touch-btn {
  width: 58px;
  height: 58px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, rgba(38, 30, 52, 0.88) 0%, rgba(14, 11, 20, 0.94) 100%);
  border: 2px solid rgba(255, 255, 255, 0.3);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.75), inset 0 2px 6px rgba(255, 255, 255, 0.15);
  color: #ffffff;
  font-family: 'Rajdhani', sans-serif;
  font-weight: 800;
  font-size: 1.05rem;
  letter-spacing: 1px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(10px);
  cursor: pointer;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  transition: transform 0.08s ease, background 0.08s ease, border-color 0.08s ease, box-shadow 0.08s ease;
}

.touch-btn:active, .touch-btn.active {
  transform: scale(0.90);
  box-shadow: 0 0 20px rgba(255, 50, 70, 0.9);
}

.touch-btn.punch {
  width: 64px;
  height: 64px;
  border-color: rgba(255, 65, 75, 0.7);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.8), 0 0 10px rgba(255, 50, 60, 0.3);
}

.touch-btn.punch:active, .touch-btn.punch.active {
  background: rgba(255, 40, 60, 0.65);
  border-color: #ff2233;
}

.touch-btn.kick {
  width: 62px;
  height: 62px;
  border-color: rgba(255, 170, 40, 0.7);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.8), 0 0 10px rgba(255, 160, 30, 0.3);
}

.touch-btn.kick:active, .touch-btn.kick.active {
  background: rgba(255, 160, 30, 0.65);
  border-color: #ffaa22;
}

.touch-btn.block {
  width: 56px;
  height: 56px;
  border-color: rgba(70, 165, 255, 0.7);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.8), 0 0 10px rgba(50, 150, 255, 0.3);
}

.touch-btn.block:active, .touch-btn.block.active {
  background: rgba(40, 140, 255, 0.65);
  border-color: #3399ff;
}

/* ==================== COMPACT MOBILE LANDSCAPE ADAPTATION ==================== */
@media screen and (max-height: 540px) {
  #hud-overlay {
    padding: 6px 14px;
  }

  .avatar-frame {
    width: 38px;
    height: 38px;
    border-radius: 6px;
  }

  .fighter-name {
    font-size: 0.95rem;
    letter-spacing: 1.2px;
  }

  .health-bar-track {
    height: 13px;
  }

  .timer-container {
    width: 52px;
    height: 52px;
    margin: 0 6px;
  }

  #round-timer {
    font-size: 1.35rem;
  }

  .round-banner {
    font-size: 0.62rem;
    letter-spacing: 1px;
  }

  .round-dot {
    width: 7px;
    height: 7px;
  }

  .hud-toolbar {
    top: 6px;
    right: 12px;
    gap: 6px;
  }

  .icon-btn {
    width: 32px;
    height: 32px;
    font-size: 0.95rem;
  }

  .touch-btn {
    width: 48px;
    height: 48px;
    font-size: 0.88rem;
  }

  .touch-btn.punch {
    width: 54px;
    height: 54px;
  }

  .touch-btn.kick {
    width: 52px;
    height: 52px;
  }

  .touch-btn.block {
    width: 46px;
    height: 46px;
  }

  .dpad-center {
    width: 18px;
    height: 18px;
  }

  #touch-controls {
    bottom: 6px;
  }
}

/* ==================== PORTRAIT ROTATE PROMPT ==================== */
#rotate-prompt {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: radial-gradient(circle at center, rgba(26, 20, 36, 0.98) 0%, rgba(6, 4, 8, 0.99) 100%);
  backdrop-filter: blur(16px);
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  text-align: center;
  padding: 30px;
}

/* Shown via JS (.is-portrait) so CSS landscape-fallback iframes don't false-trigger */
#rotate-prompt.is-portrait {
  display: flex;
}

.rotate-phone-icon {
  animation: rotatePhone 2.2s infinite ease-in-out;
  margin-bottom: 24px;
  filter: drop-shadow(0 0 16px rgba(255, 50, 70, 0.7));
}

@keyframes rotatePhone {
  0% { transform: rotate(0deg); }
  35% { transform: rotate(-90deg); }
  65% { transform: rotate(-90deg); }
  100% { transform: rotate(0deg); }
}

.rotate-title {
  font-family: 'Cinzel', serif;
  font-size: 1.8rem;
  font-weight: 900;
  letter-spacing: 3px;
  color: #ffffff;
  margin-bottom: 10px;
  text-shadow: 0 0 14px rgba(255, 50, 70, 0.6);
}

.rotate-desc {
  font-size: 1.1rem;
  color: rgba(255, 255, 255, 0.75);
  max-width: 280px;
  line-height: 1.4;
  letter-spacing: 1px;
}

/* ==================== MODAL SCREENS ==================== */
.modal-overlay {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  background: rgba(4, 3, 6, 0.85);
  backdrop-filter: blur(12px);
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: max(10px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) max(10px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
  box-sizing: border-box;
  pointer-events: auto;
  touch-action: manipulation;
  animation: modalFadeIn 0.3s cubic-bezier(0.2, 0.9, 0.3, 1);
}

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

/* Keep touch pads from intercepting pause/result taps */
body.is-modal-open #touch-controls,
body.is-modal-open .hud-toolbar {
  visibility: hidden;
  pointer-events: none;
}

/* Result/pause modals are desktop-only on phones (JS auto-rematch / toolbar toggle) */
@media (pointer: coarse), (max-width: 900px), (max-height: 540px) {
  #pause-modal,
  #pause-modal.active,
  #game-over-modal,
  #game-over-modal.active {
    display: none !important;
    pointer-events: none !important;
  }

  /* Never lock mobile controls behind a hidden modal */
  body.is-modal-open #touch-controls,
  body.is-modal-open .hud-toolbar {
    visibility: visible;
    pointer-events: auto;
  }
}

@keyframes modalFadeIn {
  0% { opacity: 0; }
  100% { opacity: 1; }
}

.modal-card {
  background: radial-gradient(circle at center top, rgba(32, 25, 45, 0.95), rgba(12, 10, 18, 0.98));
  border: 2px solid rgba(255, 200, 100, 0.35);
  box-shadow: 0 0 35px rgba(255, 70, 30, 0.35), 0 10px 40px rgba(0, 0, 0, 0.9);
  border-radius: 16px;
  padding: 36px 48px;
  text-align: center;
  max-width: 520px;
  width: min(92vw, 520px);
  max-height: min(92dvh, 100%);
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

.modal-title {
  font-family: 'Cinzel', serif;
  font-size: clamp(1.55rem, 5vw, 2.8rem);
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: 4px;
  margin-bottom: 12px;
  line-height: 1.1;
  color: #fff;
}

.modal-title.victory {
  background: linear-gradient(180deg, #ffffff 0%, #ffcc44 50%, #ff7700 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  filter: drop-shadow(0 0 16px rgba(255, 180, 0, 0.7));
}

.modal-title.defeat {
  background: linear-gradient(180deg, #ffffff 0%, #ff4455 50%, #880011 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  filter: drop-shadow(0 0 16px rgba(255, 30, 50, 0.7));
}

.modal-subtitle {
  font-size: clamp(0.95rem, 2.6vw, 1.25rem);
  color: rgba(255, 255, 255, 0.85);
  margin-bottom: 24px;
  letter-spacing: 1.5px;
}

.stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  margin-bottom: 28px;
  background: rgba(0, 0, 0, 0.4);
  padding: 16px;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.stat-item {
  display: flex;
  flex-direction: column;
}

.stat-label {
  font-size: 0.85rem;
  color: rgba(255, 255, 255, 0.6);
  letter-spacing: 1px;
  text-transform: uppercase;
}

.stat-val {
  font-family: 'Orbitron', monospace;
  font-size: 1.5rem;
  font-weight: 700;
  color: #ffcc55;
  margin-top: 2px;
}

.modal-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  justify-content: center;
}

.btn-primary {
  background: linear-gradient(135deg, #ff3344 0%, #cc1122 100%);
  border: 1px solid #ff7788;
  box-shadow: 0 0 18px rgba(255, 40, 60, 0.6);
  color: #fff;
  font-family: 'Rajdhani', sans-serif;
  font-weight: 800;
  font-size: 1.25rem;
  letter-spacing: 2px;
  text-transform: uppercase;
  padding: 12px 32px;
  min-height: 48px;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s ease;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.btn-primary:hover {
  transform: translateY(-2px) scale(1.03);
  box-shadow: 0 0 28px rgba(255, 40, 60, 0.9);
}

.btn-secondary {
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.25);
  color: #fff;
  font-family: 'Rajdhani', sans-serif;
  font-weight: 700;
  font-size: 1.15rem;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  padding: 12px 26px;
  min-height: 48px;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s ease;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.btn-secondary:hover {
  background: rgba(255, 255, 255, 0.2);
  border-color: rgba(255, 255, 255, 0.4);
}

/* Compact pause / result UI for mobile + short landscape */
@media screen and (max-height: 540px), screen and (max-width: 720px) {
  .modal-card {
    padding: 18px 20px 20px;
    border-radius: 14px;
    width: min(92vw, 380px);
    text-align: center;
  }

  .modal-title {
    font-size: clamp(1.35rem, 5vh, 1.85rem);
    letter-spacing: 2px;
    margin-bottom: 8px;
  }

  .modal-subtitle {
    font-size: 0.95rem;
    margin-bottom: 16px;
    letter-spacing: 0.8px;
  }

  .stats-grid {
    gap: 8px;
    margin-bottom: 14px;
    padding: 10px;
  }

  .stat-label { font-size: 0.72rem; }
  .stat-val { font-size: 1.15rem; }

  .modal-actions {
    gap: 10px;
    flex-wrap: nowrap;
  }

  .btn-primary,
  .btn-secondary {
    flex: 1 1 0;
    font-size: 1rem;
    letter-spacing: 1px;
    padding: 10px 14px;
    min-height: 44px;
  }
}

@media screen and (orientation: landscape) and (max-height: 400px) {
  .modal-card {
    padding: 12px 16px 14px;
    width: min(70vw, 420px);
  }

  .modal-title {
    font-size: 1.25rem;
    margin-bottom: 4px;
  }

  .modal-subtitle {
    font-size: 0.85rem;
    margin-bottom: 10px;
  }

  .modal-actions {
    gap: 8px;
  }

  .btn-primary,
  .btn-secondary {
    min-height: 40px;
    padding: 8px 12px;
    font-size: 0.95rem;
  }
}
