*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background-color: #111;
  touch-action: none;
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

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

#hud.hidden {
  display: none;
}

#hud {
  position: absolute;
  top: 16px;
  left: 0;
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: 0 16px;
  pointer-events: none;
  gap: 12px;
}

.fighter-panel {
  width: 34%;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.fighter-panel .name {
  color: #fff;
  font-size: 14px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.8);
}

.fighter-panel.opponent .name {
  text-align: right;
}

.bar {
  width: 100%;
  height: 16px;
  background: rgba(0, 0, 0, 0.6);
  border: 2px solid #ffffff;
  border-radius: 4px;
  overflow: hidden;
}

.bar .fill {
  width: 100%;
  height: 100%;
  transition: width 0.1s linear;
}

.health-bar .fill {
  background: #e63946;
}

.stamina-bar .fill {
  background: #facc15;
}

.fighter-panel.opponent .health-bar .fill {
  background: #3b82f6;
}

.hud-info {
  font-size: 12px;
  font-weight: 600;
  color: #e5e5e5;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.8);
}

.fighter-panel.opponent .hud-info {
  text-align: right;
}

.center-panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  color: #fff;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.9);
}

#round-label {
  font-size: 14px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
}

#round-timer {
  font-size: 36px;
  font-weight: 900;
  line-height: 1;
  margin-top: 2px;
}

#round-score {
  margin-top: 4px;
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.15em;
  color: #facc15;
}

#round-message {
  margin-top: 6px;
  font-size: 18px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  min-height: 24px;
  opacity: 0;
  transition: opacity 0.2s linear;
}

#round-message.active {
  opacity: 1;
}

#round-stats {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 25;
  width: min(340px, 86vw);
  background: rgba(10, 10, 18, 0.9);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 12px;
  padding: 20px 24px;
  color: #fff;
  text-align: center;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.6);
  cursor: pointer;
}

#round-stats.hidden {
  display: none;
}

.round-stats-title {
  font-size: 20px;
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 14px;
  color: #facc15;
}

.round-stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px 16px;
}

.round-stats-header {
  font-size: 14px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding-bottom: 4px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.2);
}

.round-stats-header.player {
  color: #e63946;
}

.round-stats-header.opponent {
  color: #3b82f6;
}

.round-stats-value {
  font-size: 14px;
  font-weight: 600;
  color: #e5e5e5;
}

.round-stats-skip {
  margin-top: 10px;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: rgba(255, 255, 255, 0.45);
  text-align: center;
  animation: pulse-stamina 1.2s ease-in-out infinite;
}

#joystick-zone {
  position: absolute;
  top: 0;
  left: 0;
  width: 50%;
  height: 100%;
  touch-action: none;
  z-index: 5;
}

#joystick {
  position: absolute;
  bottom: 30px;
  left: 30px;
  width: 120px;
  height: 120px;
  pointer-events: none;
  touch-action: none;
  user-select: none;
  opacity: 0;
  z-index: 6;
}

/* Floating joystick: only visible while the thumb is down. */
#joystick.active {
  opacity: 1;
}

#joystick-base {
  position: absolute;
  width: 100%;
  height: 100%;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.15);
  border: 2px solid rgba(255, 255, 255, 0.4);
}

#joystick-knob {
  position: absolute;
  width: 50%;
  height: 50%;
  top: 25%;
  left: 25%;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.5);
  transform: translate(0, 0);
  transition: transform 0.05s linear;
}

#damage-flash {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.05s linear;
  z-index: 10;
}

#damage-flash.active {
  opacity: 1;
}

.stamina-bar .fill.low {
  background: #f97316;
  animation: pulse-stamina 0.6s ease-in-out infinite;
}

.stamina-bar .fill.empty {
  background: #ef4444;
  animation: none;
}

@keyframes pulse-stamina {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.65; }
}

#round-timer.critical {
  color: #ef4444;
  animation: pulse-timer 0.5s ease-in-out infinite;
}

#round-timer.urgent {
  color: #ef4444;
  animation: pulse-timer 0.25s ease-in-out infinite;
}

@keyframes pulse-timer {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.1); }
}

.overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.78);
  z-index: 30;
  opacity: 1;
  transition: opacity 0.3s ease;
}

.overlay.hidden {
  opacity: 0;
  pointer-events: none;
}

.back-button {
  position: absolute;
  top: 16px;
  left: 16px;
  z-index: 35;
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 80px;
  min-height: 44px;
  padding: 8px 12px;
  font-size: 14px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: #e5e5e5;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.25);
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.1s ease;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}

.back-button:hover {
  background: rgba(255, 255, 255, 0.2);
}

