* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: #0d0714;
  color: #fff;
  font-family: 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  overflow: hidden;
  height: 100%;
}

#app {
  position: relative;
  width: 100vw;
  height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
}

#game-canvas {
  background: #000;
  width: min(100vw, 177.78vh);
  height: min(100vh, 56.25vw);
  image-rendering: pixelated;
  display: block;
  position: relative;
  z-index: 1;
}

/* 3D view: WebGL canvas underneath, the 2D canvas becomes a HUD overlay. */
#game-canvas-3d {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: min(100vw, 177.78vh);
  height: min(100vh, 56.25vw);
  display: block;
  z-index: 0;
}

#game-canvas.overlay-3d {
  background: transparent;
  image-rendering: auto;
}

.screen {
  position: absolute;
  z-index: 2;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  background: rgba(10, 5, 20, 0.92);
  padding: 20px;
  text-align: center;
  overflow-y: auto;
}
/* Centred when the content fits, scrolls from the top when it doesn't
   (plain justify-content: center pushes the top out of scroll reach). */
.screen > :first-child { margin-top: auto; }
.screen > :last-child { margin-bottom: auto; }

.screen.hidden { display: none; }

h1 {
  font-size: 4rem;
  margin: 0 0 4px 0;
  letter-spacing: 4px;
  color: #ffd166;
  text-shadow: 3px 3px 0 #e63946;
}

.subtitle {
  color: #cbb9e0;
  margin-bottom: 30px;
}

h2 {
  color: #ffd166;
  font-size: 2.2rem;
  margin-bottom: 8px;
}

.hint {
  color: #cbb9e0;
  max-width: 700px;
  margin: 0 auto 20px auto;
  font-size: 0.95rem;
}

button {
  font-size: 1.1rem;
  padding: 12px 28px;
  margin: 6px;
  border-radius: 8px;
  border: 2px solid #6b3fa0;
  background: #2b1b3d;
  color: #fff;
  cursor: pointer;
  transition: transform 0.08s ease, background 0.15s ease;
}

button:hover {
  background: #45305e;
  transform: translateY(-2px);
}

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

.btn-primary {
  background: #e63946;
  border-color: #ff6b6b;
  font-weight: bold;
}

.btn-primary:hover {
  background: #ff4d5e;
}

/* Online: you've pressed Ready (or Rematch) and are waiting for the other player */
.btn-primary.is-ready, .btn-primary.is-ready:hover {
  background: #2e9e57;
  border-color: #6fe39a;
}

.menu-buttons {
  display: flex;
  gap: 8px;
  margin-bottom: 24px;
  flex-wrap: wrap;
  justify-content: center;
}

.stats-link {
  color: #cbb9e0;
  margin: -12px 0 20px;
  font-size: 0.9rem;
}

