:root {
  --bg-color: #0b0f19;
  --surface: #151d30;
  --surface-border: #24324f;
  --text-main: #f8fafc;
  --text-dim: #94a3b8;
  --accent: #38bdf8;
  --accent-hover: #0284c7;
  --player-red: #ef4444;
  --player-blue: #3b82f6;
  --player-green: #10b981;
  --player-yellow: #f59e0b;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

html, body {
  background-color: var(--bg-color);
  color: var(--text-main);
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  justify-content: center;
  align-items: center;
  overflow-x: hidden;
  overscroll-behavior: none;
  touch-action: manipulation;
}

.hidden {
  display: none !important;
}

/* =========================================
   VIEW 1: LOBBY / MENU AWAL
========================================= */
.lobby-wrapper {
  width: 100%;
  max-width: 680px;
  padding: 16px;
  display: flex;
  justify-content: center;
  align-items: center;
}

.lobby-card {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--surface-border);
  border-radius: 20px;
  padding: 28px 24px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.6);
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.lobby-header {
  text-align: center;
}

.lobby-header h1 {
  font-size: 2rem;
  letter-spacing: 1.5px;
  margin-bottom: 4px;
}

.lobby-header h1 span {
  color: var(--accent);
}

.lobby-subtitle {
  color: var(--text-dim);
  font-size: 0.9rem;
}

.lobby-section {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.player-name-section label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.input-with-icon {
  display: flex;
  align-items: center;
  background: #0b0f19;
  border: 2px solid var(--surface-border);
  border-radius: 12px;
  padding: 4px 14px;
  transition: border-color 0.2s;
}

.input-with-icon:focus-within {
  border-color: var(--accent);
}

.input-icon {
  font-size: 1.2rem;
  margin-right: 10px;
}

.input-with-icon input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: white;
  font-size: 1.05rem;
  padding: 10px 0;
  font-weight: 600;
}

/* Action Cards Grid */
.lobby-actions-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

.action-card {
  background: #0f172a;
  border: 1px solid var(--surface-border);
  border-radius: 14px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  justify-content: space-between;
}

.action-card.create-card {
  border-top: 4px solid var(--accent);
}

.action-card.join-card {
  border-top: 4px solid #10b981;
}

.card-title h3 {
  font-size: 1rem;
}

.card-desc {
  font-size: 0.8rem;
  color: var(--text-dim);
  line-height: 1.35;
  min-height: 32px;
}

.room-input-row {
  display: flex;
  gap: 6px;
}

.room-input-row input {
  flex: 1;
  background: #0b0f19;
  border: 1px solid var(--surface-border);
  color: white;
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 0.95rem;
  outline: none;
  font-family: monospace;
  font-weight: 600;
  text-transform: uppercase;
}

.room-input-row input:focus {
  border-color: var(--accent);
}

.btn-primary {
  background: linear-gradient(135deg, #0284c7, #38bdf8);
  color: white;
  border: none;
  padding: 12px 18px;
  font-size: 0.95rem;
  font-weight: bold;
  border-radius: 10px;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(56, 189, 248, 0.4);
  transition: transform 0.1s, opacity 0.2s;
  text-align: center;
}

.btn-primary:active {
  transform: scale(0.97);
}

.btn-secondary {
  background: linear-gradient(135deg, #059669, #10b981);
  color: white;
  border: none;
  padding: 12px 18px;
  font-size: 0.95rem;
  font-weight: bold;
  border-radius: 10px;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(16, 185, 129, 0.4);
  transition: transform 0.1s, opacity 0.2s;
  text-align: center;
}

.btn-secondary:active {
  transform: scale(0.97);
}

.btn-block {
  width: 100%;
}

.btn-sm {
  background: #1e293b;
  border: 1px solid var(--surface-border);
  color: var(--text-main);
  padding: 6px 12px;
  border-radius: 8px;
  font-size: 0.8rem;
  cursor: pointer;
}

.btn-sm:hover {
  background: #334155;
}

/* Active Rooms Section */
.active-rooms-section {
  border-top: 1px solid var(--surface-border);
  padding-top: 16px;
}

.active-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}

.active-header h3 {
  font-size: 0.9rem;
  color: var(--text-dim);
}

.active-rooms-container {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 180px;
  overflow-y: auto;
}

.room-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: #0f172a;
  border: 1px solid var(--surface-border);
  padding: 10px 14px;
  border-radius: 10px;
}