.back-button:active {
  transform: scale(0.96);
}

@media (max-width: 768px) {
  .back-button {
    top: 12px;
    left: 12px;
    min-width: 72px;
    min-height: 44px;
    font-size: 13px;
  }
}

.overlay-content {
  text-align: center;
  color: #fff;
  padding: 32px;
}

.overlay-subtitle {
  font-size: 18px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: #a3a3a3;
}

.overlay-title {
  font-size: 52px;
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-top: 8px;
  text-shadow: 0 4px 16px rgba(0, 0, 0, 0.9);
}

.overlay-title.win {
  color: #22c55e;
}

.overlay-title.loss {
  color: #ef4444;
}

.overlay-title.draw {
  color: #facc15;
}

.overlay-description {
  font-size: 20px;
  font-weight: 500;
  color: #e5e5e5;
  margin-top: 12px;
}

.overlay-points {
  font-size: 24px;
  font-weight: 800;
  color: #facc15;
  margin-top: 20px;
}

.match-result-actions {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  margin-top: 24px;
}

.match-result-actions .primary-button,
.match-result-actions .secondary-button {
  margin: 0;
  width: 100%;
  max-width: 240px;
  min-height: 48px;
}

.primary-button {
  margin-top: 28px;
  padding: 14px 40px;
  font-size: 18px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #111;
  background: #facc15;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
  transition: transform 0.1s ease, background 0.1s ease;
}

.primary-button:hover {
  background: #fde047;
  transform: scale(1.05);
}

.primary-button:active {
  transform: scale(0.98);
}

.continue-campaign-button {
  margin-top: 12px;
  background: #22c55e;
  color: #fff;
}

.continue-campaign-button:hover {
  background: #16a34a;
}

.hidden {
  display: none !important;
}

.secondary-button {
  display: block;
  margin: 14px auto 0;
  padding: 10px 28px;
  font-size: 14px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #e5e5e5;
  background: transparent;
  border: 2px solid rgba(255, 255, 255, 0.4);
  border-radius: 8px;
  cursor: pointer;
  transition: border-color 0.1s ease, color 0.1s ease;
}

.secondary-button:hover {
  border-color: #fff;
  color: #fff;
}

.menu-stats {
  margin: 32px auto 0;
  width: min(280px, 80vw);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.menu-stat {
  display: flex;
  justify-content: space-between;
  font-size: 15px;
  font-weight: 600;
  color: #e5e5e5;
}

.menu-stat span:last-child {
  color: #facc15;
  font-weight: 800;
}

#roster-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 10px;
  margin: 24px auto 0;
  width: min(360px, 86vw);
}

.roster-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 6px 4px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.12);
  transition: transform 0.1s ease, background 0.1s ease;
}

.roster-card.locked {
  opacity: 0.55;
  cursor: not-allowed;
}

.roster-card.locked .roster-portrait {
  filter: grayscale(100%);
}

.roster-card.unlocked {
  cursor: pointer;
}

.roster-card.unlocked:hover {
  background: rgba(255, 255, 255, 0.12);
  transform: scale(1.05);
}

.roster-card.unlocked:active {
  transform: scale(0.98);
}

.roster-card.unlocking {
  background: rgba(250, 204, 21, 0.18);
  border-color: rgba(250, 204, 21, 0.6);
}

.roster-card.unlocking .roster-portrait {
  animation: unlock-portrait 0.9s ease-out forwards;
}

.roster-card.unlocking .roster-name {
  color: #facc15;
}

@keyframes unlock-portrait {
  0% {
    filter: grayscale(100%);
    transform: scale(1);
  }
  40% {
    filter: grayscale(60%);
    transform: scale(1.12);
  }
  70% {
    filter: grayscale(10%);
    transform: scale(1.05);
  }
  100% {
    filter: grayscale(0%);
    transform: scale(1);
  }
}

.roster-portrait {
  width: 48px;
  height: 48px;
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.3);
  object-fit: cover;
  image-rendering: auto;
}

.roster-name {
  font-size: 9px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: #e5e5e5;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.roster-record {
  font-size: 8px;
  font-weight: 700;
  letter-spacing: 0.03em;
  color: #a3a3a3;
}

.roster-card.unlocking .roster-record {
  color: #facc15;
}

@media (max-width: 768px) {
  #roster-grid {
    grid-template-columns: repeat(5, 1fr);
    gap: 6px;
    width: min(320px, 92vw);
  }

  .roster-portrait {
    width: 40px;
    height: 40px;
  }

  .roster-name {
    font-size: 8px;
  }
}

#volume-control {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin-top: 24px;
}

