/* CHROMA CLASH — UI. Dark arena theme; DOM menus + canvas game. */

:root {
  --bg: #0b0d1a;
  --panel: #141830;
  --panel-2: #1b2040;
  --text: #dfe6ff;
  --dim: #8b93b8;
  --accent: #b06bff;
  --accent-2: #59e3ff;
}

* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, 'Segoe UI', sans-serif;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

#app { position: fixed; inset: 0; }

/* ------------------------------------------------------------- screens --- */

.screen {
  position: absolute; inset: 0;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  padding: max(12px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right))
           max(12px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  background:
    radial-gradient(1200px 600px at 50% -10%, rgba(176, 107, 255, 0.14), transparent),
    radial-gradient(900px 500px at 80% 110%, rgba(89, 227, 255, 0.10), transparent),
    var(--bg);
  /* Menu content can be taller than short phones/landscape — scroll instead of
     silently clipping buttons past the fold (touch-action re-enables panning,
     since html/body disable it globally for in-game joystick dragging). */
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-y;
}
.screen.active { display: flex; }

#screen-game { padding: 0; background: #000; overflow: hidden; touch-action: none; }
#game-canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }

h2 { font-size: clamp(20px, 4vw, 30px); letter-spacing: 4px; color: var(--accent-2); }

.logo {
  font-size: clamp(44px, 10vw, 92px);
  line-height: 0.95;
  letter-spacing: 6px;
  text-align: center;
  background: linear-gradient(100deg, #59e3ff 0%, #b06bff 45%, #ff5fd0 80%, #ffd93b 105%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 4px 22px rgba(176, 107, 255, 0.35));
}
.logo span { display: block; letter-spacing: 18px; padding-left: 8px; }

.tagline { color: var(--dim); letter-spacing: 2px; }
.credits { position: absolute; bottom: 14px; color: var(--dim); font-size: 12px; letter-spacing: 1px; text-align: center; }
.hint { color: var(--dim); font-size: 13.5px; max-width: 640px; text-align: center; line-height: 1.5; min-height: 18px; }

/* ------------------------------------------------------------- buttons --- */

.btn {
  background: var(--panel);
  color: var(--text);
  border: 2px solid #2a3158;
  border-radius: 12px;
  padding: 10px 20px;
  font: inherit;
  font-weight: 700;
  letter-spacing: 1.5px;
  cursor: pointer;
  transition: transform 0.06s, border-color 0.15s, background 0.15s;
}
.btn:hover { border-color: var(--accent); background: var(--panel-2); }
.btn:active { transform: scale(0.96); }
.btn.big { font-size: 18px; padding: 14px 34px; min-width: 220px; }
.btn.primary { border-color: var(--accent); background: linear-gradient(135deg, #2a1a4d, #17324d); }
.btn.arrow { min-width: 44px; padding: 8px 12px; font-size: 20px; }

.menu-col { display: flex; flex-direction: column; gap: 12px; align-items: center; }
.nav-row { display: flex; gap: 14px; flex-wrap: wrap; justify-content: center; }

.chip {
  position: absolute; top: max(10px, env(safe-area-inset-top)); right: 12px;
  z-index: 50;
  background: rgba(20, 24, 48, 0.8);
  border: 1px solid #2a3158;
  border-radius: 999px;
  font-size: 17px;
  padding: 7px 11px;
  cursor: pointer;
  color: var(--text);
}

/* ------------------------------------------------------ fighter select --- */

#slots {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 12px;
  width: min(860px, 100%);
}
.slot-card {
  background: var(--panel);
  border: 2px solid #2a3158;
  border-radius: 14px;
  padding: 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 7px;
  min-height: 250px;
  transition: border-color 0.2s;
}
.slot-card.off { opacity: 0.45; }
.slot-head { color: var(--dim); font-weight: 800; letter-spacing: 2px; font-size: 12px; }
.slot-type { font-size: 12px; padding: 7px 10px; width: 100%; }
.char-row { display: flex; align-items: center; gap: 4px; }
.portrait { width: 92px; height: 76px; }
.char-name { font-size: 17px; font-weight: 800; letter-spacing: 2px; min-height: 20px; }
.char-title { font-size: 11px; color: var(--dim); min-height: 14px; font-style: italic; }
.char-stats { font-size: 10.5px; color: var(--dim); letter-spacing: 1px; min-height: 14px; }
.bind-status { font-size: 11px; color: #6fdc8f; min-height: 15px; text-align: center; }
.bind-status.waiting { color: var(--accent-2); animation: pulse 1.2s infinite; }
@keyframes pulse { 50% { opacity: 0.45; } }

/* -------------------------------------------------------- stage select --- */

#stage-cards { display: flex; gap: 14px; flex-wrap: wrap; justify-content: center; }
.stage-card {
  background: var(--panel);
  border: 2px solid #2a3158;
  border-radius: 14px;
  padding: 10px;
  cursor: pointer;
  color: var(--text);
  font: inherit;
  display: flex;
  flex-direction: column;
  gap: 6px;
  align-items: center;
  transition: border-color 0.15s, transform 0.1s;
}
.stage-card:hover { transform: translateY(-2px); }
.stage-card.selected { border-color: var(--accent-2); box-shadow: 0 0 18px rgba(89, 227, 255, 0.25); }
.stage-card canvas { border-radius: 8px; width: 220px; height: 120px; }
.stage-name { font-weight: 800; letter-spacing: 1.5px; }
.stage-desc { font-size: 11.5px; color: var(--dim); }

#stocks-row { display: flex; gap: 8px; align-items: center; color: var(--dim); letter-spacing: 2px; font-weight: 700; font-size: 13px; }
.stock-btn { min-width: 42px; }
.stock-btn.selected { border-color: var(--accent-2); color: var(--accent-2); }

/* ------------------------------------------------------------ overlays --- */

.overlay {
  position: absolute; inset: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(5, 6, 14, 0.78);
  backdrop-filter: blur(3px);
  padding: 16px;
}
.overlay.hidden, .hidden { display: none !important; }

.panel {
  background: var(--panel);
  border: 2px solid #2a3158;
  border-radius: 18px;
  padding: 26px 30px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  max-width: min(92vw, 460px);
  max-height: 92vh;
  overflow-y: auto;
}
.panel.wide { max-width: min(94vw, 620px); }
.panel h2 { color: var(--text); }

.controls-table { border-collapse: collapse; font-size: 12.5px; }
.controls-table th, .controls-table td { border: 1px solid #2a3158; padding: 5px 10px; text-align: center; }
.controls-table th { color: var(--accent-2); letter-spacing: 1px; }
.controls-table td:first-child { text-align: left; color: var(--dim); }

#results-title { letter-spacing: 3px; }
#results-body { display: flex; flex-direction: column; gap: 8px; width: 100%; }
.result-row {
  display: flex; justify-content: space-between; gap: 16px;
  border: 1px solid; border-radius: 10px; padding: 8px 12px; font-size: 13.5px;
}
.result-row span { color: var(--dim); }

/* ------------------------------------------------------ touch controls --- */

#touch-controls { position: absolute; inset: 0; z-index: 30; pointer-events: none; }
#touch-controls > * { pointer-events: auto; }

#joystick {
  position: absolute;
  left: max(18px, env(safe-area-inset-left));
  bottom: max(96px, calc(env(safe-area-inset-bottom) + 96px));
  width: 130px; height: 130px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.07);
  border: 2px solid rgba(255, 255, 255, 0.18);
}
#joystick-knob {
  position: absolute; left: 50%; top: 50%;
  width: 56px; height: 56px;
  margin: -28px 0 0 -28px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.22);
  border: 2px solid rgba(255, 255, 255, 0.4);
}