.stats-link:hover { color: #ffd166; }

.controls-legend {
  display: flex;
  gap: 40px;
}

.controls-col h3 {
  color: #7ee8fa;
  margin-bottom: 8px;
}

.controls-col ul {
  list-style: none;
  padding: 0;
  margin: 0;
  text-align: left;
}

.controls-col li {
  margin: 6px 0;
  font-size: 0.95rem;
}

.key {
  display: inline-block;
  min-width: 34px;
  padding: 2px 8px;
  margin-right: 8px;
  background: #333;
  border: 1px solid #666;
  border-radius: 4px;
  font-weight: bold;
  text-align: center;
}

.select-arena {
  display: flex;
  align-items: flex-start;
  justify-content: center;
  gap: 22px;
  width: 100%;
  max-width: 1180px;
  margin: 0 auto 20px auto;
  flex-wrap: wrap;
}

.select-side {
  flex: 1 1 380px;
  max-width: 400px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

.side-label {
  font-size: 0.85rem;
  font-weight: bold;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: #7ee8fa;
}

.vs-divider {
  align-self: center;
  font-size: 2.2rem;
  font-weight: 900;
  color: #ffd166;
  text-shadow: 2px 2px 0 #e63946;
  padding: 0 6px;
  margin-top: 0;
}

/* ---- Big full-body fighters behind the select screen ---- */
.select-art {
  position: fixed;
  top: 0;
  bottom: 0;
  width: min(34vw, 520px);
  height: 100vh;
  pointer-events: none;
  z-index: 0;
  -webkit-mask-image: linear-gradient(to top, transparent 0, #000 10%);
  mask-image: linear-gradient(to top, transparent 0, #000 10%);
}
.select-art-left { left: 0; }
.select-art-right { right: 0; }
/* The menu itself sits above the art. */
#screen-select > *:not(.select-art) { position: relative; z-index: 1; }
/* The art canvases come first in the markup, so the heading is no longer :first-child and lost the
   `.screen > :first-child { margin-top: auto }` centring (it got the browser's default ~29px margin
   instead, which pushed the Fight button off short screens). Give it the same auto margin. */
#screen-select > h2 { margin-top: auto; }
@media (max-width: 900px) { .select-art { display: none; } }

/* ---- Fighter preview: the big "who's selected" panel ---- */
.fighter-preview {
  --fp-color: #3d2a55;
  --fp-glow: rgba(0, 0, 0, 0);
  width: 100%;
  /* A fixed size, so what the hovered fighter's text happens to be never
     changes the layout (the roster above stays exactly where it is): the
     header is fixed and only the ability list scrolls if it runs long. */
  height: clamp(330px, calc(100vh - 425px), 400px); /* fixed for a given window, never by content */
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: linear-gradient(160deg, #241633, #150d20);
  border: 2px solid var(--fp-color);
  border-radius: 16px;
  padding: 12px 18px;
  box-shadow: 0 0 20px var(--fp-glow);
  animation: previewGlow 2.6s ease-in-out infinite;
  transition: border-color 0.2s ease;
}

@keyframes previewGlow {
  0%, 100% { box-shadow: 0 0 16px var(--fp-glow); }
  50% { box-shadow: 0 0 28px var(--fp-glow); }
}

.preview-avatar-wrap {
  position: relative;
  width: 76px;
  height: 76px;
  margin: 0 auto 8px auto;
  border-radius: 50%;
  overflow: hidden;
  border: 3px solid var(--fp-color);
  box-shadow: 0 0 16px var(--fp-glow);
}

.preview-avatar-wrap .avatar-fallback {
  position: absolute;
  inset: 0;
}

.preview-avatar-wrap .avatar-img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.preview-name {
  text-align: center;
  font-size: 1.4rem;
  font-weight: 800;
  color: #fff;
  line-height: 1.1;
}

.preview-title {
  text-align: center;
  font-size: 0.78rem;
  color: var(--fp-color);
  filter: brightness(1.6) saturate(1.3);
  text-transform: uppercase;
  letter-spacing: 1.5px;
  margin-bottom: 12px;
}

.stat-bars {
  margin-bottom: 12px;
}

.stat-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 5px 0;
}

.stat-label {
  width: 58px;
  flex-shrink: 0;
  font-size: 0.66rem;
  color: #cbb9e0;
  text-align: right;
  white-space: nowrap;
}

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

.stat-fill {
  height: 100%;
  border-radius: 4px;
  background: var(--fp-color);
  filter: brightness(1.3);
  transition: width 0.25s ease;
}

.preview-head {
  flex: none;
  display: flex;
  align-items: center;
  gap: 16px;
}
.preview-id { flex: 0 0 132px; min-width: 0; }
.preview-head .stat-bars { flex: 1 1 auto; min-width: 0; margin: 0; }
.preview-id .preview-name { font-size: 1.25rem; overflow-wrap: anywhere; }
.preview-id .preview-title { font-size: 0.66rem; line-height: 1.25; }

/* The scrolling part of the preview: everything under the stat bars. */
.preview-abilities {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  margin-top: 4px;
  padding-right: 6px;
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.25) transparent;
}

.ability-row {
  display: flex;
  gap: 9px;
  align-items: flex-start;
  margin-top: 9px;
  text-align: left;
}

.key-badge {
  flex-shrink: 0;
  min-width: 22px;
  height: 22px;
  padding: 0 5px;
  border-radius: 5px;
  background: rgba(0, 0, 0, 0.5);
  border: 1px solid rgba(255, 255, 255, 0.3);
  color: #fff;
  font-weight: bold;
  font-size: 0.75rem;
  display: flex;
  align-items: center;
  justify-content: center;
}

.ability-name {
  font-weight: bold;
  font-size: 0.8rem;
  color: #fff;
}

.ability-desc {
  font-size: 0.7rem;
  color: #a89bc0;
  line-height: 1.35;
}

/* ---- Roster grid: small selectable icons beneath the preview ---- */
.roster-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 6px;
  width: 100%;
  max-width: 400px;
}

.roster-icon {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 5px;
  border-radius: 10px;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.12s ease;
}

.roster-icon:hover {
  background: rgba(255, 255, 255, 0.07);
  transform: translateY(-2px);
}

.roster-icon.selected {
  background: rgba(255, 209, 102, 0.12);
}

.roster-avatar {
  position: relative;
  width: 100%;
  aspect-ratio: 1;
  border-radius: 50%;
  border: 3px solid #3d2a55;
  overflow: hidden;
  transition: border-color 0.12s ease, box-shadow 0.12s ease, transform 0.12s ease;
}

.roster-icon:hover .roster-avatar {
  border-color: #8a7cae;
  transform: scale(1.06);
}

.roster-icon.selected .roster-avatar {
  border-color: #ffd166;
  box-shadow: 0 0 14px rgba(255, 209, 102, 0.7);
  transform: scale(1.08);
}

.roster-avatar .icon-fallback {
  position: absolute;
  inset: 0;
}

.roster-avatar .icon-img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.roster-icon.random .roster-avatar {
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(circle at 30% 28%, #6b3fa0, #241633);
  border-style: dashed;
  border-color: #8a7cae;
}

.random-mark {
  font-size: 1.5rem;
  font-weight: 900;
  color: #ffd166;
  line-height: 1;
}

.roster-icon.random.spinning .roster-avatar {
  border-style: solid;
  border-color: #ffd166;
  box-shadow: 0 0 14px rgba(255, 209, 102, 0.7);
}

.roster-icon.random.spinning .random-mark {
  animation: randomSpin 0.4s linear infinite;
}

@keyframes randomSpin {
  from { transform: rotateY(0deg); }
  to { transform: rotateY(360deg); }
}

.roster-name {
  font-size: 0.62rem;
  color: #cbb9e0;
  text-align: center;
}

.roster-icon.selected .roster-name {
  color: #ffd166;
  font-weight: bold;
}

.row-buttons {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: center;
}

@media (max-width: 900px) {
  .controls-legend { gap: 24px; }
}

/* ---- Online lobby ---- */
.online-join {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 6px;
  margin: 10px 0;
}

.online-join input {
  font-size: 1.3rem;
  padding: 10px 14px;
  width: 170px;
  text-align: center;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  border-radius: 8px;
  border: 2px solid #6b3fa0;
  background: #1a1026;
  color: #fff;
}

.online-status {
  min-height: 1.4em;
  color: #ffe066;
  font-size: 1.1rem;
  margin: 12px auto;
}

.online-status .room-code {
  font-size: 2rem;
  letter-spacing: 0.25em;
  font-weight: bold;
  color: #fff;
  user-select: all;
}

.roster-grid.locked .roster-icon {
  opacity: 0.55;
  cursor: default;
  pointer-events: none;
}

button:disabled {
  opacity: 0.45;
  cursor: default;
  transform: none;
}

.direct-label {
  display: block;
  color: #cbb9e0;
  font-size: 0.85rem;
  margin: 6px auto;
}

/* ---- Sound controls ---- */
#audio-ctl {
  position: fixed;
  top: 10px;
  right: 10px;
  z-index: 60;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
}
#btn-audio {
  width: 38px;
  height: 38px;
  padding: 0;
  border-radius: 50%;
  font-size: 18px;
  line-height: 1;
  background: rgba(20, 10, 40, 0.75);
  border: 1px solid rgba(255, 255, 255, 0.25);
  color: #fff;
  cursor: pointer;
}
#btn-audio:hover { background: rgba(60, 35, 100, 0.9); }
#audio-ctl .corner-buttons { display: flex; gap: 6px; }
#btn-gfx {
  width: 38px;
  height: 38px;
  padding: 0;
  border-radius: 50%;
  font-size: 20px;
  line-height: 1;
  background: rgba(20, 10, 40, 0.75);
  border: 1px solid rgba(255, 255, 255, 0.25);
  color: #fff;
  cursor: pointer;
}
#btn-gfx:hover { background: rgba(60, 35, 100, 0.9); }
/* Only on the menus and the pause screen: mid-fight it would sit on P2's health bar. */
body:not(:has(.screen:not(.hidden))) #btn-gfx,
body:not(:has(.screen:not(.hidden))) #gfx-panel { display: none; }

