* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  touch-action: manipulation;
  overscroll-behavior: none;
}

body {
  font-family: Arial, sans-serif;
  background: #0f141c;
  color: #f2f5f8;
}

.app {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 320px 1fr;
}

.panel {
  padding: 24px;
  background: #161d27;
  border-right: 1px solid rgba(255, 255, 255, 0.08);
}

.panel h1 {
  margin: 0 0 8px;
  font-size: 28px;
}

.sub {
  margin: 0 0 24px;
  color: #9eb1c7;
}

label {
  display: block;
  margin: 16px 0 8px;
  font-weight: bold;
}

input[type="text"],
input[type="color"] {
  width: 100%;
  padding: 12px;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: #0f141c;
  color: white;
}

input[type="color"] {
  height: 48px;
  padding: 6px;
}

.buttons {
  display: flex;
  gap: 12px;
  margin-top: 20px;
}

button {
  flex: 1;
  padding: 12px 14px;
  border: none;
  border-radius: 12px;
  font-weight: bold;
  cursor: pointer;
}

button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

#joinBtn {
  background: #67e8a5;
  color: #0e1712;
}

#leaveBtn {
  background: #ff8b8b;
  color: #261111;
}

.info,
.help {
  margin-top: 24px;
  padding: 14px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.05);
}

.game-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  overflow: hidden;
}

.game-stage {
  position: relative;
  width: 960px;
  max-width: 100%;
}

canvas {
  display: block;
  width: 960px;
  max-width: 100%;
  height: auto;
  border-radius: 18px;
  background: linear-gradient(#b8dcff, #dff0ff);
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.35);
}

.chat-toggle {
  position: absolute;
  top: 14px;
  right: 14px;
  z-index: 20;
  width: 56px;
  height: 56px;
  padding: 0;
  border: none;
  border-radius: 50%;
  background: transparent;
  cursor: pointer;
  overflow: hidden;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.28);
  flex: none;
}

.chat-toggle img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.fullscreen-toggle {
  position: absolute;
  top: 14px;
  right: 80px;
  z-index: 20;
  width: 56px;
  height: 56px;
  padding: 0;
  border: none;
  border-radius: 50%;
  background: rgba(15, 20, 28, 0.88);
  color: white;
  font-size: 28px;
  line-height: 1;
  cursor: pointer;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.28);
  flex: none;
}

.fullscreen-toggle:active,
.chat-toggle:active {
  transform: scale(0.96);
}

.chat-composer {
  position: absolute;
  top: 80px;
  right: 14px;
  z-index: 25;
  width: 280px;
  max-width: calc(100% - 28px);
  background: rgba(15, 20, 28, 0.96);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 16px;
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.35);
  padding: 14px;
}

.hidden {
  display: none !important;
}

#chatInput {
  width: 100%;
  padding: 12px;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: #0f141c;
  color: #fff;
}

.chat-row {
  display: flex;
  gap: 10px;
  margin-top: 12px;
}

#sendChatBtn {
  background: #67e8a5;
  color: #0e1712;
}

#cancelChatBtn {
  background: #ff8b8b;
  color: #261111;
}

.mobile-controls {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 30;
}

.mobile-left,
.mobile-right {
  position: absolute;
  bottom: 18px;
  display: flex;
  gap: 12px;
  pointer-events: auto;
}

.mobile-left {
  left: 18px;
}

.mobile-right {
  right: 18px;
}

.mobile-btn {
  width: 64px;
  height: 64px;
  border: none;
  border-radius: 18px;
  font-size: 28px;
  font-weight: bold;
  color: white;
  background: rgba(15, 20, 28, 0.72);
  backdrop-filter: blur(6px);
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.28);
  display: flex;
  align-items: center;
  justify-content: center;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
  flex: none;
}

.jump-btn {
  width: 74px;
  height: 74px;
  border-radius: 50%;
}

.mobile-btn:active {
  transform: scale(0.96);
}

body.fullscreen-active .panel {
  display: none;
}

body.fullscreen-active .app {
  grid-template-columns: 1fr;
}

body.fullscreen-active .game-wrap {
  padding: 0;
}

.game-stage:fullscreen {
  width: 100vw;
  height: 100vh;
  max-width: none;
  background: #0b1220;
  display: flex;
  align-items: center;
  justify-content: center;
}

.game-stage:fullscreen canvas {
  width: 100vw;
  height: auto;
  max-height: 100vh;
  max-width: calc(100vh * 1.6);
  border-radius: 0;
}

.game-stage:fullscreen .mobile-controls {
  inset: 0;
}

.game-stage:fullscreen .chat-toggle {
  top: max(12px, env(safe-area-inset-top));
  right: max(12px, env(safe-area-inset-right));
}

.game-stage:fullscreen .fullscreen-toggle {
  top: max(12px, env(safe-area-inset-top));
  right: calc(max(12px, env(safe-area-inset-right)) + 66px);
}

.game-stage:fullscreen .chat-composer {
  top: calc(max(12px, env(safe-area-inset-top)) + 66px);
  right: max(12px, env(safe-area-inset-right));
}

@media (hover: hover) and (pointer: fine) {
  .mobile-btn:hover {
    background: rgba(15, 20, 28, 0.86);
  }
}

@media (max-width: 980px) {
  .app {
    grid-template-columns: 1fr;
  }

  .panel {
    border-right: none;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  }

  .game-wrap {
    padding: 12px;
  }

  .chat-toggle {
    width: 50px;
    height: 50px;
    top: 10px;
    right: 10px;
  }

  .fullscreen-toggle {
    width: 50px;
    height: 50px;
    top: 10px;
    right: 68px;
    font-size: 24px;
  }

  .chat-composer {
    top: 68px;
    right: 10px;
    width: min(280px, calc(100% - 20px));
  }
}