:root {
  --bg: #0b0a17;
  --panel: rgba(20, 17, 38, 0.94);
  --border: rgba(255, 255, 255, 0.14);
  --text: #f8fafc;
  --muted: #94a3b8;
  --primary: #f97316;
  --primary-2: #ef4444;
  --online: #06b6d4;
  --accent: #a855f7;
  --gold: #facc15;
}

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

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

#app {
  width: 100%;
  height: 100dvh;
  position: relative;
}

.screen {
  position: absolute;
  inset: 0;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: env(safe-area-inset-top, 10px) 14px env(safe-area-inset-bottom, 10px);
  overflow-y: auto;
}

.screen.active {
  display: flex;
}

.hidden {
  display: none !important;
}

/* TITLE SCREEN */
.title-bg-glow {
  position: fixed;
  inset: 0;
  background:
    radial-gradient(circle at 20% 25%, rgba(249, 115, 22, 0.25), transparent 45%),
    radial-gradient(circle at 80% 70%, rgba(56, 189, 248, 0.22), transparent 45%),
    linear-gradient(180deg, #0c0a1d 0%, #170f2e 100%);
  z-index: 0;
}

.title-content {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 460px;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 14px;
  align-items: center;
}

.title-badge {
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.14em;
  color: var(--gold);
  background: rgba(250, 204, 21, 0.12);
  border: 1px solid rgba(250, 204, 21, 0.35);
  padding: 5px 12px;
  border-radius: 999px;
}

.game-logo {
  font-size: clamp(40px, 10vw, 58px);
  font-weight: 900;
  font-style: italic;
  letter-spacing: -0.02em;
  line-height: 0.95;
  text-shadow: 0 5px 0 #1e1b4b, 0 10px 28px rgba(249, 115, 22, 0.45);
}

.game-logo span {
  display: inline-block;
  margin-left: 6px;
  background: linear-gradient(180deg, #fef08a 0%, #f97316 55%, #ef4444 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.title-showcase {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  margin: 4px 0;
}

.showcase-card {
  width: 96px;
  height: 96px;
  border-radius: 18px;
  object-fit: cover;
  border: 3px solid var(--gold);
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.45);
  background: #1c1230;
}

.showcase-card.right {
  transform: scaleX(-1);
  border-color: var(--online);
}

.showcase-vs {
  font-size: 28px;
  font-weight: 900;
  font-style: italic;
  color: var(--gold);
  text-shadow: 0 3px 10px rgba(250, 204, 21, 0.5);
}

.mode-grid {
  width: 100%;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.btn {
  border: none;
  border-radius: 14px;
  color: #fff;
  font-weight: 800;
  cursor: pointer;
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  transition: transform 0.1s ease, filter 0.15s ease;
}

.btn:active {
  transform: scale(0.96);
}

.btn:disabled {
  opacity: 0.45;
  pointer-events: none;
}

.btn-lg {
  grid-column: span 2;
  padding: 14px 16px;
}

.btn-block {
  width: 100%;
  padding: 14px;
  font-size: 16px;
}

.btn-sm {
  padding: 8px 12px;
  font-size: 13px;
  border-radius: 10px;
}

.btn-xs {
  padding: 6px 10px;
  font-size: 12px;
  border-radius: 9px;
}

.btn-title {
  font-size: 16px;
  letter-spacing: 0.04em;
}

.btn-sub {
  font-size: 11px;
  font-weight: 600;
  opacity: 0.85;
}

.btn-primary {
  background: linear-gradient(135deg, #f97316, #ef4444);
  box-shadow: 0 6px 18px rgba(239, 68, 68, 0.35);
}

.btn-online {
  background: linear-gradient(135deg, #06b6d4, #2563eb);
  box-shadow: 0 6px 18px rgba(37, 99, 235, 0.35);
}

.btn-secondary {
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid var(--border);
}

.btn-accent {
  background: linear-gradient(135deg, #9333ea, #ec4899);
}

.title-tip {
  font-size: 12px;
  color: var(--muted);
  line-height: 1.4;
}

/* PANELS (ONLINE / SELECT) */
.panel {
  width: 100%;
  max-width: 520px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.55);
  max-height: 94dvh;
  overflow-y: auto;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.panel-header h2 {
  font-size: 18px;
  font-weight: 900;
  letter-spacing: 0.04em;
}

.btn-icon {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
  font-size: 18px;
  cursor: pointer;
}

.pill {
  font-size: 11px;
  font-weight: 800;
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(6, 182, 212, 0.2);
  color: #38bdf8;
}

/* ONLINE LOBBY */
.online-box {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.room-code-box {
  background: rgba(6, 182, 212, 0.12);
  border: 1px solid rgba(56, 189, 248, 0.45);
  border-radius: 14px;
  padding: 14px;
  text-align: center;
}

.room-label {
  font-size: 11px;
  color: #7dd3fc;
  font-weight: 700;
  letter-spacing: 0.1em;
}

.room-code {
  font-size: 36px;
  font-weight: 900;
  letter-spacing: 0.22em;
  color: var(--gold);
  margin: 4px 0 10px;
}

.divider {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 11px;
  color: var(--muted);
  font-weight: 700;
}

.divider::before, .divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}

.join-row {
  display: flex;
  gap: 8px;
}

.join-row input {
  flex: 1;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
  color: #fff;
  font-size: 16px;
  font-weight: 800;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  text-align: center;
}

.status-text {
  font-size: 13px;
  color: #cbd5e1;
  text-align: center;
  min-height: 18px;
}

/* CHARACTER SELECT */
.vs-preview {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.slot-card {
  flex: 1;
  background: rgba(255, 255, 255, 0.05);
  border: 2px solid var(--border);
  border-radius: 14px;
  padding: 10px;
  text-align: center;
  position: relative;
}

.slot-card.p1 { border-color: rgba(250, 204, 21, 0.65); }
.slot-card.p2 { border-color: rgba(56, 189, 248, 0.65); }

.slot-tag {
  position: absolute;
  top: 6px;
  left: 8px;
  font-size: 10px;
  font-weight: 900;
  background: rgba(0, 0, 0, 0.55);
  padding: 2px 6px;
  border-radius: 6px;
}

.slot-card img {
  width: 72px;
  height: 72px;
  border-radius: 12px;
  object-fit: cover;
  background: #1c1230;
}

.slot-card.p2 img {
  transform: scaleX(-1);
}

.slot-name {
  font-size: 15px;
  font-weight: 900;
  margin-top: 4px;
}

.slot-move {
  font-size: 10px;
  color: var(--gold);
  font-weight: 700;
}

.vs-bolt {
  font-size: 22px;
  font-weight: 900;
  font-style: italic;
  color: var(--primary);
}

.select-target-tabs {
  display: flex;
  gap: 8px;
}

.tab-btn {
  flex: 1;
  padding: 8px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.05);
  color: var(--muted);
  font-weight: 800;
  font-size: 13px;
  cursor: pointer;
}

.tab-btn.active {
  background: rgba(250, 204, 21, 0.18);
  border-color: var(--gold);
  color: #fff;
}

.roster-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(105px, 1fr));
  gap: 8px;
}

.fighter-tile {
  background: rgba(255, 255, 255, 0.06);
  border: 2px solid transparent;
  border-radius: 12px;
  padding: 8px;
  text-align: center;
  cursor: pointer;
  position: relative;
}

.fighter-tile.selected-p1 { border-color: var(--gold); }
.fighter-tile.selected-p2 { box-shadow: inset 0 0 0 2px #38bdf8; }

.fighter-tile img {
  width: 64px;
  height: 64px;
  border-radius: 10px;
  object-fit: cover;
}

.fighter-tile .ft-name {
  font-size: 13px;
  font-weight: 800;
  margin-top: 4px;
}

.fighter-tile .ft-title {
  font-size: 10px;
  color: var(--muted);
}

.select-options {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.opt-group label {
  display: block;
  font-size: 11px;
  font-weight: 800;
  color: var(--muted);
  margin-bottom: 5px;
  text-transform: uppercase;
}

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

.chip {
  flex: 1;
  min-width: 82px;
  padding: 7px 10px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.06);
  color: #cbd5e1;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
}

.chip.active {
  background: rgba(56, 189, 248, 0.22);
  border-color: #38bdf8;
  color: #fff;
}

.btn-fight {
  font-size: 18px;
  letter-spacing: 0.08em;
  font-style: italic;
}

/* MODAL IMPORTER */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(6, 5, 14, 0.82);
  backdrop-filter: blur(6px);
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 14px;
}

.modal-card {
  width: 100%;
  max-width: 480px;
  background: #16122c;
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-height: 92dvh;
  overflow-y: auto;
}

.modal-desc {
  font-size: 12px;
  color: var(--muted);
  line-height: 1.45;
}

.importer-body {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  align-items: start;
}

@media (max-width: 440px) {
  .importer-body { grid-template-columns: 1fr; }
}

.importer-preview-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

#importer-preview-canvas {
  width: 164px;
  height: 164px;
  border-radius: 14px;
  background: radial-gradient(circle, #2a2048, #120e24);
  border: 2px solid var(--border);
}

.importer-fields {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.importer-fields label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 11px;
  font-weight: 700;
  color: var(--muted);
}

.importer-fields input[type="text"],
.importer-fields select {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 8px 10px;
  color: #fff;
  font-size: 13px;
  font-weight: 700;
}

.importer-fields input[type="color"] {
  width: 100%;
  height: 36px;
  border: none;
  border-radius: 8px;
  background: transparent;
}

/* BATTLE SCREEN (MOBILE-FIRST FULL BLEED) */
.battle-screen {
  padding: 0;
  justify-content: space-between;
  background: #070611;
  overflow: hidden;
}

.hud {
  width: 100%;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 8px;
  padding: max(6px, env(safe-area-inset-top)) 10px 6px;
  background: linear-gradient(180deg, rgba(10, 8, 22, 0.96), rgba(10, 8, 22, 0.6));
  z-index: 5;
}

.hud-player {
  display: flex;
  align-items: center;
  gap: 7px;
  min-width: 0;
}

.hud-portrait {
  width: 42px;
  height: 42px;
  border-radius: 10px;
  border: 2px solid var(--gold);
  object-fit: cover;
  flex-shrink: 0;
}

.hud-player.p2 .hud-portrait {
  border-color: #38bdf8;
  transform: scaleX(-1);
}

.hud-bars {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.hud-top-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}

.hud-name {
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 0.05em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.round-orbs {
  display: flex;
  gap: 4px;
}

.orb {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  border: 1.5px solid var(--gold);
  background: rgba(255, 255, 255, 0.08);
}

.orb.won {
  background: var(--gold);
  box-shadow: 0 0 8px var(--gold);
}

.hp-track {
  height: 14px;
  background: #1e1b2e;
  border: 2px solid #09090b;
  border-radius: 6px;
  position: relative;
  overflow: hidden;
}

.hp-trail, .hp-fill {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 100%;
}

.hud-player.p1 .hp-trail, .hud-player.p1 .hp-fill { right: 0; }
.hud-player.p2 .hp-trail, .hud-player.p2 .hp-fill { left: 0; }

.hp-trail {
  background: #ef4444;
  transition: width 0.12s linear;
}

.hp-fill {
  background: linear-gradient(180deg, #fde047 0%, #22c55e 100%);
}

.hp-fill.danger {
  background: linear-gradient(180deg, #fca5a5 0%, #dc2626 100%);
}

.super-track {
  height: 9px;
  background: #141226;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 4px;
  position: relative;
  overflow: hidden;
}

.super-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #06b6d4, #3b82f6, #facc15);
  transition: width 0.08s linear;
}

.super-fill.ready {
  animation: pulseReady 0.6s infinite alternate;
}

@keyframes pulseReady {
  from { filter: brightness(1); }
  to { filter: brightness(1.5); }
}

.super-label {
  position: absolute;
  inset: 0;
  font-size: 7px;
  font-weight: 900;
  letter-spacing: 0.12em;
  display: flex;
  align-items: center;
  justify-content: center;
  text-shadow: 0 1px 2px #000;
}

.hud-center {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
}

.timer-box {
  font-size: 24px;
  font-weight: 900;
  color: var(--gold);
  line-height: 1;
  background: #141129;
  border: 2px solid rgba(250, 204, 21, 0.6);
  border-radius: 10px;
  padding: 4px 10px;
  min-width: 48px;
  text-align: center;
}

.hud-meta {
  display: flex;
  gap: 4px;
  align-items: center;
}

.hud-mini-btn {
  font-size: 9px;
  font-weight: 800;
  background: rgba(255, 255, 255, 0.12);
  border: 1px solid var(--border);
  color: #fff;
  padding: 3px 6px;
  border-radius: 6px;
  cursor: pointer;
}

.ping-badge {
  font-size: 9px;
  font-weight: 800;
  color: #4ade80;
}

/* ARENA CANVAS */
.arena-wrap {
  flex: 1;
  width: 100%;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  min-height: 0;
}

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

/* MATCH RESULT OVERLAY */
.result-overlay {
  position: absolute;
  inset: 0;
  background: rgba(8, 6, 20, 0.78);
  backdrop-filter: blur(5px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 15;
}

.result-card {
  background: #181332;
  border: 2px solid var(--gold);
  border-radius: 20px;
  padding: 20px;
  text-align: center;
  width: min(320px, 88vw);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

.result-badge {
  font-size: 11px;
  font-weight: 900;
  color: var(--gold);
  letter-spacing: 0.14em;
}

.result-card img {
  width: 104px;
  height: 104px;
  border-radius: 16px;
  border: 3px solid var(--gold);
  object-fit: cover;
}

.result-actions {
  width: 100%;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 6px;
}

/* MOBILE MULTI-TOUCH ARCADE CONTROLS */
.touch-controls {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px max(12px, env(safe-area-inset-bottom));
  background: linear-gradient(0deg, rgba(10, 8, 22, 0.98), rgba(10, 8, 22, 0.7));
  z-index: 10;
  flex-shrink: 0;
}

.dpad-zone {
  width: 132px;
  height: 132px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.dpad-ring {
  width: 118px;
  height: 118px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.07);
  border: 2px solid rgba(255, 255, 255, 0.22);
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
}

.dpad-arrow {
  position: absolute;
  font-size: 12px;
  color: rgba(255, 255, 255, 0.35);
  pointer-events: none;
}
.dpad-arrow.up { top: 8px; }
.dpad-arrow.down { bottom: 8px; }
.dpad-arrow.left { left: 10px; }
.dpad-arrow.right { right: 10px; }

.dpad-knob {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #64748b, #1e293b);
  border: 2px solid rgba(255, 255, 255, 0.45);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.6);
  pointer-events: none;
}

.action-pad {
  display: grid;
  grid-template-columns: repeat(3, 56px);
  gap: 8px;
}

.arc-btn {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.32);
  color: #fff;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  line-height: 1;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.45);
  transition: transform 0.06s ease;
}

.arc-btn span { font-size: 14px; font-weight: 900; }
.arc-btn small { font-size: 8px; opacity: 0.85; margin-top: 2px; }

.arc-btn.active, .arc-btn:active {
  transform: scale(0.88);
  filter: brightness(1.3);
}

.btn-lp { background: linear-gradient(135deg, #3b82f6, #1d4ed8); }
.btn-hp { background: linear-gradient(135deg, #f97316, #c2410c); }
.btn-sp { background: linear-gradient(135deg, #06b6d4, #0e7490); }
.btn-lk { background: linear-gradient(135deg, #22c55e, #15803d); }
.btn-hk { background: linear-gradient(135deg, #ef4444, #b91c1c); }
.btn-sup { background: linear-gradient(135deg, #7c3aed, #db2777); opacity: 0.55; }
.btn-sup.ready {
  opacity: 1;
  border-color: var(--gold);
  box-shadow: 0 0 18px rgba(250, 204, 21, 0.75);
}

.desktop-keys-hint {
  display: none;
  font-size: 11px;
  color: var(--muted);
  text-align: center;
  padding: 4px 10px 6px;
  background: rgba(10, 8, 22, 0.9);
}

/* Landscape mobile: overlay touch controls transparently at bottom corners so arena is huge! */
@media (orientation: landscape) and (max-height: 520px) {
  .touch-controls {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    background: transparent;
    pointer-events: none;
    padding: 6px 14px;
  }
  .dpad-zone, .action-pad {
    pointer-events: auto;
    opacity: 0.78;
  }
  .dpad-ring { width: 102px; height: 102px; }
  .dpad-knob { width: 44px; height: 44px; }
  .action-pad { grid-template-columns: repeat(3, 48px); gap: 6px; }
  .arc-btn { width: 48px; height: 48px; }
}

@media (hover: hover) and (pointer: fine) and (min-width: 820px) {
  .desktop-keys-hint { display: block; }
  .touch-controls {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 24px;
    background: transparent;
    pointer-events: none;
    padding: 0 18px;
  }
  .dpad-zone, .action-pad {
    pointer-events: auto;
    opacity: 0.55;
  }
  .dpad-zone:hover, .action-pad:hover { opacity: 0.95; }
}