/* ---- Graphics settings ---- */
#gfx-panel {
  width: 290px;
  padding: 12px;
  border-radius: 10px;
  background: rgba(15, 8, 30, 0.92);
  border: 1px solid rgba(255, 255, 255, 0.2);
  font-size: 13px;
}
#gfx-panel[hidden] { display: none; }
#gfx-panel .gfx-label { margin-bottom: 6px; opacity: 0.8; }
#gfx-panel .gfx-presets { display: flex; gap: 4px; margin-bottom: 6px; }
#gfx-panel .gfx-presets button { flex: 1; padding: 6px 2px; font-size: 12px; opacity: 0.6; }
#gfx-panel .gfx-presets button.active { opacity: 1; outline: 2px solid currentColor; }
#gfx-panel label { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 4px; margin: 10px 0 0; }
#gfx-panel input[type=range] { width: 100%; }
#gfx-panel .gfx-check { justify-content: flex-start; align-items: center; cursor: pointer; }
#gfx-panel .gfx-note { font-size: 12px; opacity: 0.75; min-height: 1em; }
#gfx-panel .gfx-note[hidden] { display: none; }
#gfx-reload { margin-top: 10px; opacity: 1; }
#gfx-reload button { display: block; width: 100%; margin-top: 6px; padding: 6px 4px; font-size: 12px; }
#fps-counter {
  position: fixed;
  left: 10px;
  bottom: 8px;
  z-index: 60;
  padding: 2px 8px;
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.55);
  color: #fff;
  font: 12px/1.5 ui-monospace, Menlo, monospace;
  pointer-events: none;
}
#fps-counter[hidden] { display: none; }
#audio-panel {
  width: 210px;
  padding: 12px;
  border-radius: 10px;
  background: rgba(15, 8, 30, 0.92);
  border: 1px solid rgba(255, 255, 255, 0.2);
  font-size: 13px;
}
#audio-panel[hidden] { display: none; }
#audio-panel label { display: flex; flex-direction: column; gap: 4px; margin-bottom: 10px; }
#audio-panel input[type=range] { width: 100%; }
#audio-panel .audio-row { display: flex; gap: 6px; }
#audio-panel .audio-row button { flex: 1; padding: 6px 4px; font-size: 12px; }
#now-playing { margin-top: 8px; opacity: 0.75; font-size: 12px; word-break: break-word; }


