* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  touch-action: none;
}

body, html {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background-color: #121214;
  color: #f0f0f5;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

.screen {
  display: none;
  width: 100%;
  height: 100%;
}

.screen.active {
  display: flex;
}

/* ========================================================
   JOIN SCREEN
======================================================== */
#join-screen {
  justify-content: center;
  align-items: center;
  background: radial-gradient(circle at center, #1e1e24 0%, #121214 100%);
  padding: 20px;
}

.join-card {
  width: 100%;
  max-width: 380px;
  background: rgba(30, 30, 36, 0.7);
  backdrop-filter: blur(12px);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 20px;
  padding: 30px 24px;
  text-align: center;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.6);
}

.logo {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
}

.logo h1 {
  font-size: 28px;
  font-weight: 800;
  letter-spacing: -0.5px;
}

.logo h1 span {
  color: #e60012; /* Nintendo Red */
}

.subtitle {
  font-size: 13px;
  color: #8e8e93;
  margin-bottom: 24px;
}

.code-input-container {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 20px;
}

.code-input-container label {
  font-size: 11px;
  letter-spacing: 1.5px;
  font-weight: 700;
  color: #0ab9e6; /* Switch Cyan */
}

#room-code {
  width: 100%;
  height: 56px;
  border-radius: 12px;
  border: 2px solid #2c2c34;
  background: #18181d;
  color: #ffffff;
  font-size: 24px;
  font-weight: 800;
  letter-spacing: 6px;
  text-align: center;
  text-transform: uppercase;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}

#room-code:focus {
  border-color: #0ab9e6;
  box-shadow: 0 0 16px rgba(10, 185, 230, 0.4);
}

.btn-primary {
  width: 100%;
  height: 50px;
  border: none;
  border-radius: 12px;
  background: linear-gradient(135deg, #0ab9e6 0%, #0077c8 100%);
  color: white;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 8px 24px rgba(10, 185, 230, 0.3);
  transition: transform 0.1s, opacity 0.2s;
}

.btn-primary:active {
  transform: scale(0.98);
  opacity: 0.9;
}

.status-msg {
  margin-top: 14px;
  font-size: 13px;
  min-height: 18px;
}

.status-msg.error {
  color: #ff453a;
}

.status-msg.info {
  color: #30d158;
}

/* ========================================================
   GAMEPAD CONTROLLER SCREEN
======================================================== */
#gamepad-screen {
  flex-direction: column;
}

.hud-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  height: 40px;
  padding: 0 16px;
  background: #18181d;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.player-badge {
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 1px;
  color: #0ab9e6;
  background: rgba(10, 185, 230, 0.15);
  padding: 4px 10px;
  border-radius: 12px;
}

.hud-center {
  display: flex;
  gap: 8px;
}

.hud-btn {
  background: #282830;
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: #cccccc;
  font-size: 11px;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 8px;
  cursor: pointer;
}

.hud-btn.active {
  background: #30d158;
  color: #000;
}

.connection-status {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  color: #8e8e93;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #ff453a;
}

.status-dot.connected {
  background: #30d158;
  box-shadow: 0 0 6px #30d158;
}

/* Controller Surface */
.controller-surface {
  flex: 1;
  display: flex;
  padding: 10px 14px;
  gap: 12px;
}

.wing {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.wing-center {
  width: 50px;
  display: flex;
  justify-content: center;
  align-items: center;
}

.brand-badge {
  font-size: 10px;
  letter-spacing: 2px;
  color: rgba(255, 255, 255, 0.2);
  transform: rotate(-90deg);
  font-weight: 800;
}

/* Shoulder Buttons (L, ZL, R, ZR) */
.shoulder-row {
  display: flex;
  gap: 10px;
  height: 48px;
}

.btn-shoulder {
  flex: 1;
  background: #24242c;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 10px;
  color: #ffffff;
  font-size: 15px;
  font-weight: 800;
  display: flex;
  justify-content: center;
  align-items: center;
  box-shadow: 0 4px 10px rgba(0,0,0,0.4);
}

.btn-shoulder.active {
  background: #0ab9e6;
  box-shadow: 0 0 16px #0ab9e6;
  transform: translateY(2px);
}

.right-wing .btn-shoulder.active {
  background: #e60012;
  box-shadow: 0 0 16px #e60012;
}

/* Middle meta buttons (+, -, Home, Capture) */
.middle-row {
  display: flex;
  gap: 12px;
  justify-content: flex-end;
  padding: 4px 8px;
}

.btn-meta {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: #202026;
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: #ffffff;
  font-size: 15px;
  font-weight: bold;
}

.btn-meta.active {
  background: #ffffff;
  color: #000000;
}

/* Joystick Zones */
.joystick-zone {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 140px;
}

.joystick-base {
  width: 120px;
  height: 120px;
  border-radius: 50%;
  background: radial-gradient(circle at center, #26262e 0%, #17171a 100%);
  border: 2px solid rgba(255, 255, 255, 0.1);
  display: flex;
  justify-content: center;
  align-items: center;
  position: relative;
  box-shadow: inset 0 4px 10px rgba(0, 0, 0, 0.6);
}

.joystick-thumb {
  width: 54px;
  height: 54px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #444450 0%, #202026 100%);
  border: 2px solid rgba(255, 255, 255, 0.2);
  box-shadow: 0 6px 14px rgba(0, 0, 0, 0.6);
  position: absolute;
  pointer-events: none;
  transform: translate(0px, 0px);
  transition: transform 0.05s ease-out;
}

/* D-Pad */
.dpad {
  display: grid;
  grid-template-columns: repeat(3, 44px);
  grid-template-rows: repeat(3, 44px);
  justify-content: center;
  align-content: center;
}

.btn-dpad {
  background: #24242c;
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: #ffffff;
  font-size: 16px;
  display: flex;
  justify-content: center;
  align-items: center;
}

.btn-dpad.up { grid-column: 2; grid-row: 1; border-radius: 8px 8px 0 0; }
.btn-dpad.left { grid-column: 1; grid-row: 2; border-radius: 8px 0 0 8px; }
.btn-dpad.center { grid-column: 2; grid-row: 2; background: #24242c; border: none; }
.btn-dpad.right { grid-column: 3; grid-row: 2; border-radius: 0 8px 8px 0; }
.btn-dpad.down { grid-column: 2; grid-row: 3; border-radius: 0 0 8px 8px; }

.btn-dpad.active {
  background: #0ab9e6;
  box-shadow: 0 0 12px #0ab9e6;
}

/* ABXY Cluster */
.abxy-cluster {
  display: grid;
  grid-template-columns: repeat(3, 46px);
  grid-template-rows: repeat(3, 46px);
  justify-content: center;
  align-content: center;
}

.btn-action {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: #24242c;
  border: 1px solid rgba(255, 255, 255, 0.15);
  color: #ffffff;
  font-size: 18px;
  font-weight: 800;
  display: flex;
  justify-content: center;
  align-items: center;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.4);
}

.btn-action.x { grid-column: 2; grid-row: 1; }
.btn-action.y { grid-column: 1; grid-row: 2; }
.btn-action.a { grid-column: 3; grid-row: 2; }
.btn-action.b { grid-column: 2; grid-row: 3; }

.btn-action.active {
  background: #e60012;
  box-shadow: 0 0 16px #e60012;
  transform: scale(0.92);
}
