/* ═══════════ BatPet 2.0 — Styles ═══════════ */
* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { height: 100%; font-family: 'Segoe UI', Tahoma, sans-serif; background: #1a1a2e; color: #e0e0e0; overflow: hidden; }

/* Screens */
.screen { display: none; width: 100%; height: 100%; }
.screen.active { display: flex; }

/* ───── Auth ───── */
#authScreen { align-items: center; justify-content: center; background: linear-gradient(135deg, #1a1a2e 0%, #16213e 50%, #0f3460 100%); }
.auth-box { background: #16213e; border-radius: 12px; padding: 40px; width: 400px; max-width: 95vw; box-shadow: 0 8px 32px rgba(0,0,0,0.4); text-align: center; }
.auth-box h1 { font-size: 2rem; margin-bottom: 4px; color: #e94560; }
.subtitle { color: #8888aa; margin-bottom: 24px; font-size: 0.9rem; }
.auth-form h2 { font-size: 1.2rem; margin-bottom: 16px; color: #53a8b6; }
.auth-form input[type="text"],
.auth-form input[type="password"] { display: block; width: 100%; padding: 10px 14px; margin-bottom: 12px; border: 1px solid #333; border-radius: 6px; background: #0f0f23; color: #e0e0e0; font-size: 0.95rem; }
.auth-form input:focus { border-color: #e94560; outline: none; }
.btn-primary { width: 100%; padding: 12px; border: none; border-radius: 6px; background: #e94560; color: #fff; font-size: 1rem; cursor: pointer; font-weight: 600; transition: background 0.2s; }
.btn-primary:hover { background: #c73552; }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }
.auth-switch { margin-top: 14px; font-size: 0.85rem; color: #888; }
.auth-switch a { color: #53a8b6; text-decoration: none; }
.auth-switch a:hover { text-decoration: underline; }
.error-msg { color: #e94560; font-size: 0.85rem; margin-top: 8px; min-height: 1.2em; }
.hint { color: #aaa; font-size: 0.8rem; margin-bottom: 12px; }
.gender-select { display: flex; gap: 20px; justify-content: center; margin-bottom: 16px; }
.gender-select label { cursor: pointer; font-size: 1rem; display: flex; align-items: center; gap: 6px; }

/* ───── Game screen layout ───── */
#gameScreen { flex-direction: column; background: #111; }
#topBar { display: flex; align-items: center; gap: 8px; padding: 6px 16px; background: #16213e; border-bottom: 1px solid #333; flex-shrink: 0; height: 40px; }
#playerInfo { font-weight: 600; color: #53a8b6; flex-shrink: 0; }
.btn-small { padding: 4px 12px; border: 1px solid #555; border-radius: 4px; background: transparent; color: #ccc; cursor: pointer; font-size: 0.8rem; flex-shrink: 0; }
.btn-small:hover { background: #333; }

/* ── News Ticker ── */
#newsTicker { flex: 1; overflow: hidden; position: relative; height: 24px; margin: 0 8px; }
#newsTickerInner { display: inline-block; white-space: nowrap; animation: tickerScroll 20s linear infinite; color: #d4d4d4; font-size: 0.8rem; line-height: 24px; }
#newsTicker:hover #newsTickerInner { animation-play-state: paused; }
.ticker-item { cursor: pointer; transition: color 0.2s; }
.ticker-item:hover { color: #58a6ff; }
.ticker-sep { color: #555; }
@keyframes tickerScroll { 0% { transform: translateX(100%); } 100% { transform: translateX(-100%); } }

/* ── News Bell ── */
#newsBtn { font-size: 18px; cursor: pointer; position: relative; flex-shrink: 0; user-select: none; line-height: 1; }
#newsBtn:hover { filter: brightness(1.3); }
#newsBadge { position: absolute; top: -6px; right: -8px; background: #e94560; color: #fff; font-size: 10px; font-weight: 700; min-width: 16px; height: 16px; border-radius: 8px; display: flex; align-items: center; justify-content: center; padding: 0 3px; }

/* ── News Popup ── */
#newsPopup { position: fixed; top: 0; left: 0; width: 100%; height: 100%; z-index: 9990; display: flex; align-items: center; justify-content: center; }
#newsPopupBackdrop { position: absolute; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.6); }
#newsPopupBox { position: relative; z-index: 1; width: 90%; max-width: 520px; max-height: 80vh; background: #161b22; border: 1px solid #30363d; border-radius: 12px; display: flex; flex-direction: column; overflow: hidden; box-shadow: 0 8px 32px rgba(0,0,0,0.5); }
#newsPopupHeader { display: flex; align-items: center; justify-content: space-between; padding: 14px 18px; border-bottom: 1px solid #30363d; flex-shrink: 0; }
#newsPopupTitle { color: #f0f6fc; font-weight: 600; font-size: 15px; }
#newsPopupClose { color: #8b949e; font-size: 24px; cursor: pointer; line-height: 1; width: 28px; height: 28px; display: flex; align-items: center; justify-content: center; border-radius: 6px; }
#newsPopupClose:hover { background: #21262d; color: #f0f6fc; }
#newsPopupBody { padding: 12px 18px; overflow-y: auto; flex: 1; }

/* News list items */
.news-list-item { display: flex; align-items: center; gap: 8px; padding: 10px 12px; border-radius: 8px; cursor: pointer; transition: background 0.15s; border-bottom: 1px solid #21262d; }
.news-list-item:last-child { border-bottom: none; }
.news-list-item:hover { background: #21262d; }
.news-list-title { flex: 1; color: #c9d1d9; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.news-list-date { color: #8b949e; font-size: 11px; flex-shrink: 0; }
.news-detail-content { color: #c9d1d9; font-size: 14px; line-height: 1.7; word-wrap: break-word; }
.news-detail-content h1,.news-detail-content h2,.news-detail-content h3 { color: #f0f6fc; margin: 12px 0 6px; }
.news-detail-content a { color: #58a6ff; }
.news-detail-content blockquote { border-left: 3px solid #30363d; padding-left: 12px; color: #8b949e; margin: 8px 0; }
.news-detail-content code { background: #0d1117; padding: 2px 6px; border-radius: 4px; font-size: 13px; }
.news-detail-content pre { background: #0d1117; padding: 12px; border-radius: 6px; overflow-x: auto; }

/* Main game area */
#gameShell { position: relative; flex: 1; display: flex; align-items: center; justify-content: center; overflow: hidden; background: #000; }
#controlsGuide { position: absolute; bottom: 6px; left: 50%; transform: translateX(-50%); background: rgba(0,0,0,0.65); color: #ccc; font-size: 12px; padding: 4px 14px; border-radius: 8px; z-index: 5; pointer-events: none; white-space: nowrap; backdrop-filter: blur(4px); }
#controlsGuide .cg-key { 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: bold; font-size: 11px; color: #fff; margin-right: 2px; }
#gbaPlayer { width: 100%; height: 100%; }

/* Online overlay (sits on top of emulator canvas) */
#onlineOverlay { position: absolute; top: 0; left: 0; width: 100%; height: 100%; pointer-events: none; z-index: 10; }

/* Loading overlay (covers emulator during intro auto-skip) */
#loadingOverlay { position: absolute; top: 0; left: 0; width: 100%; height: 100%; background: linear-gradient(135deg, #1a1a2e 0%, #16213e 50%, #0f3460 100%); z-index: 15; display: none; align-items: center; justify-content: center; flex-direction: column; }
#loadingOverlay.visible { display: flex; }
.loading-content { text-align: center; }
.loading-spinner { width: 48px; height: 48px; border: 4px solid rgba(255,255,255,0.15); border-top-color: #e94560; border-radius: 50%; margin: 0 auto 16px; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
#loadingText { color: #aaa; font-size: 0.95rem; }

/* Player name tags */
.player-name-tag { position: absolute; transform: translate(-50%, -100%); padding: 1px 6px; border-radius: 3px; font-size: 10px; font-weight: 600; white-space: nowrap; pointer-events: none; background: rgba(255,255,255,0.7); color: #000; text-shadow: 0 1px 2px rgba(255,255,255,0.6); display: none; }
.player-name-tag.visible { display: block; }
.player-name-tag.self { color: #0277bd; }

/* Remote player entities */
.player-remote-entity { position: absolute; left: 0; top: 0; will-change: transform; pointer-events: none; text-align: center; }
.player-remote-sprite { margin: 0 auto; background-repeat: no-repeat; image-rendering: pixelated; image-rendering: -moz-crisp-edges; image-rendering: crisp-edges; }
.player-name-remote { font-size: 9px; color: #000; text-shadow: 0 1px 2px rgba(255,255,255,0.6); white-space: nowrap; margin-top: 0; font-weight: 600; }

/* ───── Chat ───── */
#chatPanel { position: fixed; bottom: 0; left: 0; width: 260px; max-height: 220px; background: rgba(16,33,62,0.95); border-top: 1px solid #333; border-right: 1px solid #333; border-radius: 0 8px 0 0; display: flex; flex-direction: column; z-index: 20; }
#chatLog { flex: 1; overflow-y: auto; padding: 6px 8px; font-size: 0.75rem; max-height: 170px; }
#chatLog .chat-item { margin-bottom: 4px; }
#chatLog .chat-item strong { color: #53a8b6; margin-right: 6px; }
#chatLog .chat-item span { color: #666; font-size: 0.75rem; margin-left: 4px; }
#chatLog .chat-item p { margin: 0; color: #ccc; }
#chatInputRow { display: flex; padding: 4px; gap: 3px; border-top: 1px solid #333; }
#chatInput { flex: 1; padding: 5px 8px; border: 1px solid #444; border-radius: 4px; background: #0f0f23; color: #e0e0e0; font-size: 0.8rem; }
#chatInput:focus { border-color: #e94560; outline: none; }
#chatSendBtn { padding: 5px 10px; border: none; border-radius: 4px; background: #e94560; color: #fff; cursor: pointer; font-size: 0.75rem; }

/* ───── Players sidebar ───── */
#playersPanel { position: fixed; top: 40px; right: 0; width: 180px; max-height: 300px; background: rgba(16,33,62,0.92); border-left: 1px solid #333; border-bottom: 1px solid #333; border-radius: 0 0 0 8px; padding: 10px; overflow-y: auto; z-index: 20; }
#playersPanel h3 { font-size: 0.85rem; color: #53a8b6; margin-bottom: 8px; }
#playersList { list-style: none; font-size: 0.8rem; }
#playersList li { padding: 3px 0; color: #ccc; }
#playersList li::before { content: "🟢 "; font-size: 0.65rem; }

/* ───── Avatar selection modal ───── */
#avatarModal { position: fixed; top: 0; left: 0; width: 100%; height: 100%; z-index: 100; display: flex; align-items: center; justify-content: center; }
.avatar-modal-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,0.6); }
.avatar-modal-content { position: relative; background: #16213e; border-radius: 12px; padding: 24px; width: 440px; max-width: 95vw; max-height: 80vh; overflow-y: auto; box-shadow: 0 8px 32px rgba(0,0,0,0.5); text-align: center; }
.avatar-modal-content h3 { color: #e94560; margin-bottom: 4px; }
.avatar-hint { color: #888; font-size: 0.8rem; margin-bottom: 16px; }
#avatarGrid { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; }
.avatar-option { cursor: pointer; border: 3px solid transparent; border-radius: 8px; padding: 6px; background: #0f0f23; transition: border-color 0.2s, transform 0.15s; text-align: center; width: 72px; }
.avatar-option:hover { border-color: #53a8b6; transform: scale(1.05); }
.avatar-option.selected { border-color: #e94560; background: #1a1030; }
.avatar-option img { width: 32px; height: 64px; image-rendering: pixelated; image-rendering: -moz-crisp-edges; image-rendering: crisp-edges; object-fit: none; object-position: 0 0; }
.avatar-option .avatar-label { font-size: 0.7rem; color: #aaa; margin-top: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ───── Pokeball button ───── */
.pokeball-btn { position: fixed; bottom: 20px; right: 20px; width: 52px; height: 52px; z-index: 30; cursor: pointer; filter: drop-shadow(0 2px 8px rgba(0,0,0,0.5)); transition: transform 0.15s; }
.pokeball-btn:hover { transform: scale(1.12); }
.pokeball-icon { width: 52px; height: 52px; border-radius: 50%; overflow: hidden; position: relative; border: 3px solid #222; box-sizing: border-box; }
.pokeball-top { height: 50%; background: #e94560; }
.pokeball-bot { height: 50%; background: #f0f0f0; }
.pokeball-mid { position: absolute; top: 50%; left: 50%; transform: translate(-50%,-50%); width: 22px; height: 22px; background: #fff; border: 3px solid #222; border-radius: 50%; z-index: 2; display: flex; align-items: center; justify-content: center; overflow: hidden; }
.pokeball-dot { width: 8px; height: 8px; background: #222; border-radius: 50%; }
.pokeball-avatar { width: 16px; height: 16px; image-rendering: pixelated; image-rendering: -moz-crisp-edges; image-rendering: crisp-edges; }
.pokeball-icon::after { content: ''; position: absolute; top: calc(50% - 2px); left: 0; right: 0; height: 4px; background: #222; z-index: 1; }

/* ───── Hide EmulatorJS UI (keep audio + video) ───── */
#gbaPlayer .ejs--controls { display: none !important; }
#gbaPlayer .ejs--bar { display: none !important; }
#gbaPlayer [class*="ejs_menu"] { display: none !important; }
#gbaPlayer .ejs--dialogs { display: none !important; }
#gbaPlayer .ejs--save-state { display: none !important; }
#gbaPlayer .ejs--load-state { display: none !important; }
#gbaPlayer .ejs--cheat-menu { display: none !important; }

/* ───── Pokemenu panel ───── */
.pokemenu-panel { position: fixed; bottom: 80px; right: 20px; width: 310px; max-height: 70vh; background: rgba(16,33,62,0.96); border: 1px solid #444; border-radius: 12px; padding: 0; z-index: 30; overflow-y: auto; box-shadow: 0 8px 32px rgba(0,0,0,0.6); display: none; }
.pokemenu-title { text-align: center; font-size: 0.9rem; font-weight: bold; color: #e94560; padding: 12px 14px 8px; border-bottom: 1px solid #333; letter-spacing: 2px; }
.pokemenu-item { padding: 12px 18px; color: #ddd; font-size: 0.85rem; cursor: pointer; transition: background 0.15s; display: flex; align-items: center; gap: 10px; }
.pokemenu-item:hover { background: rgba(233,69,96,0.15); }
.pokemenu-item.pokemenu-close { color: #888; border-top: 1px solid #333; }
.pokemenu-icon { font-size: 1rem; }

/* ───── Menu header with back button ───── */
.pokemenu-header { display: flex; align-items: center; gap: 10px; padding: 12px 14px; border-bottom: 1px solid #333; font-size: 0.85rem; font-weight: bold; color: #e94560; letter-spacing: 1px; }
.pokemenu-back { cursor: pointer; color: #888; font-size: 1rem; transition: color 0.15s; }
.pokemenu-back:hover { color: #fff; }
.pokemenu-count { margin-left: auto; color: #888; font-size: 0.75rem; font-weight: normal; }

/* ───── Pokemon list items ───── */
.pokemenu-list { padding: 4px 0; }
.pokemenu-pokemon { padding: 8px 14px; cursor: pointer; transition: background 0.15s; border-bottom: 1px solid rgba(255,255,255,0.04); }
.pokemenu-pokemon:hover { background: rgba(83,168,182,0.12); }
.pokemenu-pokemon.empty { cursor: default; padding: 6px 14px; }
.pokemenu-pokemon.empty:hover { background: transparent; }
.pokemenu-pokemon-top { display: flex; align-items: center; justify-content: space-between; }
.pokemenu-pname { color: #e0e0e0; font-weight: bold; font-size: 0.82rem; }
.pokemenu-plevel { color: #53a8b6; font-size: 0.75rem; }
.pokemenu-pokemon-bot { display: flex; align-items: center; gap: 8px; margin-top: 3px; }
.pokemenu-species { color: #888; font-size: 0.7rem; min-width: 64px; }
.pokemenu-hp-bar { flex: 1; height: 6px; background: #1a1a2e; border-radius: 3px; overflow: hidden; }
.pokemenu-hp-bar.wide { flex: 1; height: 8px; }
.pokemenu-hp-fill { height: 100%; border-radius: 3px; transition: width 0.3s; }
.pokemenu-hp-text { color: #aaa; font-size: 0.65rem; min-width: 50px; text-align: right; }
.pokemenu-empty { text-align: center; padding: 20px 14px; color: #555; font-size: 0.8rem; }

/* ───── Pokedex view ───── */
.pokemenu-dex-stats { padding: 16px; }
.pokemenu-dex-row { display: flex; justify-content: space-between; padding: 8px 0; border-bottom: 1px solid rgba(255,255,255,0.05); }
.pokemenu-dex-label { color: #aaa; font-size: 0.82rem; }
.pokemenu-dex-val { color: #53a8b6; font-weight: bold; font-size: 0.9rem; }

/* ───── Pokemon detail view ───── */
.pkd-topinfo { padding: 10px 14px 6px; }
.pkd-species { color: #53a8b6; font-size: 0.8rem; }
.pkd-level { color: #e0e0e0; font-weight: bold; font-size: 0.9rem; margin-top: 2px; }
.pkd-nature { color: #ccc; font-size: 0.78rem; margin-top: 4px; }
.pkd-ot { color: #aaa; font-size: 0.75rem; margin-top: 2px; }
.pkd-section { padding: 6px 14px; }
.pkd-section-title { color: #e94560; font-size: 0.72rem; font-weight: bold; letter-spacing: 1px; margin-bottom: 6px; padding-bottom: 3px; border-bottom: 1px solid #333; }
.pkd-stat-row { display: flex; align-items: center; gap: 6px; margin-bottom: 4px; }
.pkd-stat-name { color: #aaa; font-size: 0.72rem; min-width: 50px; }
.pkd-stat-bar { flex: 1; height: 6px; background: #1a1a2e; border-radius: 3px; overflow: hidden; }
.pkd-stat-fill { height: 100%; background: #53a8b6; border-radius: 3px; }
.pkd-stat-val { color: #e0e0e0; font-size: 0.75rem; min-width: 30px; text-align: right; }
.pkd-iv-grid { font-size: 0.72rem; }
.pkd-iv-header { display: grid; grid-template-columns: 50px 1fr 1fr; color: #888; padding-bottom: 4px; border-bottom: 1px solid rgba(255,255,255,0.06); margin-bottom: 2px; }
.pkd-iv-row { display: grid; grid-template-columns: 50px 1fr 1fr; padding: 2px 0; color: #ccc; }
.pkd-iv-row span:first-child { color: #aaa; }
.pkd-move { padding: 4px 8px; margin-bottom: 3px; background: #0f0f23; border: 1px solid #333; border-radius: 4px; color: #e0e0e0; font-size: 0.78rem; }
.pkd-exp { color: #888; font-size: 0.72rem; text-align: center; padding: 4px 0 8px; }

/* Responsive */
/* ───── PC Box views ───── */
.pc-box-list .pc-box-item { cursor: pointer; }
.pc-box-item.pc-active { border-left: 3px solid #e94560; }
.pc-box-bar { height: 4px; background: #1a1a2e; border-radius: 2px; margin-top: 4px; overflow: hidden; }
.pc-box-fill { height: 100%; background: #53a8b6; border-radius: 2px; transition: width 0.3s; }
.pc-nav-btn { cursor: pointer; color: #53a8b6; font-size: 1rem; padding: 0 6px; user-select: none; }
.pc-nav-btn:hover { color: #e94560; }
/* Pokemon sprite icons (32×64 two-frame sheets, animated) */
@keyframes poke-bounce {
  0%, 40%  { object-position: 0 0; }
  50%, 90% { object-position: 0 100%; }
}
.poke-icon { width: 32px; height: 32px; object-fit: cover; object-position: 0 0; image-rendering: pixelated; display: block; margin: 0 auto; animation: poke-bounce 0.6s steps(1) infinite; }
.poke-icon-sm { width: 24px; height: 24px; object-fit: cover; object-position: 0 0; image-rendering: pixelated; vertical-align: middle; margin-right: 4px; display: inline-block; animation: poke-bounce 0.6s steps(1) infinite; }
.poke-icon-lg { width: 48px; height: 48px; object-fit: cover; object-position: 0 0; image-rendering: pixelated; display: block; margin: 0 auto 4px; animation: poke-bounce 0.6s steps(1) infinite; }

.pc-grid { display: grid; grid-template-columns: repeat(6, 1fr); gap: 3px; padding: 8px 10px; }
.pc-slot { aspect-ratio: 1; border-radius: 4px; display: flex; flex-direction: column; align-items: center; justify-content: center; font-size: 0.6rem; min-height: 0; overflow: hidden; }
.pc-slot.empty { background: rgba(255,255,255,0.03); border: 1px solid rgba(255,255,255,0.05); }
.pc-slot.filled { background: rgba(83,168,182,0.12); border: 1px solid rgba(83,168,182,0.3); cursor: grab; transition: background 0.15s; }
.pc-slot.filled:hover { background: rgba(83,168,182,0.25); }
.pc-slot.filled:active { cursor: grabbing; }
.pc-slot.filled.dragging { opacity: 0.4; }
.pc-slot-name { color: #e0e0e0; font-size: 0.58rem; text-align: center; line-height: 1.1; word-break: break-all; }
.pc-slot-info { color: #888; font-size: 0.52rem; margin-top: 1px; }

/* ═══════════ TEAM MENU (inside Pokeball menu) ═══════════ */
.team-tabs { display: flex; border-bottom: 1px solid #333; margin-bottom: 6px; }
.team-tab {
  flex: 1; text-align: center; padding: 6px 0; font-size: 0.7rem; font-weight: 600;
  color: #888; cursor: pointer; border-bottom: 2px solid transparent;
  transition: all 0.15s;
}
.team-tab:hover { color: #ccc; }
.team-tab.active { color: #53a8b6; border-bottom-color: #53a8b6; }
.team-tab.is-party { color: #4caf50; }
.team-tab.is-party.active { color: #4caf50; border-bottom-color: #4caf50; }

.team-slots { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; padding: 4px 8px; }
.team-slot {
  background: rgba(255,255,255,0.04); border: 1px dashed rgba(255,255,255,0.12);
  border-radius: 6px; padding: 6px 4px; min-height: 44px;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  font-size: 0.65rem; color: #555; cursor: default;
  transition: border-color 0.15s, background 0.15s;
  position: relative;
}
.team-slot.drag-over { border-color: #53a8b6; background: rgba(83,168,182,0.15); }
.team-slot.has-pokemon {
  background: rgba(83,168,182,0.08); border: 1px solid rgba(83,168,182,0.25);
  color: #e0e0e0; cursor: grab;
}
.team-slot.has-pokemon:active { cursor: grabbing; }
.team-slot.dragging { opacity: 0.4; }
.team-slot-name { font-size: 0.63rem; font-weight: 600; color: #e0e0e0; text-align: center; line-height: 1.1; }
.team-slot-info { font-size: 0.53rem; color: #888; margin-top: 1px; }
.team-slot-remove {
  position: absolute; top: 1px; right: 3px; font-size: 0.6rem;
  color: #666; cursor: pointer; line-height: 1;
}
.team-slot-remove:hover { color: #e94560; }
.team-slot-empty { color: #444; font-size: 0.6rem; }

.team-apply-btn {
  display: block; width: calc(100% - 16px); margin: 6px 8px;
  padding: 7px 0; border: none; border-radius: 5px;
  background: #e94560; color: #fff; font-size: 0.72rem; font-weight: 600;
  cursor: pointer; transition: background 0.15s;
}
.team-apply-btn:hover { background: #c73552; }
.team-apply-btn:disabled { opacity: 0.4; cursor: not-allowed; }

/* Team lock banner */
.team-lock-banner {
  background: linear-gradient(135deg, #1a1a2e, #16213e);
  border: 1px solid #ff9800;
  border-radius: 6px;
  margin: 6px 8px;
  padding: 8px 10px;
  text-align: center;
  font-size: 0.65rem;
  color: #ff9800;
  font-weight: 600;
}
.team-lock-progress {
  width: 100%;
  height: 6px;
  background: #333;
  border-radius: 3px;
  margin: 5px 0 3px;
  overflow: hidden;
}
.team-lock-bar {
  height: 100%;
  background: linear-gradient(90deg, #ff9800, #ffc107);
  border-radius: 3px;
  transition: width 0.4s ease;
}
.team-lock-count {
  font-size: 0.6rem;
  color: #aaa;
  font-weight: 400;
}

/* PC Box embedded inside Team view */
.team-pc-section { border-top: 1px solid #333; margin-top: 6px; padding-top: 4px; }
.team-pc-header { display: flex; align-items: center; justify-content: center; gap: 8px; padding: 4px 8px; font-size: 0.7rem; color: #aaa; font-weight: 600; }
.team-pc-title { flex: 0 1 auto; text-align: center; }
.team-apply-btn:disabled { opacity: 0.4; cursor: not-allowed; }

.team-party-badge {
  display: inline-block; background: #4caf50; color: #fff; font-size: 0.5rem;
  padding: 1px 4px; border-radius: 3px; margin-left: 4px; vertical-align: middle;
}

/* Adjust game layout — no left panel */
#gameShell { transition: margin-left 0.25s ease; }

/* ───── Mobile toggle buttons ───── */
.mobile-toggle-chat,
.mobile-toggle-players {
  display: none; /* hidden on desktop */
  position: fixed; z-index: 25;
  width: 36px; height: 36px;
  border-radius: 50%;
  border: 1px solid #444;
  background: rgba(16,33,62,0.92);
  color: #aaa;
  font-size: 0.9rem;
  cursor: pointer;
  align-items: center; justify-content: center;
  box-shadow: 0 2px 8px rgba(0,0,0,0.4);
  -webkit-tap-highlight-color: transparent;
}
.mobile-toggle-chat { bottom: 80px; left: 10px; }
.mobile-toggle-players { top: 42px; right: 10px; }
.mobile-toggle-chat.active,
.mobile-toggle-players.active { background: rgba(233,69,96,0.3); color: #fff; border-color: #e94560; }

@media (max-width: 600px) {
  /* ───── Auth ───── */
  .auth-box { padding: 20px 16px; width: 100%; max-width: 100vw; border-radius: 0; }
  .auth-box h1 { font-size: 1.5rem; }
  .subtitle { font-size: 0.85rem; margin-bottom: 16px; }
  .auth-form input[type="text"],
  .auth-form input[type="password"] { font-size: 1rem; padding: 12px 14px; }
  .btn-primary { font-size: 1rem; padding: 14px; }
  .gender-select { gap: 12px; }
  .gender-select label { font-size: 0.95rem; }

  /* ───── Top bar ───── */
  #topBar { padding: 4px 8px; height: 36px; gap: 4px; }
  #playerInfo { font-size: 0.75rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 90px; }
  #onlineCount { font-size: 0.7rem; }
  .btn-small { padding: 4px 8px; font-size: 0.7rem; }

  /* ───── Chat panel — bottom drawer ───── */
  #chatPanel { width: 100%; border-radius: 0; max-height: 180px; }
  #chatLog { max-height: 130px; font-size: 0.8rem; padding: 6px; }
  #chatInputRow { padding-right: 70px; }
  #chatInput { font-size: 0.9rem; padding: 8px 10px; }
  #chatSendBtn { font-size: 0.8rem; padding: 8px 14px; min-width: 44px; min-height: 36px; }

  /* ───── Players sidebar — narrower ───── */
  #playersPanel { width: 130px; max-height: 240px; padding: 6px; top: 36px; }
  #playersPanel h3 { font-size: 0.75rem; margin-bottom: 4px; }
  #playersList { font-size: 0.72rem; }
  #playersList li { padding: 2px 0; }

  /* ───── Pokeball button — easier to tap ───── */
  .pokeball-btn { width: 56px; height: 56px; bottom: 14px; right: 10px; }
  .pokeball-icon { width: 56px; height: 56px; }

  /* ───── Pokemenu panel — full width bottom sheet ───── */
  .pokemenu-panel {
    width: 100vw !important;
    max-width: 100vw !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    max-height: 75vh;
    border-radius: 16px 16px 0 0;
    border: none;
    border-top: 1px solid #444;
  }
  .pokemenu-title { font-size: 1rem; padding: 14px 16px 10px; }
  .pokemenu-item { padding: 14px 18px; font-size: 0.95rem; min-height: 48px; }
  .pokemenu-icon { font-size: 1.1rem; }
  .pokemenu-header { padding: 12px 16px; font-size: 0.9rem; }
  .pokemenu-back { font-size: 1.2rem; padding: 4px; min-width: 32px; min-height: 32px; display: flex; align-items: center; justify-content: center; }
  .pokemenu-count { font-size: 0.8rem; }

  /* ───── Pokemon list ───── */
  .pokemenu-pokemon { padding: 10px 14px; }
  .pokemenu-pname { font-size: 0.9rem; }
  .pokemenu-plevel { font-size: 0.8rem; }
  .pokemenu-species { font-size: 0.75rem; }
  .pokemenu-hp-bar { height: 8px; }
  .pokemenu-hp-text { font-size: 0.72rem; }

  /* ───── Pokemon detail ───── */
  .pkd-topinfo { padding: 12px 16px 8px; }
  .pkd-species { font-size: 0.85rem; }
  .pkd-level { font-size: 1rem; }
  .pkd-nature { font-size: 0.85rem; }
  .pkd-ot { font-size: 0.8rem; }
  .pkd-section { padding: 8px 16px; }
  .pkd-section-title { font-size: 0.78rem; }
  .pkd-stat-row { margin-bottom: 6px; }
  .pkd-stat-name { font-size: 0.78rem; min-width: 44px; }
  .pkd-stat-bar { height: 8px; }
  .pkd-stat-val { font-size: 0.8rem; }
  .pkd-iv-grid { font-size: 0.78rem; }
  .pkd-move { font-size: 0.85rem; padding: 6px 10px; }

  /* ───── Pokedex ───── */
  .pokemenu-dex-row { padding: 10px 0; }
  .pokemenu-dex-label { font-size: 0.88rem; }
  .pokemenu-dex-val { font-size: 0.95rem; }

  /* ───── Team menu ───── */
  .team-tabs { margin-bottom: 4px; }
  .team-tab { padding: 10px 0; font-size: 0.78rem; }
  .team-party-badge { font-size: 0.55rem; padding: 2px 5px; }
  .team-slots { gap: 5px; padding: 4px 10px; }
  .team-slot { min-height: 52px; padding: 8px 6px; }
  .team-slot-name { font-size: 0.7rem; }
  .team-slot-info { font-size: 0.6rem; }
  .team-slot-remove { font-size: 0.7rem; top: 2px; right: 5px; min-width: 24px; min-height: 24px; display: flex; align-items: center; justify-content: center; }
  .team-slot-empty { font-size: 0.65rem; }
  .team-apply-btn { font-size: 0.82rem; padding: 10px 0; margin: 8px 10px; min-height: 44px; }
  .team-lock-banner { margin: 6px 10px; padding: 10px 12px; font-size: 0.72rem; }
  .team-lock-progress { height: 8px; }
  .team-lock-count { font-size: 0.65rem; }

  /* ───── PC grid — 5 columns on small screens ───── */
  .pc-grid { grid-template-columns: repeat(5, 1fr); gap: 3px; padding: 6px 8px; }
  .pc-slot { font-size: 0.55rem; }
  .pc-slot-name { font-size: 0.55rem; }
  .pc-slot-info { font-size: 0.5rem; }
  .team-pc-header { font-size: 0.72rem; padding: 6px 10px; }
  .pc-nav-btn { font-size: 1.2rem; padding: 2px 8px; min-width: 32px; min-height: 32px; display: inline-flex; align-items: center; justify-content: center; }

  /* ───── Avatar modal ───── */
  .avatar-modal-content { padding: 16px; width: 100%; max-width: 100vw; border-radius: 12px 12px 0 0; }
  .avatar-option { width: 64px; padding: 4px; }

  /* ───── Poke icons — slightly larger for touch ───── */
  .poke-icon { width: 36px; height: 36px; }
  .poke-icon-sm { width: 28px; height: 28px; }

  /* ───── Mobile toggle buttons ───── */
  .mobile-toggle-chat,
  .mobile-toggle-players { display: flex; }

  /* ───── Chat & Players default hidden on mobile ───── */
  #chatPanel { display: none; }
  #chatPanel.mobile-open { display: flex; }
  #playersPanel { display: none; }
  #playersPanel.mobile-open { display: block; }

  /* ───── Hide controls guide on mobile (virtual gamepad replaces it) ───── */
  #controlsGuide { display: none; }

  /* ───── Touch optimizations ───── */
  * { -webkit-tap-highlight-color: transparent; }
  .pokemenu-item:active { background: rgba(233,69,96,0.2); }
  .team-tab:active { background: rgba(83,168,182,0.15); }
  .pokemenu-pokemon:active { background: rgba(83,168,182,0.18); }

  /* ───── Virtual gamepad adjustments ───── */
  #gameShell { padding-bottom: 180px; }
  .pokeball-btn { bottom: 194px; }
}

/* ───── Very small phones (≤360px) ───── */
@media (max-width: 360px) {
  .auth-box { padding: 16px 12px; }
  #topBar { padding: 3px 6px; }
  #playerInfo { max-width: 70px; font-size: 0.7rem; }
  .pokemenu-panel { max-height: 80vh; }
  .pokemenu-item { padding: 12px 14px; font-size: 0.88rem; }
  .pc-grid { grid-template-columns: repeat(5, 1fr); gap: 2px; }
  .team-slots { gap: 3px; padding: 3px 6px; }
  .team-slot { min-height: 48px; }
}

/* ───── Landscape phone ───── */
@media (max-height: 500px) and (orientation: landscape) {
  #topBar { height: 30px; padding: 2px 8px; }
  #topBar .btn-small { padding: 2px 8px; }
  .pokemenu-panel { max-height: 85vh; bottom: 0 !important; border-radius: 12px 12px 0 0; }
  .pokemenu-item { padding: 10px 16px; min-height: 40px; }
  .pokeball-btn { width: 44px; height: 44px; bottom: 8px; right: 8px; }
  .pokeball-icon { width: 44px; height: 44px; }
  .pokeball-mid { width: 18px; height: 18px; }
  #chatPanel { max-height: 140px; }
  #chatLog { max-height: 90px; }
  #playersPanel { top: 30px; max-height: 180px; }
  /* Landscape: smaller gamepad */
  #virtualGamepad { height: 140px; }
  #virtualGamepad.active { padding: 0 8px 8px; }
  .vgp-dpad { width: 100px; height: 100px; }
  .vgp-dpad-btn { width: 34px; height: 34px; font-size: 14px; }
  .vgp-btn { width: 42px; height: 42px; font-size: 14px; }
  .vgp-btn-a { margin-bottom: 14px; }
  .vgp-meta { bottom: 148px; }
  .vgp-shoulder-left { bottom: 148px; }
  .vgp-shoulder-right { bottom: 148px; }
  #gameShell { padding-bottom: 140px; }
  .pokeball-btn { bottom: 150px; }
}

/* ═══════════ PVP SYSTEM ═══════════ */

/* ═══════════ VIRTUAL GAMEPAD (mobile) ═══════════ */
#virtualGamepad { display: none; position: fixed; bottom: 0; left: 0; right: 0; height: 180px; z-index: 25; pointer-events: none; }
#virtualGamepad.active { display: flex; justify-content: space-between; align-items: flex-end; padding: 0 12px 16px; }

/* D-Pad */
.vgp-dpad { position: relative; width: 130px; height: 130px; pointer-events: auto; }
.vgp-dpad-btn { position: absolute; width: 44px; height: 44px; background: rgba(255,255,255,0.18); border: 2px solid rgba(255,255,255,0.3); border-radius: 8px; display: flex; align-items: center; justify-content: center; font-size: 18px; color: rgba(255,255,255,0.7); user-select: none; -webkit-user-select: none; touch-action: none; }
.vgp-dpad-btn:active, .vgp-dpad-btn.pressed { background: rgba(233,69,96,0.45); border-color: rgba(233,69,96,0.7); }
.vgp-dpad-up    { top: 0; left: 50%; transform: translateX(-50%); }
.vgp-dpad-down  { bottom: 0; left: 50%; transform: translateX(-50%); }
.vgp-dpad-left  { left: 0; top: 50%; transform: translateY(-50%); }
.vgp-dpad-right { right: 0; top: 50%; transform: translateY(-50%); }

/* Action buttons (A, B) */
.vgp-actions { display: flex; gap: 10px; align-items: flex-end; pointer-events: auto; }
.vgp-btn { width: 52px; height: 52px; border-radius: 50%; background: rgba(255,255,255,0.18); border: 2px solid rgba(255,255,255,0.3); display: flex; align-items: center; justify-content: center; font-size: 16px; font-weight: 700; color: rgba(255,255,255,0.8); user-select: none; -webkit-user-select: none; touch-action: none; }
.vgp-btn:active, .vgp-btn.pressed { background: rgba(233,69,96,0.45); border-color: rgba(233,69,96,0.7); }
.vgp-btn-a { margin-bottom: 20px; }
.vgp-btn-b { margin-bottom: 0; }

/* Small buttons (Start, Select, L, R) */
.vgp-meta { position: fixed; bottom: 186px; left: 50%; transform: translateX(-50%); display: flex; gap: 12px; pointer-events: auto; }
.vgp-meta-btn { padding: 6px 14px; border-radius: 12px; background: rgba(255,255,255,0.12); border: 1px solid rgba(255,255,255,0.2); font-size: 11px; font-weight: 600; color: rgba(255,255,255,0.6); user-select: none; -webkit-user-select: none; touch-action: none; }
.vgp-meta-btn:active, .vgp-meta-btn.pressed { background: rgba(233,69,96,0.35); border-color: rgba(233,69,96,0.6); }

.vgp-shoulder { position: fixed; top: auto; display: flex; gap: 8px; pointer-events: auto; }
.vgp-shoulder-left { left: 12px; bottom: 196px; }
.vgp-shoulder-right { right: 12px; bottom: 196px; }

/* ═══════════ PVP SYSTEM ═══════════ */
.btn-pvp { display:block; width:100%; padding:8px; margin-top:10px; border:none; border-radius:6px; background:#e94560; color:#fff; font-size:0.8rem; font-weight:600; cursor:pointer; transition:background 0.2s; }
.btn-pvp:hover { background:#c73552; }
.btn-pvp:disabled { opacity:0.5; cursor:not-allowed; }
.btn-pvp-secondary { display:block; width:100%; padding:6px; margin-top:6px; border:1px solid #53a8b6; border-radius:6px; background:transparent; color:#53a8b6; font-size:0.75rem; cursor:pointer; transition:background 0.2s; }
.btn-pvp-secondary:hover { background:rgba(83,168,182,0.15); }

/* PVP Queue & Result overlays */
#pvpQueueOverlay, #pvpResultOverlay, #pvpLeaderboardOverlay { position:fixed; top:0; left:0; width:100%; height:100%; background:rgba(0,0,0,0.7); z-index:200; display:flex; align-items:center; justify-content:center; }
.pvp-overlay-box { background:#16213e; border-radius:12px; padding:32px; text-align:center; min-width:280px; box-shadow:0 8px 32px rgba(0,0,0,0.5); }
.pvp-overlay-box h2 { color:#e94560; margin-bottom:12px; }

/* PVP Battle overlay */
#pvpBattleOverlay { position:fixed; top:0; left:0; width:100%; height:100%; background:rgba(0,0,0,0.85); z-index:200; display:flex; align-items:center; justify-content:center; }
.pvp-battle-container { background:linear-gradient(180deg, #1a2a4a 0%, #0d1b2a 100%); border-radius:12px; width:520px; max-width:96vw; max-height:96vh; overflow-y:auto; box-shadow:0 8px 40px rgba(0,0,0,0.6); display:flex; flex-direction:column; }
.pvp-battle-header { display:flex; align-items:center; justify-content:space-between; padding:8px 16px; background:rgba(0,0,0,0.3); border-radius:12px 12px 0 0; font-size:0.85rem; }
#pvpBattleVs { color:#e94560; font-weight:700; }

/* Pokemon display */
.pvp-side { padding:10px 16px; }
.pvp-opponent { border-bottom:1px solid rgba(255,255,255,0.08); }
.pvp-active-pokemon { display:flex; align-items:center; gap:12px; }
.pvp-sprite { width:80px; height:80px; image-rendering:pixelated; image-rendering:-moz-crisp-edges; background:#0f0f23; border-radius:8px; }
.pvp-pokemon-info { flex:1; }
.pvp-pokemon-info span { display:inline-block; margin-right:8px; font-size:0.85rem; }
#pvpSelfName, #pvpOppName { color:#fff; font-weight:600; }
#pvpSelfLevel, #pvpOppLevel { color:#aaa; font-size:0.75rem; }
.pvp-hp-bar { width:100%; height:8px; background:#333; border-radius:4px; margin-top:4px; overflow:hidden; }
.pvp-hp-fill { height:100%; background:#4caf50; border-radius:4px; transition:width 0.4s; }
.pvp-hp-fill.yellow { background:#ff9800; }
.pvp-hp-fill.red { background:#f44336; }
.pvp-hp-text { font-size:0.7rem; color:#aaa; display:block; margin-top:2px; }
.pvp-status-badge { font-size:0.7rem; padding:1px 6px; border-radius:3px; color:#fff; font-weight:600; }
.pvp-status-badge.burn { background:#e65100; }
.pvp-status-badge.paralyze { background:#f9a825; color:#000; }
.pvp-status-badge.poison, .pvp-status-badge.badly_poison { background:#7b1fa2; }
.pvp-status-badge.sleep { background:#546e7a; }
.pvp-status-badge.freeze { background:#00bcd4; }
.pvp-status-badge.confusion { background:#ff7043; }

/* Party indicators */
.pvp-party-bar { display:flex; gap:4px; margin:4px 0; }
.pvp-party-dot { width:14px; height:14px; border-radius:50%; background:#4caf50; border:1px solid rgba(255,255,255,0.2); }
.pvp-party-dot.fainted { background:#555; }
.pvp-party-dot.empty { background:transparent; border:1px solid #444; }
.pvp-party-dot.active { box-shadow:0 0 6px #4fc3f7; border-color:#4fc3f7; }

/* Battle log */
.pvp-battle-log { height:80px; overflow-y:auto; padding:6px 16px; font-size:0.75rem; color:#aaa; background:rgba(0,0,0,0.2); border-top:1px solid rgba(255,255,255,0.05); }
.pvp-battle-log .pvp-log-entry { margin-bottom:2px; }
.pvp-log-entry.super_effective { color:#ff9800; }
.pvp-log-entry.not_very_effective { color:#888; }
.pvp-log-entry.crit { color:#f44336; }
.pvp-log-entry.faint { color:#e94560; font-weight:600; }

/* Action panel */
.pvp-action-panel { padding:10px 16px 14px; border-top:1px solid rgba(255,255,255,0.08); }
.pvp-moves { display:grid; grid-template-columns:1fr 1fr; gap:6px; margin-bottom:6px; }
.pvp-move-btn { padding:10px 8px; border:1px solid #444; border-radius:6px; background:#0f1a2e; color:#e0e0e0; font-size:0.8rem; cursor:pointer; transition:background 0.15s, border-color 0.15s; text-align:center; }
.pvp-move-btn:hover { background:#1a2a4a; border-color:#53a8b6; }
.pvp-move-btn:disabled { opacity:0.4; cursor:not-allowed; }
.pvp-switches { display:flex; flex-wrap:wrap; gap:4px; }
.pvp-switch-btn { padding:5px 10px; border:1px solid #555; border-radius:4px; background:transparent; color:#ccc; font-size:0.7rem; cursor:pointer; }
.pvp-switch-btn:hover { background:rgba(83,168,182,0.15); border-color:#53a8b6; }
.pvp-switch-btn:disabled { opacity:0.3; cursor:not-allowed; }

/* Leaderboard */
.pvp-leaderboard-box { background:#16213e; border-radius:12px; padding:24px; min-width:360px; max-width:500px; max-height:80vh; overflow-y:auto; box-shadow:0 8px 32px rgba(0,0,0,0.5); text-align:center; }
.pvp-leaderboard-box h2 { color:#e94560; margin-bottom:16px; }
#pvpLeaderboardTable { width:100%; border-collapse:collapse; font-size:0.85rem; }
#pvpLeaderboardTable th { color:#53a8b6; padding:6px 8px; border-bottom:1px solid #333; text-align:center; }
#pvpLeaderboardTable td { padding:6px 8px; border-bottom:1px solid #222; text-align:center; color:#ccc; }
#pvpLeaderboardTable tr:hover td { background:rgba(83,168,182,0.08); }
#pvpLeaderboardTable .rank-1 { color:#ffd700; font-weight:700; }
#pvpLeaderboardTable .rank-2 { color:#c0c0c0; font-weight:600; }
#pvpLeaderboardTable .rank-3 { color:#cd7f32; font-weight:600; }