#touch-buttons {
  position: absolute;
  right: max(14px, env(safe-area-inset-right));
  bottom: max(92px, calc(env(safe-area-inset-bottom) + 92px));
  display: grid;
  grid-template-columns: repeat(3, 64px);
  grid-template-rows: 48px 64px 64px;
  gap: 8px;
  justify-items: center;
  align-items: center;
}
.tbtn {
  width: 64px; height: 64px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.3);
  background: rgba(255, 255, 255, 0.10);
  color: #fff;
  font-weight: 800;
  font-size: 12px;
  letter-spacing: 1px;
}
.tbtn.active { background: rgba(176, 107, 255, 0.45); border-color: var(--accent); }
.tbtn.small { width: 52px; height: 44px; border-radius: 12px; font-size: 11px; }
.tbtn.jump { grid-column: 2 / 4; width: 100%; height: 60px; border-radius: 999px; background: rgba(89, 227, 255, 0.15); border-color: rgba(89, 227, 255, 0.45); }
#touch-buttons .small:nth-child(1) { grid-column: 1; grid-row: 1; }
#touch-buttons .small:nth-child(2) { grid-column: 3; grid-row: 1; }
#touch-buttons [data-action="light"] { grid-row: 2; grid-column: 1; }
#touch-buttons [data-action="heavy"] { grid-row: 2; grid-column: 2; }
#touch-buttons [data-action="special"] { grid-row: 2; grid-column: 3; }
#touch-buttons [data-action="jump"] { grid-row: 3; }
.tbtn.pausebtn {
  position: absolute;
  top: max(10px, env(safe-area-inset-top));
  left: 12px;
  width: 46px; height: 38px;
  border-radius: 10px;
  font-size: 13px;
}