.room-item-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.room-item-name {
  font-weight: 700;
  font-size: 0.95rem;
  font-family: monospace;
}

.room-item-meta {
  font-size: 0.75rem;
  font-weight: 600;
}

.room-item-meta.available {
  color: #34d399;
}

.room-item-meta.full {
  color: #f87171;
}

/* =========================================
   VIEW 2: GAME ARENA
========================================= */
.app-container {
  width: 100%;
  max-width: 1300px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  box-sizing: border-box;
}

.game-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--surface);
  border: 1px solid var(--surface-border);
  padding: 8px 14px;
  border-radius: 12px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.4);
  flex-wrap: wrap;
  gap: 8px;
}

.logo-area {
  display: flex;
  align-items: center;
  gap: 8px;
}

.logo-area h1 {
  font-size: 1.15rem;
  letter-spacing: 1px;
}

.logo-area h1 span {
  color: var(--accent);
}

.status-badge {
  font-size: 0.7rem;
  padding: 2px 7px;
  border-radius: 20px;
  font-weight: 600;
  text-transform: uppercase;
}

.status-badge.connected {
  background: rgba(16, 185, 129, 0.2);
  color: #10b981;
  border: 1px solid #10b981;
}

.status-badge.connecting {
  background: rgba(245, 158, 11, 0.2);
  color: #f59e0b;
  border: 1px solid #f59e0b;
}

.status-badge.disconnected {
  background: rgba(239, 68, 68, 0.2);
  color: #ef4444;
  border: 1px solid #ef4444;
}

.ping-badge {
  font-size: 0.72rem;
  padding: 2px 7px;
  border-radius: 20px;
  font-weight: 700;
  font-family: monospace;
  background: rgba(148, 163, 184, 0.15);
  color: var(--text-dim);
  border: 1px solid var(--surface-border);
  transition: all 0.2s ease;
}

.ping-badge.good {
  background: rgba(16, 185, 129, 0.15);
  color: #34d399;
  border-color: #10b981;
}

.ping-badge.medium {
  background: rgba(245, 158, 11, 0.15);
  color: #f59e0b;
  border-color: #f59e0b;
}

.ping-badge.bad {
  background: rgba(239, 68, 68, 0.15);
  color: #f87171;
  border-color: #ef4444;
}

.room-pill {
  display: flex;
  align-items: center;
  gap: 6px;
  background: #0f172a;
  border: 1px solid var(--surface-border);
  padding: 4px 8px;
  border-radius: 8px;
  font-size: 0.8rem;
}

.room-label {
  color: var(--text-dim);
}

#currentRoomText {
  color: var(--accent);
  letter-spacing: 0.5px;
  font-family: monospace;
}

.pill-btn {
  background: #1e293b;
  border: 1px solid var(--surface-border);
  color: var(--text-main);
  padding: 3px 8px;
  border-radius: 6px;
  font-size: 0.75rem;
  cursor: pointer;
  transition: all 0.2s;
  font-weight: 600;
}

.pill-btn:hover {
  background: #334155;
}

.pill-btn.highlight {
  background: #0284c7;
  border-color: #38bdf8;
  color: white;
}

.pill-btn.danger {
  background: rgba(239, 68, 68, 0.2);
  border-color: #ef4444;
  color: #fca5a5;
}

.pill-btn.danger:hover {
  background: #ef4444;
  color: white;
}

.bot-pill {
  display: flex;
  align-items: center;
  gap: 4px;
}

.pill-btn.bot-add-btn {
  background: rgba(16, 185, 129, 0.2);
  border-color: #10b981;
  color: #6ee7b7;
}

.pill-btn.bot-add-btn:hover {
  background: #10b981;
  color: white;
}

.pill-btn.bot-del-btn {
  background: rgba(239, 68, 68, 0.15);
  border-color: #ef4444;
  color: #fca5a5;
}

.pill-btn.bot-del-btn:hover {
  background: #ef4444;
  color: white;
}