/* Vs CPU difficulty picker (character select, above the CPU's side) */
/* CPU difficulty, ball and balance options share one line on the select screen. */
.select-options { display: flex; flex-wrap: wrap; gap: 6px 28px; justify-content: center; align-items: center; margin: 4px 0 8px; }
.select-options .cpu-difficulty { margin: 0; }
.cpu-difficulty { display: flex; gap: 6px; justify-content: center; align-items: center; margin: 12px 0 0; }
.cpu-difficulty.hidden { display: none; }
.cpu-difficulty button { padding: 4px 12px; font-size: 13px; opacity: 0.6; }
.cpu-difficulty button.active { opacity: 1; outline: 2px solid currentColor; }

/* Base / Transformed switch on the fighter overview (Robert). */
.form-toggle {
  display: flex;
  margin: 6px auto 0;
  width: 100%;
  border: 1px solid var(--fp-color, #888);
  border-radius: 999px;
  overflow: hidden;
}
.form-toggle button {
  font: inherit;
  flex: 1 1 auto;
  font-size: 0.56rem;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  padding: 3px 4px;
  white-space: nowrap;
  border: 0;
  background: transparent;
  color: inherit;
  cursor: pointer;
  opacity: 0.7;
}
.form-toggle button.on {
  background: var(--fp-color, #888);
  color: #fff;
  opacity: 1;
}

/* ---- Free-for-all lobby (online, experimental) ---- */
.tag-exp {
  font-size: 0.55em;
  font-weight: normal;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: #ffd166;
  border: 1px solid rgba(255, 209, 102, 0.6);
  border-radius: 4px;
  padding: 1px 5px;
  vertical-align: middle;
}

.ffa-code {
  font-size: 2rem;
  font-weight: bold;
  letter-spacing: 6px;
  color: #ffd166;
  margin: 0 0 6px;
}

#screen-ffa h2 { margin: 0 0 4px; }
#screen-ffa .hint { margin: 0 0 8px; max-width: 720px; }
#screen-ffa .row-buttons { margin-top: 4px; }
#screen-ffa .online-status { margin: 6px auto 0; font-size: 0.95rem; }

.ffa-code small {
  display: block;
  font-size: 0.8rem;
  font-weight: normal;
  letter-spacing: 0;
  color: #cbb9e0;
}

.ffa-players {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  width: 100%;
  max-width: 720px;
  margin-bottom: 16px;
}

.ffa-player {
  border: 2px solid rgba(255, 255, 255, 0.12);
  border-top: 5px solid var(--slot-color);
  border-radius: 10px;
  padding: 10px 6px;
  background: rgba(255, 255, 255, 0.04);
  min-height: 132px;
}

.ffa-player.empty {
  border-top-color: rgba(255, 255, 255, 0.12);
  color: #8f879b;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.9rem;
}

.ffa-player img {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  object-fit: cover;
  border: 3px solid var(--slot-color);
  background: #1d1428;
}

.ffa-player .slot {
  font-weight: bold;
  color: var(--slot-color);
  font-size: 0.85rem;
}

.ffa-player .char {
  font-weight: bold;
  margin-top: 4px;
}

.ffa-player .you {
  display: inline-block;
  margin-left: 4px;
  font-size: 0.7rem;
  background: #2c2c3a;
  border-radius: 4px;
  padding: 1px 5px;
  color: #fff;
}

.ffa-pick-label {
  color: #cbb9e0;
  margin-bottom: 6px;
}

.ffa-grid {
  max-width: 400px;
  margin-bottom: 8px;
}

@media (max-width: 640px) {
  .ffa-players { grid-template-columns: repeat(2, 1fr); }
}