/* ------------------------------------------------------------ online --- */

.online-panels { display: flex; gap: 16px; flex-wrap: wrap; justify-content: center; }
.online-card {
  background: var(--panel);
  border: 2px solid #2a3158;
  border-radius: 14px;
  padding: 18px 22px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  min-width: 230px;
}
.online-card h3 { color: var(--accent-2); letter-spacing: 2px; font-size: 15px; }
.hint.small { font-size: 11.5px; }

.room-code {
  font-size: 40px;
  font-weight: 900;
  letter-spacing: 10px;
  padding-left: 10px; /* visually recentre the letter-spacing overhang */
  color: var(--accent-2);
  text-shadow: 0 0 18px rgba(89, 227, 255, 0.4);
  user-select: text;
  -webkit-user-select: text;
}
.lobby-code { color: var(--accent-2); letter-spacing: 6px; }

#join-code {
  background: #0d1020;
  border: 2px solid #2a3158;
  border-radius: 10px;
  color: var(--text);
  font: inherit;
  font-size: 22px;
  font-weight: 800;
  letter-spacing: 6px;
  text-align: center;
  text-transform: uppercase;
  padding: 8px 10px;
  width: 170px;
  user-select: text;
  -webkit-user-select: text;
  touch-action: auto;
}
#join-code:focus { outline: none; border-color: var(--accent-2); }

#net-slots { display: flex; gap: 14px; flex-wrap: wrap; justify-content: center; }
#net-slots .slot-card { min-height: 200px; min-width: 190px; }

/* --------------------------------------------------------- rotate hint --- */

#rotate-hint {
  display: none;
  position: fixed; inset: 0;
  z-index: 100;
  background: var(--bg);
  color: var(--text);
  font-size: 22px;
  font-weight: 800;
  text-align: center;
  align-items: center;
  justify-content: center;
  letter-spacing: 1px;
}
@media (orientation: portrait) and (pointer: coarse) {
  #rotate-hint { display: flex; }
}

/* ------------------------------------------------------- compact phones --- */
/* Shrinks the menu screens so the common 2-player case fits without needing
   the overflow-y:auto scroll above; larger rosters (3-4p) still scroll fine. */
@media (max-width: 480px) {
  .screen { gap: 10px; padding-top: max(8px, env(safe-area-inset-top)); padding-bottom: max(8px, env(safe-area-inset-bottom)); }
  .logo { font-size: clamp(32px, 13vw, 56px); letter-spacing: 4px; }
  .logo span { letter-spacing: 10px; padding-left: 4px; }
  .tagline { font-size: 13px; }
  h2 { margin-bottom: 2px; }

  #slots { grid-template-columns: repeat(2, 1fr); gap: 8px; }
  .slot-card { min-height: 185px; padding: 7px; gap: 4px; }
  .portrait { width: 68px; height: 56px; }
  .char-name { font-size: 13.5px; letter-spacing: 1px; }
  .char-title { font-size: 9px; }
  .char-stats { font-size: 8.5px; }
  .bind-status { font-size: 9px; }
  .slot-type { font-size: 10.5px; padding: 6px 8px; }

  #stage-cards { gap: 8px; }
  .stage-card { padding: 6px; gap: 3px; }
  .stage-card canvas { width: 130px; height: 71px; }
  .stage-name { font-size: 12.5px; }
  .stage-desc { font-size: 10px; }

  .btn.big { padding: 10px 22px; font-size: 15px; min-width: 150px; }
  .hint { font-size: 12px; }
}