.hud-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.hud-bot-actions {
  display: flex;
  gap: 4px;
}

/* Floating K.O. Round End Banner */
.ko-banner {
  position: absolute;
  top: 18px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(15, 23, 42, 0.92);
  border: 2px solid #ef4444;
  border-radius: 30px;
  padding: 8px 20px;
  display: flex;
  align-items: center;
  gap: 10px;
  box-shadow: 0 8px 24px rgba(239, 68, 68, 0.4);
  z-index: 8;
  animation: koBannerDrop 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  pointer-events: none;
}

@keyframes koBannerDrop {
  from {
    opacity: 0;
    transform: translate(-50%, -20px) scale(0.9);
  }
  to {
    opacity: 1;
    transform: translate(-50%, 0) scale(1);
  }
}

.ko-badge {
  font-size: 1rem;
  font-weight: 900;
  color: #f87171;
  letter-spacing: 1px;
}

.ko-text {
  font-size: 0.85rem;
  font-weight: 700;
  color: #f8fafc;
}

.bot-tag {
  display: inline-block;
  font-size: 0.65rem;
  font-weight: 800;
  padding: 1px 5px;
  border-radius: 4px;
  background: rgba(56, 189, 248, 0.2);
  border: 1px solid #38bdf8;
  color: #7dd3fc;
  margin-left: 4px;
  vertical-align: middle;
}

.user-panel {
  display: flex;
  align-items: center;
  gap: 8px;
}

.player-badge {
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 0.8rem;
  font-weight: 700;
  background: #334155;
  color: white;
}

#nameInput {
  background: #0b0f19;
  border: 1px solid var(--surface-border);
  color: white;
  padding: 5px 10px;
  border-radius: 6px;
  font-size: 0.8rem;
  outline: none;
  width: 95px;
}

#nameInput:focus {
  border-color: var(--accent);
}

.icon-btn {
  background: #1e293b;
  border: 1px solid var(--surface-border);
  color: white;
  width: 32px;
  height: 32px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 1rem;
  display: flex;
  align-items: center;
  justify-content: center;
}

.icon-btn:hover {
  background: #334155;
}

/* Mobile Player Strip (Compact cards below header) */
.mobile-player-strip {
  display: none;
  gap: 6px;
  overflow-x: auto;
  padding: 4px 2px;
  width: 100%;
}

.mobile-p-pill {
  display: flex;
  align-items: center;
  gap: 5px;
  background: #151d30;
  border: 1px solid var(--surface-border);
  border-left: 4px solid #64748b;
  padding: 4px 8px;
  border-radius: 6px;
  font-size: 0.72rem;
  white-space: nowrap;
}

.mobile-p-pill.dead {
  opacity: 0.45;
  filter: grayscale(1);
}

.mobile-p-pill.is-you {
  border-color: #38bdf8;
  background: #172554;
}

/* Main Layout */
.game-main {
  display: grid;
  grid-template-columns: 1fr 270px;
  gap: 12px;
  align-items: start;
}

.canvas-wrapper {
  position: relative;
  width: 100%;
  aspect-ratio: 15 / 11;
  background: #111827;
  border: 2px solid var(--surface-border);
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.6);
  touch-action: none;
}

#gameCanvas {
  width: 100%;
  height: 100%;
  display: block;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  touch-action: none;
}

/* Compact Floating Round Result Notification (Does NOT cover arena) */
.round-result-banner {
  position: absolute;
  top: 14px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(15, 23, 42, 0.95);
  border: 2px solid var(--accent);
  border-radius: 14px;
  padding: 8px 18px;
  display: flex;
  align-items: center;
  gap: 14px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.75), 0 0 15px rgba(56, 189, 248, 0.35);
  z-index: 10;
  animation: slideDownResult 0.35s cubic-bezier(0.16, 1, 0.3, 1);
  pointer-events: auto;
  max-width: 90%;
}

@keyframes slideDownResult {
  from {
    opacity: 0;
    transform: translate(-50%, -24px) scale(0.95);
  }
  to {
    opacity: 1;
    transform: translate(-50%, 0) scale(1);
  }
}

.result-trophy {
  font-size: 1.6rem;
  line-height: 1;
}