#volume-control .icon-button {
  width: 36px;
  height: 36px;
  font-size: 18px;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.25);
  border-radius: 8px;
  color: #fff;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.1s ease;
}

#volume-control .icon-button:hover {
  background: rgba(255, 255, 255, 0.2);
}

#volume-control .icon-button:active {
  transform: scale(0.95);
}

#volume-slider {
  width: 120px;
  accent-color: #facc15;
  cursor: pointer;
}

.overlay.panel-left {
  justify-content: flex-start;
  background: linear-gradient(90deg, rgba(0, 0, 0, 0.88) 0%, rgba(0, 0, 0, 0.7) 34%, rgba(0, 0, 0, 0) 62%);
}

.customize-panel {
  width: min(320px, 86vw);
  margin-left: min(40px, 4vw);
  max-height: 88vh;
  overflow-y: auto;
  padding: 28px 24px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  background: rgba(10, 10, 18, 0.75);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 12px;
  color: #fff;
}

.customize-panel .overlay-subtitle {
  text-align: center;
  margin-bottom: 10px;
}

.customize-panel .primary-button,
.customize-panel .secondary-button {
  margin-top: 18px;
}

.customize-panel .secondary-button {
  margin-top: 10px;
}

.field-label {
  margin-top: 12px;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #a3a3a3;
}

#name-input {
  padding: 10px 12px;
  font-size: 16px;
  font-weight: 600;
  color: #fff;
  background: rgba(255, 255, 255, 0.08);
  border: 2px solid rgba(255, 255, 255, 0.25);
  border-radius: 8px;
  outline: none;
}

#name-input:focus {
  border-color: #facc15;
}

.type-picker {
  display: flex;
  align-items: center;
  gap: 8px;
}

.picker-arrow {
  width: 34px;
  height: 30px;
  flex-shrink: 0;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.1);
  border: 2px solid rgba(255, 255, 255, 0.3);
  color: #fff;
  font-size: 11px;
  cursor: pointer;
  padding: 0;
}

.picker-arrow:hover {
  border-color: #facc15;
}

.picker-label {
  flex: 1;
  text-align: center;
  font-size: 14px;
  font-weight: 700;
}

.swatch-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.swatch {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.35);
  cursor: pointer;
  padding: 0;
}

.swatch.selected {
  border-color: #facc15;
  box-shadow: 0 0 0 2px rgba(250, 204, 21, 0.5);
}

#action-buttons {
  position: absolute;
  bottom: 30px;
  right: 24px;
  display: grid;
  grid-template-columns: repeat(2, 64px);
  gap: 12px;
  pointer-events: auto;
  touch-action: none;
  user-select: none;
}

.action-button {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.18);
  border: 2px solid rgba(255, 255, 255, 0.45);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  padding: 0;
}

.action-button:active {
  background: rgba(255, 255, 255, 0.4);
}

#btn-jab {
  border-color: rgba(230, 57, 70, 0.8);
}

#btn-cross {
  border-color: rgba(230, 57, 70, 0.8);
  background: rgba(230, 57, 70, 0.25);
}

/* Touch controls only exist on touch/small screens AND only during a fight. */
#joystick-zone,
#joystick,
#action-buttons {
  display: none;
}

@media (max-width: 768px), (pointer: coarse) {
  body.in-fight #joystick-zone {
    display: block;
  }

  body.in-fight #joystick {
    display: block;
  }

  body.in-fight #action-buttons {
    display: grid;
  }
}

.action-button.on-cooldown {
  opacity: 0.35;
}

/* Pause and mute buttons, top-right corner, only during a fight. */
.hud-corner-button {
  position: absolute;
  top: 16px;
  z-index: 25;
  display: none;
  align-items: center;
  justify-content: center;
  transform: translateY(-50%);
  width: 44px;
  height: 44px;
  font-size: 20px;
  color: #e5e5e5;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.25);
  border-radius: 8px;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}

.hud-corner-button:active {
  background: rgba(255, 255, 255, 0.25);
}

#pause-button {
  right: 16px;
  top: calc(50% - 52px);
}

#fight-mute-button {
  right: 16px;
  top: calc(50% + 8px);
}

body.in-fight .hud-corner-button {
  display: flex;
}

/* ─── Main menu controls panel ─── */

#menu-controls-panel {
  position: absolute;
  left: 0;
  top: 0;
  height: 100%;
  width: min(300px, 28vw);
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 14px;
  padding: 24px;
  background: linear-gradient(90deg, rgba(0, 0, 0, 0.72) 0%, rgba(0, 0, 0, 0.2) 70%, rgba(0, 0, 0, 0) 100%);
  pointer-events: none;
  z-index: 31;
}

.controls-title {
  font-size: 14px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: #facc15;
  margin-bottom: 4px;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.8);
}

.control-scheme {
  background: rgba(10, 10, 18, 0.65);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-left: 3px solid #facc15;
  border-radius: 8px;
  padding: 12px 14px;
  color: #e5e5e5;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}

.scheme-icon {
  display: flex;
  align-items: center;
  margin-bottom: 8px;
  color: #fff;
}

.scheme-name {
  font-size: 13px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: #fff;
  margin-bottom: 8px;
}

.scheme-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.scheme-list li {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  font-weight: 600;
  color: #d4d4d4;
}

.scheme-list li span {
  color: #a3a3a3;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-right: 8px;
}

@media (max-width: 1024px) {
  #menu-controls-panel {
    width: min(260px, 30vw);
    padding: 16px;
    gap: 12px;
  }

  .control-scheme {
    padding: 10px 12px;
  }

  .scheme-name {
    font-size: 12px;
  }

  .scheme-list li {
    font-size: 11px;
  }
}

@media (max-width: 768px) {
  #menu-screen {
    flex-direction: column;
  }

  #menu-screen .overlay-content {
    padding: 24px 16px 12px;
  }

  #menu-controls-panel {
    position: relative;
    width: 100%;
    height: auto;
    flex-direction: row;
    justify-content: center;
    align-items: flex-start;
    gap: 10px;
    padding: 14px 16px;
    background: rgba(0, 0, 0, 0.55);
  }

  .controls-title {
    display: none;
  }

  .control-scheme {
    flex: 1 1 0;
    max-width: 140px;
    padding: 10px;
    border-left-width: 2px;
  }

  .scheme-icon {
    justify-content: center;
    margin-bottom: 6px;
  }

  .scheme-name {
    text-align: center;
    font-size: 11px;
    margin-bottom: 6px;
  }

  .scheme-list {
    gap: 2px;
  }

  .scheme-list li {
    flex-direction: column;
    align-items: center;
    text-align: center;
    font-size: 10px;
    line-height: 1.2;
  }

  .scheme-list li span {
    margin-right: 0;
    font-size: 9px;
  }
}

@media (max-width: 480px) {
  #menu-controls-panel {
    gap: 6px;
    padding: 10px 12px;
  }

  .control-scheme {
    max-width: 110px;
    padding: 8px 6px;
  }

  .scheme-icon svg {
    width: 32px;
    height: 32px;
  }

  .scheme-name {
    font-size: 10px;
  }

  .scheme-list li {
    font-size: 9px;
  }
}

/* ─── Main menu action buttons ─── */

.menu-actions {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 12px;
  margin-top: 28px;
  flex-wrap: wrap;
}

.menu-actions .primary-button {
  margin-top: 0;
}

.continue-career-button {
  background: #22c55e;
  color: #fff;
}

.continue-career-button:hover {
  background: #16a34a;
}

@media (max-width: 480px) {
  .menu-actions {
    gap: 10px;
  }

  .menu-actions .primary-button {
    padding: 12px 28px;
    font-size: 16px;
  }
}

/* ─── Loading / start screen ─── */

#loading-screen {
  z-index: 40;
  background: rgba(0, 0, 0, 0.88);
}

.loading-content {
  max-width: 920px;
  width: 90vw;
}

.loading-instructions {
  display: flex;
  justify-content: center;
  align-items: stretch;
  gap: 14px;
  margin: 28px 0;
}

.loading-scheme {
  flex: 1 1 0;
  min-width: 0;
  background: rgba(10, 10, 18, 0.7);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 10px;
  padding: 16px;
  color: #e5e5e5;
}

.loading-scheme .scheme-icon {
  justify-content: center;
  margin-bottom: 10px;
  color: #fff;
}

.loading-scheme .scheme-name {
  text-align: center;
  font-size: 13px;
  margin-bottom: 10px;
}

.loading-scheme .scheme-list {
  gap: 3px;
}

.loading-scheme .scheme-list li {
  justify-content: center;
  gap: 6px;
  font-size: 11px;
}

.loading-scheme .scheme-list li span {
  margin-right: 0;
}

@media (max-width: 768px) {
  .loading-instructions {
    flex-direction: column;
    align-items: center;
    gap: 10px;
    margin: 20px 0;
  }

  .loading-scheme {
    width: 100%;
    max-width: 320px;
    padding: 12px;
  }

  .loading-scheme .scheme-icon svg {
    width: 32px;
    height: 32px;
  }

  .loading-scheme .scheme-name {
    font-size: 12px;
  }

  .loading-scheme .scheme-list li {
    font-size: 10px;
  }
}