.result-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.result-title {
  font-size: 0.95rem;
  font-weight: 800;
  color: #f8fafc;
}

.result-sub {
  font-size: 0.75rem;
  color: var(--text-dim);
}

.btn-restart-pill {
  background: #0284c7;
  border: 1px solid #38bdf8;
  color: #ffffff;
  padding: 6px 14px;
  border-radius: 8px;
  font-weight: 700;
  font-size: 0.82rem;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.2s;
  box-shadow: 0 2px 8px rgba(2, 132, 199, 0.4);
}

.btn-restart-pill:hover {
  background: #0369a1;
  transform: scale(1.04);
}

/* Desktop Sidebar HUD */
.players-hud {
  background: var(--surface);
  border: 1px solid var(--surface-border);
  border-radius: 12px;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.players-hud h2 {
  font-size: 0.95rem;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.player-cards {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.p-card {
  background: #0f172a;
  border: 1px solid var(--surface-border);
  border-left: 5px solid #64748b;
  border-radius: 8px;
  padding: 8px 10px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.p-card.is-you {
  background: #172554;
  border-color: #3b82f6;
}

.p-card.dead {
  opacity: 0.5;
  filter: grayscale(0.8);
}

.p-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.p-name {
  font-weight: bold;
  font-size: 0.9rem;
}

.p-status {
  font-size: 0.68rem;
  padding: 2px 6px;
  border-radius: 4px;
  font-weight: 700;
}

.p-status.alive {
  background: #065f46;
  color: #34d399;
}

.p-status.eliminated {
  background: #7f1d1d;
  color: #f87171;
}

.p-stats {
  display: flex;
  gap: 10px;
  font-size: 0.78rem;
  color: var(--text-dim);
}

.p-stats span b {
  color: var(--text-main);
}

.buff-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 4px;
}

.buff-tag {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-size: 0.7rem;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 4px;
  background: #1e293b;
  border: 1px solid #334155;
  animation: buffPulse 1.8s infinite ease-in-out;
}

.mobile-buff-tag {
  font-size: 0.65rem;
  font-weight: 700;
  padding: 1px 4px;
  border-radius: 4px;
}

@keyframes buffPulse {
  0%, 100% { opacity: 0.95; }
  50% { opacity: 0.7; }
}

.buff-tag.shield, .mobile-buff-tag.shield {
  background: rgba(168, 85, 247, 0.25);
  border: 1px solid #a855f7;
  color: #d8b4fe;
}

.buff-tag.fire, .mobile-buff-tag.fire {
  background: rgba(245, 158, 11, 0.25);
  border: 1px solid #f59e0b;
  color: #fcd34d;
}

.buff-tag.speed, .mobile-buff-tag.speed {
  background: rgba(56, 189, 248, 0.25);
  border: 1px solid #38bdf8;
  color: #7dd3fc;
}

.buff-tag.bomb, .mobile-buff-tag.bomb {
  background: rgba(239, 68, 68, 0.25);
  border: 1px solid #ef4444;
  color: #fca5a5;
}

/* Controls Guide */
.controls-guide {
  background: #0f172a;
  border: 1px solid var(--surface-border);
  border-radius: 8px;
  padding: 10px;
  font-size: 0.8rem;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.controls-guide h3 {
  font-size: 0.85rem;
  color: var(--accent);
}

kbd {
  background: #334155;
  border: 1px solid #475569;
  border-radius: 4px;
  padding: 2px 5px;
  font-size: 0.72rem;
  font-weight: 600;
}

.item-legend {
  display: flex;
  justify-content: space-between;
  border-top: 1px solid var(--surface-border);
  padding-top: 6px;
  font-size: 0.75rem;
}

/* =========================================
   ERGONOMIC MOBILE CONTROLS
========================================= */
.mobile-controls {
  display: none;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  width: 100%;
  justify-content: space-between;
  align-items: center;
  padding: 8px 12px;
  box-sizing: border-box;
}

/* Touch D-Pad */
.dpad-touch-zone {
  width: 150px;
  height: 150px;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: none;
}

.dpad-cross {
  width: 144px;
  height: 144px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  position: relative;
}

.dpad-mid-row {
  display: flex;
  align-items: center;
  justify-content: center;
}

.dpad-dir {
  width: 48px;
  height: 48px;
  background: #1e293b;
  border: 2px solid #334155;
  color: #94a3b8;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  transition: background 0.1s;
  touch-action: none;
}

.dpad-up {
  border-radius: 12px 12px 4px 4px;
  border-bottom: none;
}

.dpad-down {
  border-radius: 4px 4px 12px 12px;
  border-top: none;
}

.dpad-left {
  border-radius: 12px 4px 4px 12px;
  border-right: none;
}

.dpad-right {
  border-radius: 4px 12px 12px 4px;
  border-left: none;
}

.dpad-center-hub {
  width: 48px;
  height: 48px;
  background: #151d30;
  border: 1px solid #24324f;
}

/* Active touch state on D-pad */
.dpad-dir.active {
  background: var(--accent) !important;
  color: #0b0f19 !important;
  box-shadow: 0 0 14px var(--accent);
}

/* Big Action Bomb Button */
.action-buttons {
  display: flex;
  align-items: center;
  justify-content: center;
}

.touch-bomb-btn {
  width: 90px;
  height: 90px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #f87171, #dc2626 65%, #991b1b);
  border: 4px solid #fecaca;
  color: white;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  box-shadow: 0 8px 22px rgba(220, 38, 38, 0.55), inset 0 2px 4px rgba(255, 255, 255, 0.4);
  touch-action: none;
  cursor: pointer;
  transition: transform 0.08s;
}

.touch-bomb-btn:active {
  transform: scale(0.9);
  background: radial-gradient(circle at 35% 35%, #ef4444, #b91c1c 70%, #7f1d1d);
  box-shadow: 0 4px 10px rgba(220, 38, 38, 0.7);
}

.touch-bomb-btn .bomb-emoji {
  font-size: 1.8rem;
  line-height: 1;
}

.touch-bomb-btn .bomb-txt {
  font-size: 0.75rem;
  font-weight: 900;
  letter-spacing: 1px;
}

/* Toast */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: #1e293b;
  border: 1px solid var(--accent);
  color: white;
  padding: 10px 20px;
  border-radius: 30px;
  font-size: 0.85rem;
  box-shadow: 0 6px 20px rgba(0,0,0,0.5);
  z-index: 200;
  transition: opacity 0.3s ease;
  pointer-events: none;
}

.toast.hidden {
  opacity: 0;
}

/* =========================================
   RESPONSIVE DESIGN (SMARTPHONES & TABLETS)
========================================= */
@media (max-width: 900px) {
  .lobby-card {
    padding: 20px 16px;
  }
  .lobby-actions-grid {
    grid-template-columns: 1fr;
    gap: 12px;
  }
  .game-main {
    grid-template-columns: 1fr;
    gap: 8px;
  }
  .desktop-only {
    display: none !important;
  }
  .mobile-player-strip {
    display: flex;
  }
  .mobile-controls {
    display: flex;
  }
  .app-container {
    padding: 6px;
    gap: 6px;
  }
  .game-header {
    padding: 6px 10px;
  }
  .logo-area h1 {
    font-size: 1rem;
  }
}

/* Landscape mode on phones (Nintendo Switch layout) */
@media (max-width: 900px) and (orientation: landscape) {
  body {
    align-items: stretch;
  }
  .app-container {
    height: 100vh;
    height: 100dvh;
    padding: 4px;
    justify-content: space-between;
  }
  .game-main {
    flex: 1;
    display: flex;
    justify-content: center;
    align-items: center;
  }
  .canvas-wrapper {
    height: 100%;
    max-height: calc(100vh - 120px);
    max-height: calc(100dvh - 120px);
    width: auto;
  }
  .mobile-controls {
    padding: 2px 20px 6px;
  }
  .dpad-touch-zone {
    width: 120px;
    height: 120px;
  }
  .dpad-cross {
    width: 120px;
    height: 120px;
  }
  .dpad-dir, .dpad-center-hub {
    width: 40px;
    height: 40px;
  }
  .touch-bomb-btn {
    width: 76px;
    height: 76px;
  }
}
